Debian Codegraph @

src/Bedrock/Field/Translation/Parameters/Defaults.v

raw
1 From Coq Require Import ZArith.
2 From Coq Require Import String.
3 From Coq Require Import List.
4 Require Import coqutil.Word.Interface.
5 Require Import bedrock2.Syntax.
6 Require Import Crypto.Bedrock.Field.Common.Types.
7 Require Import Crypto.BoundsPipeline.
8 Require Import Crypto.PushButtonSynthesis.Primitives.
9 Require Import Crypto.UnsaturatedSolinasHeuristics.
10 Require Crypto.Util.Strings.Decimal.
11 Require Import Crypto.Util.Strings.String.
12 Import ListNotations.
13
14 (* Declares default parameters for the bedrock2 backend that apply to all
15 machine word sizes. Do NOT import this file unless you're prepared to have a
16 bunch of global typeclass instances declared for you. *)
17
18 (* use in-memory lists; local ones are only used internally *)
19 Global Existing Instances Types.rep.Z Types.rep.listZ_mem.
20
21 Global Instance pipeline_opts : PipelineOptions :=
22 let _ := default_PipelineOptions in
23 {| (* Abstract interpretation options; currently only involving (>>) uint1 bounds, which is not relevant to bedrock2 *)
24 absint_opts :=
25 {| AbstractInterpretation.shiftr_avoid_uint1 := false (* we need to not avoid uint1 to pass bounds analysis tightness, for some reason? *) |}
26 (* Split multiplications into two outputs, not just one huge word *)
27 ; should_split_mul := true
28 (* For functions that return multiple values, split into two LetIns (this is
29 because bedrock2 does not support multiple-sets, so they would have to be
30 split anyway) *)
31 ; should_split_multiret := true
32 (* Make all words full-size, even if they could be smaller *)
33 ; widen_carry := true
34 ; widen_bytes := true
35 (* Unsigned integers *)
36 ; only_signed := false
37 (* Rewrite selects into expressions that don't require cmov *)
38 ; no_select := true
39 (* We don't handle value_barrier in bedrock2 *)
40 ; unfold_value_barrier := true
41 |}.
42
43 Global Instance tight_upperbound_fraction : tight_upperbound_fraction_opt := default_tight_upperbound_fraction.
44
45 (* bedrock2 backend parameters *)
46 Global Existing Instances Types.rep.Z Types.rep.listZ_mem.
47
48 Local Definition ERROR := "ERROR"%string.
49
50 Section Defs.
51 (* quick check to make sure the expression produced no errors *)
52 Fixpoint error_free_expr (x : Syntax.expr) : bool :=
53 match x with
54 | expr.literal _ => true
55 | expr.var x => negb (String.eqb x ERROR)
56 | expr.load _ a => error_free_expr a
57 | expr.op1 _ x => error_free_expr x
58 | expr.op _ x y => (error_free_expr x && error_free_expr y)%bool
59 | expr.inlinetable _ _ index => error_free_expr index
60 | expr.ite c a b => (error_free_expr c && error_free_expr a && error_free_expr b)%bool
61 end.
62 Fixpoint error_free_cmd (x : cmd.cmd) : bool :=
63 match x with
64 | cmd.skip => true
65 | cmd.unset _ => true
66 | cmd.set _ v => error_free_expr v
67 | cmd.store _ a v =>
68 (error_free_expr a && error_free_expr v)%bool
69 | cmd.cond c t f =>
70 (error_free_expr c && error_free_cmd t && error_free_cmd f)%bool
71 | cmd.seq x y => (error_free_cmd x && error_free_cmd y)%bool
72 | cmd.while c b => (error_free_expr c && error_free_cmd b)
73 | cmd.call _ _ args => forallb error_free_expr args
74 | cmd.stackalloc _ _ x => error_free_cmd x
75 | cmd.interact _ _ args => forallb error_free_expr args
76 end.
77 End Defs.