comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: sub-optimal code for packed boolean arrays -- bug or inherent limitation
Date: Tue, 03 Jul 2007 08:42:07 -0700
Date: 2007-07-03T08:42:07-07:00	[thread overview]
Message-ID: <1183477327.123666.166750@a26g2000pre.googlegroups.com> (raw)
In-Reply-To: <1183404856.375083.160890@q69g2000hsb.googlegroups.com>

On Jul 2, 12:34 pm, Alinabi <alexander.the.aver...@gmail.com> wrote:


>     procedure Flip(B : in out Bitboard_T; I : in Index_T) is
>     begin
>         B(i) := not B(i);
>     end;

Just as an experiment, I wonder what the following does.  I realize
that this code isn't useful.

   procedure Sideways_Flip(B : in out Bitboard_T; I, J : in Index_T)
is
   begin
       B(i) := not B(j);
   end;

If the assembly code looks substantially the same as your example,
that's an indication that your compiler isn't recognizing that the
B(i) on the left and right sides of the assignment are the same.  (It
makes perfect sense to me that the compiler might be able to recognize
a simple variable that's the same on both sides, but not an indexed
variable.)  I don't know that this helps solve the problem, except to
indicate that most likely any other "solution" that has B(i) on both
sides of := isn't going to be any better.

Hmmm... it just occurred to me that if the compiler can figure out to
optimize simple names on both sides of := but not indexed variables,
maybe this will work:

   procedure Flip(B : in out Bitboard_T; I : Index_T) is
      The_Bit : Boolean renames B(I);
   begin
      The_Bit := not The_Bit;
   end;

It's worth a try.  Sometimes doing stuff like this is enough to
confuse a compiler into doing the right thing.

If nothing else works, here's a possible workaround, but be warned
that I haven't tried this:

   procedure Flip(B : in out Bitboard_T; I : in Index_T) is
      type Int_64 is mod 2**64;
      B_Overlay : Int_64;
      for B_Overlay'Address use B'Address;
   begin
      B_Overlay := B_Overlay xor 2**Integer(I);  --or
      B_Overlay := B_Overlay xor 2**Integer(63-I);
   end;

I don't know which of the xor's will work, or if either of them work;
it depends on how the elements of Bitboard_T are ordered.  The above
code is evil, and it's the kind of thing I'd do only out of
desperation---but at least the obfuscation in your program will be
limited to one place.

                   -- Adam





  parent reply	other threads:[~2007-07-03 15:42 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-02 19:34 sub-optimal code for packed boolean arrays -- bug or inherent limitation Alinabi
2007-07-02 20:08 ` Ludovic Brenta
2007-07-03  1:01 ` Jeffrey R. Carter
2007-07-03  7:22   ` Harald Korneliussen
2007-07-03  8:37     ` Georg Bauhaus
2007-07-03  7:59 ` gautier_niouzes
2007-07-03  9:25 ` Stefan Lucks
2007-07-03 12:40   ` Stefan Lucks
2007-07-03 15:42 ` Adam Beneschan [this message]
2007-07-03 18:04 ` Alinabi
2007-07-03 18:09   ` Alinabi
2007-07-03 18:17     ` Alinabi
2007-07-10  2:06       ` Randy Brukardt
2007-07-03 18:36   ` Jeffrey R. Carter
2007-07-03 19:42     ` Alinabi
2007-07-04  1:12       ` Jeffrey R. Carter
2007-07-04 10:15         ` Jeffrey Creem
2007-07-04 18:28           ` Jeffrey R. Carter
2007-07-04  3:22       ` Steve
2007-07-04  6:31         ` Harald Korneliussen
2007-07-08 22:53     ` Robert A Duff
2007-07-09  6:09       ` tmoran
2007-07-04  9:00   ` Jean-Pierre Rosen
2007-07-04 18:27     ` tmoran
2007-07-04 19:16       ` Pascal Obry
2007-07-05  1:45         ` tmoran
2007-07-05  4:53       ` Jeffrey R. Carter
2007-07-04 18:51     ` tmoran
2007-07-08 22:58 ` Robert A Duff
replies disabled

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