bv-0.5: Bit-vector arithmetic library
Copyright(c) 2012-2016 Iago Abal
(c) 2012-2013 HASLab & University of Minho
LicenseBSD3
MaintainerIago Abal <mail@iagoabal.eu>
Safe HaskellNone
LanguageHaskell98

Data.BitVector

Description

Bit-vector arithmetic inspired by SMT-LIB http://smt-lib.org/ and Cryptol http://cryptol.net/.

Bit-vectors are represented as a pair size and value, where sizes are of type Int and values are Integer.

  • Bit-vectors are interpreted as unsigned integers (i.e. natural numbers) except for some specific signed operations.
  • Most operations are in some way size-polymorphic and, if required, will perform padding to adjust the size of input bit-vectors.

For documentation purposes we will write [n]k to denote a bit-vector of size n representing the natural number k.

Synopsis

Bit-vectors

type BitVector = BV Source #

An alias for BV.

data BV Source #

Big-endian pseudo size-polymorphic bit-vectors.

Instances

Instances details
Monoid BV Source # 
Instance details

Defined in Data.BitVector

Methods

mempty :: BV

mappend :: BV -> BV -> BV

mconcat :: [BV] -> BV

Semigroup BV Source # 
Instance details

Defined in Data.BitVector

Methods

(<>) :: BV -> BV -> BV

sconcat :: NonEmpty BV -> BV

stimes :: Integral b => b -> BV -> BV

Bits BV Source # 
Instance details

Defined in Data.BitVector

Methods

(.&.) :: BV -> BV -> BV #

(.|.) :: BV -> BV -> BV #

xor :: BV -> BV -> BV #

complement :: BV -> BV #

shift :: BV -> Int -> BV #

rotate :: BV -> Int -> BV #

zeroBits :: BV #

bit :: Int -> BV #

setBit :: BV -> Int -> BV #

clearBit :: BV -> Int -> BV #

complementBit :: BV -> Int -> BV #

testBit :: BV -> Int -> Bool #

bitSizeMaybe :: BV -> Maybe Int #

bitSize :: BV -> Int #

isSigned :: BV -> Bool #

shiftL :: BV -> Int -> BV #

unsafeShiftL :: BV -> Int -> BV #

shiftR :: BV -> Int -> BV #

unsafeShiftR :: BV -> Int -> BV #

rotateL :: BV -> Int -> BV #

rotateR :: BV -> Int -> BV #

popCount :: BV -> Int #

Data BV Source # 
Instance details

Defined in Data.BitVector

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> BV -> c BV

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c BV

toConstr :: BV -> Constr

dataTypeOf :: BV -> DataType

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c BV)

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c BV)

gmapT :: (forall b. Data b => b -> b) -> BV -> BV

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> BV -> r

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> BV -> r

gmapQ :: (forall d. Data d => d -> u) -> BV -> [u]

gmapQi :: Int -> (forall d. Data d => d -> u) -> BV -> u

gmapM :: Monad m => (forall d. Data d => d -> m d) -> BV -> m BV

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> BV -> m BV

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> BV -> m BV

Enum BV Source # 
Instance details

Defined in Data.BitVector

Methods

succ :: BV -> BV

pred :: BV -> BV

toEnum :: Int -> BV

fromEnum :: BV -> Int

enumFrom :: BV -> [BV]

enumFromThen :: BV -> BV -> [BV]

enumFromTo :: BV -> BV -> [BV]

enumFromThenTo :: BV -> BV -> BV -> [BV]

Num BV Source # 
Instance details

Defined in Data.BitVector

Methods

(+) :: BV -> BV -> BV

(-) :: BV -> BV -> BV

(*) :: BV -> BV -> BV

negate :: BV -> BV

abs :: BV -> BV

signum :: BV -> BV

fromInteger :: Integer -> BV

Read BV Source # 
Instance details

Defined in Data.BitVector

Methods

readsPrec :: Int -> ReadS BV

readList :: ReadS [BV]

readPrec :: ReadPrec BV

readListPrec :: ReadPrec [BV]

Integral BV Source # 
Instance details

Defined in Data.BitVector

Methods

quot :: BV -> BV -> BV

rem :: BV -> BV -> BV

div :: BV -> BV -> BV

mod :: BV -> BV -> BV

quotRem :: BV -> BV -> (BV, BV)

divMod :: BV -> BV -> (BV, BV)

toInteger :: BV -> Integer

Real BV Source # 
Instance details

Defined in Data.BitVector

Methods

toRational :: BV -> Rational

Show BV Source # 
Instance details

Defined in Data.BitVector

Methods

showsPrec :: Int -> BV -> ShowS

show :: BV -> String

showList :: [BV] -> ShowS

Eq BV Source # 
Instance details

Defined in Data.BitVector

Methods

(==) :: BV -> BV -> Bool

(/=) :: BV -> BV -> Bool

Ord BV Source # 
Instance details

Defined in Data.BitVector

Methods

compare :: BV -> BV -> Ordering

(<) :: BV -> BV -> Bool

(<=) :: BV -> BV -> Bool

(>) :: BV -> BV -> Bool

(>=) :: BV -> BV -> Bool

max :: BV -> BV -> BV

min :: BV -> BV -> BV

size :: BV -> Int Source #

The size of a bit-vector.

width :: BV -> Int Source #

An alias for size.

nat :: BV -> Integer Source #

The value of a bit-vector, as a natural number.

uint :: BV -> Integer Source #

An alias for nat.

int :: BV -> Integer Source #

2's complement value of a bit-vector.

>>> int [2]3
-1
>>> int [4]12
-4

Creation

nil :: BV Source #

The empty bit-vector, ie. [0]0.

bitVec :: Integral a => Int -> a -> BV Source #

