mirror of
https://github.com/GaloisInc/cryptol.git
synced 2024-08-17 01:41:09 +03:00
Merge pull request #1170 from GaloisInc/faster-pmod
Add a shortcut to speed up concrete evaluation of pmod.
This commit is contained in:
commit
282613d320
@ -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)
|
||||
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user