Copyright | (C) 2013-2016 University of Twente 2016 Myrtle Software Ltd 2021-2024 QBayLogic B.V. |
---|---|
License | BSD2 (see the file LICENSE) |
Maintainer | QBayLogic B.V. <devops@qbaylogic.com> |
Safe Haskell | Unsafe |
Language | Haskell2010 |
Extensions |
|
Synopsis
- newtype Signed (n :: Nat) = S {}
- size# :: KnownNat n => Signed n -> Int
- pack# :: forall n. KnownNat n => Signed n -> BitVector n
- unpack# :: forall n. KnownNat n => BitVector n -> Signed n
- eq# :: Signed n -> Signed n -> Bool
- neq# :: Signed n -> Signed n -> Bool
- lt# :: Signed n -> Signed n -> Bool
- ge# :: Signed n -> Signed n -> Bool
- gt# :: Signed n -> Signed n -> Bool
- le# :: Signed n -> Signed n -> Bool
- toEnum# :: forall n. KnownNat n => Int -> Signed n
- fromEnum# :: forall n. KnownNat n => Signed n -> Int
- enumFrom# :: forall n. KnownNat n => Signed n -> [Signed n]
- enumFromThen# :: forall n. KnownNat n => Signed n -> Signed n -> [Signed n]
- enumFromTo# :: forall n. KnownNat n => Signed n -> Signed n -> [Signed n]
- enumFromThenTo# :: forall n. KnownNat n => Signed n -> Signed n -> Signed n -> [Signed n]
- minBound# :: forall n. KnownNat n => Signed n
- maxBound# :: forall n. KnownNat n => Signed n
- (+#) :: forall n. KnownNat n => Signed n -> Signed n -> Signed n
- (-#) :: forall n. KnownNat n => Signed n -> Signed n -> Signed n
- (*#) :: forall n. KnownNat n => Signed n -> Signed n -> Signed n
- negate# :: forall n. KnownNat n => Signed n -> Signed n
- abs# :: forall n. KnownNat n => Signed n -> Signed n
- fromInteger# :: forall n. KnownNat n => Integer -> Signed (n :: Nat)
- plus# :: Signed m -> Signed n -> Signed (Max m n + 1)
- minus# :: Signed m -> Signed n -> Signed (Max m n + 1)
- times# :: Signed m -> Signed n -> Signed (m + n)
- quot# :: forall n. KnownNat n => Signed n -> Signed n -> Signed n
- rem# :: Signed n -> Signed n -> Signed n
- div# :: forall n. KnownNat n => Signed n -> Signed n -> Signed n
- mod# :: Signed n -> Signed n -> Signed n
- toInteger# :: Signed n -> Integer
- and# :: forall n. KnownNat n => Signed n -> Signed n -> Signed n
- or# :: forall n. KnownNat n => Signed n -> Signed n -> Signed n
- xor# :: forall n. KnownNat n => Signed n -> Signed n -> Signed n
- complement# :: forall n. KnownNat n => Signed n -> Signed n
- shiftL# :: forall n. KnownNat n => Signed n -> Int -> Signed n
- shiftR# :: forall n. KnownNat n => Signed n -> Int -> Signed n
- rotateL# :: forall n. KnownNat n => Signed n -> Int -> Signed n
- rotateR# :: forall n. KnownNat n => Signed n -> Int -> Signed n
- resize# :: forall m n. (KnownNat n, KnownNat m) => Signed n -> Signed m
- truncateB# :: forall m n. KnownNat m => Signed (m + n) -> Signed m
- minBoundSym# :: KnownNat n => Signed n
Datatypes
newtype 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 throughInteger
which is arbitrarily bounded in HDL. Instead usebitCoerce
and theResize
class. - NB: The
Num
operators performwrap-around
on overflow. If you want saturation on overflow, check out theSaturatingNum
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.
S | The constructor, |
Instances
Accessors
Length information
Type classes
BitPack
Eq
Ord
Enum
Enum (not synthesizable)
Bounded
Num
ExtendingNum
Integral
toInteger# :: Signed n -> Integer Source #
Bits
Resize
SaturatingNum
minBoundSym# :: KnownNat n => Signed n Source #