aboutsummaryrefslogtreecommitdiffstats
path: root/src/mutils.adb
blob: 1b40bff791216d5b8bb4d8f6847c9508cf9b85a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package body Mutils is
   function Clog2 (V : Uns64) return Integer
   is
      Low : Natural;
   begin
      if V >= 2**16 then
         if V >= 2**32 then
            Low := 32;
         else
            Low := 16;
         end if;
      else
         if V >= 2**8 then
            Low := 8;
         else
            Low := 0;
         end if;
      end if;
      for I in Low .. 63 loop
         if 2**I >= V then
            return I;
         end if;
      end loop;
      return 64;
   end Clog2;

end Mutils;