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.4 required=5.0 tests=BAYES_00,FORGED_MUA_MOZILLA autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,7e15102eb14c0020 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.180.84.74 with SMTP id w10mr612066wiy.4.1348954620760; Sat, 29 Sep 2012 14:37:00 -0700 (PDT) Path: q10ni31693062wif.0!nntp.google.com!proxad.net!feeder1-2.proxad.net!newsfeed.straub-nv.de!uucp.gnuu.de!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Sat, 29 Sep 2012 23:36:59 +0200 From: Georg Bauhaus User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:15.0) Gecko/20120907 Thunderbird/15.0.1 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: highest bit, statically determined References: <50673111$0$9505$9b4e6d93@newsspool1.arcor-online.net> In-Reply-To: Message-ID: <506769fb$0$6580$9b4e6d93@newsspool3.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 29 Sep 2012 23:36:59 CEST NNTP-Posting-Host: 1979b18f.newsspool3.arcor-online.net X-Trace: DXC=JUfSEPmEjJmUoRk[hk2WalMcF=Q^Z^V3h4Fo<]lROoRa8kFejVhNH>negGeW]hB7D>oTOoFoh X-Complaints-To: usenet-abuse@arcor.de Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Date: 2012-09-29T23:36:59+02:00 List-Id: On 29.09.12 21:16, Bill Findlay wrote: functionfirst_1_bit :-) > I can now confirm that with GNAT GPL 2012 at -O3 it does inline and fold, > but I now see that you want the result to be static as well as the operand, > and this does not achieve that. Daringly, I have tried to steal the idea and try a comparison (out of curiosity, not for the static thing). GCC performs simple tail call elimination (explaining the Shift parameter)! function First_1_Bit_A (y : octet; Shift : Integer := 0) return Natural is begin if y >= 2**4 then if y >= 2**6 then return Shift + 7 + Boolean'Pos (y >= 2**7); else return Shift + 5 + Boolean'Pos (y >= 2**5); end if; else if Y = 0 then return 0; else return First_1_Bit_A (y * 2**4, Shift => -4); end if; end if; end First_1_Bit_A; Don't know if that's as readily adaptable to other word sizes, but it might make the functionist happier. ;-)