aboutsummaryrefslogtreecommitdiffstats
path: root/backend/SelectDivproof.v
diff options
context:
space:
mode:
authorXavier Leroy <xavier.leroy@inria.fr>2017-04-28 15:56:59 +0200
committerXavier Leroy <xavier.leroy@inria.fr>2017-04-28 16:05:51 +0200
commitf642817f0dc761e51c3bd362f75b0068a8d4b0c8 (patch)
treeb5830bb772611d2271c4b7d26f162d5c200dd788 /backend/SelectDivproof.v
parent2fbdb0c45f0913b9fd8e95606c525fc5bfb3bc6d (diff)
downloadcompcert-kvx-f642817f0dc761e51c3bd362f75b0068a8d4b0c8.tar.gz
compcert-kvx-f642817f0dc761e51c3bd362f75b0068a8d4b0c8.zip
RISC-V port and assorted changes
This commits adds code generation for the RISC-V architecture, both in 32- and 64-bit modes. The generated code was lightly tested using the simulator and cross-binutils from https://riscv.org/software-tools/ This port required the following additional changes: - Integers: More properties about shrx - SelectOp: now provides smart constructors for mulhs and mulhu - SelectDiv, 32-bit integer division and modulus: implement constant propagation, use the new smart constructors mulhs and mulhu. - Runtime library: if no asm implementation is provided, run the reference C implementation through CompCert. Since CompCert rejects the definitions of names of special functions such as __i64_shl, the reference implementation now uses "i64_" names, e.g. "i64_shl", and a renaming "i64_ -> __i64_" is performed over the generated assembly file, before assembling and building the runtime library. - test/: add SIMU make variable to run tests through a simulator - test/regression/alignas.c: make sure _Alignas and _Alignof are not #define'd by C headers commit da14495c01cf4f66a928c2feff5c53f09bde837f Author: Xavier Leroy <xavier.leroy@inria.fr> Date: Thu Apr 13 17:36:10 2017 +0200 RISC-V port, continued Now working on Asmgen. commit 36f36eb3a5abfbb8805960443d087b6a83e86005 Author: Xavier Leroy <xavier.leroy@inria.fr> Date: Wed Apr 12 17:26:39 2017 +0200 RISC-V port, first steps This port is based on Prashanth Mundkur's experimental RV32 port and brings it up to date with CompCert, and adds 64-bit support (RV64). Work in progress.
Diffstat (limited to 'backend/SelectDivproof.v')
-rw-r--r--backend/SelectDivproof.v78
1 files changed, 55 insertions, 23 deletions
diff --git a/backend/SelectDivproof.v b/backend/SelectDivproof.v
index 2ca30e52..5704b32b 100644
--- a/backend/SelectDivproof.v
+++ b/backend/SelectDivproof.v
@@ -488,6 +488,14 @@ Variable sp: val.
Variable e: env.
Variable m: mem.
+Lemma is_intconst_sound:
+ forall v a n le,
+ is_intconst a = Some n -> eval_expr ge sp e m le a v -> v = Vint n.
+Proof with (try discriminate).
+ intros. unfold is_intconst in *.
+ destruct a... destruct o... inv H. inv H0. destruct vl; inv H5. auto.
+Qed.
+
Lemma eval_divu_mul:
forall le x y p M,
divu_mul_params (Int.unsigned y) = Some(p, M) ->
@@ -495,12 +503,10 @@ Lemma eval_divu_mul:
eval_expr ge sp e m le (divu_mul p M) (Vint (Int.divu x y)).
Proof.
intros. unfold divu_mul. exploit (divu_mul_shift x); eauto. intros [A B].
- assert (eval_expr ge sp e m le
- (Eop Omulhu (Eletvar 0 ::: Eop (Ointconst (Int.repr M)) Enil ::: Enil))
- (Vint (Int.mulhu x (Int.repr M)))).
- { EvalOp. econstructor. econstructor; eauto. econstructor. EvalOp. simpl; reflexivity. constructor.
- auto. }
- exploit eval_shruimm. eexact H1. instantiate (1 := Int.repr p).
+ assert (C: eval_expr ge sp e m le (Eletvar 0) (Vint x)) by (apply eval_Eletvar; eauto).
+ assert (D: eval_expr ge sp e m le (Eop (Ointconst (Int.repr M)) Enil) (Vint (Int.repr M))) by EvalOp.
+ exploit eval_mulhu. eexact C. eexact D. intros (v & E & F). simpl in F. inv F.
+ exploit eval_shruimm. eexact E. instantiate (1 := Int.repr p).
intros [v [P Q]]. simpl in Q.
replace (Int.ltu (Int.repr p) Int.iwordsize) with true in Q.
inv Q. rewrite B. auto.
@@ -537,8 +543,15 @@ Theorem eval_divu:
Val.divu x y = Some z ->
exists v, eval_expr ge sp e m le (divu a b) v /\ Val.lessdef z v.
Proof.
- unfold divu; intros until b. destruct (divu_match b); intros.
-- inv H0. inv H5. simpl in H7. inv H7. eapply eval_divuimm; eauto.
+ unfold divu; intros.
+ destruct (is_intconst b) as [n2|] eqn:B.
+- exploit is_intconst_sound; eauto. intros EB; clear B.
+ destruct (is_intconst a) as [n1|] eqn:A.
++ exploit is_intconst_sound; eauto. intros EA; clear A.
+ destruct (Int.eq n2 Int.zero) eqn:Z. eapply eval_divu_base; eauto.
+ subst. simpl in H1. rewrite Z in H1; inv H1.
+ TrivialExists.
++ subst. eapply eval_divuimm; eauto.
- eapply eval_divu_base; eauto.
Qed.
@@ -585,8 +598,15 @@ Theorem eval_modu:
Val.modu x y = Some z ->
exists v, eval_expr ge sp e m le (modu a b) v /\ Val.lessdef z v.
Proof.
- unfold modu; intros until b. destruct (modu_match b); intros.
-- inv H0. inv H5. simpl in H7. inv H7. eapply eval_moduimm; eauto.
+ unfold modu; intros.
+ destruct (is_intconst b) as [n2|] eqn:B.
+- exploit is_intconst_sound; eauto. intros EB; clear B.
+ destruct (is_intconst a) as [n1|] eqn:A.
++ exploit is_intconst_sound; eauto. intros EA; clear A.
+ destruct (Int.eq n2 Int.zero) eqn:Z. eapply eval_modu_base; eauto.
+ subst. simpl in H1. rewrite Z in H1; inv H1.
+ TrivialExists.
++ subst. eapply eval_moduimm; eauto.
- eapply eval_modu_base; eauto.
Qed.
@@ -597,14 +617,10 @@ Lemma eval_divs_mul:
eval_expr ge sp e m le (divs_mul p M) (Vint (Int.divs x y)).
Proof.
intros. unfold divs_mul.
- assert (V: eval_expr ge sp e m le (Eletvar O) (Vint x)).
- { constructor; auto. }
- assert (X: eval_expr ge sp e m le
- (Eop Omulhs (Eletvar 0 ::: Eop (Ointconst (Int.repr M)) Enil ::: Enil))
- (Vint (Int.mulhs x (Int.repr M)))).
- { EvalOp. econstructor. eauto. econstructor. EvalOp. simpl; reflexivity. constructor.
- auto. }
- exploit eval_shruimm. eexact V. instantiate (1 := Int.repr (Int.zwordsize - 1)).
+ assert (C: eval_expr ge sp e m le (Eletvar 0) (Vint x)) by (apply eval_Eletvar; eauto).
+ assert (D: eval_expr ge sp e m le (Eop (Ointconst (Int.repr M)) Enil) (Vint (Int.repr M))) by EvalOp.
+ exploit eval_mulhs. eexact C. eexact D. intros (v & X & F). simpl in F; inv F.
+ exploit eval_shruimm. eexact C. instantiate (1 := Int.repr (Int.zwordsize - 1)).
intros [v1 [Y LD]]. simpl in LD.
change (Int.ltu (Int.repr 31) Int.iwordsize) with true in LD.
simpl in LD. inv LD.
@@ -619,7 +635,7 @@ Proof.
simpl in LD. inv LD.
rewrite B. exact W.
- exploit (divs_mul_shift_2 x); eauto. intros [A B].
- exploit eval_add. eexact X. eexact V. intros [v1 [Z LD]].
+ exploit eval_add. eexact X. eexact C. intros [v1 [Z LD]].
simpl in LD. inv LD.
exploit eval_shrimm. eexact Z. instantiate (1 := Int.repr p). intros [v1 [U LD]].
simpl in LD. rewrite RANGE in LD by auto. inv LD.
@@ -657,8 +673,16 @@ Theorem eval_divs:
Val.divs x y = Some z ->
exists v, eval_expr ge sp e m le (divs a b) v /\ Val.lessdef z v.
Proof.
- unfold divs; intros until b. destruct (divs_match b); intros.
-- inv H0. inv H5. simpl in H7. inv H7. eapply eval_divsimm; eauto.
+ unfold divs; intros.
+ destruct (is_intconst b) as [n2|] eqn:B.
+- exploit is_intconst_sound; eauto. intros EB; clear B.
+ destruct (is_intconst a) as [n1|] eqn:A.
++ exploit is_intconst_sound; eauto. intros EA; clear A.
+ destruct (Int.eq n2 Int.zero) eqn:Z. eapply eval_divs_base; eauto.
+ subst. simpl in H1.
+ destruct (Int.eq n2 Int.zero || Int.eq n1 (Int.repr Int.min_signed) && Int.eq n2 Int.mone); inv H1.
+ TrivialExists.
++ subst. eapply eval_divsimm; eauto.
- eapply eval_divs_base; eauto.
Qed.
@@ -700,8 +724,16 @@ Theorem eval_mods:
Val.mods x y = Some z ->
exists v, eval_expr ge sp e m le (mods a b) v /\ Val.lessdef z v.
Proof.
- unfold mods; intros until b. destruct (mods_match b); intros.
-- inv H0. inv H5. simpl in H7. inv H7. eapply eval_modsimm; eauto.
+ unfold mods; intros.
+ destruct (is_intconst b) as [n2|] eqn:B.
+- exploit is_intconst_sound; eauto. intros EB; clear B.
+ destruct (is_intconst a) as [n1|] eqn:A.
++ exploit is_intconst_sound; eauto. intros EA; clear A.
+ destruct (Int.eq n2 Int.zero) eqn:Z. eapply eval_mods_base; eauto.
+ subst. simpl in H1.
+ destruct (Int.eq n2 Int.zero || Int.eq n1 (Int.repr Int.min_signed) && Int.eq n2 Int.mone); inv H1.
+ TrivialExists.
++ subst. eapply eval_modsimm; eauto.
- eapply eval_mods_base; eauto.
Qed.