clash-prelude-1.6.4: Clash: a functional hardware description language - Prelude library
Copyright(C) 2019 Google Inc.
2021-2022 QBayLogic B.V.
2021-2022 Myrtle.ai
LicenseBSD2 (see the file LICENSE)
MaintainerQBayLogic B.V. <devops@qbaylogic.com>
Safe HaskellNone
LanguageHaskell2010

Clash.Class.AutoReg.Internal

Description

 
Synopsis

Documentation

class NFDataX a => AutoReg a where Source #

autoReg is a "smart" version of register. It does two things:

  1. It splits product types over their fields. For example, given a 3-tuple, the corresponding HDL will end up with three instances of a register (or more if the three fields can be split up similarly).
  2. Given a data type where a constructor indicates (parts) of the data will (not) be updated a given cycle, it will split the data in two parts. The first part will contain the "always interesting" parts (the constructor bits). The second holds the "potentially uninteresting" data (the rest). Both parts will be stored in separate registers. The register holding the "potentially uninteresting" part will only be enabled if the constructor bits indicate they're interesting.

The most important example of this is Maybe. Consider Maybe (Signed 16); when viewed as bits, a Nothing would look like:

>>> pack @(Maybe (Signed 16)) Nothing
0b0_...._...._...._....

and Just

>>> pack @(Maybe (Signed 16)) (Just 3)
0b1_0000_0000_0000_0011

In the first case, Nothing, we don't particularly care about updating the register holding the Signed 16 field, as they'll be unknown anyway. We can therefore deassert its enable line.

Making Clash lay it out like this increases the chances of synthesis tools clock gating the registers, saving energy.

This version of autoReg will split the given data type up recursively. For example, given a :: Maybe (Maybe Int, Maybe Int), a total of five registers will be rendered. Both the "interesting" and "uninteresting" enable lines of the inner Maybe types will be controlled by the outer one, in addition to the inner parts controlling their "uninteresting" parts as described in (2).

The default implementation is just register. If you don't need or want the special features of AutoReg, you can use that by writing an empty instance.

data MyDataType = ...
instance AutoReg MyDataType

If you have a product type you can use deriveAutoReg to derive an instance.

Minimal complete definition

Nothing

Methods

autoReg Source #

Arguments

:: (HasCallStack, KnownDomain dom) 
=> Clock dom 
-> Reset dom 
-> Enable dom 
-> a

Reset value

-> Signal dom a 
-> Signal dom a 

For documentation see class AutoReg.

This is the version with explicit clock/reset/enable inputs, Clash.Prelude exports an implicit version of this: autoReg

Instances

Instances details
AutoReg Bool Source # 
Instance details

Defined in Clash.Class.AutoReg.Internal

Methods

autoReg :: forall (dom :: Domain). (HasCallStack, KnownDomain dom) => Clock dom -> Reset dom -> Enable dom -> Bool -> Signal dom Bool -> Signal dom Bool Source #

AutoReg Char Source # 
Instance details

Defined in Clash.Class.AutoReg.Internal

Methods

autoReg :: forall (dom :: Domain). (HasCallStack, KnownDomain dom) => Clock dom -> Reset dom -> Enable dom -> Char -> Signal dom Char -> Signal dom Char Source #

AutoReg Double Source # 
Instance details

Defined in Clash.Class.AutoReg.Internal

Methods

autoReg :: forall (dom :: Domain). (HasCallStack, KnownDomain dom) => Clock dom -> Reset dom -> Enable dom -> Double -> Signal dom Double -> Signal dom Double Source #

AutoReg Float Source # 
Instance details

Defined in Clash.Class.AutoReg.Internal

Methods

autoReg :: forall (dom :: Domain). (HasCallStack, KnownDomain dom) => Clock dom -> Reset dom -> Enable dom -> Float -> Signal dom Float -> Signal dom Float Source #

AutoReg Int Source # 
Instance details

Defined in Clash.Class.AutoReg.Internal

Methods

autoReg :: forall (dom :: Domain). (HasCallStack, KnownDomain dom) => Clock dom -> Reset dom -> Enable dom -> Int -> Signal dom Int -> Signal dom Int Source #

AutoReg Int8 Source # 
Instance details

Defined in Clash.Class.AutoReg.Internal

Methods

autoReg :: forall (dom :: Domain). (HasCallStack, KnownDomain dom) => Clock dom -> Reset dom -> Enable dom -> Int8 -> Signal dom Int8 -> Signal dom Int8 Source #

AutoReg Int16 Source # 
Instance details

Defined in Clash.Class.AutoReg.Internal

Methods

