Correctness proof for PPC generation: auxiliary results.
Require Import Coqlib.
Require Import Maps.
Require Import AST.
Require Import Integers.
Require Import Floats.
Require Import Values.
Require Import Memory.
Require Import Globalenvs.
Require Import Op.
Require Import Locations.
Require Import Mach.
Require Import Machsem.
Require Import Machtyping.
Require Import Asm.
Require Import Asmgen.
Require Import Conventions.
Properties of low half/high half decomposition
Lemma high_half_zero:
forall v,
Val.add (
high_half v)
Vzero =
high_half v.
Proof.
Lemma low_high_u:
forall n,
Int.or (
Int.shl (
high_u n) (
Int.repr 16)) (
low_u n) =
n.
Proof.
Lemma low_high_u_xor:
forall n,
Int.xor (
Int.shl (
high_u n) (
Int.repr 16)) (
low_u n) =
n.
Proof.
Lemma low_high_s:
forall n,
Int.add (
Int.shl (
high_s n) (
Int.repr 16)) (
low_s n) =
n.
Proof.
Correspondence between Mach registers and PPC registers
Hint Extern 2 (
_ <>
_) =>
discriminate:
ppcgen.
Mapping from Mach registers to PPC registers.
Lemma preg_of_injective:
forall r1 r2,
preg_of r1 =
preg_of r2 ->
r1 =
r2.
Proof.
destruct r1; destruct r2; simpl; intros; reflexivity || discriminate.
Qed.
Characterization of PPC registers that correspond to Mach registers.
Definition is_data_reg (
r:
preg) :
bool :=
match r with
|
IR GPR0 =>
false
|
PC =>
false |
LR =>
false |
CTR =>
false
|
CR0_0 =>
false |
CR0_1 =>
false |
CR0_2 =>
false |
CR0_3 =>
false
|
CARRY =>
false
|
_ =>
true
end.
Lemma ireg_of_is_data_reg:
forall (
r:
mreg),
is_data_reg (
ireg_of r) =
true.
Proof.
destruct r; reflexivity.
Qed.
Lemma freg_of_is_data_reg:
forall (
r:
mreg),
is_data_reg (
ireg_of r) =
true.
Proof.
destruct r; reflexivity.
Qed.
Lemma preg_of_is_data_reg:
forall (
r:
mreg),
is_data_reg (
preg_of r) =
true.
Proof.
destruct r; reflexivity.
Qed.
Lemma data_reg_diff:
forall r r',
is_data_reg r =
true ->
is_data_reg r' =
false ->
r <>
r'.
Proof.
intros. congruence.
Qed.
Lemma ireg_diff:
forall r r',
r <>
r' ->
IR r <>
IR r'.
Proof.
intros. congruence.
Qed.
Lemma diff_ireg:
forall r r',
IR r <>
IR r' ->
r <>
r'.
Proof.
intros. congruence.
Qed.
Hint Resolve ireg_of_is_data_reg freg_of_is_data_reg preg_of_is_data_reg
data_reg_diff ireg_diff diff_ireg:
ppcgen.
Definition is_nontemp_reg (
r:
preg) :
bool :=
match r with
|
IR GPR0 =>
false |
IR GPR11 =>
false |
IR GPR12 =>
false
|
FR FPR0 =>
false |
FR FPR12 =>
false |
FR FPR13 =>
false
|
PC =>
false |
LR =>
false |
CTR =>
false
|
CR0_0 =>
false |
CR0_1 =>
false |
CR0_2 =>
false |
CR0_3 =>
false
|
CARRY =>
false
|
_ =>
true
end.
Remark is_nontemp_is_data:
forall r,
is_nontemp_reg r =
true ->
is_data_reg r =
true.
Proof.
destruct r; simpl; try congruence. destruct i; congruence.
Qed.
Lemma nontemp_reg_diff:
forall r r',
is_nontemp_reg r =
true ->
is_nontemp_reg r' =
false ->
r <>
r'.
Proof.
intros. congruence.
Qed.
Hint Resolve is_nontemp_is_data nontemp_reg_diff:
ppcgen.
Lemma ireg_of_not_GPR1:
forall r,
ireg_of r <>
GPR1.
Proof.
intro. case r; discriminate.
Qed.
Lemma preg_of_not_GPR1:
forall r,
preg_of r <>
GPR1.
Proof.
intro. case r; discriminate.
Qed.
Hint Resolve ireg_of_not_GPR1 preg_of_not_GPR1:
ppcgen.
Lemma int_temp_for_diff:
forall r,
IR(
int_temp_for r) <>
preg_of r.
Proof.
Agreement between Mach register sets and PPC register sets.
Record agree (
ms:
Mach.regset) (
sp:
val) (
rs:
Asm.regset) :
Prop :=
mkagree {
agree_sp:
rs#
GPR1 =
sp;
agree_sp_def:
sp <>
Vundef;
agree_mregs:
forall r:
mreg,
Val.lessdef (
ms r) (
rs#(
preg_of r))
}.
Lemma preg_val:
forall ms sp rs r,
agree ms sp rs ->
Val.lessdef (
ms r)
rs#(
preg_of r).
Proof.
Lemma preg_vals:
forall ms sp rs rl,
agree ms sp rs ->
Val.lessdef_list (
List.map ms rl) (
List.map rs (
List.map preg_of rl)).
Proof.
induction rl;
intros;
simpl.
constructor.
constructor.
eapply preg_val;
eauto.
eauto.
Qed.
Lemma ireg_val:
forall ms sp rs r,
agree ms sp rs ->
mreg_type r =
Tint ->
Val.lessdef (
ms r)
rs#(
ireg_of r).
Proof.
Lemma freg_val:
forall ms sp rs r,
agree ms sp rs ->
mreg_type r =
Tfloat ->
Val.lessdef (
ms r)
rs#(
freg_of r).
Proof.
Lemma sp_val:
forall ms sp rs,
agree ms sp rs ->
sp =
rs#
GPR1.
Proof.
intros. elim H; auto.
Qed.
Lemma agree_exten:
forall ms sp rs rs',
agree ms sp rs ->
(
forall r,
is_data_reg r =
true ->
rs'#
r =
rs#
r) ->
agree ms sp rs'.
Proof.
intros. inv H. constructor; auto.
intros. rewrite H0; auto with ppcgen.
Qed.
Preservation of register agreement under various assignments.
Lemma agree_set_mreg:
forall ms sp rs r v rs',
agree ms sp rs ->
Val.lessdef v (
rs'#(
preg_of r)) ->
(
forall r',
is_data_reg r' =
true ->
r' <>
preg_of r ->
rs'#
r' =
rs#
r') ->
agree (
Regmap.set r v ms)
sp rs'.
Proof.
intros.
inv H.
constructor;
auto with ppcgen.
intros.
unfold Regmap.set.
destruct (
RegEq.eq r0 r).
subst r0.
auto.
rewrite H1;
auto with ppcgen.
red;
intros;
elim n;
apply preg_of_injective;
auto.
Qed.
Hint Resolve agree_set_mreg:
ppcgen.
Lemma agree_set_mireg:
forall ms sp rs r v (
rs':
regset),
agree ms sp rs ->
Val.lessdef v (
rs'#(
ireg_of r)) ->
mreg_type r =
Tint ->
(
forall r',
is_data_reg r' =
true ->
r' <>
preg_of r ->
rs'#
r' =
rs#
r') ->
agree (
Regmap.set r v ms)
sp rs'.
Proof.
intros.
eapply agree_set_mreg;
eauto.
unfold preg_of;
rewrite H1;
auto.
Qed.
Hint Resolve agree_set_mireg:
ppcgen.
Lemma agree_set_mfreg:
forall ms sp rs r v (
rs':
regset),
agree ms sp rs ->
Val.lessdef v (
rs'#(
freg_of r)) ->
mreg_type r =
Tfloat ->
(
forall r',
is_data_reg r' =
true ->
r' <>
preg_of r ->
rs'#
r' =
rs#
r') ->
agree (
Regmap.set r v ms)
sp rs'.
Proof.
intros.
eapply agree_set_mreg;
eauto.
unfold preg_of;
rewrite H1;
auto.
Qed.
Lemma agree_set_other:
forall ms sp rs r v,
agree ms sp rs ->
is_data_reg r =
false ->
agree ms sp (
rs#
r <-
v).
Proof.
Hint Resolve agree_set_other:
ppcgen.
Lemma agree_nextinstr:
forall ms sp rs,
agree ms sp rs ->
agree ms sp (
nextinstr rs).
Proof.
Hint Resolve agree_nextinstr:
ppcgen.
Lemma agree_undef_regs:
forall rl ms sp rs rs',
agree ms sp rs ->
(
forall r,
is_data_reg r =
true -> ~
In r (
List.map preg_of rl) ->
rs'#
r =
rs#
r) ->
agree (
undef_regs rl ms)
sp rs'.
Proof.
induction rl;
simpl;
intros.
apply agree_exten with rs;
auto.
apply IHrl with (
rs#(
preg_of a) <- (
rs'#(
preg_of a))).
apply agree_set_mreg with rs;
auto with ppcgen.
intros.
unfold Pregmap.set.
destruct (
PregEq.eq r' (
preg_of a)).
congruence.
auto.
intros.
unfold Pregmap.set.
destruct (
PregEq.eq r (
preg_of a)).
congruence.
apply H0;
auto.
intuition congruence.
Qed.
Lemma agree_undef_temps:
forall ms sp rs rs',
agree ms sp rs ->
(
forall r,
is_nontemp_reg r =
true ->
rs'#
r =
rs#
r) ->
agree (
undef_temps ms)
sp rs'.
Proof.
unfold undef_temps.
intros.
apply agree_undef_regs with rs;
auto.
simpl.
unfold preg_of;
simpl.
intros.
intuition.
apply H0.
destruct r;
simpl in *;
auto.
destruct i;
intuition.
destruct f;
intuition.
Qed.
Hint Resolve agree_undef_temps:
ppcgen.
Lemma agree_set_mreg_undef_temps:
forall ms sp rs r v rs',
agree ms sp rs ->
Val.lessdef v (
rs'#(
preg_of r)) ->
(
forall r',
is_nontemp_reg r' =
true ->
r' <>
preg_of r ->
rs'#
r' =
rs#
r') ->
agree (
Regmap.set r v (
undef_temps ms))
sp rs'.
Proof.
Lemma agree_set_twice_mireg:
forall ms sp rs r v v1 v',
agree (
Regmap.set r v1 ms)
sp rs ->
mreg_type r =
Tint ->
Val.lessdef v v' ->
agree (
Regmap.set r v ms)
sp (
rs#(
ireg_of r) <-
v').
Proof.
Useful properties of the PC and GPR0 registers.
Lemma nextinstr_inv:
forall r rs,
r <>
PC -> (
nextinstr rs)#
r =
rs#
r.
Proof.
intros.
unfold nextinstr.
apply Pregmap.gso.
auto.
Qed.
Hint Resolve nextinstr_inv:
ppcgen.
Lemma gpr_or_zero_not_zero:
forall rs r,
r <>
GPR0 ->
gpr_or_zero rs r =
rs#
r.
Proof.
intros.
unfold gpr_or_zero.
case (
ireg_eq r GPR0);
tauto.
Qed.
Lemma gpr_or_zero_zero:
forall rs,
gpr_or_zero rs GPR0 =
Vzero.
Proof.
intros. reflexivity.
Qed.
Hint Resolve gpr_or_zero_not_zero gpr_or_zero_zero:
ppcgen.
Connection between Mach and Asm calling conventions for external
functions.
Lemma extcall_arg_match:
forall ms sp rs m m'
l v,
agree ms sp rs ->
Mem.extends m m' ->
Machsem.extcall_arg ms m sp l v ->
exists v',
Asm.extcall_arg rs m'
l v' /\
Val.lessdef v v'.
Proof.
intros.
inv H1.
exists (
rs#(
preg_of r));
split.
constructor.
eapply preg_val;
eauto.
unfold load_stack in H2.
exploit Mem.loadv_extends;
eauto.
intros [
v' [
A B]].
rewrite (
sp_val _ _ _ H)
in A.
exists v';
split;
auto.
destruct ty;
econstructor.
reflexivity.
assumption.
reflexivity.
assumption.
Qed.
Lemma extcall_args_match:
forall ms sp rs m m',
agree ms sp rs ->
Mem.extends m m' ->
forall ll vl,
list_forall2 (
Machsem.extcall_arg ms m sp)
ll vl ->
exists vl',
list_forall2 (
Asm.extcall_arg rs m')
ll vl' /\
Val.lessdef_list vl vl'.
Proof.
induction 3;
intros.
exists (@
nil val);
split.
constructor.
constructor.
exploit extcall_arg_match;
eauto.
intros [
v1' [
A B]].
destruct IHlist_forall2 as [
vl' [
C D]].
exists (
v1' ::
vl');
split;
constructor;
auto.
Qed.
Lemma extcall_arguments_match:
forall ms m m'
sp rs sg args,
agree ms sp rs ->
Mem.extends m m' ->
Machsem.extcall_arguments ms m sp sg args ->
exists args',
Asm.extcall_arguments rs m'
sg args' /\
Val.lessdef_list args args'.
Proof.
unfold Machsem.extcall_arguments,
Asm.extcall_arguments;
intros.
eapply extcall_args_match;
eauto.
Qed.
Translation of arguments to annotations.
Lemma annot_arg_match:
forall ms sp rs m m'
p v,
agree ms sp rs ->
Mem.extends m m' ->
Machsem.annot_arg ms m sp p v ->
exists v',
Asm.annot_arg rs m' (
transl_annot_param p)
v' /\
Val.lessdef v v'.
Proof.
intros.
inv H1;
simpl.
exists (
rs (
preg_of r));
split.
constructor.
eapply preg_val;
eauto.
exploit Mem.load_extends;
eauto.
intros [
v' [
A B]].
exists v';
split;
auto.
inv H.
econstructor;
eauto.
Qed.
Lemma annot_arguments_match:
forall ms sp rs m m',
agree ms sp rs ->
Mem.extends m m' ->
forall pl vl,
Machsem.annot_arguments ms m sp pl vl ->
exists vl',
Asm.annot_arguments rs m' (
map transl_annot_param pl)
vl'
/\
Val.lessdef_list vl vl'.
Proof.
induction 3;
intros.
exists (@
nil val);
split.
constructor.
constructor.
exploit annot_arg_match;
eauto.
intros [
v1' [
A B]].
destruct IHlist_forall2 as [
vl' [
C D]].
exists (
v1' ::
vl');
split;
constructor;
auto.
Qed.
Execution of straight-line code
Section STRAIGHTLINE.
Variable ge:
genv.
Variable fn:
code.
Straight-line code is composed of PPC instructions that execute
in sequence (no branches, no function calls and returns).
The following inductive predicate relates the machine states
before and after executing a straight-line sequence of instructions.
Instructions are taken from the first list instead of being fetched
from memory.
Inductive exec_straight:
code ->
regset ->
mem ->
code ->
regset ->
mem ->
Prop :=
|
exec_straight_one:
forall i1 c rs1 m1 rs2 m2,
exec_instr ge fn i1 rs1 m1 =
OK rs2 m2 ->
rs2#
PC =
Val.add rs1#
PC Vone ->
exec_straight (
i1 ::
c)
rs1 m1 c rs2 m2
|
exec_straight_step:
forall i c rs1 m1 rs2 m2 c'
rs3 m3,
exec_instr ge fn i rs1 m1 =
OK rs2 m2 ->
rs2#
PC =
Val.add rs1#
PC Vone ->
exec_straight c rs2 m2 c'
rs3 m3 ->
exec_straight (
i ::
c)
rs1 m1 c'
rs3 m3.
Lemma exec_straight_trans:
forall c1 rs1 m1 c2 rs2 m2 c3 rs3 m3,
exec_straight c1 rs1 m1 c2 rs2 m2 ->
exec_straight c2 rs2 m2 c3 rs3 m3 ->
exec_straight c1 rs1 m1 c3 rs3 m3.
Proof.
Lemma exec_straight_two:
forall i1 i2 c rs1 m1 rs2 m2 rs3 m3,
exec_instr ge fn i1 rs1 m1 =
OK rs2 m2 ->
exec_instr ge fn i2 rs2 m2 =
OK rs3 m3 ->
rs2#
PC =
Val.add rs1#
PC Vone ->
rs3#
PC =
Val.add rs2#
PC Vone ->
exec_straight (
i1 ::
i2 ::
c)
rs1 m1 c rs3 m3.
Proof.
Lemma exec_straight_three:
forall i1 i2 i3 c rs1 m1 rs2 m2 rs3 m3 rs4 m4,
exec_instr ge fn i1 rs1 m1 =
OK rs2 m2 ->
exec_instr ge fn i2 rs2 m2 =
OK rs3 m3 ->
exec_instr ge fn i3 rs3 m3 =
OK rs4 m4 ->
rs2#
PC =
Val.add rs1#
PC Vone ->
rs3#
PC =
Val.add rs2#
PC Vone ->
rs4#
PC =
Val.add rs3#
PC Vone ->
exec_straight (
i1 ::
i2 ::
i3 ::
c)
rs1 m1 c rs4 m4.
Proof.
Correctness of PowerPC constructor functions
Ltac SIMP :=
(
rewrite nextinstr_inv ||
rewrite Pregmap.gss ||
rewrite Pregmap.gso);
auto with ppcgen.
Properties of comparisons.
Lemma compare_float_spec:
forall rs v1 v2,
let rs1 :=
nextinstr (
compare_float rs v1 v2)
in
rs1#
CR0_0 =
Val.cmpf Clt v1 v2
/\
rs1#
CR0_1 =
Val.cmpf Cgt v1 v2
/\
rs1#
CR0_2 =
Val.cmpf Ceq v1 v2
/\
forall r',
r' <>
CR0_0 ->
r' <>
CR0_1 ->
r' <>
CR0_2 ->
r' <>
CR0_3 ->
r' <>
PC ->
rs1#
r' =
rs#
r'.
Proof.
intros. unfold rs1.
split. reflexivity.
split. reflexivity.
split. reflexivity.
intros. unfold compare_float. repeat SIMP.
Qed.
Lemma compare_sint_spec:
forall rs v1 v2,
let rs1 :=
nextinstr (
compare_sint rs v1 v2)
in
rs1#
CR0_0 =
Val.cmp Clt v1 v2
/\
rs1#
CR0_1 =
Val.cmp Cgt v1 v2
/\
rs1#
CR0_2 =
Val.cmp Ceq v1 v2
/\
forall r',
r' <>
CR0_0 ->
r' <>
CR0_1 ->
r' <>
CR0_2 ->
r' <>
CR0_3 ->
r' <>
PC ->
rs1#
r' =
rs#
r'.
Proof.
intros. unfold rs1.
split. reflexivity.
split. reflexivity.
split. reflexivity.
intros. unfold compare_sint. repeat SIMP.
Qed.
Lemma compare_uint_spec:
forall rs m v1 v2,
let rs1 :=
nextinstr (
compare_uint rs m v1 v2)
in
rs1#
CR0_0 =
Val.cmpu (
Mem.valid_pointer m)
Clt v1 v2
/\
rs1#
CR0_1 =
Val.cmpu (
Mem.valid_pointer m)
Cgt v1 v2
/\
rs1#
CR0_2 =
Val.cmpu (
Mem.valid_pointer m)
Ceq v1 v2
/\
forall r',
r' <>
CR0_0 ->
r' <>
CR0_1 ->
r' <>
CR0_2 ->
r' <>
CR0_3 ->
r' <>
PC ->
rs1#
r' =
rs#
r'.
Proof.
intros. unfold rs1.
split. reflexivity.
split. reflexivity.
split. reflexivity.
intros. unfold compare_uint. repeat SIMP.
Qed.
Loading a constant.
Lemma loadimm_correct:
forall r n k rs m,
exists rs',
exec_straight (
loadimm r n k)
rs m k rs'
m
/\
rs'#
r =
Vint n
/\
forall r':
preg,
r' <>
r ->
r' <>
PC ->
rs'#
r' =
rs#
r'.
Proof.
Add integer immediate.
Lemma addimm_correct:
forall r1 r2 n k rs m,
r1 <>
GPR0 ->
r2 <>
GPR0 ->
exists rs',
exec_straight (
addimm r1 r2 n k)
rs m k rs'
m
/\
rs'#
r1 =
Val.add rs#
r2 (
Vint n)
/\
forall r':
preg,
r' <>
r1 ->
r' <>
PC ->
rs'#
r' =
rs#
r'.
Proof.
And integer immediate.
Lemma andimm_base_correct:
forall r1 r2 n k (
rs :
regset)
m,
r2 <>
GPR0 ->
let v :=
Val.and rs#
r2 (
Vint n)
in
exists rs',
exec_straight (
andimm_base r1 r2 n k)
rs m k rs'
m
/\
rs'#
r1 =
v
/\
rs'#
CR0_2 =
Val.cmp Ceq v Vzero
/\
forall r',
is_data_reg r' =
true ->
r' <>
r1 ->
rs'#
r' =
rs#
r'.
Proof.
Lemma andimm_correct:
forall r1 r2 n k (
rs :
regset)
m,
r2 <>
GPR0 ->
exists rs',
exec_straight (
andimm r1 r2 n k)
rs m k rs'
m
/\
rs'#
r1 =
Val.and rs#
r2 (
Vint n)
/\
forall r',
is_data_reg r' =
true ->
r' <>
r1 ->
rs'#
r' =
rs#
r'.
Proof.
Or integer immediate.
Lemma orimm_correct:
forall r1 (
r2:
ireg)
n k (
rs :
regset)
m,
let v :=
Val.or rs#
r2 (
Vint n)
in
exists rs',
exec_straight (
orimm r1 r2 n k)
rs m k rs'
m
/\
rs'#
r1 =
v
/\
forall r':
preg,
r' <>
r1 ->
r' <>
PC ->
rs'#
r' =
rs#
r'.
Proof.
Xor integer immediate.
Lemma xorimm_correct:
forall r1 (
r2:
ireg)
n k (
rs :
regset)
m,
let v :=
Val.xor rs#
r2 (
Vint n)
in
exists rs',
exec_straight (
xorimm r1 r2 n k)
rs m k rs'
m
/\
rs'#
r1 =
v
/\
forall r':
preg,
r' <>
r1 ->
r' <>
PC ->
rs'#
r' =
rs#
r'.
Proof.
Rotate and mask.
Lemma rolm_correct:
forall r1 r2 amount mask k (
rs :
regset)
m,
r1 <>
GPR0 ->
exists rs',
exec_straight (
rolm r1 r2 amount mask k)
rs m k rs'
m
/\
rs'#
r1 =
Val.rolm rs#
r2 amount mask
/\
forall r',
is_data_reg r' =
true ->
r' <>
r1 ->
rs'#
r' =
rs#
r'.
Proof.
Indexed memory loads.
Lemma loadind_correct:
forall (
base:
ireg)
ofs ty dst k (
rs:
regset)
m v,
Mem.loadv (
chunk_of_type ty)
m (
Val.add rs#
base (
Vint ofs)) =
Some v ->
mreg_type dst =
ty ->
base <>
GPR0 ->
exists rs',
exec_straight (
loadind base ofs ty dst k)
rs m k rs'
m
/\
rs'#(
preg_of dst) =
v
/\
forall r,
r <>
PC ->
r <>
preg_of dst ->
r <>
GPR0 ->
rs'#
r =
rs#
r.
Proof.
intros.
unfold loadind.
destruct (
Int.eq (
high_s ofs)
Int.zero).
exists (
nextinstr (
rs#(
preg_of dst) <-
v));
split.
unfold preg_of.
rewrite H0.
destruct ty;
apply exec_straight_one;
auto with ppcgen;
simpl.
unfold load1.
rewrite gpr_or_zero_not_zero;
auto.
simpl in *.
rewrite H.
auto.
unfold load1.
rewrite gpr_or_zero_not_zero;
auto.
simpl in *.
rewrite H.
auto.
split.
repeat SIMP.
intros.
repeat SIMP.
exploit (
loadimm_correct GPR0 ofs);
eauto.
intros [
rs' [
A [
B C]]].
exists (
nextinstr (
rs'#(
preg_of dst) <-
v));
split.
eapply exec_straight_trans.
eexact A.
unfold preg_of.
rewrite H0.
destruct ty;
apply exec_straight_one;
auto with ppcgen;
simpl.
unfold load2.
rewrite B.
rewrite C;
auto with ppcgen.
simpl in H.
rewrite H.
auto.
unfold load2.
rewrite B.
rewrite C;
auto with ppcgen.
simpl in H.
rewrite H.
auto.
split.
repeat SIMP.
intros.
repeat SIMP.
Qed.
Indexed memory stores.
Lemma storeind_correct:
forall (
base:
ireg)
ofs ty src k (
rs:
regset)
m m',
Mem.storev (
chunk_of_type ty)
m (
Val.add rs#
base (
Vint ofs)) (
rs#(
preg_of src)) =
Some m' ->
mreg_type src =
ty ->
base <>
GPR0 ->
exists rs',
exec_straight (
storeind src base ofs ty k)
rs m k rs'
m'
/\
forall r,
r <>
PC ->
r <>
GPR0 ->
rs'#
r =
rs#
r.
Proof.
intros.
unfold storeind.
destruct (
Int.eq (
high_s ofs)
Int.zero).
exists (
nextinstr rs);
split.
destruct ty;
apply exec_straight_one;
auto with ppcgen;
simpl.
unfold store1.
rewrite gpr_or_zero_not_zero;
auto.
simpl in *.
unfold preg_of in H;
rewrite H0 in H.
rewrite H.
auto.
unfold store1.
rewrite gpr_or_zero_not_zero;
auto.
simpl in *.
unfold preg_of in H;
rewrite H0 in H.
rewrite H.
auto.
intros.
apply nextinstr_inv;
auto.
exploit (
loadimm_correct GPR0 ofs);
eauto.
intros [
rs' [
A [
B C]]].
assert (
rs'
base =
rs base).
apply C;
auto with ppcgen.
assert (
rs' (
preg_of src) =
rs (
preg_of src)).
apply C;
auto with ppcgen.
exists (
nextinstr rs').
split.
eapply exec_straight_trans.
eexact A.
destruct ty;
apply exec_straight_one;
auto with ppcgen;
simpl.
unfold store2.
replace (
IR (
ireg_of src))
with (
preg_of src).
rewrite H2;
rewrite H3.
rewrite B.
simpl in H.
rewrite H.
auto.
unfold preg_of;
rewrite H0;
auto.
unfold store2.
replace (
FR (
freg_of src))
with (
preg_of src).
rewrite H2;
rewrite H3.
rewrite B.
simpl in H.
rewrite H.
auto.
unfold preg_of;
rewrite H0;
auto.
intros.
rewrite nextinstr_inv;
auto.
Qed.
Float comparisons.
Lemma floatcomp_correct:
forall cmp (
r1 r2:
freg)
k rs m,
exists rs',
exec_straight (
floatcomp cmp r1 r2 k)
rs m k rs'
m
/\
rs'#(
reg_of_crbit (
fst (
crbit_for_fcmp cmp))) =
(
if snd (
crbit_for_fcmp cmp)
then Val.cmpf cmp rs#
r1 rs#
r2
else Val.notbool (
Val.cmpf cmp rs#
r1 rs#
r2))
/\
forall r',
r' <>
PC ->
r' <>
CR0_0 ->
r' <>
CR0_1 ->
r' <>
CR0_2 ->
r' <>
CR0_3 ->
rs'#
r' =
rs#
r'.
Proof.
Ltac TypeInv :=
match goal with
|
H: (
List.map ?
f ?
x =
nil) |-
_ =>
destruct x; [
clear H |
simpl in H;
discriminate]
|
H: (
List.map ?
f ?
x = ?
hd :: ?
tl) |-
_ =>
destruct x;
simpl in H;
[
discriminate |
injection H;
clear H;
let T :=
fresh "
T"
in (
intros H T;
TypeInv) ]
|
_ =>
idtac
end.
Ltac UseTypeInfo :=
match goal with
|
T: (
mreg_type ?
r = ?
t),
H:
context[
preg_of ?
r] |-
_ =>
unfold preg_of in H;
UseTypeInfo
|
T: (
mreg_type ?
r = ?
t),
H:
context[
mreg_type ?
r] |-
_ =>
rewrite T in H;
UseTypeInfo
|
T: (
mreg_type ?
r = ?
t) |-
context[
preg_of ?
r] =>
unfold preg_of;
UseTypeInfo
|
T: (
mreg_type ?
r = ?
t) |-
context[
mreg_type ?
r] =>
rewrite T;
UseTypeInfo
|
_ =>
idtac
end.
Translation of conditions.
Lemma transl_cond_correct_1:
forall cond args k rs m,
map mreg_type args =
type_of_condition cond ->
exists rs',
exec_straight (
transl_cond cond args k)
rs m k rs'
m
/\
rs'#(
reg_of_crbit (
fst (
crbit_for_cond cond))) =
(
if snd (
crbit_for_cond cond)
then Val.of_optbool (
eval_condition cond (
map rs (
map preg_of args))
m)
else Val.notbool (
Val.of_optbool (
eval_condition cond (
map rs (
map preg_of args))
m)))
/\
forall r,
is_data_reg r =
true ->
rs'#
r =
rs#
r.
Proof.
Lemma transl_cond_correct_2:
forall cond args k rs m b,
map mreg_type args =
type_of_condition cond ->
eval_condition cond (
map rs (
map preg_of args))
m =
Some b ->
exists rs',
exec_straight (
transl_cond cond args k)
rs m k rs'
m
/\
rs'#(
reg_of_crbit (
fst (
crbit_for_cond cond))) =
(
if snd (
crbit_for_cond cond)
then Val.of_bool b
else Val.notbool (
Val.of_bool b))
/\
forall r,
is_data_reg r =
true ->
rs'#
r =
rs#
r.
Proof.
Lemma transl_cond_correct:
forall cond args k ms sp rs m b m',
map mreg_type args =
type_of_condition cond ->
agree ms sp rs ->
eval_condition cond (
map ms args)
m =
Some b ->
Mem.extends m m' ->
exists rs',
exec_straight (
transl_cond cond args k)
rs m'
k rs'
m'
/\
rs'#(
reg_of_crbit (
fst (
crbit_for_cond cond))) =
(
if snd (
crbit_for_cond cond)
then Val.of_bool b
else Val.notbool (
Val.of_bool b))
/\
agree ms sp rs'.
Proof.
Translation of condition operators
Remark add_carry_eq0:
forall i,
Vint (
Int.add (
Int.add (
Int.sub Int.zero i)
i)
(
Int.add_carry Int.zero (
Int.xor i Int.mone)
Int.one)) =
Val.of_bool (
Int.eq i Int.zero).
Proof.
Remark add_carry_ne0:
forall i,
Vint (
Int.add (
Int.add i (
Int.xor (
Int.add i Int.mone)
Int.mone))
(
Int.add_carry i Int.mone Int.zero)) =
Val.of_bool (
negb (
Int.eq i Int.zero)).
Proof.
Lemma transl_cond_op_correct:
forall cond args r k rs m,
mreg_type r =
Tint ->
map mreg_type args =
type_of_condition cond ->
exists rs',
exec_straight (
transl_cond_op cond args r k)
rs m k rs'
m
/\
rs'#(
ireg_of r) =
Val.of_optbool (
eval_condition cond (
map rs (
map preg_of args))
m)
/\
forall r',
is_data_reg r' =
true ->
r' <>
ireg_of r ->
rs'#
r' =
rs#
r'.
Proof.
Translation of arithmetic operations.
Ltac TranslOpSimpl :=
econstructor;
split;
[
apply exec_straight_one; [
simpl;
eauto |
reflexivity]
|
split;
intros; (
repeat SIMP;
fail) ].
Lemma transl_op_correct_aux:
forall op args res k (
rs:
regset)
m v,
wt_instr (
Mop op args res) ->
eval_operation ge (
rs#
GPR1)
op (
map rs (
map preg_of args))
m =
Some v ->
exists rs',
exec_straight (
transl_op op args res k)
rs m k rs'
m
/\
rs'#(
preg_of res) =
v
/\
forall r,
match op with Omove =>
is_data_reg r =
true |
_ =>
is_nontemp_reg r =
true end ->
r <>
preg_of res ->
rs'#
r =
rs#
r.
Proof.
Lemma transl_op_correct:
forall op args res k ms sp rs m v m',
wt_instr (
Mop op args res) ->
agree ms sp rs ->
eval_operation ge sp op (
map ms args)
m =
Some v ->
Mem.extends m m' ->
exists rs',
exec_straight (
transl_op op args res k)
rs m'
k rs'
m'
/\
agree (
Regmap.set res v (
undef_op op ms))
sp rs'.
Proof.
Lemma transl_load_store_correct:
forall (
mk1:
constant ->
ireg ->
instruction) (
mk2:
ireg ->
ireg ->
instruction)
addr args (
temp:
ireg)
k ms sp rs m ms'
m',
(
forall cst (
r1:
ireg) (
rs1:
regset)
k,
eval_addressing ge sp addr (
map rs (
map preg_of args)) =
Some(
Val.add (
gpr_or_zero rs1 r1) (
const_low ge cst)) ->
(
forall (
r:
preg),
r <>
PC ->
r <>
temp ->
rs1 r =
rs r) ->
exists rs',
exec_straight (
mk1 cst r1 ::
k)
rs1 m k rs'
m' /\
agree ms'
sp rs') ->
(
forall (
r1 r2:
ireg)
k,
eval_addressing ge sp addr (
map rs (
map preg_of args)) =
Some(
Val.add rs#
r1 rs#
r2) ->
exists rs',
exec_straight (
mk2 r1 r2 ::
k)
rs m k rs'
m' /\
agree ms'
sp rs') ->
agree ms sp rs ->
map mreg_type args =
type_of_addressing addr ->
temp <>
GPR0 ->
exists rs',
exec_straight (
transl_load_store mk1 mk2 addr args temp k)
rs m
k rs'
m'
/\
agree ms'
sp rs'.
Proof.
Translation of memory loads.
Lemma transl_load_correct:
forall (
mk1:
constant ->
ireg ->
instruction) (
mk2:
ireg ->
ireg ->
instruction)
chunk addr args k ms sp rs m m'
dst a v,
(
forall cst (
r1:
ireg) (
rs1:
regset),
exec_instr ge fn (
mk1 cst r1)
rs1 m' =
load1 ge chunk (
preg_of dst)
cst r1 rs1 m') ->
(
forall (
r1 r2:
ireg) (
rs1:
regset),
exec_instr ge fn (
mk2 r1 r2)
rs1 m' =
load2 chunk (
preg_of dst)
r1 r2 rs1 m') ->
agree ms sp rs ->
map mreg_type args =
type_of_addressing addr ->
eval_addressing ge sp addr (
map ms args) =
Some a ->
Mem.loadv chunk m a =
Some v ->
Mem.extends m m' ->
exists rs',
exec_straight (
transl_load_store mk1 mk2 addr args GPR12 k)
rs m'
k rs'
m'
/\
agree (
Regmap.set dst v (
undef_temps ms))
sp rs'.
Proof.
Translation of memory stores.
Lemma transl_store_correct:
forall (
mk1:
constant ->
ireg ->
instruction) (
mk2:
ireg ->
ireg ->
instruction)
chunk addr args k ms sp rs m src a m'
m1,
(
forall cst (
r1:
ireg) (
rs1 rs2:
regset) (
m2:
mem),
store1 ge chunk (
preg_of src)
cst r1 rs1 m1 =
OK rs2 m2 ->
exists rs3,
exec_instr ge fn (
mk1 cst r1)
rs1 m1 =
OK rs3 m2
/\ (
forall (
r:
preg),
r <>
FPR13 ->
rs3 r =
rs2 r)) ->
(
forall (
r1 r2:
ireg) (
rs1 rs2:
regset) (
m2:
mem),
store2 chunk (
preg_of src)
r1 r2 rs1 m1 =
OK rs2 m2 ->
exists rs3,
exec_instr ge fn (
mk2 r1 r2)
rs1 m1 =
OK rs3 m2
/\ (
forall (
r:
preg),
r <>
FPR13 ->
rs3 r =
rs2 r)) ->
agree ms sp rs ->
map mreg_type args =
type_of_addressing addr ->
eval_addressing ge sp addr (
map ms args) =
Some a ->
Mem.storev chunk m a (
ms src) =
Some m' ->
Mem.extends m m1 ->
exists m1',
Mem.extends m'
m1'
/\
exists rs',
exec_straight (
transl_load_store mk1 mk2 addr args (
int_temp_for src)
k)
rs m1
k rs'
m1'
/\
agree (
undef_temps ms)
sp rs'.
Proof.
End STRAIGHTLINE.