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

Copyright(C) 2013-2016 University of Twente
2017 Google Inc.
2019 Myrtle Software Ltd
LicenseBSD2 (see the file LICENSE)
MaintainerChristiaan Baaij <christiaan.baaij@gmail.com>
Safe HaskellTrustworthy
LanguageHaskell2010
Extensions
  • Cpp
  • UndecidableInstances
  • MonoLocalBinds
  • ScopedTypeVariables
  • BangPatterns
  • TypeFamilies
  • ViewPatterns
  • GADTs
  • GADTSyntax
  • DataKinds
  • InstanceSigs
  • StandaloneDeriving
  • DeriveDataTypeable
  • DeriveFunctor
  • DeriveTraversable
  • DeriveFoldable
  • DeriveGeneric
  • DefaultSignatures
  • DeriveLift
  • DerivingStrategies
  • ConstrainedClassMethods
  • MultiParamTypeClasses
  • MagicHash
  • KindSignatures
  • TupleSections
  • TypeOperators
  • ExplicitNamespaces
  • ExplicitForAll
  • BinaryLiterals
  • TypeApplications

Clash.Explicit.Signal.Delayed

Contents

Description

 
Synopsis

Documentation

data DSignal (dom :: Domain) (delay :: Nat) a Source #

A synchronized signal with samples of type a, synchronized to clock clk, that has accumulated delay amount of samples delay along its path.

Instances
Functor (DSignal dom delay) Source # 
Instance details

Defined in Clash.Signal.Delayed.Internal

Methods

fmap :: (a -> b) -> DSignal dom delay a -> DSignal dom delay b #

(<$) :: a -> DSignal dom delay b -> DSignal dom delay a #

Applicative (DSignal dom delay) Source # 
Instance details

Defined in Clash.Signal.Delayed.Internal

Methods

pure :: a -> DSignal dom delay a #

(<*>) :: DSignal dom delay (a -> b) -> DSignal dom delay a -> DSignal dom delay b #

liftA2 :: (a -> b -> c) -> DSignal dom delay a -> DSignal dom delay b -> DSignal dom delay c #

(*>) :: DSignal dom delay a -> DSignal dom delay b -> DSignal dom delay b #

(<*) :: DSignal dom delay a -> DSignal dom delay b -> DSignal dom delay a #

Foldable (DSignal dom delay) Source # 
Instance details

Defined in Clash.Signal.Delayed.Internal

Methods

fold :: Monoid m => DSignal dom delay m -> m #

foldMap :: Monoid m => (a -> m) -> DSignal dom delay a -> m #

foldr :: (a -> b -> b) -> b -> DSignal dom delay a -> b #

foldr' :: (a -> b -> b) -> b -> DSignal dom delay a -> b #

foldl :: (b -> a -> b) -> b -> DSignal dom delay a -> b #

foldl' :: (b -> a -> b) -> b -> DSignal dom delay a -> b #

foldr1 :: (a -> a -> a) -> DSignal dom delay a -> a #

foldl1 :: (a -> a -> a) -> DSignal dom delay a -> a #

toList :: DSignal dom delay a -> [a] #

null :: DSignal dom delay a -> Bool #

length :: DSignal dom delay a -> Int #

elem :: Eq a => a -> DSignal dom delay a -> Bool #

maximum :: Ord a => DSignal dom delay a -> a #

minimum :: Ord a => DSignal dom delay a -> a #

sum :: Num a => DSignal dom delay a -> a #

product :: Num a => DSignal dom delay a -> a #

Traversable (DSignal dom delay) Source # 
Instance details

Defined in Clash.Signal.Delayed.Internal

Methods

traverse :: Applicative f => (a -> f b) -> DSignal dom delay a -> f (DSignal dom delay b) #

sequenceA :: Applicative f => DSignal dom delay (f a) -> f (DSignal dom delay a) #

mapM :: Monad m => (a -> m b) -> DSignal dom delay a -> m (DSignal dom delay b) #

sequence :: Monad m => DSignal dom delay (m a) -> m (DSignal dom delay a) #

Fractional a => Fractional (DSignal dom delay a) Source # 
Instance details

Defined in Clash.Signal.Delayed.Internal

Methods

(/) :: DSignal dom delay a -> DSignal dom delay a -> DSignal dom delay a #

recip :: DSignal dom delay a -> DSignal dom delay a #

fromRational :: Rational -> DSignal dom delay a #

Num a => Num (DSignal dom delay a) Source # 
Instance details

Defined in Clash.Signal.Delayed.Internal

