comp.lang.ada
 help / color / mirror / Atom feed
From: Vadim Godunko <vgodunko@gmail.com>
Subject: Re: highest bit, statically determined
Date: Sun, 30 Sep 2012 08:01:54 -0700 (PDT)
Date: 2012-09-30T08:01:54-07:00	[thread overview]
Message-ID: <b81d4661-16cc-4f09-a6f5-82c68f5c0bef@googlegroups.com> (raw)
In-Reply-To: <506769fb$0$6580$9b4e6d93@newsspool3.arcor-online.net>

On Sunday, September 30, 2012 1:37:00 AM UTC+4, Georg Bauhaus wrote:
> 
> 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)!
> 
If you don't need static function, you can use following function (GCC can precompute its result for static value):

with Interfaces.C; use Interfaces.C;

function Bit (X : Unsigned) return Unsigned;
pragma Inline (Bit);

function Bit (X : Unsigned) return Unsigned is

   function CLZ (X : Unsigned) return Unsigned;
   pragma Import (Intrinsic, CLZ, "__builtin_clz");

begin
   if X = 0 then
      --  XXX Return what you want.

      return 0;

   else
      return Unsigned'Size - CLZ (X);
   end if;
end Bit;



  parent reply	other threads:[~2012-09-30 15:01 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-29 17:34 highest bit, statically determined Georg Bauhaus
2012-09-29 18:11 ` Pascal Obry
2012-09-29 18:59   ` Georg Bauhaus
2012-09-29 19:18     ` Georg Bauhaus
2012-09-29 18:57 ` Bill Findlay
2012-09-29 19:16   ` Bill Findlay
2012-09-29 21:36     ` Georg Bauhaus
2012-09-29 22:06       ` Georg Bauhaus
2012-09-29 23:38       ` Bill Findlay
2012-09-30 15:01       ` Vadim Godunko [this message]
2012-11-04 20:45     ` Yannick Duchêne (Hibou57)
2012-11-04 22:00       ` Bill Findlay
2012-09-30 15:39 ` Anatoly Chernyshev
2012-09-30 18:36   ` Shark8
2012-10-01  8:07   ` Georg Bauhaus
2012-10-01  8:11     ` Georg Bauhaus
2012-10-01  8:52     ` Anatoly Chernyshev
2012-10-01 21:30       ` Georg Bauhaus
2012-10-01 22:55         ` Shark8
2012-10-01 23:25           ` Georg Bauhaus
2012-10-02 11:03         ` Brian Drummond
2012-10-03  9:30           ` kalvink65
2012-10-03 18:54             ` Georg Bauhaus
2012-10-04  7:46               ` Georg Bauhaus
2012-10-04  8:25           ` Stephen Leake
2012-10-04 10:01       ` kalvin.news
2012-10-05  7:50         ` Anatoly Chernyshev
2012-10-05  8:38           ` Anatoly Chernyshev
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox