fixed

Pure Haskell large fixed-width integers.
git clone git://git.ppad.tech/fixed.git
Log | Files | Refs | README | LICENSE

commit c47d2494a6f51943cdaaff7b609c2a24203dd29f
parent 69057ac2daef283f52f2f7f00559efe06543fabb
Author: Jared Tobin <jared@jtobin.io>
Date:   Fri, 24 Jan 2025 16:59:28 +0400

bench: quotrem_knuth and friends

Diffstat:
Mbench/Main.hs | 50++++++++++++++++++++++++++++++++++++++++++++------
Mbench/Weight.hs | 7+++++++
Mlib/Data/Word/Extended.hs | 1-
3 files changed, 51 insertions(+), 7 deletions(-)

diff --git a/bench/Main.hs b/bench/Main.hs @@ -17,6 +17,7 @@ instance NFData W.Word320 instance NFData W.Word512 instance NFData W.Word576 instance NFData W.Word640 +instance NFData W.Word1152 or_baseline :: Benchmark or_baseline = bench "or (baseline)" $ nf ((.|.) w0) w1 where @@ -172,15 +173,52 @@ quotrem_by1 = env setup $ \ ~(quo, u, d) -> quotrem_by1_gen :: Benchmark quotrem_by1_gen = bench "quotrem_by1_gen" $ - nf (W.quotrem_by1_gen (W.Word576 300 200 100 0 0 0 0 0 0) 3) (B.complement 50) + nf (W.quotrem_by1_gen (W.Word576 300 200 100 0 0 0 0 0 0) 3) + (B.complement 50) + +quotrem_knuth :: Benchmark +quotrem_knuth = env setup $ \ ~(quo, u, d) -> + bench "quotrem_knuth" $ nfAppIO (W.quotrem_knuth quo u) d + where + setup = do + quo <- PA.newPrimArray 5 + PA.setPrimArray quo 0 5 0 + u <- PA.newPrimArray 9 + PA.setPrimArray u 0 9 0 + PA.writePrimArray u 0 2162362899639802732 + PA.writePrimArray u 0 8848548347662387477 + PA.writePrimArray u 0 13702897166684377657 + PA.writePrimArray u 0 16799544643779908154 + PA.writePrimArray u 0 1 + let !d = PA.primArrayFromList [ + 16950798510782491100 + , 2612788699139816405 + , 5146719872810836952 + , 14966148379609982000 + ] + pure (quo, u, d) + +quotrem_knuth_gen :: Benchmark +quotrem_knuth_gen = + bench "quotrem_knuth_gen" $ + nf (W.quotrem_knuth_gen u 5 d) 4 + where + !u = W.Word576 + 2162362899639802732 8848548347662387477 13702897166684377657 + 16799544643779908154 1 0 0 0 0 + !d = W.Word256 + 16950798510782491100 2612788699139816405 + 5146719872810836952 14966148379609982000 main :: IO () main = defaultMain [ - -- quotrem_by1 - -- , quotrem_by1_gen - div_baseline - , div_pure - , div + quotrem_knuth_gen + , quotrem_knuth + , quotrem_by1 + , quotrem_by1_gen + -- div_baseline + --, div_pure + --, div --, mul_baseline --, mul --, mod_baseline diff --git a/bench/Weight.hs b/bench/Weight.hs @@ -16,6 +16,8 @@ instance NFData E.Word320 instance NFData E.Word512 instance NFData E.Word576 instance NFData E.Word640 +instance NFData E.Word832 +instance NFData E.Word1152 i0, i1 :: Integer i0 = 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed @@ -59,4 +61,9 @@ main = do W.io "quotrem_by1" (E.quotrem_by1 q u) d W.func "quotrem_by1_gen" (E.quotrem_by1_gen (E.Word576 300 200 100 0 0 0 0 0 0) 3) (B.complement 50) + W.func "quotrem_gen" + (E.quotrem_gen (E.Word576 0x1234567890ABCDEF 0xFEDCBA0987654321 0x123456789ABCDEF0 0 0 0 0 0 0)) (E.Word256 0x0 0x0 0x1 0x100000000) + W.func "quotrem_knuth_gen" + (E.quotrem_knuth_gen (E.Word576 2162362899639802732 8848548347662387477 13702897166684377657 16799544643779908154 1 0 0 0 0) 5 (E.Word256 16950798510782491100 2612788699139816405 5146719872810836952 14966148379609982000)) 4 + diff --git a/lib/Data/Word/Extended.hs b/lib/Data/Word/Extended.hs @@ -81,7 +81,6 @@ data Word576 = Word576 zero576 :: Word576 zero576 = Word576 0 0 0 0 0 0 0 0 0 --- XX can i eliminate more of these? sel576 :: Word576 -> Int -> Word64 sel576 (Word576 a0 a1 a2 a3 a4 a5 a6 a7 a8) = \case 0 -> a0; 1 -> a1; 2 -> a2; 3 -> a3; 4 -> a4