File: BenchVector.hs

package info (click to toggle)
haskell-clash-prelude 1.8.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,432 kB
  • sloc: haskell: 23,509; makefile: 6
file content (44 lines) | stat: -rw-r--r-- 1,229 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
{-# LANGUAGE CPP, DataKinds, MagicHash, TypeOperators, TemplateHaskell #-}
{-# LANGUAGE NoStarIsType #-}

{-# OPTIONS_GHC -ddump-simpl -ddump-splices -ddump-to-file #-}

#define WORD_SIZE_IN_BITS 64

module BenchVector (vectorBench) where

import Clash.Class.BitPack
import Clash.Promoted.Nat.Literals
import Clash.Sized.BitVector
import Clash.Sized.Vector
import Criterion                   (Benchmark, env, bench, nf, bgroup)
import Language.Haskell.TH.Syntax  (lift)
import Prelude                     hiding (replicate)

vectorBench :: Benchmark
vectorBench = bgroup "Vector"
  [ vectorPackBench
  , vectorUnpackBench
  ]

smallValue1 :: Vec 8 (BitVector 24)
smallValue1 = $(lift (replicate d8 (2^(16::Int)-10 :: BitVector 24)))
{-# INLINE smallValue1 #-}

smallValue2 :: BitVector 192
smallValue2 = $(lift (maxBound :: BitVector 192))
{-# INLINE smallValue2 #-}

vectorPackBench :: Benchmark
vectorPackBench = env setup $ \m ->
  bench "pack" $
  nf (pack :: Vec 8 (BitVector 24) -> BitVector 192) m
  where
    setup = return smallValue1

vectorUnpackBench :: Benchmark
vectorUnpackBench = env setup $ \m ->
  bench "unpack" $
  nf (unpack :: BitVector 192 -> Vec 8 (BitVector 24)) m
  where
    setup = return smallValue2