| Copyright | (C) 2013-2016 University of Twente 2020 Myrtle Software Ltd 2024 QBayLogic B.V. |
|---|---|
| License | BSD2 (see the file LICENSE) |
| Maintainer | QBayLogic B.V. <devops@qbaylogic.com> |
| Safe Haskell | Safe |
| Language | Haskell2010 |
| Extensions |
|
Clash.Class.Resize
Contents
Description
Synopsis
- class Resize (f :: Nat -> Type) where
- resize :: forall (a :: Nat) (b :: Nat). (KnownNat a, KnownNat b) => f a -> f b
- extend :: forall (a :: Nat) (b :: Nat). (KnownNat a, KnownNat b) => f a -> f (b + a)
- zeroExtend :: forall (a :: Nat) (b :: Nat). (KnownNat a, KnownNat b) => f a -> f (b + a)
- signExtend :: forall (a :: Nat) (b :: Nat). (KnownNat a, KnownNat b) => f a -> f (b + a)
- truncateB :: forall (a :: Nat) (b :: Natural). KnownNat a => f (a + b) -> f a
- checkedResize :: forall (a :: Nat) (b :: Nat) f. (HasCallStack, Resize f, KnownNat a, Integral (f a), KnownNat b, Integral (f b), Bounded (f b)) => f a -> f b
- checkedFromIntegral :: (HasCallStack, Integral a, Integral b, Bounded b) => a -> b
- checkedTruncateB :: forall (a :: Natural) (b :: Nat) 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
Minimal complete definition
Methods
resize :: forall (a :: Nat) (b :: Nat). (KnownNat a, KnownNat b) => f a -> f b Source #
A sign-preserving 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 L-1 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) N-L bits.
extend :: forall (a :: Nat) (b :: Nat). (KnownNat a, KnownNat b) => f a -> f (b + a) Source #
Perform a zeroExtend for unsigned datatypes, and signExtend for a
signed datatypes
zeroExtend :: forall (a :: Nat) (b :: Nat). (KnownNat a, KnownNat b) => f a -> f (b + a) Source #
Add extra zero bits in front of the MSB
signExtend :: forall (a :: Nat) (b :: Nat). (KnownNat a, KnownNat b) => f a -> f (b + a) Source #
Add extra sign bits in front of the MSB
truncateB :: forall (a :: Nat) (b :: Natural). KnownNat a => f (a + b) -> f a Source #
Remove bits from the MSB
Instances
| Resize BitVector Source # | |
Defined in Clash.Sized.Internal.BitVector Methods resize :: forall (a :: Nat) (b :: Nat). (KnownNat a, KnownNat b) => BitVector a -> BitVector b Source # extend :: forall (a :: Nat) (b :: Nat). (KnownNat a, KnownNat b) => BitVector a -> BitVector (b + a) Source # zeroExtend :: forall (a :: Nat) (b :: Nat). (KnownNat a, KnownNat b) => BitVector a -> BitVector (b + a) Source # signExtend :: forall (a :: Nat) (b :: Nat). (KnownNat a, KnownNat b) => BitVector a -> BitVector (b + a) Source # truncateB :: forall (a :: Nat) (b :: Natural). KnownNat a => BitVector (a + b) -> BitVector a Source # | |
| Resize Index Source # | |
Defined in Clash.Sized.Internal.Index Methods resize :: forall (a :: Nat) (b :: Nat). (KnownNat a, KnownNat b) => Index a -> Index b Source # extend :: forall (a :: Nat) (b :: Nat). (KnownNat a, KnownNat b) => Index a -> Index (b + a) Source # zeroExtend :: forall (a :: Nat) (b :: Nat). (KnownNat a, KnownNat b) => Index a -> Index (b + a) Source # signExtend :: forall (a :: Nat) (b :: Nat). (KnownNat a, KnownNat b) => Index a -> Index (b + a) Source # truncateB :: forall (a :: Nat) (b :: Natural). KnownNat a => Index (a + b) -> Index a Source # | |
| Resize Signed Source # | |
Defined in Clash.Sized.Internal.Signed Methods resize :: forall (a :: Nat) (b :: Nat). (KnownNat a, KnownNat b) => Signed a -> Signed b Source # extend :: forall (a :: Nat) (b :: Nat). (KnownNat a, KnownNat b) => Signed a -> Signed (b + a) Source # zeroExtend :: forall (a :: Nat) (b :: Nat). (KnownNat a, KnownNat b) => Signed a -> Signed (b + a) Source # signExtend :: forall (a :: Nat) (b :: Nat). (KnownNat a, KnownNat b) => Signed a -> Signed (b + a) Source # truncateB :: forall (a :: Nat) (b :: Natural). KnownNat a => Signed (a + b) -> Signed a Source # | |
| Resize Unsigned Source # | |
Defined in Clash.Sized.Internal.Unsigned Methods resize :: forall (a :: Nat) (b :: Nat). (KnownNat a, KnownNat b) => Unsigned a -> Unsigned b Source # extend :: forall (a :: Nat) (b :: Nat). (KnownNat a, KnownNat b) => Unsigned a -> Unsigned (b + a) Source # zeroExtend :: forall (a :: Nat) (b :: Nat). (KnownNat a, KnownNat b) => Unsigned a -> Unsigned (b + a) Source # signExtend :: forall (a :: Nat) (b :: Nat). (KnownNat a, KnownNat b) => Unsigned a -> Unsigned (b + a) Source # truncateB :: forall (a :: Nat) (b :: Natural). KnownNat a => Unsigned (a + b) -> Unsigned a Source # | |
| Resize f => Resize (Compose Erroring f) Source # | |
Defined in Clash.Num.Erroring Methods resize :: forall (a :: Nat) (b :: Nat). (KnownNat a, KnownNat b) => Compose Erroring f a -> Compose Erroring f b Source # extend :: forall (a :: Nat) (b :: Nat). (KnownNat a, KnownNat b) => Compose Erroring f a -> Compose Erroring f (b + a) Source # zeroExtend :: forall (a :: Nat) (b :: Nat). (KnownNat a, KnownNat b) => Compose Erroring f a -> Compose Erroring f (b + a) Source # signExtend :: forall (a :: Nat) (b :: Nat). (KnownNat a, KnownNat b) => Compose Erroring f a -> Compose Erroring f (b + a) Source # truncateB :: forall (a :: Nat) (b :: Natural). KnownNat a => Compose Erroring f (a + b) -> Compose Erroring f a Source # | |
| Resize f => Resize (Compose Saturating f) Source # | |
Defined in Clash.Num.Saturating Methods resize :: forall (a :: Nat) (b :: Nat). (KnownNat a, KnownNat b) => Compose Saturating f a -> Compose Saturating f b Source # extend :: forall (a :: Nat) (b :: Nat). (KnownNat a, KnownNat b) => Compose Saturating f a -> Compose Saturating f (b + a) Source # zeroExtend :: forall (a :: Nat) (b :: Nat). (KnownNat a, KnownNat b) => Compose Saturating f a -> Compose Saturating f (b + a) Source # signExtend :: forall (a :: Nat) (b :: Nat). (KnownNat a, KnownNat b) => Compose Saturating f a -> Compose Saturating f (b + a) Source # truncateB :: forall (a :: Nat) (b :: Natural). KnownNat a => Compose Saturating f (a + b) -> Compose Saturating f a Source # | |
| Resize f => Resize (Compose Wrapping f) Source # | |
Defined in Clash.Num.Wrapping Methods resize :: forall (a :: Nat) (b :: Nat). (KnownNat a, KnownNat b) => Compose Wrapping f a -> Compose Wrapping f b Source # extend :: forall (a :: Nat) (b :: Nat). (KnownNat a, KnownNat b) => Compose Wrapping f a -> Compose Wrapping f (b + a) Source # zeroExtend :: forall (a :: Nat) (b :: Nat). (KnownNat a, KnownNat b) => Compose Wrapping f a -> Compose Wrapping f (b + a) Source # signExtend :: forall (a :: Nat) (b :: Nat). (KnownNat a, KnownNat b) => Compose Wrapping f a -> Compose Wrapping f (b + a) Source # truncateB :: forall (a :: Nat) (b :: Natural). KnownNat a => Compose Wrapping f (a + b) -> Compose Wrapping f a Source # | |
| Resize f => Resize (Compose Zeroing f) Source # | |
Defined in Clash.Num.Zeroing Methods resize :: forall (a :: Nat) (b :: Nat). (KnownNat a, KnownNat b) => Compose Zeroing f a -> Compose Zeroing f b Source # extend :: forall (a :: Nat) (b :: Nat). (KnownNat a, KnownNat b) => Compose Zeroing f a -> Compose Zeroing f (b + a) Source # zeroExtend :: forall (a :: Nat) (b :: Nat). (KnownNat a, KnownNat b) => Compose Zeroing f a -> Compose Zeroing f (b + a) Source # signExtend :: forall (a :: Nat) (b :: Nat). (KnownNat a, KnownNat b) => Compose Zeroing f a -> Compose Zeroing f (b + a) Source # truncateB :: forall (a :: Nat) (b :: Natural). KnownNat a => Compose Zeroing f (a + b) -> Compose Zeroing f a Source # | |
Resize helpers
checkedResize :: forall (a :: Nat) (b :: Nat) 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.
NB: Check only affects simulation. I.e., no checks will be inserted into the generated HDL
checkedFromIntegral :: (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:
fromIntegralis not well suited for Clash as it will go throughIntegerwhich is arbitrarily bounded in HDL. Instead usebitCoerceand theResizeclass.
checkedTruncateB :: forall (a :: Natural) (b :: Nat) 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.
NB: Check only affects simulation. I.e., no checks will be inserted into the generated HDL