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

Copyright | (C) 2013-2016 University of Twente 2016-2019 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

- Cpp
- UndecidableInstances
- MonoLocalBinds
- TemplateHaskell
- TemplateHaskellQuotes
- ScopedTypeVariables
- BangPatterns
- TypeFamilies
- ViewPatterns
- DataKinds
- InstanceSigs
- StandaloneDeriving
- DeriveDataTypeable
- DeriveFunctor
- DeriveTraversable
- DeriveFoldable
- DeriveGeneric
- DefaultSignatures
- DeriveAnyClass
- DeriveLift
- DerivingStrategies
- FlexibleContexts
- ConstrainedClassMethods
- MultiParamTypeClasses
- MagicHash
- KindSignatures
- RoleAnnotations
- PostfixOperators
- TupleSections
- TypeOperators
- ExplicitNamespaces
- ExplicitForAll
- BinaryLiterals
- TypeApplications

Clash.Sized.Internal.Index

Contents

- Datatypes
- Construction
- Accessors
  - Length information
- Type classes
  - BitPack
  - Eq
  - Ord
  - Enum
  - Enum (not synthesizable)
  - Bounded
  - Num
  - ExtendingNum
  - Integral
  - Resize

Description

Synopsis

- data Index (n :: Nat) = I {
  - unsafeToInteger :: !Integer
  }
