{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE MagicHash #-}
module Data.Unicode.Internal.Bits
(
lookupBit64
) where
import Data.Bits (finiteBitSize, popCount)
import GHC.Exts
(Addr#, Int(..), Word(..), indexWordOffAddr#, and#, andI#,
uncheckedIShiftRL#, uncheckedShiftL#)
lookupBit64 :: Addr# -> Int -> Bool
lookupBit64 :: Addr# -> Int -> Bool
lookupBit64 addr# :: Addr#
addr# (I# index# :: Int#
index#) = Word# -> Word
W# (Word#
word## Word# -> Word# -> Word#
`and#` Word#
bitMask##) Word -> Word -> Bool
forall a. Eq a => a -> a -> Bool
/= 0
where
!fbs :: Int
fbs@(I# fbs# :: Int#
fbs#) = Word -> Int
forall b. FiniteBits b => b -> Int
finiteBitSize (0 :: Word) Int -> Int -> Int
forall a. Num a => a -> a -> a
- 1
!(I# logFbs# :: Int#
logFbs#) = case Int
fbs of
31 -> 5
63 -> 6
_ -> Int -> Int
forall a. Bits a => a -> Int
popCount Int
fbs
wordIndex# :: Int#
wordIndex# = Int#
index# Int# -> Int# -> Int#
`uncheckedIShiftRL#` Int#
logFbs#
word## :: Word#
word## = Addr# -> Int# -> Word#
indexWordOffAddr# Addr#
addr# Int#
wordIndex#
bitIndex# :: Int#
bitIndex# = Int#
index# Int# -> Int# -> Int#
`andI#` Int#
fbs#
bitMask## :: Word#
bitMask## = 1## Word# -> Int# -> Word#
`uncheckedShiftL#` Int#
bitIndex#