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

Clash.Sized.Signed

Description

Synopsis

# 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
 Source # Instance detailsDefined in Clash.Sized.Internal.Signed Methodsresize :: 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 :: Nat). KnownNat a => Signed (a + b) -> Signed a Source # KnownNat n => Lift (Signed n :: Type) Source # Instance detailsDefined in Clash.Sized.Internal.Signed Methodslift :: Signed n -> Q Exp #liftTyped :: Signed n -> Q (TExp (Signed n)) # KnownNat n => Bounded (Signed n) Source # Instance detailsDefined in Clash.Sized.Internal.Signed Methods KnownNat n => Enum (Signed n) Source # The functions: enumFrom, enumFromThen, enumFromTo, and enumFromThenTo, are not synthesizable. Instance detailsDefined in Clash.Sized.Internal.Signed Methodssucc :: Signed n -> Signed n #pred :: Signed n -> Signed n #toEnum :: Int -> Signed n #fromEnum :: Signed n -> Int #enumFrom :: Signed n -> [Signed n] #enumFromThen :: Signed n -> Signed n -> [Signed n] #enumFromTo :: Signed n -> Signed n -> [Signed n] #enumFromThenTo :: Signed n -> Signed n -> Signed n -> [Signed n] # Eq (Signed n) Source # Instance detailsDefined in Clash.Sized.Internal.Signed Methods(==) :: Signed n -> Signed n -> Bool #(/=) :: Signed n -> Signed n -> Bool # 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 detailsDefined in Clash.Sized.Internal.Signed Methodsquot :: Signed n -> Signed n -> Signed n #rem :: Signed n -> Signed n -> Signed n #div :: Signed n -> Signed n -> Signed n #mod :: Signed n -> Signed n -> Signed n #quotRem :: Signed n -> Signed n -> (Signed n, Signed n) #divMod :: Signed n -> Signed n -> (Signed n, Signed n) #toInteger :: Signed n -> Integer # KnownNat n => Data (Signed n) Source # Instance detailsDefined in Clash.Sized.Internal.Signed Methodsgfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Signed n -> c (Signed n) #gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Signed n) #toConstr :: Signed n -> Constr #dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Signed n)) #dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Signed n)) #gmapT :: (forall b. Data b => b -> b) -> Signed n -> Signed n #gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Signed n -> r #gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Signed n -> r #gmapQ :: (forall d. Data d => d -> u) -> Signed n -> [u] #gmapQi :: Int -> (forall d. Data d => d -> u) -> Signed n -> u #gmapM :: Monad m => (forall d. Data d => d -> m d) -> Signed n -> m (Signed n) #gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Signed n -> m (Signed n) #gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Signed n -> m (Signed n) # KnownNat n => Num (Signed n) Source # Operators do wrap-around on overflowNB: fromInteger/fromIntegral can cause unexpected truncation, as Integer is arbitrarily bounded during synthesis. Prefer bitCoerce and the Resize class. Instance detailsDefined in Clash.Sized.Internal.Signed Methods(+) :: Signed n -> Signed n -> Signed n #(-) :: Signed n -> Signed n -> Signed n #(*) :: Signed n -> Signed n -> Signed n #negate :: Signed n -> Signed n #abs :: Signed n -> Signed n #signum :: Signed n -> Signed n # Ord (Signed n) Source # Instance detailsDefined in Clash.Sized.Internal.Signed Methodscompare :: Signed n -> Signed n -> Ordering #(<) :: Signed n -> Signed n -> Bool #(<=) :: Signed n -> Signed n -> Bool #(>) :: Signed n -> Signed n -> Bool #(>=) :: Signed n -> Signed n -> Bool #max :: Signed n -> Signed n -> Signed n #min :: Signed n -> Signed n -> Signed n # KnownNat n => Read (Signed n) Source # None of the Read class' methods are synthesizable. Instance detailsDefined in Clash.Sized.Internal.Signed MethodsreadsPrec :: Int -> ReadS (Signed n) #readList :: ReadS [Signed n] # KnownNat n => Real (Signed n) Source # Instance detailsDefined in Clash.Sized.Internal.Signed Methods Show (Signed n) Source # Instance detailsDefined in Clash.Sized.Internal.Signed MethodsshowsPrec :: Int -> Signed n -> ShowS #show :: Signed n -> String #showList :: [Signed n] -> ShowS # KnownNat n => Ix (Signed n) Source # Instance detailsDefined in Clash.Sized.Internal.Signed Methodsrange :: (Signed n, Signed n) -> [Signed n] #index :: (Signed n, Signed n) -> Signed n -> Int #unsafeIndex :: (Signed n, Signed n) -> Signed n -> Int #inRange :: (Signed n, Signed n) -> Signed n -> Bool #rangeSize :: (Signed n, Signed n) -> Int #unsafeRangeSize :: (Signed n, Signed n) -> Int # Source # Instance detailsDefined in Clash.Sized.Internal.Signed Associated Typestype Rep (Signed n) :: Type -> Type # Methodsfrom :: Signed n -> Rep (Signed n) x #to :: Rep (Signed n) x -> Signed n # KnownNat n => Arbitrary (Signed n) Source # Instance detailsDefined in Clash.Sized.Internal.Signed Methodsarbitrary :: Gen (Signed n) #shrink :: Signed n -> [Signed n] # KnownNat n => CoArbitrary (Signed n) Source # Instance detailsDefined in Clash.Sized.Internal.Signed Methodscoarbitrary :: Signed n -> Gen b -> Gen b # KnownNat n => PrintfArg (Signed n) Source # Instance detailsDefined in Clash.Sized.Internal.Signed Methods KnownNat n => Bits (Signed n) Source # Instance detailsDefined in Clash.Sized.Internal.Signed Methods(.&.) :: Signed n -> Signed n -> Signed n #(.|.) :: Signed n -> Signed n -> Signed n #xor :: Signed n -> Signed n -> Signed n #complement :: Signed n -> Signed n #shift :: Signed n -> Int -> Signed n #rotate :: Signed n -> Int -> Signed n #bit :: Int -> Signed n #setBit :: Signed n -> Int -> Signed n #clearBit :: Signed n -> Int -> Signed n #complementBit :: Signed n -> Int -> Signed n #testBit :: Signed n -> Int -> Bool #bitSize :: Signed n -> Int #isSigned :: Signed n -> Bool #shiftL :: Signed n -> Int -> Signed n #unsafeShiftL :: Signed n -> Int -> Signed n #shiftR :: Signed n -> Int -> Signed n #unsafeShiftR :: Signed n -> Int -> Signed n #rotateL :: Signed n -> Int -> Signed n #rotateR :: Signed n -> Int -> Signed n #popCount :: Signed n -> Int # KnownNat n => FiniteBits (Signed n) Source # Instance detailsDefined in Clash.Sized.Internal.Signed MethodsfiniteBitSize :: Signed n -> Int # KnownNat n => Default (Signed n) Source # Instance detailsDefined in Clash.Sized.Internal.Signed Methodsdef :: Signed n # NFData (Signed n) Source # Instance detailsDefined in Clash.Sized.Internal.Signed Methodsrnf :: Signed n -> () # KnownNat n => Ixed (Signed n) Source # Instance detailsDefined in Clash.Sized.Internal.Signed Methodsix :: Index (Signed n) -> Traversal' (Signed n) (IxValue (Signed n)) # KnownNat n => SaturatingNum (Signed n) Source # Instance detailsDefined in Clash.Sized.Internal.Signed MethodssatAdd :: 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 # Source # Instance detailsDefined in Clash.Sized.Internal.Signed MethodsrnfX :: Signed n -> () Source # ShowX (Signed n) Source # Instance detailsDefined in Clash.Sized.Internal.Signed MethodsshowsPrecX :: Int -> Signed n -> ShowS Source #showX :: Signed n -> String Source #showListX :: [Signed n] -> ShowS Source # KnownNat n => BitPack (Signed n) Source # Instance detailsDefined in Clash.Sized.Internal.Signed Associated Typestype BitSize (Signed n) :: Nat Source # Methodspack :: Signed n -> BitVector (BitSize (Signed n)) Source #unpack :: BitVector (BitSize (Signed n)) -> Signed n Source # KnownNat n => Parity (Signed n) Source # Instance detailsDefined in Clash.Sized.Internal.Signed Methodseven :: Signed n -> Bool Source #odd :: Signed n -> Bool Source # Bundle (Signed n) Source # Instance detailsDefined in Clash.Signal.Bundle Associated Typestype Unbundled dom (Signed n) = (res :: Type) Source # Methodsbundle :: 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 detailsDefined in Clash.Signal.Delayed.Bundle Associated Typestype Unbundled dom d (Signed n) = (res :: Type) Source # Methodsbundle :: 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 # KnownNat n => Counter (Signed n) Source # Instance detailsDefined in Clash.Class.Counter.Internal MethodscountSuccOverflow :: Signed n -> (Bool, Signed n) Source #countPredOverflow :: Signed n -> (Bool, Signed n) Source # Source # Instance detailsDefined in Clash.Class.AutoReg.Internal MethodsautoReg :: forall (dom :: Domain). (HasCallStack, KnownDomain dom) => Clock dom -> Reset dom -> Enable dom -> Signed n -> Signal dom (Signed n) -> Signal dom (Signed n) Source # KnownNat m => Exp (Signed m) Source # Instance detailsDefined in Clash.Class.Exp Associated Typestype ExpResult (Signed m) n Source # Methods(^) :: forall (n :: Nat). Signed m -> SNat n -> ExpResult (Signed m) n Source # ExtendingNum (Signed m) (Signed n) Source # Instance detailsDefined in Clash.Sized.Internal.Signed Associated Typestype AResult (Signed m) (Signed n) Source #type MResult (Signed m) (Signed n) Source # Methodsadd :: 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 detailsDefined in Clash.Signal.Delayed.Bundle type Unbundled dom d (Signed n) = DSignal dom d (Signed n) type Unbundled dom (Signed n) Source # Instance detailsDefined in Clash.Signal.Bundle type Unbundled dom (Signed n) = Signal dom (Signed n) type TryDomain t (Signed n) Source # Instance detailsDefined in Clash.Class.HasDomain.HasSingleDomain type TryDomain t (Signed n) = 'NotFound type Rep (Signed n) Source # Instance detailsDefined in Clash.Sized.Internal.Signed type Rep (Signed n) = D1 ('MetaData "Signed" "Clash.Sized.Internal.Signed" "clash-prelude-1.6.4-inplace" 'True) (C1 ('MetaCons "S" 'PrefixI 'True) (S1 ('MetaSel ('Just "unsafeToInteger") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Integer))) type Index (Signed n) Source # Instance detailsDefined in Clash.Sized.Internal.Signed type Index (Signed n) = Int type IxValue (Signed n) Source # Instance detailsDefined in Clash.Sized.Internal.Signed type IxValue (Signed n) = Bit type BitSize (Signed n) Source # Instance detailsDefined in Clash.Sized.Internal.Signed type BitSize (Signed n) = n type ExpResult (Signed m) n Source # Instance detailsDefined in Clash.Class.Exp type ExpResult (Signed m) n = Signed (Max 2 (m * n)) type AResult (Signed m) (Signed n) Source # Instance detailsDefined in Clash.Sized.Internal.Signed type AResult (Signed m) (Signed n) = Signed (Max m n + 1) type MResult (Signed m) (Signed n) Source # Instance detailsDefined in Clash.Sized.Internal.Signed type MResult (Signed m) (Signed n) = Signed (m + n)