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

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

Clash.Sized.Signed

Description

Synopsis

- data Signed (n :: Nat)

# Documentation

data Signed (n :: Nat) Source #

Arbitrary-width signed integer represented by `n` bits, including the sign bit

Uses standard 2-complements representation. Meaning that, given `n` bits, a `Signed` `n` number has a range of: [-(2^(`n`-1)) .. 2^(`n`-1)-1] for `n > 0`. When `n = 0`, both the min and max bound are 0.

- NB: The usual Haskell method of converting an integral numeric type to another, `fromIntegral`, is not well suited for Clash as it will go through `Integer` which is arbitrarily bounded in HDL. Instead use `bitCoerce` and the `Resize` class.
- NB: The `Num` operators perform `wrap-around` on overflow. If you want saturation on overflow, check out the `SaturatingNum` class.

    >>> maxBound :: Signed 3
    3
    >>> minBound :: Signed 3
    -4
    >>> read (show (minBound :: Signed 3)) :: Signed 3
    -4
    >>> 1 + 2 :: Signed 3
    3
    >>> 2 + 3 :: Signed 3
    -3
    >>> (-2) + (-3) :: Signed 3
    3
    >>> 2 * 3 :: Signed 4
    6
    >>> 2 * 4 :: Signed 4
    -8
    >>> (2 :: Signed 3) `mul` (4 :: Signed 4) :: Signed 7
    8
    >>> (2 :: Signed 3) `add` (3 :: Signed 3) :: Signed 4
    5
    >>> (-2 :: Signed 3) `add` (-3 :: Signed 3) :: Signed 4
    -5
    >>> satAdd SatSymmetric 2 3 :: Signed 3
    3
    >>> satAdd SatSymmetric (-2) (-3) :: Signed 3
    -3

Signed has the type role

    >>> :i Signed
    type role Signed nominal
    ...

as it is not safe to coerce between different width Signed. To change the width, use the functions in the `Resize` class.

#### Instances

Instances details

Resize Signed Source # |

Instance details

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 #

KnownNat n => Lift (Signed n :: Type) Source # |
Instance details Defined in Clash.Sized.Internal.Signed Methods lift :: Quote m => Signed n -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => Signed n -> Code m (Signed n) Source #
KnownNat n => Arbitrary (Signed n) Source # |
Instance details Defined in Clash.Sized.Internal.Signed Methods arbitrary :: Gen (Signed n) Source # shrink :: Signed n -> [Signed n] Source #
KnownNat n => CoArbitrary (Signed n) Source # |
Instance details Defined in Clash.Sized.Internal.Signed Methods coarbitrary :: Signed n -> Gen b -> Gen b Source #
KnownNat n => PrintfArg (Signed n) Source # |
Instance details Defined in Clash.Sized.Internal.Signed Methods formatArg :: Signed n -> FieldFormatter Source # parseFormat :: Signed n -> ModifierParser Source #
AutoReg (Signed n) Source # |
Instance details Defined in Clash.Class.AutoReg.Internal Methods autoReg :: forall (dom :: Domain). (HasCallStack, KnownDomain dom) => Clock dom -> Reset dom -> Enable dom -> Signed n -> Signal dom (Signed n) -> Signal dom (Signed n) Source #
KnownNat n => BitPack (Signed n) Source # |

Instance details

Defined in Clash.Sized.Internal.Signed

Associated Types

type BitSize (Signed n) |
Instance details Defined in Clash.Sized.Internal.Signed type BitSize (Signed n) = n

Methods

pack :: Signed n -> BitVector (BitSize (Signed n)) Source #

unpack :: BitVector (BitSize (Signed n)) -> Signed n Source #

KnownNat n => Counter (Signed n) Source # |
Instance details Defined in Clash.Class.Counter.Internal Methods countMin :: Signed n Source # countMax :: Signed n Source # countSuccOverflow :: Signed n -> (Bool, Signed n) Source # countPredOverflow :: Signed n -> (Bool, Signed n) Source #
KnownNat m => Exp (Signed m) Source # |
Instance details Defined in Clash.Class.Exp Methods (^) :: forall (n :: Nat). Signed m -> SNat n -> ExpResult (Signed m) 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 => Parity (Signed n) Source # |
Instance details Defined in Clash.Sized.Internal.Signed Methods even :: Signed n -> Bool Source # odd :: Signed n -> Bool Source #
Bundle (Signed n) Source # |
Instance details Defined in Clash.Signal.Bundle Methods bundle :: forall (dom :: Domain). Unbundled dom (Signed n) -> Signal dom (Signed n) Source # unbundle :: forall (dom :: Domain). Signal dom (Signed n) -> Unbundled dom (Signed n) Source #
Bundle (Signed n) Source # |
Instance details Defined in Clash.Signal.Delayed.Bundle Methods bundle :: forall (dom :: Domain) (d :: Nat). Unbundled dom d (Signed n) -> DSignal dom d (Signed n) Source # unbundle :: forall (dom :: Domain) (d :: Nat). DSignal dom d (Signed n) -> Unbundled dom d (Signed n) Source #
NFDataX (Signed n) Source # |
Instance details Defined in Clash.Sized.Internal.Signed Methods deepErrorX :: String -> Signed n Source # hasUndefined :: Signed n -> Bool Source # ensureSpine :: Signed n -> Signed n Source # rnfX :: Signed n -> () Source #
ShowX (Signed n) Source # |
Instance details Defined in Clash.Sized.Internal.Signed Methods showsPrecX :: Int -> Signed n -> ShowS Source # showX :: Signed n -> String Source # showListX :: [Signed n] -> ShowS Source #
KnownNat n => Default (Signed n) Source # |
Instance details Defined in Clash.Sized.Internal.Signed Methods def :: Signed n #
NFData (Signed n) Source # |
Instance details Defined in Clash.Sized.Internal.Signed Methods rnf :: Signed n -> () Source #
KnownNat n => Bits (Signed n) Source # |

