We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ca3406c commit 0e0ac14Copy full SHA for 0e0ac14
Utils/Containers/Internal/BitUtil.hs
@@ -39,7 +39,11 @@ module Utils.Containers.Internal.BitUtil
39
) where
40
41
import Data.Bits ((.|.), xor)
42
-import Data.Bits (popCount, unsafeShiftL, unsafeShiftR)
+import Data.Bits (popCount, unsafeShiftL, unsafeShiftR
43
+#if MIN_VERSION_base(4,8,0)
44
+ , countLeadingZeros
45
+#endif
46
+ )
47
#if MIN_VERSION_base(4,7,0)
48
import Data.Bits (finiteBitSize)
49
#else
@@ -72,6 +76,9 @@ bitcount a x = a + popCount x
72
76
73
77
-- | Return a word where only the highest bit is set.
74
78
highestBitMask :: Word -> Word
79
80
+highestBitMask w = shiftLL 1 (wordSize - 1 - countLeadingZeros w)
81
+#else
75
82
highestBitMask x1 = let x2 = x1 .|. x1 `shiftRL` 1
83
x3 = x2 .|. x2 `shiftRL` 2
84
x4 = x3 .|. x3 `shiftRL` 4
@@ -83,6 +90,7 @@ highestBitMask x1 = let x2 = x1 .|. x1 `shiftRL` 1
90
91
in x6 `xor` (x6 `shiftRL` 1)
85
92
#endif
93
86
94
{-# INLINE highestBitMask #-}
87
95
88
96
-- Right and left logical shifts.
0 commit comments