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 |
Extensions |
|
Documentation
data Index (n :: Nat) Source #
Arbitrary-bounded unsigned integer represented by ceil(log_2(n))
bits.
Given an upper bound n
, an Index
n
number has a range of: [0 .. n
-1]
>>>
maxBound :: Index 8
7>>>
minBound :: Index 8
0>>>
read (show (maxBound :: Index 8)) :: Index 8
7>>>
1 + 2 :: Index 8
3>>>
2 + 6 :: Index 8
*** Exception: Clash.Sized.Index: result 8 is out of bounds: [0..7] ...>>>
1 - 3 :: Index 8
*** Exception: Clash.Sized.Index: result -2 is out of bounds: [0..7] ...>>>
2 * 3 :: Index 8
6>>>
2 * 4 :: Index 8
*** Exception: Clash.Sized.Index: result 8 is out of bounds: [0..7] ...
Instances
Resize Index Source # | |
resize :: (KnownNat a, KnownNat b) => Index a -> Index b Source # extend :: (KnownNat a, KnownNat b) => Index a -> Index (b + a) Source # zeroExtend :: (KnownNat a, KnownNat b) => Index a -> Index (b + a) Source # signExtend :: (KnownNat a, KnownNat b) => Index a -> Index (b + a) Source # truncateB :: KnownNat a => Index (a + b) -> Index a Source # | |
KnownNat n => Bounded (Index n) Source # | |
KnownNat n => Enum (Index n) Source # | The functions: |
Eq (Index n) Source # | |
KnownNat n => Integral (Index n) Source # | |
KnownNat n => Data (Index n) Source # | |
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Index n -> c (Index n) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Index n) # toConstr :: Index n -> Constr # dataTypeOf :: Index n -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Index n)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Index n)) # gmapT :: (forall b. Data b => b -> b) -> Index n -> Index n # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Index n -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Index n -> r # gmapQ :: (forall d. Data d => d -> u) -> Index n -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Index n -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Index n -> m (Index n) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Index n -> m (Index n) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Index n -> m (Index n) # | |
KnownNat n => Num (Index n) Source # | Operators report an error on overflow and underflow |
Ord (Index n) Source # | |
KnownNat n => Read (Index n) Source # | None of the |
KnownNat n => Real (Index n) Source # | |
toRational :: Index n -> Rational # | |
Show (Index n) Source # | |
KnownNat n => Lift (Index n) Source # | |
NFData (Index n) Source # | |
(KnownNat n, 1 <= n) => SaturatingNum (Index n) Source # | |
ShowX (Index n) Source # | |
KnownNat n => Default (Index n) Source # | |
KnownNat n => Arbitrary (Index n) Source # | |
KnownNat n => CoArbitrary (Index n) Source # | |
coarbitrary :: Index n -> Gen b -> Gen b | |
KnownNat n => BitPack (Index n) Source # | |
Bundle (Index n) Source # | |
ExtendingNum (Index m) (Index n) Source # | |
type Unbundled domain (Index n) Source # | |
type BitSize (Index n) Source # | |
type AResult (Index m) (Index n) Source # | |
type MResult (Index m) (Index n) Source # | |
bv2i :: KnownNat n => BitVector n -> Index (2 ^ n) Source #
An alternative implementation of unpack
for the
Index
data type; for when you know the size of the BitVector
and want
to determine the size of the Index
.
That is, the type of unpack
is:
unpack ::BitVector
(CLog
2 n) ->Index
n
And is useful when you know the size of the Index
, and want to get a value
from a BitVector
that is large enough (CLog 2 n
) enough to hold an
Index
. Note that unpack
can fail at run-time when
the value inside the BitVector
is higher than 'n-1'.
bv2i
on the other hand will never fail at run-time, because the
BitVector
argument determines the size.