Instance details

Defined in Clash.Sized.Internal.Signed

Methods

(.&.) :: Signed n -> Signed n -> Signed n Source #

(.|.) :: Signed n -> Signed n -> Signed n Source #

xor :: Signed n -> Signed n -> Signed n Source #

complement :: Signed n -> Signed n Source #

shift :: Signed n -> Int -> Signed n Source #

rotate :: Signed n -> Int -> Signed n Source #

zeroBits :: Signed n Source #

bit :: Int -> Signed n Source #

setBit :: Signed n -> Int -> Signed n Source #

clearBit :: Signed n -> Int -> Signed n Source #

complementBit :: Signed n -> Int -> Signed n Source #

testBit :: Signed n -> Int -> Bool Source #

bitSizeMaybe :: Signed n -> Maybe Int Source #

bitSize :: Signed n -> Int Source #

isSigned :: Signed n -> Bool Source #

shiftL :: Signed n -> Int -> Signed n Source #

unsafeShiftL :: Signed n -> Int -> Signed n Source #

shiftR :: Signed n -> Int -> Signed n Source #

unsafeShiftR :: Signed n -> Int -> Signed n Source #

rotateL :: Signed n -> Int -> Signed n Source #

rotateR :: Signed n -> Int -> Signed n Source #

popCount :: Signed n -> Int Source #

KnownNat n => FiniteBits (Signed n) Source # |
Instance details Defined in Clash.Sized.Internal.Signed Methods finiteBitSize :: Signed n -> Int Source # countLeadingZeros :: Signed n -> Int Source # countTrailingZeros :: Signed n -> Int Source #
KnownNat n => Data (Signed n) Source # |

Instance details

Defined in Clash.Sized.Internal.Signed

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Signed n -> c (Signed n) Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Signed n) Source #

toConstr :: Signed n -> Constr Source #

dataTypeOf :: Signed n -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Signed n)) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Signed n)) Source #

gmapT :: (forall b. Data b => b -> b) -> Signed n -> Signed n Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Signed n -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Signed n -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> Signed n -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Signed n -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Signed n -> m (Signed n) Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Signed n -> m (Signed n) Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Signed n -> m (Signed n) Source #

KnownNat n => Bounded (Signed n) Source # |
Instance details Defined in Clash.Sized.Internal.Signed Methods minBound :: Signed n Source # maxBound :: Signed n Source #
KnownNat n => Enum (Signed n) Source # | The functions: `enumFrom`, `enumFromThen`, `enumFromTo`, and `enumFromThenTo`, are not synthesizable.

Instance details

Defined in Clash.Sized.Internal.Signed

Methods

succ :: Signed n -> Signed n Source #

pred :: Signed n -> Signed n Source #

toEnum :: Int -> Signed n Source #

fromEnum :: Signed n -> Int Source #

enumFrom :: Signed n -> [Signed n] Source #

enumFromThen :: Signed n -> Signed n -> [Signed n] Source #

enumFromTo :: Signed n -> Signed n -> [Signed n] Source #

enumFromThenTo :: Signed n -> Signed n -> Signed n -> [Signed n] Source #

Generic (Signed n) Source # |

Instance details

Defined in Clash.Sized.Internal.Signed

Associated Types

