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,FREEMAIL_FROM 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!o61g2000hsh.googlegroups.com!not-for-mail From: gautier_niouzes@hotmail.com Newsgroups: comp.lang.ada Subject: Re: sub-optimal code for packed boolean arrays -- bug or inherent limitation Date: Tue, 03 Jul 2007 00:59:19 -0700 Organization: http://groups.google.com Message-ID: <1183449559.774375.229380@o61g2000hsh.googlegroups.com> References: <1183404856.375083.160890@q69g2000hsb.googlegroups.com> NNTP-Posting-Host: 206.122.158.4 Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-Trace: posting.google.com 1183449560 20746 127.0.0.1 (3 Jul 2007 07:59:20 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 3 Jul 2007 07:59:20 +0000 (UTC) In-Reply-To: <1183404856.375083.160890@q69g2000hsb.googlegroups.com> User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 1.1.4322; InfoPath.1),gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: o61g2000hsh.googlegroups.com; posting-host=206.122.158.4; posting-account=CZAoAgwAAAD9ntJQ85OlWL0_Q5EFdzP_ Xref: g2news1.google.com comp.lang.ada:16391 Date: 2007-07-03T00:59:19-07:00 List-Id: ... > The only notable exception is procedure Flip, which becomes > > procedure Flip(B : in out Bitboard_T; I : in Index_T) is > 30: 89 f1 mov %esi,%ecx > begin > B(i) := not B(i); > 32: 48 c7 c0 fe ff ff ff mov $0xfffffffffffffffe,%rax > 39: 48 d3 c0 rol %cl,%rax > 3c: 48 21 f8 and %rdi,%rax > 3f: 48 d3 ef shr %cl,%rdi > 42: 83 f7 01 xor $0x1,%edi > 45: 83 e7 01 and $0x1,%edi > 48: 48 d3 e7 shl %cl,%rdi > 4b: 48 09 f8 or %rdi,%rax > end; > 4e: c3 retq > > instead of the shorter > > mov %esi, %ecx > mov 0x1, %rax > shl %cl, %rax > xor % rax, %rdx > retq > > I don't know much (if anything) about compiler internals, so I was > wondering if I should file a bug report. Is there some good > theoretical justification for all that extraneous shifts and > rotations? I would think that if the compiler can figure out the best > way to set or clear a bit in a register using shift and logical ops, > than it should also be able to negate it efficiently. Did you time both codes ? Often a much shorter code is not faster at all. BTW, you can also do assembler insertions with Ada (although it would be a pity if you had to). G.