Copyright  (C) 20132016 University of Twente 2020 Myrtle Software Ltd 

License  BSD2 (see the file LICENSE) 
Maintainer  QBayLogic B.V. <devops@qbaylogic.com> 
Safe Haskell  Safe 
Language  Haskell2010 
Extensions 

Synopsis
 class Resize (f :: Nat > Type) where
 checkedResize :: forall a b f. (HasCallStack, Resize f, KnownNat a, Integral (f a), KnownNat b, Integral (f b), Bounded (f b)) => f a > f b
 checkedFromIntegral :: forall a b. HasCallStack => (Integral a, Integral b, Bounded b) => a > b
 checkedTruncateB :: forall a b f. (HasCallStack, Resize f, KnownNat b, Integral (f (a + b)), KnownNat a, Integral (f a), Bounded (f a)) => f (a + b) > f a
Documentation
class Resize (f :: Nat > Type) where Source #
Coerce a value to be represented by a different number of bits
resize :: (KnownNat a, KnownNat b) => f a > f b Source #
A signpreserving resize operation
 For signed datatypes: Increasing the size of the number replicates the sign bit to the left. Truncating a number to length L keeps the sign bit and the rightmost L1 bits.
 For unsigned datatypes: Increasing the size of the number extends with zeros to the left. Truncating a number of length N to a length L just removes the left (most significant) NL bits.
extend :: (KnownNat a, KnownNat b) => f a > f (b + a) Source #
Perform a zeroExtend
for unsigned datatypes, and signExtend
for a
signed datatypes
zeroExtend :: (KnownNat a, KnownNat b) => f a > f (b + a) Source #
Add extra zero bits in front of the MSB
signExtend :: (KnownNat a, KnownNat b) => f a > f (b + a) Source #
Add extra sign bits in front of the MSB
truncateB :: KnownNat a => f (a + b) > f a Source #
Remove bits from the MSB
Instances
Resize helpers
checkedResize :: forall a b f. (HasCallStack, Resize f, KnownNat a, Integral (f a), KnownNat b, Integral (f b), Bounded (f b)) => f a > f b Source #
Like resize
, but errors if f a is out of bounds for f b. Useful when
you "know" f a can't be out of bounds, but would like to have your
assumptions checked.
N.B.: Check only affects simulation. I.e., no checks will be inserted into the generated HDL
checkedFromIntegral :: forall a b. HasCallStack => (Integral a, Integral b, Bounded b) => a > b Source #
Like fromIntegral
, but errors if a is out of bounds for b. Useful when
you "know" a can't be out of bounds, but would like to have your assumptions
checked.
 NB: Check only affects simulation. I.e., no checks will be inserted into the generated HDL
 NB:
fromIntegral
is not well suited for Clash as it will go throughInteger
which is arbitrarily bounded in HDL. Instead usebitCoerce
and theResize
class.
checkedTruncateB :: forall a b f. (HasCallStack, Resize f, KnownNat b, Integral (f (a + b)), KnownNat a, Integral (f a), Bounded (f a)) => f (a + b) > f a Source #
Like truncateB
, but errors if f (a + b) is out of bounds for f a. Useful
when you "know" f (a + b) can't be out of bounds, but would like to have your
assumptions checked.
N.B.: Check only affects simulation. I.e., no checks will be inserted into the generated HDL