autoReg :: forall (dom :: Domain). (HasCallStack, KnownDomain dom) => Clock dom -> Reset dom -> Enable dom -> Int16 -> Signal dom Int16 -> Signal dom Int16 Source #

AutoReg Int32 Source # 
Instance details

Defined in Clash.Class.AutoReg.Internal

Methods

autoReg :: forall (dom :: Domain). (HasCallStack, KnownDomain dom) => Clock dom -> Reset dom -> Enable dom -> Int32 -> Signal dom Int32 -> Signal dom Int32 Source #

AutoReg Int64 Source # 
Instance details

Defined in Clash.Class.AutoReg.Internal

Methods

autoReg :: forall (dom :: Domain). (HasCallStack, KnownDomain dom) => Clock dom -> Reset dom -> Enable dom -> Int64 -> Signal dom Int64 -> Signal dom Int64 Source #

AutoReg Integer Source # 
Instance details

Defined in Clash.Class.AutoReg.Internal

Methods

autoReg :: forall (dom :: Domain). (HasCallStack, KnownDomain dom) => Clock dom -> Reset dom -> Enable dom -> Integer -> Signal dom Integer -> Signal dom Integer Source #

AutoReg Word Source # 
Instance details

Defined in Clash.Class.AutoReg.Internal

Methods

autoReg :: forall (dom :: Domain). (HasCallStack, KnownDomain dom) => Clock dom -> Reset dom -> Enable dom -> Word -> Signal dom Word -> Signal dom Word Source #

AutoReg Word8 Source # 
Instance details

Defined in Clash.Class.AutoReg.Internal

Methods

autoReg :: forall (dom :: Domain). (HasCallStack, KnownDomain dom) => Clock dom -> Reset dom -> Enable dom -> Word8 -> Signal dom Word8 -> Signal dom Word8 Source #

AutoReg Word16 Source # 
Instance details

Defined in Clash.Class.AutoReg.Internal

Methods

autoReg :: forall (dom :: Domain). (HasCallStack, KnownDomain dom) => Clock dom -> Reset dom -> Enable dom -> Word16 -> Signal dom Word16 -> Signal dom Word16 Source #

AutoReg Word32 Source # 
Instance details

Defined in Clash.Class.AutoReg.Internal

Methods

autoReg :: forall (dom :: Domain). (HasCallStack, KnownDomain dom) => Clock dom -> Reset dom -> Enable dom -> Word32 -> Signal dom Word32 -> Signal dom Word32 Source #

AutoReg Word64 Source # 
Instance details

Defined in Clash.Class.AutoReg.Internal

Methods

autoReg :: forall (dom :: Domain). (HasCallStack, KnownDomain dom) => Clock dom -> Reset dom -> Enable dom -> Word64 -> Signal dom Word64 -> Signal dom Word64 Source #

AutoReg () Source # 
Instance details

Defined in Clash.Class.AutoReg.Internal

Methods

autoReg :: forall (dom :: Domain). (HasCallStack, KnownDomain dom) => Clock dom -> Reset dom -> Enable dom -> () -> Signal dom () -> Signal dom () Source #

AutoReg CUShort Source # 
Instance details

Defined in Clash.Class.AutoReg.Internal

Methods

autoReg :: forall (dom :: Domain). (HasCallStack, KnownDomain dom) => Clock dom -> Reset dom -> Enable dom -> CUShort -> Signal dom CUShort -> Signal dom CUShort Source #

AutoReg Half Source # 
Instance details

Defined in Clash.Class.AutoReg.Internal

Methods

autoReg :: forall (dom :: Domain). (HasCallStack, KnownDomain dom) => Clock dom -> Reset dom -> Enable dom -> Half -> Signal dom Half -> Signal dom Half Source #

AutoReg Bit Source # 
Instance details

Defined in Clash.Class.AutoReg.Internal

Methods

autoReg :: forall (dom :: Domain). (HasCallStack, KnownDomain dom) => Clock dom -> Reset dom -> Enable dom -> Bit -> Signal dom Bit -> Signal dom Bit Source #

AutoReg a => AutoReg (Maybe a) Source # 
Instance details

Defined in Clash.Class.AutoReg.Internal

Methods

autoReg :: forall (dom :: Domain). (HasCallStack, KnownDomain dom) => Clock dom -> Reset dom -> Enable dom -> Maybe a -> Signal dom (Maybe a) -> Signal dom (Maybe a) Source #

AutoReg a => AutoReg (Ratio a) Source # 
Instance details

Defined in Clash.Class.AutoReg.Instances

Methods

autoReg :: forall (dom :: Domain). (HasCallStack, KnownDomain dom) => Clock dom -> Reset dom -> Enable dom -> Ratio a -> Signal dom (Ratio a) -> Signal dom (Ratio a) Source #

