Skip to content
This repository has been archived by the owner on Sep 7, 2018. It is now read-only.

Simplify type of window/windowD #123

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 8 additions & 17 deletions src/CLaSH/Explicit/Prelude.hs
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ import CLaSH.XException
{- $setup
>>> :set -XDataKinds -XTypeApplications
>>> import CLaSH.Explicit.Prelude
>>> let window4 = window @3
>>> let windowD3 = windowD @2
>>> let window4 = window @4
>>> let windowD3 = windowD @3
-}

-- | Give a window over a 'Signal'
Expand All @@ -181,15 +181,9 @@ window
=> Clock domain gated
-- ^ Clock to which the incoming signal is synchronized
-> Reset domain synchronous
-> Signal domain a -- ^ Signal to create a window over
-> Vec (n + 1) (Signal domain a) -- ^ Window of at least size 1
window clk rst x = res
where
res = x :> prev
prev = case natVal (asNatProxy prev) of
0 -> repeat def
_ -> let next = x +>> prev
in registerB clk rst (repeat def) next
-> Signal domain a -- ^ Signal to create a window over
-> Vec n (Signal domain a) -- ^ Window size
window clk rst = iterateI (register clk rst def)
{-# INLINABLE window #-}

-- | Give a delayed window over a 'Signal'
Expand All @@ -208,10 +202,7 @@ windowD
=> Clock domain gated
-- ^ Clock to which the incoming signal is synchronized
-> Reset domain synchronous
-> Signal domain a -- ^ Signal to create a window over
-> Vec (n + 1) (Signal domain a) -- ^ Window of at least size 1
windowD clk rst x =
let prev = registerB clk rst (repeat def) next
next = x +>> prev
in prev
-> Signal domain a -- ^ Signal to create a window over
-> Vec n (Signal domain a) -- ^ Window size
windowD clk rst = iterateI (register clk rst def) . register clk rst def
{-# INLINABLE windowD #-}
8 changes: 4 additions & 4 deletions src/CLaSH/Prelude.hs
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ It instead exports the identically named functions defined in terms of
-- ...
window
:: (KnownNat n, Default a, HasClockReset domain gated synchronous)
=> Signal domain a -- ^ Signal to create a window over
-> Vec (n + 1) (Signal domain a) -- ^ Window of at least size 1
=> Signal domain a -- ^ Signal to create a window over
-> Vec n (Signal domain a) -- ^ Window size
window = E.window hasClock hasReset
{-# INLINE window #-}

Expand All @@ -211,7 +211,7 @@ window = E.window hasClock hasReset
-- ...
windowD
:: (KnownNat n, Default a, HasClockReset domain gated synchronous)
=> Signal domain a -- ^ Signal to create a window over
-> Vec (n + 1) (Signal domain a) -- ^ Window of at least size 1
=> Signal domain a -- ^ Signal to create a window over
-> Vec n (Signal domain a) -- ^ Window size
windowD = E.windowD hasClock hasReset
{-# INLINE windowD #-}
3 changes: 1 addition & 2 deletions src/CLaSH/Sized/Internal/Index.hs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,12 @@ where
import Control.DeepSeq (NFData (..))
import Data.Data (Data)
import Data.Default (Default (..))
import Data.Function (on)
import Data.Proxy (Proxy (..))
import Text.Read (Read (..), ReadPrec)
import Language.Haskell.TH (TypeQ, appT, conT, litT, numTyLit, sigE)
import Language.Haskell.TH.Syntax (Lift(..))
import GHC.TypeLits (CmpNat, KnownNat, Nat, type (+), type (-),
type (*), type (<=), type (^), natVal)
type (*), type (<=), natVal)
import GHC.TypeLits.Extra (CLog)
import Test.QuickCheck.Arbitrary (Arbitrary (..), CoArbitrary (..),
arbitraryBoundedIntegral,
Expand Down