clash-prelude-1.8.4: Clash: a functional hardware description language - Prelude library

Copyright | (C) 2013-2016 University of Twente 2024 Google LLC
License | BSD2 (see the file LICENSE)
Maintainer | Christiaan Baaij <christiaan.baaij@gmail.com>
Safe Haskell | Safe
Language | Haskell2010

Extensions

- MonoLocalBinds
- ScopedTypeVariables
- BangPatterns
- TypeFamilies
- ViewPatterns
- DataKinds
- InstanceSigs
- StandaloneDeriving
- DeriveDataTypeable
- DeriveFunctor
- DeriveTraversable
- DeriveFoldable
- DeriveGeneric
- DefaultSignatures
- DeriveLift
- DerivingStrategies
- ConstrainedClassMethods
- MultiParamTypeClasses
- MagicHash
- KindSignatures
- PostfixOperators
- TupleSections
- TypeOperators
- ExplicitNamespaces
- ExplicitForAll
- BinaryLiterals
- TypeApplications

Clash.Class.Num

Contents

- Arithmetic functions for arguments and results of different precision
- Saturating arithmetic functions

Description

Synopsis

- class ExtendingNum a b where
  - type AResult a b
  - type MResult a b
  - add :: a -> b -> AResult a b
  - sub :: a -> b -> AResult a b
  - mul :: a -> b -> MResult a b
- data SaturationMode
  - = SatWrap
  - | SatBound
  - | SatZero
  - | SatSymmetric
  - | SatError
- class (Bounded a, Num a) => SaturatingNum a where
  - satAdd :: SaturationMode -> a -> a -> a
  - satSub :: SaturationMode -> a -> a -> a
  - satMul :: SaturationMode -> a -> a -> a
  - satSucc :: SaturationMode -> a -> a
  - satPred :: SaturationMode -> a -> a
- boundedAdd :: SaturatingNum a => a -> a -> a
- boundedSub :: SaturatingNum a => a -> a -> a
- boundedMul :: SaturatingNum a => a -> a -> a

# Arithmetic functions for arguments and results of different precision

class ExtendingNum a b where Source #

Adding, subtracting, and multiplying values of two different (sub-)types.

Associated Types

type AResult a b Source #

Type of the result of the addition or subtraction

type MResult a b Source #

Type of the result of the multiplication

Methods

add :: a -> b -> AResult a b infixl 6 Source #

Add values of different (sub-)types, return a value of a (sub-)type that is potentially different from either argument.

sub :: a -> b -> AResult a b infixl 6 Source #

Subtract values of different (sub-)types, return a value of a (sub-)type that is potentially different from either argument.

mul :: a -> b -> MResult a b infixl 7 Source #

Multiply values of different (sub-)types, return a value of a (sub-)type that is potentially different from either argument.

#### Instances

Instances details

(KnownNat m, KnownNat n) => ExtendingNum (BitVector m) (BitVector n) Source # |

Instance details

Defined in Clash.Sized.Internal.BitVector

Associated Types

type AResult (BitVector m) (BitVector n) |
Instance details Defined in Clash.Sized.Internal.BitVector type AResult (BitVector m) (BitVector n) = BitVector (Max m n + 1)
type MResult (BitVector m) (BitVector n) |
Instance details Defined in Clash.Sized.Internal.BitVector type MResult (BitVector m) (BitVector n) = BitVector (m + n)

Methods

add :: BitVector m -> BitVector n -> AResult (BitVector m) (BitVector n) Source #

sub :: BitVector m -> BitVector n -> AResult (BitVector m) (BitVector n) Source #

mul :: BitVector m -> BitVector n -> MResult (BitVector m) (BitVector n) Source #

ExtendingNum (Index m) (Index n) Source # |

Instance details

Defined in Clash.Sized.Internal.Index

Associated Types

type AResult (Index m) (Index n) |
Instance details Defined in Clash.Sized.Internal.Index type AResult (Index m) (Index n) = Index ((m + n) - 1)
type MResult (Index m) (Index n) |
Instance details Defined in Clash.Sized.Internal.Index type MResult (Index m) (Index n) = Index (((m - 1) * (n - 1)) + 1)

Methods

add :: Index m -> Index n -> AResult (Index m) (Index n) Source #

sub :: Index m -> Index n -> AResult (Index m) (Index n) Source #

mul :: Index m -> Index n -> MResult (Index m) (Index n) Source #

ExtendingNum (Signed m) (Signed n) Source # |

Instance details

Defined in Clash.Sized.Internal.Signed

Associated Types

