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: 103376,5ff6e0c3de8331c0 X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!a26g2000pre.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: sub-optimal code for packed boolean arrays -- bug or inherent limitation Date: Tue, 03 Jul 2007 08:42:07 -0700 Organization: http://groups.google.com Message-ID: <1183477327.123666.166750@a26g2000pre.googlegroups.com> References: <1183404856.375083.160890@q69g2000hsb.googlegroups.com> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-Trace: posting.google.com 1183477328 851 127.0.0.1 (3 Jul 2007 15:42:08 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 3 Jul 2007 15:42:08 +0000 (UTC) In-Reply-To: <1183404856.375083.160890@q69g2000hsb.googlegroups.com> User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: a26g2000pre.googlegroups.com; posting-host=66.126.103.122; posting-account=cw1zeQwAAABOY2vF_g6V_9cdsyY_wV9w Xref: g2news1.google.com comp.lang.ada:16396 Date: 2007-07-03T08:42:07-07:00 List-Id: On Jul 2, 12:34 pm, Alinabi 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