type Rep (Signed n) |
Instance details Defined in Clash.Sized.Internal.Signed type Rep (Signed n) = D1 ('MetaData "Signed" "Clash.Sized.Internal.Signed" "clash-prelude-1.8.4-1CKHk9HHRNIGPqhYHQsmcW" 'False) (C1 ('MetaCons "S" 'PrefixI 'True) (S1 ('MetaSel ('Just "unsafeToInteger") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Integer)))

Methods

from :: Signed n -> Rep (Signed n) x Source #

to :: Rep (Signed n) x -> Signed n Source #

KnownNat n => Ix (Signed n) Source # |

Instance details

Defined in Clash.Sized.Internal.Signed

Methods

range :: (Signed n, Signed n) -> [Signed n] Source #

index :: (Signed n, Signed n) -> Signed n -> Int Source #

unsafeIndex :: (Signed n, Signed n) -> Signed n -> Int Source #

inRange :: (Signed n, Signed n) -> Signed n -> Bool Source #

rangeSize :: (Signed n, Signed n) -> Int Source #

unsafeRangeSize :: (Signed n, Signed n) -> Int Source #

KnownNat n => Num (Signed n) Source # | Operators do `wrap-around` on overflow NB: `fromInteger`/`fromIntegral` can cause unexpected truncation, as `Integer` is arbitrarily bounded during synthesis. Prefer `bitCoerce` and the `Resize` class.
Instance details Defined in Clash.Sized.Internal.Signed Methods (+) :: Signed n -> Signed n -> Signed n Source # (-) :: Signed n -> Signed n -> Signed n Source # (*) :: Signed n -> Signed n -> Signed n Source # negate :: Signed n -> Signed n Source # abs :: Signed n -> Signed n Source # signum :: Signed n -> Signed n Source # fromInteger :: Integer -> Signed n Source #
KnownNat n => Read (Signed n) Source # | None of the `Read` class' methods are synthesizable.
Instance details Defined in Clash.Sized.Internal.Signed Methods readsPrec :: Int -> ReadS (Signed n) Source # readList :: ReadS [Signed n] Source # readPrec :: ReadPrec (Signed n) Source # readListPrec :: ReadPrec [Signed n] Source #
KnownNat n => Integral (Signed n) Source # | NB: `toInteger`/`fromIntegral` can cause unexpected truncation, as `Integer` is arbitrarily bounded during synthesis. Prefer `bitCoerce` and the `Resize` class.

Instance details

Defined in Clash.Sized.Internal.Signed

Methods

quot :: Signed n -> Signed n -> Signed n Source #

rem :: Signed n -> Signed n -> Signed n Source #

div :: Signed n -> Signed n -> Signed n Source #

mod :: Signed n -> Signed n -> Signed n Source #

quotRem :: Signed n -> Signed n -> (Signed n, Signed n) Source #

divMod :: Signed n -> Signed n -> (Signed n, Signed n) Source #

toInteger :: Signed n -> Integer Source #

KnownNat n => Real (Signed n) Source # |
Instance details Defined in Clash.Sized.Internal.Signed Methods toRational :: Signed n -> Rational Source #
Show (Signed n) Source # |
Instance details Defined in Clash.Sized.Internal.Signed Methods showsPrec :: Int -> Signed n -> ShowS Source # show :: Signed n -> String Source # showList :: [Signed n] -> ShowS Source #
Eq (Signed n) Source # |
Instance details Defined in Clash.Sized.Internal.Signed Methods (==) :: Signed n -> Signed n -> Bool Source # (/=) :: Signed n -> Signed n -> Bool Source #
Ord (Signed n) Source # |
Instance details Defined in Clash.Sized.Internal.Signed Methods compare :: Signed n -> Signed n -> Ordering Source # (<) :: Signed n -> Signed n -> Bool Source # (<=) :: Signed n -> Signed n -> Bool Source # (>) :: Signed n -> Signed n -> Bool Source # (>=) :: Signed n -> Signed n -> Bool Source # max :: Signed n -> Signed n -> Signed n Source # min :: Signed n -> Signed n -> Signed n Source #
KnownNat n => Ixed (Signed n) Source # |
Instance details Defined in Clash.Sized.Internal.Signed Methods ix :: Index (Signed n) -> Traversal' (Signed n) (IxValue (Signed 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 #

type Unbundled dom d (Signed n) Source # |
Instance details Defined in Clash.Signal.Delayed.Bundle type Unbundled dom d (Signed n) = DSignal dom d (Signed n)
type TryDomain t (Signed n) Source # |
Instance details Defined in Clash.Class.HasDomain.HasSingleDomain type TryDomain t (Signed n) = 'NotFound
type Unbundled dom (Signed n) Source # |
Instance details Defined in Clash.Signal.Bundle type Unbundled dom (Signed n) = Signal dom (Signed n)
type BitSize (Signed n) Source # |
Instance details Defined in Clash.Sized.Internal.Signed type BitSize (Signed n) = n
type Rep (Signed n) Source # |
Instance details Defined in Clash.Sized.Internal.Signed type Rep (Signed n) = D1 ('MetaData "Signed" "Clash.Sized.Internal.Signed" "clash-prelude-1.8.4-1CKHk9HHRNIGPqhYHQsmcW" 'False) (C1 ('MetaCons "S" 'PrefixI 'True) (S1 ('MetaSel ('Just "unsafeToInteger") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Integer)))
type Index (Signed n) Source # |
Instance details Defined in Clash.Sized.Internal.Signed type Index (Signed n) = Int
type IxValue (Signed n) Source # |
Instance details Defined in Clash.Sized.Internal.Signed type IxValue (Signed n) = Bit
type ExpResult (Signed m) n Source # |
Instance details Defined in Clash.Class.Exp type ExpResult (Signed m) n = Signed (Max 2 (m * n))
type AResult (Signed m) (Signed n) Source # |
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) Source # |
Instance details Defined in Clash.Sized.Internal.Signed type MResult (Signed m) (Signed n) = Signed (m + n)