Skip to content

Commit 1854670

Browse files
Introduce select_long
Like `select` at type `Tlong`, but guaranteed to be available on all platforms, by using two `select` at type `Tint` if needed. Co-authored-by: Bernhard Schommer <bernhardschommer@gmail.com>
1 parent 9de88be commit 1854670

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

backend/SplitLong.vp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,4 +338,18 @@ Definition cmpl (c: comparison) (e1 e2: expr) :=
338338
else cmpl_gen Cgt Cge e1 e2
339339
end.
340340

341+
Definition select_long (cond: condition) (args: exprlist) (e1 e2: expr) :=
342+
if select_supported Tlong then
343+
select Tlong cond args e1 e2
344+
else
345+
bind_exprs (e1 ::: e2 ::: args) (fun al =>
346+
match al with
347+
| e1 ::: e2 ::: args =>
348+
makelong
349+
(select Tint cond args (Eop Ohighlong (e1 ::: Enil)) (Eop Ohighlong (e2 ::: Enil)))
350+
(select Tint cond args (Eop Olowlong (e1 ::: Enil)) (Eop Olowlong (e2 ::: Enil)))
351+
352+
| _ => longconst Int64.zero (*r cannot happen *)
353+
end).
354+
341355
End SELECT.

backend/SplitLongproof.v

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,5 +1107,52 @@ Proof.
11071107
rewrite Int64.decompose_le. rewrite Int.eq_sym. auto.
11081108
Qed.
11091109

1110+
Remark select_int_supported: select_supported Tint = true.
1111+
Proof. reflexivity. Qed.
1112+
1113+
Remark select_long_unsupported: select_supported Tlong = false -> Archi.ptr64 = false.
1114+
Proof.
1115+
unfold select_supported; intros; auto; congruence.
1116+
Qed.
1117+
1118+
Theorem eval_select_long:
1119+
forall le cond al vl a1 v1 a2 v2,
1120+
eval_exprlist ge sp e m le al vl ->
1121+
eval_expr ge sp e m le a1 v1 ->
1122+
eval_expr ge sp e m le a2 v2 ->
1123+
exists v,
1124+
eval_expr ge sp e m le (select_long cond al a1 a2) v
1125+
/\ Val.lessdef (Val.select (eval_condition cond vl m) v1 v2 Tlong) v.
1126+
Proof.
1127+
unfold select_long; intros. destruct (select_supported Tlong) eqn:SUP.
1128+
- eapply eval_select; eauto.
1129+
- assert (NOT64: Archi.ptr64 = false) by auto using select_long_unsupported.
1130+
assert (AUX: forall v vhi vlo,
1131+
Val.lessdef (Val.normalize (Val.hiword v) Tint) vhi ->
1132+
Val.lessdef (Val.normalize (Val.loword v) Tint) vlo ->
1133+
Val.lessdef (Val.normalize v Tlong) (Val.longofwords vhi vlo)).
1134+
{ intros. unfold Val.normalize. rewrite NOT64. destruct v; auto.
1135+
simpl in *. inv H2; inv H3. simpl. rewrite Int64.ofwords_recompose. auto. }
1136+
eapply eval_bind_exprs_gen with (P := Val.lessdef (Val.select (eval_condition cond vl m) v1 v2 Tlong)); eauto using eval_exprlist.
1137+
intros args EV. set (le' := app (rev (v1 :: v2 :: vl)) le) in *.
1138+
inv EV. inv H7. rename a0 into b1. rename a3 into b2. rename al1 into bl.
1139+
exploit eval_select.
1140+
apply select_int_supported.
1141+
eexact H9.
1142+
eapply eval_Eop with (op := Ohighlong) (al := b1 ::: Enil); eauto using eval_exprlist. simpl; eauto.
1143+
eapply eval_Eop with (op := Ohighlong) (al := b2 ::: Enil); eauto using eval_exprlist. simpl; eauto.
1144+
intros (vhi & EHI & LHI).
1145+
exploit eval_select.
1146+
apply select_int_supported.
1147+
eexact H9.
1148+
eapply eval_Eop with (op := Olowlong) (al := b1 ::: Enil); eauto using eval_exprlist. simpl; eauto.
1149+
eapply eval_Eop with (op := Olowlong) (al := b2 ::: Enil); eauto using eval_exprlist. simpl; eauto.
1150+
intros (vlo & ELO & LLO).
1151+
exists (Val.longofwords vhi vlo); split.
1152+
eapply eval_Eop; eauto using eval_exprlist.
1153+
destruct (eval_condition cond vl m) as [b|]; simpl in *; auto.
1154+
destruct b; apply AUX; auto.
1155+
Qed.
1156+
11101157
End CMCONSTR.
11111158

0 commit comments

Comments
 (0)