AutoReg a => AutoReg (Complex a) Source # 
Instance details

Defined in Clash.Class.AutoReg.Instances

Methods

autoReg :: forall (dom :: Domain). (HasCallStack, KnownDomain dom) => Clock dom -> Reset dom -> Enable dom -> Complex a -> Signal dom (Complex a) -> Signal dom (Complex a) Source #

AutoReg a => AutoReg (Down a) Source # 
Instance details

Defined in Clash.Class.AutoReg.Instances

Methods

autoReg :: forall (dom :: Domain). (HasCallStack, KnownDomain dom) => Clock dom -> Reset dom -> Enable dom -> Down a -> Signal dom (Down a) -> Signal dom (Down a) Source #

KnownNat n => AutoReg (BitVector n) Source # 
Instance details

Defined in Clash.Class.AutoReg.Internal

Methods

autoReg :: forall (dom :: Domain). (HasCallStack, KnownDomain dom) => Clock dom -> Reset dom -> Enable dom -> BitVector n -> Signal dom (BitVector n) -> Signal dom (BitVector n) 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 #

AutoReg (Unsigned n) Source # 
Instance details

Defined in Clash.Class.AutoReg.Internal

Methods

autoReg :: forall (dom :: Domain). (HasCallStack, KnownDomain dom) => Clock dom -> Reset dom -> Enable dom -> Unsigned n -> Signal dom (Unsigned n) -> Signal dom (Unsigned n) Source #

AutoReg (Signed n) Source # 
Instance details

Defined in Clash.Class.AutoReg.Internal

Methods

autoReg :: forall (dom :: Domain). (HasCallStack, KnownDomain dom) => Clock dom -> Reset dom -> Enable dom -> Signed n -> Signal dom (Signed n) -> Signal dom (Signed n) Source #

(AutoReg a, AutoReg b) => AutoReg (a, b) Source # 
Instance details

Defined in Clash.Class.AutoReg.Instances

Methods

autoReg :: forall (dom :: Domain). (HasCallStack, KnownDomain dom) => Clock dom -> Reset dom -> Enable dom -> (a, b) -> Signal dom (a, b) -> Signal dom (a, b) Source #

(KnownNat n, AutoReg a) => AutoReg (Vec n a) Source # 
Instance details

Defined in Clash.Class.AutoReg.Internal

Methods

autoReg :: forall (dom :: Domain). (HasCallStack, KnownDomain dom) => Clock dom -> Reset dom -> Enable dom -> Vec n a -> Signal dom (Vec n a) -> Signal dom (Vec n a) Source #

(KnownNat d, AutoReg a) => AutoReg (RTree d a) Source # 
Instance details

Defined in Clash.Class.AutoReg.Internal

Methods

autoReg :: forall (dom :: Domain). (HasCallStack, KnownDomain dom) => Clock dom -> Reset dom -> Enable dom -> RTree d a -> Signal dom (RTree d a) -> Signal dom (RTree d a) Source #

(AutoReg a, AutoReg b, AutoReg c) => AutoReg (a, b, c) Source #

N.B.: The documentation only shows instances up to 3-tuples. By default, instances up to and including 12-tuples will exist. If the flag large-tuples is set instances up to the GHC imposed limit will exist. The GHC imposed limit is either 62 or 64 depending on the GHC version.

Instance details

Defined in Clash.Class.AutoReg.Instances

Methods

autoReg :: forall (dom :: Domain). (HasCallStack, KnownDomain dom) => Clock dom -> Reset dom -> Enable dom -> (a, b, c) -> Signal dom (a, b, c) -> Signal dom (a, b, c) Source #

NFDataX (rep (int + frac)) => AutoReg (Fixed rep int frac) Source # 
Instance details

Defined in Clash.Class.AutoReg.Internal

Methods

autoReg :: forall (dom :: Domain). (HasCallStack, KnownDomain dom) => Clock dom -> Reset dom -> Enable dom -> Fixed rep int frac -> Signal dom (Fixed rep int frac) -> Signal dom (Fixed rep int frac) Source #

deriveAutoReg :: Name -> DecsQ Source #

Automatically derives an AutoReg instance for a product type

Usage:

data Pair a b = MkPair { getA :: a, getB :: b } deriving (Generic, NFDataX)
data Tup3 a b c = MkTup3 { getAB :: Pair a b, getC :: c } deriving (Generic, NFDataX)
deriveAutoReg ''Pair
deriveAutoReg ''Tup3

NB: Because of the way template haskell works the order here matters, if you try to deriveAutoReg ''Tup3 before Pair it will complain about missing an instance AutoReg (Pair a b).