Create a bit-vector given a size and an integer value.

>>> bitVec 4 3
[4]3

This function also handles negative values.

>>> bitVec 4 (-1)
[4]15

bitVecs :: Integral a => Int -> [a] -> [BV] Source #

List of bit-vector literals of the same size

When a list of integer literals is interpreted as a list of bit-vectors, fromInteger is applied to each element invidually:

>>> [1,3,5] :: [BV]
[ [1]1, [2]3, [3]5 ]

Sometimes we want to specify a list of bit-vectors literals of the same size, and for that we can use bitVects:

>>> bitVecs 3 [1,3,5]
[ [3]1, [3]3, [3]5 ]

ones :: Int -> BV Source #

Create a mask of ones.

zeros :: Int -> BV Source #

Create a mask of zeros.

Test

isNat :: BV -> Bool Source #

Test if the signed value of a bit-vector is a natural number.

isPos :: BV -> Bool Source #

Test if the signed value of a bit-vector is a positive number.

Comparison

(==.) :: BV -> BV -> Bool infix 4 Source #

Fixed-size equality.

In contrast with ==, which is size-polymorphic, this equality requires both bit-vectors to be of equal size.

>>> [n]k ==. [m]k
False
>>> [n]k ==. [n]k
True

(/=.) :: BV -> BV -> Bool infix 4 Source #

Fixed-size inequality.

The negated version of ==..

(<.) :: BV -> BV -> Bool infix 4 Source #

Fixed-size less-than.

(<=.) :: BV -> BV -> Bool infix 4 Source #

Fixed-size less-than-or-equals.

(>.) :: BV -> BV -> Bool infix 4 Source #

Fixed-size greater-than.

(>=.) :: BV -> BV -> Bool infix 4 Source #

Fixed-size greater-than-or-equals.

slt :: BV -> BV -> Bool infix 4 Source #

Fixed-size signed less-than.

sle :: BV -> BV -> Bool infix 4 Source #

Fixed-size signed less-than-or-equals.

sgt :: BV -> BV -> Bool infix 4 Source #

Fixed-size signed greater-than.

sge :: BV -> BV -> Bool infix 4 Source #

Fixed-size signed greater-than-or-equals.

Indexing

(@.) :: Integral ix => BV -> ix -> Bool infixl 9 Source #

Bit indexing.

u @. i stands for the i-th bit of u.

>>> [4]2 @. 0
False
>>> [4]2 @. 1
True

index :: Integral ix => ix -> BV -> Bool Source #

index i a == a @. i

(@@) :: Integral ix => BV -> (ix, ix) -> BV infixl 9 Source #

Bit-string extraction.

u @@ (j,i) == fromBits (map (u @.) [j,j-1..i])
>>> [4]7 @@ (3,1)
[3]3

extract :: Integral ix => ix -> ix -> BV -> BV Source #

extract j i a == a @@ (j,i)

(@:) :: Integral ix => BV -> [ix] -> BV infixl 9 Source #

Bit list indexing.

u @: is ==. fromBits $ List.map (u @.) is

(!.) :: Integral ix => BV -> ix -> Bool infixl 9 Source #

Reverse bit-indexing.

Index starting from the most significant bit.

u !. i == u @. (size u - i - 1)
>>> [3]3 !. 0
False

least :: Integral ix => ix -> BV -> BV Source #

Take least significant bits.

least m u == u @@ (m-1,0)

most :: Integral ix => ix -> BV -> BV Source #

Take most significant bits.

most m u == u @@ (n-1,n-m)

msb :: BV -> Bool Source #

Most significant bit.

msb u == u !. 0

lsb :: BV -> Bool Source #

Least significant bit.

lsb u == u @. 0

msb1 :: BV -> Int Source #

Most significant 1-bit.

Pre: input must be non-zero.

>>> msb1 [4]2
1
>>> msb1 [4]4
2

lsb1 :: BV -> Int Source #

Least significant 1-bit.

Pre: input must be non-zero.

>>> msb1 [4]3
0
>>> msb1 [4]6
1

Arithmetic

signumI :: Integral a => BV -> a Source #

Bit-vector signum as an Integral.

pow :: Integral exp => BV -> exp -> BV Source #

Bit-vector exponentiation.

pow [n]k e computes k raised to e modulo n.

This is faster than Haskell's (^) operator because it performs modulo division just once. Besides, a^0 == [1]0 !!!

sdiv :: BV -> BV -> BV Source #

2's complement signed division.

srem :: BV -> BV -> BV Source #

2's complement signed remainder (sign follows dividend).

smod :: BV -> BV -> BV Source #

2's complement signed remainder (sign follows divisor).

lg2 :: BV -> BV Source #

Ceiling logarithm base 2.

Pre: input bit-vector must be non-zero.

List-like operations