Methods

(+) :: DSignal dom delay a -> DSignal dom delay a -> DSignal dom delay a #

(-) :: DSignal dom delay a -> DSignal dom delay a -> DSignal dom delay a #

(*) :: DSignal dom delay a -> DSignal dom delay a -> DSignal dom delay a #

negate :: DSignal dom delay a -> DSignal dom delay a #

abs :: DSignal dom delay a -> DSignal dom delay a #

signum :: DSignal dom delay a -> DSignal dom delay a #

fromInteger :: Integer -> DSignal dom delay a #

Show a => Show (DSignal dom delay a) Source # 
Instance details

Defined in Clash.Signal.Delayed.Internal

Methods

showsPrec :: Int -> DSignal dom delay a -> ShowS #

show :: DSignal dom delay a -> String #

showList :: [DSignal dom delay a] -> ShowS #

Lift a => Lift (DSignal dom delay a) Source # 
Instance details

Defined in Clash.Signal.Delayed.Internal

Methods

lift :: DSignal dom delay a -> Q Exp #

Arbitrary a => Arbitrary (DSignal dom delay a) Source # 
Instance details

Defined in Clash.Signal.Delayed.Internal

Methods

arbitrary :: Gen (DSignal dom delay a) #

shrink :: DSignal dom delay a -> [DSignal dom delay a] #

CoArbitrary a => CoArbitrary (DSignal dom delay a) Source # 
Instance details

Defined in Clash.Signal.Delayed.Internal

Methods

coarbitrary :: DSignal dom delay a -> Gen b -> Gen b #

Default a => Default (DSignal dom delay a) Source # 
Instance details

Defined in Clash.Signal.Delayed.Internal

Methods

def :: DSignal dom delay a #

type HasDomain dom1 (DSignal dom2 delay a) Source # 
Instance details

Defined in Clash.Class.HasDomain.HasSpecificDomain

type HasDomain dom1 (DSignal dom2 delay a) = DomEq dom1 dom2
type TryDomain t (DSignal dom delay a) Source # 
Instance details

Defined in Clash.Class.HasDomain.HasSingleDomain

type TryDomain t (DSignal dom delay a) = Found dom

Delay-annotated synchronous signals

delayed Source #

Arguments

:: (KnownDomain dom, KnownNat d, NFDataX a) 
=> Clock dom 
-> Reset dom 
-> Enable dom 
-> Vec d a

Initial values

-> DSignal dom n a 
-> DSignal dom (n + d) a 

Delay a DSignal for d periods.

delay3
  :: KnownDomain dom
  => Clock dom
  -> Reset dom
  -> Enable dom
  -> DSignal dom n Int
  -> DSignal dom (n + 3) Int
delay3 clk rst en = delayed clk rst en (-1 :> -1 :> -1 :> Nil)
>>> sampleN 7 (delay3 systemClockGen resetGen enableGen (dfromList [0..]))
[-1,-1,-1,-1,1,2,3]

delayedI Source #

Arguments

:: (KnownNat d, KnownDomain dom, NFDataX a) 
=> Clock dom 
-> Reset dom 
-> Enable dom 
-> a

Initial value

-> DSignal dom n a 
-> DSignal dom (n + d) a 

Delay a DSignal for d periods, where d is derived from the context.

delay2
  :: KnownDomain dom
  => Clock dom
  -> Reset dom
  -> Enable dom
  -> Int
  -> DSignal dom n Int
  -> DSignal dom (n + 2) Int
delay2 = delayedI
>>> sampleN 7 (delay2 systemClockGen resetGen enableGen (-1) (dfromList ([0..])))
[-1,-1,-1,1,2,3,4]

d can also be specified using type application:

>>> :t delayedI @3
delayedI @3
  :: ... =>
     Clock dom
     -> Reset dom
     -> Enable dom
     -> a
     -> DSignal dom n a
     -> DSignal dom (n + 3) a

delayN Source #

Arguments

:: (KnownDomain dom, NFDataX a) 
=> SNat d 
-> a

Initial value

-> Enable dom 
-> Clock dom 
-> DSignal dom n a 
-> DSignal dom (n + d) a 

Delay a DSignal for d cycles, the value at time 0..d-1 is a.

delayN2
  :: KnownDomain dom
  => Int
  -> Enable dom
  -> Clock dom
  -> DSignal dom n Int
  -> DSignal dom (n + 2) Int
delayN2 = delayN d2
>>> printX $ sampleN 6 (toSignal (delayN2 (-1) enableGen systemClockGen (dfromList [1..])))
[-1,-1,1,2,3,4]

