Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module provides misc. utilities for bitwhacking that are useful in dealing with low-level details of the Cap'N Proto wire format.
This is mostly an implementation detail; users are unlikely to need to use this module directly.
Synopsis
- newtype BitCount = BitCount Int
- newtype ByteCount = ByteCount Int
- newtype WordCount = WordCount Int
- newtype Word1 = Word1 {
- word1ToBool :: Bool
- bitsToBytesCeil :: BitCount -> ByteCount
- bytesToWordsCeil :: ByteCount -> WordCount
- bytesToWordsFloor :: ByteCount -> WordCount
- wordsToBytes :: WordCount -> ByteCount
- lo :: Word64 -> Word32
- hi :: Word64 -> Word32
- i32 :: Word32 -> Int32
- i30 :: Word32 -> Int32
- i29 :: Word32 -> Int32
- fromLo :: Word32 -> Word64
- fromHi :: Word32 -> Word64
- fromI32 :: Int32 -> Word32
- fromI30 :: Int32 -> Word32
- fromI29 :: Int32 -> Word32
- bitRange :: Integral a => Word64 -> Int -> Int -> a
- replaceBits :: (Bounded a, Integral a) => a -> Word64 -> Int -> Word64
Documentation
Wrapper type for a quantity of bits. This along with ByteCount
and
WordCount
are helpful for avoiding mixing up units
Instances
A quantity of bytes
Instances
A quantity of 64-bit words
Instances
1 bit datatype, in the tradition of Word8, Word16 et al.
Word1 | |
|
Instances
Bounded Word1 Source # | |
Enum Word1 Source # | |
Eq Word1 Source # | |
Integral Word1 Source # | |
Num Word1 Source # | |
Ord Word1 Source # | |
Real Word1 Source # | |
Defined in Data.Capnp.Bits toRational :: Word1 -> Rational # | |
Show Word1 Source # | |
Bits Word1 Source # | |
Defined in Data.Capnp.Bits (.&.) :: Word1 -> Word1 -> Word1 # (.|.) :: Word1 -> Word1 -> Word1 # xor :: Word1 -> Word1 -> Word1 # complement :: Word1 -> Word1 # shift :: Word1 -> Int -> Word1 # rotate :: Word1 -> Int -> Word1 # setBit :: Word1 -> Int -> Word1 # clearBit :: Word1 -> Int -> Word1 # complementBit :: Word1 -> Int -> Word1 # testBit :: Word1 -> Int -> Bool # bitSizeMaybe :: Word1 -> Maybe Int # shiftL :: Word1 -> Int -> Word1 # unsafeShiftL :: Word1 -> Int -> Word1 # shiftR :: Word1 -> Int -> Word1 # unsafeShiftR :: Word1 -> Int -> Word1 # rotateL :: Word1 -> Int -> Word1 # | |
IsWord Word1 Source # | |
bitsToBytesCeil :: BitCount -> ByteCount Source #
Convert bits to bytes. Rounds up.
bytesToWordsCeil :: ByteCount -> WordCount Source #
Convert bytes to words. Rounds up.
bytesToWordsFloor :: ByteCount -> WordCount Source #
Convert bytes to words. Rounds down.
wordsToBytes :: WordCount -> ByteCount Source #
Convert words to bytes.
lo :: Word64 -> Word32 Source #
lo and hi extract the low and high 32 bits of a 64-bit word, respectively.
hi :: Word64 -> Word32 Source #
lo and hi extract the low and high 32 bits of a 64-bit word, respectively.
i32 :: Word32 -> Int32 Source #
iN (where N is 32, 30, or 29) extracts the high N bits of its argument, and treats them as a signed 32-bit integer.
i30 :: Word32 -> Int32 Source #
iN (where N is 32, 30, or 29) extracts the high N bits of its argument, and treats them as a signed 32-bit integer.
i29 :: Word32 -> Int32 Source #
iN (where N is 32, 30, or 29) extracts the high N bits of its argument, and treats them as a signed 32-bit integer.
fromLo :: Word32 -> Word64 Source #
fromLo and fromHi convert a 32-bit word to the low or high portion of
a 64-bit word. In general, fromHi (hi w) .|. fromLo (lo w) == w
.
fromHi :: Word32 -> Word64 Source #
fromLo and fromHi convert a 32-bit word to the low or high portion of
a 64-bit word. In general, fromHi (hi w) .|. fromLo (lo w) == w
.
fromI32 :: Int32 -> Word32 Source #
fromIN (where N is 32, 30, or 29) treats its argument as the high N bits of
a 32-bit word, returning the word. If w < 2 ** N
then fromIN (iN w) == w
.
fromI30 :: Int32 -> Word32 Source #
fromIN (where N is 32, 30, or 29) treats its argument as the high N bits of
a 32-bit word, returning the word. If w < 2 ** N
then fromIN (iN w) == w
.
fromI29 :: Int32 -> Word32 Source #
fromIN (where N is 32, 30, or 29) treats its argument as the high N bits of
a 32-bit word, returning the word. If w < 2 ** N
then fromIN (iN w) == w
.