(#) :: BV -> BV -> BV infixr 5 Source #

Concatenation of two bit-vectors.

cat :: BV -> BV -> BV Source #

Deprecated: Use (#) or append instead

Concatenation of two bit-vectors.

append :: BV -> BV -> BV Source #

Concatenation of two bit-vectors.

concat :: [BV] -> BV Source #

An alias for join.

zeroExtend :: Integral size => size -> BV -> BV Source #

Logical extension.

>>> zeroExtend 3 [1]1
[4]1

signExtend :: Integral size => size -> BV -> BV Source #

Arithmetic extension.

>>> signExtend 2 [2]1
[4]1
>>> signExtend 2 [2]3
[4]15

foldl :: (a -> Bool -> a) -> a -> BV -> a Source #

foldl f z (fromBits [un, ..., u1, u0]) == ((((z `f` un) `f` ...) `f` u1) `f` u0)
foldl f e = fromBits . foldl f e . toBits

foldl_ :: (a -> Bool -> a) -> a -> BV -> a Source #

Deprecated: Use corresponding versions without underscore

foldl f z (fromBits [un, ..., u1, u0]) == ((((z `f` un) `f` ...) `f` u1) `f` u0)
foldl f e = fromBits . foldl f e . toBits

foldr :: (Bool -> a -> a) -> a -> BV -> a Source #

foldr f z (fromBits [un, ..., u1, u0]) == un `f` (... `f` (u1 `f` (u0 `f` z)))
foldr f e = fromBits . foldr f e . toBits

foldr_ :: (Bool -> a -> a) -> a -> BV -> a Source #

Deprecated: Use corresponding versions without underscore

foldr f z (fromBits [un, ..., u1, u0]) == un `f` (... `f` (u1 `f` (u0 `f` z)))
foldr f e = fromBits . foldr f e . toBits

reverse :: BV -> BV Source #

reverse == fromBits . reverse . toBits

reverse_ :: BV -> BV Source #

Deprecated: Use corresponding versions without underscore

reverse == fromBits . reverse . toBits

replicate :: Integral size => size -> BV -> BV Source #

Pre: if replicate_ n u then n > 0 must hold.

replicate_ n == fromBits . concat . replicate n . toBits

replicate_ :: Integral size => size -> BV -> BV Source #

Deprecated: Use corresponding versions without underscore

Pre: if replicate_ n u then n > 0 must hold.

replicate_ n == fromBits . concat . replicate n . toBits

and :: [BV] -> BV Source #

Conjunction.

Essentially, and == foldr1 (.&.).

Returns [1]1 if the input list is empty.

and_ :: [BV] -> BV Source #

Deprecated: Use corresponding versions without underscore

Conjunction.

Essentially, and == foldr1 (.&.).

Returns [1]1 if the input list is empty.

or :: [BV] -> BV Source #

Disjunction.

Essentially, or == foldr1 (.|.).

Returns [1]0 if the input list is empty.

or_ :: [BV] -> BV Source #

Deprecated: Use corresponding versions without underscore

Disjunction.

Essentially, or == foldr1 (.|.).

Returns [1]0 if the input list is empty.

split :: Integral times => times -> BV -> [BV] Source #

Split a bit-vector k times.

>>> split 3 [4]15
[[2]0,[2]3,[2]3]

group :: Integral size => size -> BV -> [BV] Source #

Split a bit-vector into n-wide pieces.

>>> group 3 [4]15
[[3]1,[3]7]

group_ :: Integral size => size -> BV -> [BV] Source #

Deprecated: Use corresponding versions without underscore

Split a bit-vector into n-wide pieces.

>>> group 3 [4]15
[[3]1,[3]7]

join :: [BV] -> BV Source #

Concatenate a (possibly empty) list of bit-vectors.

>>> join [[2]3,[2]2]
[4]14

Bitwise operations

class Eq a => Bits a where #

Methods

(.&.) :: a -> a -> a #

(.|.) :: a -> a -> a #

xor :: a -> a -> a #

complement :: a -> a #

shift :: a -> Int -> a #

rotate :: a -> Int -> a #

zeroBits :: a #

bit :: Int -> a #

setBit :: a -> Int -> a #

clearBit :: a -> Int -> a #

complementBit :: a -> Int -> a #

testBit :: a -> Int -> Bool #

bitSizeMaybe :: a -> Maybe Int #

bitSize :: a -> Int #

isSigned :: a -> Bool #

shiftL :: a -> Int -> a #

unsafeShiftL :: a -> Int -> a #

shiftR :: a -> Int -> a #

unsafeShiftR :: a -> Int -> a #

rotateL :: a -> Int -> a #

rotateR :: a -> Int -> a #

popCount :: a -> Int #

Instances

Instances details
Bits BV Source # 
Instance details

Defined in Data.BitVector

Methods

(.&.) :: BV -> BV -> BV #

(.|.) :: BV -> BV -> BV #

xor :: BV -> BV -> BV #

complement :: BV -> BV #

shift :: BV -> Int -> BV #

rotate :: BV -> Int -> BV #

zeroBits :: BV #

bit :: Int -> BV #

setBit :: BV -> Int -> BV #

clearBit :: BV -> Int -> BV #

complementBit :: BV -> Int -> BV #

testBit :: BV -> Int -> Bool #

bitSizeMaybe :: BV -> Maybe Int #

bitSize :: BV -> Int #

isSigned :: BV -> Bool #

shiftL :: BV -> Int -> BV #

unsafeShiftL :: BV -> Int -> BV #

shiftR :: BV -> Int -> BV #

unsafeShiftR :: BV -> Int -> BV #

rotateL :: BV -> Int -> BV #

rotateR :: BV -> Int -> BV #

popCount :: BV -> Int #

Bits Integer 
Instance details

Defined in GHC.Internal.Bits

Methods

(.&.) :: Integer -> Integer -> Integer #

(.|.) :: Integer -> Integer -> Integer #

xor :: Integer -> Integer -> Integer #

complement :: Integer -> Integer #

shift :: Integer -> Int -> Integer #

rotate :: Integer -> Int -> Integer #

zeroBits :: Integer #

bit :: Int -> Integer #

setBit :: Integer -> Int -> Integer #

clearBit :: Integer -> Int -> Integer #

complementBit :: Integer -> Int -> Integer #

testBit :: Integer -> Int -> Bool #

bitSizeMaybe :: Integer -> Maybe Int #

bitSize :: Integer -> Int #

isSigned :: Integer -> Bool #

shiftL :: Integer -> Int -> Integer #

unsafeShiftL :: Integer -> Int -> Integer #

shiftR :: Integer -> Int -> Integer #

unsafeShiftR :: Integer -> Int -> Integer #

rotateL :: Integer -> Int -> Integer #

rotateR :: Integer -> Int -> Integer #

popCount :: Integer -> Int #

Bits Natural 
Instance details

Defined in GHC.Internal.Bits

Methods

(.&.) :: Natural -> Natural -> Natural #

(.|.) :: Natural -> Natural -> Natural #

xor :: Natural -> Natural -> Natural #

complement :: Natural -> Natural #

shift :: Natural -> Int -> Natural #

rotate :: Natural -> Int -> Natural #

zeroBits :: Natural #

bit :: Int -> Natural #

setBit :: Natural -> Int -> Natural #

clearBit :: Natural -> Int -> Natural #

complementBit :: Natural -> Int -> Natural #

testBit :: Natural -> Int -> Bool #

bitSizeMaybe :: Natural -> Maybe Int #

bitSize :: Natural -> Int #

isSigned :: Natural -> Bool #

shiftL :: Natural -> Int -> Natural #

unsafeShiftL :: Natural -> Int -> Natural #

shiftR :: Natural -> Int -> Natural #

unsafeShiftR :: Natural -> Int -> Natural #

rotateL :: Natural -> Int -> Natural #

rotateR :: Natural -> Int -> Natural #

popCount :: Natural -> Int #

Bits Bool 
Instance details

Defined in GHC.Internal.Bits

Methods

(.&.) :: Bool -> Bool -> Bool #

(.|.) :: Bool -> Bool -> Bool #

xor :: Bool -> Bool -> Bool #

complement :: Bool -> Bool #

shift :: Bool -> Int -> Bool #

rotate :: Bool -> Int -> Bool #

zeroBits :: Bool #

bit :: Int -> Bool #

setBit :: Bool -> Int -> Bool #

clearBit :: Bool -> Int -> Bool #

complementBit :: Bool -> Int -> Bool #

testBit :: Bool -> Int -> Bool #

bitSizeMaybe :: Bool -> Maybe Int #

bitSize :: Bool -> Int #

isSigned :: Bool -> Bool #

shiftL :: Bool -> Int -> Bool #

unsafeShiftL :: Bool -> Int -> Bool #

shiftR :: Bool -> Int -> Bool #

unsafeShiftR :: Bool -> Int -> Bool #

rotateL :: Bool -> Int -> Bool #

rotateR :: Bool -> Int -> Bool #

popCount :: Bool -> Int #

Bits Int 
Instance details

Defined in GHC.Internal.Bits

Methods

(.&.) :: Int -> Int -> Int #

(.|.) :: Int -> Int -> Int #

xor :: Int -> Int -> Int #

complement :: Int -> Int #

shift :: Int -> Int -> Int #

rotate :: Int -> Int -> Int #

zeroBits :: Int #

bit :: Int -> Int #

setBit :: Int -> Int -> Int #

clearBit :: Int -> Int -> Int #

complementBit :: Int -> Int -> Int #

testBit :: Int -> Int -> Bool #

bitSizeMaybe :: Int -> Maybe Int #

bitSize :: Int -> Int #

isSigned :: Int -> Bool #

shiftL :: Int -> Int -> Int #

unsafeShiftL :: Int -> Int -> Int #

shiftR :: Int -> Int -> Int #

unsafeShiftR :: Int -> Int -> Int #

rotateL :: Int -> Int -> Int #

rotateR :: Int -> Int -> Int #

popCount :: Int -> Int #

Bits Word 
Instance details

Defined in GHC.Internal.Bits

Methods

(.&.) :: Word -> Word -> Word #

(.|.) :: Word -> Word -> Word #

xor :: Word -> Word -> Word #

complement :: Word -> Word #

shift :: Word -> Int -> Word #

rotate :: Word -> Int -> Word #

zeroBits :: Word #

bit :: Int -> Word #

setBit :: Word -> Int -> Word #

clearBit :: Word -> Int -> Word #

complementBit :: Word -> Int -> Word #

testBit :: Word -> Int -> Bool #

bitSizeMaybe :: Word -> Maybe Int #

bitSize :: Word -> Int #

isSigned :: Word -> Bool #

shiftL :: Word -> Int -> Word #

unsafeShiftL :: Word -> Int -> Word #

shiftR :: Word -> Int -> Word #

unsafeShiftR :: Word -> Int -> Word #

rotateL :: Word -> Int -> Word #

rotateR :: Word -> Int -> Word #

popCount :: Word -> Int #

Bits a => Bits (And a) 
Instance details

Defined in GHC.Internal.Data.Bits

Methods

(.&.) :: And a -> And a -> And a #

(.|.) :: And a -> And a -> And a #

xor :: And a -> And a -> And a #

complement :: And a -> And a #

shift :: And a -> Int -> And a #

rotate :: And a -> Int -> And a #

zeroBits :: And a #

bit :: Int -> And a #

setBit :: And a -> Int -> And a #

clearBit :: And a -> Int -> And a #

complementBit :: And a -> Int -> And a #

testBit :: And a -> Int -> Bool #

bitSizeMaybe :: And a -> Maybe Int #

bitSize :: And a -> Int #

isSigned :: And a -> Bool #

shiftL :: And a -> Int -> And a #

unsafeShiftL :: And a -> Int -> And a #

shiftR :: And a -> Int -> And a #

unsafeShiftR :: And a -> Int -> And a #

rotateL :: And a -> Int -> And a #

rotateR :: And a -> Int -> And a #

popCount :: And a -> Int #

Bits a => Bits (Iff a) 
Instance details

Defined in GHC.Internal.Data.Bits

Methods

(.&.) :: Iff a -> Iff a -> Iff a #

(.|.) :: Iff a -> Iff a -> Iff a #

xor :: Iff a -> Iff a -> Iff a #

complement :: Iff a -> Iff a #

shift :: Iff a -> Int -> Iff a #

rotate :: Iff a -> Int -> Iff a #

zeroBits :: Iff a #

bit :: Int -> Iff a #

setBit :: Iff a -> Int -> Iff a #

clearBit :: Iff a -> Int -> Iff a #

complementBit :: Iff a -> Int -> Iff a #

testBit :: Iff a -> Int -> Bool #

bitSizeMaybe :: Iff a -> Maybe Int #

bitSize :: Iff a -> Int #

isSigned :: Iff a -> Bool #

shiftL :: Iff a -> Int -> Iff a #

unsafeShiftL :: Iff a -> Int -> Iff a #

shiftR :: Iff a -> Int -> Iff a #

unsafeShiftR :: Iff a -> Int -> Iff a #

rotateL :: Iff a -> Int -> Iff a #

rotateR :: Iff a -> Int -> Iff a #

popCount :: Iff a -> Int #

Bits a => Bits (Ior a) 
Instance details

Defined in GHC.Internal.Data.Bits

Methods

(.&.) :: Ior a -> Ior a -> Ior a #

(.|.) :: Ior a -> Ior a -> Ior a #

xor :: Ior a -> Ior a -> Ior a #

complement :: Ior a -> Ior a #

shift :: Ior a -> Int -> Ior a #

rotate :: Ior a -> Int -> Ior a #

zeroBits :: Ior a #

bit :: Int -> Ior a #

setBit :: Ior a -> Int -> Ior a #

clearBit :: Ior a -> Int -> Ior a #

complementBit :: Ior a -> Int -> Ior a #

testBit :: Ior a -> Int -> Bool #

bitSizeMaybe :: Ior a -> Maybe Int #

bitSize :: Ior a -> Int #

isSigned :: Ior a -> Bool #

shiftL :: Ior a -> Int -> Ior a #

unsafeShiftL :: Ior a -> Int -> Ior a #

shiftR :: Ior a -> Int -> Ior a #

unsafeShiftR :: Ior a -> Int -> Ior a #

rotateL :: Ior a -> Int -> Ior a #

rotateR :: Ior a -> Int -> Ior a #

popCount :: Ior a -> Int #

Bits a => Bits (Xor a) 
Instance details

Defined in GHC.Internal.Data.Bits

Methods

(.&.) :: Xor a -> Xor a -> Xor a #

(.|.) :: Xor a -> Xor a -> Xor a #

xor :: Xor a -> Xor a -> Xor a #

complement :: Xor a -> Xor a #

shift :: Xor a -> Int -> Xor a #

rotate :: Xor a -> Int -> Xor a #

zeroBits :: Xor a #

bit :: Int -> Xor a #

setBit :: Xor a -> Int -> Xor a #

clearBit :: Xor a -> Int -> Xor a #

complementBit :: Xor a -> Int -> Xor a #

testBit :: Xor a -> Int -> Bool #

bitSizeMaybe :: Xor a -> Maybe Int #

bitSize :: Xor a -> Int #

isSigned :: Xor a -> Bool #

shiftL :: Xor a -> Int -> Xor a #

unsafeShiftL :: Xor a -> Int -> Xor a #

shiftR :: Xor a -> Int -> Xor a #

unsafeShiftR :: Xor a -> Int -> Xor a #

rotateL :: Xor a -> Int -> Xor a #

rotateR :: Xor a -> Int -> Xor a #

popCount :: Xor a -> Int #

Bits a => Bits (Down a) 
Instance details

Defined in GHC.Internal.Data.Ord

Methods

(.&.) :: Down a -> Down a -> Down a #

(.|.) :: Down a -> Down a -> Down a #

xor :: Down a -> Down a -> Down a #

complement :: Down a -> Down a #

shift :: Down a -> Int -> Down a #

rotate :: Down a -> Int -> Down a #

zeroBits :: Down a #

bit :: Int -> Down a #

setBit :: Down a -> Int -> Down a #

clearBit :: Down a -> Int -> Down a #

complementBit :: Down a -> Int -> Down a #

testBit :: Down a -> Int -> Bool #

bitSizeMaybe :: Down a -> Maybe Int #

bitSize :: Down a -> Int #

isSigned :: Down a -> Bool #

shiftL :: Down a -> Int -> Down a #

unsafeShiftL :: Down a -> Int -> Down a #

shiftR :: Down a -> Int -> Down a #

unsafeShiftR :: Down a -> Int -> Down a #

rotateL :: Down a -> Int -> Down a #

rotateR :: Down a -> Int -> Down a #

popCount :: Down a -> Int #

bitDefault :: (Bits a, Num a) => Int -> a #

popCountDefault :: (Bits a, Num a) => a -> Int #

testBitDefault :: (Bits a, Num a) => a -> Int -> Bool #

toIntegralSized :: (Integral a, Integral b, Bits a, Bits b) => a -> Maybe b #

(!<<.) :: Bits a => a -> Int -> a #

(!>>.) :: Bits a => a -> Int -> a #

(.<<.) :: Bits a => a -> Int -> a #

(.>>.) :: Bits a => a -> Int -> a #

(.^.) :: Bits a => a -> a -> a #

oneBits :: FiniteBits a => a #

class Bits b => FiniteBits b where #

Minimal complete definition

finiteBitSize

Methods

finiteBitSize :: b -> Int #

countLeadingZeros :: b -> Int #

countTrailingZeros :: b -> Int #

Instances

Instances details
FiniteBits Bool 
Instance details

Defined in GHC.Internal.Bits

Methods

finiteBitSize :: Bool -> Int #

countLeadingZeros :: Bool -> Int #

countTrailingZeros :: Bool -> Int #

FiniteBits Int 
Instance details

Defined in GHC.Internal.Bits

Methods

finiteBitSize :: Int -> Int #

countLeadingZeros :: Int -> Int #

countTrailingZeros :: Int -> Int #

FiniteBits Word 
Instance details

Defined in GHC.Internal.Bits

Methods

finiteBitSize :: Word -> Int #

countLeadingZeros :: Word -> Int #

countTrailingZeros :: Word -> Int #

FiniteBits a => FiniteBits (And a) 
Instance details

Defined in GHC.Internal.Data.Bits

Methods

finiteBitSize :: And a -> Int #

countLeadingZeros :: And a -> Int #

countTrailingZeros :: And a -> Int #

FiniteBits a => FiniteBits (Iff a) 
Instance details

Defined in GHC.Internal.Data.Bits

Methods

finiteBitSize :: Iff a -> Int #

countLeadingZeros :: Iff a -> Int #

countTrailingZeros :: Iff a -> Int #

FiniteBits a => FiniteBits (Ior a) 
Instance details

Defined in GHC.Internal.Data.Bits

Methods

finiteBitSize :: Ior a -> Int #

countLeadingZeros :: Ior a -> Int #

countTrailingZeros :: Ior a -> Int #

FiniteBits a => FiniteBits (Xor a) 
Instance details

Defined in GHC.Internal.Data.Bits

Methods

finiteBitSize :: Xor a -> Int #

countLeadingZeros :: Xor a -> Int #

countTrailingZeros :: Xor a -> Int #

FiniteBits a => FiniteBits (Down a) 
Instance details

Defined in GHC.Internal.Data.Ord

Methods

finiteBitSize :: Down a -> Int #

countLeadingZeros :: Down a -> Int #

countTrailingZeros :: Down a -> Int #

newtype And a #

Constructors

And 

Fields

Instances

Instances details
FiniteBits a => Monoid (And a) 
Instance details

Defined in GHC.Internal.Data.Bits

Methods

mempty :: And a

mappend :: And a -> And a -> And a

mconcat :: [And a] -> And a

Bits a => Semigroup (And a) 
Instance details

Defined in GHC.Internal.Data.Bits

Methods

(<>) :: And a -> And a -> And a

sconcat :: NonEmpty (And a) -> And a

stimes :: Integral b => b -> And a -> And a

Bits a => Bits (And a) 
Instance details

Defined in GHC.Internal.Data.Bits

Methods

(.&.) :: And a -> And a -> And a #

(.|.) :: And a -> And a -> And a #

xor :: And a -> And a -> And a #

complement :: And a -> And a #

shift :: And a -> Int -> And a #

rotate :: And a -> Int -> And a #

zeroBits :: And a #

bit :: Int -> And a #

setBit :: And a -> Int -> And a #

clearBit :: And a -> Int -> And a #

complementBit :: And a -> Int -> And a #

testBit :: And a -> Int -> Bool #

bitSizeMaybe :: And a -> Maybe Int #

bitSize :: And a -> Int #

isSigned :: And a -> Bool #

shiftL :: And a -> Int -> And a #

unsafeShiftL :: And a -> Int -> And a #

shiftR :: And a -> Int -> And a #

unsafeShiftR :: And a -> Int -> And a #

rotateL :: And a -> Int -> And a #

rotateR :: And a -> Int -> And a #

popCount :: And a -> Int #

FiniteBits a => FiniteBits (And a) 
Instance details

Defined in GHC.Internal.Data.Bits

Methods

finiteBitSize :: And a -> Int #

countLeadingZeros :: And a -> Int #

countTrailingZeros :: And a -> Int #

Bounded a => Bounded (And a) 
Instance details

Defined in GHC.Internal.Data.Bits

Methods

minBound :: And a

maxBound :: And a

Enum a => Enum (And a) 
Instance details

Defined in GHC.Internal.Data.Bits

Methods

succ :: And a -> And a

pred :: And a -> And a

toEnum :: Int -> And a

fromEnum :: And a -> Int

enumFrom :: And a -> [And a]

enumFromThen :: And a -> And a -> [And a]

enumFromTo :: And a -> And a -> [And a]

enumFromThenTo :: And a -> And a -> And a -> [And a]

Read a => Read (And a) 
Instance details

Defined in GHC.Internal.Data.Bits

Methods

readsPrec :: Int -> ReadS (And a)

readList :: ReadS [And a]

readPrec :: ReadPrec (And a)

readListPrec :: ReadPrec [And a]

Show a => Show (And a) 
Instance details

Defined in GHC.Internal.Data.Bits

Methods

showsPrec :: Int -> And a -> ShowS

show :: And a -> String

showList :: [And a] -> ShowS

Eq a => Eq (And a) 
Instance details

Defined in GHC.Internal.Data.Bits

Methods

(==) :: And a -> And a -> Bool

(/=) :: And a -> And a -> Bool

newtype Iff a #

Constructors

Iff 

Fields

Instances

Instances details
FiniteBits a => Monoid (Iff a) 
Instance details

Defined in GHC.Internal.Data.Bits

Methods

mempty :: Iff a

mappend :: Iff a -> Iff a -> Iff a

mconcat :: [Iff a] -> Iff a

FiniteBits a => Semigroup (Iff a) 
Instance details

Defined in GHC.Internal.Data.Bits

Methods

(<>) :: Iff a -> Iff a -> Iff a

sconcat :: NonEmpty (Iff a) -> Iff a

stimes :: Integral b => b -> Iff a -> Iff a

Bits a => Bits (Iff a) 
Instance details

Defined in GHC.Internal.Data.Bits

Methods

(.&.) :: Iff a -> Iff a -> Iff a #

(.|.) :: Iff a -> Iff a -> Iff a #

xor :: Iff a -> Iff a -> Iff a #

complement :: Iff a -> Iff a #

shift :: Iff a -> Int -> Iff a #

rotate :: Iff a -> Int -> Iff a #

zeroBits :: Iff a #

bit :: Int -> Iff a #

setBit :: Iff a -> Int -> Iff a #

clearBit :: Iff a -> Int -> Iff a #

complementBit :: Iff a -> Int -> Iff a #

testBit :: Iff a -> Int -> Bool #

bitSizeMaybe :: Iff a -> Maybe Int #

bitSize :: Iff a -> Int #

isSigned :: Iff a -> Bool #

shiftL :: Iff a -> Int -> Iff a #

unsafeShiftL :: Iff a -> Int -> Iff a #

shiftR :: Iff a -> Int -> Iff a #

unsafeShiftR :: Iff a -> Int -> Iff a #

rotateL :: Iff a -> Int -> Iff a #

rotateR :: Iff a -> Int -> Iff a #

popCount :: Iff a -> Int #

FiniteBits a => FiniteBits (Iff a) 
Instance details

Defined in GHC.Internal.Data.Bits

Methods

finiteBitSize :: Iff a -> Int #

countLeadingZeros :: Iff a -> Int #

countTrailingZeros :: Iff a -> Int #

Bounded a => Bounded (Iff a) 
Instance details

Defined in GHC.Internal.Data.Bits

Methods

minBound :: Iff a

maxBound :: Iff a

Enum a => Enum (Iff a) 
Instance details

Defined in GHC.Internal.Data.Bits

Methods

succ :: Iff a -> Iff a

pred :: Iff a -> Iff a

toEnum :: Int -> Iff a

fromEnum :: Iff a -> Int

enumFrom :: Iff a -> [Iff a]

enumFromThen :: Iff a -> Iff a -> [Iff a]

enumFromTo :: Iff a -> Iff a -> [Iff a]

enumFromThenTo :: Iff a -> Iff a -> Iff a -> [Iff a]

Read a => Read (Iff a) 
Instance details

Defined in GHC.Internal.Data.Bits

Methods

readsPrec :: Int -> ReadS (Iff a)

readList :: ReadS [Iff a]

readPrec :: ReadPrec (Iff a)

readListPrec :: ReadPrec [Iff a]

Show a => Show (Iff a) 
Instance details

Defined in GHC.Internal.Data.Bits

Methods

showsPrec :: Int -> Iff a -> ShowS

show :: Iff a -> String

showList :: [Iff a] -> ShowS

Eq a => Eq (Iff a) 
Instance details

Defined in GHC.Internal.Data.Bits

Methods

(==) :: Iff a -> Iff a -> Bool

(/=) :: Iff a -> Iff a -> Bool

newtype Ior a #

Constructors

Ior 

Fields

Instances

Instances details
Bits a => Monoid (Ior a) 
Instance details

Defined in GHC.Internal.Data.Bits

Methods

mempty :: Ior a

mappend :: Ior a -> Ior a -> Ior a

mconcat :: [Ior a] -> Ior a

Bits a => Semigroup (Ior a) 
Instance details

Defined in GHC.Internal.Data.Bits

Methods

(<>) :: Ior a -> Ior a -> Ior a

sconcat :: NonEmpty (Ior a) -> Ior a

stimes :: Integral b => b -> Ior a -> Ior a

Bits a => Bits (Ior a) 
Instance details

Defined in GHC.Internal.Data.Bits

Methods

(.&.) :: Ior a -> Ior a -> Ior a #

(.|.) :: Ior a -> Ior a -> Ior a #

xor :: Ior a -> Ior a -> Ior a #

complement :: Ior a -> Ior a #

shift :: Ior a -> Int -> Ior a #

rotate :: Ior a -> Int -> Ior a #

zeroBits :: Ior a #

bit :: Int -> Ior a #

setBit :: Ior a -> Int -> Ior a #

clearBit :: Ior a -> Int -> Ior a #

complementBit :: Ior a -> Int -> Ior a #

testBit :: Ior a -> Int -> Bool #

bitSizeMaybe :: Ior a -> Maybe Int #

bitSize :: Ior a -> Int #

isSigned :: Ior a -> Bool #

shiftL :: Ior a -> Int -> Ior a #

unsafeShiftL :: Ior a -> Int -> Ior a #

shiftR :: Ior a -> Int -> Ior a #

unsafeShiftR :: Ior a -> Int -> Ior a #

rotateL :: Ior a -> Int -> Ior a #

rotateR :: Ior a -> Int -> Ior a #

popCount :: Ior a -> Int #

FiniteBits a => FiniteBits (Ior a) 
Instance details

Defined in GHC.Internal.Data.Bits

Methods

finiteBitSize :: Ior a -> Int #

countLeadingZeros :: Ior a -> Int #

countTrailingZeros :: Ior a -> Int #

Bounded a => Bounded (Ior a) 
Instance details

Defined in GHC.Internal.Data.Bits

Methods

minBound :: Ior a

maxBound :: Ior a

Enum a => Enum (Ior a) 
Instance details

Defined in GHC.Internal.Data.Bits

Methods

succ :: Ior a -> Ior a

pred :: Ior a -> Ior a

toEnum :: Int -> Ior a

fromEnum :: Ior a -> Int

enumFrom :: Ior a -> [Ior a]

enumFromThen :: Ior a -> Ior a -> [Ior a]

enumFromTo :: Ior a -> Ior a -> [Ior a]

enumFromThenTo :: Ior a -> Ior a -> Ior a -> [Ior a]

Read a => Read (Ior a) 
Instance details

Defined in GHC.Internal.Data.Bits

Methods

readsPrec :: Int -> ReadS (Ior a)

readList :: ReadS [Ior a]

readPrec :: ReadPrec (Ior a)

readListPrec :: ReadPrec [Ior a]

Show a => Show (Ior a) 
Instance details

Defined in GHC.Internal.Data.Bits

Methods

showsPrec :: Int -> Ior a -> ShowS

show :: Ior a -> String

showList :: [Ior a] -> ShowS

Eq a => Eq (Ior a) 
Instance details

Defined in GHC.Internal.Data.Bits

Methods

(==) :: Ior a -> Ior a -> Bool

(/=) :: Ior a -> Ior a -> Bool

newtype Xor a #

Constructors

Xor 

Fields

Instances

Instances details
Bits a => Monoid (Xor a) 
Instance details

Defined in GHC.Internal.Data.Bits

Methods

mempty :: Xor a

mappend :: Xor a -> Xor a -> Xor a

mconcat :: [Xor a] -> Xor a

Bits a => Semigroup (Xor a) 
Instance details

Defined in GHC.Internal.Data.Bits

Methods

(<>) :: Xor a -> Xor a -> Xor a

sconcat :: NonEmpty (Xor a) -> Xor a

stimes :: Integral b => b -> Xor a -> Xor a

Bits a => Bits (Xor a) 
Instance details

Defined in GHC.Internal.Data.Bits

Methods

(.&.) :: Xor a -> Xor a -> Xor a #

(.|.) :: Xor a -> Xor a -> Xor a #

xor :: Xor a -> Xor a -> Xor a #

complement :: Xor a -> Xor a #

shift :: Xor a -> Int -> Xor a #

rotate :: Xor a -> Int -> Xor a #

zeroBits :: Xor a #

bit :: Int -> Xor a #

setBit :: Xor a -> Int -> Xor a #

clearBit :: Xor a -> Int -> Xor a #

complementBit :: Xor a -> Int -> Xor a #

testBit :: Xor a -> Int -> Bool #

bitSizeMaybe :: Xor a -> Maybe Int #

bitSize :: Xor a -> Int #

isSigned :: Xor a -> Bool #

shiftL :: Xor a -> Int -> Xor a #

unsafeShiftL :: Xor a -> Int -> Xor a #

shiftR :: Xor a -> Int -> Xor a #

unsafeShiftR :: Xor a -> Int -> Xor a #

rotateL :: Xor a -> Int -> Xor a #

rotateR :: Xor a -> Int -> Xor a #

popCount :: Xor a -> Int #

FiniteBits a => FiniteBits (Xor a) 
Instance details

Defined in GHC.Internal.Data.Bits

Methods

finiteBitSize :: Xor a -> Int #

countLeadingZeros :: Xor a -> Int #

countTrailingZeros :: Xor a -> Int #

Bounded a => Bounded (Xor a) 
Instance details

Defined in GHC.Internal.Data.Bits

Methods

minBound :: Xor a

maxBound :: Xor a

Enum a => Enum (Xor a) 
Instance details

Defined in GHC.Internal.Data.Bits

Methods

succ :: Xor a -> Xor a

pred :: Xor a -> Xor a

toEnum :: Int -> Xor a

fromEnum :: Xor a -> Int

enumFrom :: Xor a -> [Xor a]

enumFromThen :: Xor a -> Xor a -> [Xor a]

enumFromTo :: Xor a -> Xor a -> [Xor a]

enumFromThenTo :: Xor a -> Xor a -> Xor a -> [Xor a]

Read a => Read (Xor a) 
Instance details

Defined in GHC.Internal.Data.Bits

Methods

readsPrec :: Int -> ReadS (Xor a)

readList :: ReadS [Xor a]

readPrec :: ReadPrec (Xor a)

readListPrec :: ReadPrec [Xor a]

Show a => Show (Xor a) 
Instance details

Defined in GHC.Internal.Data.Bits

Methods

showsPrec :: Int -> Xor a -> ShowS

show :: Xor a -> String

showList :: [Xor a] -> ShowS

Eq a => Eq (Xor a) 
Instance details

Defined in GHC.Internal.Data.Bits

Methods

(==) :: Xor a -> Xor a -> Bool

(/=) :: Xor a -> Xor a -> Bool

not :: BV -> BV Source #

An alias for complement.

not_ :: BV -> BV Source #

Deprecated: Use corresponding versions without underscore

An alias for complement.

nand :: BV -> BV -> BV Source #

Negated .&..

nor :: BV -> BV -> BV Source #

Negated .|..

xnor :: BV -> BV -> BV Source #

Negated xor.

(<<.) :: BV -> BV -> BV infixl 8 Source #

Left shift.

shl :: BV -> BV -> BV infixl 8 Source #

Left shift.

(>>.) :: BV -> BV -> BV infixl 8 Source #

Logical right shift.

shr :: BV -> BV -> BV infixl 8 Source #

Logical right shift.

ashr :: BV -> BV -> BV infixl 8 Source #

Arithmetic right shift

(<<<.) :: BV -> BV -> BV infixl 8 Source #

Rotate left.

rol :: BV -> BV -> BV infixl 8 Source #

Rotate left.

(>>>.) :: BV -> BV -> BV infixl 8 Source #

Rotate right.

ror :: BV -> BV -> BV infixl 8 Source #

Rotate right.

Conversion

fromBool :: Bool -> BV Source #

Create a bit-vector from a single bit.

fromBits :: [Bool] -> BV Source #

Create a bit-vector from a big-endian list of bits.

>>> fromBits [False, False, True]
[3]1

toBits :: BV -> [Bool] Source #

Create a big-endian list of bits from a bit-vector.

>>> toBits [4]11
[True, False, True, True]

Pretty-printing

showBin :: BV -> String Source #

Show a bit-vector in binary form.

showOct :: BV -> String Source #

Show a bit-vector in octal form.

showHex :: BV -> String Source #

Show a bit-vector in hexadecimal form.