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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
|
{-# LANGUAGE CPP, DataKinds, MagicHash, TypeOperators, TemplateHaskell #-}
{-# LANGUAGE NoStarIsType #-}
{-# OPTIONS_GHC -ddump-simpl -ddump-splices -ddump-to-file #-}
#define WORD_SIZE_IN_BITS 64
module BenchSigned (signedBench) where
import Data.Bits
import Clash.Class.Num
import Clash.Class.BitPack
import Clash.Sized.BitVector
import Clash.Sized.Signed
import Criterion (Benchmark, env, bench, nf, bgroup)
import Language.Haskell.TH.Syntax (lift)
import GHC.TypeLits (type (*))
import BenchCommon
signedBench :: Benchmark
signedBench = bgroup "Signed"
[ fromIntegerBench
, addBench
, addBenchL
, negateBench
, negateBenchL
, subBench
, subBenchL
, multBench
, multBenchL
, plusBench
, minusBench
, timesBench
, boundedAddBench
, boundedSubBench
, boundedMulBench
, packBench
, unpackBench
, xorBench
, xorBenchL
, andBench
, andBenchL
, orBench
, orBenchL
, complementBench
, complementBenchL
]
smallValueI :: Integer
smallValueI = $(lift (2^(16::Int)-10 :: Integer))
{-# INLINE smallValueI #-}
smallValue1 :: Signed WORD_SIZE_IN_BITS
smallValue1 = $(lift (2^(16::Int)-10 :: Signed WORD_SIZE_IN_BITS))
{-# INLINE smallValue1 #-}
smallValue2 :: Signed WORD_SIZE_IN_BITS
smallValue2 = $(lift (2^(16::Int)-100 :: Signed WORD_SIZE_IN_BITS))
{-# INLINE smallValue2 #-}
smallValueBV :: BitVector WORD_SIZE_IN_BITS
smallValueBV = $(lift (2^(16::Int)-10 :: BitVector WORD_SIZE_IN_BITS))
{-# INLINE smallValueBV #-}
largeValue1 :: Signed (3*WORD_SIZE_IN_BITS)
largeValue1 = $(lift (2^(2*WORD_SIZE_IN_BITS :: Int)-10 :: Signed (3*WORD_SIZE_IN_BITS)))
{-# INLINE largeValue1 #-}
largeValue2 :: Signed (3*WORD_SIZE_IN_BITS)
largeValue2 = $(lift (2^(2*WORD_SIZE_IN_BITS :: Int)-100 :: Signed (3*WORD_SIZE_IN_BITS)))
{-# INLINE largeValue2 #-}
fromIntegerBench :: Benchmark
fromIntegerBench = env setup $ \m ->
bench "fromInteger WORD_SIZE_IN_BITS" $
nf (fromInteger :: Integer -> Signed WORD_SIZE_IN_BITS) m
where
setup = return smallValueI
addBench :: Benchmark
addBench = env setup $ \m ->
bench "+ WORD_SIZE_IN_BITS" $ nf (apSwapAp (+)) m
where
setup = return (smallValue1,smallValue2)
addBenchL :: Benchmark
addBenchL = env setup $ \m ->
bench "+ 3*WORD_SIZE_IN_BITS" $ nf (apSwapAp (+)) m
where
setup = return (largeValue1,largeValue2)
negateBench :: Benchmark
negateBench = env setup $ \m ->
bench "negate WORD_SIZE_IN_BITS" $ nf negate m
where
setup = return smallValue1
negateBenchL :: Benchmark
negateBenchL = env setup $ \m ->
bench "negate 3*WORD_SIZE_IN_BITS" $ nf negate m
where
setup = return largeValue1
subBench :: Benchmark
subBench = env setup $ \m ->
bench "- WORD_SIZE_IN_BITS" $ nf (apSwapAp (-)) m
where
setup = return (smallValue1,smallValue2)
subBenchL :: Benchmark
subBenchL = env setup $ \m ->
bench "- 3*WORD_SIZE_IN_BITS" $ nf (apSwapAp (-)) m
where
setup = return (largeValue1,largeValue2)
multBench :: Benchmark
multBench = env setup $ \m ->
bench "* WORD_SIZE_IN_BITS" $ nf (apSwapAp (*)) m
where
setup = return (smallValue1,smallValue2)
multBenchL :: Benchmark
multBenchL = env setup $ \m ->
bench "* 3*WORD_SIZE_IN_BITS" $ nf (apSwapAp (*)) m
where
setup = return (largeValue1,largeValue2)
plusBench :: Benchmark
plusBench = env setup $ \m ->
bench "plus WORD_SIZE_IN_BITS" $ nf (apSwapAp2 add add) m
where
setup = return (smallValue1,smallValue2)
minusBench :: Benchmark
minusBench = env setup $ \m ->
bench "minus WORD_SIZE_IN_BITS" $ nf (apSwapAp2 sub sub) m
where
setup = return (smallValue1,smallValue2)
timesBench :: Benchmark
timesBench = env setup $ \m ->
bench "times WORD_SIZE_IN_BITS" $ nf (apSwapAp2 mul mul) m
where
setup = return (smallValue1,smallValue2)
boundedAddBench :: Benchmark
boundedAddBench = env setup $ \m ->
bench "boundedAdd WORD_SIZE_IN_BITS" $ nf (apSwapAp boundedAdd) m
where
setup = return (smallValue1,smallValue2)
boundedSubBench :: Benchmark
boundedSubBench = env setup $ \m ->
bench "boundedSub WORD_SIZE_IN_BITS" $ nf (apSwapAp boundedSub) m
where
setup = return (smallValue1,smallValue2)
boundedMulBench :: Benchmark
boundedMulBench = env setup $ \m ->
bench "boundedMul WORD_SIZE_IN_BITS" $ nf (apSwapAp boundedMul) m
where
setup = return (smallValue1,smallValue2)
packBench :: Benchmark
packBench = env setup $ \m ->
bench "pack WORD_SIZE_IN_BITS" $ nf pack m
where
setup = return smallValue1
unpackBench :: Benchmark
unpackBench = env setup $ \m ->
bench "unpack WORD_SIZE_IN_BITS" $
nf (unpack :: BitVector WORD_SIZE_IN_BITS -> Signed WORD_SIZE_IN_BITS) m
where
setup = return smallValueBV
xorBench :: Benchmark
xorBench = env setup $ \m ->
bench "xor WORD_SIZE_IN_BITS" $ nf (apSwapAp xor) m
where
setup = return (smallValue1,smallValue2)
xorBenchL :: Benchmark
xorBenchL = env setup $ \m ->
bench "xor 3*WORD_SIZE_IN_BITS" $ nf (apSwapAp xor) m
where
setup = return (largeValue1,largeValue2)
andBench :: Benchmark
andBench = env setup $ \m ->
bench ".&. WORD_SIZE_IN_BITS" $ nf (apSwapAp (.&.)) m
where
setup = return (smallValue1,smallValue2)
andBenchL :: Benchmark
andBenchL = env setup $ \m ->
bench ".&. 3*WORD_SIZE_IN_BITS" $ nf (apSwapAp (.&.)) m
where
setup = return (largeValue1,largeValue2)
orBench :: Benchmark
orBench = env setup $ \m ->
bench ".|. WORD_SIZE_IN_BITS" $ nf (apSwapAp (.|.)) m
where
setup = return (smallValue1,smallValue2)
orBenchL :: Benchmark
orBenchL = env setup $ \m ->
bench ".|. 3*WORD_SIZE_IN_BITS" $ nf (apSwapAp (.|.)) m
where
setup = return (largeValue1,largeValue2)
complementBench :: Benchmark
complementBench = env setup $ \m ->
bench "complement WORD_SIZE_IN_BITS" $ nf complement m
where
setup = return smallValue1
complementBenchL :: Benchmark
complementBenchL = env setup $ \m ->
bench "complement 3*WORD_SIZE_IN_BITS" $ nf complement m
where
setup = return largeValue1
|