38 lines
988 B
Haskell
38 lines
988 B
Haskell
-- https://github.com/clash-lang/clash-compiler/blob/master/examples/MatrixVect.hs
|
|
|
|
module MulVecMatrix where
|
|
|
|
import Clash.Prelude
|
|
import qualified Data.List as L
|
|
|
|
row1 = 1 :> 2 :> 3 :> Nil
|
|
row2 = 4 :> 5 :> 6 :> Nil
|
|
row3 = 7 :> 8 :> 9 :> Nil
|
|
|
|
matrix = row1 :> row2 :> row3 :> Nil
|
|
-- [[1, 2, 3],
|
|
-- [4, 5, 6],
|
|
-- [7, 8, 9]]
|
|
|
|
dotProduct v1 v2 = foldr (+) 0
|
|
(zipWith (*) v1 v2)
|
|
-- λ> dotProduct [1,2,3] [4,5,6]
|
|
-- 32
|
|
|
|
mulVecMatrix m v = map (dotProduct v) m
|
|
|
|
topEntity :: Vec 3 (Signed 16) -> Vec 3 (Signed 16)
|
|
topEntity = mulVecMatrix matrix
|
|
{-# NOINLINE topEntity #-}
|
|
|
|
|
|
import Clash.Explicit.Testbench
|
|
testBench :: Signal System Bool
|
|
testBench = done
|
|
where
|
|
testInput = stimuliGenerator clk rst ((2 :> 3 :> 4 :> Nil) :> Nil)
|
|
expectedOutput = outputVerifier' clk rst ((20 :> 47 :> 74 :> Nil) :> Nil)
|
|
done = expectedOutput (topEntity <$> testInput)
|
|
clk = tbSystemClockGen (not <$> done)
|
|
rst = systemResetGen
|