comp.lang.ada
 help / color / mirror / Atom feed
From: Georg Bauhaus <rm.dash-bauhaus@futureapps.de>
Subject: Re: Tasking for Mandelbrot program
Date: Tue, 13 Oct 2009 14:57:06 +0200
Date: 2009-10-13T14:57:07+02:00	[thread overview]
Message-ID: <4ad47923$0$6662$9b4e6d93@newsspool2.arcor-online.net> (raw)
In-Reply-To: <a5ee058d-4093-4c1a-b1a7-50c3870ce688@g31g2000yqc.googlegroups.com>

Gautier write-only schrieb:
> On 13 Okt., 11:11, Mark Lorenzen <mark.loren...@gmail.com> 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;



      reply	other threads:[~2009-10-13 12:57 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-27  1:08 Tasking for Mandelbrot program Georg Bauhaus
2009-09-27 11:24 ` Martin
2009-09-27 21:27   ` Georg Bauhaus
2009-09-28  5:48     ` Martin
2009-09-28 19:27     ` jonathan
2009-09-29 15:26       ` Georg Bauhaus
2009-09-28 19:52     ` jonathan
2009-10-12 16:58       ` Georg Bauhaus
2009-10-12 22:46         ` jonathan
2009-10-12 23:42           ` Anh Vo
2009-10-13  9:11         ` Mark Lorenzen
2009-10-13  9:39           ` Gautier write-only
2009-10-13 12:57             ` Georg Bauhaus [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox