From 6dc1781b13e14c64a6e209a0981c03203fdd9e70 Mon Sep 17 00:00:00 2001 From: Jason Gross Date: Wed, 27 Jul 2016 17:18:30 -0700 Subject: Move most notation level declarations into Util This reveals and prevents notation clashes. Notable breakage: - `x {{ y }}` breaks `Context {forall x, {P x} + {~P x}}.` (@jadephilipoom) - `x [[ y ]]` breaks `destruct x as [[a]|[b]].` (@jadephilipoom) - `O :( A , B ): :?: L ::: R` breaks `((1):nat)` and `constr:(nat)` (@varomodt) After | File Name | Before || Change ------------------------------------------------------------------------------------ 3m16.07s | Total | 3m23.63s || -0m07.55s ------------------------------------------------------------------------------------ 0m16.90s | ModularArithmetic/ModularBaseSystemProofs | 0m19.02s || -0m02.12s 0m03.29s | ModularArithmetic/ModularBaseSystemOpt | 0m05.30s || -0m02.00s 0m12.04s | Experiments/SpecEd25519 | 0m13.89s || -0m01.85s 0m36.02s | CompleteEdwardsCurve/ExtendedCoordinates | 0m36.12s || -0m00.09s 0m34.48s | Specific/GF25519 | 0m34.27s || +0m00.20s 0m15.62s | CompleteEdwardsCurve/CompleteEdwardsCurveTheorems | 0m15.76s || -0m00.14s 0m07.36s | Specific/GF1305 | 0m07.34s || +0m00.02s 0m06.64s | Algebra | 0m06.14s || +0m00.50s 0m05.12s | WeierstrassCurve/Pre | 0m05.09s || +0m00.03s 0m04.58s | ModularArithmetic/Tutorial | 0m03.83s || +0m00.75s 0m04.46s | BaseSystemProofs | 0m04.33s || +0m00.12s 0m04.26s | ModularArithmetic/Pow2BaseProofs | 0m05.16s || -0m00.90s 0m03.91s | CompleteEdwardsCurve/Pre | 0m04.62s || -0m00.71s 0m02.75s | Assembly/State | 0m03.12s || -0m00.37s 0m02.55s | Experiments/EdDSARefinement | 0m01.85s || +0m00.69s 0m02.46s | Util/ZUtil | 0m02.45s || +0m00.00s 0m01.86s | Assembly/Wordize | 0m02.02s || -0m00.15s 0m01.68s | ModularArithmetic/ModularArithmeticTheorems | 0m01.68s || +0m00.00s 0m01.67s | ModularArithmetic/PrimeFieldTheorems | 0m01.96s || -0m00.29s 0m01.50s | Encoding/PointEncodingPre | 0m02.20s || -0m00.70s 0m01.46s | ModularArithmetic/BarrettReduction/Z | 0m01.02s || +0m00.43s 0m01.26s | BaseSystem | 0m01.21s || +0m00.05s 0m01.24s | Assembly/Pseudize | 0m01.22s || +0m00.02s 0m01.20s | ModularArithmetic/ExtendedBaseVector | 0m01.86s || -0m00.66s 0m01.04s | Util/IterAssocOp | 0m00.74s || +0m00.30s 0m00.96s | ModularArithmetic/ExtPow2BaseMulProofs | 0m00.67s || +0m00.28s 0m00.96s | Assembly/Pipeline | 0m00.65s || +0m00.30s 0m00.93s | Experiments/DerivationsOptionRectLetInEncoding | 0m00.98s || -0m00.04s 0m00.93s | ModularArithmetic/ModularBaseSystemField | 0m00.95s || -0m00.01s 0m00.92s | Util/NumTheoryUtil | 0m01.19s || -0m00.26s 0m00.90s | ModularArithmetic/ModularBaseSystemListProofs | 0m00.89s || +0m00.01s 0m00.82s | ModularArithmetic/PseudoMersenneBaseParamProofs | 0m00.95s || -0m00.13s 0m00.81s | Assembly/QhasmEvalCommon | 0m00.86s || -0m00.04s 0m00.80s | Assembly/StringConversion | 0m00.60s || +0m00.20s 0m00.79s | Assembly/Qhasm | 0m00.54s || +0m00.25s 0m00.73s | Assembly/Pseudo | 0m00.98s || -0m00.25s 0m00.72s | Util/AdditionChainExponentiation | 0m00.92s || -0m00.20s 0m00.69s | Experiments/SpecificCurve25519 | 0m00.72s || -0m00.03s 0m00.65s | Spec/ModularWordEncoding | 0m00.85s || -0m00.19s 0m00.65s | ModularArithmetic/ModularBaseSystemList | 0m00.68s || -0m00.03s 0m00.65s | Assembly/PseudoConversion | 0m00.67s || -0m00.02s 0m00.64s | Encoding/ModularWordEncodingPre | 0m00.62s || +0m00.02s 0m00.64s | Spec/EdDSA | 0m00.93s || -0m00.29s 0m00.64s | Testbit | 0m00.94s || -0m00.29s 0m00.63s | Encoding/ModularWordEncodingTheorems | 0m00.66s || -0m00.03s 0m00.62s | Assembly/AlmostQhasm | 0m00.49s || +0m00.13s 0m00.59s | ModularArithmetic/ModularBaseSystem | 0m00.61s || -0m00.02s 0m00.49s | Spec/WeierstrassCurve | 0m00.43s || +0m00.06s 0m00.49s | Assembly/QhasmUtil | 0m00.51s || -0m00.02s 0m00.49s | ModularArithmetic/Pre | 0m00.47s || +0m00.02s 0m00.47s | Assembly/Vectorize | 0m00.51s || -0m00.04s 0m00.46s | Assembly/AlmostConversion | 0m00.44s || +0m00.02s 0m00.42s | ModularArithmetic/Pow2Base | 0m00.42s || +0m00.00s 0m00.41s | ModularArithmetic/PseudoMersenneBaseParams | 0m00.45s || -0m00.04s 0m00.41s | Spec/ModularArithmetic | 0m00.41s || +0m00.00s 0m00.39s | Spec/CompleteEdwardsCurve | 0m00.41s || -0m00.01s 0m00.03s | Util/Notations | 0m00.03s || +0m00.00s --- src/Assembly/Pipeline.v | 15 ++++++++------- src/Assembly/Pseudo.v | 48 +++++++++++++++++++++++++++--------------------- src/Assembly/QhasmUtil.v | 23 ++++++++++++----------- src/Assembly/Vectorize.v | 5 +++-- 4 files changed, 50 insertions(+), 41 deletions(-) (limited to 'src/Assembly') diff --git a/src/Assembly/Pipeline.v b/src/Assembly/Pipeline.v index 8e58e7345..87102cca8 100644 --- a/src/Assembly/Pipeline.v +++ b/src/Assembly/Pipeline.v @@ -1,8 +1,9 @@ Require Import Bedrock.Word. -Require Import QhasmCommon QhasmEvalCommon. -Require Import Pseudo Qhasm AlmostQhasm Conversion Language. -Require Import PseudoConversion AlmostConversion StringConversion. -Require Import Wordize Vectorize Pseudize. +Require Import Crypto.Assembly.QhasmCommon Crypto.Assembly.QhasmEvalCommon. +Require Import Crypto.Assembly.Pseudo Crypto.Assembly.Qhasm Crypto.Assembly.AlmostQhasm Crypto.Assembly.Conversion Crypto.Assembly.Language. +Require Import Crypto.Assembly.PseudoConversion Crypto.Assembly.AlmostConversion Crypto.Assembly.StringConversion. +Require Import Crypto.Assembly.Wordize Crypto.Assembly.Vectorize Crypto.Assembly.Pseudize. +Require Import Crypto.Util.Notations. Module Pipeline. Export AlmostQhasm Qhasm QhasmString. @@ -24,8 +25,8 @@ End Pipeline. Module PipelineExamples. Import Pipeline ListNotations StateCommon EvalUtil ListState. - Local Notation "v [[ i ]]" := (nth i v (wzero _)) (at level 40). - Local Notation "$$ v" := (natToWord _ v) (at level 40). + Local Notation "v [[ i ]]" := (nth i v (wzero _)). + Local Notation "$$ v" := (natToWord _ v). (* Definition add_example: @pseudeq 32 W32 1 1 (fun v => @@ -53,7 +54,7 @@ Module PipelineExamples. plet b := v[[0]] in (* NOTE: we want the lets in this format to unify with - pseudo_mult_dual *) + pseudo_mult_dual *) plet c := multHigh a b in plet d := a ^* b in diff --git a/src/Assembly/Pseudo.v b/src/Assembly/Pseudo.v index b8aae4521..ca4700a7f 100644 --- a/src/Assembly/Pseudo.v +++ b/src/Assembly/Pseudo.v @@ -1,6 +1,7 @@ Require Import Crypto.Assembly.QhasmCommon Crypto.Assembly.QhasmUtil Crypto.Assembly.State. Require Import Crypto.Assembly.Language Crypto.Assembly.QhasmEvalCommon. Require Import Coq.Lists.List Coq.Arith.Compare_dec Coq.omega.Omega. +Require Import Crypto.Util.Notations. Require Export Crypto.Util.FixCoqMistakes. Module Pseudo <: Language. @@ -31,8 +32,8 @@ Module Pseudo <: Language. }. Definition Params := Params'. - Definition State (p: Params): Type := ListState (width p). - Definition Program (p: Params): Type := + Definition State (p: Params) : Type := ListState (width p). + Definition Program (p: Params) : Type := @Pseudo (width p) (spec p) (inputs p) (outputs p). Definition Unary32: Params := mkParams 32 W32 1 1. @@ -40,7 +41,7 @@ Module Pseudo <: Language. (* Evaluation *) - Fixpoint pseudoEval {n m w s} (prog: @Pseudo w s n m) (st: ListState w): option (ListState w) := + Fixpoint pseudoEval {n m w s} (prog: @Pseudo w s n m) (st: ListState w) : option (ListState w) := match prog with | PVar n _ i => omap (getVar i st) (fun x => Some (setList [x] st)) | PMem n m v i => omap (getMem v i st) (fun x => Some (setList [x] st)) @@ -114,7 +115,7 @@ Module Pseudo <: Language. Delimit Scope pseudo_notations with p. Local Open Scope pseudo_notations. - Definition indexize {n: nat} (x: nat): Index n. + Definition indexize {n: nat} (x: nat) : Index n. intros; destruct (le_dec n 0). - exists 0; abstract intuition auto with zarith. @@ -123,60 +124,65 @@ Module Pseudo <: Language. Defined. Notation "% A" := (PVar _ (Some false) (indexize A)) - (at level 20, right associativity) : pseudo_notations. + : pseudo_notations. Notation "$ A" := (PVar _ (Some true) (indexize A)) - (at level 20, right associativity) : pseudo_notations. + : pseudo_notations. Notation "A :[ B ]:" := (PMem _ _ (indexize A) (indexize B)) - (at level 20, right associativity) : pseudo_notations. + : pseudo_notations. Notation "# A" := (PConst _ (natToWord _ A)) - (at level 20, right associativity) : pseudo_notations. + : pseudo_notations. Notation "A :+: B" := (PBin _ IAdd (PComb _ _ _ A B)) - (at level 60, right associativity) : pseudo_notations. + : pseudo_notations. Notation "A :+c: B" := (PCarry _ AddWithCarry (PComb _ _ _ A B)) - (at level 60, right associativity) : pseudo_notations. + : pseudo_notations. Notation "A :-: B" := (PBin _ ISub (PComb _ _ _ A B)) - (at level 60, right associativity) : pseudo_notations. + : pseudo_notations. Notation "A :&: B" := (PBin _ IAnd (PComb _ _ _ A B)) - (at level 45, right associativity) : pseudo_notations. + : pseudo_notations. Notation "A :^: B" := (PBin _ IXor (PComb _ _ _ A B)) - (at level 45, right associativity) : pseudo_notations. + : pseudo_notations. Notation "A :>>: B" := (PShift _ Shr (indexize B) A) - (at level 60, right associativity) : pseudo_notations. + : pseudo_notations. Notation "A :<<: B" := (PShift _ Shl (indexize B) A) - (at level 60, right associativity) : pseudo_notations. + : pseudo_notations. Notation "A :*: B" := (PDual _ Mult (PComb _ _ _ A B)) - (at level 55, right associativity) : pseudo_notations. + : pseudo_notations. + (* TODO(rsloan, from jgross): This notation is not okay. It breaks + [constr:(nat)] and [((1):nat)]. Please remove all frowny faces + from notations, and then move [Reserved Notation] line to + Fiat.Crypto.Util.Notations. *) + Reserved Notation "O :( A , B ): :?: L ::: R" (at level 70, right associativity). Notation "O :( A , B ): :?: L ::: R" := (PIf _ _ O (indexize A) (indexize B) L R) - (at level 70, right associativity) : pseudo_notations. + : pseudo_notations. Notation "F :**: e" := (PFunExp _ F e) - (at level 70, right associativity) : pseudo_notations. + : pseudo_notations. Notation "E :->: F" := (PLet _ _ _ E F) - (at level 70, right associativity) : pseudo_notations. + : pseudo_notations. Notation "A :|: B" := (PComb _ _ _ A B) - (at level 65, left associativity) : pseudo_notations. + : pseudo_notations. Notation "n ::: A :():" := (PCall _ _ n A) - (at level 65, left associativity) : pseudo_notations. + : pseudo_notations. Close Scope pseudo_notations. End Pseudo. diff --git a/src/Assembly/QhasmUtil.v b/src/Assembly/QhasmUtil.v index 1ab894e94..53e9cf573 100644 --- a/src/Assembly/QhasmUtil.v +++ b/src/Assembly/QhasmUtil.v @@ -1,40 +1,41 @@ Require Import Coq.ZArith.ZArith Coq.NArith.NArith Coq.Numbers.Natural.Peano.NPeano. Require Import Crypto.Assembly.QhasmCommon. +Require Import Crypto.Util.Notations. Require Export Bedrock.Word. Require Export Crypto.Util.FixCoqMistakes. Delimit Scope nword_scope with w. Local Open Scope nword_scope. -Notation "& x" := (wordToN x) (at level 30) : nword_scope. -Notation "** x" := (NToWord _ x) (at level 30) : nword_scope. +Notation "& x" := (wordToN x) : nword_scope. +Notation "** x" := (NToWord _ x) : nword_scope. Section Util. - Definition convS {A B: Set} (x: A) (H: A = B): B := + Definition convS {A B: Set} (x: A) (H: A = B) : B := eq_rect A (fun B0 : Set => B0) x B H. - Definition high {k n: nat} (p: (k <= n)%nat) (w: word n): word k. + Definition high {k n: nat} (p: (k <= n)%nat) (w: word n) : word k. refine (split1 k (n - k) (convS w _)). abstract (replace n with (k + (n - k)) by omega; intuition auto with arith). Defined. - Definition low {k n: nat} (p: (k <= n)%nat) (w: word n): word k. + Definition low {k n: nat} (p: (k <= n)%nat) (w: word n) : word k. refine (split2 (n - k) k (convS w _)). abstract (replace n with (k + (n - k)) by omega; intuition auto with zarith). Defined. - Definition extend {k n: nat} (p: (k <= n)%nat) (w: word k): word n. + Definition extend {k n: nat} (p: (k <= n)%nat) (w: word k) : word n. refine (convS (zext w (n - k)) _). abstract (replace (k + (n - k)) with n by omega; intuition). Defined. - Definition shiftr {n} (w: word n) (k: nat): word n := + Definition shiftr {n} (w: word n) (k: nat) : word n := match (le_dec k n) with | left p => extend p (high p w) | right _ => wzero n end. - Definition mask {n} (k: nat) (w: word n): word n := + Definition mask {n} (k: nat) (w: word n) : word n := match (le_dec k n) with | left p => extend p (low p w) | right _ => w @@ -58,7 +59,7 @@ Section Util. end). Defined. - Definition break {n} (m: nat) (x: word n): word m * word (n - m). + Definition break {n} (m: nat) (x: word n) : word m * word (n - m). refine match (le_dec m n) with | left p => (extend _ (low p x), extend _ (@high (n - m) n _ x)) | right p => (extend _ x, _) @@ -67,13 +68,13 @@ Section Util. replace (n - m) with O by abstract omega; exact WO. Defined. - Definition addWithCarry {n} (x y: word n) (c: bool): word n := + Definition addWithCarry {n} (x y: word n) (c: bool) : word n := x ^+ y ^+ (natToWord _ (if c then 1 else 0)). Definition omap {A B} (x: option A) (f: A -> option B) := match x with | Some y => f y | _ => None end. - Notation "A <- X ; B" := (omap X (fun A => B)) (at level 70, right associativity). + Notation "A <- X ; B" := (omap X (fun A => B)). End Util. Close Scope nword_scope. diff --git a/src/Assembly/Vectorize.v b/src/Assembly/Vectorize.v index 4eed28aad..08e9ee356 100644 --- a/src/Assembly/Vectorize.v +++ b/src/Assembly/Vectorize.v @@ -1,20 +1,21 @@ Require Export Bedrock.Word Bedrock.Nomega. Require Import Coq.Numbers.Natural.Peano.NPeano Coq.NArith.NArith Coq.PArith.PArith Coq.NArith.Ndigits Coq.Arith.Compare_dec Coq.Arith.Arith. Require Import Coq.Logic.ProofIrrelevance Coq.setoid_ring.Ring Coq.Lists.List Coq.omega.Omega. +Require Import Crypto.Util.Notations. Require Export Crypto.Util.FixCoqMistakes. Definition Let_In {A P} (x : A) (f : forall a : A, P a) : P x := let y := x in f y. -Notation "'plet' x := y 'in' z" := (Let_In y (fun x => z)) (at level 60). +Notation "'plet' x := y 'in' z" := (Let_In y (fun x => z)). Section Vector. Import ListNotations. Definition vec T n := {x: list T | length x = n}. - Definition vget {n T} (x: vec T n) (i: {v: nat | (v < n)%nat}): T. + Definition vget {n T} (x: vec T n) (i: {v: nat | (v < n)%nat}) : T. refine ( match (proj1_sig x) as x' return (proj1_sig x) = x' -> _ with | [] => fun _ => _ -- cgit v1.2.3