- fromSNat :: forall (m :: Nat) (n :: Natural). (KnownNat m, (n + 1) <= m) => SNat n -> Index m
- size# :: forall (n :: Nat). (KnownNat n, 1 <= n) => Index n -> Int
- pack# :: forall (n :: Nat). Index n -> BitVector (CLog 2 n)
- unpack# :: forall (n :: Nat). (KnownNat n, 1 <= n) => BitVector (CLog 2 n) -> Index n
- eq# :: forall (n :: Nat). Index n -> Index n -> Bool
- neq# :: forall (n :: Nat). Index n -> Index n -> Bool
- lt# :: forall (n :: Nat). Index n -> Index n -> Bool
- ge# :: forall (n :: Nat). Index n -> Index n -> Bool
- gt# :: forall (n :: Nat). Index n -> Index n -> Bool
- le# :: forall (n :: Nat). Index n -> Index n -> Bool
- toEnum# :: forall (n :: Nat). KnownNat n => Int -> Index n
- fromEnum# :: forall (n :: Nat). KnownNat n => Index n -> Int
- enumFrom# :: forall (n :: Nat). KnownNat n => Index n -> [Index n]
- enumFromThen# :: forall (n :: Nat). KnownNat n => Index n -> Index n -> [Index n]
- enumFromTo# :: forall (n :: Nat). Index n -> Index n -> [Index n]
- enumFromThenTo# :: forall (n :: Nat). Index n -> Index n -> Index n -> [Index n]
- maxBound# :: forall (n :: Nat). KnownNat n => Index n
- (+#) :: forall (n :: Nat). KnownNat n => Index n -> Index n -> Index n
- (-#) :: forall (n :: Nat). KnownNat n => Index n -> Index n -> Index n
- (*#) :: forall (n :: Nat). KnownNat n => Index n -> Index n -> Index n
- negate# :: forall (n :: Nat). KnownNat n => Index n -> Index n
- fromInteger# :: forall (n :: Nat). KnownNat n => Integer -> Index n
- plus# :: forall (m :: Nat) (n :: Nat). Index m -> Index n -> Index ((m + n) - 1)
- minus# :: forall (m :: Nat) (n :: Nat). Index m -> Index n -> Index ((m + n) - 1)
- times# :: forall (m :: Nat) (n :: Nat). Index m -> Index n -> Index (((m - 1) * (n - 1)) + 1)
- quot# :: forall (n :: Nat). Index n -> Index n -> Index n
- rem# :: forall (n :: Nat). Index n -> Index n -> Index n
- toInteger# :: forall (n :: Nat). Index n -> Integer
- resize# :: forall (m :: Nat) (n :: Nat). KnownNat m => Index n -> Index m

# Datatypes

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 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]
    ...

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 Index
    type role Index nominal
    ...

as it is not safe to coerce between `Index`es with different ranges. To change the size, use the functions in the `Resize` class.

Constructors

I | The constructor, `I`, and the field, `unsafeToInteger`, are not synthesizable.

Fields

- unsafeToInteger :: !Integer

#### Instances

Instances details

Resize Index Source # |

Instance details

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 # |
Instance details Defined in Clash.Sized.Internal.Index Methods lift :: Quote m => Index n -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => Index n -> Code m (Index n) Source #
KnownNat n => Arbitrary (Index n) Source # |
Instance details Defined in Clash.Sized.Internal.Index Methods arbitrary :: Gen (Index n) Source # shrink :: Index n -> [Index n] Source #
KnownNat n => CoArbitrary (Index n) Source # |
Instance details Defined in Clash.Sized.Internal.Index Methods coarbitrary :: Index n -> Gen b -> Gen b Source #
KnownNat n => PrintfArg (Index n) Source # |
Instance details Defined in Clash.Sized.Internal.Index Methods formatArg :: Index n -> FieldFormatter Source # parseFormat :: Index n -> ModifierParser Source #
AutoReg (Index n) Source # |
Instance details Defined in Clash.Class.AutoReg.Internal Methods autoReg :: forall (dom :: Domain). (HasCallStack, KnownDomain dom) => Clock dom -> Reset dom -> Enable dom -> Index n -> Signal dom (Index n) -> Signal dom (Index n) Source #
(KnownNat n, 1 <= n) => BitPack (Index n) Source # |

Instance details

Defined in Clash.Sized.Internal.Index

Associated Types

type BitSize (Index n) |
Instance details Defined in Clash.Sized.Internal.Index type BitSize (Index n) = CLog 2 n

Methods

pack :: Index n -> BitVector (BitSize (Index n)) Source #

unpack :: BitVector (BitSize (Index n)) -> Index n Source #

(1 <= n, KnownNat n) => Counter (Index n) Source # |
Instance details Defined in Clash.Class.Counter.Internal Methods countMin :: Index n Source # countMax :: Index n Source # countSuccOverflow :: Index n -> (Bool, Index n) Source # countPredOverflow :: Index n -> (Bool, Index n) Source #
KnownNat m => Exp (Index m) Source # |
Instance details Defined in Clash.Class.Exp Methods (^) :: forall (n :: Nat). Index m -> SNat n -> ExpResult (Index m) n Source #
(KnownNat n, 1 <= n) => SaturatingNum (Index n) Source # |
Instance details Defined in Clash.Sized.Internal.Index Methods satAdd :: SaturationMode -> Index n -> Index n -> Index n Source # satSub :: SaturationMode -> Index n -> Index n -> Index n Source # satMul :: SaturationMode -> Index n -> Index n -> Index n Source # satSucc :: SaturationMode -> Index n -> Index n Source # satPred :: SaturationMode -> Index n -> Index n 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 Methods bundle :: forall (dom :: Domain). Unbundled dom (Index n) -> Signal dom (Index n) Source # unbundle :: forall (dom :: Domain). Signal dom (Index n) -> Unbundled dom (Index n) Source #
Bundle (Index n) Source # |
Instance details Defined in Clash.Signal.Delayed.Bundle Methods bundle :: forall (dom :: Domain) (d :: Nat). Unbundled dom d (Index n) -> DSignal dom d (Index n) Source # unbundle :: forall (dom :: Domain) (d :: Nat). DSignal dom d (Index n) -> Unbundled dom d (Index n) Source #
NFDataX (Index n) Source # |
Instance details Defined in Clash.Sized.Internal.Index Methods deepErrorX :: String -> Index n Source # hasUndefined :: Index n -> Bool Source # ensureSpine :: Index n -> Index n Source # rnfX :: Index n -> () Source #
ShowX (Index n) Source # |
Instance details Defined in Clash.Sized.Internal.Index Methods showsPrecX :: Int -> Index n -> ShowS Source # showX :: Index n -> String Source # showListX :: [Index n] -> ShowS Source #
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 -> () Source #
(KnownNat n, 1 <= n) => Bits (Index n) Source # |

Instance details

Defined in Clash.Sized.Internal.Index

Methods

(.&.) :: Index n -> Index n -> Index n Source #

(.|.) :: Index n -> Index n -> Index n Source #

xor :: Index n -> Index n -> Index n Source #

complement :: Index n -> Index n Source #

shift :: Index n -> Int -> Index n Source #

rotate :: Index n -> Int -> Index n Source #

zeroBits :: Index n Source #

bit :: Int -> Index n Source #

setBit :: Index n -> Int -> Index n Source #

clearBit :: Index n -> Int -> Index n Source #

complementBit :: Index n -> Int -> Index n Source #

testBit :: Index n -> Int -> Bool Source #

bitSizeMaybe :: Index n -> Maybe Int Source #

bitSize :: Index n -> Int Source #

isSigned :: Index n -> Bool Source #

shiftL :: Index n -> Int -> Index n Source #

unsafeShiftL :: Index n -> Int -> Index n Source #

shiftR :: Index n -> Int -> Index n Source #

unsafeShiftR :: Index n -> Int -> Index n Source #

rotateL :: Index n -> Int -> Index n Source #

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

popCount :: Index n -> Int Source #

(KnownNat n, 1 <= n) => FiniteBits (Index n) Source # |
Instance details Defined in Clash.Sized.Internal.Index Methods finiteBitSize :: Index n -> Int Source # countLeadingZeros :: Index n -> Int Source # countTrailingZeros :: Index n -> Int Source #
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) Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Index n) Source #

