ivory-0.1.0.8: Safe embedded C programming.

Safe HaskellNone
LanguageHaskell2010

Ivory.Language.Bits

Synopsis

Documentation

bitOp :: forall a. IvoryExpr a => ExpOp -> a -> a -> a Source #

class (Num a, IvoryExpr a) => IvoryBits a where Source #

Minimal complete definition

iBitSize

Methods

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

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

(.^) :: a -> a -> a Source #

iComplement :: a -> a Source #

iBitSize :: a -> Int Source #

iShiftL :: a -> a -> a Source #

iShiftR :: a -> a -> a Source #

class (IvoryBits a, IvoryBits b) => BitSplit a b | a -> b where Source #

Extraction of the upper or lower half of a bit type into the next smallest bit type.

Minimal complete definition

ubits, lbits

Methods

ubits :: a -> b Source #

lbits :: a -> b Source #

Instances
BitSplit Uint64 Uint32 Source # 
Instance details

Defined in Ivory.Language.Bits

BitSplit Uint32 Uint16 Source # 
Instance details

Defined in Ivory.Language.Bits

BitSplit Uint16 Uint8 Source # 
Instance details

Defined in Ivory.Language.Bits

class (IvoryBits a, IvoryBits b) => BitCast a b where Source #

A narrowing cast from one bit type to another. This explicitly discards the upper bits of the input value to return a smaller type, and is only defined for unsigned integers.

Minimal complete definition

bitCast

Methods

bitCast :: a -> b Source #

Instances
BitCast Uint64 Uint64 Source # 
Instance details

Defined in Ivory.Language.Bits

BitCast Uint64 Uint32 Source # 
Instance details

Defined in Ivory.Language.Bits

BitCast Uint64 Uint16 Source # 
Instance details

Defined in Ivory.Language.Bits

BitCast Uint64 Uint8 Source # 
Instance details

Defined in Ivory.Language.Bits

Methods

bitCast :: Uint64 -> Uint8 Source #

BitCast Uint32 Uint32 Source # 
Instance details

Defined in Ivory.Language.Bits

BitCast Uint32 Uint16 Source # 
Instance details

Defined in Ivory.Language.Bits

BitCast Uint32 Uint8 Source # 
Instance details

Defined in Ivory.Language.Bits

Methods

bitCast :: Uint32 -> Uint8 Source #

BitCast Uint16 Uint16 Source # 
Instance details

Defined in Ivory.Language.Bits

BitCast Uint16 Uint8 Source # 
Instance details

Defined in Ivory.Language.Bits

Methods

bitCast :: Uint16 -> Uint8 Source #

BitCast Uint8 Uint8 Source # 
Instance details

Defined in Ivory.Language.Bits

Methods

bitCast :: Uint8 -> Uint8 Source #

class (IvoryBits unsigned, IvoryEq unsigned, IvoryExpr signed, Num signed, IvoryIntegral unsigned, Bounded unsigned, Bounded signed, IvoryOrd signed) => TwosComplementCast unsigned signed | signed -> unsigned, unsigned -> signed where Source #

Re-interpret the bits of an unsigned integer as though they were a signed number in two's complement representation.

Methods

twosComplementCast :: unsigned -> signed Source #

twosComplementRep :: signed -> unsigned Source #

extractByte :: BitCast a Uint8 => a -> (Uint8, a) Source #

Extract the least significant byte from an integer. This returns the two values (x & 0xFF, x >> 8), with the first value safely casted to an 8-bit integer.

This is convenient to use with a state monad and "sets", such as:

fst $ runState x $ do
  a <- sets extractByte
  b <- sets extractByte
  return (a, b)