diff options
-rw-r--r-- | src/mutils.adb | 27 | ||||
-rw-r--r-- | src/mutils.ads | 7 |
2 files changed, 34 insertions, 0 deletions
diff --git a/src/mutils.adb b/src/mutils.adb new file mode 100644 index 000000000..1b40bff79 --- /dev/null +++ b/src/mutils.adb @@ -0,0 +1,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; diff --git a/src/mutils.ads b/src/mutils.ads new file mode 100644 index 000000000..4275fe6c0 --- /dev/null +++ b/src/mutils.ads @@ -0,0 +1,7 @@ +with Types; use Types; + +package Mutils is + -- Return the ceiling log2 of V. + -- Returns 0 for 0. + function Clog2 (V : Uns64) return Integer; +end Mutils; |