clash-prelude-1.2.0: CAES Language for Synchronous Hardware - Prelude library

Copyright(C) 2013-2016 University of Twente
LicenseBSD2 (see the file LICENSE)
MaintainerChristiaan Baaij <christiaan.baaij@gmail.com>
Safe HaskellTrustworthy
LanguageHaskell2010
Extensions
  • ScopedTypeVariables
  • BangPatterns
  • ViewPatterns
  • DataKinds
  • InstanceSigs
  • StandaloneDeriving
  • DeriveDataTypeable
  • DeriveFunctor
  • DeriveTraversable
  • DeriveFoldable
  • DeriveGeneric
  • DefaultSignatures
  • DeriveLift
  • DerivingStrategies
  • MagicHash
  • KindSignatures
  • TupleSections
  • TypeOperators
  • ExplicitNamespaces
  • ExplicitForAll
  • BinaryLiterals
  • TypeApplications

Clash.Sized.Index

Description

 
Synopsis

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: 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 8
6
>>> 2 * 4 :: Index 8
*** Exception: X: Clash.Sized.Index: result 8 is out of bounds: [0..7]
...
Instances
Resize Index Source # 
Instance details

Defined in Clash.Sized.Internal.Index

Methods

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 # 
Instance details

Defined in Clash.Sized.Internal.Index

Methods

minBound :: Index n #

maxBound :: Index n #

KnownNat n => Enum (Index n) Source #

The functions: enumFrom, enumFromThen, enumFromTo, and enumFromThenTo, are not synthesizable.

Instance details

Defined in Clash.Sized.Internal.Index

Methods

succ :: Index n -> Index n #

pred :: Index n -> Index n #

toEnum :: Int -> Index n #

fromEnum :: Index n -> Int #

enumFrom :: Index n -> [Index n] #

enumFromThen :: Index n -> Index n -> [Index n] #

enumFromTo :: Index n -> Index n -> [Index n] #

enumFromThenTo :: Index n -> Index n -> Index n -> [Index n] #

Eq (Index n) Source # 
Instance details

Defined in Clash.Sized.Internal.Index

Methods

(==) :: Index n -> Index n -> Bool #

(/=) :: Index n -> Index n -> Bool #

KnownNat n => Integral (Index n) Source # 
Instance details

Defined in Clash.Sized.Internal.Index

Methods

quot :: Index n -> Index n -> Index n #

rem :: Index n -> Index n -> Index n #

div :: Index n -> Index n -> Index n #

mod :: Index n -> Index n -> Index n #

quotRem :: Index n -> Index n -> (Index n, Index n) #

divMod :: Index n -> Index n -> (Index n, Index n) #

toInteger :: Index n -> Integer #

KnownNat n => Data (Index n) Source # 
Instance details

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) #

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

Instance details

Defined in Clash.Sized.Internal.Index

Methods

(+) :: Index n -> Index n -> Index n #

(-) :: Index n -> Index n -> Index n #

(*) :: Index n -> Index n -> Index n #

negate :: Index n -> Index n #

abs :: Index n -> Index n #

signum :: Index n -> Index n #

fromInteger :: Integer -> Index n #

Ord (Index n) Source # 
Instance details

Defined in Clash.Sized.Internal.Index

Methods

compare :: Index n -> Index n -> Ordering #

(<) :: Index n -> Index n -> Bool #

(<=) :: Index n -> Index n -> Bool #

(>) :: Index n -> Index n -> Bool #

(>=) :: Index n -> Index n -> Bool #

max :: Index n -> Index n -> Index n #

min :: Index n -> Index n -> Index n #

KnownNat n => Read (Index n) Source #

None of the Read class' methods are synthesizable.

Instance details

Defined in Clash.Sized.Internal.Index

KnownNat n => Real (Index n) Source # 
Instance details

Defined in Clash.Sized.Internal.Index

Methods

toRational :: Index n -> Rational #

Show (Index n) Source # 
Instance details

Defined in Clash.Sized.Internal.Index

Methods

showsPrec :: Int -> Index n -> ShowS #

show :: Index n -> String #

showList :: [Index n] -> ShowS #

Generic (Index n) Source # 
Instance details

Defined in Clash.Sized.Internal.Index

Associated Types

type Rep (Index n) :: Type -> Type #

Methods

from :: Index n -> Rep (Index n) x #

to :: Rep (Index n) x -> Index n #

KnownNat n => Lift (Index n) Source # 
Instance details

Defined in Clash.Sized.Internal.Index

Methods

lift :: Index n -> Q Exp #

KnownNat n => Arbitrary (Index n) Source # 
Instance details

Defined in Clash.Sized.Internal.Index

Methods

arbitrary :: Gen (Index n) #

shrink :: Index n -> [Index n] #

KnownNat n => CoArbitrary (Index n) Source # 
Instance details

Defined in Clash.Sized.Internal.Index

