| 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 |
|
Clash.Sized.Index
Description
Documentation
data Index (n :: Nat) Source #
Arbitrarily-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 87>>>minBound :: Index 80>>>read (show (maxBound :: Index 8)) :: Index 87>>>1 + 2 :: Index 83>>>2 + 6 :: Index 8*** Exception: X: Clash.Sized.Index: result 8 is out of bounds: [0..7] ...>>>1 - 3 :: Index 8*** Exception: X: Clash.Sized.Index: result -2 is out of bounds: [0..7] ...>>>2 * 3 :: Index 86>>>2 * 4 :: Index 8*** Exception: X: Clash.Sized.Index: result 8 is out of bounds: [0..7] ...
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.
Index has the type role
>>>:i Indextype role Index nominal ...
as it is not safe to coerce between Indexes with different ranges. To
change the size, use the functions in the Resize class.
Instances
| Resize Index Source # | |||||
Defined in Clash.Sized.Internal.Index Methods resize :: forall (a :: Nat) (b :: Nat). (KnownNat a, KnownNat b) => Index a -> Index b Source # extend :: forall (a :: Nat) (b :: Nat). (KnownNat a, KnownNat b) => Index a -> Index (b + a) Source # zeroExtend :: forall (a :: Nat) (b :: Nat). (KnownNat a, KnownNat b) => Index a -> Index (b + a) Source # signExtend :: forall (a :: Nat) (b :: Nat). (KnownNat a, KnownNat b) => Index a -> Index (b + a) Source # truncateB :: forall (a :: Nat) (b :: Natural). KnownNat a => Index (a + b) -> Index a Source # | |||||
| KnownNat n => Lift (Index n :: Type) Source # | |||||
| KnownNat n => Arbitrary (Index n) Source # | |||||
| KnownNat n => CoArbitrary (Index n) Source # | |||||
Defined in Clash.Sized.Internal.Index | |||||
| KnownNat n => PrintfArg (Index n) Source # | |||||
Defined in Clash.Sized.Internal.Index | |||||
| AutoReg (Index n) Source # | |||||
| (KnownNat n, 1 <= n) => BitPack (Index n) Source # | |||||
| (1 <= n, KnownNat n) => Counter (Index n) Source # | |||||
| KnownNat m => Exp (Index m) Source # | |||||
| (KnownNat n, 1 <= n) => SaturatingNum (Index n) Source # | |||||
| (KnownNat n, 1 <= n) => Parity (Index n) Source # | |||||
| Bundle (Index n) Source # | |||||
| Bundle (Index n) Source # | |||||
| NFDataX (Index n) Source # | |||||
Defined in Clash.Sized.Internal.Index | |||||
| ShowX (Index n) Source # | |||||
| KnownNat n => Default (Index n) Source # | |||||
Defined in Clash.Sized.Internal.Index | |||||
| NFData (Index n) Source # | |||||
Defined in Clash.Sized.Internal.Index | |||||
| (KnownNat n, 1 <= n) => Bits (Index n) Source # | |||||
Defined in Clash.Sized.Internal.Index Methods (.&.) :: Index n -> Index n -> Index n # (.|.) :: Index n -> Index n -> Index n # xor :: Index n -> Index n -> Index n # complement :: Index n -> Index n # shift :: Index n -> Int -> Index n # rotate :: Index n -> Int -> Index n # setBit :: Index n -> Int -> Index n # clearBit :: Index n -> Int -> Index n # complementBit :: Index n -> Int -> Index n # testBit :: Index n -> Int -> Bool # bitSizeMaybe :: Index n -> Maybe Int # shiftL :: Index n -> Int -> Index n # unsafeShiftL :: Index n -> Int -> Index n # shiftR :: Index n -> Int -> Index n # unsafeShiftR :: Index n -> Int -> Index n # rotateL :: Index n -> Int -> Index n # | |||||
| (KnownNat n, 1 <= n) => FiniteBits (Index n) Source # | |||||
Defined in Clash.Sized.Internal.Index Methods finiteBitSize :: Index n -> Int # countLeadingZeros :: Index n -> Int # countTrailingZeros :: Index n -> Int # | |||||
| KnownNat n => Data (Index n) Source # | |||||
Defined in Clash.Sized.Internal.Index Methods 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) 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 :: forall r r'. (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 => Bounded (Index n) Source # | |||||
| KnownNat n => Enum (Index n) Source # | The functions: | ||||
| Generic (Index n) Source # | |||||
Defined in Clash.Sized.Internal.Index Associated Types
| |||||
| KnownNat n => Ix (Index n) Source # | |||||
Defined in Clash.Sized.Internal.Index | |||||
| KnownNat n => Num (Index n) Source # | Operators report an error on overflow and underflow NB: | ||||
| KnownNat n => Read (Index n) Source # | None of the | ||||
| KnownNat n => Integral (Index n) Source # | NB: | ||||
Defined in Clash.Sized.Internal.Index | |||||
| KnownNat n => Real (Index n) Source # | |||||
Defined in Clash.Sized.Internal.Index Methods toRational :: Index n -> Rational # | |||||
| Show (Index n) Source # | |||||
| Eq (Index n) Source # | |||||
| Ord (Index n) Source # | |||||
Defined in Clash.Sized.Internal.Index | |||||
| ExtendingNum (Index m) (Index n) Source # | |||||
| type Unbundled dom d (Index n) Source # | |||||
Defined in Clash.Signal.Delayed.Bundle | |||||
| type TryDomain t (Index n) Source # | |||||
Defined in Clash.Class.HasDomain.HasSingleDomain | |||||
| type Unbundled dom (Index n) Source # | |||||
Defined in Clash.Signal.Bundle | |||||
| type BitSize (Index n) Source # | |||||
Defined in Clash.Sized.Internal.Index | |||||
| type Rep (Index n) Source # | |||||
Defined in Clash.Sized.Internal.Index | |||||
| type ExpResult (Index m) n Source # | |||||
| type AResult (Index m) (Index n) Source # | |||||
| type MResult (Index m) (Index n) Source # | |||||
bv2i :: forall (n :: Nat). 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(CLog2 n) ->Indexn
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.