Skip to content

Commit

Permalink
Merge pull request #1170 from GaloisInc/faster-pmod
Browse files Browse the repository at this point in the history
Add a shortcut to speed up concrete evaluation of pmod.
  • Loading branch information
brianhuffman authored Apr 28, 2021
2 parents eec1fb0 + 44ed895 commit 282613d
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Cryptol/F2.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pdiv w x m = go (w-1) 0 0


pmod :: Int -> Integer -> Integer -> Integer
pmod w x m = mask .&. go 0 0 (reduce 1)
pmod w x m = go degree (x .&. mask) (clearBit m degree)
where
degree :: Int
degree = fromInteger (widthInteger m - 1)
Expand All @@ -43,6 +43,7 @@ pmod w x m = mask .&. go 0 0 (reduce 1)

mask = bit degree - 1

-- invariant: z and p are in the range [0..mask]
go !i !z !p
| i < w = go (i+1) (if testBit x i then z `xor` p else z) (reduce (p `shiftL` 1))
| otherwise = z

0 comments on commit 282613d

Please sign in to comment.