delayI Source #

Arguments

:: (NFDataX a, KnownDomain dom, KnownNat d) 
=> a

Initial value

-> Enable dom 
-> Clock dom 
-> DSignal dom n a 
-> DSignal dom (n + d) a 

Delay a DSignal for d cycles, where d is derived from the context. The value at time 0..d-1 is a default value.

delayI2
  :: KnownDomain dom
  => Int
  -> Enable dom
  -> Clock dom
  -> DSignal dom n Int
  -> DSignal dom (n + 2) Int
delayI2 = delayI
>>> sampleN 6 (toSignal (delayI2 (-1) enableGen systemClockGen (dfromList [1..])))
[-1,-1,1,2,3,4]

You can also use type application to do the same: >>> sampleN 6 (toSignal (delayI @2 (-1) enableGen systemClockGen (dfromList [1..]))) [-1,-1,1,2,3,4]

delayedFold Source #

Arguments

:: (NFDataX a, KnownDomain dom, KnownNat delay, KnownNat k) 
=> SNat delay

Delay applied after each step

-> a

Initial value

-> (a -> a -> a)

Fold operation to apply

-> Enable dom 
-> Clock dom 
-> Vec (2 ^ k) (DSignal dom n a)

Vector input of size 2^k

-> DSignal dom (n + (delay * k)) a

Output Signal delayed by (delay * k)

Tree fold over a Vec of DSignals with a combinatorial function, and delaying delay cycles after each application. Values at times 0..(delay*k)-1 are set to a default.

countingSignals :: Vec 4 (DSignal dom 0 Int)
countingSignals = repeat (dfromList [0..])
>>> printX $ sampleN 6 (toSignal (delayedFold  d1 (-1) (+) enableGen systemClockGen countingSignals))
[-1,-2,0,4,8,12]
>>> printX $ sampleN 8 (toSignal (delayedFold d2 (-1) (*) enableGen systemClockGen countingSignals))
[-1,-1,1,1,0,1,16,81]

feedback :: (DSignal dom n a -> (DSignal dom n a, DSignal dom ((n + m) + 1) a)) -> DSignal dom n a Source #

Feed the delayed result of a function back to its input:

mac :: Clock dom -> Reset dom -> Enable dom
    -> DSignal dom 0 Int -> DSignal dom 0 Int -> DSignal dom 0 Int
mac clk rst en x y = feedback (mac' x y)
  where
    mac' :: DSignal dom 0 Int -> DSignal dom 0 Int -> DSignal dom 0 Int
         -> (DSignal dom 0 Int, DSignal dom 1 Int)
    mac' a b acc = let acc' = a * b + acc
                   in  (acc, delay clk rst en (singleton 0) acc')
>>> sampleN 7 (mac systemClockGen systemResetGen enableGen (dfromList [0..]) (dfromList [0..]))
[0,0,1,5,14,30,55]

Signal <-> DSignal conversion

fromSignal :: Signal dom a -> DSignal dom 0 a Source #

Signals are not delayed

sample s == dsample (fromSignal s)

toSignal :: DSignal dom delay a -> Signal dom a Source #

Strip a DSignal from its delay information.

List <-> DSignal conversion (not synthesizable)

dfromList :: NFDataX a => [a] -> DSignal dom 0 a Source #

Create a DSignal from a list

Every element in the list will correspond to a value of the signal for one clock cycle.

>>> sampleN 2 (dfromList [1,2,3,4,5])
[1,2]

NB: This function is not synthesizable

lazy versions

dfromList_lazy :: [a] -> DSignal dom 0 a Source #

Create a DSignal from a list

Every element in the list will correspond to a value of the signal for one clock cycle.

>>> sampleN 2 (dfromList [1,2,3,4,5])
[1,2]

NB: This function is not synthesizable

Experimental

unsafeFromSignal :: Signal dom a -> DSignal dom n a Source #

EXPERIMENTAL

Unsafely convert a Signal to any DSignal clk'.

NB: Should only be used to interface with functions specified in terms of Signal.

antiDelay :: SNat d -> DSignal dom (n + d) a -> DSignal dom n a Source #

EXPERIMENTAL

Access a delayed signal in the present.

mac :: Clock dom -> Reset dom -> Enable dom
    -> DSignal dom 0 Int -> DSignal dom 0 Int -> DSignal dom 0 Int
mac clk rst en x y = acc'
  where
    acc' = (x * y) + antiDelay d1 acc
    acc  = delay clk rst en (singleton 0) acc'