Skip to content

Commit 5c55234

Browse files
Bodigrimharendra-kumar
authored andcommitted
Fix x32 build
1 parent 19aec48 commit 5c55234

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

Data/Unicode/Internal/Bits.hs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
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)
1921
import 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
2931
lookupBit64 :: Addr# -> Int -> Bool
3032
lookupBit64 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

Comments
 (0)