From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,2c57913d6b8220c1 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!feeder.news-service.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Tue, 13 Oct 2009 14:57:06 +0200 From: Georg Bauhaus User-Agent: Thunderbird 2.0.0.23 (Macintosh/20090812) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Tasking for Mandelbrot program References: <4abebaf4$0$31342$9b4e6d93@newsspool4.arcor-online.net> <4abfd8df$0$31337$9b4e6d93@newsspool4.arcor-online.net> <59856ad8-2434-4370-a1df-875b46b3b7bc@o41g2000yqb.googlegroups.com> <4ad36024$0$7626$9b4e6d93@newsspool1.arcor-online.net> <13d4e273-d473-4e9e-9029-61910e969108@k19g2000yqc.googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Message-ID: <4ad47923$0$6662$9b4e6d93@newsspool2.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 13 Oct 2009 14:57:07 CEST NNTP-Posting-Host: 41e3c18a.newsspool2.arcor-online.net X-Trace: DXC=i`9IgjQaYlig`45cDR8l?oA9EHlD;3Ycb4Fo<]lROoRa8kF55@P_anc\616M64>jLh>_cHTX3jmXW7MlId`I6` X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:8696 Date: 2009-10-13T14:57:07+02:00 List-Id: Gautier write-only schrieb: > On 13 Okt., 11:11, Mark Lorenzen wrote: > >> Please note that the "bit-wise or" operation in the following line has >> no effect: >> Byte_Acc := Shift_Left (Byte_Acc, 1) or 16#00# >> >> When shifting left, you are guaranteed that zeroes are shifted in. > > Well "or 0" has no effect anyway (shift or not shift). If you wanted > to filter something, you would write "and 16#FFFFFF00# :-) I'm stating the obvious when saying that the compiler knows that "or 16#00#" has no effect... ;-) FWIW, the simple symmetric if/else around the above line seems to give the fastest program with this distinction, at least when produced by the Shootout compiler; with GNATs such as GPL GNAT we might be able to reduce source size by using Boolean'Pos instead of if/else or even anonymous conditional expressions as are proposed for Ada 1Y. Compile with -gnatX if using GNAT, to see timing differences, if any: with Interfaces; use Interfaces; with Ada.Command_Line ; use Ada.Command_Line; with Ada.Calendar; use Ada.Calendar; with Ada.Text_IO; use Ada.Text_IO; procedure Bittest is Byte_Acc : Unsigned_8; Ntests : constant := 100; procedure Work (This_Way: Boolean) is pragma Inline (Work); begin for K in 1 .. Ntests loop Byte_Acc := Shift_Left (Byte_Acc, 1) or Boolean'Pos(not This_Way); end loop; end work; procedure Work2 (This_Way: Boolean) is -- original pragma Inline (Work2); begin for K in 1 .. Ntests loop if This_Way then Byte_Acc := Shift_Left (Byte_Acc, 1) or 16#00#; else Byte_Acc := Shift_Left (Byte_Acc, 1) or 16#01#; end if; end loop; end Work2; procedure WorkX (This_Way: Boolean) is pragma Inline (WorkX); begin for K in 1 .. Ntests loop Byte_Acc := Shift_Left (Byte_Acc, 1) or (if This_Way then 16#00# else 16#01#); end loop; end WorkX; Start, Finish: Time; begin Byte_Acc := Boolean'Pos(Argument_Count > 1); Start := Clock; for K in 1 .. 5_000_000 loop Work (Argument(1) = "yes"); end loop; Finish := Clock; Put_Line ("Work: Byte_Acc = " & Unsigned_8'Image (Byte_Acc) & " in " & Duration'Image (Finish - Start) & " seconds"); Byte_Acc := Boolean'Pos(Argument_Count > 1); Start := Clock; for K in 1 .. 5_000_000 loop Work2 (Argument(1) = "yes"); end loop; Finish := Clock; Put_Line ("Work2: Byte_Acc = " & Unsigned_8'Image (Byte_Acc) & " in " & Duration'Image (Finish - Start) & " seconds"); Byte_Acc := Boolean'Pos(Argument_Count > 1); Start := Clock; for K in 1 .. 5_000_000 loop WorkX (Argument(1) = "yes"); end loop; Finish := Clock; Put_Line ("WorkX: Byte_Acc = " & Unsigned_8'Image (Byte_Acc) & " in " & Duration'Image (Finish - Start) & " seconds"); end Bittest;