@@ -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.
@@ -596,7 +597,6 @@ Import ListNotations.
596
597
597
598
Section WithContext.
598
599
Context (ctx : symbol -> option Z).
599
- 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.
600
600
Definition op_to_Z_binop (o : op) : option _
601
601
:= match o with
602
602
| add _ => Some Z.add
@@ -627,12 +627,12 @@ Section WithContext.
627
627
| subborrow s, cons a args' =>
628
628
Some ((- Z.shiftr (a - List.fold_right Z.add 0 args') (Z.of_N s)) mod 2)
629
629
| addoverflow s, args => Some (Z.b2z (negb (Z.eqb
630
- (signed s (keep s (List.fold_right Z.add 0 args)))
631
- (List.fold_right Z.add 0%Z (List.map (signed s) args)))))
630
+ (Z. signed s (keep s (List.fold_right Z.add 0 args)))
631
+ (List.fold_right Z.add 0%Z (List.map (Z. signed s) args)))))
632
632
| neg s, [a] => Some (keep s (- a))
633
633
| shl s, [a; b] => Some (keep s (Z.shiftl a b))
634
634
| shr s, [a; b] => Some (keep s (Z.shiftr a b))
635
- | sar s, [a; b] => Some (keep s (Z.shiftr (signed s a) b))
635
+ | sar s, [a; b] => Some (keep s (Z.shiftr (Z. signed s a) b))
636
636
| rcr s, [v1; cf; cnt] => Some (
637
637
let v1c := Z.lor v1 (Z.shiftl cf (Z.of_N s)) in
638
638
let l := Z.lor v1c (Z.shiftl v1 (1+Z.of_N s)) in
@@ -2604,18 +2604,6 @@ Proof using Type.
2604
2604
rewrite Z.ones_equiv in * |- ; rewrite Z.shiftr_div_pow2, Z.div_small; cbn; lia.
2605
2605
Qed .
2606
2606
2607
- Lemma signed_small s v (Hv : (0 <= v <= Z.ones (Z.of_N s-1))%Z) : signed s v = v.
2608
- Proof using Type .
2609
- destruct (N.eq_dec s 0); subst; cbv [signed].
2610
- { rewrite Z.land_0_r. cbn in *; Lia.lia. }
2611
- rewrite !Z.land_ones, !Z.shiftl_mul_pow2, ?Z.add_0_r, ?Z.mul_1_l by Lia.lia.
2612
- rewrite Z.ones_equiv in Hv.
2613
- rewrite Z.mod_small; try ring.
2614
- enough (2 ^ Z.of_N s = 2 ^ (Z.of_N s - 1) + 2 ^ (Z.of_N s - 1))%Z; try Lia.lia.
2615
- replace (Z.of_N s) with (1+(Z.of_N s-1))%Z at 1 by Lia.lia.
2616
- rewrite Z.pow_add_r; try Lia.lia.
2617
- Qed .
2618
-
2619
2607
Definition addoverflow_small (d : dag) :=
2620
2608
fun e => match e with
2621
2609
ExprApp (addoverflow s, ([_]|[_;_]|[_;_;_]) as args) =>
@@ -2632,7 +2620,7 @@ Proof using Type.
2632
2620
BreakMatch.break_match_hyps; Option.inversion_option; t;
2633
2621
epose proof Z.ones_equiv (Z.of_N s -1);
2634
2622
destruct_head'_and; reflect_hyps; destruct_head'_and.
2635
- all : rewrite Z.land_ones, !Z.mod_small, !signed_small, !Z.eqb_refl; trivial.
2623
+ all : rewrite Z.land_ones, !Z.mod_small, !Z. signed_small, !Z.eqb_refl; trivial.
2636
2624
all : try split; try Lia.lia.
2637
2625
all : replace (Z.of_N s) with (1+(Z.of_N s-1))%Z at 1 by Lia.lia;
2638
2626
rewrite Z.pow_add_r; try Lia.lia.
@@ -2694,19 +2682,6 @@ Proof.
2694
2682
apply fold_right_filter_identity_gen with (G:=id); cbv [id]; intuition (subst; eauto).
2695
2683
Qed .
2696
2684
2697
- Lemma signed_0 s : signed s 0 = 0%Z.
2698
- Proof using Type .
2699
- destruct (N.eq_dec s 0); subst; trivial.
2700
- cbv [signed].
2701
- rewrite !Z.land_ones, !Z.shiftl_mul_pow2, ?Z.add_0_r, ?Z.mul_1_l by Lia.lia.
2702
- rewrite Z.mod_small; try ring.
2703
- split; try (eapply Z.pow_lt_mono_r; Lia.lia).
2704
- eapply Z.pow_nonneg; Lia.lia.
2705
- Qed .
2706
- #[global]
2707
- Hint Rewrite signed_0 : zsimplify_const zsimplify zsimplify_fast.
2708
- Global Hint Resolve signed_0 : zarith.
2709
-
2710
2685
Lemma interp_op_drop_identity o id : identity o = Some id ->
2711
2686
forall G xs, interp_op G o xs = interp_op G o (List.filter (fun v => negb (Z.eqb v id)) xs).
2712
2687
Proof using Type .
0 commit comments