diff options
author | Jason Gross <jgross@mit.edu> | 2017-06-17 16:20:14 -0400 |
---|---|---|
committer | Jason Gross <jgross@mit.edu> | 2017-06-17 16:20:14 -0400 |
commit | 599922047d89a89afe6fca798cb52d5f6adc7615 (patch) | |
tree | 8bd7e09c0d2d881e68c82958e8ddb8edbec12971 /src/Util | |
parent | 16382f1e356cadfd8d50252ae397306d9f246ba9 (diff) |
Unfold Z.mul_split_at_bitwidth for reification
Also reimplement it with a shift and a mask
Diffstat (limited to 'src/Util')
-rw-r--r-- | src/Util/ZUtil.v | 1 | ||||
-rw-r--r-- | src/Util/ZUtil/Definitions.v | 11 | ||||
-rw-r--r-- | src/Util/ZUtil/MulSplit.v | 11 |
3 files changed, 19 insertions, 4 deletions
diff --git a/src/Util/ZUtil.v b/src/Util/ZUtil.v index fb7d0133a..01e125e00 100644 --- a/src/Util/ZUtil.v +++ b/src/Util/ZUtil.v @@ -26,7 +26,6 @@ Require Export Crypto.Util.ZUtil.Sgn. Require Export Crypto.Util.ZUtil.Tactics. Require Export Crypto.Util.ZUtil.Testbit. Require Export Crypto.Util.ZUtil.ZSimplify. -Require Export Crypto.Util.ZUtil.Z2Nat. Import Nat. Local Open Scope Z. 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 diff --git a/src/Util/ZUtil/MulSplit.v b/src/Util/ZUtil/MulSplit.v index 2f6805446..1cc6b7af0 100644 --- a/src/Util/ZUtil/MulSplit.v +++ b/src/Util/ZUtil/MulSplit.v @@ -1,4 +1,5 @@ Require Import Coq.ZArith.ZArith. +Require Import Coq.micromega.Lia. Require Import Crypto.Util.ZUtil.Definitions. Require Import Crypto.Util.ZUtil.Tactics.LtbToLt. Require Import Crypto.Util.Tactics.BreakMatch. @@ -6,9 +7,15 @@ Local Open Scope Z_scope. Module Z. Lemma mul_split_at_bitwidth_mod bw x y : fst (Z.mul_split_at_bitwidth bw x y) = (x * y) mod 2^bw. - Proof. reflexivity. Qed. + Proof. + unfold Z.mul_split_at_bitwidth, LetIn.Let_In; break_innermost_match; Z.ltb_to_lt; try reflexivity; + apply Z.land_ones; lia. + Qed. Lemma mul_split_at_bitwidth_div bw x y : snd (Z.mul_split_at_bitwidth bw x y) = (x * y) / 2^bw. - Proof. reflexivity. Qed. + Proof. + unfold Z.mul_split_at_bitwidth, LetIn.Let_In; break_innermost_match; Z.ltb_to_lt; try reflexivity; + apply Z.shiftr_div_pow2; lia. + Qed. Lemma mul_split_mod s x y : fst (Z.mul_split s x y) = (x * y) mod s. Proof. unfold Z.mul_split; break_match; Z.ltb_to_lt; |