X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=mmult.hs;fp=mmult.hs;h=efed9a0edfcd4fd5b4e5e938fc49ad914fb9e22e;hb=a37aac300ad93f0fd5edbed645655c2af2915002;hp=0000000000000000000000000000000000000000;hpb=e6ccae0292cdcf1c47eae5c939f6def8f36560a3;p=matthijs%2Fmaster-project%2Fc%CE%BBash.git diff --git a/mmult.hs b/mmult.hs new file mode 100644 index 0000000..efed9a0 --- /dev/null +++ b/mmult.hs @@ -0,0 +1,32 @@ +{-# LANGUAGE TypeOperators, TemplateHaskell, TypeFamilies, ScopedTypeVariables, FlexibleContexts #-} + +module MMult where + +-- hide default prelude functions +import qualified Prelude as P + +-- import CλaSH specific types +import CLasH.HardwareTypes +import CLasH.Translator.Annotations + +type Word = Signed D16 + +foldl1 f xs = foldl f (head xs) (tail xs) +as ** bs = foldl1 (+) (zipWith (*) as bs) + +{-# ANN mmult2x4_4x3 TopEntity #-} +mmult2x4_4x3 :: Vector D2 (Vector D4 Word) -> Vector D4 (Vector D3 Word) -> Vector D2 (Vector D3 Word) +mmult2x4_4x3 a b = mmult a b + +mmult xss yss = map f xss + where + f xs = map (xs **) colsy + colsy = transpose yss (iterate (1+) 0) + +transpose :: + ( PositiveT s1 + , PositiveT s2 + ) => Vector s1 (Vector s2 a) -> + Vector s2 (Index s2) -> + Vector s2 (Vector s1 a) +transpose m ixs = map (\x-> map (!x) m) ixs \ No newline at end of file