toConstr :: Index n -> Constr Source #

dataTypeOf :: Index n -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Index n)) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Index n)) Source #

gmapT :: (forall b. Data b => b -> b) -> Index n -> Index n Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Index n -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Index n -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> Index n -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Index n -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Index n -> m (Index n) Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Index n -> m (Index n) Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Index n -> m (Index n) Source #

KnownNat n => Bounded (Index n) Source # |
Instance details Defined in Clash.Sized.Internal.Index Methods minBound :: Index n Source # maxBound :: Index n Source #
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 Source #

pred :: Index n -> Index n Source #

toEnum :: Int -> Index n Source #

fromEnum :: Index n -> Int Source #

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

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

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

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

Generic (Index n) Source # |

Instance details

Defined in Clash.Sized.Internal.Index

Associated Types

type Rep (Index n) |
Instance details Defined in Clash.Sized.Internal.Index type Rep (Index n) = D1 ('MetaData "Index" "Clash.Sized.Internal.Index" "clash-prelude-1.8.4-1CKHk9HHRNIGPqhYHQsmcW" 'False) (C1 ('MetaCons "I" 'PrefixI 'True) (S1 ('MetaSel ('Just "unsafeToInteger") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Integer)))

Methods

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

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

KnownNat n => Ix (Index n) Source # |
Instance details Defined in Clash.Sized.Internal.Index Methods range :: (Index n, Index n) -> [Index n] Source # index :: (Index n, Index n) -> Index n -> Int Source # unsafeIndex :: (Index n, Index n) -> Index n -> Int Source # inRange :: (Index n, Index n) -> Index n -> Bool Source # rangeSize :: (Index n, Index n) -> Int Source # unsafeRangeSize :: (Index n, Index n) -> Int Source #
KnownNat n => Num (Index n) Source # | Operators report an error on overflow and underflow NB: `fromInteger`/`fromIntegral` can cause unexpected truncation, as `Integer` is arbitrarily bounded during synthesis. Prefer `bitCoerce` and the `Resize` class.
Instance details Defined in Clash.Sized.Internal.Index Methods (+) :: Index n -> Index n -> Index n Source # (-) :: Index n -> Index n -> Index n Source # (*) :: Index n -> Index n -> Index n Source # negate :: Index n -> Index n Source # abs :: Index n -> Index n Source # signum :: Index n -> Index n Source # fromInteger :: Integer -> Index n Source #
KnownNat n => Read (Index n) Source # | None of the `Read` class' methods are synthesizable.
Instance details Defined in Clash.Sized.Internal.Index Methods readsPrec :: Int -> ReadS (Index n) Source # readList :: ReadS [Index n] Source # readPrec :: ReadPrec (Index n) Source # readListPrec :: ReadPrec [Index n] Source #
KnownNat n => Integral (Index n) Source # | NB: `toInteger`/`fromIntegral` can cause unexpected truncation, as `Integer` is arbitrarily bounded during synthesis. Prefer `bitCoerce` and the `Resize` class.

Instance details

Defined in Clash.Sized.Internal.Index

Methods

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

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

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

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

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

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

toInteger :: Index n -> Integer Source #

KnownNat n => Real (Index n) Source # |
Instance details Defined in Clash.Sized.Internal.Index Methods toRational :: Index n -> Rational Source #
Show (Index n) Source # |
Instance details Defined in Clash.Sized.Internal.Index Methods showsPrec :: Int -> Index n -> ShowS Source # show :: Index n -> String Source # showList :: [Index n] -> ShowS Source #
Eq (Index n) Source # |
Instance details Defined in Clash.Sized.Internal.Index Methods (==) :: Index n -> Index n -> Bool Source # (/=) :: Index n -> Index n -> Bool Source #
Ord (Index n) Source # |
Instance details Defined in Clash.Sized.Internal.Index Methods compare :: Index n -> Index n -> Ordering Source # (<) :: Index n -> Index n -> Bool Source # (<=) :: Index n -> Index n -> Bool Source # (>) :: Index n -> Index n -> Bool Source # (>=) :: Index n -> Index n -> Bool Source # max :: Index n -> Index n -> Index n Source # min :: Index n -> Index n -> Index n Source #
ExtendingNum (Index m) (Index n) Source # |

Instance details

Defined in Clash.Sized.Internal.Index

Associated Types

type AResult (Index m) (Index n) |
Instance details Defined in Clash.Sized.Internal.Index type AResult (Index m) (Index n) = Index ((m + n) - 1)
type MResult (Index m) (Index n) |
Instance details Defined in Clash.Sized.Internal.Index type MResult (Index m) (Index n) = Index (((m - 1) * (n - 1)) + 1)

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 TryDomain t (Index n) Source # |
Instance details Defined in Clash.Class.HasDomain.HasSingleDomain type TryDomain t (Index n) = 'NotFound
type Unbundled dom (Index n) Source # |
Instance details Defined in Clash.Signal.Bundle type Unbundled dom (Index n) = Signal dom (Index n)
type BitSize (Index n) Source # |
Instance details Defined in Clash.Sized.Internal.Index type BitSize (Index n) = CLog 2 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.8.4-1CKHk9HHRNIGPqhYHQsmcW" 'False) (C1 ('MetaCons "I" 'PrefixI 'True) (S1 ('MetaSel ('Just "unsafeToInteger") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Integer)))
type ExpResult (Index m) n Source # |
Instance details Defined in Clash.Class.Exp type ExpResult (Index m) n = Index (Max 2 (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)

# Construction

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

Safely convert an `SNat` value to an `Index`

# Accessors

## Length information

size# :: forall (n :: Nat). (KnownNat n, 1 <= n) => Index n -> Int Source #

# Type classes

## BitPack

pack# :: forall (n :: Nat). Index n -> BitVector (CLog 2 n) Source #

unpack# :: forall (n :: Nat). (KnownNat n, 1 <= n) => BitVector (CLog 2 n) -> Index n Source #

## Eq

eq# :: forall (n :: Nat). Index n -> Index n -> Bool Source #

neq# :: forall (n :: Nat). Index n -> Index n -> Bool Source #

## Ord

lt# :: forall (n :: Nat). Index n -> Index n -> Bool Source #

ge# :: forall (n :: Nat). Index n -> Index n -> Bool Source #

gt# :: forall (n :: Nat). Index n -> Index n -> Bool Source #

le# :: forall (n :: Nat). Index n -> Index n -> Bool Source #

## Enum

toEnum# :: forall (n :: Nat). KnownNat n => Int -> Index n Source #

fromEnum# :: forall (n :: Nat). KnownNat n => Index n -> Int Source #

## Enum (not synthesizable)

enumFrom# :: forall (n :: Nat). KnownNat n => Index n -> [Index n] Source #

enumFromThen# :: forall (n :: Nat). KnownNat n => Index n -> Index n -> [Index n] Source #

enumFromTo# :: forall (n :: Nat). Index n -> Index n -> [Index n] Source #

enumFromThenTo# :: forall (n :: Nat). Index n -> Index n -> Index n -> [Index n] Source #

## Bounded

maxBound# :: forall (n :: Nat). KnownNat n => Index n Source #

## Num

(+#) :: forall (n :: Nat). KnownNat n => Index n -> Index n -> Index n Source #

(-#) :: forall (n :: Nat). KnownNat n => Index n -> Index n -> Index n Source #

(*#) :: forall (n :: Nat). KnownNat n => Index n -> Index n -> Index n Source #

negate# :: forall (n :: Nat). KnownNat n => Index n -> Index n Source #

fromInteger# :: forall (n :: Nat). KnownNat n => Integer -> Index n Source #

## ExtendingNum

plus# :: forall (m :: Nat) (n :: Nat). Index m -> Index n -> Index ((m + n) - 1) Source #

minus# :: forall (m :: Nat) (n :: Nat). Index m -> Index n -> Index ((m + n) - 1) Source #

times# :: forall (m :: Nat) (n :: Nat). Index m -> Index n -> Index (((m - 1) * (n - 1)) + 1) Source #

## Integral

quot# :: forall (n :: Nat). Index n -> Index n -> Index n Source #

rem# :: forall (n :: Nat). Index n -> Index n -> Index n Source #

toInteger# :: forall (n :: Nat). Index n -> Integer Source #

## Resize

resize# :: forall (m :: Nat) (n :: Nat). KnownNat m => Index n -> Index m Source #