Skip to content

Commit 3c99c7f

Browse files
committed
put the new rewrite rule in its own pass
1 parent 568e9c8 commit 3c99c7f

File tree

6 files changed

+213
-195
lines changed

6 files changed

+213
-195
lines changed

fiat-c/src/secp256k1_dettman_64.c

+104-112
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/BoundsPipeline.v

+2-1
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,8 @@ Module Pipeline.
806806
match E' with
807807
(* rewrites after bounds relaxation---add a new one named arithWithRelaxedCasts or something. *)
808808
| inl E
809-
=> (E <- match split_mul_to with
809+
=> (E <- RewriteAndEliminateDeadAndInline "RewriteArithWithRelaxedCasts" (RewriteRules.RewriteArithWithRelaxedCasts opts) with_dead_code_elimination with_subst01 with_let_bind_return E;
810+
E <- match split_mul_to with
810811
| Some (max_bitwidth, lgcarrymax)
811812
=> wrap_debug_rewrite "RewriteMulSplit" (RewriteRules.RewriteMulSplit max_bitwidth lgcarrymax opts) E
812813
| None => Debug.ret E

src/Rewriter/All.v

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Require Import Crypto.Rewriter.Passes.NBE.
22
Require Import Crypto.Rewriter.Passes.AddAssocLeft.
33
Require Import Crypto.Rewriter.Passes.Arith.
44
Require Import Crypto.Rewriter.Passes.ArithWithCasts.
5+
Require Import Crypto.Rewriter.Passes.ArithWithRelaxedCasts.
56
Require Import Crypto.Rewriter.Passes.StripLiteralCasts.
67
Require Import Crypto.Rewriter.Passes.FlattenThunkedRects.
78
Require Import Crypto.Rewriter.Passes.MulSplit.
@@ -17,6 +18,7 @@ Module Compilers.
1718
Export AddAssocLeft.Compilers.
1819
Export Arith.Compilers.
1920
Export ArithWithCasts.Compilers.
21+
Export ArithWithRelaxedCasts.Compilers.
2022
Export StripLiteralCasts.Compilers.
2123
Export FlattenThunkedRects.Compilers.
2224
Export MulSplit.Compilers.
@@ -32,6 +34,7 @@ Module Compilers.
3234
Export AddAssocLeft.Compilers.RewriteRules.
3335
Export Arith.Compilers.RewriteRules.
3436
Export ArithWithCasts.Compilers.RewriteRules.
37+
Export ArithWithRelaxedCasts.Compilers.RewriteRules.
3538
Export StripLiteralCasts.Compilers.RewriteRules.
3639
Export FlattenThunkedRects.Compilers.RewriteRules.
3740
Export MulSplit.Compilers.RewriteRules.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
Require Import Rewriter.Language.Language.
2+
Require Import Crypto.Language.API.
3+
Require Import Rewriter.Language.Wf.
4+
Require Import Crypto.Language.WfExtra.
5+
Require Import Crypto.Rewriter.AllTacticsExtra.
6+
Require Import Crypto.Rewriter.RulesProofs.
7+
8+
Module Compilers.
9+
Import Language.Compilers.
10+
Import Language.API.Compilers.
11+
Import Language.Wf.Compilers.
12+
Import Language.WfExtra.Compilers.
13+
Import Rewriter.AllTacticsExtra.Compilers.RewriteRules.GoalType.
14+
Import Rewriter.AllTactics.Compilers.RewriteRules.Tactic.
15+
Import Compilers.Classes.
16+
17+
Module Import RewriteRules.
18+
Section __.
19+
Definition VerifiedRewriterArithWithRelaxedCasts : VerifiedRewriter_with_args false false true arith_with_relaxed_casts_rewrite_rules_proofs.
20+
Proof using All. make_rewriter. Defined.
21+
22+
Definition default_opts := Eval hnf in @default_opts VerifiedRewriterArithWithRelaxedCasts.
23+
Let optsT := Eval hnf in optsT VerifiedRewriterArithWithRelaxedCasts.
24+
25+
Definition RewriteArithWithRelaxedCasts (opts : optsT) {t : API.type} := Eval hnf in @Rewrite VerifiedRewriterArithWithRelaxedCasts opts t.
26+
27+
Lemma Wf_RewriteArithWithRelaxedCasts opts {t} e (Hwf : Wf e) : Wf (@RewriteArithWithRelaxedCasts opts t e).
28+
Proof. now apply VerifiedRewriterArithWithRelaxedCasts. Qed.
29+
30+
Lemma Interp_RewriteArithWithRelaxedCasts opts {t} e (Hwf : Wf e) : API.Interp (@RewriteArithWithRelaxedCasts opts t e) == API.Interp e.
31+
Proof. now apply VerifiedRewriterArithWithRelaxedCasts. Qed.
32+
End __.
33+
End RewriteRules.
34+
35+
Module Export Hints.
36+
#[global]
37+
Hint Resolve Wf_RewriteArithWithRelaxedCasts : wf wf_extra.
38+
#[global]
39+
Hint Opaque RewriteArithWithRelaxedCasts : wf wf_extra interp interp_extra rewrite.
40+
#[global]
41+
Hint Rewrite @Interp_RewriteArithWithRelaxedCasts : interp interp_extra.
42+
End Hints.
43+
End Compilers.

src/Rewriter/Rules.v

+25-11
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,30 @@ Definition arith_with_casts_rewrite_rulesT (adc_no_carry_to_add : bool) : list (
561561
]
562562
]%Z%zrange.
563563

564+
Definition arith_with_relaxed_casts_rewrite_rulesT : list (bool * Prop)
565+
:= Eval cbv [myapp mymap myflatten] in
566+
myflatten
567+
[mymap
568+
dont_do_again
569+
[(forall rland rm1 rv v,
570+
rland.(upper) ∈ rm1
571+
-> rland.(upper) = Z.ones (Z.succ (Z.log2 rland.(upper)))
572+
-> 0 = rland.(lower)
573+
-> 0 = rv.(lower)
574+
-> 0 <= rv.(upper)
575+
-> (rv.(upper) + 1) mod (rland.(upper) + 1) = 0
576+
-> cstZ rland (Z.land (cstZ rv v) (cstZ rm1 ('rland.(upper)))) = cstZ rland v)
577+
; (forall rland rm1 rv v,
578+
rland.(upper) ∈ rm1
579+
-> rland.(upper) = Z.ones (Z.succ (Z.log2 rland.(upper)))
580+
-> 0 = rland.(lower)
581+
-> 0 = rv.(lower)
582+
-> 0 <= rv.(upper)
583+
-> (rv.(upper) + 1) mod (rland.(upper) + 1) = 0
584+
-> cstZ rland (Z.land (cstZ rm1 ('rland.(upper))) (cstZ rv v)) = cstZ rland v)
585+
]
586+
]%Z%zrange.
587+
564588
Definition strip_literal_casts_rewrite_rulesT : list (bool * Prop)
565589
:= [dont_do_again (forall rx x, x ∈ rx -> cstZ rx ('x) = 'x)]%Z%zrange.
566590

@@ -1060,17 +1084,7 @@ Section with_bitwidth.
10601084
[mymap dont_do_again []
10611085
; mymap
10621086
do_again
1063-
[
1064-
(* owen put this here, and he needs to remove it. *)
1065-
(forall rland rm1 rv v,
1066-
rland.(upper) ∈ rm1
1067-
-> rland.(upper) = Z.ones (Z.succ (Z.log2 rland.(upper)))
1068-
-> 0 = rland.(lower)
1069-
-> 0 = rv.(lower)
1070-
-> 0 <= rv.(upper)
1071-
-> (rv.(upper) + 1) mod (rland.(upper) + 1) = 0
1072-
-> cstZ rland (Z.land (cstZ rv v) (cstZ rm1 ('rland.(upper)))) = cstZ rland v)
1073-
; (forall A B x y, @fst A B (x, y) = x)
1087+
[(forall A B x y, @fst A B (x, y) = x)
10741088
; (forall A B x y, @snd A B (x, y) = y)
10751089
(** In order to avoid tautological compares, we need to deal with carry/borrows being 0 *)
10761090
; (forall r0 s x y r1 r2,

0 commit comments

Comments
 (0)