1+ {-# LANGUAGE BangPatterns #-}
12{-# LANGUAGE MagicHash #-}
23-- |
34-- Module : Data.Unicode.Internal.Bits
@@ -16,8 +17,9 @@ module Data.Unicode.Internal.Bits
1617 lookupBit64
1718 ) where
1819
20+ import Data.Bits (finiteBitSize , popCount )
1921import GHC.Exts
20- (Addr #, Int (.. ), Word (.. ), indexWord64OffAddr #, and #, andI #,
22+ (Addr #, Int (.. ), Word (.. ), indexWordOffAddr #, and #, andI #,
2123 uncheckedIShiftRL #, uncheckedShiftL #)
2224
2325-- | @lookup64 addr index@ looks up the bit stored at bit index @index@ using a
@@ -29,7 +31,13 @@ import GHC.Exts
2931lookupBit64 :: Addr # -> Int -> Bool
3032lookupBit64 addr# (I # index# ) = W # (word## `and # ` bitMask## ) /= 0
3133 where
32- wordIndex# = index# `uncheckedIShiftRL# ` 6 #
33- word## = indexWord64OffAddr# addr# wordIndex#
34- bitIndex# = index# `andI# ` 63 #
34+ ! fbs@ (I # fbs# ) = finiteBitSize (0 :: Word ) - 1
35+ ! (I # logFbs# ) = case fbs of
36+ 31 -> 5
37+ 63 -> 6
38+ _ -> popCount fbs -- this is a really weird architecture
39+
40+ wordIndex# = index# `uncheckedIShiftRL# ` logFbs#
41+ word## = indexWordOffAddr# addr# wordIndex#
42+ bitIndex# = index# `andI# ` fbs#
3543 bitMask## = 1 ## `uncheckedShiftL# ` bitIndex#
0 commit comments