@@ -21,26 +21,32 @@ import GHC.Prim (Int#, (/=#), (>=#), (<#), (-#),
2121import GHC.Integer.GMP.PrimExt (popCountInteger #, testBitInteger #,
2222 setBitInteger #, clearBitInteger #)
2323
24+ #if __GLASGOW_HASKELL__ >= 707
25+ import GHC.Exts (isTrue #)
26+ #else
27+ isTrue# = id
28+ #endif
29+
2430popCountInteger :: Integer -> Int #
2531popCountInteger (S # i) = word2Int# (popCnt# (int2Word# i))
2632popCountInteger (J # s d) = popCountInteger# s d
2733{-# NOINLINE popCountInteger #-}
2834
2935testBitInteger :: Integer -> Int # -> Bool
3036testBitInteger (S # j) i
31- | i <# 0 # = False
32- | i <# (WORD_SIZE_IN_BITS # -# 1 # ) =
37+ | isTrue # ( i <# 0 # ) = False
38+ | isTrue # ( i <# (WORD_SIZE_IN_BITS # -# 1 # ) ) =
3339 let ! mask = 1 # `uncheckedIShiftL# ` i in
34- word2Int# (int2Word# j `and # ` int2Word# mask) /=# 0 #
40+ isTrue # ( word2Int# (int2Word# j `and # ` int2Word# mask) /=# 0 # )
3541 | otherwise =
3642 let ! (# s, d # ) = int2Integer# j in testBitInteger (J # s d) i
37- testBitInteger (J # s d) i = testBitInteger# s d i /=# 0 #
43+ testBitInteger (J # s d) i = isTrue # ( testBitInteger# s d i /=# 0 # )
3844{-# NOINLINE testBitInteger #-}
3945
4046setBitInteger :: Integer -> Int # -> Integer
4147setBitInteger (S # j) i
42- | i <# 0 # = S # j
43- | i <# (WORD_SIZE_IN_BITS # -# 1 # ) =
48+ | isTrue # ( i <# 0 # ) = S # j
49+ | isTrue # ( i <# (WORD_SIZE_IN_BITS # -# 1 # ) ) =
4450 let ! mask = 1 # `uncheckedIShiftL# ` i in
4551 S # (word2Int# (int2Word# j `or # ` int2Word# mask))
4652 | otherwise =
@@ -51,12 +57,12 @@ setBitInteger (J# s d) i =
5157
5258clearBitInteger :: Integer -> Int # -> Integer
5359clearBitInteger (S # j) i
54- | i <# 0 # || i >=# (WORD_SIZE_IN_BITS # -# 1 # ) = S # j
60+ | isTrue # ( i <# 0 # ) || isTrue # ( i >=# (WORD_SIZE_IN_BITS # -# 1 # ) ) = S # j
5561 | otherwise =
5662 let ! mask =
5763 int2Word# (1 # `uncheckedIShiftL# ` i) `xor# `
5864 int2Word# (negateInt# 1 # )
5965 in S # (word2Int# (int2Word# j `and # ` mask))
6066clearBitInteger (J # s d) i =
6167 let ! (# s', d' # ) = clearBitInteger# s d i in J # s' d'
62- {-# NOINLINE clearBitInteger #-}
68+ {-# NOINLINE clearBitInteger #-}
0 commit comments