type AResult (Signed m) (Signed n) |
Instance details Defined in Clash.Sized.Internal.Signed type AResult (Signed m) (Signed n) = Signed (Max m n + 1)
type MResult (Signed m) (Signed n) |
Instance details Defined in Clash.Sized.Internal.Signed type MResult (Signed m) (Signed n) = Signed (m + n)

Methods

add :: Signed m -> Signed n -> AResult (Signed m) (Signed n) Source #

sub :: Signed m -> Signed n -> AResult (Signed m) (Signed n) Source #

mul :: Signed m -> Signed n -> MResult (Signed m) (Signed n) Source #

(KnownNat m, KnownNat n) => ExtendingNum (Unsigned m) (Unsigned n) Source # |

Instance details

Defined in Clash.Sized.Internal.Unsigned

Associated Types

type AResult (Unsigned m) (Unsigned n) |
Instance details Defined in Clash.Sized.Internal.Unsigned type AResult (Unsigned m) (Unsigned n) = Unsigned (Max m n + 1)
type MResult (Unsigned m) (Unsigned n) |
Instance details Defined in Clash.Sized.Internal.Unsigned type MResult (Unsigned m) (Unsigned n) = Unsigned (m + n)

Methods

add :: Unsigned m -> Unsigned n -> AResult (Unsigned m) (Unsigned n) Source #

sub :: Unsigned m -> Unsigned n -> AResult (Unsigned m) (Unsigned n) Source #

mul :: Unsigned m -> Unsigned n -> MResult (Unsigned m) (Unsigned n) Source #

ENumFixedC rep int1 frac1 int2 frac2 => ExtendingNum (Fixed rep int1 frac1) (Fixed rep int2 frac2) Source #

When used in a polymorphic setting, use the following Constraint synonyms for less verbose type signatures:

- ``ENumFixedC` rep frac1 frac2 size1 size2` for: `Fixed`
- ``ENumSFixedC` int1 frac1 int2 frac2` for: `SFixed`
- ``ENumUFixedC` int1 frac1 int2 frac2` for: `UFixed`

Instance details

Defined in Clash.Sized.Fixed

Associated Types

type AResult (Fixed rep int1 frac1) (Fixed rep int2 frac2) |
Instance details Defined in Clash.Sized.Fixed type AResult (Fixed rep int1 frac1) (Fixed rep int2 frac2) = Fixed rep (1 + Max int1 int2) (Max frac1 frac2)
type MResult (Fixed rep int1 frac1) (Fixed rep int2 frac2) |
Instance details Defined in Clash.Sized.Fixed type MResult (Fixed rep int1 frac1) (Fixed rep int2 frac2) = Fixed rep (int1 + int2) (frac1 + frac2)

Methods

add :: Fixed rep int1 frac1 -> Fixed rep int2 frac2 -> AResult (Fixed rep int1 frac1) (Fixed rep int2 frac2) Source #

sub :: Fixed rep int1 frac1 -> Fixed rep int2 frac2 -> AResult (Fixed rep int1 frac1) (Fixed rep int2 frac2) Source #

mul :: Fixed rep int1 frac1 -> Fixed rep int2 frac2 -> MResult (Fixed rep int1 frac1) (Fixed rep int2 frac2) Source #

# Saturating arithmetic functions

data SaturationMode Source #

Determine how overflow and underflow are handled by the functions in `SaturatingNum`

Constructors

SatWrap | Wrap around on overflow and underflow
SatBound | Become `maxBound` on overflow, and `minBound` on underflow
SatZero | Become `0` on overflow and underflow
SatSymmetric | Become `maxBound` on overflow, and (``minBound` + 1`) on underflow for signed numbers, and `minBound` for unsigned numbers.
SatError | Become an XException on overflow and underflow

#### Instances

Instances details

Bounded SaturationMode Source # |
Instance details Defined in Clash.Class.Num Methods minBound :: SaturationMode Source # maxBound :: SaturationMode Source #
Enum SaturationMode Source # |

Instance details

Defined in Clash.Class.Num

Methods

succ :: SaturationMode -> SaturationMode Source #

pred :: SaturationMode -> SaturationMode Source #

toEnum :: Int -> SaturationMode Source #

fromEnum :: SaturationMode -> Int Source #

enumFrom :: SaturationMode -> [SaturationMode] Source #

enumFromThen :: SaturationMode -> SaturationMode -> [SaturationMode] Source #

enumFromTo :: SaturationMode -> SaturationMode -> [SaturationMode] Source #

enumFromThenTo :: SaturationMode -> SaturationMode -> SaturationMode -> [SaturationMode] Source #

