aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Monniaux <david.monniaux@univ-grenoble-alpes.fr>2021-01-30 15:52:21 +0100
committerDavid Monniaux <david.monniaux@univ-grenoble-alpes.fr>2021-01-30 15:52:21 +0100
commit0eb1e1e6dd80154fb9841697b2c19482ece2f7da (patch)
tree2394d791c757e0daec9cf489bb1911e08aaccf4e
parent18a2f80686c651dde5964098c8b76e5aa94e6340 (diff)
downloadcompcert-kvx-0eb1e1e6dd80154fb9841697b2c19482ece2f7da.tar.gz
compcert-kvx-0eb1e1e6dd80154fb9841697b2c19482ece2f7da.zip
select through bitwise operations
-rw-r--r--riscV/ExtValues.v40
1 files changed, 40 insertions, 0 deletions
diff --git a/riscV/ExtValues.v b/riscV/ExtValues.v
new file mode 100644
index 00000000..0f29e837
--- /dev/null
+++ b/riscV/ExtValues.v
@@ -0,0 +1,40 @@
+Require Import Coqlib.
+Require Import Integers.
+Require Import Values.
+Require Import Floats.
+
+Definition bitwise_select_int b vtrue vfalse :=
+ Val.or (Val.and (Val.neg b) vtrue)
+ (Val.and (Val.sub b Vone) vfalse).
+
+Lemma bitwise_select_int_true :
+ forall vtrue vfalse,
+ bitwise_select_int (Val.of_optbool (Some true)) (Vint vtrue) (Vint vfalse)
+ = Vint vtrue.
+Proof.
+ intros. cbn. f_equal.
+ change (Int.neg Int.one) with Int.mone.
+ rewrite Int.and_commut.
+ rewrite Int.and_mone.
+ rewrite Int.sub_idem.
+ rewrite Int.and_commut.
+ rewrite Int.and_zero.
+ apply Int.or_zero.
+Qed.
+
+Lemma bitwise_select_int_false :
+ forall vtrue vfalse,
+ bitwise_select_int (Val.of_optbool (Some false)) (Vint vtrue) (Vint vfalse)
+ = Vint vfalse.
+Proof.
+ intros. cbn. f_equal.
+ rewrite Int.neg_zero.
+ rewrite Int.and_commut.
+ rewrite Int.and_zero.
+ rewrite Int.sub_zero_r.
+ change (Int.neg Int.one) with Int.mone.
+ rewrite Int.and_commut.
+ rewrite Int.and_mone.
+ rewrite Int.or_commut.
+ apply Int.or_zero.
+Qed.