Safe Haskell | None |
---|---|

Language | Haskell2010 |

## Synopsis

- bitOp :: forall a. IvoryExpr a => ExpOp -> a -> a -> a
- class (Num a, IvoryExpr a) => IvoryBits a where
- class (IvoryBits a, IvoryBits b) => BitSplit a b | a -> b where
- class (IvoryBits a, IvoryBits b) => BitCast a b where
- bitCast :: a -> b

- 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
- twosComplementCast :: unsigned -> signed
- twosComplementRep :: signed -> unsigned

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

# Documentation

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

## Instances

IvoryBits Uint64 Source # | |

Defined in Ivory.Language.Bits | |

IvoryBits Uint32 Source # | |

Defined in Ivory.Language.Bits | |

IvoryBits Uint16 Source # | |

Defined in Ivory.Language.Bits | |

IvoryBits Uint8 Source # | |

Defined in Ivory.Language.Bits |

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.

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.

## Instances

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.

Nothing

twosComplementCast :: unsigned -> signed Source #

twosComplementRep :: signed -> unsigned Source #

## Instances

TwosComplementCast Uint64 Sint64 Source # | |

Defined in Ivory.Language.Bits twosComplementCast :: Uint64 -> Sint64 Source # twosComplementRep :: Sint64 -> Uint64 Source # | |

TwosComplementCast Uint32 Sint32 Source # | |

Defined in Ivory.Language.Bits twosComplementCast :: Uint32 -> Sint32 Source # twosComplementRep :: Sint32 -> Uint32 Source # | |

TwosComplementCast Uint16 Sint16 Source # | |

Defined in Ivory.Language.Bits twosComplementCast :: Uint16 -> Sint16 Source # twosComplementRep :: Sint16 -> Uint16 Source # | |

TwosComplementCast Uint8 Sint8 Source # | |

Defined in Ivory.Language.Bits twosComplementCast :: Uint8 -> Sint8 Source # twosComplementRep :: Sint8 -> Uint8 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)