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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no 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!w5g2000hsg.googlegroups.com!not-for-mail From: Alinabi Newsgroups: comp.lang.ada Subject: Re: sub-optimal code for packed boolean arrays -- bug or inherent limitation Date: Tue, 03 Jul 2007 18:04:02 -0000 Organization: http://groups.google.com Message-ID: <1183485842.725620.199490@w5g2000hsg.googlegroups.com> References: <1183404856.375083.160890@q69g2000hsb.googlegroups.com> NNTP-Posting-Host: 75.75.8.72 Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-Trace: posting.google.com 1183485842 5900 127.0.0.1 (3 Jul 2007 18:04:02 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 3 Jul 2007 18:04:02 +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.8.1.4) Gecko/20061201 Firefox/2.0.0.4 (Ubuntu-feisty),gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: w5g2000hsg.googlegroups.com; posting-host=75.75.8.72; posting-account=gD74RA0AAABm9rsBG7oeOmJ-iO5c3KUQ Xref: g2news1.google.com comp.lang.ada:16397 Date: 2007-07-03T18:04:02+00:00 List-Id: First, let me thank all of you for your replies. I feel that I have to clarify a few things about this pet project of mine. I used to play chess at a competition level and I always wanted to write a chess program, but part of the motivation for starting the project is to learn the "dark corners" of Ada. So, I am not interested in switching to C. As I said, the bitboard operations can be implemented in C-like fashion, using Unsigned_64, masks and shifts, and that's how I have implemented them so far. This makes the static evaluation function hard to understand for someone who is not necessarily an experienced programmer. While I used to be a candidate master once upon a time, I do not play at that strength anymore and I could benefit from the advice of a strong player (who might not be a programmer). For such a person B(i) := not B(i) is much easier to understand than B := B xor Bitborad_T(Shift_Left(1, i)). I asked my question on the gcc mailing list and the answer was that I should not bother with a bug report. Their point of view, which I can understand, is that since the code generated is correct and this is such a niche feature, nobody will be in any hurry to work on it. They did suggest that I try to fix it myself, and they even pointed me at the file of interest in the gcc source. I barely have free time for my chess program, so I don't think I'll take them up on that any time soon, but if anybody here wants to give it a try, the relevant file is exp_pakd.adb Now, concerning efficiency: these basic operations on bitboards are used 1e8 to 1e9 times every time the program tries to decide what to move next. Even the smallest improvement in speed can mean the difference between searching 10 or 11 ply deep, which can mean an improvement of over 50 Elo points in strength. For Stefan Lucks: I tried both procedure Flip(B : in out Bitboard_T; I : in Index_T) is begin B(I) := B(I) xor True; end; and procedure Flip(B : in out Bitboard_T; I : in Index_T) is One: constant Bitborard := (others => False); begin One(i) := True; B(i) := B(i) xor One; end; The first one results in the same code as the original (B(i) := not B(i)) version, while the second one generates the optimal code, but if I am to explicitly use masks, I might as well go with the Unsigned_64 version. The whole point of using packed arrays is to write easy to read code and let the compiler take care of the masks and shifts behind the scene. For Adam Beneschan: procedure Flip(B : in out Bitboard_T; I : Index_T) is The_Bit : Boolean renames B(I); begin The_Bit := not The_Bit; end; results in the same code as my initial version.