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,7e15102eb14c0020 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.180.73.242 with SMTP id o18mr656323wiv.0.1348961914166; Sat, 29 Sep 2012 16:38:34 -0700 (PDT) Path: q11ni101783571wiw.1!nntp.google.com!proxad.net!feeder1-2.proxad.net!usenet-fr.net!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Bill Findlay Newsgroups: comp.lang.ada Subject: Re: highest bit, statically determined Date: Sun, 30 Sep 2012 00:38:33 +0100 Message-ID: References: <50673111$0$9505$9b4e6d93@newsspool1.arcor-online.net> <506769fb$0$6580$9b4e6d93@newsspool3.arcor-online.net> Mime-Version: 1.0 X-Trace: individual.net DkdX5JFZTB7t0Dvs4Ru5QwB0P6UObM1Hs4s4gIDeeLzByH6WdwjyJwchytsI4tKb2I Cancel-Lock: sha1:3z4mjy5RmDnOLfM1qR17KJ0L4OY= User-Agent: Microsoft-Entourage/12.33.0.120411 Thread-Topic: highest bit, statically determined Thread-Index: Ac2em4mkqBEDwgxuD0OB3T08LniBFA== Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Date: 2012-09-30T00:38:33+01:00 List-Id: On 29/09/2012 22:36, in article 506769fb$0$6580$9b4e6d93@newsspool3.arcor-online.net, "Georg Bauhaus" wrote: > 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; These bogus parameters, used to pretend that data is not intrinsically variable, are as objectionable as using goto statements to synthesize while loops, IMNSHO. > Don't know if that's as readily adaptable to other word sizes, but it might > make the functionist happier. ;-) Fortunately, I have no interest in keeping functionists (or the adherents of any other religion) happy. 8-) -- Bill Findlay with blueyonder.co.uk; use surname & forename;