Methods

coarbitrary :: Index n -> Gen b -> Gen b #

(KnownNat n, 1 <= n) => Bits (Index n) Source # 
Instance details

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 #

zeroBits :: Index n #

bit :: 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 #

bitSize :: Index n -> Int #

isSigned :: Index n -> Bool #

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 #

rotateR :: Index n -> Int -> Index n #

popCount :: Index n -> Int #

(KnownNat n, 1 <= n) => FiniteBits (Index n) Source # 
Instance details

Defined in Clash.Sized.Internal.Index

KnownNat n => Default (Index n) Source # 
Instance details

Defined in Clash.Sized.Internal.Index

Methods

def :: Index n #

NFData (Index n) Source # 
Instance details

Defined in Clash.Sized.Internal.Index

Methods

rnf :: Index n -> () #

(KnownNat n, 1 <= n) => SaturatingNum (Index n) Source # 
Instance details

Defined in Clash.Sized.Internal.Index

NFDataX (Index n) Source # 
Instance details

Defined in Clash.Sized.Internal.Index

ShowX (Index n) Source # 
Instance details

Defined in Clash.Sized.Internal.Index

(KnownNat n, 1 <= n) => BitPack (Index n) Source # 
Instance details

Defined in Clash.Sized.Internal.Index

Associated Types

type BitSize (Index n) :: Nat Source #

(KnownNat n, 1 <= n) => Parity (Index n) Source # 
Instance details

Defined in Clash.Sized.Internal.Index

Methods

even :: Index n -> Bool Source #

odd :: Index n -> Bool Source #

Bundle (Index n) Source # 
Instance details

Defined in Clash.Signal.Bundle

Associated Types

type Unbundled dom (Index n) = (res :: Type) Source #

Methods

bundle :: Unbundled dom (Index n) -> Signal dom (Index n) Source #

unbundle :: Signal dom (Index n) -> Unbundled dom (Index n) Source #

Bundle (Index n) Source # 
Instance details

Defined in Clash.Signal.Delayed.Bundle

Associated Types

type Unbundled dom d (Index n) = (res :: Type) Source #

Methods

bundle :: Unbundled dom d (Index n) -> DSignal dom d (Index n) Source #

unbundle :: DSignal dom d (Index n) -> Unbundled dom d (Index n) Source #

AutoReg (Index n) Source # 
Instance details

Defined in Clash.Class.AutoReg.Internal

Methods

autoReg :: (HasCallStack, KnownDomain dom) => Clock dom -> Reset dom -> Enable dom -> Index n -> Signal dom (Index n) -> Signal dom (Index n) Source #

KnownNat m => Exp (Index m) Source # 
Instance details

Defined in Clash.Class.Exp

Associated Types

type ExpResult (Index m) n :: Type Source #

Methods

(^) :: Index m -> SNat n -> ExpResult (Index m) n Source #

ExtendingNum (Index m) (Index n) Source # 
Instance details

Defined in Clash.Sized.Internal.Index

Associated Types

type AResult (Index m) (Index n) :: Type Source #

type MResult (Index m) (Index n) :: Type Source #

Methods

add :: Index m -> Index n -> AResult (Index m) (Index n) Source #

sub :: Index m -> Index n -> AResult (Index m) (Index n) Source #

mul :: Index m -> Index n -> MResult (Index m) (Index n) Source #

type Unbundled dom d (Index n) Source # 
Instance details

Defined in Clash.Signal.Delayed.Bundle

type Unbundled dom d (Index n) = DSignal dom d (Index n)
type Unbundled dom (Index n) Source # 
Instance details

Defined in Clash.Signal.Bundle

type Unbundled dom (Index n) = Signal dom (Index n)
type Rep (Index n) Source # 
Instance details

Defined in Clash.Sized.Internal.Index

type Rep (Index n) = D1 (MetaData "Index" "Clash.Sized.Internal.Index" "clash-prelude-1.2.0-inplace" True) (C1 (MetaCons "I" PrefixI True) (S1 (MetaSel (Just "unsafeToInteger") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Integer)))
type BitSize (Index n) Source # 
Instance details

Defined in Clash.Sized.Internal.Index

type BitSize (Index n) = CLog 2 n
type ExpResult (Index m) n Source # 
Instance details

Defined in Clash.Class.Exp

type ExpResult (Index m) n = Index (m ^ n)
type AResult (Index m) (Index n) Source # 
Instance details

Defined in Clash.Sized.Internal.Index

type AResult (Index m) (Index n) = Index ((m + n) - 1)
type MResult (Index m) (Index n) Source # 
Instance details

Defined in Clash.Sized.Internal.Index

type MResult (Index m) (Index n) = Index (((m - 1) * (n - 1)) + 1)

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.

fromSNat :: (KnownNat m, n <= (m + 1)) => SNat n -> Index m Source #

Safely convert an SNat value to an Index