aboutsummaryrefslogtreecommitdiff
path: root/src/Util/ZUtil/Definitions.v
diff options
context:
space:
mode:
authorGravatar Jason Gross <jgross@mit.edu>2017-06-17 16:20:14 -0400
committerGravatar Jason Gross <jgross@mit.edu>2017-06-17 16:20:14 -0400
commit599922047d89a89afe6fca798cb52d5f6adc7615 (patch)
tree8bd7e09c0d2d881e68c82958e8ddb8edbec12971 /src/Util/ZUtil/Definitions.v
parent16382f1e356cadfd8d50252ae397306d9f246ba9 (diff)
Unfold Z.mul_split_at_bitwidth for reification
Also reimplement it with a shift and a mask
Diffstat (limited to 'src/Util/ZUtil/Definitions.v')
-rw-r--r--src/Util/ZUtil/Definitions.v11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/Util/ZUtil/Definitions.v b/src/Util/ZUtil/Definitions.v
index fb7754a7a..f6892be13 100644
--- a/src/Util/ZUtil/Definitions.v
+++ b/src/Util/ZUtil/Definitions.v
@@ -1,6 +1,7 @@
Require Import Coq.ZArith.ZArith.
Require Import Crypto.Util.Decidable.
Require Import Crypto.Util.ZUtil.Notations.
+Require Import Crypto.Util.LetIn.
Local Open Scope Z_scope.
Module Z.
@@ -36,7 +37,15 @@ Module Z.
else ((x + y) mod bound, (x + y) / bound).
Definition mul_split_at_bitwidth (bitwidth : Z) (x y : Z) : Z * Z
- := ((x * y) mod 2^bitwidth, (x * y) / 2^bitwidth).
+ := dlet xy := x * y in
+ (match bitwidth with
+ | Z.pos _ | Z0 => xy &' Z.ones bitwidth
+ | Z.neg _ => xy mod 2^bitwidth
+ end,
+ match bitwidth with
+ | Z.pos _ | Z0 => xy >> bitwidth
+ | Z.neg _ => xy / 2^bitwidth
+ end).
Definition mul_split (s x y : Z) : Z * Z
:= if s =? 2^Z.log2 s
then mul_split_at_bitwidth (Z.log2 s) x y