@@ -24,6 +24,7 @@ Require Import Crypto.Util.ZUtil.Land.
24
24
Require Import Crypto.Util.ZUtil.Land.Fold.
25
25
Require Import Crypto.Util.ZUtil.Ones.
26
26
Require Import Crypto.Util.ZUtil.Definitions.
27
+ Require Import Crypto.Util.ZUtil.Signed.
27
28
Require Import Crypto.Util.Equality .
28
29
Require Import Crypto.Util.Bool.Reflect.
29
30
Require Import Crypto.Util.Option.
@@ -587,7 +588,6 @@ Import ListNotations.
587
588
588
589
Section WithContext.
589
590
Context (ctx : symbol -> option Z).
590
- Definition signed s n : Z := (Z.land (Z.shiftl 1 (Z.of_N s-1) + n) (Z.ones (Z.of_N s)) - Z.shiftl 1 (Z.of_N s-1))%Z.
591
591
Definition op_to_Z_binop (o : op) : option _
592
592
:= match o with
593
593
| add _ => Some Z.add
@@ -618,12 +618,12 @@ Section WithContext.
618
618
| subborrow s, cons a args' =>
619
619
Some ((- Z.shiftr (a - List.fold_right Z.add 0 args') (Z.of_N s)) mod 2)
620
620
| addoverflow s, args => Some (Z.b2z (negb (Z.eqb
621
- (signed s (keep s (List.fold_right Z.add 0 args)))
622
- (List.fold_right Z.add 0%Z (List.map (signed s) args)))))
621
+ (Z. signed s (keep s (List.fold_right Z.add 0 args)))
622
+ (List.fold_right Z.add 0%Z (List.map (Z. signed s) args)))))
623
623
| neg s, [a] => Some (keep s (- a))
624
624
| shl s, [a; b] => Some (keep s (Z.shiftl a b))
625
625
| shr s, [a; b] => Some (keep s (Z.shiftr a b))
626
- | sar s, [a; b] => Some (keep s (Z.shiftr (signed s a) b))
626
+ | sar s, [a; b] => Some (keep s (Z.shiftr (Z. signed s a) b))
627
627
| rcr s, [v1; cf; cnt] => Some (
628
628
let v1c := Z.lor v1 (Z.shiftl cf (Z.of_N s)) in
629
629
let l := Z.lor v1c (Z.shiftl v1 (1+Z.of_N s)) in
@@ -2595,18 +2595,6 @@ Proof using Type.
2595
2595
rewrite Z.ones_equiv in * |- ; rewrite Z.shiftr_div_pow2, Z.div_small; cbn; lia.
2596
2596
Qed .
2597
2597
2598
- Lemma signed_small s v (Hv : (0 <= v <= Z.ones (Z.of_N s-1))%Z) : signed s v = v.
2599
- Proof using Type .
2600
- destruct (N.eq_dec s 0); subst; cbv [signed].
2601
- { rewrite Z.land_0_r. cbn in *; Lia.lia. }
2602
- rewrite !Z.land_ones, !Z.shiftl_mul_pow2, ?Z.add_0_r, ?Z.mul_1_l by Lia.lia.
2603
- rewrite Z.ones_equiv in Hv.
2604
- rewrite Z.mod_small; try ring.
2605
- enough (2 ^ Z.of_N s = 2 ^ (Z.of_N s - 1) + 2 ^ (Z.of_N s - 1))%Z; try Lia.lia.
2606
- replace (Z.of_N s) with (1+(Z.of_N s-1))%Z at 1 by Lia.lia.
2607
- rewrite Z.pow_add_r; try Lia.lia.
2608
- Qed .
2609
-
2610
2598
Definition addoverflow_small (d : dag) :=
2611
2599
fun e => match e with
2612
2600
ExprApp (addoverflow s, ([_]|[_;_]|[_;_;_]) as args) =>
@@ -2623,7 +2611,7 @@ Proof using Type.
2623
2611
BreakMatch.break_match_hyps; Option.inversion_option; t;
2624
2612
epose proof Z.ones_equiv (Z.of_N s -1);
2625
2613
destruct_head'_and; reflect_hyps; destruct_head'_and.
2626
- all : rewrite Z.land_ones, !Z.mod_small, !signed_small, !Z.eqb_refl; trivial.
2614
+ all : rewrite Z.land_ones, !Z.mod_small, !Z. signed_small, !Z.eqb_refl; trivial.
2627
2615
all : try split; try Lia.lia.
2628
2616
all : replace (Z.of_N s) with (1+(Z.of_N s-1))%Z at 1 by Lia.lia;
2629
2617
rewrite Z.pow_add_r; try Lia.lia.
@@ -2685,19 +2673,6 @@ Proof.
2685
2673
apply fold_right_filter_identity_gen with (G:=id); cbv [id]; intuition (subst; eauto).
2686
2674
Qed .
2687
2675
2688
- Lemma signed_0 s : signed s 0 = 0%Z.
2689
- Proof using Type .
2690
- destruct (N.eq_dec s 0); subst; trivial.
2691
- cbv [signed].
2692
- rewrite !Z.land_ones, !Z.shiftl_mul_pow2, ?Z.add_0_r, ?Z.mul_1_l by Lia.lia.
2693
- rewrite Z.mod_small; try ring.
2694
- split; try (eapply Z.pow_lt_mono_r; Lia.lia).
2695
- eapply Z.pow_nonneg; Lia.lia.
2696
- Qed .
2697
- #[global]
2698
- Hint Rewrite signed_0 : zsimplify_const zsimplify zsimplify_fast.
2699
- Global Hint Resolve signed_0 : zarith.
2700
-
2701
2676
Lemma interp_op_drop_identity o id : identity o = Some id ->
2702
2677
forall G xs, interp_op G o xs = interp_op G o (List.filter (fun v => negb (Z.eqb v id)) xs).
2703
2678
Proof using Type .
0 commit comments