fixed

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

commit 59753b492b5a6e64e35a93ae4cd4ceedc53e7f7c
parent 9e0c922a934c352813e80b6cc9e6234645ae1621
Author: Jared Tobin <jared@jtobin.io>
Date:   Sat,  6 Dec 2025 13:06:37 +0400

bench: don't measure fromInteger allocation

Diffstat:
Mbench/Weight.hs | 113++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------
1 file changed, 74 insertions(+), 39 deletions(-)

diff --git a/bench/Weight.hs b/bench/Weight.hs @@ -20,54 +20,89 @@ main = mainWith $ do retr add :: Weigh () -add = wgroup "add" $ do - func "curve: M(1) + M(2)" (C.add 1) 2 - func "curve: M(1) + M(2 ^ 255 - 19)" (C.add 1) (2 ^ 255 - 19) - func "scalar: M(1) + M(2)" (S.add 1) 2 - func "scalar: M(1) + M(2 ^ 255 - 19)" (S.add 1) (2 ^ 255 - 19) +add = + let !c1 = 1 :: C.Montgomery + !c2 = 2 :: C.Montgomery + !c_big = (2 ^ 255 - 19) :: C.Montgomery + !s1 = 1 :: S.Montgomery + !s2 = 2 :: S.Montgomery + !s_big = (2 ^ 255 - 19) :: S.Montgomery + in wgroup "add" $ do + func "curve: M(1) + M(2)" (C.add c1) c2 + func "curve: M(1) + M(2 ^ 255 - 19)" (C.add c1) c_big + func "scalar: M(1) + M(2)" (S.add s1) s2 + func "scalar: M(1) + M(2 ^ 255 - 19)" (S.add s1) s_big sub :: Weigh () -sub = wgroup "sub" $ do - func "curve: M(2 ^ 255 - 1) - M(1)" - (C.sub (2 ^ 255 - 1)) 1 - func "curve: M(2 ^ 255 - 1) - M(2 ^ 255 - 19)" - (C.sub (2 ^ 255 - 1)) (2 ^ 255 - 19) - func "scalar: M(2 ^ 255 - 1) - M(1)" - (S.sub (2 ^ 255 - 1)) 1 - func "scalar: M(2 ^ 255 - 1) - M(2 ^ 255 - 19)" - (S.sub (2 ^ 255 - 1)) (2 ^ 255 - 19) +sub = + let !c_max = (2 ^ 255 - 1) :: C.Montgomery + !c1 = 1 :: C.Montgomery + !c_big = (2 ^ 255 - 19) :: C.Montgomery + !s_max = (2 ^ 255 - 1) :: S.Montgomery + !s1 = 1 :: S.Montgomery + !s_big = (2 ^ 255 - 19) :: S.Montgomery + in wgroup "sub" $ do + func "curve: M(2 ^ 255 - 1) - M(1)" (C.sub c_max) c1 + func "curve: M(2 ^ 255 - 1) - M(2 ^ 255 - 19)" (C.sub c_max) c_big + func "scalar: M(2 ^ 255 - 1) - M(1)" (S.sub s_max) s1 + func "scalar: M(2 ^ 255 - 1) - M(2 ^ 255 - 19)" (S.sub s_max) s_big mul :: Weigh () -mul = wgroup "mul" $ do - func "curve: M(2) * M(2)" (C.mul 2) 2 - func "curve: M(2) * M(2 ^ 255 - 19)" (C.mul 2) (2 ^ 255 - 19) - func "scalar: M(2) * M(2)" (S.mul 2) 2 - func "scalar: M(2) * M(2 ^ 255 - 19)" (S.mul 2) (2 ^ 255 - 19) +mul = + let !c2 = 2 :: C.Montgomery + !c_big = (2 ^ 255 - 19) :: C.Montgomery + !s2 = 2 :: S.Montgomery + !s_big = (2 ^ 255 - 19) :: S.Montgomery + in wgroup "mul" $ do + func "curve: M(2) * M(2)" (C.mul c2) c2 + func "curve: M(2) * M(2 ^ 255 - 19)" (C.mul c2) c_big + func "scalar: M(2) * M(2)" (S.mul s2) s2 + func "scalar: M(2) * M(2 ^ 255 - 19)" (S.mul s2) s_big sqr :: Weigh () -sqr = wgroup "sqr" $ do - func "curve: M(2) ^ 2" C.sqr 2 - func "curve: M(2 ^ 255 - 19) ^ 2" C.sqr (2 ^ 255 - 19) - func "scalar: M(2) ^ 2" S.sqr 2 - func "scalar: M(2 ^ 255 - 19) ^ 2" S.sqr (2 ^ 255 - 19) +sqr = + let !c2 = 2 :: C.Montgomery + !c_big = (2 ^ 255 - 19) :: C.Montgomery + !s2 = 2 :: S.Montgomery + !s_big = (2 ^ 255 - 19) :: S.Montgomery + in wgroup "sqr" $ do + func "curve: M(2) ^ 2" C.sqr c2 + func "curve: M(2 ^ 255 - 19) ^ 2" C.sqr c_big + func "scalar: M(2) ^ 2" S.sqr s2 + func "scalar: M(2 ^ 255 - 19) ^ 2" S.sqr s_big inv :: Weigh () -inv = wgroup "inv" $ do - func "curve: M(2) ^ -1" C.inv 2 - func "curve: M(2 ^ 255 - 19) ^ -1" C.inv (2 ^ 255 - 19) - func "scalar: M(2) ^ -1" S.inv 2 - func "scalar: M(2 ^ 255 - 19) ^ -1" S.inv (2 ^ 255 - 19) +inv = + let !c2 = 2 :: C.Montgomery + !c_big = (2 ^ 255 - 19) :: C.Montgomery + !s2 = 2 :: S.Montgomery + !s_big = (2 ^ 255 - 19) :: S.Montgomery + in wgroup "inv" $ do + func "curve: M(2) ^ -1" C.inv c2 + func "curve: M(2 ^ 255 - 19) ^ -1" C.inv c_big + func "scalar: M(2) ^ -1" S.inv s2 + func "scalar: M(2 ^ 255 - 19) ^ -1" S.inv s_big redc :: Weigh () -redc = wgroup "redc" $ do - func "curve: REDC(M(2), M(2))" (C.redc 2) 2 - func "curve: REDC(M(2), M(2 ^ 255 - 19))" (C.redc 2) (2 ^ 255 - 19) - func "scalar: REDC(M(2), M(2))" (S.redc 2) 2 - func "scalar: REDC(M(2), M(2 ^ 255 - 19))" (S.redc 2) (2 ^ 255 - 19) +redc = + let !c2 = 2 :: C.Montgomery + !c_big = (2 ^ 255 - 19) :: C.Montgomery + !s2 = 2 :: S.Montgomery + !s_big = (2 ^ 255 - 19) :: S.Montgomery + in wgroup "redc" $ do + func "curve: REDC(M(2), M(2))" (C.redc c2) c2 + func "curve: REDC(M(2), M(2 ^ 255 - 19))" (C.redc c2) c_big + func "scalar: REDC(M(2), M(2))" (S.redc s2) s2 + func "scalar: REDC(M(2), M(2 ^ 255 - 19))" (S.redc s2) s_big retr :: Weigh () -retr = wgroup "retr" $ do - func "curve: RETR(M(2))" C.retr 2 - func "curve: RETR(M(2 ^ 255 - 19))" C.retr (2 ^ 255 - 19) - func "scalar: RETR(M(2))" S.retr 2 - func "scalar: RETR(M(2 ^ 255 - 19))" S.retr (2 ^ 255 - 19) +retr = + let !c2 = 2 :: C.Montgomery + !c_big = (2 ^ 255 - 19) :: C.Montgomery + !s2 = 2 :: S.Montgomery + !s_big = (2 ^ 255 - 19) :: S.Montgomery + in wgroup "retr" $ do + func "curve: RETR(M(2))" C.retr c2 + func "curve: RETR(M(2 ^ 255 - 19))" C.retr c_big + func "scalar: RETR(M(2))" S.retr s2 + func "scalar: RETR(M(2 ^ 255 - 19))" S.retr s_big