Show SaturationMode Source # |
Instance details Defined in Clash.Class.Num Methods showsPrec :: Int -> SaturationMode -> ShowS Source # show :: SaturationMode -> String Source # showList :: [SaturationMode] -> ShowS Source #
Eq SaturationMode Source # |
Instance details Defined in Clash.Class.Num Methods (==) :: SaturationMode -> SaturationMode -> Bool Source # (/=) :: SaturationMode -> SaturationMode -> Bool Source #

class (Bounded a, Num a) => SaturatingNum a where Source #

`Num` operators in which overflow and underflow behavior can be specified using `SaturationMode`.

Minimal complete definition

satAdd, satSub, satMul

Methods

satAdd :: SaturationMode -> a -> a -> a infixl 6 Source #

Addition with parameterizable over- and underflow behavior

satSub :: SaturationMode -> a -> a -> a infixl 6 Source #

Subtraction with parameterizable over- and underflow behavior

satMul :: SaturationMode -> a -> a -> a infixl 7 Source #

Multiplication with parameterizable over- and underflow behavior

satSucc :: SaturationMode -> a -> a Source #

Get successor of (or in other words, add 1 to) given number

satPred :: SaturationMode -> a -> a Source #

Get predecessor of (or in other words, subtract 1 from) given number

#### Instances

Instances details

KnownNat n => SaturatingNum (BitVector n) Source # |

Instance details

Defined in Clash.Sized.Internal.BitVector

Methods

satAdd :: SaturationMode -> BitVector n -> BitVector n -> BitVector n Source #

satSub :: SaturationMode -> BitVector n -> BitVector n -> BitVector n Source #

satMul :: SaturationMode -> BitVector n -> BitVector n -> BitVector n Source #

satSucc :: SaturationMode -> BitVector n -> BitVector n Source #

satPred :: SaturationMode -> BitVector n -> BitVector n Source #

(KnownNat n, 1 <= n) => SaturatingNum (Index n) Source # |
Instance details Defined in Clash.Sized.Internal.Index Methods satAdd :: SaturationMode -> Index n -> Index n -> Index n Source # satSub :: SaturationMode -> Index n -> Index n -> Index n Source # satMul :: SaturationMode -> Index n -> Index n -> Index n Source # satSucc :: SaturationMode -> Index n -> Index n Source # satPred :: SaturationMode -> Index n -> Index n Source #
KnownNat n => SaturatingNum (Signed n) Source # |
Instance details Defined in Clash.Sized.Internal.Signed Methods satAdd :: SaturationMode -> Signed n -> Signed n -> Signed n Source # satSub :: SaturationMode -> Signed n -> Signed n -> Signed n Source # satMul :: SaturationMode -> Signed n -> Signed n -> Signed n Source # satSucc :: SaturationMode -> Signed n -> Signed n Source # satPred :: SaturationMode -> Signed n -> Signed n Source #
KnownNat n => SaturatingNum (Unsigned n) Source # |

Instance details

Defined in Clash.Sized.Internal.Unsigned

Methods

satAdd :: SaturationMode -> Unsigned n -> Unsigned n -> Unsigned n Source #

satSub :: SaturationMode -> Unsigned n -> Unsigned n -> Unsigned n Source #

satMul :: SaturationMode -> Unsigned n -> Unsigned n -> Unsigned n Source #

satSucc :: SaturationMode -> Unsigned n -> Unsigned n Source #

satPred :: SaturationMode -> Unsigned n -> Unsigned n Source #

NumFixedC rep int frac => SaturatingNum (Fixed rep int frac) Source # |

Instance details

Defined in Clash.Sized.Fixed

Methods

satAdd :: SaturationMode -> Fixed rep int frac -> Fixed rep int frac -> Fixed rep int frac Source #

satSub :: SaturationMode -> Fixed rep int frac -> Fixed rep int frac -> Fixed rep int frac Source #

satMul :: SaturationMode -> Fixed rep int frac -> Fixed rep int frac -> Fixed rep int frac Source #

satSucc :: SaturationMode -> Fixed rep int frac -> Fixed rep int frac Source #

satPred :: SaturationMode -> Fixed rep int frac -> Fixed rep int frac Source #

boundedAdd :: SaturatingNum a => a -> a -> a infixl 6 Source #

Addition that clips to `maxBound` on overflow, and `minBound` on underflow

boundedSub :: SaturatingNum a => a -> a -> a infixl 6 Source #

Subtraction that clips to `maxBound` on overflow, and `minBound` on underflow

boundedMul :: SaturatingNum a => a -> a -> a infixl 7 Source #

Multiplication that clips to `maxBound` on overflow, and `minBound` on underflow