diff options
author | Cyril SIX <cyril.six@kalray.eu> | 2020-10-16 15:52:19 +0200 |
---|---|---|
committer | Cyril SIX <cyril.six@kalray.eu> | 2020-10-16 15:52:19 +0200 |
commit | ae3e1ed0515236e25924b12d475bc991a33b7632 (patch) | |
tree | 154428527771fbdec77f23846652d252400f81c8 | |
parent | fae36491fa22adaaf447e189988848483eb01dcd (diff) | |
parent | 53544f625ac6ed6ddb000f5ae8f28faac0da7a7b (diff) | |
download | compcert-kvx-ae3e1ed0515236e25924b12d475bc991a33b7632.tar.gz compcert-kvx-ae3e1ed0515236e25924b12d475bc991a33b7632.zip |
Merge remote-tracking branch 'origin/kvx-test-prepass' into mppa-RTLpathSE-verif
-rw-r--r-- | Makefile | 21 | ||||
-rw-r--r-- | Makefile.extr | 8 | ||||
-rw-r--r-- | aarch64/Asmgenproof1.v | 87 | ||||
-rw-r--r-- | aarch64/ConstpropOpproof.v | 121 | ||||
-rw-r--r-- | aarch64/Op.v | 179 | ||||
-rw-r--r-- | aarch64/OpWeights.ml | 329 | ||||
-rw-r--r-- | aarch64/PrepassSchedulingOracle.ml (renamed from kvx/lib/PrepassSchedulingOracle.ml) | 45 | ||||
-rw-r--r-- | aarch64/SelectLongproof.v | 26 | ||||
-rw-r--r-- | aarch64/SelectOpproof.v | 28 | ||||
-rw-r--r-- | aarch64/ValueAOp.v | 24 | ||||
l--------- | arm/PrepassSchedulingOracle.ml | 1 | ||||
-rw-r--r-- | backend/Duplicateaux.ml | 11 | ||||
-rw-r--r-- | backend/ValueDomain.v | 483 | ||||
-rwxr-xr-x | config_kvx_elf.sh | 1 | ||||
-rwxr-xr-x | configure | 6 | ||||
-rw-r--r-- | doc/index-kvx.html | 4 | ||||
-rw-r--r-- | kvx/Asm.v | 40 | ||||
-rw-r--r-- | kvx/Asmblock.v | 52 | ||||
-rw-r--r-- | kvx/Asmblockprops.v | 6 | ||||
-rw-r--r-- | kvx/Asmgenproof.v | 4 | ||||
-rw-r--r-- | kvx/Asmvliw.v | 16 | ||||
-rw-r--r-- | kvx/CSE2depsproof.v | 6 | ||||
-rw-r--r-- | kvx/CombineOpproof.v | 56 | ||||
-rw-r--r-- | kvx/ConstpropOpproof.v | 196 | ||||
-rw-r--r-- | kvx/Conventions1.v | 34 | ||||
-rw-r--r-- | kvx/ExtValues.v | 72 | ||||
-rw-r--r-- | kvx/NeedOp.v | 54 | ||||
-rw-r--r-- | kvx/Op.v | 484 | ||||
-rw-r--r-- | kvx/OpWeights.ml | 4 | ||||
-rw-r--r-- | kvx/Peephole.v | 2 | ||||
-rw-r--r-- | kvx/PostpassSchedulingOracle.ml | 27 | ||||
l--------- | kvx/PrepassSchedulingOracle.ml | 1 | ||||
-rw-r--r-- | kvx/Stacklayout.v | 6 | ||||
-rw-r--r-- | kvx/ValueAOp.v | 313 | ||||
-rw-r--r-- | kvx/abstractbb/AbstractBasicBlocksDef.v | 94 | ||||
-rw-r--r-- | kvx/abstractbb/ImpSimuTest.v | 82 | ||||
-rw-r--r-- | kvx/abstractbb/Parallelizability.v | 149 | ||||
-rw-r--r-- | kvx/abstractbb/SeqSimuTheory.v | 77 | ||||
-rw-r--r-- | kvx/lib/ForwardSimulationBlock.v | 30 | ||||
-rw-r--r-- | kvx/lib/Machblock.v | 14 | ||||
-rw-r--r-- | kvx/lib/Machblockgen.v | 14 | ||||
-rw-r--r-- | kvx/lib/Machblockgenproof.v | 138 | ||||
-rw-r--r-- | lib/Impure/ImpConfig.v (renamed from kvx/abstractbb/Impure/ImpConfig.v) | 0 | ||||
-rw-r--r-- | lib/Impure/ImpCore.v (renamed from kvx/abstractbb/Impure/ImpCore.v) | 0 | ||||
-rw-r--r-- | lib/Impure/ImpExtern.v (renamed from kvx/abstractbb/Impure/ImpExtern.v) | 0 | ||||
-rw-r--r-- | lib/Impure/ImpHCons.v (renamed from kvx/abstractbb/Impure/ImpHCons.v) | 0 | ||||
-rw-r--r-- | lib/Impure/ImpIO.v (renamed from kvx/abstractbb/Impure/ImpIO.v) | 0 | ||||
-rw-r--r-- | lib/Impure/ImpLoops.v (renamed from kvx/abstractbb/Impure/ImpLoops.v) | 0 | ||||
-rw-r--r-- | lib/Impure/ImpMonads.v (renamed from kvx/abstractbb/Impure/ImpMonads.v) | 0 | ||||
-rw-r--r-- | lib/Impure/ImpPrelude.v (renamed from kvx/abstractbb/Impure/ImpPrelude.v) | 0 | ||||
-rw-r--r-- | lib/Impure/LICENSE (renamed from kvx/abstractbb/Impure/LICENSE) | 0 | ||||
-rw-r--r-- | lib/Impure/README.md (renamed from kvx/abstractbb/Impure/README.md) | 0 | ||||
-rw-r--r-- | lib/Impure/ocaml/ImpHConsOracles.ml (renamed from kvx/abstractbb/Impure/ocaml/ImpHConsOracles.ml) | 0 | ||||
-rw-r--r-- | lib/Impure/ocaml/ImpHConsOracles.mli (renamed from kvx/abstractbb/Impure/ocaml/ImpHConsOracles.mli) | 0 | ||||
-rw-r--r-- | lib/Impure/ocaml/ImpIOOracles.ml (renamed from kvx/abstractbb/Impure/ocaml/ImpIOOracles.ml) | 0 | ||||
-rw-r--r-- | lib/Impure/ocaml/ImpIOOracles.mli (renamed from kvx/abstractbb/Impure/ocaml/ImpIOOracles.mli) | 0 | ||||
-rw-r--r-- | lib/Impure/ocaml/ImpLoopOracles.ml (renamed from kvx/abstractbb/Impure/ocaml/ImpLoopOracles.ml) | 0 | ||||
-rw-r--r-- | lib/Impure/ocaml/ImpLoopOracles.mli (renamed from kvx/abstractbb/Impure/ocaml/ImpLoopOracles.mli) | 0 | ||||
l--------- | powerpc/PrepassSchedulingOracle.ml | 1 | ||||
-rw-r--r-- | riscV/Asmgenproof1.v | 45 | ||||
-rw-r--r-- | riscV/ConstpropOpproof.v | 152 | ||||
-rw-r--r-- | riscV/Op.v | 275 | ||||
-rw-r--r-- | riscV/OpWeights.ml | 39 | ||||
l--------- | riscV/PrepassSchedulingOracle.ml | 1 | ||||
-rw-r--r-- | riscV/SelectLongproof.v | 54 | ||||
-rw-r--r-- | riscV/SelectOpproof.v | 70 | ||||
-rw-r--r-- | riscV/ValueAOp.v | 33 | ||||
-rw-r--r-- | runtime/Makefile | 6 | ||||
-rw-r--r-- | scheduling/InstructionScheduler.ml (renamed from kvx/InstructionScheduler.ml) | 45 | ||||
-rw-r--r-- | scheduling/InstructionScheduler.mli (renamed from kvx/InstructionScheduler.mli) | 10 | ||||
-rw-r--r-- | scheduling/RTLpath.v (renamed from kvx/lib/RTLpath.v) | 0 | ||||
-rw-r--r-- | scheduling/RTLpathLivegen.v (renamed from kvx/lib/RTLpathLivegen.v) | 0 | ||||
-rw-r--r-- | scheduling/RTLpathLivegenaux.ml (renamed from kvx/lib/RTLpathLivegenaux.ml) | 0 | ||||
-rw-r--r-- | scheduling/RTLpathLivegenproof.v (renamed from kvx/lib/RTLpathLivegenproof.v) | 8 | ||||
-rw-r--r-- | scheduling/RTLpathSE_impl.v (renamed from kvx/lib/RTLpathSE_impl.v) | 0 | ||||
-rw-r--r-- | scheduling/RTLpathSE_impl_junk.v | 758 | ||||
-rw-r--r-- | scheduling/RTLpathSE_theory.v (renamed from kvx/lib/RTLpathSE_theory.v) | 0 | ||||
-rw-r--r-- | scheduling/RTLpathScheduler.v (renamed from kvx/lib/RTLpathScheduler.v) | 0 | ||||
-rw-r--r-- | scheduling/RTLpathScheduleraux.ml (renamed from kvx/lib/RTLpathScheduleraux.ml) | 0 | ||||
-rw-r--r-- | scheduling/RTLpathSchedulerproof.v (renamed from kvx/lib/RTLpathSchedulerproof.v) | 0 | ||||
-rw-r--r-- | scheduling/RTLpathproof.v (renamed from kvx/lib/RTLpathproof.v) | 0 | ||||
-rw-r--r-- | test/kvx/instr/Makefile | 10 | ||||
-rw-r--r-- | test/kvx/interop/Makefile | 6 | ||||
-rw-r--r-- | test/kvx/lib/Makefile | 6 | ||||
-rw-r--r-- | test/kvx/mmult/Makefile | 8 | ||||
-rw-r--r-- | test/kvx/prng/Makefile | 5 | ||||
-rw-r--r-- | test/kvx/sort/Makefile | 11 | ||||
-rw-r--r-- | test/monniaux/picosat-965/onefile/picosat.c | 9788 | ||||
-rw-r--r-- | test/monniaux/rules.mk | 16 | ||||
-rw-r--r-- | test/monniaux/scheduling/mal_schedule.c | 14 | ||||
-rw-r--r-- | test/monniaux/yarpgen/Makefile | 2 | ||||
-rw-r--r-- | x86/PrepassSchedulingOracle.ml | 5 |
92 files changed, 3357 insertions, 11356 deletions
@@ -23,11 +23,11 @@ endif BACKENDLIB?=Asmgenproof0.v Asmgenproof1.v -DIRS=lib common $(ARCHDIRS) backend cfrontend driver \ +DIRS=lib lib/Impure common $(ARCHDIRS) scheduling backend cfrontend driver \ flocq/Core flocq/Prop flocq/Calc flocq/IEEE754 \ exportclight MenhirLib cparser -RECDIRS=lib common $(ARCHDIRS) backend cfrontend driver flocq exportclight \ +RECDIRS=lib common $(ARCHDIRS) scheduling backend cfrontend driver flocq exportclight \ MenhirLib cparser COQINCLUDES=$(foreach d, $(RECDIRS), -R $(d) $(subst /,.,compcert.$(d))) @@ -60,7 +60,9 @@ VLIB=Axioms.v Coqlib.v Intv.v Maps.v Heaps.v Lattice.v Ordered.v \ HashedSet.v \ Iteration.v Zbits.v Integers.v Archi.v IEEE754_extra.v Floats.v \ Parmov.v UnionFind.v Wfsimpl.v \ - Postorder.v FSetAVLplus.v IntvSets.v Decidableplus.v BoolEqual.v + Postorder.v FSetAVLplus.v IntvSets.v Decidableplus.v BoolEqual.v \ + ImpConfig.v ImpExtern.v ImpIO.v ImpMonads.v \ + ImpCore.v ImpHCons.v ImpLoops.v ImpPrelude.v # Parts common to the front-ends and the back-end (in common/) @@ -111,6 +113,13 @@ BACKEND=\ Asm.v Asmgen.v Asmgenproof.v Asmaux.v \ $(BACKENDLIB) +SCHEDULING= \ + RTLpathLivegenproof.v RTLpathSE_impl_junk.v \ + RTLpathLivegen.v RTLpathSE_impl.v \ + RTLpathproof.v RTLpathSE_theory.v \ + RTLpathSchedulerproof.v RTLpath.v \ + RTLpathScheduler.v + # C front-end modules (in cfrontend/) CFRONTEND=Ctypes.v Cop.v Csyntax.v Csem.v Ctyping.v Cstrategy.v Cexec.v \ @@ -136,7 +145,7 @@ DRIVER=Compopts.v Compiler.v Complements.v # All source files -FILES=$(VLIB) $(COMMON) $(BACKEND) $(CFRONTEND) $(DRIVER) $(FLOCQ) \ +FILES=$(VLIB) $(COMMON) $(BACKEND) $(SCHEDULING) $(CFRONTEND) $(DRIVER) $(FLOCQ) \ $(MENHIRLIB) $(PARSER) # Generated source files @@ -179,6 +188,10 @@ ccomp: .depend.extr compcert.ini driver/Version.ml FORCE ccomp.byte: .depend.extr compcert.ini driver/Version.ml FORCE $(MAKE) -f Makefile.extr ccomp.byte +# DM force compilation without checking dependencies +ccomp.force: .depend.extr compcert.ini driver/Version.ml FORCE + $(MAKE) -f Makefile.extr ccomp.force + clightgen: .depend.extr compcert.ini exportclight/Clightdefs.vo driver/Version.ml FORCE $(MAKE) -f Makefile.extr clightgen clightgen.byte: .depend.extr compcert.ini exportclight/Clightdefs.vo driver/Version.ml FORCE diff --git a/Makefile.extr b/Makefile.extr index 59cc6c1d..75eb6dca 100644 --- a/Makefile.extr +++ b/Makefile.extr @@ -42,8 +42,8 @@ cparser/pre_parser_messages.ml: # Directories containing plain Caml code DIRS=extraction \ - lib common $(ARCH) backend cfrontend cparser driver \ - exportclight debug kvx/unittest kvx/abstractbb/Impure/ocaml \ + lib common $(ARCH) scheduling backend cfrontend cparser driver \ + exportclight debug kvx/unittest lib/Impure/ocaml \ kvx/lib INCLUDES=$(patsubst %,-I %, $(DIRS)) @@ -93,6 +93,10 @@ ccomp: $(CCOMP_OBJS) @echo "Linking $@" @$(OCAMLOPT) -o $@ $(LIBS) $(LINK_OPT) $+ +# DM force compilation without checking dependencies +ccomp.force: + $(OCAMLOPT) -o $@ $(LIBS) $(LINK_OPT) $(CCOMP_OBJS) + ccomp.byte: $(CCOMP_OBJS:.cmx=.cmo) @echo "Linking $@" @$(OCAMLC) -o $@ $(LIBS_BYTE) $+ diff --git a/aarch64/Asmgenproof1.v b/aarch64/Asmgenproof1.v index 0e36bd05..35f1f2d7 100644 --- a/aarch64/Asmgenproof1.v +++ b/aarch64/Asmgenproof1.v @@ -881,7 +881,40 @@ Proof. split. subst v; Simpl. split; intros; Simpl. Qed. - + + +Lemma exec_shrx32_none: forall (rd r1: ireg) (n: int) k (rs: regset) m, + Val.shrx rs#r1 (Vint n) = None -> + r1 <> X16 -> + (IR RA) <> (preg_of_iregsp (RR1 rd)) -> + exists rs', + exec_straight ge fn (shrx32 rd r1 n k) rs m k rs' m + /\ (forall r, data_preg r = true -> r <> rd -> rs'#r = rs#r) + /\ rs' # RA = rs # RA. +Proof. + unfold shrx32; intros. + destruct (Int.eq n Int.zero) eqn:E. +- econstructor; split. apply exec_straight_one; [simpl;eauto|auto]. + split. + + intros. Simpl. + + Simpl. +- generalize (Int.eq_spec n Int.one). + destruct (Int.eq n Int.one); intro ONE. + * subst n. + econstructor; split. eapply exec_straight_two. + all: cbn; auto. + split. + ** intros. + destruct (Val.add _ _); cbn; Simpl. + ** Simpl. + * econstructor; split. eapply exec_straight_three. + all: cbn; auto. + split. + ** intros. + destruct (Val.shr _ _); cbn; Simpl. + ** Simpl. +Qed. + Lemma exec_shrx64: forall (rd r1: ireg) (n: int) k v (rs: regset) m, Val.shrxl rs#r1 (Vint n) = Some v -> r1 <> X16 -> @@ -918,6 +951,38 @@ Proof. split; intros; Simpl. Qed. +Lemma exec_shrx64_none: forall (rd r1: ireg) (n: int) k (rs: regset) m, + Val.shrxl rs#r1 (Vint n) = None -> + r1 <> X16 -> + (IR RA) <> (preg_of_iregsp (RR1 rd)) -> + exists rs', + exec_straight ge fn (shrx64 rd r1 n k) rs m k rs' m + /\ (forall r, data_preg r = true -> r <> rd -> rs'#r = rs#r) + /\ rs' # RA = rs # RA. +Proof. + unfold shrx64; intros. + destruct (Int.eq n Int.zero) eqn:E. +- econstructor; split. apply exec_straight_one; [simpl;eauto|auto]. + split. + + intros. Simpl. + + Simpl. +- generalize (Int.eq_spec n Int.one). + destruct (Int.eq n Int.one); intro ONE. + * subst n. + econstructor; split. eapply exec_straight_two. + all: cbn; auto. + split. + ** intros. + destruct (Val.addl _ _); cbn; Simpl. + ** Simpl. + * econstructor; split. eapply exec_straight_three. + all: cbn; auto. + split. + ** intros. + destruct (Val.shrl _ _); cbn; Simpl. + ** Simpl. +Qed. + (** Condition bits *) Lemma compare_int_spec: forall rs v1 v2 m, @@ -1660,10 +1725,19 @@ Local Transparent Val.add. TranslOpBase. destruct (eval_shift s (rs x0) a); auto. simpl. rewrite Int.or_zero_l; auto. - (* shrx *) - exploit (exec_shrx32 x x0 n); eauto with asmgen. apply (ireg_of_not_RA'' res); eassumption. + destruct (Val.shrx (rs x0) (Vint n)) eqn:TOTAL. + { + exploit (exec_shrx32 x x0 n); eauto with asmgen. apply (ireg_of_not_RA'' res); eassumption. intros (rs' & A & B & C & D). econstructor; split. eexact A. split. rewrite B; auto. split; auto. + } + exploit (exec_shrx32_none x x0 n); eauto with asmgen. apply (ireg_of_not_RA'' res); eassumption. + intros (rs' & A & B & C). + econstructor; split. { eexact A. } + split. { cbn. constructor. } + split; auto. + - (* zero-ext *) TranslOpBase. destruct (rs x0); auto; simpl. rewrite Int.shl_zero. auto. @@ -1736,9 +1810,18 @@ Local Transparent Val.add. TranslOpBase. destruct (eval_shiftl s (rs x0) a); auto. simpl. rewrite Int64.or_zero_l; auto. - (* shrx *) + destruct (Val.shrxl (rs x0) (Vint n)) eqn:TOTAL. + { exploit (exec_shrx64 x x0 n); eauto with asmgen. apply (ireg_of_not_RA'' res); eassumption. intros (rs' & A & B & C & D ). econstructor; split. eexact A. split. rewrite B; auto. auto. + } + exploit (exec_shrx64_none x x0 n); eauto with asmgen. apply (ireg_of_not_RA'' res); eassumption. + intros (rs' & A & B & C). + econstructor; split. { eexact A. } + split. { cbn. constructor. } + split; auto. + - (* zero-ext-l *) TranslOpBase. destruct (rs x0); auto; simpl. rewrite Int64.shl'_zero. auto. diff --git a/aarch64/ConstpropOpproof.v b/aarch64/ConstpropOpproof.v index deab7cd4..c777062c 100644 --- a/aarch64/ConstpropOpproof.v +++ b/aarch64/ConstpropOpproof.v @@ -335,40 +335,63 @@ Qed. Lemma make_divimm_correct: forall n r1 r2 v, - Val.divs e#r1 e#r2 = Some v -> + Val.maketotal (Val.divs e#r1 e#r2) = v -> e#r2 = Vint n -> let (op, args) := make_divimm n r1 r2 in exists w, eval_operation ge (Vptr sp Ptrofs.zero) op e##args m = Some w /\ Val.lessdef v w. Proof. intros; unfold make_divimm. - predSpec Int.eq Int.eq_spec n Int.one; intros. subst. rewrite H0 in H. - destruct (e#r1) eqn:?; - try (rewrite Val.divs_one in H; exists (Vint i); split; simpl; try rewrite Heqv0; auto); - inv H; auto. - destruct (Int.is_power2 n) eqn:?. - destruct (Int.ltu i (Int.repr 31)) eqn:?. - exists v; split; auto. simpl. eapply Val.divs_pow2; eauto. congruence. - exists v; auto. - exists v; auto. + predSpec Int.eq Int.eq_spec n Int.one; intros; subst; rewrite H0. + { destruct (e # r1) eqn:Er1. + all: try (cbn; exists (e # r1); split; auto; fail). + rewrite Val.divs_one. + cbn. + rewrite Er1. + exists (Vint i); split; auto. + } + destruct (Int.is_power2 n) eqn:Power2. + { + destruct (Int.ltu i (Int.repr 31)) eqn:iLT31. + { + cbn. + exists (Val.maketotal (Val.shrx e # r1 (Vint i))); split; auto. + destruct (Val.divs e # r1 (Vint n)) eqn:DIVS; cbn; auto. + rewrite Val.divs_pow2 with (y:=v) (n:=n). + cbn. + all: auto. + } + exists (Val.maketotal (Val.divs e # r1 (Vint n))); split; cbn; auto; congruence. + } + exists (Val.maketotal (Val.divs e # r1 (Vint n))); split; cbn; auto; congruence. Qed. + Lemma make_divuimm_correct: forall n r1 r2 v, - Val.divu e#r1 e#r2 = Some v -> + Val.maketotal (Val.divu e#r1 e#r2) = v -> e#r2 = Vint n -> let (op, args) := make_divuimm n r1 r2 in exists w, eval_operation ge (Vptr sp Ptrofs.zero) op e##args m = Some w /\ Val.lessdef v w. Proof. intros; unfold make_divuimm. - predSpec Int.eq Int.eq_spec n Int.one; intros. subst. rewrite H0 in H. - destruct (e#r1) eqn:?; - try (rewrite Val.divu_one in H; exists (Vint i); split; simpl; try rewrite Heqv0; auto); - inv H; auto. - destruct (Int.is_power2 n) eqn:?. - econstructor; split. simpl; eauto. - rewrite mk_amount32_eq by (eapply Int.is_power2_range; eauto). - rewrite H0 in H. erewrite Val.divu_pow2 by eauto. auto. - exists v; auto. + predSpec Int.eq Int.eq_spec n Int.one; intros; subst; rewrite H0. + { destruct (e # r1) eqn:Er1. + all: try (cbn; exists (e # r1); split; auto; fail). + rewrite Val.divu_one. + cbn. + rewrite Er1. + exists (Vint i); split; auto. + } + destruct (Int.is_power2 n) eqn:Power2. + { + cbn. + rewrite mk_amount32_eq by (eapply Int.is_power2_range; eauto). + exists (Val.shru e # r1 (Vint i)); split; auto. + destruct (Val.divu e # r1 (Vint n)) eqn:DIVU; cbn; auto. + rewrite Val.divu_pow2 with (y:=v) (n:=n). + all: auto. + } + exists (Val.maketotal (Val.divu e # r1 (Vint n))); split; cbn; auto; congruence. Qed. Lemma make_andimm_correct: @@ -503,34 +526,60 @@ Qed. Lemma make_divlimm_correct: forall n r1 r2 v, - Val.divls e#r1 e#r2 = Some v -> + Val.maketotal (Val.divls e#r1 e#r2) = v -> e#r2 = Vlong n -> let (op, args) := make_divlimm n r1 r2 in exists w, eval_operation ge (Vptr sp Ptrofs.zero) op e##args m = Some w /\ Val.lessdef v w. Proof. intros; unfold make_divlimm. - destruct (Int64.is_power2' n) eqn:?. destruct (Int.ltu i (Int.repr 63)) eqn:?. - rewrite H0 in H. econstructor; split. simpl; eauto. eapply Val.divls_pow2; eauto. auto. - exists v; auto. - exists v; auto. + destruct (Int64.is_power2' n) eqn:Power2. + { + destruct (Int.ltu i (Int.repr 63)) eqn:iLT63. + { + cbn. + exists (Val.maketotal (Val.shrxl e # r1 (Vint i))); split; auto. + rewrite H0 in H. + destruct (Val.divls e # r1 (Vlong n)) eqn:DIVS; cbn in H; auto. + { + subst v0. + rewrite Val.divls_pow2 with (y:=v) (n:=n). + cbn. + all: auto. + } + subst. auto. + } + cbn. subst. rewrite H0. + exists (Val.maketotal (Val.divls e # r1 (Vlong n))); split; auto. + } + cbn. subst. rewrite H0. + exists (Val.maketotal (Val.divls e # r1 (Vlong n))); split; auto. Qed. + Lemma make_divluimm_correct: forall n r1 r2 v, - Val.divlu e#r1 e#r2 = Some v -> + Val.maketotal (Val.divlu e#r1 e#r2) = v -> e#r2 = Vlong n -> let (op, args) := make_divluimm n r1 r2 in exists w, eval_operation ge (Vptr sp Ptrofs.zero) op e##args m = Some w /\ Val.lessdef v w. Proof. intros; unfold make_divluimm. destruct (Int64.is_power2' n) eqn:?. + { econstructor; split. simpl; eauto. - rewrite mk_amount64_eq by (eapply Int64.is_power2'_range; eauto). - rewrite H0 in H. destruct (e#r1); inv H. destruct (Int64.eq n Int64.zero); inv H2. - simpl. - erewrite Int64.is_power2'_range by eauto. - erewrite Int64.divu_pow2' by eauto. auto. - exists v; auto. + rewrite H0 in H. destruct (e#r1); inv H. + all: cbn; auto. + { + rewrite mk_amount64_eq by (eapply Int64.is_power2'_range; eauto). + destruct (Int64.eq n Int64.zero); cbn; auto. + erewrite Int64.is_power2'_range by eauto. + erewrite Int64.divu_pow2' by eauto. auto. + } + } + exists v; split; auto. + cbn. + rewrite H. + reflexivity. Qed. Lemma make_andlimm_correct: @@ -679,10 +728,10 @@ Proof. InvApproxRegs; SimplVM; inv H0. apply make_mulimm_correct; auto. - (* divs *) assert (e#r2 = Vint n2). clear H0. InvApproxRegs; SimplVM; auto. - apply make_divimm_correct; auto. + apply make_divimm_correct; auto. congruence. - (* divu *) assert (e#r2 = Vint n2). clear H0. InvApproxRegs; SimplVM; auto. - apply make_divuimm_correct; auto. + apply make_divuimm_correct; auto. congruence. - (* and 1 *) rewrite Val.and_commut in H0. InvApproxRegs; SimplVM; inv H0. apply make_andimm_correct; auto. - (* and 2 *) @@ -745,10 +794,10 @@ Proof. InvApproxRegs; SimplVM; inv H0. apply make_mullimm_correct; auto. - (* divl *) assert (e#r2 = Vlong n2). clear H0. InvApproxRegs; SimplVM; auto. - apply make_divlimm_correct; auto. + apply make_divlimm_correct; auto. congruence. - (* divlu *) assert (e#r2 = Vlong n2). clear H0. InvApproxRegs; SimplVM; auto. - apply make_divluimm_correct; auto. + apply make_divluimm_correct; auto. congruence. - (* andl 1 *) rewrite Val.andl_commut in H0. InvApproxRegs; SimplVM; inv H0. apply make_andlimm_correct; auto. - (* andl 2 *) diff --git a/aarch64/Op.v b/aarch64/Op.v index afc25aa6..0a29ff3e 100644 --- a/aarch64/Op.v +++ b/aarch64/Op.v @@ -386,8 +386,8 @@ Definition eval_operation | Omul, v1 :: v2 :: nil => Some (Val.mul v1 v2) | Omuladd, v1 :: v2 :: v3 :: nil => Some (Val.add v1 (Val.mul v2 v3)) | Omulsub, v1 :: v2 :: v3 :: nil => Some (Val.sub v1 (Val.mul v2 v3)) - | Odiv, v1 :: v2 :: nil => Val.divs v1 v2 - | Odivu, v1 :: v2 :: nil => Val.divu v1 v2 + | Odiv, v1 :: v2 :: nil => Some (Val.maketotal (Val.divs v1 v2)) + | Odivu, v1 :: v2 :: nil => Some (Val.maketotal (Val.divu v1 v2)) | Oand, v1 :: v2 :: nil => Some (Val.and v1 v2) | Oandshift s a, v1 :: v2 :: nil => Some (Val.and v1 (eval_shift s v2 a)) | Oandimm n, v1 :: nil => Some (Val.and v1 (Vint n)) @@ -408,7 +408,7 @@ Definition eval_operation | Oshl, v1 :: v2 :: nil => Some (Val.shl v1 v2) | Oshr, v1 :: v2 :: nil => Some (Val.shr v1 v2) | Oshru, v1 :: v2 :: nil => Some (Val.shru v1 v2) - | Oshrximm n, v1::nil => Val.shrx v1 (Vint n) + | Oshrximm n, v1::nil => Some (Val.maketotal (Val.shrx v1 (Vint n))) | Ozext s, v1 :: nil => Some (Val.zero_ext s v1) | Osext s, v1 :: nil => Some (Val.sign_ext s v1) | Oshlzext s a, v1 :: nil => Some (Val.shl (Val.zero_ext s v1) (Vint a)) @@ -435,8 +435,8 @@ Definition eval_operation | Omullsub, v1 :: v2 :: v3 :: nil => Some (Val.subl v1 (Val.mull v2 v3)) | Omullhs, v1::v2::nil => Some (Val.mullhs v1 v2) | Omullhu, v1::v2::nil => Some (Val.mullhu v1 v2) - | Odivl, v1 :: v2 :: nil => Val.divls v1 v2 - | Odivlu, v1 :: v2 :: nil => Val.divlu v1 v2 + | Odivl, v1 :: v2 :: nil => Some (Val.maketotal (Val.divls v1 v2)) + | Odivlu, v1 :: v2 :: nil => Some (Val.maketotal (Val.divlu v1 v2)) | Oandl, v1 :: v2 :: nil => Some (Val.andl v1 v2) | Oandlshift s a, v1 :: v2 :: nil => Some (Val.andl v1 (eval_shiftl s v2 a)) | Oandlimm n, v1 :: nil => Some (Val.andl v1 (Vlong n)) @@ -457,7 +457,7 @@ Definition eval_operation | Oshll, v1 :: v2 :: nil => Some (Val.shll v1 v2) | Oshrl, v1 :: v2 :: nil => Some (Val.shrl v1 v2) | Oshrlu, v1 :: v2 :: nil => Some (Val.shrlu v1 v2) - | Oshrlximm n, v1::nil => Val.shrxl v1 (Vint n) + | Oshrlximm n, v1::nil => Some (Val.maketotal (Val.shrxl v1 (Vint n))) | Ozextl s, v1 :: nil => Some (Val.zero_ext_l s v1) | Osextl s, v1 :: nil => Some (Val.sign_ext_l s v1) | Oshllzext s a, v1 :: nil => Some (Val.shll (Val.zero_ext_l s v1) (Vint a)) @@ -481,22 +481,22 @@ Definition eval_operation | Osingleoffloat, v1::nil => Some (Val.singleoffloat v1) | Ofloatofsingle, v1::nil => Some (Val.floatofsingle v1) - | Ointoffloat, v1::nil => Val.intoffloat v1 - | Ointuoffloat, v1::nil => Val.intuoffloat v1 - | Ofloatofint, v1::nil => Val.floatofint v1 - | Ofloatofintu, v1::nil => Val.floatofintu v1 - | Ointofsingle, v1::nil => Val.intofsingle v1 - | Ointuofsingle, v1::nil => Val.intuofsingle v1 - | Osingleofint, v1::nil => Val.singleofint v1 - | Osingleofintu, v1::nil => Val.singleofintu v1 - | Olongoffloat, v1::nil => Val.longoffloat v1 - | Olonguoffloat, v1::nil => Val.longuoffloat v1 - | Ofloatoflong, v1::nil => Val.floatoflong v1 - | Ofloatoflongu, v1::nil => Val.floatoflongu v1 - | Olongofsingle, v1::nil => Val.longofsingle v1 - | Olonguofsingle, v1::nil => Val.longuofsingle v1 - | Osingleoflong, v1::nil => Val.singleoflong v1 - | Osingleoflongu, v1::nil => Val.singleoflongu v1 + | Ointoffloat, v1::nil => Some (Val.maketotal (Val.intoffloat v1)) + | Ointuoffloat, v1::nil => Some (Val.maketotal (Val.intuoffloat v1)) + | Ofloatofint, v1::nil => Some (Val.maketotal (Val.floatofint v1)) + | Ofloatofintu, v1::nil => Some (Val.maketotal (Val.floatofintu v1)) + | Ointofsingle, v1::nil => Some (Val.maketotal (Val.intofsingle v1)) + | Ointuofsingle, v1::nil => Some (Val.maketotal (Val.intuofsingle v1)) + | Osingleofint, v1::nil => Some (Val.maketotal (Val.singleofint v1)) + | Osingleofintu, v1::nil => Some (Val.maketotal (Val.singleofintu v1)) + | Olongoffloat, v1::nil => Some (Val.maketotal (Val.longoffloat v1)) + | Olonguoffloat, v1::nil => Some (Val.maketotal (Val.longuoffloat v1)) + | Ofloatoflong, v1::nil => Some (Val.maketotal (Val.floatoflong v1)) + | Ofloatoflongu, v1::nil => Some (Val.maketotal (Val.floatoflongu v1)) + | Olongofsingle, v1::nil => Some (Val.maketotal (Val.longofsingle v1)) + | Olonguofsingle, v1::nil => Some (Val.maketotal (Val.longuofsingle v1)) + | Osingleoflong, v1::nil => Some (Val.maketotal (Val.singleoflong v1)) + | Osingleoflongu, v1::nil => Some (Val.maketotal (Val.singleoflongu v1)) | Ocmp c, _ => Some (Val.of_optbool (eval_condition c vl m)) | Osel c ty, v1::v2::vl => Some(Val.select (eval_condition c vl m) v1 v2 ty) @@ -788,10 +788,10 @@ Proof with (try exact I; try reflexivity; auto using Val.Vptr_has_type). - destruct v0... destruct v1... - apply type_add. - apply type_sub. - - destruct v0; destruct v1; simpl in *; inv H0. - destruct (Int.eq i0 Int.zero || Int.eq i (Int.repr Int.min_signed) && Int.eq i0 Int.mone); inv H2... - - destruct v0; destruct v1; simpl in *; inv H0. - destruct (Int.eq i0 Int.zero); inv H2... + - destruct v0; destruct v1; cbn in *; trivial. + destruct (_ || _); trivial... + - destruct v0; destruct v1; cbn in *; trivial. + destruct (Int.eq i0 Int.zero); constructor. - destruct v0... destruct v1... - destruct v0... destruct (eval_shift s v1 a)... - destruct v0... @@ -812,7 +812,8 @@ Proof with (try exact I; try reflexivity; auto using Val.Vptr_has_type). - destruct v0; destruct v1; simpl... destruct (Int.ltu i0 Int.iwordsize)... - destruct v0; destruct v1; simpl... destruct (Int.ltu i0 Int.iwordsize)... - destruct v0; destruct v1; simpl... destruct (Int.ltu i0 Int.iwordsize)... - - destruct v0; simpl in H0; try discriminate. destruct (Int.ltu n (Int.repr 31)); inv H0... + - destruct v0; cbn; trivial. + destruct (Int.ltu n (Int.repr 31)); cbn; trivial. - destruct v0... - destruct v0... - destruct (Val.zero_ext s v0)... simpl; rewrite a32_range... @@ -843,10 +844,10 @@ Proof with (try exact I; try reflexivity; auto using Val.Vptr_has_type). - apply type_subl. - destruct v0... destruct v1... - destruct v0... destruct v1... - - destruct v0; destruct v1; simpl in *; inv H0. - destruct (Int64.eq i0 Int64.zero || Int64.eq i (Int64.repr Int64.min_signed) && Int64.eq i0 Int64.mone); inv H2... - - destruct v0; destruct v1; simpl in *; inv H0. - destruct (Int64.eq i0 Int64.zero); inv H2... + - destruct v0; destruct v1; cbn; trivial. + destruct (_ || _); cbn; trivial. + - destruct v0; destruct v1; cbn; trivial. + destruct (Int64.eq i0 Int64.zero); cbn; trivial. - destruct v0... destruct v1... - destruct v0... destruct (eval_shiftl s v1 a)... - destruct v0... @@ -867,7 +868,8 @@ Proof with (try exact I; try reflexivity; auto using Val.Vptr_has_type). - destruct v0; destruct v1; simpl... destruct (Int.ltu i0 Int64.iwordsize')... - destruct v0; destruct v1; simpl... destruct (Int.ltu i0 Int64.iwordsize')... - destruct v0; destruct v1; simpl... destruct (Int.ltu i0 Int64.iwordsize')... - - destruct v0; simpl in H0; try discriminate. destruct (Int.ltu n (Int.repr 63)); inv H0... + - destruct v0; cbn; trivial. + destruct (Int.ltu n (Int.repr 63)); cbn; trivial. - destruct v0... - destruct v0... - destruct (Val.zero_ext_l s v0)... simpl; rewrite a64_range... @@ -893,29 +895,29 @@ Proof with (try exact I; try reflexivity; auto using Val.Vptr_has_type). - destruct v0... - destruct v0... (* intoffloat, intuoffloat *) - - destruct v0; simpl in H0; inv H0. destruct (Float.to_int f); inv H2... - - destruct v0; simpl in H0; inv H0. destruct (Float.to_intu f); inv H2... + - destruct v0; cbn; trivial. destruct (Float.to_int f); cbn; trivial. + - destruct v0; cbn; trivial. destruct (Float.to_intu f); cbn; trivial. (* floatofint, floatofintu *) - - destruct v0; simpl in H0; inv H0... - - destruct v0; simpl in H0; inv H0... + - destruct v0; cbn; trivial. + - destruct v0; cbn; trivial. (* intofsingle, intuofsingle *) - - destruct v0; simpl in H0; inv H0. destruct (Float32.to_int f); inv H2... - - destruct v0; simpl in H0; inv H0. destruct (Float32.to_intu f); inv H2... + - destruct v0; cbn; trivial. destruct (Float32.to_int f); cbn; trivial. + - destruct v0; cbn; trivial. destruct (Float32.to_intu f); cbn; trivial. (* singleofint, singleofintu *) - - destruct v0; simpl in H0; inv H0... - - destruct v0; simpl in H0; inv H0... + - destruct v0; cbn; trivial. + - destruct v0; cbn; trivial. (* longoffloat, longuoffloat *) - - destruct v0; simpl in H0; inv H0. destruct (Float.to_long f); inv H2... - - destruct v0; simpl in H0; inv H0. destruct (Float.to_longu f); inv H2... + - destruct v0; cbn; trivial. destruct (Float.to_long f); cbn; trivial. + - destruct v0; cbn; trivial. destruct (Float.to_longu f); cbn; trivial. (* floatoflong, floatoflongu *) - - destruct v0; simpl in H0; inv H0... - - destruct v0; simpl in H0; inv H0... + - destruct v0; cbn; trivial. + - destruct v0; cbn; trivial. (* longofsingle, longuofsingle *) - - destruct v0; simpl in H0; inv H0. destruct (Float32.to_long f); inv H2... - - destruct v0; simpl in H0; inv H0. destruct (Float32.to_longu f); inv H2... + - destruct v0; cbn; trivial. destruct (Float32.to_long f); cbn; trivial. + - destruct v0; cbn; trivial. destruct (Float32.to_longu f); cbn; trivial. (* singleoflong, singleoflongu *) - - destruct v0; simpl in H0; inv H0... - - destruct v0; simpl in H0; inv H0... + - destruct v0; cbn; trivial. + - destruct v0; cbn; trivial. (* cmp *) - destruct (eval_condition cond vl m) as [[]|]... - unfold Val.select. destruct (eval_condition cond vl m). apply Val.normalize_type. exact I. @@ -924,16 +926,7 @@ Qed. Definition is_trapping_op (op : operation) := match op with - | Odiv | Odivu | Odivl | Odivlu - | Oshrximm _ | Oshrlximm _ - | Ointoffloat | Ointuoffloat - | Ointofsingle | Ointuofsingle - | Ofloatofint | Ofloatofintu - | Osingleofint | Osingleofintu - | Olongoffloat | Olonguoffloat - | Olongofsingle | Olonguofsingle - | Ofloatoflong | Ofloatoflongu - | Osingleoflong | Osingleoflongu => true + | Omove => false | _ => false end. @@ -1409,12 +1402,12 @@ Proof. - apply Val.add_inject; auto. inv H2; inv H3; simpl; auto. - apply Val.sub_inject; auto. inv H2; inv H3; simpl; auto. (* div, divu *) - - inv H4; inv H3; simpl in H1; inv H1. simpl. - destruct (Int.eq i0 Int.zero - || Int.eq i (Int.repr Int.min_signed) && Int.eq i0 Int.mone); inv H2. - TrivialExists. - - inv H4; inv H3; simpl in H1; inv H1. simpl. - destruct (Int.eq i0 Int.zero); inv H2. TrivialExists. + - inv H4; inv H2; trivial. cbn. + destruct (_ || _); cbn; + constructor. + - inv H4; inv H2; trivial. cbn. + destruct (Int.eq i0 Int.zero); cbn; + constructor. (* and*) - inv H4; inv H2; simpl; auto. - generalize (eval_shift_inject s a H2); intros J; inv H4; inv J; simpl; auto. @@ -1446,8 +1439,8 @@ Proof. (* shru *) - inv H4; inv H2; simpl; auto. destruct (Int.ltu i0 Int.iwordsize); auto. (* shrx *) - - inv H4; simpl in H1; try discriminate. simpl. - destruct (Int.ltu n (Int.repr 31)); inv H1. TrivialExists. + - inv H4; cbn; trivial. + destruct (Int.ltu n (Int.repr 31)); inv H; cbn; trivial. (* shift-ext *) - inv H4; simpl; auto. - inv H4; simpl; auto. @@ -1482,12 +1475,10 @@ Proof. - inv H4; inv H2; simpl; auto. - inv H4; inv H2; simpl; auto. (* divl, divlu *) - - inv H4; inv H3; simpl in H1; inv H1. simpl. - destruct (Int64.eq i0 Int64.zero - || Int64.eq i (Int64.repr Int64.min_signed) && Int64.eq i0 Int64.mone); inv H2. - TrivialExists. - - inv H4; inv H3; simpl in H1; inv H1. simpl. - destruct (Int64.eq i0 Int64.zero); inv H2. TrivialExists. + - inv H4; inv H2; cbn; trivial. + destruct (_ || _); cbn; trivial. + - inv H4; inv H2; cbn; trivial. + destruct (Int64.eq i0 Int64.zero); cbn; trivial. (* andl *) - inv H4; inv H2; simpl; auto. - generalize (eval_shiftl_inject s a H2); intros J; inv H4; inv J; simpl; auto. @@ -1519,8 +1510,8 @@ Proof. (* shrlu *) - inv H4; inv H2; simpl; auto. destruct (Int.ltu i0 Int64.iwordsize'); auto. (* shrlx *) - - inv H4; simpl in H1; try discriminate. simpl. - destruct (Int.ltu n (Int.repr 63)); inv H1. TrivialExists. + - inv H4; cbn; trivial. + destruct (Int.ltu n (Int.repr 63)); inv H; cbn; trivial. (* shift-ext *) - inv H4; simpl; auto. - inv H4; simpl; auto. @@ -1551,37 +1542,29 @@ Proof. - inv H4; simpl; auto. - inv H4; simpl; auto. (* intoffloat, intuoffloat *) - - inv H4; simpl in H1; inv H1. simpl. destruct (Float.to_int f0); simpl in H2; inv H2. - exists (Vint i); auto. - - inv H4; simpl in H1; inv H1. simpl. destruct (Float.to_intu f0); simpl in H2; inv H2. - exists (Vint i); auto. + - inv H4; cbn; trivial. destruct (Float.to_int f0); cbn; trivial. + - inv H4; cbn; trivial. destruct (Float.to_intu f0); cbn; trivial. (* floatofint, floatofintu *) - - inv H4; simpl in H1; inv H1. simpl. TrivialExists. - - inv H4; simpl in H1; inv H1. simpl. TrivialExists. + - inv H4; cbn; trivial. + - inv H4; cbn; trivial. (* intofsingle, intuofsingle *) - - inv H4; simpl in H1; inv H1. simpl. destruct (Float32.to_int f0); simpl in H2; inv H2. - exists (Vint i); auto. - - inv H4; simpl in H1; inv H1. simpl. destruct (Float32.to_intu f0); simpl in H2; inv H2. - exists (Vint i); auto. + - inv H4; cbn; trivial. destruct (Float32.to_int f0); cbn; trivial. + - inv H4; cbn; trivial. destruct (Float32.to_intu f0); cbn; trivial. (* singleofint, singleofintu *) - - inv H4; simpl in H1; inv H1. simpl. TrivialExists. - - inv H4; simpl in H1; inv H1. simpl. TrivialExists. + - inv H4; cbn; trivial. + - inv H4; cbn; trivial. (* longoffloat, longuoffloat *) - - inv H4; simpl in H1; inv H1. simpl. destruct (Float.to_long f0); simpl in H2; inv H2. - exists (Vlong i); auto. - - inv H4; simpl in H1; inv H1. simpl. destruct (Float.to_longu f0); simpl in H2; inv H2. - exists (Vlong i); auto. + - inv H4; cbn; trivial. destruct (Float.to_long f0); cbn; trivial. + - inv H4; cbn; trivial. destruct (Float.to_longu f0); cbn; trivial. (* floatoflong, floatoflongu *) - - inv H4; simpl in H1; inv H1. simpl. TrivialExists. - - inv H4; simpl in H1; inv H1. simpl. TrivialExists. + - inv H4; cbn; trivial. + - inv H4; cbn; trivial. (* longofsingle, longuofsingle *) - - inv H4; simpl in H1; inv H1. simpl. destruct (Float32.to_long f0); simpl in H2; inv H2. - exists (Vlong i); auto. - - inv H4; simpl in H1; inv H1. simpl. destruct (Float32.to_longu f0); simpl in H2; inv H2. - exists (Vlong i); auto. + - inv H4; cbn; trivial. destruct (Float32.to_long f0); cbn; trivial. + - inv H4; cbn; trivial. destruct (Float32.to_longu f0); cbn; trivial. (* singleoflong, singleoflongu *) - - inv H4; simpl in H1; inv H1. simpl. TrivialExists. - - inv H4; simpl in H1; inv H1. simpl. TrivialExists. + - inv H4; cbn; trivial. + - inv H4; cbn; trivial. (* cmp, sel *) - subst v1. destruct (eval_condition cond vl1 m1) eqn:?. exploit eval_condition_inj; eauto. intros EQ; rewrite EQ. diff --git a/aarch64/OpWeights.ml b/aarch64/OpWeights.ml new file mode 100644 index 00000000..1b48bc0f --- /dev/null +++ b/aarch64/OpWeights.ml @@ -0,0 +1,329 @@ +open Op;; +let resource_bounds = [| 2; 2; 1; 1 |];; (* instr ; ALU ; MAC; LSU *) +let nr_non_pipelined_units = 1;; + +let latency_of_op (op : operation) (nargs : int) = + match op with + | Omove + | Ointconst _ + | Olongconst _ + | Ofloatconst _ + | Osingleconst _ + | Oaddrsymbol _ + | Oaddrstack _ -> 1 + | Oshift _ -> 2 + | Oadd -> 1 + | Oaddshift _ -> 2 + | Oaddimm _ + | Oneg -> 1 + | Onegshift _ -> 2 + | Osub -> 1 + | Osubshift _ -> 2 + | Omul + | Omuladd + | Omulsub -> 4 + | Odiv + | Odivu -> 29 + | Oand -> 1 + | Oandshift _ -> 2 + | Oandimm _ -> 1 + | Oor -> 1 + | Oorshift _ -> 2 + | Oorimm _ -> 1 + | Oxor -> 1 + | Oxorshift _ -> 2 + | Oxorimm _ -> 1 + | Onot -> 1 + | Onotshift _ -> 2 + | Obic -> 1 + | Obicshift _ -> 2 + | Oorn -> 1 + | Oornshift _ -> 2 + | Oeqv -> 1 + | Oeqvshift _ -> 2 + | Oshl + | Oshr + | Oshru -> 2 + | Oshrximm _ -> 6 + | Ozext _ + | Osext _ -> 1 + | Oshlzext _ + | Oshlsext _ + | Ozextshr _ + | Osextshr _ -> 2 + +(* 64-bit integer arithmetic *) + | Oshiftl _ -> 2 + | Oextend _ -> 1 + | Omakelong + | Olowlong + | Ohighlong + | Oaddl -> 1 + | Oaddlshift _ + | Oaddlext _ -> 2 + | Oaddlimm _ + | Onegl -> 1 + | Oneglshift _ -> 2 + | Osubl -> 1 + | Osublshift _ + | Osublext _ -> 2 + | Omull + | Omulladd + | Omullsub + | Omullhs + | Omullhu -> 4 + | Odivl -> 50 + | Odivlu -> 50 + | Oandl -> 1 + | Oandlshift _ -> 2 + | Oandlimm _ + | Oorl -> 1 + | Oorlshift _ -> 2 + | Oorlimm _ + | Oxorl -> 1 + | Oxorlshift _ -> 2 + | Oxorlimm _ + | Onotl -> 1 + | Onotlshift _ -> 2 + | Obicl -> 1 + | Obiclshift _ -> 2 + | Oornl -> 1 + | Oornlshift _ -> 2 + | Oeqvl -> 1 + | Oeqvlshift _ -> 2 + | Oshll + | Oshrl + | Oshrlu -> 2 + | Oshrlximm _ -> 6 + | Ozextl _ + | Osextl _ -> 1 + | Oshllzext _ + | Oshllsext _ + | Ozextshrl _ + | Osextshrl _ -> 2 + +(* 64-bit floating-point arithmetic *) + | Onegf (* r [rd = - r1] *) + | Oabsf (* r [rd = abs(r1)] *) + | Oaddf (* r [rd = r1 + r2] *) + | Osubf (* r [rd = r1 - r2] *) + | Omulf (* r [rd = r1 * r2] *) +(* 32-bit floating-point arithmetic *) + | Onegfs (* r [rd = - r1] *) + | Oabsfs (* r [rd = abs(r1)] *) + | Oaddfs (* r [rd = r1 + r2] *) + | Osubfs (* r [rd = r1 - r2] *) + | Omulfs (* r [rd = r1 * r2] *) + | Osingleoffloat (* r [rd] is [r1] truncated to single-precision float *) + | Ofloatofsingle (* r [rd] is [r1] extended to double-precision float *) +(* Conversions between int and float *) + | Ointoffloat (* r [rd = signed_int_of_float64(r1)] *) + | Ointuoffloat (* r [rd = unsigned_int_of_float64(r1)] *) + | Ofloatofint (* r [rd = float64_of_signed_int(r1)] *) + | Ofloatofintu (* r [rd = float64_of_unsigned_int(r1)] *) + | Ointofsingle (* r [rd = signed_int_of_float32(r1)] *) + | Ointuofsingle (* r [rd = unsigned_int_of_float32(r1)] *) + | Osingleofint (* r [rd = float32_of_signed_int(r1)] *) + | Osingleofintu (* r [rd = float32_of_unsigned_int(r1)] *) + | Olongoffloat (* r [rd = signed_long_of_float64(r1)] *) + | Olonguoffloat (* r [rd = unsigned_long_of_float64(r1)] *) + | Ofloatoflong (* r [rd = float64_of_signed_long(r1)] *) + | Ofloatoflongu (* r [rd = float64_of_unsigned_long(r1)] *) + | Olongofsingle (* r [rd = signed_long_of_float32(r1)] *) + | Olonguofsingle (* r [rd = unsigned_long_of_float32(r1)] *) + | Osingleoflong (* r [rd = float32_of_signed_long(r1)] *) + | Osingleoflongu (* r [rd = float32_of_unsigned_int(r1)] *) + -> 6 + | Odivf -> 50 (* r [rd = r1 / r2] *) + | Odivfs -> 20 + (* Boolean tests *) + | Ocmp cmp | Osel (cmp, _) -> + (match cmp with + | Ccompf _ (* r FP comparison *) + | Cnotcompf _ (* r negation of an FP comparison *) + | Ccompfzero _ (* r comparison with 0.0 *) + | Cnotcompfzero _ (* r negation of comparison with 0.0 *) + | Ccompfs _ (* r FP comparison *) + | Cnotcompfs _ (* r negation of an FP comparison *) + | Ccompfszero _ (* r equal to 0.0 *) + | Cnotcompfszero _ (* r not equal to 0.0 *) -> 6 + | _ -> 1);; + +let resources_of_op (op : operation) (nargs : int) = + match op with + | Omove + | Ointconst _ + | Olongconst _ + | Ofloatconst _ + | Osingleconst _ + | Oaddrsymbol _ + | Oaddrstack _ +(* 32-bit integer arithmetic *) + | Oshift _ + | Oadd + | Oaddshift _ + | Oaddimm _ + | Oneg + | Onegshift _ + | Osub + | Osubshift _ -> [| 1 ; 1; 0; 0 |] + | Omul + | Omuladd + | Omulsub -> [| 1; 1; 1; 0 |] + | Odiv + | Odivu -> [| 1; 0; 0; 0 |] + | Oand + | Oandshift _ + | Oandimm _ + | Oor + | Oorshift _ + | Oorimm _ + | Oxor + | Oxorshift _ + | Oxorimm _ + | Onot + | Onotshift _ + | Obic + | Obicshift _ + | Oorn + | Oornshift _ + | Oeqv + | Oeqvshift _ + | Oshl + | Oshr + | Oshru + | Oshrximm _ + | Ozext _ + | Osext _ + | Oshlzext _ + | Oshlsext _ + | Ozextshr _ + | Osextshr _ + +(* 64-bit integer arithmetic *) + | Oshiftl _ + | Oextend _ + | Omakelong + | Olowlong + | Ohighlong + | Oaddl + | Oaddlshift _ + | Oaddlext _ + | Oaddlimm _ + | Onegl + | Oneglshift _ + | Osubl + | Osublshift _ + | Osublext _ -> [| 1 ; 1 ; 0; 0 |] + | Omull + | Omulladd + | Omullsub + | Omullhs + | Omullhu -> [| 1 ; 1 ; 1; 0 |] + | Odivl + | Odivlu -> [| 1; 0; 0; 0 |] + | Oandl + | Oandlshift _ + | Oandlimm _ + | Oorl + | Oorlshift _ + | Oorlimm _ + | Oxorl + | Oxorlshift _ + | Oxorlimm _ + | Onotl + | Onotlshift _ + | Obicl + | Obiclshift _ + | Oornl + | Oornlshift _ + | Oeqvl + | Oeqvlshift _ + | Oshll + | Oshrl + | Oshrlu + | Oshrlximm _ + | Ozextl _ + | Osextl _ + | Oshllzext _ + | Oshllsext _ + | Ozextshrl _ + | Osextshrl _ -> [| 1; 1; 0; 0 |] +(* 64-bit floating-point arithmetic *) + | Onegf (* r [rd = - r1] *) + | Oabsf (* r [rd = abs(r1)] *) + | Oaddf (* r [rd = r1 + r2] *) + | Osubf (* r [rd = r1 - r2] *) + | Omulf (* r [rd = r1 * r2] *) + | Odivf +(* 32-bit floating-point arithmetic *) + | Onegfs (* r [rd = - r1] *) + | Oabsfs (* r [rd = abs(r1)] *) + | Oaddfs (* r [rd = r1 + r2] *) + | Osubfs (* r [rd = r1 - r2] *) + | Omulfs (* r [rd = r1 * r2] *) + | Odivfs (* r [rd = r1 / r2] *) + | Osingleoffloat (* r [rd] is [r1] truncated to single-precision float *) + | Ofloatofsingle (* r [rd] is [r1] extended to double-precision float *) +(* Conversions between int and float *) + | Ointoffloat (* r [rd = signed_int_of_float64(r1)] *) + | Ointuoffloat (* r [rd = unsigned_int_of_float64(r1)] *) + | Ofloatofint (* r [rd = float64_of_signed_int(r1)] *) + | Ofloatofintu (* r [rd = float64_of_unsigned_int(r1)] *) + | Ointofsingle (* r [rd = signed_int_of_float32(r1)] *) + | Ointuofsingle (* r [rd = unsigned_int_of_float32(r1)] *) + | Osingleofint (* r [rd = float32_of_signed_int(r1)] *) + | Osingleofintu (* r [rd = float32_of_unsigned_int(r1)] *) + | Olongoffloat (* r [rd = signed_long_of_float64(r1)] *) + | Olonguoffloat (* r [rd = unsigned_long_of_float64(r1)] *) + | Ofloatoflong (* r [rd = float64_of_signed_long(r1)] *) + | Ofloatoflongu (* r [rd = float64_of_unsigned_long(r1)] *) + | Olongofsingle (* r [rd = signed_long_of_float32(r1)] *) + | Olonguofsingle (* r [rd = unsigned_long_of_float32(r1)] *) + | Osingleoflong (* r [rd = float32_of_signed_long(r1)] *) + | Osingleoflongu (* r [rd = float32_of_unsigned_int(r1)] *) + -> [| 1 ; 1; 1; 0 |] + +(* Boolean tests *) + | Ocmp cmp | Osel (cmp, _) -> + (match cmp with + | Ccompf _ (* r FP comparison *) + | Cnotcompf _ (* r negation of an FP comparison *) + | Ccompfzero _ (* r comparison with 0.0 *) + | Cnotcompfzero _ (* r negation of comparison with 0.0 *) + | Ccompfs _ (* r FP comparison *) + | Cnotcompfs _ (* r negation of an FP comparison *) + | Ccompfszero _ (* r equal to 0.0 *) + | Cnotcompfszero _ (* r not equal to 0.0 *) -> + [| 1; 1; 1; 0 |] + | _ -> [| 1; 1; 0; 0 |] );; + +let non_pipelined_resources_of_op (op : operation) (nargs : int) = + match op with + | Odiv | Odivu -> [| 29 |] + | Odivfs -> [| 20 |] + | Odivl | Odivlu | Odivf -> [| 50 |] + | _ -> [| -1 |];; + +let resources_of_cond (cmp : condition) (nargs : int) = + (match cmp with + | Ccompf _ (* r FP comparison *) + | Cnotcompf _ (* r negation of an FP comparison *) + | Ccompfzero _ (* r comparison with 0.0 *) + | Cnotcompfzero _ (* r negation of comparison with 0.0 *) + | Ccompfs _ (* r FP comparison *) + | Cnotcompfs _ (* r negation of an FP comparison *) + | Ccompfszero _ (* r equal to 0.0 *) + | Cnotcompfszero _ (* r not equal to 0.0 *) -> + [| 1; 1; 1; 0 |] + | _ -> [| 1; 1; 0; 0 |] );; + +let latency_of_load trap chunk (addr : addressing) (nargs : int) = 3;; +let latency_of_call _ _ = 6;; + +let resources_of_load trap chunk addressing nargs = [| 1; 0; 0; 1 |];; + +let resources_of_store chunk addressing nargs = [| 1; 0; 0; 1 |];; + +let resources_of_call _ _ = resource_bounds;; +let resources_of_builtin _ = resource_bounds;; diff --git a/kvx/lib/PrepassSchedulingOracle.ml b/aarch64/PrepassSchedulingOracle.ml index 78961310..25083bcd 100644 --- a/kvx/lib/PrepassSchedulingOracle.ml +++ b/aarch64/PrepassSchedulingOracle.ml @@ -25,6 +25,8 @@ let get_simple_dependencies (seqa : (instruction*Regset.t) array) = and last_mem_reads : int list ref = ref [] and last_mem_write : int option ref = ref None and last_branch : int option ref = ref None + and last_non_pipelined_op : int array = Array.make + nr_non_pipelined_units ( -1 ) and latency_constraints : latency_constraint list ref = ref [] in let add_constraint instr_from instr_to latency = assert (instr_from <= instr_to); @@ -119,7 +121,15 @@ let get_simple_dependencies (seqa : (instruction*Regset.t) array) = | Some j -> add_constraint j i 1 in let set_branch i = irreversible_action i; - last_branch := Some i + last_branch := Some i in + let add_non_pipelined_resources i resources = + Array.iter2 + (fun latency last -> + if latency >= 0 && last >= 0 then add_constraint last i latency) + resources last_non_pipelined_op; + Array.iteri (fun rsc latency -> + if latency >= 0 + then last_non_pipelined_op.(rsc) <- i) resources in Array.iteri begin @@ -131,6 +141,8 @@ let get_simple_dependencies (seqa : (instruction*Regset.t) array) = match insn with | Inop _ -> () | Iop(op, inputs, output, _) -> + add_non_pipelined_resources i + (non_pipelined_resources_of_op op (List.length inputs)); (if Op.is_trapping_op op then irreversible_action i); add_input_regs i inputs; add_output_reg i (latency_of_op op (List.length inputs)) output @@ -403,6 +415,29 @@ let define_problem seqa = then (get_alias_dependencies seqa) @ simple_deps else *) simple_deps };; +let zigzag_scheduler problem early_ones = + let nr_instructions = get_nr_instructions problem in + assert(nr_instructions = (Array.length early_ones)); + match list_scheduler problem with + | Some fwd_schedule -> + let fwd_makespan = fwd_schedule.((Array.length fwd_schedule) - 1) in + let constraints' = ref problem.latency_constraints in + Array.iteri (fun i is_early -> + if is_early then + constraints' := { + instr_from = i; + instr_to = nr_instructions ; + latency = fwd_makespan - fwd_schedule.(i) } ::!constraints' ) + early_ones; + validated_scheduler reverse_list_scheduler + { problem with latency_constraints = !constraints' } + | None -> None;; + +let prepass_scheduler_by_name name problem early_ones = + match name with + | "zigzag" -> zigzag_scheduler problem early_ones + | _ -> scheduler_by_name name problem + let schedule_sequence (seqa : (instruction*Regset.t) array) = try if (Array.length seqa) <= 1 @@ -414,7 +449,13 @@ let schedule_sequence (seqa : (instruction*Regset.t) array) = let problem = define_problem seqa in print_sequence stdout (Array.map fst seqa); print_problem stdout problem; - match scheduler_by_name (!Clflags.option_fprepass_sched) problem with + match prepass_scheduler_by_name + (!Clflags.option_fprepass_sched) + problem + (Array.map (fun (ins, _) -> + match ins with + | Icond _ -> true + | _ -> false) seqa) with | None -> Printf.printf "no solution in prepass scheduling\n"; None | Some solution -> diff --git a/aarch64/SelectLongproof.v b/aarch64/SelectLongproof.v index 60dc1a12..513ee9bd 100644 --- a/aarch64/SelectLongproof.v +++ b/aarch64/SelectLongproof.v @@ -559,25 +559,29 @@ Qed. Theorem eval_divls_base: partial_binary_constructor_sound divls_base Val.divls. Proof. red; intros; unfold divls_base; TrivialExists. + cbn. rewrite H1. reflexivity. Qed. Theorem eval_modls_base: partial_binary_constructor_sound modls_base Val.modls. Proof. red; intros; unfold modls_base, modl_aux. exploit Val.modls_divls; eauto. intros (q & A & B). subst z. - TrivialExists. repeat (econstructor; eauto with evalexpr). exact A. + TrivialExists. repeat (econstructor; eauto with evalexpr). + rewrite A. reflexivity. Qed. Theorem eval_divlu_base: partial_binary_constructor_sound divlu_base Val.divlu. Proof. red; intros; unfold divlu_base; TrivialExists. + cbn. rewrite H1. reflexivity. Qed. Theorem eval_modlu_base: partial_binary_constructor_sound modlu_base Val.modlu. Proof. red; intros; unfold modlu_base, modl_aux. exploit Val.modlu_divlu; eauto. intros (q & A & B). subst z. - TrivialExists. repeat (econstructor; eauto with evalexpr). exact A. + TrivialExists. repeat (econstructor; eauto with evalexpr). + rewrite A. reflexivity. Qed. Theorem eval_shrxlimm: @@ -592,7 +596,7 @@ Proof. destruct x; simpl in H0; try discriminate. change (Int.ltu Int.zero (Int.repr 63)) with true in H0; inv H0. rewrite Int64.shrx'_zero. auto. -- TrivialExists. +- TrivialExists. cbn. rewrite H0. reflexivity. Qed. (** General shifts *) @@ -726,42 +730,42 @@ Qed. Theorem eval_longoffloat: partial_unary_constructor_sound longoffloat Val.longoffloat. Proof. - red; intros; TrivialExists. + red; intros; TrivialExists. cbn. rewrite H0. reflexivity. Qed. Theorem eval_longuoffloat: partial_unary_constructor_sound longuoffloat Val.longuoffloat. Proof. - red; intros; TrivialExists. + red; intros; TrivialExists. cbn. rewrite H0. reflexivity. Qed. Theorem eval_floatoflong: partial_unary_constructor_sound floatoflong Val.floatoflong. Proof. - red; intros; TrivialExists. + red; intros; TrivialExists. cbn. rewrite H0. reflexivity. Qed. Theorem eval_floatoflongu: partial_unary_constructor_sound floatoflongu Val.floatoflongu. Proof. - red; intros; TrivialExists. + red; intros; TrivialExists. cbn. rewrite H0. reflexivity. Qed. Theorem eval_longofsingle: partial_unary_constructor_sound longofsingle Val.longofsingle. Proof. - red; intros; TrivialExists. + red; intros; TrivialExists. cbn. rewrite H0. reflexivity. Qed. Theorem eval_longuofsingle: partial_unary_constructor_sound longuofsingle Val.longuofsingle. Proof. - red; intros; TrivialExists. + red; intros; TrivialExists. cbn. rewrite H0. reflexivity. Qed. Theorem eval_singleoflong: partial_unary_constructor_sound singleoflong Val.singleoflong. Proof. - red; intros; TrivialExists. + red; intros; TrivialExists. cbn. rewrite H0. reflexivity. Qed. Theorem eval_singleoflongu: partial_unary_constructor_sound singleoflongu Val.singleoflongu. Proof. - red; intros; TrivialExists. + red; intros; TrivialExists. cbn. rewrite H0. reflexivity. Qed. End CMCONSTR. diff --git a/aarch64/SelectOpproof.v b/aarch64/SelectOpproof.v index 3379cbd8..9ce7a8bf 100644 --- a/aarch64/SelectOpproof.v +++ b/aarch64/SelectOpproof.v @@ -666,7 +666,8 @@ Theorem eval_divs_base: Val.divs x y = Some z -> exists v, eval_expr ge sp e m le (divs_base a b) v /\ Val.lessdef z v. Proof. - intros; unfold divs_base; TrivialExists. + intros; unfold divs_base; TrivialExists; cbn. + rewrite H1. reflexivity. Qed. Theorem eval_mods_base: @@ -678,7 +679,8 @@ Theorem eval_mods_base: Proof. intros; unfold mods_base, mod_aux. exploit Val.mods_divs; eauto. intros (q & A & B). subst z. - TrivialExists. repeat (econstructor; eauto with evalexpr). exact A. + TrivialExists. repeat (econstructor; eauto with evalexpr). + cbn. rewrite A. reflexivity. Qed. Theorem eval_divu_base: @@ -689,6 +691,7 @@ Theorem eval_divu_base: exists v, eval_expr ge sp e m le (divu_base a b) v /\ Val.lessdef z v. Proof. intros; unfold divu_base; TrivialExists. + cbn. rewrite H1. reflexivity. Qed. Theorem eval_modu_base: @@ -700,7 +703,8 @@ Theorem eval_modu_base: Proof. intros; unfold modu_base, mod_aux. exploit Val.modu_divu; eauto. intros (q & A & B). subst z. - TrivialExists. repeat (econstructor; eauto with evalexpr). exact A. + TrivialExists. repeat (econstructor; eauto with evalexpr). + rewrite A. reflexivity. Qed. Theorem eval_shrximm: @@ -715,7 +719,7 @@ Proof. destruct x; simpl in H0; try discriminate. change (Int.ltu Int.zero (Int.repr 31)) with true in H0; inv H0. rewrite Int.shrx_zero by (compute; auto). auto. -- TrivialExists. +- TrivialExists. cbn. rewrite H0. reflexivity. Qed. (** General shifts *) @@ -928,7 +932,7 @@ Theorem eval_intoffloat: Val.intoffloat x = Some y -> exists v, eval_expr ge sp e m le (intoffloat a) v /\ Val.lessdef y v. Proof. - intros; TrivialExists. + intros; TrivialExists. cbn. rewrite H0. reflexivity. Qed. Theorem eval_floatofint: @@ -939,7 +943,7 @@ Theorem eval_floatofint: Proof. intros until y; unfold floatofint. case (floatofint_match a); intros; InvEval. - TrivialExists. -- TrivialExists. +- TrivialExists. cbn. rewrite H0. reflexivity. Qed. Theorem eval_intuoffloat: @@ -948,7 +952,7 @@ Theorem eval_intuoffloat: Val.intuoffloat x = Some y -> exists v, eval_expr ge sp e m le (intuoffloat a) v /\ Val.lessdef y v. Proof. - intros; TrivialExists. + intros; TrivialExists. cbn. rewrite H0. reflexivity. Qed. Theorem eval_floatofintu: @@ -959,7 +963,7 @@ Theorem eval_floatofintu: Proof. intros until y; unfold floatofintu. case (floatofintu_match a); intros; InvEval. - TrivialExists. -- TrivialExists. +- TrivialExists. cbn. rewrite H0. reflexivity. Qed. Theorem eval_intofsingle: @@ -968,7 +972,7 @@ Theorem eval_intofsingle: Val.intofsingle x = Some y -> exists v, eval_expr ge sp e m le (intofsingle a) v /\ Val.lessdef y v. Proof. - intros; TrivialExists. + intros; TrivialExists. cbn. rewrite H0. reflexivity. Qed. Theorem eval_singleofint: @@ -979,7 +983,7 @@ Theorem eval_singleofint: Proof. intros until y; unfold singleofint. case (singleofint_match a); intros; InvEval. - TrivialExists. -- TrivialExists. +- TrivialExists. cbn. rewrite H0. reflexivity. Qed. Theorem eval_intuofsingle: @@ -988,7 +992,7 @@ Theorem eval_intuofsingle: Val.intuofsingle x = Some y -> exists v, eval_expr ge sp e m le (intuofsingle a) v /\ Val.lessdef y v. Proof. - intros; TrivialExists. + intros; TrivialExists. cbn. rewrite H0. reflexivity. Qed. Theorem eval_singleofintu: @@ -999,7 +1003,7 @@ Theorem eval_singleofintu: Proof. intros until y; unfold singleofintu. case (singleofintu_match a); intros; InvEval. - TrivialExists. -- TrivialExists. +- TrivialExists. cbn. rewrite H0. reflexivity. Qed. (** Selection *) diff --git a/aarch64/ValueAOp.v b/aarch64/ValueAOp.v index e0d98c85..e6a60d4e 100644 --- a/aarch64/ValueAOp.v +++ b/aarch64/ValueAOp.v @@ -96,8 +96,8 @@ Definition eval_static_operation (op: operation) (vl: list aval): aval := | Omul, v1::v2::nil => mul v1 v2 | Omuladd, v1::v2::v3::nil => add v1 (mul v2 v3) | Omulsub, v1::v2::v3::nil => sub v1 (mul v2 v3) - | Odiv, v1::v2::nil => divs v1 v2 - | Odivu, v1::v2::nil => divu v1 v2 + | Odiv, v1::v2::nil => divs_total v1 v2 + | Odivu, v1::v2::nil => divu_total v1 v2 | Oand, v1::v2::nil => and v1 v2 | Oandshift s a, v1::v2::nil => and v1 (eval_static_shift s v2 a) | Oandimm n, v1::nil => and v1 (I n) @@ -145,8 +145,8 @@ Definition eval_static_operation (op: operation) (vl: list aval): aval := | Omullsub, v1::v2::v3::nil => subl v1 (mull v2 v3) | Omullhs, v1::v2::nil => mullhs v1 v2 | Omullhu, v1::v2::nil => mullhu v1 v2 - | Odivl, v1::v2::nil => divls v1 v2 - | Odivlu, v1::v2::nil => divlu v1 v2 + | Odivl, v1::v2::nil => divls_total v1 v2 + | Odivlu, v1::v2::nil => divlu_total v1 v2 | Oandl, v1::v2::nil => andl v1 v2 | Oandlshift s a, v1::v2::nil => andl v1 (eval_static_shiftl s v2 a) | Oandlimm n, v1::nil => andl v1 (L n) @@ -191,20 +191,20 @@ Definition eval_static_operation (op: operation) (vl: list aval): aval := | Osingleoffloat, v1::nil => singleoffloat v1 | Ofloatofsingle, v1::nil => floatofsingle v1 - | Ointoffloat, v1::nil => intoffloat v1 - | Ointuoffloat, v1::nil => intuoffloat v1 + | Ointoffloat, v1::nil => intoffloat_total v1 + | Ointuoffloat, v1::nil => intuoffloat_total v1 | Ofloatofint, v1::nil => floatofint v1 | Ofloatofintu, v1::nil => floatofintu v1 - | Ointofsingle, v1::nil => intofsingle v1 - | Ointuofsingle, v1::nil => intuofsingle v1 + | Ointofsingle, v1::nil => intofsingle_total v1 + | Ointuofsingle, v1::nil => intuofsingle_total v1 | Osingleofint, v1::nil => singleofint v1 | Osingleofintu, v1::nil => singleofintu v1 - | Olongoffloat, v1::nil => longoffloat v1 - | Olonguoffloat, v1::nil => longuoffloat v1 + | Olongoffloat, v1::nil => longoffloat_total v1 + | Olonguoffloat, v1::nil => longuoffloat_total v1 | Ofloatoflong, v1::nil => floatoflong v1 | Ofloatoflongu, v1::nil => floatoflongu v1 - | Olongofsingle, v1::nil => longofsingle v1 - | Olonguofsingle, v1::nil => longuofsingle v1 + | Olongofsingle, v1::nil => longofsingle_total v1 + | Olonguofsingle, v1::nil => longuofsingle_total v1 | Osingleoflong, v1::nil => singleoflong v1 | Osingleoflongu, v1::nil => singleoflongu v1 diff --git a/arm/PrepassSchedulingOracle.ml b/arm/PrepassSchedulingOracle.ml new file mode 120000 index 00000000..9885fd52 --- /dev/null +++ b/arm/PrepassSchedulingOracle.ml @@ -0,0 +1 @@ +../x86/PrepassSchedulingOracle.ml
\ No newline at end of file diff --git a/backend/Duplicateaux.ml b/backend/Duplicateaux.ml index 00819834..1297ec90 100644 --- a/backend/Duplicateaux.ml +++ b/backend/Duplicateaux.ml @@ -314,7 +314,9 @@ let get_directions code entrypoint = begin (* debug "\n"; *) List.iter (fun n -> match (get_some @@ PTree.get n code) with - | Icond (cond, lr, ifso, ifnot, _) -> + | Icond (cond, lr, ifso, ifnot, pred) -> + (match pred with Some _ -> debug "RTL node %d already has prediction information\n" (P.to_int n) + | None -> (* debug "Analyzing %d.." (P.to_int n); *) let heuristics = [ do_opcode_heuristic; do_return_heuristic; do_loop2_heuristic loop_info n; do_loop_heuristic; do_call_heuristic; @@ -333,6 +335,7 @@ let get_directions code entrypoint = begin | None -> debug "\tUNSURE\n"); debug "---------------------------------------\n" end + ) | _ -> () ) bfs_order; !directions @@ -340,7 +343,11 @@ let get_directions code entrypoint = begin end let update_direction direction = function -| Icond (cond, lr, n, n', _) -> Icond (cond, lr, n, n', direction) +| Icond (cond, lr, n, n', pred) -> + (* only update if there is no prior existing branch prediction *) + (match pred with + | None -> Icond (cond, lr, n, n', direction) + | Some _ -> Icond (cond, lr, n, n', pred) ) | i -> i let rec update_direction_rec directions = function diff --git a/backend/ValueDomain.v b/backend/ValueDomain.v index 779e7bb9..f1a46baa 100644 --- a/backend/ValueDomain.v +++ b/backend/ValueDomain.v @@ -2069,7 +2069,6 @@ Definition divfs := binop_single Float32.div. Lemma divfs_sound: forall v x w y, vmatch v x -> vmatch w y -> vmatch (Val.divfs v w) (divfs x y). Proof (binop_single_sound Float32.div). - (** Conversions *) Definition zero_ext (nbits: Z) (v: aval) := @@ -2483,6 +2482,468 @@ Proof. destruct 1; simpl; auto with va. Qed. + +(* Extensions for KVX and Risc-V *) + +Definition intoffloat_total (x: aval) := + match x with + | F f => + match Float.to_int f with + | Some i => I i + | None => ntop + end + | _ => ntop1 x + end. + +Definition intuoffloat_total (x: aval) := + match x with + | F f => + match Float.to_intu f with + | Some i => I i + | None => ntop + end + | _ => ntop1 x + end. + +Definition intofsingle_total (x: aval) := + match x with + | FS f => + match Float32.to_int f with + | Some i => I i + | None => ntop + end + | _ => ntop1 x + end. + +Definition intuofsingle_total (x: aval) := + match x with + | FS f => + match Float32.to_intu f with + | Some i => I i + | None => ntop + end + | _ => ntop1 x + end. + +Definition longoffloat_total (x: aval) := + match x with + | F f => + match Float.to_long f with + | Some i => L i + | None => ntop + end + | _ => ntop1 x + end. + +Definition longuoffloat_total (x: aval) := + match x with + | F f => + match Float.to_longu f with + | Some i => L i + | None => ntop + end + | _ => ntop1 x + end. + +Definition longofsingle_total (x: aval) := + match x with + | FS f => + match Float32.to_long f with + | Some i => L i + | None => ntop + end + | _ => ntop1 x + end. + +Definition longuofsingle_total (x: aval) := + match x with + | FS f => + match Float32.to_longu f with + | Some i => L i + | None => ntop + end + | _ => ntop1 x + end. + +Lemma intoffloat_total_sound: + forall v x + (MATCH : vmatch v x), + vmatch (Val.maketotal (Val.intoffloat v)) (intoffloat_total x). +Proof. + unfold Val.intoffloat, intoffloat_total. intros. + inv MATCH; simpl in *; try constructor. + all: destruct (Float.to_int f) as [i|] eqn:E; simpl; [auto with va | constructor]. +Qed. + +Lemma intuoffloat_total_sound: + forall v x + (MATCH : vmatch v x), + vmatch (Val.maketotal (Val.intuoffloat v)) (intuoffloat_total x). +Proof. + unfold Val.intoffloat, intoffloat_total. intros. + inv MATCH; simpl in *; try constructor. + all: destruct (Float.to_intu f) as [i|] eqn:E; simpl; [auto with va | constructor]. +Qed. + +Lemma intofsingle_total_sound: + forall v x + (MATCH : vmatch v x), + vmatch (Val.maketotal (Val.intofsingle v)) (intofsingle_total x). +Proof. + unfold Val.intofsingle, intofsingle_total. intros. + inv MATCH; simpl in *; try constructor. + all: destruct (Float32.to_int f) as [i|] eqn:E; simpl; [auto with va | constructor]. +Qed. + +Lemma intuofsingle_total_sound: + forall v x + (MATCH : vmatch v x), + vmatch (Val.maketotal (Val.intuofsingle v)) (intuofsingle_total x). +Proof. + unfold Val.intofsingle, intofsingle_total. intros. + inv MATCH; simpl in *; try constructor. + all: destruct (Float32.to_intu f) as [i|] eqn:E; simpl; [auto with va | constructor]. +Qed. + +Lemma singleofint_total_sound: + forall v x, vmatch v x -> + vmatch (Val.maketotal (Val.singleofint v)) (singleofint x). +Proof. + unfold Val.singleofint, singleofint; intros. + inv H; simpl. + all: auto with va. + all: unfold ntop1, provenance. + all: try constructor. +Qed. + +Lemma singleofintu_total_sound: + forall v x, vmatch v x -> + vmatch (Val.maketotal (Val.singleofintu v)) (singleofintu x). +Proof. + unfold Val.singleofintu, singleofintu; intros. + inv H; simpl. + all: auto with va. + all: unfold ntop1, provenance. + all: try constructor. +Qed. + +Lemma longoffloat_total_sound: + forall v x + (MATCH : vmatch v x), + vmatch (Val.maketotal (Val.longoffloat v)) (longoffloat_total x). +Proof. + unfold Val.longoffloat, longoffloat_total. intros. + inv MATCH; simpl in *; try constructor. + all: destruct (Float.to_long f) as [i|] eqn:E; simpl; [auto with va | constructor]. +Qed. + +Lemma longuoffloat_total_sound: + forall v x + (MATCH : vmatch v x), + vmatch (Val.maketotal (Val.longuoffloat v)) (longuoffloat_total x). +Proof. + unfold Val.longoffloat, longoffloat_total. intros. + inv MATCH; simpl in *; try constructor. + all: destruct (Float.to_longu f) as [i|] eqn:E; simpl; [auto with va | constructor]. +Qed. + +Lemma longofsingle_total_sound: + forall v x + (MATCH : vmatch v x), + vmatch (Val.maketotal (Val.longofsingle v)) (longofsingle_total x). +Proof. + unfold Val.longofsingle, longofsingle_total. intros. + inv MATCH; simpl in *; try constructor. + all: destruct (Float32.to_long f) as [i|] eqn:E; simpl; [auto with va | constructor]. +Qed. + +Lemma longuofsingle_total_sound: + forall v x + (MATCH : vmatch v x), + vmatch (Val.maketotal (Val.longuofsingle v)) (longuofsingle_total x). +Proof. + unfold Val.longofsingle, longofsingle_total. intros. + inv MATCH; simpl in *; try constructor. + all: destruct (Float32.to_longu f) as [i|] eqn:E; simpl; [auto with va | constructor]. +Qed. + +Lemma singleoflong_total_sound: + forall v x, vmatch v x -> + vmatch (Val.maketotal (Val.singleoflong v)) (singleoflong x). +Proof. + unfold Val.singleoflong, singleoflong; intros. + inv H; simpl. + all: auto with va. + all: unfold ntop1, provenance. + all: try constructor. +Qed. + +Lemma singleoflongu_total_sound: + forall v x, vmatch v x -> + vmatch (Val.maketotal (Val.singleoflongu v)) (singleoflongu x). +Proof. + unfold Val.singleoflongu, singleoflongu; intros. + inv H; simpl. + all: auto with va. + all: unfold ntop1, provenance. + all: try constructor. +Qed. + +Lemma floatoflong_total_sound: + forall v x, vmatch v x -> + vmatch (Val.maketotal (Val.floatoflong v)) (floatoflong x). +Proof. + unfold Val.floatoflong, floatoflong; intros. + inv H; simpl. + all: auto with va. + all: unfold ntop1, provenance. + all: try constructor. +Qed. + +Lemma floatoflongu_total_sound: + forall v x, vmatch v x -> + vmatch (Val.maketotal (Val.floatoflongu v)) (floatoflongu x). +Proof. + unfold Val.floatoflongu, floatoflongu; intros. + inv H; simpl. + all: auto with va. + all: unfold ntop1, provenance. + all: try constructor. +Qed. + +Lemma floatofint_total_sound: + forall v x, vmatch v x -> + vmatch (Val.maketotal (Val.floatofint v)) (floatofint x). +Proof. + unfold Val.floatofint, floatofint; intros. + inv H; simpl. + all: auto with va. + all: unfold ntop1, provenance. + all: try constructor. +Qed. + +Lemma floatofintu_total_sound: + forall v x, vmatch v x -> + vmatch (Val.maketotal (Val.floatofintu v)) (floatofintu x). +Proof. + unfold Val.floatofintu, floatofintu; intros. + inv H; simpl. + all: auto with va. + all: unfold ntop1, provenance. + all: try constructor. +Qed. + + +Definition divs_total (v w: aval) := + match w, v with + | I i2, I i1 => + if Int.eq i2 Int.zero + || Int.eq i1 (Int.repr Int.min_signed) && Int.eq i2 Int.mone + then ntop + else I (Int.divs i1 i2) + | _, _ => ntop2 v w + end. + +Lemma divs_total_sound: + forall v w x y, vmatch v x -> vmatch w y -> vmatch (Val.maketotal (Val.divs v w)) (divs_total x y). +Proof. + intros until y. + intros HX HY. + inv HX; inv HY; cbn in *. + { destruct (_ || _) eqn:E; cbn; unfold ntop; auto with va. + } + all: unfold ntop2; auto with va. + all: destruct (_ || _) eqn:E; unfold ntop2; cbn; auto with va. +Qed. + +Definition divu_total (v w: aval) := + match w, v with + | I i2, I i1 => + if Int.eq i2 Int.zero + then ntop + else I (Int.divu i1 i2) + | _, _ => ntop2 v w + end. + +Lemma divu_total_sound: + forall v w x y, vmatch v x -> vmatch w y -> vmatch (Val.maketotal (Val.divu v w)) (divu_total x y). +Proof. + intros until y. + intros HX HY. + inv HX; inv HY; cbn in *. + { destruct Int.eq eqn:E; cbn; unfold ntop; auto with va. + } + all: unfold ntop2; auto with va. + all: destruct Int.eq eqn:E; unfold ntop2; cbn; auto with va. +Qed. + +Definition mods_total (v w: aval) := + match w, v with + | I i2, I i1 => + if Int.eq i2 Int.zero + || Int.eq i1 (Int.repr Int.min_signed) && Int.eq i2 Int.mone + then ntop + else I (Int.mods i1 i2) + | _, _ => ntop2 v w + end. + +Lemma mods_total_sound: + forall v w x y, vmatch v x -> vmatch w y -> vmatch (Val.maketotal (Val.mods v w)) (mods_total x y). +Proof. + intros until y. + intros HX HY. + inv HX; inv HY; cbn in *. + { destruct (_ || _) eqn:E; cbn; unfold ntop; auto with va. + } + all: unfold ntop2; auto with va. + all: destruct (_ || _) eqn:E; unfold ntop2; cbn; auto with va. +Qed. + +Definition modu_total (v w: aval) := + match w, v with + | I i2, I i1 => + if Int.eq i2 Int.zero + then ntop + else I (Int.modu i1 i2) + | I i2, _ => uns (provenance v) (usize i2) + | _, _ => ntop2 v w + end. + +Lemma modu_total_sound: + forall v w x y, vmatch v x -> vmatch w y -> vmatch (Val.maketotal (Val.modu v w)) (modu_total x y). +Proof. + assert (UNS: forall i j, j <> Int.zero -> is_uns (usize j) (Int.modu i j)). + { + intros. apply is_uns_mon with (usize (Int.modu i j)). + { apply is_uns_usize. + } + unfold usize, Int.size. + apply Zsize_monotone. + generalize (Int.unsigned_range_2 j); intros RANGE. + assert (Int.unsigned j <> 0). + { red; intros; elim H. rewrite <- (Int.repr_unsigned j). rewrite H0. auto. } + exploit (Z_mod_lt (Int.unsigned i) (Int.unsigned j)). omega. intros MOD. + unfold Int.modu. rewrite Int.unsigned_repr. omega. omega. + } + intros until y. + intros HX HY. + inv HX; inv HY; cbn in *. + { destruct Int.eq eqn:E; unfold ntop; cbn; auto with va. + } + all: try discriminate. + all: unfold ntop2; auto with va. + all: try (destruct Int.eq eqn:E; cbn; unfold ntop2; auto with va; fail). + all: try apply vmatch_uns_undef. + + all: + generalize (Int.eq_spec i0 Int.zero); + destruct (Int.eq i0 Int.zero); + cbn; + intro. + all: try apply vmatch_uns_undef. + all: apply vmatch_uns; auto. +Qed. + + +Lemma shrx_total_sound: + forall v w x y, vmatch v x -> vmatch w y -> vmatch (Val.maketotal (Val.shrx v w)) (shrx x y). +Proof. + intros until y. intros HX HY. + inv HX; inv HY; cbn. + all: unfold ntop1; auto with va. + all: destruct Int.ltu eqn:LTU; cbn; unfold ntop; auto with va. +Qed. + + +Definition divls_total (v w: aval) := + match w, v with + | L i2, L i1 => + if Int64.eq i2 Int64.zero + || Int64.eq i1 (Int64.repr Int64.min_signed) && Int64.eq i2 Int64.mone + then ntop + else L (Int64.divs i1 i2) + | _, _ => ntop2 v w + end. + +Lemma divls_total_sound: + forall v w x y, vmatch v x -> vmatch w y -> vmatch (Val.maketotal (Val.divls v w)) (divls_total x y). +Proof. + intros until y. + intros HX HY. + inv HX; inv HY; cbn in *. + all: unfold ntop2; auto with va. + all: destruct (_ || _) eqn:E; unfold ntop2, ntop; cbn; auto with va. +Qed. + +Definition divlu_total (v w: aval) := + match w, v with + | L i2, L i1 => + if Int64.eq i2 Int64.zero + then ntop + else L (Int64.divu i1 i2) + | _, _ => ntop2 v w + end. + +Lemma divlu_total_sound: + forall v w x y, vmatch v x -> vmatch w y -> vmatch (Val.maketotal (Val.divlu v w)) (divlu_total x y). +Proof. + intros until y. + intros HX HY. + inv HX; inv HY; cbn in *. + all: unfold ntop2; auto with va. + all: destruct Int64.eq eqn:E; unfold ntop2, ntop; cbn; auto with va. +Qed. + + +Definition modls_total (v w: aval) := + match w, v with + | L i2, L i1 => + if Int64.eq i2 Int64.zero + || Int64.eq i1 (Int64.repr Int64.min_signed) && Int64.eq i2 Int64.mone + then ntop + else L (Int64.mods i1 i2) + | _, _ => ntop2 v w + end. + +Lemma modls_total_sound: + forall v w x y, vmatch v x -> vmatch w y -> vmatch (Val.maketotal (Val.modls v w)) (modls_total x y). +Proof. + intros until y. + intros HX HY. + inv HX; inv HY; cbn in *. + all: unfold ntop2; auto with va. + all: destruct (_ || _) eqn:E; unfold ntop2, ntop; cbn; auto with va. +Qed. + + +Definition modlu_total (v w: aval) := + match w, v with + | L i2, L i1 => + if Int64.eq i2 Int64.zero + then ntop + else L (Int64.modu i1 i2) + | _, _ => ntop2 v w + end. + +Lemma modlu_total_sound: + forall v w x y, vmatch v x -> vmatch w y -> vmatch (Val.maketotal (Val.modlu v w)) (modlu_total x y). +Proof. + intros until y. + intros HX HY. + inv HX; inv HY; cbn in *. + all: unfold ntop2; auto with va. + all: destruct Int64.eq eqn:E; cbn; unfold ntop2, ntop; auto with va. +Qed. + +Lemma shrxl_total_sound: + forall v w x y, vmatch v x -> vmatch w y -> vmatch (Val.maketotal (Val.shrxl v w)) (shrxl x y). +Proof. + intros until y. intros HX HY. + inv HX; inv HY; cbn. + all: unfold ntop1; auto with va. + all: destruct Int.ltu eqn:LTU; cbn; unfold ntop; auto with va. +Qed. + (** Comparisons and variation intervals *) Definition cmp_intv (c: comparison) (i: Z * Z) (n: Z) : abool := @@ -4734,6 +5195,26 @@ Hint Resolve cnot_sound symbol_address_sound longoffloat_sound longuoffloat_sound floatoflong_sound floatoflongu_sound longofsingle_sound longuofsingle_sound singleoflong_sound singleoflongu_sound longofwords_sound loword_sound hiword_sound + intoffloat_total_sound + intuoffloat_total_sound + intofsingle_total_sound + intuofsingle_total_sound + singleofint_total_sound + singleofintu_total_sound + longoffloat_total_sound + longuoffloat_total_sound + longofsingle_total_sound + longuofsingle_total_sound + singleoflong_total_sound + singleoflongu_total_sound + floatoflong_total_sound + floatoflongu_total_sound + floatofint_total_sound + floatofintu_total_sound + divu_total_sound divs_total_sound + modu_total_sound mods_total_sound shrx_total_sound + divlu_total_sound divls_total_sound + modlu_total_sound modls_total_sound shrxl_total_sound cmpu_bool_sound cmp_bool_sound cmplu_bool_sound cmpl_bool_sound cmpf_bool_sound cmpfs_bool_sound maskzero_sound : va. diff --git a/config_kvx_elf.sh b/config_kvx_elf.sh new file mode 100755 index 00000000..f1430417 --- /dev/null +++ b/config_kvx_elf.sh @@ -0,0 +1 @@ +exec ./config_simple.sh kvx-elf "$@" @@ -689,12 +689,14 @@ echo "-R lib compcert.lib \ -R common compcert.common \ -R ${arch} compcert.${arch} \ -R backend compcert.backend \ +-R scheduling compcert.scheduling \ -R cfrontend compcert.cfrontend \ -R driver compcert.driver \ -R flocq compcert.flocq \ -R exportclight compcert.exportclight \ -R cparser compcert.cparser \ --R MenhirLib compcert.MenhirLib" > _CoqProject +-R MenhirLib compcert.MenhirLib +-R Impure lib.Impure" > _CoqProject case $arch in x86) echo "-R x86_${bitsize} compcert.x86_${bitsize}" >> _CoqProject @@ -840,7 +842,7 @@ fi if [ "$arch" = "kvx" ]; then cat >> Makefile.config <<EOF -ARCHDIRS=$arch $arch/lib $arch/abstractbb $arch/abstractbb/Impure +ARCHDIRS=$arch $arch/lib $arch/abstractbb EXECUTE=kvx-cluster --syscall=libstd_scalls.so -- CFLAGS= -D __KVX_COS__ SIMU=kvx-cluster -- diff --git a/doc/index-kvx.html b/doc/index-kvx.html index ff3fbc17..97eefc24 100644 --- a/doc/index-kvx.html +++ b/doc/index-kvx.html @@ -64,7 +64,7 @@ inequations by fixpoint iteration. <UL> <LI> <A HREF="html/compcert.kvx.abstractbb.AbstractBasicBlocksDef.html">AbstractBasicBlocksDef</A>: an IR for verifying some semantic properties on basic-blocks. <LI> <A HREF="html/compcert.kvx.abstractbb.Parallelizability.html">Parallelizability</A>: verifying that sequential and parallel semantics are equivalent for a given abstract basic-block. -<LI> <A HREF="html/compcert.kvx.abstractbb.ImpSimuTest.html">ImpSimuTest</A>: verifying that a given abstract basic-block is simulated by another one for sequential semantics. This module refines <A HREF="html/compcert.kvx.abstractbb.SeqSimuTheory.html">SeqSimuTheory</A> with hash-consing. +<LI> <A HREF="html/compcert.kvx.abstractbb.ImpSimuTest.html">ImpSimuTest</A>: verifying that a given abstract basic-block is simulated by another one for sequential semantics. This module refines <A HREF="html/compcert.kvx.abstractbb.SeqSimuTheory.html">SeqSimuTheory</A> with hash-consing and uses <A HREF=https://github.com/boulme/ImpureDemo>the Impure library</A> to reason on physical equality and handling of imperative code in Coq. </UL> <font color=gray> @@ -325,7 +325,7 @@ This IR is generic over the processor, even if currently, only used for KVX. <TD>Flattening bundles (only a bureaucratic operation)</TD> <TD>Asmvliw to Asm</TD> <TD><A HREF="html/compcert.kvx.Asmgen.html"><I>Asmgen</I></A></TD> - <TD><A HREF="html/compcert.kvx.Asmgenproof.html"><I>Asmgenproof</I></A></TD> + <TD><A HREF="html/compcert.kvx.Asmgenproof.html"><I>Asmgenproof</I></A> (whole simulation proof from <tt>Mach</tt> to <tt>Asm</tt>)</TD> </TR> </TABLE> @@ -611,15 +611,15 @@ Program Definition genv_trans (ge: genv) : Asmvliw.genv := Genv.genv_defs := PTree.map1 globdef_proj (Genv.genv_defs ge); Genv.genv_next := Genv.genv_next ge |}. Next Obligation. - destruct ge. simpl in *. eauto. + destruct ge. cbn in *. eauto. Qed. Next Obligation. - destruct ge; simpl in *. + destruct ge; cbn in *. rewrite PTree.gmap1 in H. destruct (genv_defs ! b) eqn:GEN. - eauto. - discriminate. Qed. Next Obligation. - destruct ge; simpl in *. + destruct ge; cbn in *. eauto. Qed. @@ -655,14 +655,14 @@ Program Definition transf_function (f: Asmvliw.function) : function := Lemma transf_function_proj: forall f, function_proj (transf_function f) = f. Proof. - intros f. destruct f as [sig blks]. unfold function_proj. simpl. auto. + intros f. destruct f as [sig blks]. unfold function_proj. cbn. auto. Qed. Definition transf_fundef : Asmvliw.fundef -> fundef := AST.transf_fundef transf_function. Lemma transf_fundef_proj: forall f, fundef_proj (transf_fundef f) = f. Proof. - intros f. destruct f as [f|e]; simpl; auto. + intros f. destruct f as [f|e]; cbn; auto. rewrite transf_function_proj. auto. Qed. @@ -674,18 +674,18 @@ Lemma program_equals {A B: Type} : forall (p1 p2: AST.program A B), prog_main p1 = prog_main p2 -> p1 = p2. Proof. - intros. destruct p1. destruct p2. simpl in *. subst. auto. + intros. destruct p1. destruct p2. cbn in *. subst. auto. Qed. Lemma transf_program_proj: forall p, program_proj (transf_program p) = p. Proof. - intros p. destruct p as [defs pub main]. unfold program_proj. simpl. - apply program_equals; simpl; auto. + intros p. destruct p as [defs pub main]. unfold program_proj. cbn. + apply program_equals; cbn; auto. induction defs. - - simpl; auto. - - simpl. rewrite IHdefs. - destruct a as [id gd]; simpl. - destruct gd as [f|v]; simpl; auto. + - cbn; auto. + - cbn. rewrite IHdefs. + destruct a as [id gd]; cbn. + destruct gd as [f|v]; cbn; auto. rewrite transf_fundef_proj. auto. Qed. @@ -707,16 +707,16 @@ Lemma match_program_transf: forall p tp, match_prog p tp -> transf_program p = tp. Proof. intros p tp H. inversion_clear H. inv H1. - destruct p as [defs pub main]. destruct tp as [tdefs tpub tmain]. simpl in *. - subst. unfold transf_program. unfold transform_program. simpl. - apply program_equals; simpl; auto. - induction H0; simpl; auto. + destruct p as [defs pub main]. destruct tp as [tdefs tpub tmain]. cbn in *. + subst. unfold transf_program. unfold transform_program. cbn. + apply program_equals; cbn; auto. + induction H0; cbn; auto. rewrite IHlist_forall2. apply cons_extract. destruct a1 as [ida gda]. destruct b1 as [idb gdb]. - simpl in *. + cbn in *. inv H. inv H2. - - simpl in *. subst. auto. - - simpl in *. subst. inv H. auto. + - cbn in *. subst. auto. + - cbn in *. subst. inv H. auto. Qed. Section PRESERVATION. @@ -744,7 +744,7 @@ Proof. pose proof (match_program_transf prog tprog TRANSF) as TR. subst. unfold semantics. rewrite transf_program_proj. - eapply forward_simulation_step with (match_states := match_states); simpl; auto. + eapply forward_simulation_step with (match_states := match_states); cbn; auto. - intros. exists s1. split; auto. congruence. - intros. inv H. auto. - intros. exists s1'. inv H0. split; auto. congruence. diff --git a/kvx/Asmblock.v b/kvx/Asmblock.v index 9c8e4cc3..64b2c535 100644 --- a/kvx/Asmblock.v +++ b/kvx/Asmblock.v @@ -78,7 +78,7 @@ Fixpoint code_to_basics (c: code) := Lemma code_to_basics_id: forall c, code_to_basics (basics_to_code c) = Some c. Proof. - intros. induction c as [|i c]; simpl; auto. + intros. induction c as [|i c]; cbn; auto. rewrite IHc. auto. Qed. @@ -88,8 +88,8 @@ Lemma code_to_basics_dist: code_to_basics c' = Some l' -> code_to_basics (c ++ c') = Some (l ++ l'). Proof. - induction c as [|i c]; simpl; auto. - - intros. inv H. simpl. auto. + induction c as [|i c]; cbn; auto. + - intros. inv H. cbn. auto. - intros. destruct i; try discriminate. destruct (code_to_basics c) eqn:CTB; try discriminate. inv H. erewrite IHc; eauto. auto. Qed. @@ -138,9 +138,9 @@ Lemma non_empty_bblock_refl: Proof. intros. split. - destruct body; destruct exit. - all: simpl; auto. intros. inversion H; contradiction. + all: cbn; auto. intros. inversion H; contradiction. - destruct body; destruct exit. - all: simpl; auto. + all: cbn; auto. all: intros; try (right; discriminate); try (left; discriminate). contradiction. Qed. @@ -155,14 +155,14 @@ Lemma builtin_alone_refl: Proof. intros. split. - destruct body; destruct exit. - all: simpl; auto. - all: exploreInst; simpl; auto. + all: cbn; auto. + all: exploreInst; cbn; auto. unfold builtin_alone. intros. assert (Some (Pbuiltin e l b0) = Some (Pbuiltin e l b0)); auto. assert (b :: body = nil). eapply H; eauto. discriminate. - destruct body; destruct exit. - all: simpl; auto; try constructor. + all: cbn; auto; try constructor. + exploreInst; try discriminate. - simpl. contradiction. + cbn. contradiction. + intros. discriminate. Qed. @@ -185,14 +185,14 @@ Ltac bblock_auto_correct := (apply non_empty_bblock_refl; try discriminate; try Lemma Istrue_proof_irrelevant (b: bool): forall (p1 p2:Is_true b), p1=p2. Proof. - destruct b; simpl; auto. + destruct b; cbn; auto. - destruct p1, p2; auto. - destruct p1. Qed. Lemma bblock_equality bb1 bb2: header bb1=header bb2 -> body bb1 = body bb2 -> exit bb1 = exit bb2 -> bb1 = bb2. Proof. - destruct bb1 as [h1 b1 e1 c1], bb2 as [h2 b2 e2 c2]; simpl. + destruct bb1 as [h1 b1 e1 c1], bb2 as [h2 b2 e2 c2]; cbn. intros; subst. rewrite (Istrue_proof_irrelevant _ c1 c2). auto. @@ -212,51 +212,51 @@ Qed. Lemma length_nonil {A: Type} : forall l:(list A), l <> nil -> (length l > 0)%nat. Proof. intros. destruct l; try (contradict H; auto; fail). - simpl. omega. + cbn. omega. Qed. Lemma to_nat_pos : forall z:Z, (Z.to_nat z > 0)%nat -> z > 0. Proof. intros. destruct z; auto. - - contradict H. simpl. apply gt_irrefl. + - contradict H. cbn. apply gt_irrefl. - apply Zgt_pos_0. - - contradict H. simpl. apply gt_irrefl. + - contradict H. cbn. apply gt_irrefl. Qed. Lemma size_positive (b:bblock): size b > 0. Proof. - unfold size. destruct b as [hd bdy ex cor]. simpl. - destruct ex; destruct bdy; try (apply to_nat_pos; rewrite Nat2Z.id; simpl; omega). - inversion cor; contradict H; simpl; auto. + unfold size. destruct b as [hd bdy ex cor]. cbn. + destruct ex; destruct bdy; try (apply to_nat_pos; rewrite Nat2Z.id; cbn; omega). + inversion cor; contradict H; cbn; auto. Qed. Program Definition no_header (bb : bblock) := {| header := nil; body := body bb; exit := exit bb |}. Next Obligation. - destruct bb; simpl. assumption. + destruct bb; cbn. assumption. Defined. Lemma no_header_size: forall bb, size (no_header bb) = size bb. Proof. - intros. destruct bb as [hd bdy ex COR]. unfold no_header. simpl. reflexivity. + intros. destruct bb as [hd bdy ex COR]. unfold no_header. cbn. reflexivity. Qed. Program Definition stick_header (h : list label) (bb : bblock) := {| header := h; body := body bb; exit := exit bb |}. Next Obligation. - destruct bb; simpl. assumption. + destruct bb; cbn. assumption. Defined. Lemma stick_header_size: forall h bb, size (stick_header h bb) = size bb. Proof. - intros. destruct bb. unfold stick_header. simpl. reflexivity. + intros. destruct bb. unfold stick_header. cbn. reflexivity. Qed. Lemma stick_header_no_header: forall bb, stick_header (header bb) (no_header bb) = bb. Proof. - intros. destruct bb as [hd bdy ex COR]. simpl. unfold no_header; unfold stick_header; simpl. reflexivity. + intros. destruct bb as [hd bdy ex COR]. cbn. unfold no_header; unfold stick_header; cbn. reflexivity. Qed. (** * Sequential Semantics of basic blocks *) @@ -308,7 +308,7 @@ Fixpoint exec_body (body: list basic) (rs: regset) (m: mem): outcome := Theorem builtin_body_nil: forall bb ef args res, exit bb = Some (PExpand (Pbuiltin ef args res)) -> body bb = nil. Proof. - intros. destruct bb as [hd bdy ex WF]. simpl in *. + intros. destruct bb as [hd bdy ex WF]. cbn in *. apply wf_bblock_refl in WF. inv WF. unfold builtin_alone in H1. eapply H1; eauto. Qed. @@ -321,11 +321,11 @@ Theorem exec_body_app: /\ exec_body l' rs' m' = Next rs'' m''. Proof. induction l. - - intros. simpl in H. repeat eexists. auto. - - intros. rewrite <- app_comm_cons in H. simpl in H. + - intros. cbn in H. repeat eexists. auto. + - intros. rewrite <- app_comm_cons in H. cbn in H. destruct (exec_basic_instr a rs m) eqn:EXEBI. + apply IHl in H. destruct H as (rs1 & m1 & EXEB1 & EXEB2). - repeat eexists. simpl. rewrite EXEBI. eauto. auto. + repeat eexists. cbn. rewrite EXEBI. eauto. auto. + discriminate. Qed. diff --git a/kvx/Asmblockprops.v b/kvx/Asmblockprops.v index bc14b231..c3929be5 100644 --- a/kvx/Asmblockprops.v +++ b/kvx/Asmblockprops.v @@ -53,7 +53,7 @@ Qed. Lemma preg_of_not_SP: forall r, preg_of r <> SP. Proof. - intros. unfold preg_of; destruct r; simpl; congruence. + intros. unfold preg_of; destruct r; cbn; congruence. Qed. Hint Resolve preg_of_not_SP preg_of_not_PC: asmgen. @@ -233,7 +233,7 @@ Proof. destruct (ireg_eq rd2 ra); try discriminate. *) rewrite Pregmap.gso; try discriminate. - simpl in *. + cbn in *. destruct (Mem.loadv _ _ _); try discriminate. destruct (Mem.loadv _ _ _); try discriminate. destruct (Mem.loadv _ _ _); try discriminate. @@ -264,7 +264,7 @@ Lemma exec_store_q_offset_pc_var: exec_store_q_offset rs # PC <- v m rd ra ofs = Next rs' # PC <- v m'. Proof. intros. unfold exec_store_q_offset in *. unfold parexec_store_q_offset in *. rewrite Pregmap.gso; try discriminate. - simpl in *. + cbn in *. destruct (gpreg_q_expand _) as [s0 s1]. destruct (Mem.storev _ _ _); try discriminate. destruct (Mem.storev _ _ _); try discriminate. diff --git a/kvx/Asmgenproof.v b/kvx/Asmgenproof.v index 9e35e268..636c105f 100644 --- a/kvx/Asmgenproof.v +++ b/kvx/Asmgenproof.v @@ -39,7 +39,7 @@ Proof. unfold Asmgen.transf_program in H. apply bind_inversion in H. destruct H. inversion_clear H. apply bind_inversion in H1. destruct H1. inversion_clear H. inversion H2. unfold time, Compopts.time in *. remember (Machblockgen.transf_program p) as mbp. - unfold match_prog; simpl. + unfold match_prog; cbn. exists mbp; split. apply Machblockgenproof.transf_program_match; auto. exists x; split. apply Asmblockgenproof.transf_program_match; auto. exists x0; split. apply PostpassSchedulingproof.transf_program_match; auto. @@ -72,7 +72,7 @@ Let tge := Genv.globalenv tprog. Theorem transf_program_correct: forward_simulation (Mach.semantics return_address_offset prog) (Asm.semantics tprog). Proof. - unfold match_prog in TRANSF. simpl in TRANSF. + unfold match_prog in TRANSF. cbn in TRANSF. inv TRANSF. inv H. inv H1. inv H. inv H2. inv H. inv H3. inv H. eapply compose_forward_simulations. exploit Machblockgenproof.transf_program_correct; eauto. diff --git a/kvx/Asmvliw.v b/kvx/Asmvliw.v index 296963a7..66b468d7 100644 --- a/kvx/Asmvliw.v +++ b/kvx/Asmvliw.v @@ -849,7 +849,7 @@ Lemma Val_cmpu_correct (m:mem) (cmp: comparison) (v1 v2: val): Proof. unfold Val.cmpu, Val_cmpu. remember (Val.cmpu_bool (Mem.valid_pointer m) cmp v1 v2) as ob. - destruct ob; simpl. + destruct ob; cbn. - erewrite Val_cmpu_bool_correct; eauto. econstructor. - econstructor. @@ -873,9 +873,9 @@ Lemma Val_cmplu_correct (m:mem) (cmp: comparison) (v1 v2: val): Proof. unfold Val.cmplu, Val_cmplu. remember (Val.cmplu_bool (Mem.valid_pointer m) cmp v1 v2) as ob. - destruct ob as [b|]; simpl. + destruct ob as [b|]; cbn. - erewrite Val_cmplu_bool_correct; eauto. - simpl. econstructor. + cbn. econstructor. - econstructor. Qed. @@ -1426,13 +1426,13 @@ Definition is_label (lbl: label) (bb: bblock) : bool := Lemma is_label_correct_true lbl bb: List.In lbl (header bb) <-> is_label lbl bb = true. Proof. - unfold is_label; destruct (in_dec lbl (header bb)); simpl; intuition. + unfold is_label; destruct (in_dec lbl (header bb)); cbn; intuition. Qed. Lemma is_label_correct_false lbl bb: ~(List.In lbl (header bb)) <-> is_label lbl bb = false. Proof. - unfold is_label; destruct (in_dec lbl (header bb)); simpl; intuition. + unfold is_label; destruct (in_dec lbl (header bb)); cbn; intuition. Qed. @@ -1667,7 +1667,7 @@ Proof. constructor 1. - rewrite app_nil_r; auto. - unfold parexec_wio_bblock. - destruct (parexec_wio f _ _ _); simpl; auto. + destruct (parexec_wio f _ _ _); cbn; auto. Qed. @@ -1739,7 +1739,7 @@ Ltac Det_WIO X := exploit det_parexec_write_in_order; [ eapply H | idtac]; clear H; intro X | _ => idtac end. - intros; constructor; simpl. + intros; constructor; cbn. - (* determ *) intros s t1 s1 t2 s2 H H0. inv H; Det_WIO X1; inv H0; Det_WIO X2; Equalities. + split. constructor. auto. @@ -1754,7 +1754,7 @@ Ltac Det_WIO X := exploit external_call_determ. eexact H3. eexact H8. intros [A B]. split. auto. intros. destruct B; auto. subst. auto. - (* trace length *) - red; intros. inv H; simpl. + red; intros. inv H; cbn. omega. eapply external_call_trace_length; eauto. eapply external_call_trace_length; eauto. diff --git a/kvx/CSE2depsproof.v b/kvx/CSE2depsproof.v index f283c8ac..6c584450 100644 --- a/kvx/CSE2depsproof.v +++ b/kvx/CSE2depsproof.v @@ -71,7 +71,7 @@ Section MEMORY_WRITE. unfold largest_size_chunk in *. rewrite ptrofs_modulus in *. - simpl in *. + cbn in *. inv ADDRR. inv ADDRW. destruct base; try discriminate. @@ -126,12 +126,12 @@ Proof. { (* Aindexed / Aindexed *) destruct args as [ | base [ | ]]. 1,3: discriminate. destruct args' as [ | base' [ | ]]. 1,3: discriminate. - simpl in OVERLAP. + cbn in OVERLAP. destruct (peq base base'). 2: discriminate. subst base'. destruct (can_swap_accesses_ofs (Ptrofs.unsigned i0) chunk' (Ptrofs.unsigned i) chunk) eqn:SWAP. 2: discriminate. - simpl in *. + cbn in *. eapply load_store_away with (F:=F) (V:=V) (genv:=genv) (sp:=sp); eassumption. } Qed. diff --git a/kvx/CombineOpproof.v b/kvx/CombineOpproof.v index dafc90df..5dffc565 100644 --- a/kvx/CombineOpproof.v +++ b/kvx/CombineOpproof.v @@ -46,7 +46,7 @@ Qed. Ltac UseGetSound := match goal with | [ H: get _ = Some _ |- _ ] => - let x := fresh "EQ" in (generalize (get_op_sound _ _ _ H); intros x; simpl in x; FuncInv) + let x := fresh "EQ" in (generalize (get_op_sound _ _ _ H); intros x; cbn in x; FuncInv) end. Lemma combine_compimm_ne_0_sound: @@ -58,7 +58,7 @@ Proof. intros until args. functional induction (combine_compimm_ne_0 get x); intros EQ; inv EQ. (* of cmp *) UseGetSound. rewrite <- H. - destruct (eval_condition cond (map valu args) m); simpl; auto. destruct b; auto. + destruct (eval_condition cond (map valu args) m); cbn; auto. destruct b; auto. Qed. Lemma combine_compimm_eq_0_sound: @@ -71,7 +71,7 @@ Proof. (* of cmp *) UseGetSound. rewrite <- H. rewrite eval_negate_condition. - destruct (eval_condition c (map valu args) m); simpl; auto. destruct b; auto. + destruct (eval_condition c (map valu args) m); cbn; auto. destruct b; auto. Qed. Lemma combine_compimm_eq_1_sound: @@ -83,7 +83,7 @@ Proof. intros until args. functional induction (combine_compimm_eq_1 get x); intros EQ; inv EQ. (* of cmp *) UseGetSound. rewrite <- H. - destruct (eval_condition cond (map valu args) m); simpl; auto. destruct b; auto. + destruct (eval_condition cond (map valu args) m); cbn; auto. destruct b; auto. Qed. Lemma combine_compimm_ne_1_sound: @@ -96,7 +96,7 @@ Proof. (* of cmp *) UseGetSound. rewrite <- H. rewrite eval_negate_condition. - destruct (eval_condition c (map valu args) m); simpl; auto. destruct b; auto. + destruct (eval_condition c (map valu args) m); cbn; auto. destruct b; auto. Qed. Theorem combine_cond_sound: @@ -106,21 +106,21 @@ Theorem combine_cond_sound: Proof. intros. functional inversion H; subst. (* compimm ne zero *) - - simpl; eapply combine_compimm_ne_0_sound; eauto. + - cbn; eapply combine_compimm_ne_0_sound; eauto. (* compimm ne one *) - - simpl; eapply combine_compimm_ne_1_sound; eauto. + - cbn; eapply combine_compimm_ne_1_sound; eauto. (* compimm eq zero *) - - simpl; eapply combine_compimm_eq_0_sound; eauto. + - cbn; eapply combine_compimm_eq_0_sound; eauto. (* compimm eq one *) - - simpl; eapply combine_compimm_eq_1_sound; eauto. + - cbn; eapply combine_compimm_eq_1_sound; eauto. (* compuimm ne zero *) - - simpl; eapply combine_compimm_ne_0_sound; eauto. + - cbn; eapply combine_compimm_ne_0_sound; eauto. (* compuimm ne one *) - - simpl; eapply combine_compimm_ne_1_sound; eauto. + - cbn; eapply combine_compimm_ne_1_sound; eauto. (* compuimm eq zero *) - - simpl; eapply combine_compimm_eq_0_sound; eauto. + - cbn; eapply combine_compimm_eq_0_sound; eauto. (* compuimm eq one *) - - simpl; eapply combine_compimm_eq_1_sound; eauto. + - cbn; eapply combine_compimm_eq_1_sound; eauto. Qed. Theorem combine_addr_sound: @@ -130,10 +130,10 @@ Theorem combine_addr_sound: Proof. intros. functional inversion H; subst. - (* indexed - addimm *) - UseGetSound. simpl. rewrite <- H0. destruct v; auto. simpl; rewrite H7; simpl. + UseGetSound. cbn. rewrite <- H0. destruct v; auto. cbn; rewrite H7; cbn. rewrite Ptrofs.add_assoc. auto. - (* indexed - addimml *) - UseGetSound. simpl. rewrite <- H0. destruct v; auto. simpl; rewrite H7; simpl. + UseGetSound. cbn. rewrite <- H0. destruct v; auto. cbn; rewrite H7; cbn. rewrite Ptrofs.add_assoc. auto. Qed. @@ -144,33 +144,33 @@ Theorem combine_op_sound: Proof. intros. functional inversion H; subst. (* addimm - addimm *) - - UseGetSound. FuncInv. simpl. + - UseGetSound. FuncInv. cbn. rewrite <- H0. rewrite Val.add_assoc. auto. (* andimm - andimm *) - - UseGetSound; simpl. + - UseGetSound; cbn. generalize (Int.eq_spec p m0); rewrite H7; intros. - rewrite <- H0. rewrite Val.and_assoc. simpl. fold p. rewrite H1. auto. - - UseGetSound; simpl. + rewrite <- H0. rewrite Val.and_assoc. cbn. fold p. rewrite H1. auto. + - UseGetSound; cbn. rewrite <- H0. rewrite Val.and_assoc. auto. (* orimm - orimm *) - - UseGetSound. simpl. rewrite <- H0. rewrite Val.or_assoc. auto. + - UseGetSound. cbn. rewrite <- H0. rewrite Val.or_assoc. auto. (* xorimm - xorimm *) - - UseGetSound. simpl. rewrite <- H0. rewrite Val.xor_assoc. auto. + - UseGetSound. cbn. rewrite <- H0. rewrite Val.xor_assoc. auto. (* addlimm - addlimm *) - - UseGetSound. FuncInv. simpl. + - UseGetSound. FuncInv. cbn. rewrite <- H0. rewrite Val.addl_assoc. auto. (* andlimm - andlimm *) - - UseGetSound; simpl. + - UseGetSound; cbn. generalize (Int64.eq_spec p m0); rewrite H7; intros. - rewrite <- H0. rewrite Val.andl_assoc. simpl. fold p. rewrite H1. auto. - - UseGetSound; simpl. + rewrite <- H0. rewrite Val.andl_assoc. cbn. fold p. rewrite H1. auto. + - UseGetSound; cbn. rewrite <- H0. rewrite Val.andl_assoc. auto. (* orlimm - orlimm *) - - UseGetSound. simpl. rewrite <- H0. rewrite Val.orl_assoc. auto. + - UseGetSound. cbn. rewrite <- H0. rewrite Val.orl_assoc. auto. (* xorlimm - xorlimm *) - - UseGetSound. simpl. rewrite <- H0. rewrite Val.xorl_assoc. auto. + - UseGetSound. cbn. rewrite <- H0. rewrite Val.xorl_assoc. auto. (* cmp *) - - simpl. decEq; decEq. eapply combine_cond_sound; eauto. + - cbn. decEq; decEq. eapply combine_cond_sound; eauto. Qed. End COMBINE. diff --git a/kvx/ConstpropOpproof.v b/kvx/ConstpropOpproof.v index 05bbdde1..ffd35bcc 100644 --- a/kvx/ConstpropOpproof.v +++ b/kvx/ConstpropOpproof.v @@ -105,7 +105,7 @@ Proof. + (* global *) inv H2. exists (Genv.symbol_address ge id ofs); auto. + (* stack *) - inv H2. exists (Vptr sp ofs); split; auto. simpl. rewrite Ptrofs.add_zero_l; auto. + inv H2. exists (Vptr sp ofs); split; auto. cbn. rewrite Ptrofs.add_zero_l; auto. Qed. Lemma cond_strength_reduction_correct: @@ -115,7 +115,7 @@ Lemma cond_strength_reduction_correct: eval_condition cond' e##args' m = eval_condition cond e##args m. Proof. intros until vl. unfold cond_strength_reduction. - case (cond_strength_reduction_match cond args vl); simpl; intros; InvApproxRegs; SimplVM. + case (cond_strength_reduction_match cond args vl); cbn; intros; InvApproxRegs; SimplVM. - apply Val.swap_cmp_bool. - auto. - apply Val.swap_cmpu_bool. @@ -137,7 +137,7 @@ Proof. intros. unfold make_cmp_base. generalize (cond_strength_reduction_correct c args vl H). destruct (cond_strength_reduction c args vl) as [c' args']. intros EQ. - econstructor; split. simpl; eauto. rewrite EQ. auto. + econstructor; split. cbn; eauto. rewrite EQ. auto. Qed. Lemma make_cmp_correct: @@ -154,43 +154,43 @@ Proof. unfold make_cmp. case (make_cmp_match c args vl); intros. - unfold make_cmp_imm_eq. destruct (Int.eq_dec n Int.one && vincl v1 (Uns Ptop 1)) eqn:E1. -+ simpl in H; inv H. InvBooleans. subst n. - exists (e#r1); split; auto. simpl. - exploit Y; eauto. intros [A | [A | A]]; rewrite A; simpl; auto. ++ cbn in H; inv H. InvBooleans. subst n. + exists (e#r1); split; auto. cbn. + exploit Y; eauto. intros [A | [A | A]]; rewrite A; cbn; auto. + destruct (Int.eq_dec n Int.zero && vincl v1 (Uns Ptop 1)) eqn:E0. -* simpl in H; inv H. InvBooleans. subst n. - exists (Val.xor e#r1 (Vint Int.one)); split; auto. simpl. - exploit Y; eauto. intros [A | [A | A]]; rewrite A; simpl; auto. +* cbn in H; inv H. InvBooleans. subst n. + exists (Val.xor e#r1 (Vint Int.one)); split; auto. cbn. + exploit Y; eauto. intros [A | [A | A]]; rewrite A; cbn; auto. * apply make_cmp_base_correct; auto. - unfold make_cmp_imm_ne. destruct (Int.eq_dec n Int.zero && vincl v1 (Uns Ptop 1)) eqn:E0. -+ simpl in H; inv H. InvBooleans. subst n. - exists (e#r1); split; auto. simpl. - exploit Y; eauto. intros [A | [A | A]]; rewrite A; simpl; auto. ++ cbn in H; inv H. InvBooleans. subst n. + exists (e#r1); split; auto. cbn. + exploit Y; eauto. intros [A | [A | A]]; rewrite A; cbn; auto. + destruct (Int.eq_dec n Int.one && vincl v1 (Uns Ptop 1)) eqn:E1. -* simpl in H; inv H. InvBooleans. subst n. - exists (Val.xor e#r1 (Vint Int.one)); split; auto. simpl. - exploit Y; eauto. intros [A | [A | A]]; rewrite A; simpl; auto. +* cbn in H; inv H. InvBooleans. subst n. + exists (Val.xor e#r1 (Vint Int.one)); split; auto. cbn. + exploit Y; eauto. intros [A | [A | A]]; rewrite A; cbn; auto. * apply make_cmp_base_correct; auto. - unfold make_cmp_imm_eq. destruct (Int.eq_dec n Int.one && vincl v1 (Uns Ptop 1)) eqn:E1. -+ simpl in H; inv H. InvBooleans. subst n. - exists (e#r1); split; auto. simpl. - exploit Y; eauto. intros [A | [A | A]]; rewrite A; simpl; auto. ++ cbn in H; inv H. InvBooleans. subst n. + exists (e#r1); split; auto. cbn. + exploit Y; eauto. intros [A | [A | A]]; rewrite A; cbn; auto. + destruct (Int.eq_dec n Int.zero && vincl v1 (Uns Ptop 1)) eqn:E0. -* simpl in H; inv H. InvBooleans. subst n. - exists (Val.xor e#r1 (Vint Int.one)); split; auto. simpl. - exploit Y; eauto. intros [A | [A | A]]; rewrite A; simpl; auto. +* cbn in H; inv H. InvBooleans. subst n. + exists (Val.xor e#r1 (Vint Int.one)); split; auto. cbn. + exploit Y; eauto. intros [A | [A | A]]; rewrite A; cbn; auto. * apply make_cmp_base_correct; auto. - unfold make_cmp_imm_ne. destruct (Int.eq_dec n Int.zero && vincl v1 (Uns Ptop 1)) eqn:E0. -+ simpl in H; inv H. InvBooleans. subst n. - exists (e#r1); split; auto. simpl. - exploit Y; eauto. intros [A | [A | A]]; rewrite A; simpl; auto. ++ cbn in H; inv H. InvBooleans. subst n. + exists (e#r1); split; auto. cbn. + exploit Y; eauto. intros [A | [A | A]]; rewrite A; cbn; auto. + destruct (Int.eq_dec n Int.one && vincl v1 (Uns Ptop 1)) eqn:E1. -* simpl in H; inv H. InvBooleans. subst n. - exists (Val.xor e#r1 (Vint Int.one)); split; auto. simpl. - exploit Y; eauto. intros [A | [A | A]]; rewrite A; simpl; auto. +* cbn in H; inv H. InvBooleans. subst n. + exists (Val.xor e#r1 (Vint Int.one)); split; auto. cbn. + exploit Y; eauto. intros [A | [A | A]]; rewrite A; cbn; auto. * apply make_cmp_base_correct; auto. - apply make_cmp_base_correct; auto. Qed. @@ -203,7 +203,7 @@ Proof. intros. unfold make_addimm. predSpec Int.eq Int.eq_spec n Int.zero; intros. subst. exists (e#r); split; auto. - destruct (e#r); simpl; auto; rewrite ?Int.add_zero, ?Ptrofs.add_zero; auto. + destruct (e#r); cbn; auto; rewrite ?Int.add_zero, ?Ptrofs.add_zero; auto. exists (Val.add e#r (Vint n)); split; auto. Qed. @@ -215,10 +215,10 @@ Lemma make_shlimm_correct: Proof. intros; unfold make_shlimm. predSpec Int.eq Int.eq_spec n Int.zero; intros. subst. - exists (e#r1); split; auto. destruct (e#r1); simpl; auto. rewrite Int.shl_zero. auto. + exists (e#r1); split; auto. destruct (e#r1); cbn; auto. rewrite Int.shl_zero. auto. destruct (Int.ltu n Int.iwordsize). - econstructor; split. simpl. eauto. auto. - econstructor; split. simpl. eauto. rewrite H; auto. + econstructor; split. cbn. eauto. auto. + econstructor; split. cbn. eauto. rewrite H; auto. Qed. Lemma make_shrimm_correct: @@ -229,10 +229,10 @@ Lemma make_shrimm_correct: Proof. intros; unfold make_shrimm. predSpec Int.eq Int.eq_spec n Int.zero; intros. subst. - exists (e#r1); split; auto. destruct (e#r1); simpl; auto. rewrite Int.shr_zero. auto. + exists (e#r1); split; auto. destruct (e#r1); cbn; auto. rewrite Int.shr_zero. auto. destruct (Int.ltu n Int.iwordsize). - econstructor; split. simpl. eauto. auto. - econstructor; split. simpl. eauto. rewrite H; auto. + econstructor; split. cbn. eauto. auto. + econstructor; split. cbn. eauto. rewrite H; auto. Qed. Lemma make_shruimm_correct: @@ -243,10 +243,10 @@ Lemma make_shruimm_correct: Proof. intros; unfold make_shruimm. predSpec Int.eq Int.eq_spec n Int.zero; intros. subst. - exists (e#r1); split; auto. destruct (e#r1); simpl; auto. rewrite Int.shru_zero. auto. + exists (e#r1); split; auto. destruct (e#r1); cbn; auto. rewrite Int.shru_zero. auto. destruct (Int.ltu n Int.iwordsize). - econstructor; split. simpl. eauto. auto. - econstructor; split. simpl. eauto. rewrite H; auto. + econstructor; split. cbn. eauto. auto. + econstructor; split. cbn. eauto. rewrite H; auto. Qed. Lemma make_mulimm_correct: @@ -257,12 +257,12 @@ Lemma make_mulimm_correct: Proof. intros; unfold make_mulimm. predSpec Int.eq Int.eq_spec n Int.zero; intros. subst. - exists (Vint Int.zero); split; auto. destruct (e#r1); simpl; auto. rewrite Int.mul_zero; auto. + exists (Vint Int.zero); split; auto. destruct (e#r1); cbn; auto. rewrite Int.mul_zero; auto. predSpec Int.eq Int.eq_spec n Int.one; intros. subst. - exists (e#r1); split; auto. destruct (e#r1); simpl; auto. rewrite Int.mul_one; auto. + exists (e#r1); split; auto. destruct (e#r1); cbn; auto. rewrite Int.mul_one; auto. destruct (Int.is_power2 n) eqn:?; intros. - rewrite (Val.mul_pow2 e#r1 _ _ Heqo). econstructor; split. simpl; eauto. auto. - econstructor; split; eauto. simpl. rewrite H; auto. + rewrite (Val.mul_pow2 e#r1 _ _ Heqo). econstructor; split. cbn; eauto. auto. + econstructor; split; eauto. cbn. rewrite H; auto. Qed. Lemma make_divimm_correct: @@ -275,11 +275,11 @@ Proof. intros; unfold make_divimm. predSpec Int.eq Int.eq_spec n Int.one; intros. subst. rewrite H0 in H. destruct (e#r1) eqn:?; - try (rewrite Val.divs_one in H; exists (Vint i); split; simpl; try rewrite Heqv0; auto); + try (rewrite Val.divs_one in H; exists (Vint i); split; cbn; try rewrite Heqv0; auto); inv H; auto. destruct (Int.is_power2 n) eqn:?. destruct (Int.ltu i (Int.repr 31)) eqn:?. - exists v; split; auto. simpl. + exists v; split; auto. cbn. erewrite Val.divs_pow2; eauto. reflexivity. congruence. exists v; auto. exists v; auto. @@ -295,10 +295,10 @@ Proof. intros; unfold make_divuimm. predSpec Int.eq Int.eq_spec n Int.one; intros. subst. rewrite H0 in H. destruct (e#r1) eqn:?; - try (rewrite Val.divu_one in H; exists (Vint i); split; simpl; try rewrite Heqv0; auto); + try (rewrite Val.divu_one in H; exists (Vint i); split; cbn; try rewrite Heqv0; auto); inv H; auto. destruct (Int.is_power2 n) eqn:?. - econstructor; split. simpl; eauto. + econstructor; split. cbn; eauto. rewrite H0 in H. erewrite Val.divu_pow2 by eauto. auto. exists v; auto. Qed. @@ -312,7 +312,7 @@ Lemma make_moduimm_correct: Proof. intros; unfold make_moduimm. destruct (Int.is_power2 n) eqn:?. - exists v; split; auto. simpl. decEq. eapply Val.modu_pow2; eauto. congruence. + exists v; split; auto. cbn. decEq. eapply Val.modu_pow2; eauto. congruence. exists v; auto. Qed. @@ -324,18 +324,18 @@ Lemma make_andimm_correct: Proof. intros; unfold make_andimm. predSpec Int.eq Int.eq_spec n Int.zero; intros. - subst n. exists (Vint Int.zero); split; auto. destruct (e#r); simpl; auto. rewrite Int.and_zero; auto. + subst n. exists (Vint Int.zero); split; auto. destruct (e#r); cbn; auto. rewrite Int.and_zero; auto. predSpec Int.eq Int.eq_spec n Int.mone; intros. - subst n. exists (e#r); split; auto. destruct (e#r); simpl; auto. rewrite Int.and_mone; auto. + subst n. exists (e#r); split; auto. destruct (e#r); cbn; auto. rewrite Int.and_mone; auto. destruct (match x with Uns _ k => Int.eq (Int.zero_ext k (Int.not n)) Int.zero | _ => false end) eqn:UNS. destruct x; try congruence. exists (e#r); split; auto. - inv H; auto. simpl. replace (Int.and i n) with i; auto. + inv H; auto. cbn. replace (Int.and i n) with i; auto. generalize (Int.eq_spec (Int.zero_ext n0 (Int.not n)) Int.zero); rewrite UNS; intro EQ. Int.bit_solve. destruct (zlt i0 n0). replace (Int.testbit n i0) with (negb (Int.testbit Int.zero i0)). - rewrite Int.bits_zero. simpl. rewrite andb_true_r. auto. + rewrite Int.bits_zero. cbn. rewrite andb_true_r. auto. rewrite <- EQ. rewrite Int.bits_zero_ext by omega. rewrite zlt_true by auto. rewrite Int.bits_not by auto. apply negb_involutive. rewrite H6 by auto. auto. @@ -349,9 +349,9 @@ Lemma make_orimm_correct: Proof. intros; unfold make_orimm. predSpec Int.eq Int.eq_spec n Int.zero; intros. - subst n. exists (e#r); split; auto. destruct (e#r); simpl; auto. rewrite Int.or_zero; auto. + subst n. exists (e#r); split; auto. destruct (e#r); cbn; auto. rewrite Int.or_zero; auto. predSpec Int.eq Int.eq_spec n Int.mone; intros. - subst n. exists (Vint Int.mone); split; auto. destruct (e#r); simpl; auto. rewrite Int.or_mone; auto. + subst n. exists (Vint Int.mone); split; auto. destruct (e#r); cbn; auto. rewrite Int.or_mone; auto. econstructor; split; eauto. auto. Qed. @@ -362,7 +362,7 @@ Lemma make_xorimm_correct: Proof. intros; unfold make_xorimm. predSpec Int.eq Int.eq_spec n Int.zero; intros. - subst n. exists (e#r); split; auto. destruct (e#r); simpl; auto. rewrite Int.xor_zero; auto. + subst n. exists (e#r); split; auto. destruct (e#r); cbn; auto. rewrite Int.xor_zero; auto. predSpec Int.eq Int.eq_spec n Int.mone; intros. subst n. exists (Val.notint e#r); split; auto. econstructor; split; eauto. auto. @@ -376,7 +376,7 @@ Proof. intros. unfold make_addlimm. predSpec Int64.eq Int64.eq_spec n Int64.zero; intros. subst. exists (e#r); split; auto. - destruct (e#r); simpl; auto; rewrite ? Int64.add_zero, ? Ptrofs.add_zero; auto. + destruct (e#r); cbn; auto; rewrite ? Int64.add_zero, ? Ptrofs.add_zero; auto. exists (Val.addl e#r (Vlong n)); split; auto. Qed. @@ -388,11 +388,11 @@ Lemma make_shllimm_correct: Proof. intros; unfold make_shllimm. predSpec Int.eq Int.eq_spec n Int.zero; intros. subst. - exists (e#r1); split; auto. destruct (e#r1); simpl; auto. + exists (e#r1); split; auto. destruct (e#r1); cbn; auto. unfold Int64.shl'. rewrite Z.shiftl_0_r, Int64.repr_unsigned. auto. destruct (Int.ltu n Int64.iwordsize'). - econstructor; split. simpl. eauto. auto. - econstructor; split. simpl. eauto. rewrite H; auto. + econstructor; split. cbn. eauto. auto. + econstructor; split. cbn. eauto. rewrite H; auto. Qed. Lemma make_shrlimm_correct: @@ -403,11 +403,11 @@ Lemma make_shrlimm_correct: Proof. intros; unfold make_shrlimm. predSpec Int.eq Int.eq_spec n Int.zero; intros. subst. - exists (e#r1); split; auto. destruct (e#r1); simpl; auto. + exists (e#r1); split; auto. destruct (e#r1); cbn; auto. unfold Int64.shr'. rewrite Z.shiftr_0_r, Int64.repr_signed. auto. destruct (Int.ltu n Int64.iwordsize'). - econstructor; split. simpl. eauto. auto. - econstructor; split. simpl. eauto. rewrite H; auto. + econstructor; split. cbn. eauto. auto. + econstructor; split. cbn. eauto. rewrite H; auto. Qed. Lemma make_shrluimm_correct: @@ -418,11 +418,11 @@ Lemma make_shrluimm_correct: Proof. intros; unfold make_shrluimm. predSpec Int.eq Int.eq_spec n Int.zero; intros. subst. - exists (e#r1); split; auto. destruct (e#r1); simpl; auto. + exists (e#r1); split; auto. destruct (e#r1); cbn; auto. unfold Int64.shru'. rewrite Z.shiftr_0_r, Int64.repr_unsigned. auto. destruct (Int.ltu n Int64.iwordsize'). - econstructor; split. simpl. eauto. auto. - econstructor; split. simpl. eauto. rewrite H; auto. + econstructor; split. cbn. eauto. auto. + econstructor; split. cbn. eauto. rewrite H; auto. Qed. Lemma make_mullimm_correct: @@ -433,15 +433,15 @@ Lemma make_mullimm_correct: Proof. intros; unfold make_mullimm. predSpec Int64.eq Int64.eq_spec n Int64.zero; intros. subst. - exists (Vlong Int64.zero); split; auto. destruct (e#r1); simpl; auto. rewrite Int64.mul_zero; auto. + exists (Vlong Int64.zero); split; auto. destruct (e#r1); cbn; auto. rewrite Int64.mul_zero; auto. predSpec Int64.eq Int64.eq_spec n Int64.one; intros. subst. - exists (e#r1); split; auto. destruct (e#r1); simpl; auto. rewrite Int64.mul_one; auto. + exists (e#r1); split; auto. destruct (e#r1); cbn; auto. rewrite Int64.mul_one; auto. destruct (Int64.is_power2' n) eqn:?; intros. exists (Val.shll e#r1 (Vint i)); split; auto. - destruct (e#r1); simpl; auto. + destruct (e#r1); cbn; auto. erewrite Int64.is_power2'_range by eauto. erewrite Int64.mul_pow2' by eauto. auto. - econstructor; split; eauto. simpl; rewrite H; auto. + econstructor; split; eauto. cbn; rewrite H; auto. Qed. Lemma make_divlimm_correct: @@ -453,7 +453,7 @@ Lemma make_divlimm_correct: Proof. intros; unfold make_divlimm. destruct (Int64.is_power2' n) eqn:?. destruct (Int.ltu i (Int.repr 63)) eqn:?. - rewrite H0 in H. econstructor; split. simpl; eauto. + rewrite H0 in H. econstructor; split. cbn; eauto. erewrite Val.divls_pow2; eauto. auto. exists v; auto. exists v; auto. @@ -468,9 +468,9 @@ Lemma make_divluimm_correct: Proof. intros; unfold make_divluimm. destruct (Int64.is_power2' n) eqn:?. - econstructor; split. simpl; eauto. + econstructor; split. cbn; eauto. rewrite H0 in H. destruct (e#r1); inv H. destruct (Int64.eq n Int64.zero); inv H2. - simpl. + cbn. erewrite Int64.is_power2'_range by eauto. erewrite Int64.divu_pow2' by eauto. auto. exists v; auto. @@ -485,9 +485,9 @@ Lemma make_modluimm_correct: Proof. intros; unfold make_modluimm. destruct (Int64.is_power2 n) eqn:?. - exists v; split; auto. simpl. decEq. + exists v; split; auto. cbn. decEq. rewrite H0 in H. destruct (e#r1); inv H. destruct (Int64.eq n Int64.zero); inv H2. - simpl. erewrite Int64.modu_and by eauto. auto. + cbn. erewrite Int64.modu_and by eauto. auto. exists v; auto. Qed. @@ -498,9 +498,9 @@ Lemma make_andlimm_correct: Proof. intros; unfold make_andlimm. predSpec Int64.eq Int64.eq_spec n Int64.zero; intros. - subst n. exists (Vlong Int64.zero); split; auto. destruct (e#r); simpl; auto. rewrite Int64.and_zero; auto. + subst n. exists (Vlong Int64.zero); split; auto. destruct (e#r); cbn; auto. rewrite Int64.and_zero; auto. predSpec Int64.eq Int64.eq_spec n Int64.mone; intros. - subst n. exists (e#r); split; auto. destruct (e#r); simpl; auto. rewrite Int64.and_mone; auto. + subst n. exists (e#r); split; auto. destruct (e#r); cbn; auto. rewrite Int64.and_mone; auto. econstructor; split; eauto. auto. Qed. @@ -511,9 +511,9 @@ Lemma make_orlimm_correct: Proof. intros; unfold make_orlimm. predSpec Int64.eq Int64.eq_spec n Int64.zero; intros. - subst n. exists (e#r); split; auto. destruct (e#r); simpl; auto. rewrite Int64.or_zero; auto. + subst n. exists (e#r); split; auto. destruct (e#r); cbn; auto. rewrite Int64.or_zero; auto. predSpec Int64.eq Int64.eq_spec n Int64.mone; intros. - subst n. exists (Vlong Int64.mone); split; auto. destruct (e#r); simpl; auto. rewrite Int64.or_mone; auto. + subst n. exists (Vlong Int64.mone); split; auto. destruct (e#r); cbn; auto. rewrite Int64.or_mone; auto. econstructor; split; eauto. auto. Qed. @@ -524,7 +524,7 @@ Lemma make_xorlimm_correct: Proof. intros; unfold make_xorlimm. predSpec Int64.eq Int64.eq_spec n Int64.zero; intros. - subst n. exists (e#r); split; auto. destruct (e#r); simpl; auto. rewrite Int64.xor_zero; auto. + subst n. exists (e#r); split; auto. destruct (e#r); cbn; auto. rewrite Int64.xor_zero; auto. predSpec Int64.eq Int64.eq_spec n Int64.mone; intros. subst n. exists (Val.notl e#r); split; auto. econstructor; split; eauto. auto. @@ -538,9 +538,9 @@ Lemma make_mulfimm_correct: Proof. intros; unfold make_mulfimm. destruct (Float.eq_dec n (Float.of_int (Int.repr 2))); intros. - simpl. econstructor; split. eauto. rewrite H; subst n. - destruct (e#r1); simpl; auto. rewrite Float.mul2_add; auto. - simpl. econstructor; split; eauto. + cbn. econstructor; split. eauto. rewrite H; subst n. + destruct (e#r1); cbn; auto. rewrite Float.mul2_add; auto. + cbn. econstructor; split; eauto. Qed. Lemma make_mulfimm_correct_2: @@ -551,10 +551,10 @@ Lemma make_mulfimm_correct_2: Proof. intros; unfold make_mulfimm. destruct (Float.eq_dec n (Float.of_int (Int.repr 2))); intros. - simpl. econstructor; split. eauto. rewrite H; subst n. - destruct (e#r2); simpl; auto. rewrite Float.mul2_add; auto. + cbn. econstructor; split. eauto. rewrite H; subst n. + destruct (e#r2); cbn; auto. rewrite Float.mul2_add; auto. rewrite Float.mul_commut; auto. - simpl. econstructor; split; eauto. + cbn. econstructor; split; eauto. Qed. Lemma make_mulfsimm_correct: @@ -565,9 +565,9 @@ Lemma make_mulfsimm_correct: Proof. intros; unfold make_mulfsimm. destruct (Float32.eq_dec n (Float32.of_int (Int.repr 2))); intros. - simpl. econstructor; split. eauto. rewrite H; subst n. - destruct (e#r1); simpl; auto. rewrite Float32.mul2_add; auto. - simpl. econstructor; split; eauto. + cbn. econstructor; split. eauto. rewrite H; subst n. + destruct (e#r1); cbn; auto. rewrite Float32.mul2_add; auto. + cbn. econstructor; split; eauto. Qed. Lemma make_mulfsimm_correct_2: @@ -578,10 +578,10 @@ Lemma make_mulfsimm_correct_2: Proof. intros; unfold make_mulfsimm. destruct (Float32.eq_dec n (Float32.of_int (Int.repr 2))); intros. - simpl. econstructor; split. eauto. rewrite H; subst n. - destruct (e#r2); simpl; auto. rewrite Float32.mul2_add; auto. + cbn. econstructor; split. eauto. rewrite H; subst n. + destruct (e#r2); cbn; auto. rewrite Float32.mul2_add; auto. rewrite Float32.mul_commut; auto. - simpl. econstructor; split; eauto. + cbn. econstructor; split; eauto. Qed. Lemma make_cast8signed_correct: @@ -594,8 +594,8 @@ Proof. exists e#r; split; auto. assert (V: vmatch bc e#r (Sgn Ptop 8)). { eapply vmatch_ge; eauto. apply vincl_ge; auto. } - inv V; simpl; auto. rewrite is_sgn_sign_ext in H4 by auto. rewrite H4; auto. - econstructor; split; simpl; eauto. + inv V; cbn; auto. rewrite is_sgn_sign_ext in H4 by auto. rewrite H4; auto. + econstructor; split; cbn; eauto. Qed. Lemma make_cast16signed_correct: @@ -608,8 +608,8 @@ Proof. exists e#r; split; auto. assert (V: vmatch bc e#r (Sgn Ptop 16)). { eapply vmatch_ge; eauto. apply vincl_ge; auto. } - inv V; simpl; auto. rewrite is_sgn_sign_ext in H4 by auto. rewrite H4; auto. - econstructor; split; simpl; eauto. + inv V; cbn; auto. rewrite is_sgn_sign_ext in H4 by auto. rewrite H4; auto. + econstructor; split; cbn; eauto. Qed. Lemma op_strength_reduction_correct: @@ -620,7 +620,7 @@ Lemma op_strength_reduction_correct: exists w, eval_operation ge (Vptr sp Ptrofs.zero) op' e##args' m = Some w /\ Val.lessdef v w. Proof. intros until v; unfold op_strength_reduction; - case (op_strength_reduction_match op args vl); simpl; intros. + case (op_strength_reduction_match op args vl); cbn; intros. - (* cast8signed *) InvApproxRegs; SimplVM; inv H0. apply make_cast8signed_correct; auto. - (* cast16signed *) @@ -733,15 +733,15 @@ Lemma addr_strength_reduction_correct: exists res', eval_addressing ge (Vptr sp Ptrofs.zero) addr' e##args' = Some res' /\ Val.lessdef res res'. Proof. intros until res. unfold addr_strength_reduction. - destruct (addr_strength_reduction_match addr args vl); simpl; + destruct (addr_strength_reduction_match addr args vl); cbn; intros VL EA; InvApproxRegs; SimplVM; try (inv EA). - destruct (orb _ _). + exists (Val.offset_ptr e#r1 n); auto. -+ simpl. rewrite Genv.shift_symbol_address. econstructor; split; eauto. - inv H0; simpl; auto. ++ cbn. rewrite Genv.shift_symbol_address. econstructor; split; eauto. + inv H0; cbn; auto. - rewrite Ptrofs.add_zero_l. econstructor; split; eauto. change (Vptr sp (Ptrofs.add n1 n)) with (Val.offset_ptr (Vptr sp n1) n). - inv H0; simpl; auto. + inv H0; cbn; auto. - exists res; auto. Qed. diff --git a/kvx/Conventions1.v b/kvx/Conventions1.v index ab30ded9..0b2cf406 100644 --- a/kvx/Conventions1.v +++ b/kvx/Conventions1.v @@ -108,7 +108,7 @@ Lemma loc_result_type: subtype (proj_sig_res sig) (typ_rpair mreg_type (loc_result sig)) = true. Proof. intros. unfold proj_sig_res, loc_result, mreg_type. - destruct (sig_res sig); try destruct Archi.ptr64; simpl; trivial; destruct t; trivial. + destruct (sig_res sig); try destruct Archi.ptr64; cbn; trivial; destruct t; trivial. Qed. (** The result locations are caller-save registers *) @@ -118,7 +118,7 @@ Lemma loc_result_caller_save: forall_rpair (fun r => is_callee_save r = false) (loc_result s). Proof. intros. unfold loc_result, is_callee_save; - destruct (sig_res s); simpl; auto; try destruct Archi.ptr64; simpl; auto; try destruct t; simpl; auto. + destruct (sig_res s); cbn; auto; try destruct Archi.ptr64; cbn; auto; try destruct t; cbn; auto. Qed. (** If the result is in a pair of registers, those registers are distinct and have type [Tint] at least. *) @@ -296,9 +296,9 @@ Proof. OKREGS regs -> OKF f -> ofs >= 0 -> OK (one_arg regs rn ofs ty f)). { intros until f; intros OR OF OO; red; unfold one_arg; intros. destruct (list_nth_z regs rn) as [r|] eqn:NTH; destruct H. - - subst p; simpl. apply OR. eapply list_nth_z_in; eauto. + - subst p; cbn. apply OR. eapply list_nth_z_in; eauto. - eapply OF; eauto. - - subst p; simpl. auto using align_divides, typealign_pos. + - subst p; cbn. auto using align_divides, typealign_pos. - eapply OF; [idtac|eauto]. generalize (AL ofs ty OO) (SKK ty); omega. } @@ -310,16 +310,16 @@ Proof. assert (OO': ofs' >= 0) by (apply (AL ofs Tlong); auto). assert (DFL: OK (Twolong (S Outgoing (ofs' + 1) Tint) (S Outgoing ofs' Tint) :: f rn' (ofs' + 2))). - { red; simpl; intros. destruct H. - - subst p; simpl. + { red; cbn; intros. destruct H. + - subst p; cbn. repeat split; auto using Z.divide_1_l. omega. - eapply OF; [idtac|eauto]. omega. } destruct (list_nth_z regs rn') as [r1|] eqn:NTH1; destruct (list_nth_z regs (rn' + 1)) as [r2|] eqn:NTH2; try apply DFL. - red; simpl; intros; destruct H. - - subst p; simpl. split; apply OR; eauto using list_nth_z_in. + red; cbn; intros; destruct H. + - subst p; cbn. split; apply OR; eauto using list_nth_z_in. - eapply OF; [idtac|eauto]. auto. } assert (C: forall regs rn ofs ty f, @@ -327,10 +327,10 @@ Proof. { intros until f; intros OR OF OO OTY; unfold hybrid_arg; red; intros. set (rn' := align rn 2) in *. destruct (list_nth_z regs rn') as [r|] eqn:NTH; destruct H. - - subst p; simpl. apply OR. eapply list_nth_z_in; eauto. + - subst p; cbn. apply OR. eapply list_nth_z_in; eauto. - eapply OF; eauto. - - subst p; simpl. rewrite OTY. split. apply (AL ofs Tlong OO). apply Z.divide_1_l. - - eapply OF; [idtac|eauto]. generalize (AL ofs Tlong OO); simpl; omega. + - subst p; cbn. rewrite OTY. split. apply (AL ofs Tlong OO). apply Z.divide_1_l. + - eapply OF; [idtac|eauto]. generalize (AL ofs Tlong OO); cbn; omega. } assert (D: OKREGS param_regs). { red. decide_goal. } @@ -339,8 +339,8 @@ Proof. cut (forall va tyl rn ofs, ofs >= 0 -> OK (loc_arguments_rec va tyl rn ofs)). unfold OK. eauto. - induction tyl as [ | ty1 tyl]; intros until ofs; intros OO; simpl. - - red; simpl; tauto. + induction tyl as [ | ty1 tyl]; intros until ofs; intros OO; cbn. + - red; cbn; tauto. - destruct ty1. + (* int *) apply A; auto. + (* float *) @@ -369,10 +369,10 @@ Remark fold_max_outgoing_above: Proof. assert (A: forall n l, max_outgoing_1 n l >= n). { intros; unfold max_outgoing_1. destruct l as [_ | []]; xomega. } - induction l; simpl; intros. + induction l; cbn; intros. - omega. - eapply Zge_trans. eauto. - destruct a; simpl. apply A. eapply Zge_trans; eauto. + destruct a; cbn. apply A. eapply Zge_trans; eauto. Qed. Lemma size_arguments_above: @@ -392,14 +392,14 @@ Proof. assert (B: forall p n, In (S Outgoing ofs ty) (regs_of_rpair p) -> ofs + typesize ty <= max_outgoing_2 n p). - { intros. destruct p; simpl in H; intuition; subst; simpl. + { intros. destruct p; cbn in H; intuition; subst; cbn. - xomega. - eapply Z.le_trans. 2: apply A. xomega. - xomega. } assert (C: forall l n, In (S Outgoing ofs ty) (regs_of_rpairs l) -> ofs + typesize ty <= fold_left max_outgoing_2 l n). - { induction l; simpl; intros. + { induction l; cbn; intros. - contradiction. - rewrite in_app_iff in H. destruct H. + eapply Z.le_trans. eapply B; eauto. apply Z.ge_le. apply fold_max_outgoing_above. diff --git a/kvx/ExtValues.v b/kvx/ExtValues.v index 3664c00a..a0c10ddd 100644 --- a/kvx/ExtValues.v +++ b/kvx/ExtValues.v @@ -62,10 +62,10 @@ Lemma shift1_4_of_z_correct : end. Proof. intro. unfold shift1_4_of_z. - destruct (Z.eq_dec _ _); simpl; try congruence. - destruct (Z.eq_dec _ _); simpl; try congruence. - destruct (Z.eq_dec _ _); simpl; try congruence. - destruct (Z.eq_dec _ _); simpl; try congruence. + destruct (Z.eq_dec _ _); cbn; try congruence. + destruct (Z.eq_dec _ _); cbn; try congruence. + destruct (Z.eq_dec _ _); cbn; try congruence. + destruct (Z.eq_dec _ _); cbn; try congruence. trivial. Qed. @@ -215,19 +215,19 @@ Theorem divu_is_divlu: forall v1 v2 : val, end. Proof. intros. - destruct v1; simpl; trivial. - destruct v2; simpl; trivial. + destruct v1; cbn; trivial. + destruct v2; cbn; trivial. destruct i as [i_val i_range]. destruct i0 as [i0_val i0_range]. - simpl. + cbn. unfold Int.eq, Int64.eq, Int.zero, Int64.zero. - simpl. + cbn. rewrite Int.unsigned_repr by (compute; split; discriminate). rewrite (Int64.unsigned_repr 0) by (compute; split; discriminate). rewrite (unsigned64_repr i0_val) by assumption. - destruct (zeq i0_val 0) as [ | Hnot0]; simpl; trivial. + destruct (zeq i0_val 0) as [ | Hnot0]; cbn; trivial. f_equal. f_equal. - unfold Int.divu, Int64.divu. simpl. + unfold Int.divu, Int64.divu. cbn. rewrite (unsigned64_repr i_val) by assumption. rewrite (unsigned64_repr i0_val) by assumption. unfold Int64.loword. @@ -260,19 +260,19 @@ Theorem modu_is_modlu: forall v1 v2 : val, end. Proof. intros. - destruct v1; simpl; trivial. - destruct v2; simpl; trivial. + destruct v1; cbn; trivial. + destruct v2; cbn; trivial. destruct i as [i_val i_range]. destruct i0 as [i0_val i0_range]. - simpl. + cbn. unfold Int.eq, Int64.eq, Int.zero, Int64.zero. - simpl. + cbn. rewrite Int.unsigned_repr by (compute; split; discriminate). rewrite (Int64.unsigned_repr 0) by (compute; split; discriminate). rewrite (unsigned64_repr i0_val) by assumption. - destruct (zeq i0_val 0) as [ | Hnot0]; simpl; trivial. + destruct (zeq i0_val 0) as [ | Hnot0]; cbn; trivial. f_equal. f_equal. - unfold Int.modu, Int64.modu. simpl. + unfold Int.modu, Int64.modu. cbn. rewrite (unsigned64_repr i_val) by assumption. rewrite (unsigned64_repr i0_val) by assumption. unfold Int64.loword. @@ -347,19 +347,19 @@ Theorem divs_is_divls: forall v1 v2 : val, end. Proof. intros. - destruct v1; simpl; trivial. - destruct v2; simpl; trivial. + destruct v1; cbn; trivial. + destruct v2; cbn; trivial. destruct i as [i_val i_range]. destruct i0 as [i0_val i0_range]. - simpl. + cbn. unfold Int.eq, Int64.eq, Int.zero, Int64.zero. - simpl. + cbn. replace (Int.unsigned (Int.repr 0)) with 0 in * by reflexivity. - destruct (zeq _ _) as [H0' | Hnot0]; simpl; trivial. - destruct (zeq i_val (Int.unsigned (Int.repr Int.min_signed))) as [Hmin | Hnotmin]; simpl. + destruct (zeq _ _) as [H0' | Hnot0]; cbn; trivial. + destruct (zeq i_val (Int.unsigned (Int.repr Int.min_signed))) as [Hmin | Hnotmin]; cbn. { subst. destruct (zeq i0_val (Int.unsigned Int.mone)) as [Hmone | Hnotmone]; trivial. - unfold Int.signed. simpl. + unfold Int.signed. cbn. replace (Int64.unsigned (Int64.repr 0)) with 0 in * by reflexivity. rewrite if_zlt_min_signed_half_modulus. replace (if @@ -370,7 +370,7 @@ Proof. (Int64.unsigned (Int64.repr Int64.min_signed)) then true else false) with false by reflexivity. - simpl. + cbn. rewrite orb_false_r. destruct (zlt i0_val Int.half_modulus) as [Hlt_half | Hge_half]. { @@ -380,7 +380,7 @@ Proof. unfold Val.loword. f_equal. unfold Int64.divs, Int.divs, Int64.loword. - unfold Int.signed, Int64.signed. simpl. + unfold Int.signed, Int64.signed. cbn. rewrite if_zlt_min_signed_half_modulus. change Int.half_modulus with 2147483648 in *. destruct (zlt _ _) as [discard|]; try omega. clear discard. @@ -390,7 +390,7 @@ Proof. with 18446744071562067968. change Int64.half_modulus with 9223372036854775808. change Int64.modulus with 18446744073709551616. - simpl. + cbn. rewrite (Int64.unsigned_repr i0_val) by (change Int64.max_unsigned with 18446744073709551615; omega). destruct (zlt i0_val 9223372036854775808) as [discard |]; try omega. clear discard. @@ -449,7 +449,7 @@ Lemma big_unsigned_signed: Proof. destruct x as [xval xrange]. intro BIG. - unfold Int.signed, Int.unsigned in *. simpl in *. + unfold Int.signed, Int.unsigned in *. cbn in *. destruct (zlt _ _). omega. trivial. @@ -499,10 +499,10 @@ Lemma divs_is_quot: forall v1 v2 : val, end. Proof. - destruct v1; destruct v2; simpl; trivial. + destruct v1; destruct v2; cbn; trivial. unfold Int.divs. rewrite signed_0_eqb. - destruct (Int.eq i0 Int.zero) eqn:Eeq0; simpl; trivial. + destruct (Int.eq i0 Int.zero) eqn:Eeq0; cbn; trivial. destruct (Int.eq i (Int.repr Int.min_signed) && Int.eq i0 Int.mone) eqn:EXCEPTION. { replace (Int.signed i0) with (-1). replace (Int.signed i) with Int.min_signed. @@ -523,7 +523,7 @@ Proof. unfold Int.eq in EXCEPTION. destruct (zeq _ _) in EXCEPTION; try discriminate. destruct (zeq _ _) as [Hmone | ] in EXCEPTION; try discriminate. - destruct i0 as [i0val i0range]; unfold Int.signed in *; simpl in *. + destruct i0 as [i0val i0range]; unfold Int.signed in *; cbn in *. rewrite Hmone. reflexivity. } @@ -651,7 +651,7 @@ Qed. Lemma sub_add_neg : forall x y, Val.sub x y = Val.add x (Val.neg y). Proof. - destruct x; destruct y; simpl; trivial. + destruct x; destruct y; cbn; trivial. f_equal. apply Int.sub_add_opp. Qed. @@ -659,7 +659,7 @@ Qed. Lemma neg_mul_distr_r : forall x y, Val.neg (Val.mul x y) = Val.mul x (Val.neg y). Proof. - destruct x; destruct y; simpl; trivial. + destruct x; destruct y; cbn; trivial. f_equal. apply Int.neg_mul_distr_r. Qed. @@ -668,7 +668,7 @@ Qed. Lemma sub_addl_negl : forall x y, Val.subl x y = Val.addl x (Val.negl y). Proof. - destruct x; destruct y; simpl; trivial. + destruct x; destruct y; cbn; trivial. + f_equal. apply Int64.sub_add_opp. + destruct (Archi.ptr64) eqn:ARCHI64; trivial. f_equal. rewrite Ptrofs.sub_add_opp. @@ -681,15 +681,15 @@ Proof. rewrite Hagree2. reflexivity. exact (Ptrofs.agree64_of_int ARCHI64 i0). - + destruct (Archi.ptr64) eqn:ARCHI64; simpl; trivial. - destruct (eq_block _ _); simpl; trivial. + + destruct (Archi.ptr64) eqn:ARCHI64; cbn; trivial. + destruct (eq_block _ _); cbn; trivial. Qed. *) Lemma negl_mull_distr_r : forall x y, Val.negl (Val.mull x y) = Val.mull x (Val.negl y). Proof. - destruct x; destruct y; simpl; trivial. + destruct x; destruct y; cbn; trivial. f_equal. apply Int64.neg_mul_distr_r. Qed. diff --git a/kvx/NeedOp.v b/kvx/NeedOp.v index 4c354d5a..f636336d 100644 --- a/kvx/NeedOp.v +++ b/kvx/NeedOp.v @@ -229,7 +229,7 @@ Lemma needs_of_condition0_sound: Proof. intros until arg2. intros Hcond Hagree. - apply eval_condition0_inj with (f := inject_id) (m1 := m1) (v1 := arg1); simpl; auto. + apply eval_condition0_inj with (f := inject_id) (m1 := m1) (v1 := arg1); cbn; auto. apply val_inject_lessdef. apply lessdef_vagree. assumption. Qed. @@ -239,7 +239,7 @@ Lemma addl_sound: vagree (Val.addl v1 v2) (Val.addl w1 w2) x. Proof. unfold default; intros. - destruct x; simpl in *; trivial. + destruct x; cbn in *; trivial. - unfold Val.addl. destruct v1; destruct v2; trivial; destruct Archi.ptr64; trivial. - apply Val.addl_lessdef; trivial. @@ -249,7 +249,7 @@ Lemma subl_lessdef: forall v1 v1' v2 v2', Val.lessdef v1 v1' -> Val.lessdef v2 v2' -> Val.lessdef (Val.subl v1 v2) (Val.subl v1' v2'). Proof. - intros. inv H. inv H0. auto. destruct v1'; simpl; auto. simpl; auto. + intros. inv H. inv H0. auto. destruct v1'; cbn; auto. cbn; auto. Qed. Lemma subl_sound: @@ -258,10 +258,10 @@ Lemma subl_sound: vagree (Val.subl v1 v2) (Val.subl w1 w2) x. Proof. unfold default; intros. - destruct x; simpl in *; trivial. + destruct x; cbn in *; trivial. - unfold Val.subl. - destruct v1; destruct v2; trivial; destruct Archi.ptr64; simpl; trivial. - destruct (eq_block _ _) ; simpl; trivial. + destruct v1; destruct v2; trivial; destruct Archi.ptr64; cbn; trivial. + destruct (eq_block _ _) ; cbn; trivial. - apply subl_lessdef; trivial. Qed. @@ -272,7 +272,7 @@ Lemma mull_sound: vagree (Val.mull v1 v2) (Val.mull w1 w2) x. Proof. unfold default; intros. - destruct x; simpl in *; trivial. + destruct x; cbn in *; trivial. - unfold Val.mull. destruct v1; destruct v2; trivial. - unfold Val.mull. @@ -284,7 +284,7 @@ Qed. Remark default_idem: forall nv, default (default nv) = default nv. Proof. - destruct nv; simpl; trivial. + destruct nv; cbn; trivial. Qed. Lemma vagree_triple_op_float : @@ -298,14 +298,14 @@ Proof. induction nv; intros Hax Hby Hcz. - trivial. - - simpl in *. destruct a; simpl; trivial. - destruct b; simpl; trivial. - destruct c; simpl; trivial. - - simpl in *. destruct a; simpl; trivial. - destruct b; simpl; trivial. - destruct c; simpl; trivial. + - cbn in *. destruct a; cbn; trivial. + destruct b; cbn; trivial. + destruct c; cbn; trivial. + - cbn in *. destruct a; cbn; trivial. + destruct b; cbn; trivial. + destruct c; cbn; trivial. inv Hax. inv Hby. inv Hcz. - simpl. + cbn. constructor. Qed. @@ -320,14 +320,14 @@ Proof. induction nv; intros Hax Hby Hcz. - trivial. - - simpl in *. destruct a; simpl; trivial. - destruct b; simpl; trivial. - destruct c; simpl; trivial. - - simpl in *. destruct a; simpl; trivial. - destruct b; simpl; trivial. - destruct c; simpl; trivial. + - cbn in *. destruct a; cbn; trivial. + destruct b; cbn; trivial. + destruct c; cbn; trivial. + - cbn in *. destruct a; cbn; trivial. + destruct b; cbn; trivial. + destruct c; cbn; trivial. inv Hax. inv Hby. inv Hcz. - simpl. + cbn. constructor. Qed. @@ -343,7 +343,7 @@ Lemma needs_of_operation_sound: /\ vagree v v' nv. Proof. unfold needs_of_operation; intros; destruct op; try (eapply default_needs_of_operation_sound; eauto; fail); - simpl in *; FuncInv; InvAgree; TrivialExists. + cbn in *; FuncInv; InvAgree; TrivialExists. - apply sign_ext_sound; auto. compute; auto. - apply sign_ext_sound; auto. compute; auto. - apply add_sound; auto. @@ -384,17 +384,17 @@ Proof. - destruct (eval_condition0 _ _ _) as [b|] eqn:EC. erewrite needs_of_condition0_sound by eauto. apply select_sound; auto. - simpl; auto with na. + cbn; auto with na. (* select imm *) - destruct (eval_condition0 _ _ _) as [b|] eqn:EC. { erewrite needs_of_condition0_sound by eauto. apply select_sound; auto with na. } - simpl; auto with na. + cbn; auto with na. (* select long imm *) - destruct (eval_condition0 _ _ _) as [b|] eqn:EC. { erewrite needs_of_condition0_sound by eauto. apply select_sound; auto with na. } - simpl; auto with na. + cbn; auto with na. Qed. Lemma operation_is_redundant_sound: @@ -404,7 +404,7 @@ Lemma operation_is_redundant_sound: vagree_list (arg1 :: args) (arg1' :: args') (needs_of_operation op nv) -> vagree v arg1' nv. Proof. - intros. destruct op; simpl in *; try discriminate; inv H1; FuncInv; subst. + intros. destruct op; cbn in *; try discriminate; inv H1; FuncInv; subst. - apply sign_ext_redundant_sound; auto. omega. - apply sign_ext_redundant_sound; auto. omega. - apply andimm_redundant_sound; auto. @@ -508,9 +508,9 @@ Qed. Ltac FuncInv := match goal with | H: (match ?x with nil => _ | _ :: _ => _ end = Some _) |- _ => - destruct x; simpl in H; FuncInv + destruct x; cbn in H; FuncInv | H: (match ?v with Vundef => _ | Vint _ => _ | Vfloat _ => _ | Vptr _ _ => _ end = Some _) |- _ => - destruct v; simpl in H; FuncInv + destruct v; cbn in H; FuncInv | H: (if Archi.ptr64 then _ else _) = Some _ |- _ => destruct Archi.ptr64 eqn:?; FuncInv | H: (Some _ = Some _) |- _ => @@ -727,27 +727,27 @@ Qed. Remark type_sub: forall v1 v2, Val.has_type (Val.sub v1 v2) Tint. Proof. - intros. unfold Val.has_type, Val.sub. destruct Archi.ptr64, v1, v2; simpl; auto. + intros. unfold Val.has_type, Val.sub. destruct Archi.ptr64, v1, v2; cbn; auto. destruct (eq_block _ _); auto. Qed. Remark type_subl: forall v1 v2, Val.has_type (Val.subl v1 v2) Tlong. Proof. - intros. unfold Val.has_type, Val.subl. destruct Archi.ptr64, v1, v2; simpl; auto. + intros. unfold Val.has_type, Val.subl. destruct Archi.ptr64, v1, v2; cbn; auto. destruct (eq_block _ _); auto. Qed. Remark type_shl: forall v1 v2, Val.has_type (Val.shl v1 v2) Tint. Proof. - destruct v1, v2; simpl; trivial; destruct (Int.ltu _ _); simpl; trivial. + destruct v1, v2; cbn; trivial; destruct (Int.ltu _ _); cbn; trivial. Qed. Remark type_shll: forall v1 v2, Val.has_type (Val.shll v1 v2) Tlong. Proof. - destruct v1, v2; simpl; trivial; destruct (Int.ltu _ _); simpl; trivial. + destruct v1, v2; cbn; trivial; destruct (Int.ltu _ _); cbn; trivial. Qed. Lemma type_of_operation_sound: @@ -757,7 +757,7 @@ Lemma type_of_operation_sound: Val.has_type v (snd (type_of_operation op)). Proof with (try exact I; try reflexivity; auto using Val.Vptr_has_type). intros. - destruct op; simpl; simpl in H0; FuncInv; subst; simpl. + destruct op; cbn; cbn in H0; FuncInv; subst; cbn. (* move *) - congruence. (* intconst, longconst, floatconst, singleconst *) @@ -777,30 +777,30 @@ Proof with (try exact I; try reflexivity; auto using Val.Vptr_has_type). - apply type_add. (* addx, addximm *) - apply type_add. - - destruct v0; simpl; trivial. - destruct (Int.ltu _ _); simpl; trivial. + - destruct v0; cbn; trivial. + destruct (Int.ltu _ _); cbn; trivial. (* neg, sub *) - destruct v0... - apply type_sub. (* revsubimm, revsubx, revsubximm *) - destruct v0... - apply type_sub. - - destruct v0; simpl; trivial. - destruct (Int.ltu _ _); simpl; trivial. + - destruct v0; cbn; trivial. + destruct (Int.ltu _ _); cbn; trivial. (* mul, mulimm, mulhs, mulhu *) - destruct v0; destruct v1... - destruct v0... - destruct v0; destruct v1... - destruct v0; destruct v1... (* div, divu *) - - destruct v0; destruct v1; simpl in *; inv H0. - destruct (Int.eq i0 Int.zero || Int.eq i (Int.repr Int.min_signed) && Int.eq i0 Int.mone); inv H2... - - destruct v0; destruct v1; simpl in *; inv H0. + - destruct v0; destruct v1; cbn in *; inv H0. + destruct (_ || _); inv H2... + - destruct v0; destruct v1; cbn in *; inv H0. destruct (Int.eq i0 Int.zero); inv H2... (* mod, modu *) - - destruct v0; destruct v1; simpl in *; inv H0. - destruct (Int.eq i0 Int.zero || Int.eq i (Int.repr Int.min_signed) && Int.eq i0 Int.mone); inv H2... - - destruct v0; destruct v1; simpl in *; inv H0. + - destruct v0; destruct v1; cbn in *; inv H0. + destruct (_ || _); inv H2... + - destruct v0; destruct v1; cbn in *; inv H0. destruct (Int.eq i0 Int.zero); inv H2... (* and, andimm *) - destruct v0; destruct v1... @@ -829,18 +829,18 @@ Proof with (try exact I; try reflexivity; auto using Val.Vptr_has_type). - destruct v0; destruct v1... - destruct v0... (* shl, shlimm *) - - destruct v0; destruct v1; simpl... destruct (Int.ltu i0 Int.iwordsize)... - - destruct v0; simpl... destruct (Int.ltu n Int.iwordsize)... + - destruct v0; destruct v1; cbn... destruct (Int.ltu i0 Int.iwordsize)... + - destruct v0; cbn... destruct (Int.ltu n Int.iwordsize)... (* shr, shrimm *) - - destruct v0; destruct v1; simpl... destruct (Int.ltu i0 Int.iwordsize)... - - destruct v0; simpl... destruct (Int.ltu n Int.iwordsize)... + - destruct v0; destruct v1; cbn... destruct (Int.ltu i0 Int.iwordsize)... + - destruct v0; cbn... destruct (Int.ltu n Int.iwordsize)... (* shru, shruimm *) - - destruct v0; destruct v1; simpl... destruct (Int.ltu i0 Int.iwordsize)... - - destruct v0; simpl... destruct (Int.ltu n Int.iwordsize)... + - destruct v0; destruct v1; cbn... destruct (Int.ltu i0 Int.iwordsize)... + - destruct v0; cbn... destruct (Int.ltu n Int.iwordsize)... (* shrx *) - - destruct v0; simpl... destruct (Int.ltu n (Int.repr 31)); simpl; trivial. + - destruct v0; cbn... destruct (Int.ltu n (Int.repr 31)); cbn; trivial. (* shrimm *) - - destruct v0; simpl... + - destruct v0; cbn... (* madd *) - apply type_add. - apply type_add. @@ -858,13 +858,13 @@ Proof with (try exact I; try reflexivity; auto using Val.Vptr_has_type). - apply type_addl. (* addxl addxlimm *) - apply type_addl. - - destruct v0; simpl; trivial. - destruct (Int.ltu _ _); simpl; trivial. + - destruct v0; cbn; trivial. + destruct (Int.ltu _ _); cbn; trivial. (* negl, subl *) - destruct v0... - apply type_subl. - - destruct v0; simpl; trivial. - destruct (Int.ltu _ _); simpl; trivial. + - destruct v0; cbn; trivial. + destruct (Int.ltu _ _); cbn; trivial. - destruct v0... - apply type_subl. (* mull, mullhs, mullhu *) @@ -873,14 +873,14 @@ Proof with (try exact I; try reflexivity; auto using Val.Vptr_has_type). - destruct v0; destruct v1... - destruct v0; destruct v1... (* divl, divlu *) - - destruct v0; destruct v1; simpl in *; inv H0. - destruct (Int64.eq i0 Int64.zero || Int64.eq i (Int64.repr Int64.min_signed) && Int64.eq i0 Int64.mone); inv H2... - - destruct v0; destruct v1; simpl in *; inv H0. + - destruct v0; destruct v1; cbn in *; inv H0. + destruct (_ || _); inv H2... + - destruct v0; destruct v1; cbn in *; inv H0. destruct (Int64.eq i0 Int64.zero); inv H2... (* modl, modlu *) - - destruct v0; destruct v1; simpl in *; inv H0. - destruct (Int64.eq i0 Int64.zero || Int64.eq i (Int64.repr Int64.min_signed) && Int64.eq i0 Int64.mone); inv H2... - - destruct v0; destruct v1; simpl in *; inv H0. + - destruct v0; destruct v1; cbn in *; inv H0. + destruct (_ || _); inv H2... + - destruct v0; destruct v1; cbn in *; inv H0. destruct (Int64.eq i0 Int64.zero); inv H2... (* andl, andlimm *) - destruct v0; destruct v1... @@ -909,16 +909,16 @@ Proof with (try exact I; try reflexivity; auto using Val.Vptr_has_type). - destruct v0; destruct v1... - destruct v0... (* shll, shllimm *) - - destruct v0; destruct v1; simpl... destruct (Int.ltu i0 Int64.iwordsize')... - - destruct v0; simpl... destruct (Int.ltu n Int64.iwordsize')... + - destruct v0; destruct v1; cbn... destruct (Int.ltu i0 Int64.iwordsize')... + - destruct v0; cbn... destruct (Int.ltu n Int64.iwordsize')... (* shr, shrimm *) - - destruct v0; destruct v1; simpl... destruct (Int.ltu i0 Int64.iwordsize')... - - destruct v0; simpl... destruct (Int.ltu n Int64.iwordsize')... + - destruct v0; destruct v1; cbn... destruct (Int.ltu i0 Int64.iwordsize')... + - destruct v0; cbn... destruct (Int.ltu n Int64.iwordsize')... (* shru, shruimm *) - - destruct v0; destruct v1; simpl... destruct (Int.ltu i0 Int64.iwordsize')... - - destruct v0; simpl... destruct (Int.ltu n Int64.iwordsize')... + - destruct v0; destruct v1; cbn... destruct (Int.ltu i0 Int64.iwordsize')... + - destruct v0; cbn... destruct (Int.ltu n Int64.iwordsize')... (* shrxl *) - - destruct v0; simpl... destruct (Int.ltu n (Int.repr 63)); simpl; trivial. + - destruct v0; cbn... destruct (Int.ltu n (Int.repr 63)); cbn; trivial. (* maddl, maddlim *) - apply type_addl. - apply type_addl. @@ -960,59 +960,59 @@ Proof with (try exact I; try reflexivity; auto using Val.Vptr_has_type). - destruct v0... - destruct v0... (* intoffloat, intuoffloat *) - - destruct v0; simpl... destruct (Float.to_int f); simpl; trivial. - - destruct v0; simpl... destruct (Float.to_intu f); simpl; trivial. + - destruct v0; cbn... destruct (Float.to_int f); cbn; trivial. + - destruct v0; cbn... destruct (Float.to_intu f); cbn; trivial. (* intofsingle, intuofsingle *) - - destruct v0; simpl... destruct (Float32.to_int f); simpl; trivial. - - destruct v0; simpl... destruct (Float32.to_intu f); simpl; trivial. + - destruct v0; cbn... destruct (Float32.to_int f); cbn; trivial. + - destruct v0; cbn... destruct (Float32.to_intu f); cbn; trivial. (* singleofint, singleofintu *) - - destruct v0; simpl... - - destruct v0; simpl... + - destruct v0; cbn... + - destruct v0; cbn... (* longoffloat, longuoffloat *) - - destruct v0; simpl... destruct (Float.to_long f); simpl; trivial. - - destruct v0; simpl... destruct (Float.to_longu f); simpl; trivial. + - destruct v0; cbn... destruct (Float.to_long f); cbn; trivial. + - destruct v0; cbn... destruct (Float.to_longu f); cbn; trivial. (* floatoflong, floatoflongu *) - - destruct v0; simpl... - - destruct v0; simpl... + - destruct v0; cbn... + - destruct v0; cbn... (* longofsingle, longuofsingle *) - - destruct v0; simpl... destruct (Float32.to_long f); simpl; trivial. - - destruct v0; simpl... destruct (Float32.to_longu f); simpl; trivial. + - destruct v0; cbn... destruct (Float32.to_long f); cbn; trivial. + - destruct v0; cbn... destruct (Float32.to_longu f); cbn; trivial. (* singleoflong, singleoflongu *) - - destruct v0; simpl... - - destruct v0; simpl... + - destruct v0; cbn... + - destruct v0; cbn... (* cmp *) - destruct (eval_condition cond vl m)... destruct b... (* extfz *) - unfold extfz. destruct (is_bitfield _ _). - + destruct v0; simpl; trivial. + + destruct v0; cbn; trivial. + constructor. (* extfs *) - unfold extfs. destruct (is_bitfield _ _). - + destruct v0; simpl; trivial. + + destruct v0; cbn; trivial. + constructor. (* extfzl *) - unfold extfzl. destruct (is_bitfieldl _ _). - + destruct v0; simpl; trivial. + + destruct v0; cbn; trivial. + constructor. (* extfsl *) - unfold extfsl. destruct (is_bitfieldl _ _). - + destruct v0; simpl; trivial. + + destruct v0; cbn; trivial. + constructor. (* insf *) - unfold insf, bitfield_mask. destruct (is_bitfield _ _). - + destruct v0; destruct v1; simpl; trivial. - destruct (Int.ltu _ _); simpl; trivial. + + destruct v0; destruct v1; cbn; trivial. + destruct (Int.ltu _ _); cbn; trivial. + constructor. (* insf *) - unfold insfl, bitfield_mask. destruct (is_bitfieldl _ _). - + destruct v0; destruct v1; simpl; trivial. - destruct (Int.ltu _ _); simpl; trivial. + + destruct v0; destruct v1; cbn; trivial. + destruct (Int.ltu _ _); cbn; trivial. + constructor. (* Osel *) - unfold Val.select. destruct (eval_condition0 _ _ m). @@ -1047,7 +1047,7 @@ Lemma is_trapping_op_sound: eval_operation genv sp op vl m <> None. Proof. unfold args_of_operation. - destruct op; destruct eq_operation; intros; simpl in *; try congruence. + destruct op; destruct eq_operation; intros; cbn in *; try congruence. all: try (destruct vl as [ | vh1 vl1]; try discriminate). all: try (destruct vl1 as [ | vh2 vl2]; try discriminate). all: try (destruct vl2 as [ | vh3 vl3]; try discriminate). @@ -1101,7 +1101,7 @@ Lemma eval_negate_condition: forall cond vl m, eval_condition (negate_condition cond) vl m = option_map negb (eval_condition cond vl m). Proof. - intros. destruct cond; simpl. + intros. destruct cond; cbn. repeat (destruct vl; auto). apply Val.negate_cmp_bool. repeat (destruct vl; auto). apply Val.negate_cmpu_bool. repeat (destruct vl; auto). apply Val.negate_cmp_bool. @@ -1147,7 +1147,7 @@ Lemma eval_shift_stack_addressing: eval_addressing ge (Vptr sp Ptrofs.zero) (shift_stack_addressing delta addr) vl = eval_addressing ge (Vptr sp (Ptrofs.repr delta)) addr vl. Proof. - intros. destruct addr; simpl; auto. destruct vl; auto. + intros. destruct addr; cbn; auto. destruct vl; auto. rewrite Ptrofs.add_zero_l, Ptrofs.add_commut; auto. Qed. @@ -1156,7 +1156,7 @@ Lemma eval_shift_stack_operation: eval_operation ge (Vptr sp Ptrofs.zero) (shift_stack_operation delta op) vl m = eval_operation ge (Vptr sp (Ptrofs.repr delta)) op vl m. Proof. - intros. destruct op; simpl; auto. destruct vl; auto. + intros. destruct op; cbn; auto. destruct vl; auto. rewrite Ptrofs.add_zero_l, Ptrofs.add_commut; auto. Qed. @@ -1183,12 +1183,12 @@ Proof. assert (A: forall x n, Val.offset_ptr x (Ptrofs.add n (Ptrofs.repr delta)) = Val.add (Val.offset_ptr x n) (Vint (Int.repr delta))). - { intros; destruct x; simpl; auto. rewrite H1. + { intros; destruct x; cbn; auto. rewrite H1. rewrite Ptrofs.add_assoc. f_equal; f_equal; f_equal. symmetry; auto with ptrofs. } - destruct addr; simpl in H; inv H; simpl in *; FuncInv; subst. + destruct addr; cbn in H; inv H; cbn in *; FuncInv; subst. - rewrite A; auto. - unfold Genv.symbol_address. destruct (Genv.find_symbol ge i); auto. - simpl. rewrite H1. f_equal; f_equal; f_equal. symmetry; auto with ptrofs. + cbn. rewrite H1. f_equal; f_equal; f_equal. symmetry; auto with ptrofs. - rewrite A; auto. Qed. @@ -1223,17 +1223,17 @@ Lemma op_depends_on_memory_correct: op_depends_on_memory op = false -> eval_operation ge sp op args m1 = eval_operation ge sp op args m2. Proof. - intros until m2. destruct op; simpl; try congruence. - - destruct cond; simpl; try congruence; + intros until m2. destruct op; cbn; try congruence. + - destruct cond; cbn; try congruence; intros SF; auto; rewrite ? negb_false_iff in SF; unfold Val.cmpu_bool, Val.cmplu_bool; rewrite SF; reflexivity. - - destruct c0; simpl; try congruence; + - destruct c0; cbn; try congruence; intros SF; auto; rewrite ? negb_false_iff in SF; unfold Val.cmpu_bool, Val.cmplu_bool; rewrite SF; reflexivity. - - destruct c0; simpl; try congruence; + - destruct c0; cbn; try congruence; intros SF; auto; rewrite ? negb_false_iff in SF; unfold Val.cmpu_bool, Val.cmplu_bool; rewrite SF; reflexivity. - - destruct c0; simpl; try congruence; + - destruct c0; cbn; try congruence; intros SF; auto; rewrite ? negb_false_iff in SF; unfold Val.cmpu_bool, Val.cmplu_bool; rewrite SF; reflexivity. Qed. @@ -1387,19 +1387,19 @@ Lemma eval_condition_inj: eval_condition cond vl1 m1 = Some b -> eval_condition cond vl2 m2 = Some b. Proof. - intros. destruct cond; simpl in H0; FuncInv; InvInject; simpl; auto. -- inv H3; inv H2; simpl in H0; inv H0; auto. + intros. destruct cond; cbn in H0; FuncInv; InvInject; cbn; auto. +- inv H3; inv H2; cbn in H0; inv H0; auto. - eauto 3 using Val.cmpu_bool_inject, Mem.valid_pointer_implies. -- inv H3; simpl in H0; inv H0; auto. +- inv H3; cbn in H0; inv H0; auto. - eauto 3 using Val.cmpu_bool_inject, Mem.valid_pointer_implies. -- inv H3; inv H2; simpl in H0; inv H0; auto. +- inv H3; inv H2; cbn in H0; inv H0; auto. - eauto 3 using Val.cmplu_bool_inject, Mem.valid_pointer_implies. -- inv H3; simpl in H0; inv H0; auto. +- inv H3; cbn in H0; inv H0; auto. - eauto 3 using Val.cmplu_bool_inject, Mem.valid_pointer_implies. -- inv H3; inv H2; simpl in H0; inv H0; auto. -- inv H3; inv H2; simpl in H0; inv H0; auto. -- inv H3; inv H2; simpl in H0; inv H0; auto. -- inv H3; inv H2; simpl in H0; inv H0; auto. +- inv H3; inv H2; cbn in H0; inv H0; auto. +- inv H3; inv H2; cbn in H0; inv H0; auto. +- inv H3; inv H2; cbn in H0; inv H0; auto. +- inv H3; inv H2; cbn in H0; inv H0; auto. Qed. Lemma eval_condition0_inj: @@ -1408,10 +1408,10 @@ Lemma eval_condition0_inj: eval_condition0 cond v1 m1 = Some b -> eval_condition0 cond v2 m2 = Some b. Proof. - intros. destruct cond; simpl in H0; FuncInv; InvInject; simpl; auto. - - inv H; simpl in *; congruence. + intros. destruct cond; cbn in H0; FuncInv; InvInject; cbn; auto. + - inv H; cbn in *; congruence. - eauto 3 using Val.cmpu_bool_inject, Mem.valid_pointer_implies. - - inv H; simpl in *; congruence. + - inv H; cbn in *; congruence. - eauto 3 using Val.cmplu_bool_inject, Mem.valid_pointer_implies. Qed. @@ -1432,248 +1432,244 @@ Lemma eval_operation_inj: eval_operation ge1 sp1 op vl1 m1 = Some v1 -> exists v2, eval_operation ge2 sp2 op vl2 m2 = Some v2 /\ Val.inject f v1 v2. Proof. - intros until v1; intros GL; intros. destruct op; simpl in H1; simpl; FuncInv; InvInject; TrivialExists. + intros until v1; intros GL; intros. destruct op; cbn in H1; cbn; FuncInv; InvInject; TrivialExists. (* addrsymbol *) - - apply GL; simpl; auto. + - apply GL; cbn; auto. (* addrstack *) - apply Val.offset_ptr_inject; auto. (* castsigned *) - - inv H4; simpl; auto. - - inv H4; simpl; auto. + - inv H4; cbn; auto. + - inv H4; cbn; auto. (* add, addimm *) - apply Val.add_inject; auto. - apply Val.add_inject; auto. (* addx, addximm *) - apply Val.add_inject; trivial. - inv H4; inv H2; simpl; try destruct (Int.ltu _ _); simpl; auto. - - inv H4; simpl; trivial. - destruct (Int.ltu _ _); simpl; trivial. + inv H4; inv H2; cbn; try destruct (Int.ltu _ _); cbn; auto. + - inv H4; cbn; trivial. + destruct (Int.ltu _ _); cbn; trivial. (* neg, sub *) - - inv H4; simpl; auto. + - inv H4; cbn; auto. - apply Val.sub_inject; auto. (* revsubimm, revsubx, revsubximm *) - - inv H4; simpl; trivial. + - inv H4; cbn; trivial. - apply Val.sub_inject; trivial. - inv H4; inv H2; simpl; try destruct (Int.ltu _ _); simpl; auto. - - inv H4; simpl; try destruct (Int.ltu _ _); simpl; auto. + inv H4; inv H2; cbn; try destruct (Int.ltu _ _); cbn; auto. + - inv H4; cbn; try destruct (Int.ltu _ _); cbn; auto. (* mul, mulimm, mulhs, mulhu *) - - inv H4; inv H2; simpl; auto. - - inv H4; simpl; auto. - - inv H4; inv H2; simpl; auto. - - inv H4; inv H2; simpl; auto. + - inv H4; inv H2; cbn; auto. + - inv H4; cbn; auto. + - inv H4; inv H2; cbn; auto. + - inv H4; inv H2; cbn; auto. (* div, divu *) - - inv H4; inv H3; simpl in H1; inv H1. simpl. - destruct (Int.eq i0 Int.zero - || Int.eq i (Int.repr Int.min_signed) && Int.eq i0 Int.mone); inv H2. + - inv H4; inv H3; cbn in H1; inv H1. cbn. + destruct (_ || _); inv H2. TrivialExists. - - inv H4; inv H3; simpl in H1; inv H1. simpl. + - inv H4; inv H3; cbn in H1; inv H1. cbn. destruct (Int.eq i0 Int.zero); inv H2. TrivialExists. (* mod, modu *) - - inv H4; inv H3; simpl in H1; inv H1. simpl. - destruct (Int.eq i0 Int.zero - || Int.eq i (Int.repr Int.min_signed) && Int.eq i0 Int.mone); inv H2. + - inv H4; inv H3; cbn in H1; inv H1. cbn. + destruct (_ || _); inv H2. TrivialExists. - - inv H4; inv H3; simpl in H1; inv H1. simpl. + - inv H4; inv H3; cbn in H1; inv H1. cbn. destruct (Int.eq i0 Int.zero); inv H2. TrivialExists. (* and, andimm *) - - inv H4; inv H2; simpl; auto. - - inv H4; simpl; auto. + - inv H4; inv H2; cbn; auto. + - inv H4; cbn; auto. (* nand, nandimm *) - - inv H4; inv H2; simpl; auto. - - inv H4; simpl; auto. + - inv H4; inv H2; cbn; auto. + - inv H4; cbn; auto. (* or, orimm *) - - inv H4; inv H2; simpl; auto. - - inv H4; simpl; auto. + - inv H4; inv H2; cbn; auto. + - inv H4; cbn; auto. (* nor, norimm *) - - inv H4; inv H2; simpl; auto. - - inv H4; simpl; auto. + - inv H4; inv H2; cbn; auto. + - inv H4; cbn; auto. (* xor, xorimm *) - - inv H4; inv H2; simpl; auto. - - inv H4; simpl; auto. + - inv H4; inv H2; cbn; auto. + - inv H4; cbn; auto. (* nxor, nxorimm *) - - inv H4; inv H2; simpl; auto. - - inv H4; simpl; auto. + - inv H4; inv H2; cbn; auto. + - inv H4; cbn; auto. (* not *) - - inv H4; simpl; auto. + - inv H4; cbn; auto. (* andn, andnimm *) - - inv H4; inv H2; simpl; auto. - - inv H4; simpl; auto. + - inv H4; inv H2; cbn; auto. + - inv H4; cbn; auto. (* orn, ornimm *) - - inv H4; inv H2; simpl; auto. - - inv H4; simpl; auto. + - inv H4; inv H2; cbn; auto. + - inv H4; cbn; auto. (* shl, shlimm *) - - inv H4; inv H2; simpl; auto. destruct (Int.ltu i0 Int.iwordsize); auto. - - inv H4; simpl; auto. destruct (Int.ltu n Int.iwordsize); auto. + - inv H4; inv H2; cbn; auto. destruct (Int.ltu i0 Int.iwordsize); auto. + - inv H4; cbn; auto. destruct (Int.ltu n Int.iwordsize); auto. (* shr, shrimm *) - - inv H4; inv H2; simpl; auto. destruct (Int.ltu i0 Int.iwordsize); auto. - - inv H4; simpl; auto. destruct (Int.ltu n Int.iwordsize); auto. + - inv H4; inv H2; cbn; auto. destruct (Int.ltu i0 Int.iwordsize); auto. + - inv H4; cbn; auto. destruct (Int.ltu n Int.iwordsize); auto. (* shru, shruimm *) - - inv H4; inv H2; simpl; auto. destruct (Int.ltu i0 Int.iwordsize); auto. - - inv H4; simpl; auto. destruct (Int.ltu n Int.iwordsize); auto. + - inv H4; inv H2; cbn; auto. destruct (Int.ltu i0 Int.iwordsize); auto. + - inv H4; cbn; auto. destruct (Int.ltu n Int.iwordsize); auto. (* shrx *) - - inv H4; simpl; auto. - destruct (Int.ltu n (Int.repr 31)); inv H; simpl; auto. + - inv H4; cbn; auto. + destruct (Int.ltu n (Int.repr 31)); inv H; cbn; auto. (* rorimm *) - - inv H4; simpl; auto. + - inv H4; cbn; auto. (* madd, maddim *) - - inv H2; inv H3; inv H4; simpl; auto. - - inv H2; inv H4; simpl; auto. + - inv H2; inv H3; inv H4; cbn; auto. + - inv H2; inv H4; cbn; auto. (* msub *) - apply Val.sub_inject; auto. - inv H3; inv H2; simpl; auto. + inv H3; inv H2; cbn; auto. (* makelong, highlong, lowlong *) - - inv H4; inv H2; simpl; auto. - - inv H4; simpl; auto. - - inv H4; simpl; auto. + - inv H4; inv H2; cbn; auto. + - inv H4; cbn; auto. + - inv H4; cbn; auto. (* cast32 *) - - inv H4; simpl; auto. - - inv H4; simpl; auto. + - inv H4; cbn; auto. + - inv H4; cbn; auto. (* addl, addlimm *) - apply Val.addl_inject; auto. - apply Val.addl_inject; auto. (* addxl, addxlimm *) - apply Val.addl_inject; auto. - inv H4; simpl; trivial. - destruct (Int.ltu _ _); simpl; trivial. - - inv H4; simpl; trivial. - destruct (Int.ltu _ _); simpl; trivial. + inv H4; cbn; trivial. + destruct (Int.ltu _ _); cbn; trivial. + - inv H4; cbn; trivial. + destruct (Int.ltu _ _); cbn; trivial. (* negl, subl *) - - inv H4; simpl; auto. + - inv H4; cbn; auto. - apply Val.subl_inject; auto. - inv H4; inv H2; simpl; trivial; - destruct (Int.ltu _ _); simpl; trivial. - - inv H4; simpl; trivial; - destruct (Int.ltu _ _); simpl; trivial. - - inv H4; simpl; auto. + inv H4; inv H2; cbn; trivial; + destruct (Int.ltu _ _); cbn; trivial. + - inv H4; cbn; trivial; + destruct (Int.ltu _ _); cbn; trivial. + - inv H4; cbn; auto. - apply Val.subl_inject; auto. (* mull, mullhs, mullhu *) - - inv H4; inv H2; simpl; auto. - - inv H4; simpl; auto. - - inv H4; inv H2; simpl; auto. - - inv H4; inv H2; simpl; auto. + - inv H4; inv H2; cbn; auto. + - inv H4; cbn; auto. + - inv H4; inv H2; cbn; auto. + - inv H4; inv H2; cbn; auto. (* divl, divlu *) - - inv H4; inv H3; simpl in H1; inv H1. simpl. - destruct (Int64.eq i0 Int64.zero - || Int64.eq i (Int64.repr Int64.min_signed) && Int64.eq i0 Int64.mone); inv H2. + - inv H4; inv H3; cbn in H1; inv H1. cbn. + destruct (_ || _); inv H2. TrivialExists. - - inv H4; inv H3; simpl in H1; inv H1. simpl. + - inv H4; inv H3; cbn in H1; inv H1. cbn. destruct (Int64.eq i0 Int64.zero); inv H2. TrivialExists. (* modl, modlu *) - - inv H4; inv H3; simpl in H1; inv H1. simpl. - destruct (Int64.eq i0 Int64.zero - || Int64.eq i (Int64.repr Int64.min_signed) && Int64.eq i0 Int64.mone); inv H2. + - inv H4; inv H3; cbn in H1; inv H1. cbn. + destruct (_ || _); inv H2. TrivialExists. - - inv H4; inv H3; simpl in H1; inv H1. simpl. + - inv H4; inv H3; cbn in H1; inv H1. cbn. destruct (Int64.eq i0 Int64.zero); inv H2. TrivialExists. (* andl, andlimm *) - - inv H4; inv H2; simpl; auto. - - inv H4; simpl; auto. + - inv H4; inv H2; cbn; auto. + - inv H4; cbn; auto. (* nandl, nandlimm *) - - inv H4; inv H2; simpl; auto. - - inv H4; simpl; auto. + - inv H4; inv H2; cbn; auto. + - inv H4; cbn; auto. (* orl, orlimm *) - - inv H4; inv H2; simpl; auto. - - inv H4; simpl; auto. + - inv H4; inv H2; cbn; auto. + - inv H4; cbn; auto. (* norl, norlimm *) - - inv H4; inv H2; simpl; auto. - - inv H4; simpl; auto. + - inv H4; inv H2; cbn; auto. + - inv H4; cbn; auto. (* xorl, xorlimm *) - - inv H4; inv H2; simpl; auto. - - inv H4; simpl; auto. + - inv H4; inv H2; cbn; auto. + - inv H4; cbn; auto. (* nxorl, nxorlimm *) - - inv H4; inv H2; simpl; auto. - - inv H4; simpl; auto. + - inv H4; inv H2; cbn; auto. + - inv H4; cbn; auto. (* notl *) - - inv H4; simpl; auto. + - inv H4; cbn; auto. (* andnl, andnlimm *) - - inv H4; inv H2; simpl; auto. - - inv H4; simpl; auto. + - inv H4; inv H2; cbn; auto. + - inv H4; cbn; auto. (* ornl, ornlimm *) - - inv H4; inv H2; simpl; auto. - - inv H4; simpl; auto. + - inv H4; inv H2; cbn; auto. + - inv H4; cbn; auto. (* shll, shllimm *) - - inv H4; inv H2; simpl; auto. destruct (Int.ltu i0 Int64.iwordsize'); auto. - - inv H4; simpl; auto. destruct (Int.ltu n Int64.iwordsize'); auto. + - inv H4; inv H2; cbn; auto. destruct (Int.ltu i0 Int64.iwordsize'); auto. + - inv H4; cbn; auto. destruct (Int.ltu n Int64.iwordsize'); auto. (* shr, shrimm *) - - inv H4; inv H2; simpl; auto. destruct (Int.ltu i0 Int64.iwordsize'); auto. - - inv H4; simpl; auto. destruct (Int.ltu n Int64.iwordsize'); auto. + - inv H4; inv H2; cbn; auto. destruct (Int.ltu i0 Int64.iwordsize'); auto. + - inv H4; cbn; auto. destruct (Int.ltu n Int64.iwordsize'); auto. (* shru, shruimm *) - - inv H4; inv H2; simpl; auto. destruct (Int.ltu i0 Int64.iwordsize'); auto. - - inv H4; simpl; auto. destruct (Int.ltu n Int64.iwordsize'); auto. + - inv H4; inv H2; cbn; auto. destruct (Int.ltu i0 Int64.iwordsize'); auto. + - inv H4; cbn; auto. destruct (Int.ltu n Int64.iwordsize'); auto. (* shrx *) - - inv H4; simpl; auto. - destruct (Int.ltu n (Int.repr 63)); simpl; auto. + - inv H4; cbn; auto. + destruct (Int.ltu n (Int.repr 63)); cbn; auto. (* maddl, maddlimm *) - apply Val.addl_inject; auto. - inv H2; inv H3; inv H4; simpl; auto. + inv H2; inv H3; inv H4; cbn; auto. - apply Val.addl_inject; auto. - inv H4; inv H2; simpl; auto. + inv H4; inv H2; cbn; auto. (* msubl, msublimm *) - apply Val.subl_inject; auto. - inv H2; inv H3; inv H4; simpl; auto. + inv H2; inv H3; inv H4; cbn; auto. (* negf, absf *) - - inv H4; simpl; auto. - - inv H4; simpl; auto. + - inv H4; cbn; auto. + - inv H4; cbn; auto. (* addf, subf *) - - inv H4; inv H2; simpl; auto. - - inv H4; inv H2; simpl; auto. + - inv H4; inv H2; cbn; auto. + - inv H4; inv H2; cbn; auto. (* mulf, divf *) - - inv H4; inv H2; simpl; auto. - - inv H4; inv H2; simpl; auto. + - inv H4; inv H2; cbn; auto. + - inv H4; inv H2; cbn; auto. (* minf, maxf *) - - inv H4; inv H2; simpl; auto. - - inv H4; inv H2; simpl; auto. + - inv H4; inv H2; cbn; auto. + - inv H4; inv H2; cbn; auto. (* fmaddf, fmsubf *) - - inv H4; inv H3; inv H2; simpl; auto. - - inv H4; inv H3; inv H2; simpl; auto. + - inv H4; inv H3; inv H2; cbn; auto. + - inv H4; inv H3; inv H2; cbn; auto. (* negfs, absfs *) - - inv H4; simpl; auto. - - inv H4; simpl; auto. + - inv H4; cbn; auto. + - inv H4; cbn; auto. (* addfs, subfs *) - - inv H4; inv H2; simpl; auto. - - inv H4; inv H2; simpl; auto. + - inv H4; inv H2; cbn; auto. + - inv H4; inv H2; cbn; auto. (* mulfs, divfs *) - - inv H4; inv H2; simpl; auto. - - inv H4; inv H2; simpl; auto. + - inv H4; inv H2; cbn; auto. + - inv H4; inv H2; cbn; auto. (* minfs, maxfs *) - - inv H4; inv H2; simpl; auto. - - inv H4; inv H2; simpl; auto. + - inv H4; inv H2; cbn; auto. + - inv H4; inv H2; cbn; auto. (* invfs *) - - inv H4; simpl; auto. + - inv H4; cbn; auto. (* fmaddfs, fmsubfs *) - - inv H4; inv H3; inv H2; simpl; auto. - - inv H4; inv H3; inv H2; simpl; auto. + - inv H4; inv H3; inv H2; cbn; auto. + - inv H4; inv H3; inv H2; cbn; auto. (* singleoffloat, floatofsingle *) - - inv H4; simpl; auto. - - inv H4; simpl; auto. + - inv H4; cbn; auto. + - inv H4; cbn; auto. (* intoffloat, intuoffloat *) - - inv H4; simpl; auto. destruct (Float.to_int f0); simpl; auto. - - inv H4; simpl; auto. destruct (Float.to_intu f0); simpl; auto. + - inv H4; cbn; auto. destruct (Float.to_int f0); cbn; auto. + - inv H4; cbn; auto. destruct (Float.to_intu f0); cbn; auto. (* intofsingle, intuofsingle *) - - inv H4; simpl; auto. destruct (Float32.to_int f0); simpl; auto. - - inv H4; simpl; auto. destruct (Float32.to_intu f0); simpl; auto. + - inv H4; cbn; auto. destruct (Float32.to_int f0); cbn; auto. + - inv H4; cbn; auto. destruct (Float32.to_intu f0); cbn; auto. (* singleofint, singleofintu *) - - inv H4; simpl; auto. - - inv H4; simpl; auto. + - inv H4; cbn; auto. + - inv H4; cbn; auto. (* longoffloat, longuoffloat *) - - inv H4; simpl; auto. destruct (Float.to_long f0); simpl; auto. - - inv H4; simpl; auto. destruct (Float.to_longu f0); simpl; auto. + - inv H4; cbn; auto. destruct (Float.to_long f0); cbn; auto. + - inv H4; cbn; auto. destruct (Float.to_longu f0); cbn; auto. (* floatoflong, floatoflongu *) - - inv H4; simpl; auto. - - inv H4; simpl; auto. + - inv H4; cbn; auto. + - inv H4; cbn; auto. (* longofsingle, longuofsingle *) - - inv H4; simpl; auto. destruct (Float32.to_long f0); simpl; auto. - - inv H4; simpl; auto. destruct (Float32.to_longu f0); simpl; auto. + - inv H4; cbn; auto. destruct (Float32.to_long f0); cbn; auto. + - inv H4; cbn; auto. destruct (Float32.to_longu f0); cbn; auto. (* singleoflong, singleoflongu *) - - inv H4; simpl; auto. - - inv H4; simpl; auto. + - inv H4; cbn; auto. + - inv H4; cbn; auto. (* cmp *) - subst v1. destruct (eval_condition cond vl1 m1) eqn:?. exploit eval_condition_inj; eauto. intros EQ; rewrite EQ. - destruct b; simpl; constructor. - simpl; constructor. + destruct b; cbn; constructor. + cbn; constructor. (* extfz *) - unfold extfz. @@ -1703,16 +1699,16 @@ Proof. - unfold insf. destruct (is_bitfield _ _). + inv H4; inv H2; trivial. - simpl. destruct (Int.ltu _ _); trivial. - simpl. trivial. + cbn. destruct (Int.ltu _ _); trivial. + cbn. trivial. + trivial. (* insfl *) - unfold insfl. destruct (is_bitfieldl _ _). + inv H4; inv H2; trivial. - simpl. destruct (Int.ltu _ _); trivial. - simpl. trivial. + cbn. destruct (Int.ltu _ _); trivial. + cbn. trivial. + trivial. (* Osel *) @@ -1750,13 +1746,13 @@ Lemma eval_addressing_inj: eval_addressing ge1 sp1 addr vl1 = Some v1 -> exists v2, eval_addressing ge2 sp2 addr vl2 = Some v2 /\ Val.inject f v1 v2. Proof. - intros. destruct addr; simpl in H2; simpl; FuncInv; InvInject; TrivialExists. + intros. destruct addr; cbn in H2; cbn; FuncInv; InvInject; TrivialExists. - apply Val.addl_inject; trivial. - destruct v0; destruct v'0; simpl; trivial; destruct (Int.ltu _ _); simpl; trivial; inv H3. + destruct v0; destruct v'0; cbn; trivial; destruct (Int.ltu _ _); cbn; trivial; inv H3. apply Val.inject_long. - apply Val.addl_inject; auto. - apply Val.offset_ptr_inject; auto. - - apply H; simpl; auto. + - apply H; cbn; auto. - apply Val.offset_ptr_inject; auto. Qed. @@ -1771,7 +1767,7 @@ Lemma eval_addressing_inj_none: eval_addressing ge2 sp2 addr vl2 = None. Proof. intros until vl2. intros Hglobal Hinjsp Hinjvl. - destruct addr; simpl in *. + destruct addr; cbn in *. 1,2: inv Hinjvl; trivial; inv H0; trivial; inv H2; trivial; @@ -1895,7 +1891,7 @@ Lemma eval_addressing_lessdef_none: eval_addressing genv sp addr vl2 = None. Proof. intros until vl2. intros Hlessdef Heval1. - destruct addr; simpl in *. + destruct addr; cbn in *. 1, 2, 4, 5: inv Hlessdef; trivial; inv H0; trivial; inv H2; trivial; @@ -1980,7 +1976,7 @@ Lemma eval_operation_inject: /\ Val.inject f v1 v2. Proof. intros. - rewrite eval_shift_stack_operation. simpl. + rewrite eval_shift_stack_operation. cbn. eapply eval_operation_inj with (sp1 := Vptr sp1 Ptrofs.zero) (m1 := m1); eauto. intros; eapply Mem.valid_pointer_inject_val; eauto. intros; eapply Mem.weak_valid_pointer_inject_val; eauto. diff --git a/kvx/OpWeights.ml b/kvx/OpWeights.ml index 4c3c40d0..9614fd92 100644 --- a/kvx/OpWeights.ml +++ b/kvx/OpWeights.ml @@ -1,7 +1,7 @@ open Op;; open PostpassSchedulingOracle;; let resource_bounds = PostpassSchedulingOracle.resource_bounds;; - +let nr_non_pipelined_units = 0;; let rec nlist_rec x l = function | 0 -> l @@ -66,6 +66,8 @@ let resources_of_op (op : operation) (nargs : int) = let insn = insn_of_op op nargs in let record = basic_rec insn in rec_to_usage record;; + +let non_pipelined_resources_of_op (op : operation) (nargs : int) = [| |] let resources_of_cond (cond : condition) (nargs : int) = let insn = insn_of_cond cond nargs in diff --git a/kvx/Peephole.v b/kvx/Peephole.v index 35f4bbd9..5adb823b 100644 --- a/kvx/Peephole.v +++ b/kvx/Peephole.v @@ -153,6 +153,6 @@ Program Definition optimize_bblock (bb : bblock) := exit := exit bb |}. Next Obligation. destruct (wf_bblockb (optimize_body (body bb))) eqn:Rwf. - - rewrite Rwf. simpl. trivial. + - rewrite Rwf. cbn. trivial. - exact (correct bb). Qed. diff --git a/kvx/PostpassSchedulingOracle.ml b/kvx/PostpassSchedulingOracle.ml index 67e3f80f..2107ce22 100644 --- a/kvx/PostpassSchedulingOracle.ml +++ b/kvx/PostpassSchedulingOracle.ml @@ -504,8 +504,7 @@ let alu_lite_y : int array = let resmap = fun r -> match r with | Rissue -> 3 | Rtiny -> 1 | Rlite -> 1 | _ -> 0 in Array.of_list (List.map resmap resource_names) -let alu_nop : int array = let resmap = fun r -> match r with - | Rissue -> 1 | Rnop -> 1 | _ -> 0 +let alu_nop : int array = let resmap = fun r -> 0 in Array.of_list (List.map resmap resource_names) let alu_tiny : int array = let resmap = fun r -> match r with @@ -627,16 +626,16 @@ let rec_to_usage r = | Some U27L5 | Some U27L10 -> alu_tiny_x | Some E27U27L10 -> alu_tiny_y | _ -> raise InvalidEncoding) - | Maddw -> (match encoding with None -> mau_auxr + | Maddw | Msbfw -> (match encoding with None -> mau_auxr | Some U6 | Some S10 | Some U27L5 -> mau_auxr_x | _ -> raise InvalidEncoding) - | Maddd -> (match encoding with None | Some U6 | Some S10 -> mau_auxr + | Maddd | Msbfd -> (match encoding with None | Some U6 | Some S10 -> mau_auxr | Some U27L5 | Some U27L10 -> mau_auxr_x | Some E27U27L10 -> mau_auxr_y) - | Mulw| Msbfw -> (match encoding with None -> mau + | Mulw -> (match encoding with None -> mau | Some U6 | Some S10 | Some U27L5 -> mau_x | _ -> raise InvalidEncoding) - | Muld | Msbfd -> (match encoding with None | Some U6 | Some S10 -> mau + | Muld -> (match encoding with None | Some U6 | Some S10 -> mau | Some U27L5 | Some U27L10 -> mau_x | Some E27U27L10 -> mau_y) | Nop -> alu_nop @@ -914,12 +913,20 @@ let print_bb oc bb = let asm_instructions = Asm.unfold_bblock bb in List.iter (print_inst oc) asm_instructions +let print_schedule sched = + print_string "[ "; + Array.iter (fun x -> Printf.printf "%d; " x) sched; + print_endline "]";; + let do_schedule bb = - let problem = build_problem bb - in let solution = scheduler_by_name (!Clflags.option_fpostpass_sched) problem + let problem = build_problem bb in + (if debug then print_problem stdout problem); + let solution = scheduler_by_name (!Clflags.option_fpostpass_sched) problem in match solution with | None -> failwith "Could not find a valid schedule" - | Some sol -> let bundles = bundlize_solution bb sol in + | Some sol -> + ((if debug then print_schedule sol); + let bundles = bundlize_solution bb sol in (if debug then begin Printf.eprintf "Scheduling the following group of instructions:\n"; @@ -928,7 +935,7 @@ let do_schedule bb = List.iter (print_bb stderr) bundles; Printf.eprintf "--------------------------------\n" end; - bundles) + bundles)) (** * Dumb schedule if the above doesn't work diff --git a/kvx/PrepassSchedulingOracle.ml b/kvx/PrepassSchedulingOracle.ml new file mode 120000 index 00000000..912e9ffa --- /dev/null +++ b/kvx/PrepassSchedulingOracle.ml @@ -0,0 +1 @@ +../aarch64/PrepassSchedulingOracle.ml
\ No newline at end of file diff --git a/kvx/Stacklayout.v b/kvx/Stacklayout.v index 46202e03..81ffcebb 100644 --- a/kvx/Stacklayout.v +++ b/kvx/Stacklayout.v @@ -63,7 +63,7 @@ Lemma frame_env_separated: ** P. Proof. Local Opaque Z.add Z.mul sepconj range. - intros; simpl. + intros; cbn. set (w := if Archi.ptr64 then 8 else 4). set (olink := align (4 * b.(bound_outgoing)) w). set (oretaddr := olink + w). @@ -105,7 +105,7 @@ Lemma frame_env_range: let fe := make_env b in 0 <= fe_stack_data fe /\ fe_stack_data fe + bound_stack_data b <= fe_size fe. Proof. - intros; simpl. + intros; cbn. set (w := if Archi.ptr64 then 8 else 4). set (olink := align (4 * b.(bound_outgoing)) w). set (oretaddr := olink + w). @@ -133,7 +133,7 @@ Lemma frame_env_aligned: /\ (align_chunk Mptr | fe_ofs_link fe) /\ (align_chunk Mptr | fe_ofs_retaddr fe). Proof. - intros; simpl. + intros; cbn. set (w := if Archi.ptr64 then 8 else 4). set (olink := align (4 * b.(bound_outgoing)) w). set (oretaddr := olink + w). diff --git a/kvx/ValueAOp.v b/kvx/ValueAOp.v index e634fdc0..87554258 100644 --- a/kvx/ValueAOp.v +++ b/kvx/ValueAOp.v @@ -16,87 +16,6 @@ Require Import Coqlib Compopts. Require Import AST Integers Floats Values Memory Globalenvs. Require Import Op ExtValues ExtFloats RTL ValueDomain. - -Definition intoffloat_total (x: aval) := - match x with - | F f => - match Float.to_int f with - | Some i => I i - | None => ntop - end - | _ => ntop1 x - end. - -Definition intuoffloat_total (x: aval) := - match x with - | F f => - match Float.to_intu f with - | Some i => I i - | None => ntop - end - | _ => ntop1 x - end. - -Definition intofsingle_total (x: aval) := - match x with - | FS f => - match Float32.to_int f with - | Some i => I i - | None => ntop - end - | _ => ntop1 x - end. - -Definition intuofsingle_total (x: aval) := - match x with - | FS f => - match Float32.to_intu f with - | Some i => I i - | None => ntop - end - | _ => ntop1 x - end. - -Definition longoffloat_total (x: aval) := - match x with - | F f => - match Float.to_long f with - | Some i => L i - | None => ntop - end - | _ => ntop1 x - end. - -Definition longuoffloat_total (x: aval) := - match x with - | F f => - match Float.to_longu f with - | Some i => L i - | None => ntop - end - | _ => ntop1 x - end. - -Definition longofsingle_total (x: aval) := - match x with - | FS f => - match Float32.to_long f with - | Some i => L i - | None => ntop - end - | _ => ntop1 x - end. - -Definition longuofsingle_total (x: aval) := - match x with - | FS f => - match Float32.to_longu f with - | Some i => L i - | None => ntop - end - | _ => ntop1 x - end. - Definition minf := binop_float ExtFloat.min. Definition maxf := binop_float ExtFloat.max. Definition minfs := binop_single ExtFloat32.min. @@ -400,196 +319,6 @@ Hypothesis GENV: genv_match bc ge. Variable sp: block. Hypothesis STACK: bc sp = BCstack. -Lemma intoffloat_total_sound: - forall v x - (MATCH : vmatch bc v x), - vmatch bc (Val.maketotal (Val.intoffloat v)) (intoffloat_total x). -Proof. - unfold Val.intoffloat, intoffloat_total. intros. - inv MATCH; simpl in *; try constructor. - all: destruct (Float.to_int f) as [i|] eqn:E; simpl; [auto with va | constructor]. - unfold ntop1, provenance. - destruct (va_strict tt); constructor. -Qed. - -Hint Resolve intoffloat_total_sound : va. - -Lemma intuoffloat_total_sound: - forall v x - (MATCH : vmatch bc v x), - vmatch bc (Val.maketotal (Val.intuoffloat v)) (intuoffloat_total x). -Proof. - unfold Val.intoffloat, intoffloat_total. intros. - inv MATCH; simpl in *; try constructor. - all: destruct (Float.to_intu f) as [i|] eqn:E; simpl; [auto with va | constructor]. - unfold ntop1, provenance. - destruct (va_strict tt); constructor. -Qed. - -Hint Resolve intuoffloat_total_sound : va. - -Lemma intofsingle_total_sound: - forall v x - (MATCH : vmatch bc v x), - vmatch bc (Val.maketotal (Val.intofsingle v)) (intofsingle_total x). -Proof. - unfold Val.intofsingle, intofsingle_total. intros. - inv MATCH; simpl in *; try constructor. - all: destruct (Float32.to_int f) as [i|] eqn:E; simpl; [auto with va | constructor]. - unfold ntop1, provenance. - destruct (va_strict tt); constructor. -Qed. - -Hint Resolve intofsingle_total_sound : va. - -Lemma intuofsingle_total_sound: - forall v x - (MATCH : vmatch bc v x), - vmatch bc (Val.maketotal (Val.intuofsingle v)) (intuofsingle_total x). -Proof. - unfold Val.intofsingle, intofsingle_total. intros. - inv MATCH; simpl in *; try constructor. - all: destruct (Float32.to_intu f) as [i|] eqn:E; simpl; [auto with va | constructor]. - unfold ntop1, provenance. - destruct (va_strict tt); constructor. -Qed. - -Hint Resolve intuofsingle_total_sound : va. - -Lemma singleofint_total_sound: - forall v x, vmatch bc v x -> - vmatch bc (Val.maketotal (Val.singleofint v)) (singleofint x). -Proof. - unfold Val.singleofint, singleofint; intros. - inv H; simpl. - all: auto with va. - all: unfold ntop1, provenance. - all: try constructor. -Qed. - -Hint Resolve singleofint_total_sound : va. - -Lemma singleofintu_total_sound: - forall v x, vmatch bc v x -> - vmatch bc (Val.maketotal (Val.singleofintu v)) (singleofintu x). -Proof. - unfold Val.singleofintu, singleofintu; intros. - inv H; simpl. - all: auto with va. - all: unfold ntop1, provenance. - all: try constructor. -Qed. - -Hint Resolve singleofintu_total_sound : va. - -Lemma longoffloat_total_sound: - forall v x - (MATCH : vmatch bc v x), - vmatch bc (Val.maketotal (Val.longoffloat v)) (longoffloat_total x). -Proof. - unfold Val.longoffloat, longoffloat_total. intros. - inv MATCH; simpl in *; try constructor. - all: destruct (Float.to_long f) as [i|] eqn:E; simpl; [auto with va | constructor]. - unfold ntop1, provenance. - destruct (va_strict tt); constructor. -Qed. - -Hint Resolve longoffloat_total_sound : va. - -Lemma longuoffloat_total_sound: - forall v x - (MATCH : vmatch bc v x), - vmatch bc (Val.maketotal (Val.longuoffloat v)) (longuoffloat_total x). -Proof. - unfold Val.longoffloat, longoffloat_total. intros. - inv MATCH; simpl in *; try constructor. - all: destruct (Float.to_longu f) as [i|] eqn:E; simpl; [auto with va | constructor]. - unfold ntop1, provenance. - destruct (va_strict tt); constructor. -Qed. - -Hint Resolve longuoffloat_total_sound : va. - -Lemma longofsingle_total_sound: - forall v x - (MATCH : vmatch bc v x), - vmatch bc (Val.maketotal (Val.longofsingle v)) (longofsingle_total x). -Proof. - unfold Val.longofsingle, longofsingle_total. intros. - inv MATCH; simpl in *; try constructor. - all: destruct (Float32.to_long f) as [i|] eqn:E; simpl; [auto with va | constructor]. - unfold ntop1, provenance. - destruct (va_strict tt); constructor. -Qed. - -Hint Resolve longofsingle_total_sound : va. - -Lemma longuofsingle_total_sound: - forall v x - (MATCH : vmatch bc v x), - vmatch bc (Val.maketotal (Val.longuofsingle v)) (longuofsingle_total x). -Proof. - unfold Val.longofsingle, longofsingle_total. intros. - inv MATCH; simpl in *; try constructor. - all: destruct (Float32.to_longu f) as [i|] eqn:E; simpl; [auto with va | constructor]. - unfold ntop1, provenance. - destruct (va_strict tt); constructor. -Qed. - -Hint Resolve longuofsingle_total_sound : va. - -Lemma singleoflong_total_sound: - forall v x, vmatch bc v x -> - vmatch bc (Val.maketotal (Val.singleoflong v)) (singleoflong x). -Proof. - unfold Val.singleoflong, singleoflong; intros. - inv H; simpl. - all: auto with va. - all: unfold ntop1, provenance. - all: try constructor. -Qed. - -Hint Resolve singleoflong_total_sound : va. - -Lemma singleoflongu_total_sound: - forall v x, vmatch bc v x -> - vmatch bc (Val.maketotal (Val.singleoflongu v)) (singleoflongu x). -Proof. - unfold Val.singleoflongu, singleoflongu; intros. - inv H; simpl. - all: auto with va. - all: unfold ntop1, provenance. - all: try constructor. -Qed. - -Hint Resolve singleoflongu_total_sound : va. - -Lemma floatoflong_total_sound: - forall v x, vmatch bc v x -> - vmatch bc (Val.maketotal (Val.floatoflong v)) (floatoflong x). -Proof. - unfold Val.floatoflong, floatoflong; intros. - inv H; simpl. - all: auto with va. - all: unfold ntop1, provenance. - all: try constructor. -Qed. - -Hint Resolve floatoflong_total_sound : va. - -Lemma floatoflongu_total_sound: - forall v x, vmatch bc v x -> - vmatch bc (Val.maketotal (Val.floatoflongu v)) (floatoflongu x). -Proof. - unfold Val.floatoflongu, floatoflongu; intros. - inv H; simpl. - all: auto with va. - all: unfold ntop1, provenance. - all: try constructor. -Qed. - -Hint Resolve floatoflongu_total_sound : va. - Lemma minf_sound: forall v x w y, vmatch bc v x -> vmatch bc w y -> vmatch bc (ExtValues.minf v w) (minf x y). Proof. @@ -620,7 +349,7 @@ Proof. intros v x; intro MATCH; inversion MATCH; - simpl; + cbn; constructor. Qed. @@ -632,9 +361,9 @@ Lemma triple_op_float_sound: Proof. intros until z. intros Hax Hby Hcz. - inv Hax; simpl; try constructor; - inv Hby; simpl; try constructor; - inv Hcz; simpl; try constructor. + inv Hax; cbn; try constructor; + inv Hby; cbn; try constructor; + inv Hcz; cbn; try constructor. Qed. Lemma triple_op_single_sound: @@ -645,9 +374,9 @@ Lemma triple_op_single_sound: Proof. intros until z. intros Hax Hby Hcz. - inv Hax; simpl; try constructor; - inv Hby; simpl; try constructor; - inv Hcz; simpl; try constructor. + inv Hax; cbn; try constructor; + inv Hby; cbn; try constructor; + inv Hcz; cbn; try constructor. Qed. Lemma fmaddf_sound : @@ -691,9 +420,9 @@ Proof. intros until aargs; intros VM. inv VM. destruct cond; auto with va. inv H0. - destruct cond; simpl; eauto with va. + destruct cond; cbn; eauto with va. inv H2. - destruct cond; simpl; eauto with va. + destruct cond; cbn; eauto with va. destruct cond; auto with va. Qed. @@ -703,7 +432,7 @@ Theorem eval_static_condition0_sound: cmatch (eval_condition0 cond varg m) (eval_static_condition0 cond aarg). Proof. intros until aarg; intro VM. - destruct cond; simpl; eauto with va. + destruct cond; cbn; eauto with va. Qed. Lemma symbol_address_sound: @@ -812,19 +541,9 @@ Proof. + eauto with va. + destruct n; destruct shift; reflexivity. - (* shrx *) - inv H1; simpl; try constructor. - all: destruct Int.ltu; [simpl | constructor; fail]. + inv H1; cbn; try constructor. + all: destruct Int.ltu; [cbn | constructor; fail]. all: auto with va. - - replace (match Val.shll a1 (Vint (int_of_shift1_4 shift)) with - | Vlong n2 => Vlong (Int64.add n n2) - | Vptr b2 ofs2 => - if Archi.ptr64 - then Vptr b2 (Ptrofs.add ofs2 (Ptrofs.of_int64 n)) - else Vundef - | _ => Vundef - end) with (Val.addl (Vlong n) (Val.shll a1 (Vint (int_of_shift1_4 shift)))). - + eauto with va. - + destruct a1; destruct shift; reflexivity. - inv H1; constructor. - replace (match Val.shll a1 (Vint (int_of_shift1_4 shift)) with | Vlong n2 => Vlong (Int64.sub n n2) @@ -832,10 +551,6 @@ Proof. end) with (Val.subl (Vlong n) (Val.shll a1 (Vint (int_of_shift1_4 shift)))). + eauto with va. + destruct a1; destruct shift; reflexivity. - - (* shrxl *) - inv H1; simpl; try constructor. - all: destruct Int.ltu; [simpl | constructor; fail]. - all: auto with va. - apply of_optbool_sound. eapply eval_static_condition_sound; eauto. (* extfz *) @@ -865,12 +580,12 @@ Proof. (* insf *) - unfold insf, eval_static_insf. destruct (is_bitfield _ _). - + inv H1; inv H0; simpl; try constructor; destruct (Int.ltu _ _); simpl; constructor. + + inv H1; inv H0; cbn; try constructor; destruct (Int.ltu _ _); cbn; constructor. + constructor. (* insfl *) - unfold insfl, eval_static_insfl. destruct (is_bitfieldl _ _). - + inv H1; inv H0; simpl; try constructor; destruct (Int.ltu _ _); simpl; constructor. + + inv H1; inv H0; cbn; try constructor; destruct (Int.ltu _ _); cbn; constructor. + constructor. (* select *) - apply select_sound; auto. eapply eval_static_condition0_sound; eauto. diff --git a/kvx/abstractbb/AbstractBasicBlocksDef.v b/kvx/abstractbb/AbstractBasicBlocksDef.v index 0b1c502d..6960f363 100644 --- a/kvx/abstractbb/AbstractBasicBlocksDef.v +++ b/kvx/abstractbb/AbstractBasicBlocksDef.v @@ -45,7 +45,7 @@ End LangParam. -(** * Syntax and (sequential) semantics of "basic blocks" *) +(** * Syntax and (sequential) semantics of "abstract basic blocks" *) Module MkSeqLanguage(P: LangParam). Export P. @@ -62,12 +62,12 @@ Definition assign (m: mem) (x:R.t) (v: value): mem := fun y => if R.eq_dec x y then v else m y. -(** expressions *) +(** Expressions *) Inductive exp := - | PReg (x:R.t) - | Op (o:op) (le: list_exp) - | Old (e: exp) + | PReg (x:R.t) (**r pseudo-register *) + | Op (o:op) (le: list_exp) (**r operation *) + | Old (e: exp) (**r evaluation of [e] in the initial state of the instruction (see [inst] below) *) with list_exp := | Enil | Econs (e:exp) (le:list_exp) @@ -95,7 +95,8 @@ with list_exp_eval (le: list_exp) (m old: mem): option (list value) := | LOld le => list_exp_eval le old old end. -Definition inst := list (R.t * exp). (* = a sequence of assignments *) +(** An instruction represents a sequence of assignments where [Old] refers to the initial state of the sequence. *) +Definition inst := list (R.t * exp). Fixpoint inst_run (i: inst) (m old: mem): option mem := match i with @@ -107,6 +108,7 @@ Fixpoint inst_run (i: inst) (m old: mem): option mem := end end. +(** A basic block is a sequence of instructions. *) Definition bblock := list inst. Fixpoint run (p: bblock) (m: mem): option mem := @@ -168,7 +170,7 @@ Lemma exp_equiv e old1 old2: (exp_eval e m1 old1) = (exp_eval e m2 old2). Proof. intros H1. - induction e using exp_mut with (P0:=fun l => forall m1 m2, (forall x, m1 x = m2 x) -> list_exp_eval l m1 old1 = list_exp_eval l m2 old2); simpl; try congruence; auto. + induction e using exp_mut with (P0:=fun l => forall m1 m2, (forall x, m1 x = m2 x) -> list_exp_eval l m1 old1 = list_exp_eval l m2 old2); cbn; try congruence; auto. - intros; erewrite IHe; eauto. - intros; erewrite IHe, IHe0; auto. Qed. @@ -181,38 +183,38 @@ Lemma inst_equiv_refl i old1 old2: forall m1 m2, (forall x, m1 x = m2 x) -> res_eq (inst_run i m1 old1) (inst_run i m2 old2). Proof. - intro H; induction i as [ | [x e]]; simpl; eauto. + intro H; induction i as [ | [x e]]; cbn; eauto. intros m1 m2 H1. erewrite exp_equiv; eauto. - destruct (exp_eval e m2 old2); simpl; auto. + destruct (exp_eval e m2 old2); cbn; auto. apply IHi. unfold assign; intro y. destruct (R.eq_dec x y); auto. Qed. Lemma bblock_equiv_refl p: forall m1 m2, (forall x, m1 x = m2 x) -> res_eq (run p m1) (run p m2). Proof. - induction p as [ | i p']; simpl; eauto. + induction p as [ | i p']; cbn; eauto. intros m1 m2 H; lapply (inst_equiv_refl i m1 m2); auto. intros X; lapply (X m1 m2); auto; clear X. - destruct (inst_run i m1 m1); simpl. - - intros [m3 [H1 H2]]; rewrite H1; simpl; auto. - - intros H1; rewrite H1; simpl; auto. + destruct (inst_run i m1 m1); cbn. + - intros [m3 [H1 H2]]; rewrite H1; cbn; auto. + - intros H1; rewrite H1; cbn; auto. Qed. Lemma res_eq_sym om1 om2: res_eq om1 om2 -> res_eq om2 om1. Proof. - destruct om1; simpl. - - intros [m2 [H1 H2]]; subst; simpl. eauto. - - intros; subst; simpl; eauto. + destruct om1; cbn. + - intros [m2 [H1 H2]]; subst; cbn. eauto. + - intros; subst; cbn; eauto. Qed. Lemma res_eq_trans (om1 om2 om3: option mem): (res_eq om1 om2) -> (res_eq om2 om3) -> (res_eq om1 om3). Proof. - destruct om1; simpl. - - intros [m2 [H1 H2]]; subst; simpl. - intros [m3 [H3 H4]]; subst; simpl. + destruct om1; cbn. + - intros [m2 [H1 H2]]; subst; cbn. + intros [m3 [H3 H4]]; subst; cbn. eapply ex_intro; intuition eauto. rewrite H2; auto. - - intro; subst; simpl; auto. + - intro; subst; cbn; auto. Qed. Lemma bblock_simu_alt p1 p2: bblock_simu p1 p2 <-> (forall m1 m2, (forall x, m1 x = m2 x) -> (run p1 m1)<>None -> res_eq (run p1 m1) (run p2 m2)). @@ -230,8 +232,8 @@ Lemma run_app p1: forall m1 p2, | None => None end. Proof. - induction p1; simpl; try congruence. - intros; destruct (inst_run _ _ _); simpl; auto. + induction p1; cbn; try congruence. + intros; destruct (inst_run _ _ _); cbn; auto. Qed. Lemma run_app_None p1 m1 p2: @@ -250,12 +252,16 @@ Qed. End SEQLANG. -Module Terms. -(** terms in the symbolic evaluation -NB: such a term represents the successive computations in one given pseudo-register +(** * Terms in the symbolic execution *) + +(** Such a term represents the successive computations in one given pseudo-register. +The [hid] has no formal semantics: it is only used by the hash-consing oracle (itself dynamically checked to behave like an identity function). + *) +Module Terms. + Inductive term := | Input (x:R.t) (hid:hashcode) | App (o: op) (l: list_term) (hid:hashcode) @@ -328,17 +334,27 @@ Fixpoint allvalid ge (l: list term) m : Prop := Lemma allvalid_extensionality ge (l: list term) m: allvalid ge l m <-> (forall t, List.In t l -> term_eval ge t m <> None). Proof. - induction l as [|t l]; simpl; try (tauto). + induction l as [|t l]; cbn; try (tauto). destruct l. - intuition (congruence || eauto). - rewrite IHl; clear IHl. intuition (congruence || eauto). Qed. +(** * Rewriting rules in the symbolic execution *) + +(** The symbolic execution is parametrized by rewriting rules on pseudo-terms. *) + Record pseudo_term: Type := intro_fail { mayfail: list term; effect: term }. +(** Simulation relation between a term and a pseudo-term *) + +Definition match_pt (t: term) (pt: pseudo_term) := + (forall ge m, term_eval ge t m <> None <-> allvalid ge pt.(mayfail) m) + /\ (forall ge m0 m1, term_eval ge t m0 = Some m1 -> term_eval ge pt.(effect) m0 = Some m1). + Lemma inf_option_equivalence (A:Type) (o1 o2: option A): (o1 <> None -> o1 = o2) <-> (forall m1, o1 = Some m1 -> o2 = Some m1). Proof. @@ -346,26 +362,24 @@ Proof. symmetry; eauto. Qed. -Definition match_pt (t: term) (pt: pseudo_term) := - (forall ge m, term_eval ge t m <> None <-> allvalid ge pt.(mayfail) m) - /\ (forall ge m0 m1, term_eval ge t m0 = Some m1 -> term_eval ge pt.(effect) m0 = Some m1). - Lemma intro_fail_correct (l: list term) (t: term) : (forall ge m, term_eval ge t m <> None <-> allvalid ge l m) -> match_pt t (intro_fail l t). Proof. - unfold match_pt; simpl; intros; intuition congruence. + unfold match_pt; cbn; intros; intuition congruence. Qed. Hint Resolve intro_fail_correct: wlp. +(** The default reduction of a term to a pseudo-term *) Definition identity_fail (t: term):= intro_fail [t] t. Lemma identity_fail_correct (t: term): match_pt t (identity_fail t). Proof. - eapply intro_fail_correct; simpl; tauto. + eapply intro_fail_correct; cbn; tauto. Qed. Global Opaque identity_fail. Hint Resolve identity_fail_correct: wlp. +(** The reduction for constant term *) Definition nofail (is_constant: op -> bool) (t: term):= match t with | Input x _ => intro_fail ([])%list t @@ -376,15 +390,16 @@ Definition nofail (is_constant: op -> bool) (t: term):= Lemma nofail_correct (is_constant: op -> bool) t: (forall ge o, is_constant o = true -> op_eval ge o nil <> None) -> match_pt t (nofail is_constant t). Proof. - destruct t; simpl. - + intros; eapply intro_fail_correct; simpl; intuition congruence. - + intros; destruct l; simpl; auto with wlp. - destruct (is_constant o) eqn:Heqo; simpl; intuition eauto with wlp. - eapply intro_fail_correct; simpl; intuition eauto with wlp. + destruct t; cbn. + + intros; eapply intro_fail_correct; cbn; intuition congruence. + + intros; destruct l; cbn; auto with wlp. + destruct (is_constant o) eqn:Heqo; cbn; intuition eauto with wlp. + eapply intro_fail_correct; cbn; intuition eauto with wlp. Qed. Global Opaque nofail. Hint Resolve nofail_correct: wlp. +(** Term equivalence preserve the simulation by pseudo-terms *) Definition term_equiv t1 t2:= forall ge m, term_eval ge t1 m = term_eval ge t2 m. Global Instance term_equiv_Equivalence : Equivalence term_equiv. @@ -401,6 +416,7 @@ Proof. Qed. Hint Resolve match_pt_term_equiv: wlp. +(** Other generic reductions *) Definition app_fail (l: list term) (pt: pseudo_term): pseudo_term := {| mayfail := List.rev_append l pt.(mayfail); effect := pt.(effect) |}. @@ -409,7 +425,7 @@ Lemma app_fail_allvalid_correct l pt t1 t2: forall (V2: forall (ge : genv) (m : mem), term_eval ge t2 m <> None <-> allvalid ge (mayfail {| mayfail := t1 :: l; effect := t1 |}) m) (ge : genv) (m : mem), term_eval ge t2 m <> None <-> allvalid ge (mayfail (app_fail l pt)) m. Proof. - intros; generalize (V1 ge m) (V2 ge m); rewrite !allvalid_extensionality; simpl. clear V1 V2. + intros; generalize (V1 ge m) (V2 ge m); rewrite !allvalid_extensionality; cbn. clear V1 V2. intuition subst. + rewrite rev_append_rev, in_app_iff, <- in_rev in H3. destruct H3; eauto. + eapply H3; eauto. @@ -431,6 +447,8 @@ Extraction Inline app_fail. Import ImpCore.Notations. Local Open Scope impure_scope. +(** Specification of rewriting functions in parameter of the symbolic execution: in the impure monad, because the rewriting functions produce hash-consed terms (wrapped in pseudo-terms). +*) Record reduction:= { result:> term -> ?? pseudo_term; result_correct: forall t, WHEN result t ~> pt THEN match_pt t pt; diff --git a/kvx/abstractbb/ImpSimuTest.v b/kvx/abstractbb/ImpSimuTest.v index c914eee1..b1a3b985 100644 --- a/kvx/abstractbb/ImpSimuTest.v +++ b/kvx/abstractbb/ImpSimuTest.v @@ -10,13 +10,16 @@ (* *) (* *************************************************************) -(** Implementation of a symbolic execution of sequential semantics of Abstract Basic Blocks +(** Implementation of a simulation test (ie a "scheduling verifier") for the sequential semantics of Abstract Basic Blocks. + +It is based on a symbolic execution procedure of Abstract Basic Blocks with imperative hash-consing and rewriting. + +It also provides debugging information when the test fails. -with imperative hash-consing, and rewriting. *) -Require Export Impure.ImpHCons. +Require Export Impure.ImpHCons. (**r Import the Impure library. See https://github.com/boulme/ImpureDemo *) Export Notations. Import HConsing. @@ -32,6 +35,7 @@ Import ListNotations. Local Open Scope list_scope. +(** * Interface of (impure) equality tests for operators *) Module Type ImpParam. Include LangParam. @@ -54,6 +58,8 @@ Include MkSeqLanguage LP. End ISeqLanguage. +(** * A generic dictinary on PseudoRegisters with an impure equality test *) + Module Type ImpDict. Declare Module R: PseudoRegisters. @@ -91,26 +97,27 @@ Parameter eq_test_correct: forall A (d1 d2: t A), (* NB: we could also take an eq_test on R.t (but not really useful with "pure" dictionaries *) - -(* only for debugging *) +(** only for debugging *) Parameter not_eq_witness: forall {A}, t A -> t A -> ?? option R.t. End ImpDict. +(** * Specification of the provided tests *) Module Type ImpSimuInterface. Declare Module CoreL: ISeqLanguage. Import CoreL. Import Terms. +(** the silent test (without debugging informations) *) Parameter bblock_simu_test: reduction -> bblock -> bblock -> ?? bool. Parameter bblock_simu_test_correct: forall reduce (p1 p2 : bblock), WHEN bblock_simu_test reduce p1 p2 ~> b THEN b = true -> forall ge : genv, bblock_simu ge p1 p2. - +(** the verbose test extended with debugging informations *) Parameter verb_bblock_simu_test : reduction -> (R.t -> ?? pstring) -> @@ -127,6 +134,7 @@ Parameter verb_bblock_simu_test_correct: End ImpSimuInterface. +(** * Implementation of the provided tests *) Module ImpSimu (L: ISeqLanguage) (Dict: ImpDict with Module R:=L.LP.R): ImpSimuInterface with Module CoreL := L. @@ -152,13 +160,13 @@ Definition list_term_set_hid (l: list_term) (hid: hashcode): list_term := Lemma term_eval_set_hid ge t hid m: term_eval ge (term_set_hid t hid) m = term_eval ge t m. Proof. - destruct t; simpl; auto. + destruct t; cbn; auto. Qed. Lemma list_term_eval_set_hid ge l hid m: list_term_eval ge (list_term_set_hid l hid) m = list_term_eval ge l m. Proof. - destruct l; simpl; auto. + destruct l; cbn; auto. Qed. (* Local nickname *) @@ -168,7 +176,7 @@ Section SimuWithReduce. Variable reduce: reduction. -Section CanonBuilding. +Section CanonBuilding. (** Implementation of the symbolic execution (ie a "canonical form" representing the semantics of an abstract basic block) *) Variable hC_term: hashinfo term -> ?? term. Hypothesis hC_term_correct: forall t, WHEN hC_term t ~> t' THEN forall ge m, term_eval ge (hdata t) m = term_eval ge t' m. @@ -307,7 +315,7 @@ Proof. destruct (DM0 m) as (PRE & VALID0); clear DM0. assert (VALID1: allvalid ge hd.(hpre) m -> pre d ge m). { unfold smem_valid in PRE; tauto. } assert (VALID2: allvalid ge hd.(hpre) m -> forall x : Dict.R.t, ST.term_eval ge (d x) m <> None). { unfold smem_valid in PRE; tauto. } - rewrite !allvalid_extensionality in * |- *; simpl. + rewrite !allvalid_extensionality in * |- *; cbn. intuition (subst; eauto). + eapply smem_valid_set_proof; eauto. erewrite <- EQT; eauto. @@ -315,11 +323,11 @@ Proof. intros X1; exploit smem_valid_set_decompose_2; eauto. rewrite <- EQT; eauto. + exploit smem_valid_set_decompose_1; eauto. - - clear DM0. unfold hsmem_post_eval, hsmem_post_eval in * |- *; simpl. + - clear DM0. unfold hsmem_post_eval, hsmem_post_eval in * |- *; cbn. Local Hint Resolve smem_valid_set_decompose_1: core. intros; case (R.eq_dec x x0). - + intros; subst; rewrite !Dict.set_spec_eq; simpl; eauto. - + intros; rewrite !Dict.set_spec_diff; simpl; eauto. + + intros; subst; rewrite !Dict.set_spec_eq; cbn; eauto. + + intros; rewrite !Dict.set_spec_diff; cbn; eauto. Qed. Local Hint Resolve naive_set_correct: core. @@ -396,10 +404,10 @@ Lemma hterm_append_correct l: forall lh, WHEN hterm_append l lh ~> lh' THEN (forall ge m, allvalid ge lh' m <-> (allvalid ge l m /\ allvalid ge lh m)). Proof. Local Hint Resolve eq_trans: localhint. - induction l as [|t l']; simpl; wlp_xsimplify ltac:(eauto with wlp). + induction l as [|t l']; cbn; wlp_xsimplify ltac:(eauto with wlp). - intros; rewrite! allvalid_extensionality; intuition eauto. - intros REC ge m; rewrite REC; clear IHl' REC. rewrite !allvalid_extensionality. - simpl; intuition (subst; eauto with wlp localhint). + cbn; intuition (subst; eauto with wlp localhint). Qed. (*Local Hint Resolve hterm_append_correct: wlp.*) Global Opaque hterm_append. @@ -423,8 +431,8 @@ Lemma smart_set_correct hd x ht: forall ge m y, hsmem_post_eval ge d y m = hsmem_post_eval ge (Dict.set hd x ht) y m. Proof. destruct ht; wlp_simplify. - unfold hsmem_post_eval; simpl. case (R.eq_dec x0 y). - - intros; subst. rewrite Dict.set_spec_eq, Dict.rem_spec_eq. simpl; congruence. + unfold hsmem_post_eval; cbn. case (R.eq_dec x0 y). + - intros; subst. rewrite Dict.set_spec_eq, Dict.rem_spec_eq. cbn; congruence. - intros; rewrite Dict.set_spec_diff, Dict.rem_spec_diff; auto. Qed. (*Local Hint Resolve smart_set_correct: wlp.*) @@ -448,17 +456,17 @@ Proof. generalize (hterm_append_correct _ _ _ Hexta0); intro APPEND. generalize (hterm_lift_correct _ _ Hexta1); intro LIFT. generalize (smart_set_correct _ _ _ _ Hexta3); intro SMART. - eapply equiv_hsmem_models; eauto; unfold equiv_hsmem; simpl. + eapply equiv_hsmem_models; eauto; unfold equiv_hsmem; cbn. destruct H as (VALID & EFFECT); split. - intros; rewrite APPEND, <- VALID. - rewrite !allvalid_extensionality in * |- *; simpl; intuition (subst; eauto). + rewrite !allvalid_extensionality in * |- *; cbn; intuition (subst; eauto). - intros m x0 ALLVALID; rewrite SMART. destruct (term_eval ge ht m) eqn: Hht. * case (R.eq_dec x x0). - + intros; subst. unfold hsmem_post_eval; simpl. rewrite !Dict.set_spec_eq. + + intros; subst. unfold hsmem_post_eval; cbn. rewrite !Dict.set_spec_eq. erewrite LIFT, EFFECT; eauto. - + intros; unfold hsmem_post_eval; simpl. rewrite !Dict.set_spec_diff; auto. - * rewrite allvalid_extensionality in ALLVALID; destruct (ALLVALID ht); simpl; auto. + + intros; unfold hsmem_post_eval; cbn. rewrite !Dict.set_spec_diff; auto. + * rewrite allvalid_extensionality in ALLVALID; destruct (ALLVALID ht); cbn; auto. Qed. Local Hint Resolve hsmem_set_correct: wlp. Global Opaque hsmem_set. @@ -473,7 +481,7 @@ Proof. intro H. induction e using exp_mut with (P0:=fun le => forall d hd, smem_model ge d hd -> forall m, smem_valid ge d m -> smem_valid ge od m -> list_term_eval ge (list_exp_term le hd hod) m = list_term_eval ge (list_exp_term le d od) m); - unfold smem_model in * |- * ; simpl; intuition eauto. + unfold smem_model in * |- * ; cbn; intuition eauto. - erewrite IHe; eauto. - erewrite IHe0, IHe; eauto. Qed. @@ -508,10 +516,10 @@ Lemma exp_hterm_correct_x ge e hod od: induction e using exp_mut with (P0:=fun le => forall d hd, smem_model ge d hd -> WHEN list_exp_hterm le hd hod ~> lt THEN forall m, smem_valid ge d m -> smem_valid ge od m -> list_term_eval ge lt m = ST.list_term_eval ge (list_exp_term le d od) m); - unfold smem_model, hsmem_post_eval in * |- * ; simpl; wlp_simplify. + unfold smem_model, hsmem_post_eval in * |- * ; cbn; wlp_simplify. - rewrite H1, <- H4; auto. - - rewrite H4, <- H0; simpl; auto. - - rewrite H5, <- H0, <- H4; simpl; auto. + - rewrite H4, <- H0; cbn; auto. + - rewrite H5, <- H0, <- H4; cbn; auto. Qed. Global Opaque exp_hterm. @@ -536,7 +544,7 @@ Lemma hinst_smem_correct i: forall hd hod, forall ge od d, smem_model ge od hod -> smem_model ge d hd -> (forall m, smem_valid ge d m -> smem_valid ge od m) -> smem_model ge (inst_smem i d od) hd'. Proof. Local Hint Resolve smem_valid_set_proof: core. - induction i; simpl; wlp_simplify; eauto 15 with wlp. + induction i; cbn; wlp_simplify; eauto 15 with wlp. Qed. Global Opaque hinst_smem. Local Hint Resolve hinst_smem_correct: wlp. @@ -556,7 +564,7 @@ Fixpoint bblock_hsmem_rec (p: bblock) (d: hsmem): ?? hsmem := Lemma bblock_hsmem_rec_correct p: forall hd, WHEN bblock_hsmem_rec p hd ~> hd' THEN forall ge d, smem_model ge d hd -> smem_model ge (bblock_smem_rec p d) hd'. Proof. - induction p; simpl; wlp_simplify. + induction p; cbn; wlp_simplify. Qed. Global Opaque bblock_hsmem_rec. Local Hint Resolve bblock_hsmem_rec_correct: wlp. @@ -565,8 +573,8 @@ Definition hsmem_empty: hsmem := {| hpre:= nil ; hpost := Dict.empty |}. Lemma hsmem_empty_correct ge: smem_model ge smem_empty hsmem_empty. Proof. - unfold smem_model, smem_valid, hsmem_post_eval; simpl; intuition try congruence. - rewrite !Dict.empty_spec; simpl; auto. + unfold smem_model, smem_valid, hsmem_post_eval; cbn; intuition try congruence. + rewrite !Dict.empty_spec; cbn; auto. Qed. Definition bblock_hsmem: bblock -> ?? hsmem @@ -714,7 +722,7 @@ Theorem g_bblock_simu_test_correct p1 p2: WHEN g_bblock_simu_test p1 p2 ~> b THEN b=true -> forall ge, bblock_simu ge p1 p2. Proof. wlp_simplify. - destruct exta0; simpl in * |- *; auto. + destruct exta0; cbn in * |- *; auto. Qed. Global Opaque g_bblock_simu_test. @@ -1117,9 +1125,9 @@ Extraction Inline lift. End ImpSimu. -Require Import FMapPositive. - +(** * Implementation of the Dictionary (based on PositiveMap) *) +Require Import FMapPositive. Require Import PArith. Require Import FMapPositive. @@ -1201,12 +1209,12 @@ Lemma eq_test_correct A d1: forall (d2: t A), WHEN eq_test d1 d2 ~> b THEN b=true -> forall x, get d1 x = get d2 x. Proof. - unfold get; induction d1 as [|l1 Hl1 [x1|] r1 Hr1]; destruct d2 as [|l2 [x2|] r2]; simpl; - wlp_simplify; (discriminate || (subst; destruct x; simpl; auto)). + unfold get; induction d1 as [|l1 Hl1 [x1|] r1 Hr1]; destruct d2 as [|l2 [x2|] r2]; cbn; + wlp_simplify; (discriminate || (subst; destruct x; cbn; auto)). Qed. Global Opaque eq_test. -(* ONLY FOR DEBUGGING INFO: get some key of a non-empty d *) +(** ONLY FOR DEBUGGING INFO: get some key of a non-empty d *) Fixpoint pick {A} (d: t A): ?? R.t := match d with | Leaf _ => FAILWITH "unexpected empty dictionary" @@ -1219,7 +1227,7 @@ Fixpoint pick {A} (d: t A): ?? R.t := RET (xO p) end. -(* ONLY FOR DEBUGGING INFO: find one variable on which d1 and d2 differs *) +(** ONLY FOR DEBUGGING INFO: find one variable on which d1 and d2 differs *) Fixpoint not_eq_witness {A} (d1 d2: t A): ?? option R.t := match d1, d2 with | Leaf _, Leaf _ => RET None diff --git a/kvx/abstractbb/Parallelizability.v b/kvx/abstractbb/Parallelizability.v index feebeee5..e5d21434 100644 --- a/kvx/abstractbb/Parallelizability.v +++ b/kvx/abstractbb/Parallelizability.v @@ -26,7 +26,7 @@ Require Import Sorting.Permutation. Require Import Bool. Local Open Scope lazy_bool_scope. - +(** * Definition of the parallel semantics *) Module ParallelSemantics (L: SeqLanguage). Export L. @@ -50,8 +50,8 @@ Fixpoint inst_prun (i: inst) (m tmp old: mem): option mem := Lemma inst_run_prun i: forall m old, inst_run ge i m old = inst_prun i m m old. Proof. - induction i as [|[y e] i']; simpl; auto. - intros m old; destruct (exp_eval ge e m old); simpl; auto. + induction i as [|[y e] i']; cbn; auto. + intros m old; destruct (exp_eval ge e m old); cbn; auto. Qed. @@ -76,8 +76,8 @@ Lemma inst_prun_equiv i old: forall m1 m2 tmp, (forall x, m1 x = m2 x) -> res_eq (inst_prun i m1 tmp old) (inst_prun i m2 tmp old). Proof. - induction i as [|[x e] i']; simpl; eauto. - intros m1 m2 tmp H; destruct (exp_eval ge e tmp old); simpl; auto. + induction i as [|[x e] i']; cbn; eauto. + intros m1 m2 tmp H; destruct (exp_eval ge e tmp old); cbn; auto. eapply IHi'; unfold assign. intros; destruct (R.eq_dec x x0); auto. Qed. @@ -85,12 +85,12 @@ Lemma prun_iw_equiv p: forall m1 m2 old, (forall x, m1 x = m2 x) -> res_eq (prun_iw p m1 old) (prun_iw p m2 old). Proof. - induction p as [|i p']; simpl; eauto. + induction p as [|i p']; cbn; eauto. - intros m1 m2 old H. generalize (inst_prun_equiv i old m1 m2 old H); - destruct (inst_prun i m1 old old); simpl. - + intros (m3 & H3 & H4); rewrite H3; simpl; eauto. - + intros H1; rewrite H1; simpl; auto. + destruct (inst_prun i m1 old old); cbn. + + intros (m3 & H3 & H4); rewrite H3; cbn; eauto. + + intros H1; rewrite H1; cbn; auto. Qed. @@ -101,8 +101,8 @@ Lemma prun_iw_app p1: forall m1 old p2, | None => None end. Proof. - induction p1; simpl; try congruence. - intros; destruct (inst_prun _ _ _); simpl; auto. + induction p1; cbn; try congruence. + intros; destruct (inst_prun _ _ _); cbn; auto. Qed. Lemma prun_iw_app_None p1: forall m1 old p2, @@ -132,12 +132,12 @@ Fixpoint notIn {A} (x: A) (l:list A): Prop := Lemma notIn_iff A (x:A) l: (~List.In x l) <-> notIn x l. Proof. - induction l; simpl; intuition. + induction l; cbn; intuition. Qed. Lemma notIn_app A (x:A) l1: forall l2, notIn x (l1++l2) <-> (notIn x l1 /\ notIn x l2). Proof. - induction l1; simpl. + induction l1; cbn. - intuition. - intros; rewrite IHl1. intuition. Qed. @@ -145,7 +145,7 @@ Qed. Lemma In_Permutation A (l1 l2: list A): Permutation l1 l2 -> forall x, In x l1 -> In x l2. Proof. - induction 1; simpl; intuition. + induction 1; cbn; intuition. Qed. Lemma Permutation_incl A (l1 l2: list A): Permutation l1 l2 -> incl l1 l2. @@ -174,7 +174,7 @@ Qed. Lemma disjoint_cons_l A (x:A) (l1 l2: list A): disjoint (x::l1) l2 <-> (notIn x l2) /\ (disjoint l1 l2). Proof. - unfold disjoint. simpl; intuition subst; auto. + unfold disjoint. cbn; intuition subst; auto. Qed. Lemma disjoint_cons_r A (x:A) (l1 l2: list A): disjoint l1 (x::l2) <-> (notIn x l1) /\ (disjoint l1 l2). @@ -230,13 +230,13 @@ Fixpoint frame_assign m1 (f: list R.t) m2 := Lemma frame_assign_def f: forall m1 m2 x, frame_assign m1 f m2 x = if notIn_dec x f then m1 x else m2 x. Proof. - induction f as [|y f] ; simpl; auto. - - intros; destruct (notIn_dec x []); simpl in *; tauto. - - intros; rewrite IHf; destruct (notIn_dec x (y::f)); simpl in *. - + destruct (notIn_dec x f); simpl in *; intuition. + induction f as [|y f] ; cbn; auto. + - intros; destruct (notIn_dec x []); cbn in *; tauto. + - intros; rewrite IHf; destruct (notIn_dec x (y::f)); cbn in *. + + destruct (notIn_dec x f); cbn in *; intuition. rewrite assign_diff; auto. rewrite <- notIn_iff in *; intuition. - + destruct (notIn_dec x f); simpl in *; intuition subst. + + destruct (notIn_dec x f); cbn in *; intuition subst. rewrite assign_eq; auto. rewrite <- notIn_iff in *; intuition. Qed. @@ -266,7 +266,7 @@ Lemma frame_eq_list_split f1 (f2: R.t -> Prop) om1 om2: (forall m1 m2 x, om1 = Some m1 -> om2 = Some m2 -> f2 x -> notIn x f1 -> m1 x = m2 x) -> frame_eq f2 om1 om2. Proof. - unfold frame_eq; destruct om1 as [ m1 | ]; simpl; auto. + unfold frame_eq; destruct om1 as [ m1 | ]; cbn; auto. intros (m2 & H0 & H1); subst. intros H. eexists; intuition eauto. @@ -280,7 +280,7 @@ Lemma frame_eq_res_eq f om1 om2: res_eq om1 om2. Proof. intros H H0; lapply (frame_eq_list_split f (fun _ => True) om1 om2 H); eauto. - clear H H0; unfold frame_eq, res_eq. destruct om1; simpl; firstorder. + clear H H0; unfold frame_eq, res_eq. destruct om1; cbn; firstorder. Qed. *) @@ -296,9 +296,9 @@ Lemma inst_wframe_correct i m' old: forall m tmp, inst_prun ge i m tmp old = Some m' -> forall x, notIn x (inst_wframe i) -> m' x = m x. Proof. - induction i as [|[y e] i']; simpl. + induction i as [|[y e] i']; cbn. - intros m tmp H x H0; inversion_clear H; auto. - - intros m tmp H x (H1 & H2); destruct (exp_eval ge e tmp old); simpl; try congruence. + - intros m tmp H x (H1 & H2); destruct (exp_eval ge e tmp old); cbn; try congruence. cutrewrite (m x = assign m y v x); eauto. rewrite assign_diff; auto. Qed. @@ -306,9 +306,9 @@ Qed. Lemma inst_prun_fequiv i old: forall m1 m2 tmp, frame_eq (fun x => In x (inst_wframe i)) (inst_prun ge i m1 tmp old) (inst_prun ge i m2 tmp old). Proof. - induction i as [|[y e] i']; simpl. + induction i as [|[y e] i']; cbn. - intros m1 m2 tmp; eexists; intuition eauto. - - intros m1 m2 tmp. destruct (exp_eval ge e tmp old); simpl; auto. + - intros m1 m2 tmp. destruct (exp_eval ge e tmp old); cbn; auto. eapply frame_eq_list_split; eauto. clear IHi'. intros m1' m2' x H1 H2. lapply (inst_wframe_correct i' m1' old (assign m1 y v) (assign tmp y v)); eauto. @@ -323,7 +323,7 @@ Lemma inst_prun_None i m1 m2 tmp old: inst_prun ge i m2 tmp old = None. Proof. intros H; generalize (inst_prun_fequiv i old m1 m2 tmp). - rewrite H; simpl; auto. + rewrite H; cbn; auto. Qed. Lemma inst_prun_Some i m1 m2 tmp old m1': @@ -331,7 +331,7 @@ Lemma inst_prun_Some i m1 m2 tmp old m1': res_eq (Some (frame_assign m2 (inst_wframe i) m1')) (inst_prun ge i m2 tmp old). Proof. intros H; generalize (inst_prun_fequiv i old m1 m2 tmp). - rewrite H; simpl. + rewrite H; cbn. intros (m2' & H1 & H2). eexists; intuition eauto. rewrite frame_assign_def. @@ -351,7 +351,7 @@ Local Hint Resolve Permutation_app_head Permutation_app_tail Permutation_app_com Lemma bblock_wframe_Permutation p p': Permutation p p' -> Permutation (bblock_wframe p) (bblock_wframe p'). Proof. - induction 1 as [|i p p'|i1 i2 p|p1 p2 p3]; simpl; auto. + induction 1 as [|i p p'|i1 i2 p|p1 p2 p3]; cbn; auto. - rewrite! app_assoc; auto. - eapply Permutation_trans; eauto. Qed. @@ -361,11 +361,11 @@ Lemma bblock_wframe_correct p m' old: forall m, prun_iw p m old = Some m' -> forall x, notIn x (bblock_wframe p) -> m' x = m x. Proof. - induction p as [|i p']; simpl. + induction p as [|i p']; cbn. - intros m H; inversion_clear H; auto. - intros m H x; rewrite notIn_app; intros (H1 & H2). remember (inst_prun i m old old) as om. - destruct om as [m1|]; simpl. + destruct om as [m1|]; cbn. + eapply eq_trans. eapply IHp'; eauto. eapply inst_wframe_correct; eauto. @@ -375,12 +375,12 @@ Qed. Lemma prun_iw_fequiv p old: forall m1 m2, frame_eq (fun x => In x (bblock_wframe p)) (prun_iw p m1 old) (prun_iw p m2 old). Proof. - induction p as [|i p']; simpl. + induction p as [|i p']; cbn. - intros m1 m2; eexists; intuition eauto. - intros m1 m2; generalize (inst_prun_fequiv i old m1 m2 old). remember (inst_prun i m1 old old) as om. - destruct om as [m1'|]; simpl. - + intros (m2' & H1 & H2). rewrite H1; simpl. + destruct om as [m1'|]; cbn. + + intros (m2' & H1 & H2). rewrite H1; cbn. eapply frame_eq_list_split; eauto. clear IHp'. intros m1'' m2'' x H3 H4. rewrite in_app_iff. intros X X2. assert (X1: In x (inst_wframe i)). { destruct X; auto. rewrite <- notIn_iff in X2; tauto. } @@ -389,7 +389,7 @@ Proof. lapply (bblock_wframe_correct p' m2'' old m2'); eauto. intros Xm2' Xm1'. rewrite Xm1', Xm2'; auto. - + intro H; rewrite H; simpl; auto. + + intro H; rewrite H; cbn; auto. Qed. Lemma prun_iw_equiv p m1 m2 old: @@ -418,7 +418,7 @@ Fixpoint is_det (p: bblock): Prop := Lemma is_det_Permutation p p': Permutation p p' -> is_det p -> is_det p'. Proof. - induction 1; simpl; auto. + induction 1; cbn; auto. - intros; intuition. eapply disjoint_incl_r. 2: eauto. eapply Permutation_incl. eapply Permutation_sym. eapply bblock_wframe_Permutation; auto. @@ -431,20 +431,20 @@ Theorem is_det_correct p p': is_det p -> forall m old, res_eq (prun_iw ge p m old) (prun_iw ge p' m old). Proof. - induction 1 as [ | i p p' | i1 i2 p |Â p1 p2 p3 ]; simpl; eauto. + induction 1 as [ | i p p' | i1 i2 p |Â p1 p2 p3 ]; cbn; eauto. - intros [H0 H1] m old. remember (inst_prun ge i m old old) as om0. - destruct om0 as [ m0 | ]; simpl; auto. + destruct om0 as [ m0 | ]; cbn; auto. - rewrite disjoint_app_r. intros ([Z1 Z2] & Z3 & Z4) m old. remember (inst_prun ge i2 m old old) as om2. - destruct om2 as [ m2 | ]; simpl; auto. + destruct om2 as [ m2 | ]; cbn; auto. + remember (inst_prun ge i1 m old old) as om1. - destruct om1 as [ m1 | ]; simpl; auto. - * lapply (inst_prun_Some i2 m m1 old old m2); simpl; auto. - lapply (inst_prun_Some i1 m m2 old old m1); simpl; auto. + destruct om1 as [ m1 | ]; cbn; auto. + * lapply (inst_prun_Some i2 m m1 old old m2); cbn; auto. + lapply (inst_prun_Some i1 m m2 old old m1); cbn; auto. intros (m1' & Hm1' & Xm1') (m2' & Hm2' & Xm2'). - rewrite Hm1', Hm2'; simpl. + rewrite Hm1', Hm2'; cbn. eapply prun_iw_equiv. intros x; rewrite <- Xm1', <- Xm2'. clear Xm2' Xm1' Hm1' Hm2' m1' m2'. rewrite frame_assign_def. @@ -455,9 +455,9 @@ Proof. erewrite (inst_wframe_correct i1 m1 old m old); eauto. } rewrite frame_assign_notIn; auto. - * erewrite inst_prun_None; eauto. simpl; auto. + * erewrite inst_prun_None; eauto. cbn; auto. + remember (inst_prun ge i1 m old old) as om1. - destruct om1 as [ m1 | ]; simpl; auto. + destruct om1 as [ m1 | ]; cbn; auto. erewrite inst_prun_None; eauto. - intros; eapply res_eq_trans. eapply IHPermutation1; eauto. @@ -486,7 +486,7 @@ Lemma exp_frame_correct e old1 old2: (exp_eval ge e m1 old1)=(exp_eval ge e m2 old2). Proof. induction e using exp_mut with (P0:=fun l => (forall x, In x (list_exp_frame l) -> old1 x = old2 x) -> forall m1 m2, (forall x, In x (list_exp_frame l) -> m1 x = m2 x) -> - (list_exp_eval ge l m1 old1)=(list_exp_eval ge l m2 old2)); simpl; auto. + (list_exp_eval ge l m1 old1)=(list_exp_eval ge l m2 old2)); cbn; auto. - intros H1 m1 m2 H2; rewrite H2; auto. - intros H1 m1 m2 H2; erewrite IHe; eauto. - intros H1 m1 m2 H2; erewrite IHe, IHe0; eauto; @@ -501,7 +501,7 @@ Fixpoint inst_frame (i: inst): list R.t := Lemma inst_wframe_frame i x: In x (inst_wframe i) -> In x (inst_frame i). Proof. - induction i as [ | [y e] i']; simpl; intuition. + induction i as [ | [y e] i']; cbn; intuition. Qed. @@ -511,13 +511,13 @@ Lemma inst_frame_correct i wframe old1 old2: forall m tmp1 tmp2, (forall x, notIn x wframe -> tmp1 x = tmp2 x) -> inst_prun ge i m tmp1 old1 = inst_prun ge i m tmp2 old2. Proof. - induction i as [|[x e] i']; simpl; auto. + induction i as [|[x e] i']; cbn; auto. intros m tmp1 tmp2; rewrite disjoint_cons_l, disjoint_app_l. intros (H1 & H2 & H3) H6 H7. cutrewrite (exp_eval ge e tmp1 old1 = exp_eval ge e tmp2 old2). - destruct (exp_eval ge e tmp2 old2); auto. eapply IHi'; eauto. - simpl; intros x0 H0; unfold assign. destruct (R.eq_dec x x0); simpl; auto. + cbn; intros x0 H0; unfold assign. destruct (R.eq_dec x x0); cbn; auto. - unfold disjoint in H2; apply exp_frame_correct. intros;apply H6; auto. intros;apply H7; auto. @@ -535,8 +535,8 @@ Fixpoint pararec (p: bblock) (wframe: list R.t): Prop := Lemma pararec_disjoint (p: bblock): forall wframe, pararec p wframe -> disjoint (bblock_wframe p) wframe. Proof. - induction p as [|i p']; simpl. - - unfold disjoint; simpl; intuition. + induction p as [|i p']; cbn. + - unfold disjoint; cbn; intuition. - intros wframe [H0 H1]; rewrite disjoint_app_l. generalize (IHp' _ H1). rewrite disjoint_app_r. intuition. @@ -546,7 +546,7 @@ Qed. Lemma pararec_det p: forall wframe, pararec p wframe -> is_det p. Proof. - induction p as [|i p']; simpl; auto. + induction p as [|i p']; cbn; auto. intros wframe [H0 H1]. generalize (pararec_disjoint _ _ H1). rewrite disjoint_app_r. intuition. - apply disjoint_sym; auto. @@ -558,7 +558,7 @@ Lemma pararec_correct p old: forall wframe m, (forall x, notIn x wframe -> m x = old x) -> run ge p m = prun_iw ge p m old. Proof. - elim p; clear p; simpl; auto. + elim p; clear p; cbn; auto. intros i p' X wframe m [H H0] H1. erewrite inst_run_prun, inst_frame_correct; eauto. remember (inst_prun ge i m old old) as om0. @@ -590,17 +590,17 @@ End PARALLELI. End ParallelizablityChecking. -Module Type PseudoRegSet. - -Declare Module R: PseudoRegisters. - -(** We assume a datatype [t] refining (list R.t) +(** * We assume a datatype [PseudoRegSet.t] refining [list R.t] *) +(** This data-refinement is given by an abstract "invariant" match_frame below, preserved by the following operations. - *) +Module Type PseudoRegSet. + +Declare Module R: PseudoRegisters. + Parameter t: Type. Parameter match_frame: t -> (list R.t) -> Prop. @@ -646,7 +646,7 @@ Fixpoint inst_wsframe(i:inst): S.t := Lemma inst_wsframe_correct i: S.match_frame (inst_wsframe i) (inst_wframe i). Proof. - induction i; simpl; auto. + induction i; cbn; auto. Qed. Fixpoint exp_sframe (e: exp): S.t := @@ -664,7 +664,7 @@ with list_exp_sframe (le: list_exp): S.t := Lemma exp_sframe_correct e: S.match_frame (exp_sframe e) (exp_frame e). Proof. - induction e using exp_mut with (P0:=fun l => S.match_frame (list_exp_sframe l) (list_exp_frame l)); simpl; auto. + induction e using exp_mut with (P0:=fun l => S.match_frame (list_exp_sframe l) (list_exp_frame l)); cbn; auto. Qed. Fixpoint inst_sframe (i: inst): S.t := @@ -677,7 +677,7 @@ Local Hint Resolve exp_sframe_correct: core. Lemma inst_sframe_correct i: S.match_frame (inst_sframe i) (inst_frame i). Proof. - induction i as [|[y e] i']; simpl; auto. + induction i as [|[y e] i']; cbn; auto. Qed. Local Hint Resolve inst_wsframe_correct inst_sframe_correct: core. @@ -692,7 +692,7 @@ Fixpoint is_pararec (p: bblock) (wsframe: S.t): bool := Lemma is_pararec_correct (p: bblock): forall s l, S.match_frame s l -> (is_pararec p s)=true -> (pararec p l). Proof. - induction p; simpl; auto. + induction p; cbn; auto. intros s l H1 H2; rewrite lazy_andb_bool_true in H2. destruct H2 as [H2 H3]. constructor 1; eauto. Qed. @@ -716,6 +716,11 @@ End ParallelChecks. +(** * Implementing the datatype [PosPseudoRegSet.t] refining [list R.t] *) + +(* This data-refinement is given by an abstract "invariant" match_frame below, +preserved by the following operations. +*) Require Import PArith. Require Import MSets.MSetPositive. @@ -724,12 +729,6 @@ Module PosPseudoRegSet <: PseudoRegSet with Module R:=Pos. Module R:=Pos. -(** We assume a datatype [t] refining (list R.t) - -This data-refinement is given by an abstract "invariant" match_frame below, -preserved by the following operations. - -*) Definition t:=PositiveSet.t. @@ -740,14 +739,14 @@ Definition empty:=PositiveSet.empty. Lemma empty_match_frame: match_frame empty nil. Proof. - unfold match_frame, empty, PositiveSet.In; simpl; intuition. + unfold match_frame, empty, PositiveSet.In; cbn; intuition. Qed. Definition add: R.t -> t -> t := PositiveSet.add. Lemma add_match_frame: forall s x l, match_frame s l -> match_frame (add x s) (x::l). Proof. - unfold match_frame, add; simpl. + unfold match_frame, add; cbn. intros s x l H y. rewrite PositiveSet.add_spec, H. intuition. Qed. @@ -773,13 +772,13 @@ Fixpoint is_disjoint (s s': PositiveSet.t) : bool := Lemma is_disjoint_spec_true s: forall s', is_disjoint s s' = true -> forall x, PositiveSet.In x s -> PositiveSet.In x s' -> False. Proof. - unfold PositiveSet.In; induction s as [ |l IHl o r IHr]; simpl; try discriminate. - destruct s' as [|l' o' r']; simpl; try discriminate. + unfold PositiveSet.In; induction s as [ |l IHl o r IHr]; cbn; try discriminate. + destruct s' as [|l' o' r']; cbn; try discriminate. intros X. assert (H: ~(o = true /\ o'=true) /\ is_disjoint l l' = true /\ is_disjoint r r'=true). - { destruct o, o', (is_disjoint l l'), (is_disjoint r r'); simpl in X; intuition. } + { destruct o, o', (is_disjoint l l'), (is_disjoint r r'); cbn in X; intuition. } clear X; destruct H as (H & H1 & H2). - destruct x as [i|i|]; simpl; eauto. + destruct x as [i|i|]; cbn; eauto. Qed. Lemma is_disjoint_match_frame: forall s1 s2 l1 l2, match_frame s1 l1 -> match_frame s2 l2 -> (is_disjoint s1 s2)=true -> disjoint l1 l2. diff --git a/kvx/abstractbb/SeqSimuTheory.v b/kvx/abstractbb/SeqSimuTheory.v index 61f8f2ec..df6b9963 100644 --- a/kvx/abstractbb/SeqSimuTheory.v +++ b/kvx/abstractbb/SeqSimuTheory.v @@ -55,13 +55,14 @@ with list_term_eval ge (l: list_term) (m: mem) {struct l}: option (list value) : end end. -(* the symbolic memory: - - pre: pre-condition expressing that the computation has not yet abort on a None. - - post: the post-condition for each pseudo-register -*) -Record smem:= {pre: genv -> mem -> Prop; post:> R.t -> term}. - -(** initial symbolic memory *) +(** The (abstract) symbolic memory state *) +Record smem := +{ + pre: genv -> mem -> Prop; (**r pre-condition expressing that the computation has not yet abort on a None. *) + post:> R.t -> term (**r the output term computed on each pseudo-register *) +}. + +(** Initial symbolic memory state *) Definition smem_empty := {| pre:=fun _ _ => True; post:=(fun x => Input x) |}. Fixpoint exp_term (e: exp) (d old: smem) : term := @@ -78,11 +79,12 @@ with list_exp_term (le: list_exp) (d old: smem) : list_term := end. -(** assignment of the symbolic memory *) +(** assignment of the symbolic memory state *) Definition smem_set (d:smem) x (t:term) := {| pre:=(fun ge m => (term_eval ge (d x) m) <> None /\ (d.(pre) ge m)); post:=fun y => if R.eq_dec x y then t else d y |}. +(** Simulation theory: the theorem [bblock_smem_simu] ensures that the simulation between two abstract basic blocks is implied by the simulation between their symbolic execution. *) Section SIMU_THEORY. Variable ge: genv. @@ -90,13 +92,13 @@ Variable ge: genv. Lemma set_spec_eq d x t m: term_eval ge (smem_set d x t x) m = term_eval ge t m. Proof. - unfold smem_set; simpl; case (R.eq_dec x x); try congruence. + unfold smem_set; cbn; case (R.eq_dec x x); try congruence. Qed. Lemma set_spec_diff d x y t m: x <> y -> term_eval ge (smem_set d x t y) m = term_eval ge (d y) m. Proof. - unfold smem_set; simpl; case (R.eq_dec x y); try congruence. + unfold smem_set; cbn; case (R.eq_dec x y); try congruence. Qed. Fixpoint inst_smem (i: inst) (d old: smem): smem := @@ -121,15 +123,15 @@ Definition bblock_smem: bblock -> smem Lemma inst_smem_pre_monotonic i old: forall d m, (pre (inst_smem i d old) ge m) -> (pre d ge m). Proof. - induction i as [|[y e] i IHi]; simpl; auto. + induction i as [|[y e] i IHi]; cbn; auto. intros d a H; generalize (IHi _ _ H); clear H IHi. - unfold smem_set; simpl; intuition. + unfold smem_set; cbn; intuition. Qed. Lemma bblock_smem_pre_monotonic p: forall d m, (pre (bblock_smem_rec p d) ge m) -> (pre d ge m). Proof. - induction p as [|i p' IHp']; simpl; eauto. + induction p as [|i p' IHp']; cbn; eauto. intros d a H; eapply inst_smem_pre_monotonic; eauto. Qed. @@ -144,7 +146,7 @@ Proof. intro H. induction e using exp_mut with (P0:=fun l => forall (d:smem) m1, (forall x, term_eval ge (d x) m0 = Some (m1 x)) -> list_term_eval ge (list_exp_term l d od) m0 = list_exp_eval ge l m1 old); - simpl; auto. + cbn; auto. - intros; erewrite IHe; eauto. - intros. erewrite IHe, IHe0; eauto. Qed. @@ -154,12 +156,12 @@ Lemma inst_smem_abort i m0 x old: forall (d:smem), term_eval ge (d x) m0 = None -> term_eval ge (inst_smem i d old x) m0 = None. Proof. - induction i as [|[y e] i IHi]; simpl; auto. + induction i as [|[y e] i IHi]; cbn; auto. intros d VALID H; erewrite IHi; eauto. clear IHi. - unfold smem_set; simpl; destruct (R.eq_dec y x); auto. + unfold smem_set; cbn; destruct (R.eq_dec y x); auto. subst; generalize (inst_smem_pre_monotonic _ _ _ _ VALID); clear VALID. - unfold smem_set; simpl. intuition congruence. + unfold smem_set; cbn. intuition congruence. Qed. Lemma block_smem_rec_abort p m0 x: forall d, @@ -167,7 +169,7 @@ Lemma block_smem_rec_abort p m0 x: forall d, term_eval ge (d x) m0 = None -> term_eval ge (bblock_smem_rec p d x) m0 = None. Proof. - induction p; simpl; auto. + induction p; cbn; auto. intros d VALID H; erewrite IHp; eauto. clear IHp. eapply inst_smem_abort; eauto. Qed. @@ -179,13 +181,13 @@ Lemma inst_smem_Some_correct1 i m0 old (od:smem): (forall x, term_eval ge (d x) m0 = Some (m1 x)) -> forall x, term_eval ge (inst_smem i d od x) m0 = Some (m2 x). Proof. - intro X; induction i as [|[x e] i IHi]; simpl; intros m1 m2 d H. + intro X; induction i as [|[x e] i IHi]; cbn; intros m1 m2 d H. - inversion_clear H; eauto. - intros H0 x0. destruct (exp_eval ge e m1 old) eqn:Heqov; try congruence. refine (IHi _ _ _ _ _ _); eauto. clear x0; intros x0. - unfold assign, smem_set; simpl. destruct (R.eq_dec x x0); auto. + unfold assign, smem_set; cbn. destruct (R.eq_dec x x0); auto. subst; erewrite term_eval_exp; eauto. Qed. @@ -195,7 +197,7 @@ Lemma bblocks_smem_rec_Some_correct1 p m0: forall (m1 m2: mem) (d: smem), forall x, term_eval ge (bblock_smem_rec p d x) m0 = Some (m2 x). Proof. Local Hint Resolve inst_smem_Some_correct1: core. - induction p as [ | i p]; simpl; intros m1 m2 d H. + induction p as [ | i p]; cbn; intros m1 m2 d H. - inversion_clear H; eauto. - intros H0 x0. destruct (inst_run ge i m1 m1) eqn: Heqov. @@ -216,15 +218,15 @@ Lemma inst_smem_None_correct i m0 old (od: smem): (forall x, term_eval ge (d x) m0 = Some (m1 x)) -> inst_run ge i m1 old = None -> exists x, term_eval ge (inst_smem i d od x) m0 = None. Proof. - intro X; induction i as [|[x e] i IHi]; simpl; intros m1 d. + intro X; induction i as [|[x e] i IHi]; cbn; intros m1 d. - discriminate. - intros VALID H0. destruct (exp_eval ge e m1 old) eqn: Heqov. + refine (IHi _ _ _ _); eauto. - intros x0; unfold assign, smem_set; simpl. destruct (R.eq_dec x x0); auto. + intros x0; unfold assign, smem_set; cbn. destruct (R.eq_dec x x0); auto. subst; erewrite term_eval_exp; eauto. + intuition. - constructor 1 with (x:=x); simpl. + constructor 1 with (x:=x); cbn. apply inst_smem_abort; auto. rewrite set_spec_eq. erewrite term_eval_exp; eauto. @@ -239,14 +241,14 @@ Lemma inst_smem_Some_correct2 i m0 old (od: smem): res_eq (Some m2) (inst_run ge i m1 old). Proof. intro X. - induction i as [|[x e] i IHi]; simpl; intros m1 m2 d VALID H0. + induction i as [|[x e] i IHi]; cbn; intros m1 m2 d VALID H0. - intros H; eapply ex_intro; intuition eauto. generalize (H0 x); rewrite H. congruence. - intros H. destruct (exp_eval ge e m1 old) eqn: Heqov. + refine (IHi _ _ _ _ _ _); eauto. - intros x0; unfold assign, smem_set; simpl; destruct (R.eq_dec x x0); auto. + intros x0; unfold assign, smem_set; cbn; destruct (R.eq_dec x x0); auto. subst; erewrite term_eval_exp; eauto. + generalize (H x). rewrite inst_smem_abort; discriminate || auto. @@ -260,7 +262,7 @@ Lemma bblocks_smem_rec_Some_correct2 p m0: forall (m1 m2: mem) d, (forall x, term_eval ge (bblock_smem_rec p d x) m0 = Some (m2 x)) -> res_eq (Some m2) (run ge p m1). Proof. - induction p as [|i p]; simpl; intros m1 m2 d VALID H0. + induction p as [|i p]; cbn; intros m1 m2 d VALID H0. - intros H; eapply ex_intro; intuition eauto. generalize (H0 x); rewrite H. congruence. @@ -291,13 +293,13 @@ Lemma inst_valid i m0 old (od:smem): (forall x, term_eval ge (d x) m0 = Some (m1 x)) -> pre (inst_smem i d od) ge m0. Proof. - induction i as [|[x e] i IHi]; simpl; auto. + induction i as [|[x e] i IHi]; cbn; auto. intros Hold m1 m2 d VALID0 H Hm1. - destruct (exp_eval ge e m1 old) eqn: Heq; simpl; try congruence. + destruct (exp_eval ge e m1 old) eqn: Heq; cbn; try congruence. eapply IHi; eauto. - + unfold smem_set in * |- *; simpl. + + unfold smem_set in * |- *; cbn. rewrite Hm1; intuition congruence. - + intros x0. unfold assign, smem_set; simpl; destruct (R.eq_dec x x0); auto. + + intros x0. unfold assign, smem_set; cbn; destruct (R.eq_dec x x0); auto. subst; erewrite term_eval_exp; eauto. Qed. @@ -309,7 +311,7 @@ Lemma block_smem_rec_valid p m0: forall (m1 m2: mem) (d:smem), pre (bblock_smem_rec p d) ge m0. Proof. Local Hint Resolve inst_valid: core. - induction p as [ | i p]; simpl; intros m1 d H; auto. + induction p as [ | i p]; cbn; intros m1 d H; auto. intros H0 H1. destruct (inst_run ge i m1 m1) eqn: Heqov; eauto. congruence. @@ -320,7 +322,7 @@ Lemma bblock_smem_valid p m0 m1: pre (bblock_smem p) ge m0. Proof. intros; eapply block_smem_rec_valid; eauto. - unfold smem_empty; simpl. auto. + unfold smem_empty; cbn. auto. Qed. Definition smem_valid ge d m := pre d ge m /\ forall x, term_eval ge (d x) m <> None. @@ -337,7 +339,7 @@ Theorem bblock_smem_simu p1 p2: Proof. Local Hint Resolve bblock_smem_valid bblock_smem_Some_correct1: core. intros (INCL & EQUIV) m DONTFAIL; unfold smem_valid in * |-. - destruct (run ge p1 m) as [m1|] eqn: RUN1; simpl; try congruence. + destruct (run ge p1 m) as [m1|] eqn: RUN1; cbn; try congruence. assert (X: forall x, term_eval ge (bblock_smem p1 x) m = Some (m1 x)); eauto. eapply bblock_smem_Some_correct2; eauto. + destruct (INCL m); intuition eauto. @@ -369,21 +371,20 @@ Lemma smem_valid_set_proof d x t m: Proof. unfold smem_valid; intros (PRE & VALID) PREt. split. + split; auto. - + intros x0; unfold smem_set; simpl; case (R.eq_dec x x0); intros; subst; auto. + + intros x0; unfold smem_set; cbn; case (R.eq_dec x x0); intros; subst; auto. Qed. End SIMU_THEORY. -(** REMARKS: more abstract formulation of the proof... - but relying on functional_extensionality. +(** REMARK: this theorem reformulates the lemma above in a more abstract way (but relies on functional_extensionality axiom). *) Definition smem_correct ge (d: smem) (m: mem) (om: option mem): Prop:= forall m', om=Some m' <-> (d.(pre) ge m /\ forall x, term_eval ge (d x) m = Some (m' x)). Lemma bblock_smem_correct ge p m: smem_correct ge (bblock_smem p) m (run ge p m). Proof. - unfold smem_correct; simpl; intros m'; split. + unfold smem_correct; cbn; intros m'; split. + intros; split. * eapply bblock_smem_valid; eauto. * eapply bblock_smem_Some_correct1; eauto. diff --git a/kvx/lib/ForwardSimulationBlock.v b/kvx/lib/ForwardSimulationBlock.v index f79814f2..61466dad 100644 --- a/kvx/lib/ForwardSimulationBlock.v +++ b/kvx/lib/ForwardSimulationBlock.v @@ -42,11 +42,11 @@ Lemma starN_split n s t s': forall m k, n=m+k -> exists (t1 t2:trace) s0, starN (step L) (globalenv L) m s t1 s0 /\ starN (step L) (globalenv L) k s0 t2 s' /\ t=t1**t2. Proof. - induction 1; simpl. + induction 1; cbn. + intros m k H; assert (X: m=0); try omega. assert (X0: k=0); try omega. subst; repeat (eapply ex_intro); intuition eauto. - + intros m; destruct m as [| m']; simpl. + + intros m; destruct m as [| m']; cbn. - intros k H2; subst; repeat (eapply ex_intro); intuition eauto. - intros k H2. inversion H2. exploit (IHstarN m' k); eauto. intro. @@ -61,7 +61,7 @@ Lemma starN_tailstep n s t1 s': forall (t t2:trace) s'', Step L s' t2 s'' -> t = t1 ** t2 -> starN (step L) (globalenv L) (S n) s t s''. Proof. - induction 1; simpl. + induction 1; cbn. + intros t t1 s0; autorewrite with trace_rewrite. intros; subst; eapply starN_step; eauto. autorewrite with trace_rewrite; auto. @@ -153,8 +153,8 @@ Definition head (s: memostate): state L1 := Lemma head_followed (s: memostate): follows_in_block (head s) (real s). Proof. - destruct s as [rs ms Hs]. simpl. - destruct ms as [ms|]; unfold head; simpl; auto. + destruct s as [rs ms Hs]. cbn. + destruct ms as [ms|]; unfold head; cbn; auto. constructor 1. omega. cutrewrite ((dist_end_block rs - dist_end_block rs)%nat=O). @@ -198,21 +198,21 @@ Definition memoL1 := {| Lemma discr_dist_end s: {dist_end_block s = O} + {dist_end_block s <> O}. Proof. - destruct (dist_end_block s); simpl; intuition. + destruct (dist_end_block s); cbn; intuition. Qed. Lemma memo_simulation_step: forall s1 t s1', Step L1 s1 t s1' -> forall s2, s1 = (real s2) -> exists s2', Step memoL1 s2 t s2' /\ s1' = (real s2'). Proof. - intros s1 t s1' H1 [rs2 ms2 Hmoi] H2. simpl in H2; subst. + intros s1 t s1' H1 [rs2 ms2 Hmoi] H2. cbn in H2; subst. destruct (discr_dist_end rs2) as [H3 | H3]. - + refine (ex_intro _ {|real:=s1'; memorized:=None |} _); simpl. + + refine (ex_intro _ {|real:=s1'; memorized:=None |} _); cbn. intuition. + destruct ms2 as [s|]. - - refine (ex_intro _ {|real:=s1'; memorized:=Some s |} _); simpl. + - refine (ex_intro _ {|real:=s1'; memorized:=Some s |} _); cbn. intuition. - - refine (ex_intro _ {|real:=s1'; memorized:=Some rs2 |} _); simpl. + - refine (ex_intro _ {|real:=s1'; memorized:=Some rs2 |} _); cbn. intuition. Unshelve. * intros; discriminate. @@ -228,7 +228,7 @@ Qed. Lemma forward_memo_simulation_1: forward_simulation L1 memoL1. Proof. apply forward_simulation_step with (match_states:=fun s1 s2 => s1 = (real s2)); auto. - + intros s1 H; eapply ex_intro with (x:={|real:=s1; memorized:=None |}); simpl. + + intros s1 H; eapply ex_intro with (x:={|real:=s1; memorized:=None |}); cbn. intuition. + intros; subst; auto. + intros; exploit memo_simulation_step; eauto. @@ -239,8 +239,8 @@ Qed. Lemma forward_memo_simulation_2: forward_simulation memoL1 L2. Proof. - unfold memoL1; simpl. - apply forward_simulation_opt with (measure:=fun s => dist_end_block (real s)) (match_states:=fun s1 s2 => match_states (head s1) s2); simpl; auto. + unfold memoL1; cbn. + apply forward_simulation_opt with (measure:=fun s => dist_end_block (real s)) (match_states:=fun s1 s2 => match_states (head s1) s2); cbn; auto. + intros s1 [H0 H1]; destruct (match_initial_states (real s1) H0). unfold head; rewrite H1. intuition eauto. @@ -254,14 +254,14 @@ Proof. - (* MidBloc *) constructor 2. destruct (simu_mid_block (real s1) t (real s1')) as [H5 H4]; auto. unfold head in * |- *. rewrite H3. rewrite H4. intuition. - destruct (memorized s1); simpl; auto. tauto. + destruct (memorized s1); cbn; auto. tauto. - (* EndBloc *) constructor 1. destruct (simu_end_block (head s1) t (real s1') s2) as (s2' & H3 & H4); auto. * destruct (head_followed s1) as [H4 H3]. cutrewrite (dist_end_block (head s1) - dist_end_block (real s1) = dist_end_block (head s1)) in H3; try omega. eapply starN_tailstep; eauto. - * unfold head; rewrite H2; simpl. intuition eauto. + * unfold head; rewrite H2; cbn. intuition eauto. Qed. Lemma forward_simulation_block_rel: forward_simulation L1 L2. diff --git a/kvx/lib/Machblock.v b/kvx/lib/Machblock.v index edae0ed4..404c2a96 100644 --- a/kvx/lib/Machblock.v +++ b/kvx/lib/Machblock.v @@ -70,7 +70,7 @@ Lemma bblock_eq: b1 = b2. Proof. intros. destruct b1. destruct b2. - simpl in *. subst. auto. + cbn in *. subst. auto. Qed. Definition length_opt {A} (o: option A) : nat := @@ -85,15 +85,15 @@ Lemma size_null b: size b = 0%nat -> header b = nil /\ body b = nil /\ exit b = None. Proof. - destruct b as [h b e]. simpl. unfold size. simpl. + destruct b as [h b e]. cbn. unfold size. cbn. intros H. assert (length h = 0%nat) as Hh; [ omega |]. assert (length b = 0%nat) as Hb; [ omega |]. assert (length_opt e = 0%nat) as He; [ omega|]. repeat split. - destruct h; try (simpl in Hh; discriminate); auto. - destruct b; try (simpl in Hb; discriminate); auto. - destruct e; try (simpl in He; discriminate); auto. + destruct h; try (cbn in Hh; discriminate); auto. + destruct b; try (cbn in Hb; discriminate); auto. + destruct e; try (cbn in He; discriminate); auto. Qed. (** ** programs *) @@ -127,13 +127,13 @@ Definition is_label (lbl: label) (bb: bblock) : bool := Lemma is_label_correct_true lbl bb: List.In lbl (header bb) <-> is_label lbl bb = true. Proof. - unfold is_label; destruct (in_dec lbl (header bb)); simpl; intuition. + unfold is_label; destruct (in_dec lbl (header bb)); cbn; intuition. Qed. Lemma is_label_correct_false lbl bb: ~(List.In lbl (header bb)) <-> is_label lbl bb = false. Proof. - unfold is_label; destruct (in_dec lbl (header bb)); simpl; intuition. + unfold is_label; destruct (in_dec lbl (header bb)); cbn; intuition. Qed. diff --git a/kvx/lib/Machblockgen.v b/kvx/lib/Machblockgen.v index ab186083..3d5d7b2c 100644 --- a/kvx/lib/Machblockgen.v +++ b/kvx/lib/Machblockgen.v @@ -148,11 +148,11 @@ Lemma add_to_code_is_trans_code i c bl: is_trans_code c bl -> is_trans_code (i::c) (add_to_code (trans_inst i) bl). Proof. - destruct bl as [|bh0 bl]; simpl. + destruct bl as [|bh0 bl]; cbn. - intro H. inversion H. subst. eauto. - remember (trans_inst i) as ti. destruct ti as [l|bi|cfi]. - + intros; eapply Tr_add_label; eauto. destruct i; simpl in * |- *; congruence. + + intros; eapply Tr_add_label; eauto. destruct i; cbn in * |- *; congruence. + intros. remember (header bh0) as hbh0. destruct hbh0 as [|b]. * eapply Tr_add_basic; eauto. * cutrewrite (add_basic bi empty_bblock = add_to_new_bblock (MB_basic bi)); auto. @@ -170,7 +170,7 @@ Lemma trans_code_is_trans_code_rev c1: forall c2 mbi, is_trans_code c2 mbi -> is_trans_code (rev_append c1 c2) (trans_code_rev c1 mbi). Proof. - induction c1 as [| i c1]; simpl; auto. + induction c1 as [| i c1]; cbn; auto. Qed. Lemma trans_code_is_trans_code c: is_trans_code c (trans_code c). @@ -186,17 +186,17 @@ Lemma add_to_code_is_trans_code_inv i c bl: is_trans_code (i::c) bl -> exists bl0, is_trans_code c bl0 /\ bl = add_to_code (trans_inst i) bl0. Proof. intro H; inversion H as [|H0 H1 bl0| | H0 bi bh H1 bl0]; clear H; subst; (repeat econstructor); eauto. - + (* case Tr_end_block *) inversion H3; subst; simpl; auto. + + (* case Tr_end_block *) inversion H3; subst; cbn; auto. * destruct (header bh); congruence. - * destruct bl0; simpl; congruence. - + (* case Tr_add_basic *) rewrite H3. simpl. destruct (header bh); congruence. + * destruct bl0; cbn; congruence. + + (* case Tr_add_basic *) rewrite H3. cbn. destruct (header bh); congruence. Qed. Lemma trans_code_is_trans_code_rev_inv c1: forall c2 mbi, is_trans_code (rev_append c1 c2) mbi -> exists mbi0, is_trans_code c2 mbi0 /\ mbi=trans_code_rev c1 mbi0. Proof. - induction c1 as [| i c1]; simpl; eauto. + induction c1 as [| i c1]; cbn; eauto. intros; exploit IHc1; eauto. intros (mbi0 & H1 & H2); subst. exploit add_to_code_is_trans_code_inv; eauto. diff --git a/kvx/lib/Machblockgenproof.v b/kvx/lib/Machblockgenproof.v index dfb97bfe..fc722887 100644 --- a/kvx/lib/Machblockgenproof.v +++ b/kvx/lib/Machblockgenproof.v @@ -146,16 +146,16 @@ Lemma parent_sp_preserved: forall s, Mach.parent_sp s = parent_sp (trans_stack s). Proof. - unfold parent_sp. unfold Mach.parent_sp. destruct s; simpl; auto. - unfold trans_stackframe. destruct s; simpl; auto. + unfold parent_sp. unfold Mach.parent_sp. destruct s; cbn; auto. + unfold trans_stackframe. destruct s; cbn; auto. Qed. Lemma parent_ra_preserved: forall s, Mach.parent_ra s = parent_ra (trans_stack s). Proof. - unfold parent_ra. unfold Mach.parent_ra. destruct s; simpl; auto. - unfold trans_stackframe. destruct s; simpl; auto. + unfold parent_ra. unfold Mach.parent_ra. destruct s; cbn; auto. + unfold trans_stackframe. destruct s; cbn; auto. Qed. Lemma external_call_preserved: @@ -175,11 +175,11 @@ Proof. destruct i; try (constructor 2; split; auto; discriminate ). destruct (peq l0 l) as [P|P]. - constructor. subst l0; split; auto. - revert H. unfold Mach.find_label. simpl. rewrite peq_true. + revert H. unfold Mach.find_label. cbn. rewrite peq_true. intros H; injection H; auto. - constructor 2. split. + intro F. injection F. intros. contradict P; auto. - + revert H. unfold Mach.find_label. simpl. rewrite peq_false; auto. + + revert H. unfold Mach.find_label. cbn. rewrite peq_false; auto. Qed. Lemma find_label_is_end_block_not_label i l c bl: @@ -192,24 +192,24 @@ Proof. remember (is_label l _) as b. cutrewrite (b = false); auto. subst; unfold is_label. - destruct i; simpl in * |- *; try (destruct (in_dec l nil); intuition). + destruct i; cbn in * |- *; try (destruct (in_dec l nil); intuition). inversion H. destruct (in_dec l (l0::nil)) as [H6|H6]; auto. - simpl in H6; intuition try congruence. + cbn in H6; intuition try congruence. Qed. Lemma find_label_at_begin l bh bl: In l (header bh) -> find_label l (bh :: bl) = Some (bh::bl). Proof. - unfold find_label; rewrite is_label_correct_true; intro H; rewrite H; simpl; auto. + unfold find_label; rewrite is_label_correct_true; intro H; rewrite H; cbn; auto. Qed. Lemma find_label_add_label_diff l bh bl: ~(In l (header bh)) -> find_label l (bh::bl) = find_label l bl. Proof. - unfold find_label; rewrite is_label_correct_false; intro H; rewrite H; simpl; auto. + unfold find_label; rewrite is_label_correct_false; intro H; rewrite H; cbn; auto. Qed. Definition concat (h: list label) (c: code): code := @@ -227,18 +227,18 @@ Proof. rewrite <- is_trans_code_inv in * |-. induction Heqbl. + (* Tr_nil *) - intros; exists (l::nil); simpl in * |- *; intuition. + intros; exists (l::nil); cbn in * |- *; intuition. discriminate. + (* Tr_end_block *) intros. exploit Mach_find_label_split; eauto. clear H0; destruct 1 as [(H0&H2)|(H0&H2)]. - - subst. rewrite find_label_at_begin; simpl; auto. + - subst. rewrite find_label_at_begin; cbn; auto. inversion H as [mbi H1 H2| | ]. subst. inversion Heqbl. subst. - exists (l :: nil); simpl; eauto. + exists (l :: nil); cbn; eauto. - exploit IHHeqbl; eauto. destruct 1 as (h & H3 & H4). exists h. @@ -251,21 +251,21 @@ Proof. - subst. inversion H0 as [H1]. clear H0. - erewrite find_label_at_begin; simpl; eauto. + erewrite find_label_at_begin; cbn; eauto. subst_is_trans_code Heqbl. - exists (l :: nil); simpl; eauto. + exists (l :: nil); cbn; eauto. - subst; assert (H: l0 <> l); try congruence; clear H0. exploit IHHeqbl; eauto. clear IHHeqbl Heqbl. intros (h & H3 & H4). - simpl; unfold is_label, add_label; simpl. - destruct (in_dec l (l0::header bh)) as [H5|H5]; simpl in H5. + cbn; unfold is_label, add_label; cbn. + destruct (in_dec l (l0::header bh)) as [H5|H5]; cbn in H5. * destruct H5; try congruence. - exists (l0::h); simpl; intuition. + exists (l0::h); cbn; intuition. rewrite find_label_at_begin in H4; auto. apply f_equal. inversion H4 as [H5]. clear H4. - destruct (trans_code c'); simpl in * |- *; - inversion H5; subst; simpl; auto. + destruct (trans_code c'); cbn in * |- *; + inversion H5; subst; cbn; auto. * exists h. intuition. erewrite <- find_label_add_label_diff; eauto. + (* Tr_add_basic *) @@ -318,12 +318,12 @@ Local Hint Resolve exec_MBgetstack exec_MBsetstack exec_MBgetparam exec_MBop exe Lemma size_add_label l bh: size (add_label l bh) = size bh + 1. Proof. - unfold add_label, size; simpl; omega. + unfold add_label, size; cbn; omega. Qed. Lemma size_add_basic bi bh: header bh = nil -> size (add_basic bi bh) = size bh + 1. Proof. - intro H. unfold add_basic, size; rewrite H; simpl. omega. + intro H. unfold add_basic, size; rewrite H; cbn. omega. Qed. @@ -418,8 +418,8 @@ Proof. + exists lbl. unfold trans_inst in H1. destruct i; congruence. - + unfold add_basic in H; simpl in H; congruence. - + unfold cfi_bblock in H; simpl in H; congruence. + + unfold add_basic in H; cbn in H; congruence. + + unfold cfi_bblock in H; cbn in H; congruence. Qed. Local Hint Resolve Mlabel_is_not_basic: core. @@ -433,11 +433,11 @@ Proof. intros b bl H; remember (trans_inst i) as ti. destruct ti as [lbl|bi|cfi]; inversion H as [|d0 d1 d2 H0 H1|Â |]; subst; - try (rewrite <- Heqti in * |- *); simpl in * |- *; + try (rewrite <- Heqti in * |- *); cbn in * |- *; try congruence. + (* label at end block *) inversion H1; subst. inversion H0; subst. - assert (X:i=Mlabel lbl). { destruct i; simpl in Heqti; congruence. } + assert (X:i=Mlabel lbl). { destruct i; cbn in Heqti; congruence. } subst. repeat econstructor; eauto. + (* label at mid block *) exploit IHc; eauto. @@ -451,12 +451,12 @@ Proof. assert (X:(trans_inst i) = MB_basic bi ). { repeat econstructor; congruence. } repeat econstructor; congruence. - exists (i::c), c, c. - repeat econstructor; eauto; inversion H0; subst; repeat econstructor; simpl; try congruence. + repeat econstructor; eauto; inversion H0; subst; repeat econstructor; cbn; try congruence. * exploit (add_to_new_block_is_label i0); eauto. - intros (l & H8); subst; simpl; congruence. + intros (l & H8); subst; cbn; congruence. * exploit H3; eauto. * exploit (add_to_new_block_is_label i0); eauto. - intros (l & H8); subst; simpl; congruence. + intros (l & H8); subst; cbn; congruence. + (* basic at mid block *) inversion H1; subst. exploit IHc; eauto. @@ -476,7 +476,7 @@ Lemma step_simu_header st f sp rs m s c h c' t: starN (Mach.step (inv_trans_rao rao)) (Genv.globalenv prog) (length h) (Mach.State st f sp c rs m) t s -> s = Mach.State st f sp c' rs m /\ t = E0. Proof. - induction 1; simpl; intros hs; try (inversion hs; tauto). + induction 1; cbn; intros hs; try (inversion hs; tauto). inversion hs as [|n1 s1 t1 t2 s2 t3 s3 H1]. inversion H1. subst. auto. Qed. @@ -487,21 +487,21 @@ Lemma step_simu_basic_step (i: Mach.instruction) (bi: basic_inst) (c: Mach.code) Mach.step (inv_trans_rao rao) ge (Mach.State s f sp (i::c) rs m) t s' -> exists rs' m', s'=Mach.State s f sp c rs' m' /\ t=E0 /\ basic_step tge (trans_stack s) f sp rs m bi rs' m'. Proof. - destruct i; simpl in * |-; + destruct i; cbn in * |-; (discriminate || (intro H; inversion_clear H; intro X; inversion_clear X; eapply ex_intro; eapply ex_intro; intuition eauto)). - eapply exec_MBgetparam; eauto. exploit (functions_translated); eauto. intro. destruct H3 as (tf & A & B). subst. eapply A. - all: simpl; rewrite <- parent_sp_preserved; auto. - - eapply exec_MBop; eauto. rewrite <- H. destruct o; simpl; auto. destruct (rs ## l); simpl; auto. + all: cbn; rewrite <- parent_sp_preserved; auto. + - eapply exec_MBop; eauto. rewrite <- H. destruct o; cbn; auto. destruct (rs ## l); cbn; auto. unfold Genv.symbol_address; rewrite symbols_preserved; auto. - - eapply exec_MBload; eauto; rewrite <- H; destruct a; simpl; auto; destruct (rs ## l); simpl; auto; + - eapply exec_MBload; eauto; rewrite <- H; destruct a; cbn; auto; destruct (rs ## l); cbn; auto; unfold Genv.symbol_address; rewrite symbols_preserved; auto. - - eapply exec_MBload_notrap1; eauto; rewrite <- H; destruct a; simpl; auto; destruct (rs ## l); simpl; auto; + - eapply exec_MBload_notrap1; eauto; rewrite <- H; destruct a; cbn; auto; destruct (rs ## l); cbn; auto; unfold Genv.symbol_address; rewrite symbols_preserved; auto. - - eapply exec_MBload_notrap2; eauto; rewrite <- H; destruct a; simpl; auto; destruct (rs ## l); simpl; auto; + - eapply exec_MBload_notrap2; eauto; rewrite <- H; destruct a; cbn; auto; destruct (rs ## l); cbn; auto; unfold Genv.symbol_address; rewrite symbols_preserved; auto. - - eapply exec_MBstore; eauto; rewrite <- H; destruct a; simpl; auto; destruct (rs ## l); simpl; auto; + - eapply exec_MBstore; eauto; rewrite <- H; destruct a; cbn; auto; destruct (rs ## l); cbn; auto; unfold Genv.symbol_address; rewrite symbols_preserved; auto. Qed. @@ -511,7 +511,7 @@ Lemma star_step_simu_body_step s f sp c bdy c': starN (Mach.step (inv_trans_rao rao)) ge (length bdy) (Mach.State s f sp c rs m) t s' -> exists rs' m', s'=Mach.State s f sp c' rs' m' /\ t=E0 /\ body_step tge (trans_stack s) f sp bdy rs m rs' m'. Proof. - induction 1; simpl. + induction 1; cbn. + intros. inversion H. exists rs. exists m. auto. + intros. inversion H0. exists rs. exists m. auto. + intros. inversion H1; subst. @@ -531,15 +531,15 @@ Local Hint Resolve eval_builtin_args_preserved external_call_symbols_preserved f Lemma match_states_concat_trans_code st f sp c rs m h: match_states (Mach.State st f sp c rs m) (State (trans_stack st) f sp (concat h (trans_code c)) rs m). Proof. - intros; constructor 1; simpl. + intros; constructor 1; cbn. + intros (t0 & s1' & H0) t s'. remember (trans_code _) as bl. destruct bl as [|bh bl]. { rewrite <- is_trans_code_inv in Heqbl; inversion Heqbl; inversion H0; congruence. } clear H0. - simpl; constructor 1; - intros X; inversion X as [d1 d2 d3 d4 d5 d6 d7 rs' m' d10 d11 X1 X2| | | ]; subst; simpl in * |- *; - eapply exec_bblock; eauto; simpl; + cbn; constructor 1; + intros X; inversion X as [d1 d2 d3 d4 d5 d6 d7 rs' m' d10 d11 X1 X2| | | ]; subst; cbn in * |- *; + eapply exec_bblock; eauto; cbn; inversion X2 as [cfi d1 d2 d3 H1|]; subst; eauto; inversion H1; subst; eauto. + intros H r; constructor 1; intro X; inversion X. @@ -551,7 +551,7 @@ Lemma step_simu_cfi_step (i: Mach.instruction) (cfi: control_flow_inst) (c: Mach Mach.step (inv_trans_rao rao) ge (Mach.State stk f sp (i::c) rs m) t s' -> exists s2, cfi_step rao tge cfi (State (trans_stack stk) f sp (b::blc) rs m) t s2 /\ match_states s' s2. Proof. - destruct i; simpl in * |-; + destruct i; cbn in * |-; (intro H; intro Htc;apply is_trans_code_inv in Htc;rewrite Htc;inversion_clear H;intro X; inversion_clear X). * eapply ex_intro. intuition auto. @@ -561,8 +561,8 @@ Proof. intuition auto. eapply exec_MBtailcall;eauto. - rewrite <-H; exploit (find_function_ptr_same); eauto. - - simpl; rewrite <- parent_sp_preserved; auto. - - simpl; rewrite <- parent_ra_preserved; auto. + - cbn; rewrite <- parent_sp_preserved; auto. + - cbn; rewrite <- parent_ra_preserved; auto. * eapply ex_intro. intuition auto. eapply exec_MBbuiltin ;eauto. @@ -605,7 +605,7 @@ Proof. inversion H1; subst. exploit (step_simu_cfi_step); eauto. intros [s2 [Hcfi1 Hcfi3]]. - inversion H4. subst; simpl. + inversion H4. subst; cbn. autorewrite with trace_rewrite. exists s2. split;eauto. @@ -616,7 +616,7 @@ Lemma simu_end_block: starN (Mach.step (inv_trans_rao rao)) ge (Datatypes.S (dist_end_block s1)) s1 t s1' -> exists s2', step rao tge (trans_state s1) t s2' /\ match_states s1' s2'. Proof. - destruct s1; simpl. + destruct s1; cbn. + (* State *) remember (trans_code _) as tc. rewrite <- is_trans_code_inv in Heqtc. @@ -624,7 +624,7 @@ Proof. destruct tc as [|b bl]. { (* nil => absurd *) inversion Heqtc. subst. - unfold dist_end_block_code; simpl. + unfold dist_end_block_code; cbn. inversion_clear H; inversion_clear H0. } @@ -659,7 +659,7 @@ Proof. intros t s1' H; inversion_clear H. eapply ex_intro; constructor 1; eauto. inversion H1; subst; clear H1. - inversion_clear H0; simpl. + inversion_clear H0; cbn. - (* function_internal*) cutrewrite (trans_code (Mach.fn_code f0) = fn_code (transf_function f0)); eauto. eapply exec_function_internal; eauto. @@ -674,7 +674,7 @@ Proof. intros t s1' H; inversion_clear H. eapply ex_intro; constructor 1; eauto. inversion H1; subst; clear H1. - inversion_clear H0; simpl. + inversion_clear H0; cbn. eapply exec_return. Qed. @@ -685,10 +685,10 @@ dist_end_block_code (i :: c) = 0. Proof. unfold dist_end_block_code. intro H. destruct H as [cfi H]. - destruct i;simpl in H;try(congruence); ( + destruct i;cbn in H;try(congruence); ( remember (trans_code _) as bl; rewrite <- is_trans_code_inv in Heqbl; - inversion Heqbl; subst; simpl in * |- *; try (congruence)). + inversion Heqbl; subst; cbn in * |- *; try (congruence)). Qed. Theorem transf_program_correct: @@ -697,23 +697,23 @@ Proof. apply forward_simulation_block_trans with (dist_end_block := dist_end_block) (trans_state := trans_state). (* simu_mid_block *) - intros s1 t s1' H1 H2. - destruct H1; simpl in * |- *; omega || (intuition auto); - destruct H2; eapply cfi_dist_end_block; simpl; eauto. + destruct H1; cbn in * |- *; omega || (intuition auto); + destruct H2; eapply cfi_dist_end_block; cbn; eauto. (* public_preserved *) - apply senv_preserved. (* match_initial_states *) - - intros. simpl. + - intros. cbn. eapply ex_intro; constructor 1. eapply match_states_trans_state. destruct H. split. apply init_mem_preserved; auto. rewrite prog_main_preserved. rewrite <- H0. apply symbols_preserved. (* match_final_states *) - - intros. simpl. destruct H. split with (r := r); auto. + - intros. cbn. destruct H. split with (r := r); auto. (* final_states_end_block *) - - intros. simpl in H0. + - intros. cbn in H0. inversion H0. - inversion H; simpl; auto. + inversion H; cbn; auto. all: try (subst; discriminate). apply cfi_dist_end_block; exists MBreturn; eauto. (* simu_end_block *) @@ -733,8 +733,8 @@ Proof. intro H; destruct c as [|i' c]. { inversion H. } remember (trans_inst i) as ti. destruct ti as [lbl|bi|cfi]. - - (*i=lbl *) cutrewrite (i = Mlabel lbl). 2: ( destruct i; simpl in * |- *; try congruence ). - exists nil; simpl; eexists. eapply Tr_add_label; eauto. + - (*i=lbl *) cutrewrite (i = Mlabel lbl). 2: ( destruct i; cbn in * |- *; try congruence ). + exists nil; cbn; eexists. eapply Tr_add_label; eauto. - (*i=basic*) destruct i'. 10: { exists (add_to_new_bblock (MB_basic bi)::nil). exists b. @@ -742,11 +742,11 @@ Proof. rewrite Heqti. eapply Tr_end_block; eauto. rewrite <-Heqti. - eapply End_basic. inversion H; try(simpl; congruence). - simpl in H5; congruence. } - all: try(exists nil; simpl; eexists; eapply Tr_add_basic; eauto; inversion H; try(eauto || congruence)). + eapply End_basic. inversion H; try(cbn; congruence). + cbn in H5; congruence. } + all: try(exists nil; cbn; eexists; eapply Tr_add_basic; eauto; inversion H; try(eauto || congruence)). - (*i=cfi*) - destruct i; try(simpl in Heqti; congruence). + destruct i; try(cbn in Heqti; congruence). all: exists (add_to_new_bblock (MB_cfi cfi)::nil); exists b; cutrewrite ((add_to_new_bblock (MB_cfi cfi) :: nil) ++ (b::l)=(add_to_new_bblock (MB_cfi cfi) :: (b::l)));eauto; rewrite Heqti; @@ -768,13 +768,13 @@ Qed. (* FIXME: these two lemma should go into [Coqlib.v] *) Lemma is_tail_app A (l1: list A): forall l2, is_tail l2 (l1 ++ l2). Proof. - induction l1; simpl; auto with coqlib. + induction l1; cbn; auto with coqlib. Qed. Hint Resolve is_tail_app: coqlib. Lemma is_tail_app_inv A (l1: list A): forall l2 l3, is_tail (l1 ++ l2) l3 -> is_tail l2 l3. Proof. - induction l1; simpl; auto with coqlib. + induction l1; cbn; auto with coqlib. intros l2 l3 H; inversion H; eauto with coqlib. Qed. Hint Resolve is_tail_app_inv: coqlib. @@ -787,17 +787,17 @@ Proof. - intros; subst. remember (trans_code (Mcall _ _::c)) as tc2. rewrite <- is_trans_code_inv in Heqtc2. - inversion Heqtc2; simpl in * |- *; subst; try congruence. + inversion Heqtc2; cbn in * |- *; subst; try congruence. subst_is_trans_code H1. eapply ex_intro; eauto with coqlib. - intros; exploit IHis_tail; eauto. clear IHis_tail. intros (b & Hb). inversion Hb; clear Hb. * exploit (trans_code_monotonic i c2); eauto. intros (l' & b' & Hl'); rewrite Hl'. - exists b'; simpl; eauto with coqlib. + exists b'; cbn; eauto with coqlib. * exploit (trans_code_monotonic i c2); eauto. intros (l' & b' & Hl'); rewrite Hl'. - simpl; eapply ex_intro. + cbn; eapply ex_intro. eapply is_tail_trans; eauto with coqlib. Qed. diff --git a/kvx/abstractbb/Impure/ImpConfig.v b/lib/Impure/ImpConfig.v index dd9785b5..dd9785b5 100644 --- a/kvx/abstractbb/Impure/ImpConfig.v +++ b/lib/Impure/ImpConfig.v diff --git a/kvx/abstractbb/Impure/ImpCore.v b/lib/Impure/ImpCore.v index 508b3f19..508b3f19 100644 --- a/kvx/abstractbb/Impure/ImpCore.v +++ b/lib/Impure/ImpCore.v diff --git a/kvx/abstractbb/Impure/ImpExtern.v b/lib/Impure/ImpExtern.v index 8fb3cf3b..8fb3cf3b 100644 --- a/kvx/abstractbb/Impure/ImpExtern.v +++ b/lib/Impure/ImpExtern.v diff --git a/kvx/abstractbb/Impure/ImpHCons.v b/lib/Impure/ImpHCons.v index 637116cc..637116cc 100644 --- a/kvx/abstractbb/Impure/ImpHCons.v +++ b/lib/Impure/ImpHCons.v diff --git a/kvx/abstractbb/Impure/ImpIO.v b/lib/Impure/ImpIO.v index 6c02c395..6c02c395 100644 --- a/kvx/abstractbb/Impure/ImpIO.v +++ b/lib/Impure/ImpIO.v diff --git a/kvx/abstractbb/Impure/ImpLoops.v b/lib/Impure/ImpLoops.v index 33376c19..33376c19 100644 --- a/kvx/abstractbb/Impure/ImpLoops.v +++ b/lib/Impure/ImpLoops.v diff --git a/kvx/abstractbb/Impure/ImpMonads.v b/lib/Impure/ImpMonads.v index f01a2755..f01a2755 100644 --- a/kvx/abstractbb/Impure/ImpMonads.v +++ b/lib/Impure/ImpMonads.v diff --git a/kvx/abstractbb/Impure/ImpPrelude.v b/lib/Impure/ImpPrelude.v index de4c7973..de4c7973 100644 --- a/kvx/abstractbb/Impure/ImpPrelude.v +++ b/lib/Impure/ImpPrelude.v diff --git a/kvx/abstractbb/Impure/LICENSE b/lib/Impure/LICENSE index 65c5ca88..65c5ca88 100644 --- a/kvx/abstractbb/Impure/LICENSE +++ b/lib/Impure/LICENSE diff --git a/kvx/abstractbb/Impure/README.md b/lib/Impure/README.md index 2b19d14a..2b19d14a 100644 --- a/kvx/abstractbb/Impure/README.md +++ b/lib/Impure/README.md diff --git a/kvx/abstractbb/Impure/ocaml/ImpHConsOracles.ml b/lib/Impure/ocaml/ImpHConsOracles.ml index 68a33a91..68a33a91 100644 --- a/kvx/abstractbb/Impure/ocaml/ImpHConsOracles.ml +++ b/lib/Impure/ocaml/ImpHConsOracles.ml diff --git a/kvx/abstractbb/Impure/ocaml/ImpHConsOracles.mli b/lib/Impure/ocaml/ImpHConsOracles.mli index 5075d176..5075d176 100644 --- a/kvx/abstractbb/Impure/ocaml/ImpHConsOracles.mli +++ b/lib/Impure/ocaml/ImpHConsOracles.mli diff --git a/kvx/abstractbb/Impure/ocaml/ImpIOOracles.ml b/lib/Impure/ocaml/ImpIOOracles.ml index 9e63c12d..9e63c12d 100644 --- a/kvx/abstractbb/Impure/ocaml/ImpIOOracles.ml +++ b/lib/Impure/ocaml/ImpIOOracles.ml diff --git a/kvx/abstractbb/Impure/ocaml/ImpIOOracles.mli b/lib/Impure/ocaml/ImpIOOracles.mli index 6064286a..6064286a 100644 --- a/kvx/abstractbb/Impure/ocaml/ImpIOOracles.mli +++ b/lib/Impure/ocaml/ImpIOOracles.mli diff --git a/kvx/abstractbb/Impure/ocaml/ImpLoopOracles.ml b/lib/Impure/ocaml/ImpLoopOracles.ml index cb7625e5..cb7625e5 100644 --- a/kvx/abstractbb/Impure/ocaml/ImpLoopOracles.ml +++ b/lib/Impure/ocaml/ImpLoopOracles.ml diff --git a/kvx/abstractbb/Impure/ocaml/ImpLoopOracles.mli b/lib/Impure/ocaml/ImpLoopOracles.mli index 194696a1..194696a1 100644 --- a/kvx/abstractbb/Impure/ocaml/ImpLoopOracles.mli +++ b/lib/Impure/ocaml/ImpLoopOracles.mli diff --git a/powerpc/PrepassSchedulingOracle.ml b/powerpc/PrepassSchedulingOracle.ml new file mode 120000 index 00000000..9885fd52 --- /dev/null +++ b/powerpc/PrepassSchedulingOracle.ml @@ -0,0 +1 @@ +../x86/PrepassSchedulingOracle.ml
\ No newline at end of file diff --git a/riscV/Asmgenproof1.v b/riscV/Asmgenproof1.v index 8678a5dc..d2255e66 100644 --- a/riscV/Asmgenproof1.v +++ b/riscV/Asmgenproof1.v @@ -1035,7 +1035,9 @@ Opaque Int.eq. intros (rs' & A & B & C). exists rs'; split; eauto. rewrite B; auto with asmgen. - (* shrximm *) - clear H. exploit Val.shrx_shr_3; eauto. intros E; subst v; clear EV. + destruct (Val.shrx (rs x0) (Vint n)) eqn:TOTAL; cbn. + { + exploit Val.shrx_shr_3; eauto. intros E; subst v. destruct (Int.eq n Int.zero). + econstructor; split. apply exec_straight_one. simpl; eauto. auto. split; intros; Simpl. @@ -1052,6 +1054,24 @@ Opaque Int.eq. eapply exec_straight_step. simpl; reflexivity. auto. apply exec_straight_one. simpl; reflexivity. auto. split; intros; Simpl. + } + destruct (Int.eq n Int.zero). ++ econstructor; split. apply exec_straight_one. simpl; eauto. auto. + split; intros; Simpl. ++ destruct (Int.eq n Int.one). + * econstructor; split. + eapply exec_straight_step. simpl; reflexivity. auto. + eapply exec_straight_step. simpl; reflexivity. auto. + apply exec_straight_one. simpl; reflexivity. auto. + split; intros; Simpl. + * change (Int.repr 32) with Int.iwordsize. set (n' := Int.sub Int.iwordsize n). + econstructor; split. + eapply exec_straight_step. simpl; reflexivity. auto. + eapply exec_straight_step. simpl; reflexivity. auto. + eapply exec_straight_step. simpl; reflexivity. auto. + apply exec_straight_one. simpl; reflexivity. auto. + split; intros; Simpl. + - (* longofintu *) econstructor; split. eapply exec_straight_three. simpl; eauto. simpl; eauto. simpl; eauto. auto. auto. auto. @@ -1076,7 +1096,27 @@ Opaque Int.eq. intros (rs' & A & B & C). exists rs'; split; eauto. rewrite B; auto with asmgen. - (* shrxlimm *) - clear H. exploit Val.shrxl_shrl_3; eauto. intros E; subst v; clear EV. + destruct (Val.shrxl (rs x0) (Vint n)) eqn:TOTAL. + { + exploit Val.shrxl_shrl_3; eauto. intros E; subst v. + destruct (Int.eq n Int.zero). ++ econstructor; split. apply exec_straight_one. simpl; eauto. auto. + split; intros; Simpl. ++ destruct (Int.eq n Int.one). + * econstructor; split. + eapply exec_straight_step. simpl; reflexivity. auto. + eapply exec_straight_step. simpl; reflexivity. auto. + apply exec_straight_one. simpl; reflexivity. auto. + split; intros; Simpl. + + * change (Int.repr 64) with Int64.iwordsize'. set (n' := Int.sub Int64.iwordsize' n). + econstructor; split. + eapply exec_straight_step. simpl; reflexivity. auto. + eapply exec_straight_step. simpl; reflexivity. auto. + eapply exec_straight_step. simpl; reflexivity. auto. + apply exec_straight_one. simpl; reflexivity. auto. + split; intros; Simpl. + } destruct (Int.eq n Int.zero). + econstructor; split. apply exec_straight_one. simpl; eauto. auto. split; intros; Simpl. @@ -1094,6 +1134,7 @@ Opaque Int.eq. eapply exec_straight_step. simpl; reflexivity. auto. apply exec_straight_one. simpl; reflexivity. auto. split; intros; Simpl. + - (* cond *) exploit transl_cond_op_correct; eauto. intros (rs' & A & B & C). exists rs'; split. eexact A. eauto with asmgen. diff --git a/riscV/ConstpropOpproof.v b/riscV/ConstpropOpproof.v index 765aa035..26a50317 100644 --- a/riscV/ConstpropOpproof.v +++ b/riscV/ConstpropOpproof.v @@ -265,52 +265,84 @@ Qed. Lemma make_divimm_correct: forall n r1 r2 v, - Val.divs e#r1 e#r2 = Some v -> + Val.maketotal (Val.divs e#r1 e#r2) = v -> e#r2 = Vint n -> let (op, args) := make_divimm n r1 r2 in exists w, eval_operation ge (Vptr sp Ptrofs.zero) op e##args m = Some w /\ Val.lessdef v w. Proof. intros; unfold make_divimm. - predSpec Int.eq Int.eq_spec n Int.one; intros. subst. rewrite H0 in H. - destruct (e#r1) eqn:?; - try (rewrite Val.divs_one in H; exists (Vint i); split; simpl; try rewrite Heqv0; auto); - inv H; auto. - destruct (Int.is_power2 n) eqn:?. - destruct (Int.ltu i (Int.repr 31)) eqn:?. - exists v; split; auto. simpl. eapply Val.divs_pow2; eauto. congruence. - exists v; auto. - exists v; auto. + predSpec Int.eq Int.eq_spec n Int.one; intros; subst; rewrite H0. + { destruct (e # r1) eqn:Er1. + all: try (cbn; exists (e # r1); split; auto; fail). + rewrite Val.divs_one. + cbn. + rewrite Er1. + exists (Vint i); split; auto. + } + destruct (Int.is_power2 n) eqn:Power2. + { + destruct (Int.ltu i (Int.repr 31)) eqn:iLT31. + { + cbn. + exists (Val.maketotal (Val.shrx e # r1 (Vint i))); split; auto. + destruct (Val.divs e # r1 (Vint n)) eqn:DIVS; cbn; auto. + rewrite Val.divs_pow2 with (y:=v) (n:=n). + cbn. + all: auto. + } + exists (Val.maketotal (Val.divs e # r1 (Vint n))); split; cbn; auto; congruence. + } + exists (Val.maketotal (Val.divs e # r1 (Vint n))); split; cbn; auto; congruence. Qed. Lemma make_divuimm_correct: forall n r1 r2 v, - Val.divu e#r1 e#r2 = Some v -> + Val.maketotal (Val.divu e#r1 e#r2) = v -> e#r2 = Vint n -> let (op, args) := make_divuimm n r1 r2 in exists w, eval_operation ge (Vptr sp Ptrofs.zero) op e##args m = Some w /\ Val.lessdef v w. Proof. intros; unfold make_divuimm. - predSpec Int.eq Int.eq_spec n Int.one; intros. subst. rewrite H0 in H. - destruct (e#r1) eqn:?; - try (rewrite Val.divu_one in H; exists (Vint i); split; simpl; try rewrite Heqv0; auto); - inv H; auto. - destruct (Int.is_power2 n) eqn:?. - econstructor; split. simpl; eauto. - rewrite H0 in H. erewrite Val.divu_pow2 by eauto. auto. - exists v; auto. + predSpec Int.eq Int.eq_spec n Int.one; intros; subst; rewrite H0. + { destruct (e # r1) eqn:Er1. + all: try (cbn; exists (e # r1); split; auto; fail). + rewrite Val.divu_one. + cbn. + rewrite Er1. + exists (Vint i); split; auto. + } + destruct (Int.is_power2 n) eqn:Power2. + { + cbn. + exists (Val.shru e # r1 (Vint i)); split; auto. + destruct (Val.divu e # r1 (Vint n)) eqn:DIVU; cbn; auto. + rewrite Val.divu_pow2 with (y:=v) (n:=n). + all: auto. + } + exists (Val.maketotal (Val.divu e # r1 (Vint n))); split; cbn; auto; congruence. Qed. Lemma make_moduimm_correct: forall n r1 r2 v, - Val.modu e#r1 e#r2 = Some v -> + Val.maketotal (Val.modu e#r1 e#r2) = v -> e#r2 = Vint n -> let (op, args) := make_moduimm n r1 r2 in exists w, eval_operation ge (Vptr sp Ptrofs.zero) op e##args m = Some w /\ Val.lessdef v w. Proof. intros; unfold make_moduimm. destruct (Int.is_power2 n) eqn:?. - exists v; split; auto. simpl. decEq. eapply Val.modu_pow2; eauto. congruence. - exists v; auto. + { destruct (Val.modu e # r1 e # r2) eqn:MODU; cbn in H. + { subst v0. + exists v; split; auto. + cbn. decEq. eapply Val.modu_pow2; eauto. congruence. + } + subst v. + eexists; split; auto. + cbn. reflexivity. + } + exists v; split; auto. + cbn. + congruence. Qed. Lemma make_andimm_correct: @@ -444,48 +476,82 @@ Qed. Lemma make_divlimm_correct: forall n r1 r2 v, - Val.divls e#r1 e#r2 = Some v -> + Val.maketotal (Val.divls e#r1 e#r2) = v -> e#r2 = Vlong n -> let (op, args) := make_divlimm n r1 r2 in exists w, eval_operation ge (Vptr sp Ptrofs.zero) op e##args m = Some w /\ Val.lessdef v w. Proof. intros; unfold make_divlimm. - destruct (Int64.is_power2' n) eqn:?. destruct (Int.ltu i (Int.repr 63)) eqn:?. - rewrite H0 in H. econstructor; split. simpl; eauto. eapply Val.divls_pow2; eauto. auto. - exists v; auto. - exists v; auto. + destruct (Int64.is_power2' n) eqn:Power2. + { + destruct (Int.ltu i (Int.repr 63)) eqn:iLT63. + { + cbn. + exists (Val.maketotal (Val.shrxl e # r1 (Vint i))); split; auto. + rewrite H0 in H. + destruct (Val.divls e # r1 (Vlong n)) eqn:DIVS; cbn in H; auto. + { + subst v0. + rewrite Val.divls_pow2 with (y:=v) (n:=n). + cbn. + all: auto. + } + subst. auto. + } + cbn. subst. rewrite H0. + exists (Val.maketotal (Val.divls e # r1 (Vlong n))); split; auto. + } + cbn. subst. rewrite H0. + exists (Val.maketotal (Val.divls e # r1 (Vlong n))); split; auto. Qed. Lemma make_divluimm_correct: forall n r1 r2 v, - Val.divlu e#r1 e#r2 = Some v -> + Val.maketotal (Val.divlu e#r1 e#r2) = v -> e#r2 = Vlong n -> let (op, args) := make_divluimm n r1 r2 in exists w, eval_operation ge (Vptr sp Ptrofs.zero) op e##args m = Some w /\ Val.lessdef v w. Proof. intros; unfold make_divluimm. destruct (Int64.is_power2' n) eqn:?. + { econstructor; split. simpl; eauto. - rewrite H0 in H. destruct (e#r1); inv H. destruct (Int64.eq n Int64.zero); inv H2. - simpl. - erewrite Int64.is_power2'_range by eauto. - erewrite Int64.divu_pow2' by eauto. auto. - exists v; auto. + rewrite H0 in H. destruct (e#r1); inv H. + all: cbn; auto. + { + destruct (Int64.eq n Int64.zero); cbn; auto. + erewrite Int64.is_power2'_range by eauto. + erewrite Int64.divu_pow2' by eauto. auto. + } + } + exists v; split; auto. + cbn. + rewrite H. + reflexivity. Qed. Lemma make_modluimm_correct: forall n r1 r2 v, - Val.modlu e#r1 e#r2 = Some v -> + Val.maketotal (Val.modlu e#r1 e#r2) = v -> e#r2 = Vlong n -> let (op, args) := make_modluimm n r1 r2 in exists w, eval_operation ge (Vptr sp Ptrofs.zero) op e##args m = Some w /\ Val.lessdef v w. Proof. intros; unfold make_modluimm. destruct (Int64.is_power2 n) eqn:?. - exists v; split; auto. simpl. decEq. - rewrite H0 in H. destruct (e#r1); inv H. destruct (Int64.eq n Int64.zero); inv H2. - simpl. erewrite Int64.modu_and by eauto. auto. - exists v; auto. + { + econstructor; split. simpl; eauto. + rewrite H0 in H. destruct (e#r1); inv H. + all: cbn; auto. + { + destruct (Int64.eq n Int64.zero); cbn; auto. + erewrite Int64.modu_and by eauto. auto. + } + } + exists v; split; auto. + cbn. + rewrite H. + reflexivity. Qed. Lemma make_andlimm_correct: @@ -633,14 +699,17 @@ Proof. - (* mul 2*) InvApproxRegs; SimplVM; inv H0. apply make_mulimm_correct; auto. - (* divs *) - assert (e#r2 = Vint n2). clear H0. InvApproxRegs; SimplVM; auto. - apply make_divimm_correct; auto. + assert (e#r2 = Vint n2). { clear H0. InvApproxRegs; SimplVM; auto. } + apply make_divimm_correct; auto. + congruence. - (* divu *) assert (e#r2 = Vint n2). clear H0. InvApproxRegs; SimplVM; auto. apply make_divuimm_correct; auto. + congruence. - (* modu *) assert (e#r2 = Vint n2). clear H0. InvApproxRegs; SimplVM; auto. apply make_moduimm_correct; auto. + congruence. - (* and 1 *) rewrite Val.and_commut in H0. InvApproxRegs; SimplVM; inv H0. apply make_andimm_correct; auto. - (* and 2 *) @@ -680,12 +749,15 @@ Proof. - (* divl *) assert (e#r2 = Vlong n2). clear H0. InvApproxRegs; SimplVM; auto. apply make_divlimm_correct; auto. + congruence. - (* divlu *) assert (e#r2 = Vlong n2). clear H0. InvApproxRegs; SimplVM; auto. apply make_divluimm_correct; auto. + congruence. - (* modlu *) assert (e#r2 = Vlong n2). clear H0. InvApproxRegs; SimplVM; auto. apply make_modluimm_correct; auto. + congruence. - (* andl 1 *) rewrite Val.andl_commut in H0. InvApproxRegs; SimplVM; inv H0. apply make_andlimm_correct; auto. - (* andl 2 *) @@ -241,10 +241,10 @@ Definition eval_operation | Omul, v1 :: v2 :: nil => Some (Val.mul v1 v2) | Omulhs, v1::v2::nil => Some (Val.mulhs v1 v2) | Omulhu, v1::v2::nil => Some (Val.mulhu v1 v2) - | Odiv, v1 :: v2 :: nil => Val.divs v1 v2 - | Odivu, v1 :: v2 :: nil => Val.divu v1 v2 - | Omod, v1 :: v2 :: nil => Val.mods v1 v2 - | Omodu, v1 :: v2 :: nil => Val.modu v1 v2 + | Odiv, v1 :: v2 :: nil => Some (Val.maketotal (Val.divs v1 v2)) + | Odivu, v1 :: v2 :: nil => Some (Val.maketotal (Val.divu v1 v2)) + | Omod, v1 :: v2 :: nil => Some (Val.maketotal (Val.mods v1 v2)) + | Omodu, v1 :: v2 :: nil => Some (Val.maketotal (Val.modu v1 v2)) | Oand, v1 :: v2 :: nil => Some (Val.and v1 v2) | Oandimm n, v1 :: nil => Some (Val.and v1 (Vint n)) | Oor, v1 :: v2 :: nil => Some (Val.or v1 v2) @@ -257,7 +257,7 @@ Definition eval_operation | Oshrimm n, v1 :: nil => Some (Val.shr v1 (Vint n)) | Oshru, v1 :: v2 :: nil => Some (Val.shru v1 v2) | Oshruimm n, v1 :: nil => Some (Val.shru v1 (Vint n)) - | Oshrximm n, v1::nil => Val.shrx v1 (Vint n) + | Oshrximm n, v1::nil => Some (Val.maketotal (Val.shrx v1 (Vint n))) | Omakelong, v1::v2::nil => Some (Val.longofwords v1 v2) | Olowlong, v1::nil => Some (Val.loword v1) | Ohighlong, v1::nil => Some (Val.hiword v1) @@ -270,10 +270,10 @@ Definition eval_operation | Omull, v1::v2::nil => Some (Val.mull v1 v2) | Omullhs, v1::v2::nil => Some (Val.mullhs v1 v2) | Omullhu, v1::v2::nil => Some (Val.mullhu v1 v2) - | Odivl, v1::v2::nil => Val.divls v1 v2 - | Odivlu, v1::v2::nil => Val.divlu v1 v2 - | Omodl, v1::v2::nil => Val.modls v1 v2 - | Omodlu, v1::v2::nil => Val.modlu v1 v2 + | Odivl, v1::v2::nil => Some (Val.maketotal (Val.divls v1 v2)) + | Odivlu, v1::v2::nil => Some (Val.maketotal (Val.divlu v1 v2)) + | Omodl, v1::v2::nil => Some (Val.maketotal (Val.modls v1 v2)) + | Omodlu, v1::v2::nil => Some (Val.maketotal (Val.modlu v1 v2)) | Oandl, v1::v2::nil => Some(Val.andl v1 v2) | Oandlimm n, v1::nil => Some (Val.andl v1 (Vlong n)) | Oorl, v1::v2::nil => Some(Val.orl v1 v2) @@ -286,7 +286,7 @@ Definition eval_operation | Oshrlimm n, v1::nil => Some (Val.shrl v1 (Vint n)) | Oshrlu, v1::v2::nil => Some (Val.shrlu v1 v2) | Oshrluimm n, v1::nil => Some (Val.shrlu v1 (Vint n)) - | Oshrxlimm n, v1::nil => Val.shrxl v1 (Vint n) + | Oshrxlimm n, v1::nil => Some (Val.maketotal (Val.shrxl v1 (Vint n))) | Onegf, v1::nil => Some (Val.negf v1) | Oabsf, v1::nil => Some (Val.absf v1) | Oaddf, v1::v2::nil => Some (Val.addf v1 v2) @@ -301,22 +301,22 @@ Definition eval_operation | Odivfs, v1::v2::nil => Some (Val.divfs v1 v2) | Osingleoffloat, v1::nil => Some (Val.singleoffloat v1) | Ofloatofsingle, v1::nil => Some (Val.floatofsingle v1) - | Ointoffloat, v1::nil => Val.intoffloat v1 - | Ointuoffloat, v1::nil => Val.intuoffloat v1 - | Ofloatofint, v1::nil => Val.floatofint v1 - | Ofloatofintu, v1::nil => Val.floatofintu v1 - | Ointofsingle, v1::nil => Val.intofsingle v1 - | Ointuofsingle, v1::nil => Val.intuofsingle v1 - | Osingleofint, v1::nil => Val.singleofint v1 - | Osingleofintu, v1::nil => Val.singleofintu v1 - | Olongoffloat, v1::nil => Val.longoffloat v1 - | Olonguoffloat, v1::nil => Val.longuoffloat v1 - | Ofloatoflong, v1::nil => Val.floatoflong v1 - | Ofloatoflongu, v1::nil => Val.floatoflongu v1 - | Olongofsingle, v1::nil => Val.longofsingle v1 - | Olonguofsingle, v1::nil => Val.longuofsingle v1 - | Osingleoflong, v1::nil => Val.singleoflong v1 - | Osingleoflongu, v1::nil => Val.singleoflongu v1 + | Ointoffloat, v1::nil => Some (Val.maketotal (Val.intoffloat v1)) + | Ointuoffloat, v1::nil => Some (Val.maketotal (Val.intuoffloat v1)) + | Ofloatofint, v1::nil => Some (Val.maketotal (Val.floatofint v1)) + | Ofloatofintu, v1::nil => Some (Val.maketotal (Val.floatofintu v1)) + | Ointofsingle, v1::nil => Some (Val.maketotal (Val.intofsingle v1)) + | Ointuofsingle, v1::nil => Some (Val.maketotal (Val.intuofsingle v1)) + | Osingleofint, v1::nil => Some (Val.maketotal (Val.singleofint v1)) + | Osingleofintu, v1::nil => Some (Val.maketotal (Val.singleofintu v1)) + | Olongoffloat, v1::nil => Some (Val.maketotal (Val.longoffloat v1)) + | Olonguoffloat, v1::nil => Some (Val.maketotal (Val.longuoffloat v1)) + | Ofloatoflong, v1::nil => Some (Val.maketotal (Val.floatoflong v1)) + | Ofloatoflongu, v1::nil => Some (Val.maketotal (Val.floatoflongu v1)) + | Olongofsingle, v1::nil => Some (Val.maketotal (Val.longofsingle v1)) + | Olonguofsingle, v1::nil => Some (Val.maketotal (Val.longuofsingle v1)) + | Osingleoflong, v1::nil => Some (Val.maketotal (Val.singleoflong v1)) + | Osingleoflongu, v1::nil => Some (Val.maketotal (Val.singleoflongu v1)) | Ocmp c, _ => Some (Val.of_optbool (eval_condition c vl m)) | _, _ => None end. @@ -539,15 +539,17 @@ Proof with (try exact I; try reflexivity; auto using Val.Vptr_has_type). - destruct v0; destruct v1... - destruct v0; destruct v1... (* div, divu *) - - destruct v0; destruct v1; simpl in *; inv H0. - destruct (Int.eq i0 Int.zero || Int.eq i (Int.repr Int.min_signed) && Int.eq i0 Int.mone); inv H2... - - destruct v0; destruct v1; simpl in *; inv H0. - destruct (Int.eq i0 Int.zero); inv H2... + - destruct v0; destruct v1; cbn; trivial. + destruct (Int.eq i0 Int.zero + || Int.eq i (Int.repr (-2147483648)) && Int.eq i0 Int.mone); cbn; trivial. + - destruct v0; destruct v1; cbn; trivial. + destruct (Int.eq i0 Int.zero); cbn; trivial. (* mod, modu *) - - destruct v0; destruct v1; simpl in *; inv H0. - destruct (Int.eq i0 Int.zero || Int.eq i (Int.repr Int.min_signed) && Int.eq i0 Int.mone); inv H2... - - destruct v0; destruct v1; simpl in *; inv H0. - destruct (Int.eq i0 Int.zero); inv H2... + - destruct v0; destruct v1; cbn; trivial. + destruct (Int.eq i0 Int.zero + || Int.eq i (Int.repr (-2147483648)) && Int.eq i0 Int.mone); cbn; trivial. + - destruct v0; destruct v1; cbn; trivial. + destruct (Int.eq i0 Int.zero); cbn; trivial. (* and, andimm *) - destruct v0; destruct v1... - destruct v0... @@ -567,7 +569,8 @@ Proof with (try exact I; try reflexivity; auto using Val.Vptr_has_type). - destruct v0; destruct v1; simpl... destruct (Int.ltu i0 Int.iwordsize)... - destruct v0; simpl... destruct (Int.ltu n Int.iwordsize)... (* shrx *) - - destruct v0; simpl in H0; try discriminate. destruct (Int.ltu n (Int.repr 31)); inv H0... + - destruct v0; cbn; trivial. + destruct (Int.ltu n (Int.repr 31)); cbn; trivial. (* makelong, lowlong, highlong *) - destruct v0; destruct v1... - destruct v0... @@ -588,15 +591,19 @@ Proof with (try exact I; try reflexivity; auto using Val.Vptr_has_type). - destruct v0; destruct v1... - destruct v0; destruct v1... (* divl, divlu *) - - destruct v0; destruct v1; simpl in *; inv H0. - destruct (Int64.eq i0 Int64.zero || Int64.eq i (Int64.repr Int64.min_signed) && Int64.eq i0 Int64.mone); inv H2... - - destruct v0; destruct v1; simpl in *; inv H0. - destruct (Int64.eq i0 Int64.zero); inv H2... + - destruct v0; destruct v1; cbn; trivial. + destruct (Int64.eq i0 Int64.zero + || Int64.eq i (Int64.repr (-9223372036854775808)) && + Int64.eq i0 Int64.mone); cbn; trivial. + - destruct v0; destruct v1; cbn; trivial. + destruct (Int64.eq i0 Int64.zero); cbn; trivial. (* modl, modlu *) - - destruct v0; destruct v1; simpl in *; inv H0. - destruct (Int64.eq i0 Int64.zero || Int64.eq i (Int64.repr Int64.min_signed) && Int64.eq i0 Int64.mone); inv H2... - - destruct v0; destruct v1; simpl in *; inv H0. - destruct (Int64.eq i0 Int64.zero); inv H2... + - destruct v0; destruct v1; cbn; trivial. + destruct (Int64.eq i0 Int64.zero + || Int64.eq i (Int64.repr (-9223372036854775808)) && + Int64.eq i0 Int64.mone); cbn; trivial. + - destruct v0; destruct v1; cbn; trivial. + destruct (Int64.eq i0 Int64.zero); cbn; trivial. (* andl, andlimm *) - destruct v0; destruct v1... - destruct v0... @@ -616,7 +623,8 @@ Proof with (try exact I; try reflexivity; auto using Val.Vptr_has_type). - destruct v0; destruct v1; simpl... destruct (Int.ltu i0 Int64.iwordsize')... - destruct v0; simpl... destruct (Int.ltu n Int64.iwordsize')... (* shrxl *) - - destruct v0; simpl in H0; try discriminate. destruct (Int.ltu n (Int.repr 63)); inv H0... + - destruct v0; cbn; trivial. + destruct (Int.ltu n (Int.repr 63)); cbn; trivial. (* negf, absf *) - destruct v0... - destruct v0... @@ -639,50 +647,47 @@ Proof with (try exact I; try reflexivity; auto using Val.Vptr_has_type). - destruct v0... - destruct v0... (* intoffloat, intuoffloat *) - - destruct v0; simpl in H0; inv H0. destruct (Float.to_int f); inv H2... - - destruct v0; simpl in H0; inv H0. destruct (Float.to_intu f); inv H2... + - destruct v0; cbn; trivial. + destruct (Float.to_int f); cbn; trivial. + - destruct v0; cbn; trivial. + destruct (Float.to_intu f); cbn; trivial. (* floatofint, floatofintu *) - - destruct v0; simpl in H0; inv H0... - - destruct v0; simpl in H0; inv H0... + - destruct v0; cbn; trivial. + - destruct v0; cbn; trivial. (* intofsingle, intuofsingle *) - - destruct v0; simpl in H0; inv H0. destruct (Float32.to_int f); inv H2... - - destruct v0; simpl in H0; inv H0. destruct (Float32.to_intu f); inv H2... + - destruct v0; cbn; trivial. + destruct (Float32.to_int f); cbn; trivial. + - destruct v0; cbn; trivial. + destruct (Float32.to_intu f); cbn; trivial. (* singleofint, singleofintu *) - - destruct v0; simpl in H0; inv H0... - - destruct v0; simpl in H0; inv H0... + - destruct v0; cbn; trivial. + - destruct v0; cbn; trivial. (* longoffloat, longuoffloat *) - - destruct v0; simpl in H0; inv H0. destruct (Float.to_long f); inv H2... - - destruct v0; simpl in H0; inv H0. destruct (Float.to_longu f); inv H2... + - destruct v0; cbn; trivial. + destruct (Float.to_long f); cbn; trivial. + - destruct v0; cbn; trivial. + destruct (Float.to_longu f); cbn; trivial. (* floatoflong, floatoflongu *) - - destruct v0; simpl in H0; inv H0... - - destruct v0; simpl in H0; inv H0... + - destruct v0; cbn; trivial. + - destruct v0; cbn; trivial. (* longofsingle, longuofsingle *) - - destruct v0; simpl in H0; inv H0. destruct (Float32.to_long f); inv H2... - - destruct v0; simpl in H0; inv H0. destruct (Float32.to_longu f); inv H2... + - destruct v0; cbn; trivial. + destruct (Float32.to_long f); cbn; trivial. + - destruct v0; cbn; trivial. + destruct (Float32.to_longu f); cbn; trivial. (* singleoflong, singleoflongu *) - - destruct v0; simpl in H0; inv H0... - - destruct v0; simpl in H0; inv H0... + - destruct v0; cbn; trivial. + - destruct v0; cbn; trivial. (* cmp *) - destruct (eval_condition cond vl m)... destruct b... Qed. - +(* This should not be simplified to "false" because it breaks proofs elsewhere. *) Definition is_trapping_op (op : operation) := match op with - | Odiv | Odivl | Odivu | Odivlu - | Omod | Omodl | Omodu | Omodlu - | Oshrximm _ | Oshrxlimm _ - | Ointoffloat | Ointuoffloat - | Ointofsingle | Ointuofsingle - | Olongoffloat | Olonguoffloat - | Olongofsingle | Olonguofsingle - | Osingleofint | Osingleofintu - | Osingleoflong | Osingleoflongu - | Ofloatofint | Ofloatofintu - | Ofloatoflong | Ofloatoflongu => true + | Omove => false | _ => false end. - Definition args_of_operation op := if eq_operation op Omove @@ -1033,19 +1038,29 @@ Proof. - inv H4; inv H2; simpl; auto. - inv H4; inv H2; simpl; auto. (* div, divu *) - - inv H4; inv H3; simpl in H1; inv H1. simpl. + - inv H4; inv H2; cbn. + all: try apply Val.val_inject_undef. destruct (Int.eq i0 Int.zero - || Int.eq i (Int.repr Int.min_signed) && Int.eq i0 Int.mone); inv H2. - TrivialExists. - - inv H4; inv H3; simpl in H1; inv H1. simpl. - destruct (Int.eq i0 Int.zero); inv H2. TrivialExists. + || Int.eq i (Int.repr (-2147483648)) && Int.eq i0 Int.mone); cbn. + apply Val.val_inject_undef. + apply Val.inject_int. + - inv H4; inv H2; cbn. + all: try apply Val.val_inject_undef. + destruct (Int.eq i0 Int.zero); cbn. + apply Val.val_inject_undef. + apply Val.inject_int. (* mod, modu *) - - inv H4; inv H3; simpl in H1; inv H1. simpl. + - inv H4; inv H2; cbn. + all: try apply Val.val_inject_undef. destruct (Int.eq i0 Int.zero - || Int.eq i (Int.repr Int.min_signed) && Int.eq i0 Int.mone); inv H2. - TrivialExists. - - inv H4; inv H3; simpl in H1; inv H1. simpl. - destruct (Int.eq i0 Int.zero); inv H2. TrivialExists. + || Int.eq i (Int.repr (-2147483648)) && Int.eq i0 Int.mone); cbn. + apply Val.val_inject_undef. + apply Val.inject_int. + - inv H4; inv H2; cbn. + all: try apply Val.val_inject_undef. + destruct (Int.eq i0 Int.zero); cbn. + apply Val.val_inject_undef. + apply Val.inject_int. (* and, andimm *) - inv H4; inv H2; simpl; auto. - inv H4; simpl; auto. @@ -1065,8 +1080,10 @@ Proof. - inv H4; inv H2; simpl; auto. destruct (Int.ltu i0 Int.iwordsize); auto. - inv H4; simpl; auto. destruct (Int.ltu n Int.iwordsize); auto. (* shrx *) - - inv H4; simpl in H1; try discriminate. simpl. - destruct (Int.ltu n (Int.repr 31)); inv H1. TrivialExists. + - inv H4; cbn; try apply Val.val_inject_undef. + destruct (Int.ltu n (Int.repr 31)); cbn. + apply Val.inject_int. + apply Val.val_inject_undef. (* makelong, highlong, lowlong *) - inv H4; inv H2; simpl; auto. - inv H4; simpl; auto. @@ -1085,19 +1102,31 @@ Proof. - inv H4; inv H2; simpl; auto. - inv H4; inv H2; simpl; auto. (* divl, divlu *) - - inv H4; inv H3; simpl in H1; inv H1. simpl. + - inv H4; inv H2; cbn. + all: try apply Val.val_inject_undef. destruct (Int64.eq i0 Int64.zero - || Int64.eq i (Int64.repr Int64.min_signed) && Int64.eq i0 Int64.mone); inv H2. - TrivialExists. - - inv H4; inv H3; simpl in H1; inv H1. simpl. - destruct (Int64.eq i0 Int64.zero); inv H2. TrivialExists. + || Int64.eq i (Int64.repr (-9223372036854775808)) && + Int64.eq i0 Int64.mone); cbn. + apply Val.val_inject_undef. + apply Val.inject_long. + - inv H4; inv H2; cbn. + all: try apply Val.val_inject_undef. + destruct (Int64.eq i0 Int64.zero); cbn. + apply Val.val_inject_undef. + apply Val.inject_long. (* modl, modlu *) - - inv H4; inv H3; simpl in H1; inv H1. simpl. + - inv H4; inv H2; cbn. + all: try apply Val.val_inject_undef. destruct (Int64.eq i0 Int64.zero - || Int64.eq i (Int64.repr Int64.min_signed) && Int64.eq i0 Int64.mone); inv H2. - TrivialExists. - - inv H4; inv H3; simpl in H1; inv H1. simpl. - destruct (Int64.eq i0 Int64.zero); inv H2. TrivialExists. + || Int64.eq i (Int64.repr (-9223372036854775808)) && + Int64.eq i0 Int64.mone); cbn. + apply Val.val_inject_undef. + apply Val.inject_long. + - inv H4; inv H2; cbn. + all: try apply Val.val_inject_undef. + destruct (Int64.eq i0 Int64.zero); cbn. + apply Val.val_inject_undef. + apply Val.inject_long. (* andl, andlimm *) - inv H4; inv H2; simpl; auto. - inv H4; simpl; auto. @@ -1116,9 +1145,11 @@ Proof. (* shru, shruimm *) - inv H4; inv H2; simpl; auto. destruct (Int.ltu i0 Int64.iwordsize'); auto. - inv H4; simpl; auto. destruct (Int.ltu n Int64.iwordsize'); auto. - (* shrx *) - - inv H4; simpl in H1; try discriminate. simpl. - destruct (Int.ltu n (Int.repr 63)); inv H1. TrivialExists. + (* shrx *) + - inv H4; cbn; try apply Val.val_inject_undef. + destruct (Int.ltu n (Int.repr 63)); cbn. + apply Val.inject_long. + apply Val.val_inject_undef. (* negf, absf *) - inv H4; simpl; auto. - inv H4; simpl; auto. @@ -1141,37 +1172,37 @@ Proof. - inv H4; simpl; auto. - inv H4; simpl; auto. (* intoffloat, intuoffloat *) - - inv H4; simpl in H1; inv H1. simpl. destruct (Float.to_int f0); simpl in H2; inv H2. - exists (Vint i); auto. - - inv H4; simpl in H1; inv H1. simpl. destruct (Float.to_intu f0); simpl in H2; inv H2. - exists (Vint i); auto. + - inv H4; cbn; auto. + destruct (Float.to_int f0); cbn; auto. + - inv H4; cbn; auto. + destruct (Float.to_intu f0); cbn; auto. (* floatofint, floatofintu *) - - inv H4; simpl in H1; inv H1. simpl. TrivialExists. - - inv H4; simpl in H1; inv H1. simpl. TrivialExists. + - inv H4; cbn; auto. + - inv H4; cbn; auto. (* intofsingle, intuofsingle *) - - inv H4; simpl in H1; inv H1. simpl. destruct (Float32.to_int f0); simpl in H2; inv H2. - exists (Vint i); auto. - - inv H4; simpl in H1; inv H1. simpl. destruct (Float32.to_intu f0); simpl in H2; inv H2. - exists (Vint i); auto. + - inv H4; cbn; auto. + destruct (Float32.to_int f0); cbn; auto. + - inv H4; cbn; auto. + destruct (Float32.to_intu f0); cbn; auto. (* singleofint, singleofintu *) - - inv H4; simpl in H1; inv H1. simpl. TrivialExists. - - inv H4; simpl in H1; inv H1. simpl. TrivialExists. + - inv H4; cbn; auto. + - inv H4; cbn; auto. (* longoffloat, longuoffloat *) - - inv H4; simpl in H1; inv H1. simpl. destruct (Float.to_long f0); simpl in H2; inv H2. - exists (Vlong i); auto. - - inv H4; simpl in H1; inv H1. simpl. destruct (Float.to_longu f0); simpl in H2; inv H2. - exists (Vlong i); auto. + - inv H4; cbn; auto. + destruct (Float.to_long f0); cbn; auto. + - inv H4; cbn; auto. + destruct (Float.to_longu f0); cbn; auto. (* floatoflong, floatoflongu *) - - inv H4; simpl in H1; inv H1. simpl. TrivialExists. - - inv H4; simpl in H1; inv H1. simpl. TrivialExists. + - inv H4; cbn; auto. + - inv H4; cbn; auto. (* longofsingle, longuofsingle *) - - inv H4; simpl in H1; inv H1. simpl. destruct (Float32.to_long f0); simpl in H2; inv H2. - exists (Vlong i); auto. - - inv H4; simpl in H1; inv H1. simpl. destruct (Float32.to_longu f0); simpl in H2; inv H2. - exists (Vlong i); auto. + - inv H4; cbn; auto. + destruct (Float32.to_long f0); cbn; auto. + - inv H4; cbn; auto. + destruct (Float32.to_longu f0); cbn; auto. (* singleoflong, singleoflongu *) - - inv H4; simpl in H1; inv H1. simpl. TrivialExists. - - inv H4; simpl in H1; inv H1. simpl. TrivialExists. + - inv H4; cbn; auto. + - inv H4; cbn; auto. (* cmp *) - subst v1. destruct (eval_condition cond vl1 m1) eqn:?. exploit eval_condition_inj; eauto. intros EQ; rewrite EQ. diff --git a/riscV/OpWeights.ml b/riscV/OpWeights.ml new file mode 100644 index 00000000..143435c1 --- /dev/null +++ b/riscV/OpWeights.ml @@ -0,0 +1,39 @@ +open Op;; + +(* Attempt at modeling SweRV EH1 +[| issues ; LSU ; multiplier |] *) +let resource_bounds = [| 2 ; 1; 1 |];; +let nr_non_pipelined_units = 1;; (* divider *) + +let latency_of_op (op : operation) (nargs : int) = + match op with + | Omul | Omulhs | Omulhu + | Omull | Omullhs | Omullhu -> 3 + | Odiv | Odivu | Odivl | Odivlu -> 16 + | _ -> 1;; + +let resources_of_op (op : operation) (nargs : int) = + match op with + | Omul | Omulhs | Omulhu + | Omull | Omullhs | Omullhu -> [| 1 ; 0 ; 1 |] + | Odiv | Odivu | Odivl | Odivlu -> [| 0 ; 0; 0 |] + | _ -> [| 1; 0; 0; 0 |];; + +let non_pipelined_resources_of_op (op : operation) (nargs : int) = + match op with + | Odiv | Odivu -> [| 29 |] + | Odivfs -> [| 20 |] + | Odivl | Odivlu | Odivf -> [| 50 |] + | _ -> [| -1 |];; + +let resources_of_cond (cond : condition) (nargs : int) = [| 1; 0; 0 |];; + +let latency_of_load trap chunk (addr : addressing) (nargs : int) = 3;; +let latency_of_call _ _ = 6;; + +let resources_of_load trap chunk addressing nargs = [| 1; 1; 0 |];; + +let resources_of_store chunk addressing nargs = [| 1; 1; 0 |];; + +let resources_of_call _ _ = resource_bounds;; +let resources_of_builtin _ = resource_bounds;; diff --git a/riscV/PrepassSchedulingOracle.ml b/riscV/PrepassSchedulingOracle.ml new file mode 120000 index 00000000..912e9ffa --- /dev/null +++ b/riscV/PrepassSchedulingOracle.ml @@ -0,0 +1 @@ +../aarch64/PrepassSchedulingOracle.ml
\ No newline at end of file diff --git a/riscV/SelectLongproof.v b/riscV/SelectLongproof.v index d47b6d64..0fc578bf 100644 --- a/riscV/SelectLongproof.v +++ b/riscV/SelectLongproof.v @@ -455,6 +455,10 @@ Proof. unfold divls_base; red; intros. destruct Archi.splitlong eqn:SL. eapply SplitLongproof.eval_divls_base; eauto. TrivialExists. + cbn. + rewrite H1. + cbn. + trivial. Qed. Theorem eval_modls_base: partial_binary_constructor_sound modls_base Val.modls. @@ -462,6 +466,10 @@ Proof. unfold modls_base; red; intros. destruct Archi.splitlong eqn:SL. eapply SplitLongproof.eval_modls_base; eauto. TrivialExists. + cbn. + rewrite H1. + cbn. + trivial. Qed. Theorem eval_divlu_base: partial_binary_constructor_sound divlu_base Val.divlu. @@ -469,6 +477,10 @@ Proof. unfold divlu_base; red; intros. destruct Archi.splitlong eqn:SL. eapply SplitLongproof.eval_divlu_base; eauto. TrivialExists. + cbn. + rewrite H1. + cbn. + trivial. Qed. Theorem eval_modlu_base: partial_binary_constructor_sound modlu_base Val.modlu. @@ -476,6 +488,10 @@ Proof. unfold modlu_base; red; intros. destruct Archi.splitlong eqn:SL. eapply SplitLongproof.eval_modlu_base; eauto. TrivialExists. + cbn. + rewrite H1. + cbn. + trivial. Qed. Theorem eval_shrxlimm: @@ -490,33 +506,9 @@ Proof. - subst n. destruct x; simpl in H0; inv H0. econstructor; split; eauto. change (Int.ltu Int.zero (Int.repr 63)) with true. simpl. rewrite Int64.shrx'_zero; auto. - TrivialExists. -(* - intros. unfold shrxlimm. destruct Archi.splitlong eqn:SL. -+ eapply SplitLongproof.eval_shrxlimm; eauto using Archi.splitlong_ptr32. -+ destruct x; simpl in H0; try discriminate. - destruct (Int.ltu n (Int.repr 63)) eqn:LTU; inv H0. - predSpec Int.eq Int.eq_spec n Int.zero. - - subst n. exists (Vlong i); split; auto. rewrite Int64.shrx'_zero. auto. - - assert (NZ: Int.unsigned n <> 0). - { intro EQ; elim H0. rewrite <- (Int.repr_unsigned n). rewrite EQ; auto. } - assert (LT: 0 <= Int.unsigned n < 63) by (apply Int.ltu_inv in LTU; assumption). - assert (LTU2: Int.ltu (Int.sub Int64.iwordsize' n) Int64.iwordsize' = true). - { unfold Int.ltu; apply zlt_true. - unfold Int.sub. change (Int.unsigned Int64.iwordsize') with 64. - rewrite Int.unsigned_repr. omega. - assert (64 < Int.max_unsigned) by reflexivity. omega. } - assert (X: eval_expr ge sp e m le - (Eop (Oshrlimm (Int.repr (Int64.zwordsize - 1))) (a ::: Enil)) - (Vlong (Int64.shr' i (Int.repr (Int64.zwordsize - 1))))). - { EvalOp. } - assert (Y: eval_expr ge sp e m le (shrxlimm_inner a n) - (Vlong (Int64.shru' (Int64.shr' i (Int.repr (Int64.zwordsize - 1))) (Int.sub Int64.iwordsize' n)))). - { EvalOp. simpl. rewrite LTU2. auto. } - TrivialExists. - constructor. EvalOp. simpl; eauto. constructor. - simpl. unfold Int.ltu; rewrite zlt_true. rewrite Int64.shrx'_shr_2 by auto. reflexivity. - change (Int.unsigned Int64.iwordsize') with 64; omega. -*) + cbn. + rewrite H0. + reflexivity. Qed. Theorem eval_cmplu: @@ -566,6 +558,7 @@ Proof. unfold longoffloat; red; intros. destruct Archi.splitlong eqn:SL. eapply SplitLongproof.eval_longoffloat; eauto. TrivialExists. + cbn; rewrite H0; reflexivity. Qed. Theorem eval_longuoffloat: partial_unary_constructor_sound longuoffloat Val.longuoffloat. @@ -573,6 +566,7 @@ Proof. unfold longuoffloat; red; intros. destruct Archi.splitlong eqn:SL. eapply SplitLongproof.eval_longuoffloat; eauto. TrivialExists. + cbn; rewrite H0; reflexivity. Qed. Theorem eval_floatoflong: partial_unary_constructor_sound floatoflong Val.floatoflong. @@ -580,6 +574,7 @@ Proof. unfold floatoflong; red; intros. destruct Archi.splitlong eqn:SL. eapply SplitLongproof.eval_floatoflong; eauto. TrivialExists. + cbn; rewrite H0; reflexivity. Qed. Theorem eval_floatoflongu: partial_unary_constructor_sound floatoflongu Val.floatoflongu. @@ -587,6 +582,7 @@ Proof. unfold floatoflongu; red; intros. destruct Archi.splitlong eqn:SL. eapply SplitLongproof.eval_floatoflongu; eauto. TrivialExists. + cbn; rewrite H0; reflexivity. Qed. Theorem eval_longofsingle: partial_unary_constructor_sound longofsingle Val.longofsingle. @@ -594,6 +590,7 @@ Proof. unfold longofsingle; red; intros. destruct Archi.splitlong eqn:SL. eapply SplitLongproof.eval_longofsingle; eauto. TrivialExists. + cbn; rewrite H0; reflexivity. Qed. Theorem eval_longuofsingle: partial_unary_constructor_sound longuofsingle Val.longuofsingle. @@ -601,6 +598,7 @@ Proof. unfold longuofsingle; red; intros. destruct Archi.splitlong eqn:SL. eapply SplitLongproof.eval_longuofsingle; eauto. TrivialExists. + cbn; rewrite H0; reflexivity. Qed. Theorem eval_singleoflong: partial_unary_constructor_sound singleoflong Val.singleoflong. @@ -608,6 +606,7 @@ Proof. unfold singleoflong; red; intros. destruct Archi.splitlong eqn:SL. eapply SplitLongproof.eval_singleoflong; eauto. TrivialExists. + cbn; rewrite H0; reflexivity. Qed. Theorem eval_singleoflongu: partial_unary_constructor_sound singleoflongu Val.singleoflongu. @@ -615,6 +614,7 @@ Proof. unfold singleoflongu; red; intros. destruct Archi.splitlong eqn:SL. eapply SplitLongproof.eval_singleoflongu; eauto. TrivialExists. + cbn; rewrite H0; reflexivity. Qed. End CMCONSTR. diff --git a/riscV/SelectOpproof.v b/riscV/SelectOpproof.v index 7f2014dc..1d13702a 100644 --- a/riscV/SelectOpproof.v +++ b/riscV/SelectOpproof.v @@ -506,7 +506,12 @@ Theorem eval_divs_base: Val.divs x y = Some z -> exists v, eval_expr ge sp e m le (divs_base a b) v /\ Val.lessdef z v. Proof. - intros. unfold divs_base. exists z; split. EvalOp. auto. + intros. unfold divs_base. exists z; split. EvalOp. + 2: apply Val.lessdef_refl. + cbn. + rewrite H1. + cbn. + trivial. Qed. Theorem eval_mods_base: @@ -516,7 +521,12 @@ Theorem eval_mods_base: Val.mods x y = Some z -> exists v, eval_expr ge sp e m le (mods_base a b) v /\ Val.lessdef z v. Proof. - intros. unfold mods_base. exists z; split. EvalOp. auto. + intros. unfold mods_base. exists z; split. EvalOp. + 2: apply Val.lessdef_refl. + cbn. + rewrite H1. + cbn. + trivial. Qed. Theorem eval_divu_base: @@ -526,7 +536,12 @@ Theorem eval_divu_base: Val.divu x y = Some z -> exists v, eval_expr ge sp e m le (divu_base a b) v /\ Val.lessdef z v. Proof. - intros. unfold divu_base. exists z; split. EvalOp. auto. + intros. unfold divu_base. exists z; split. EvalOp. + 2: apply Val.lessdef_refl. + cbn. + rewrite H1. + cbn. + trivial. Qed. Theorem eval_modu_base: @@ -536,7 +551,12 @@ Theorem eval_modu_base: Val.modu x y = Some z -> exists v, eval_expr ge sp e m le (modu_base a b) v /\ Val.lessdef z v. Proof. - intros. unfold modu_base. exists z; split. EvalOp. auto. + intros. unfold modu_base. exists z; split. EvalOp. + 2: apply Val.lessdef_refl. + cbn. + rewrite H1. + cbn. + trivial. Qed. Theorem eval_shrximm: @@ -553,34 +573,12 @@ Proof. replace (Int.shrx i Int.zero) with i. auto. unfold Int.shrx, Int.divs. rewrite Int.shl_zero. change (Int.signed Int.one) with 1. rewrite Z.quot_1_r. rewrite Int.repr_signed; auto. - econstructor; split. EvalOp. auto. -(* - intros. destruct x; simpl in H0; try discriminate. - destruct (Int.ltu n (Int.repr 31)) eqn:LTU; inv H0. - unfold shrximm. - predSpec Int.eq Int.eq_spec n Int.zero. - - subst n. exists (Vint i); split; auto. - unfold Int.shrx, Int.divs. rewrite Z.quot_1_r. rewrite Int.repr_signed. auto. - - assert (NZ: Int.unsigned n <> 0). - { intro EQ; elim H0. rewrite <- (Int.repr_unsigned n). rewrite EQ; auto. } - assert (LT: 0 <= Int.unsigned n < 31) by (apply Int.ltu_inv in LTU; assumption). - assert (LTU2: Int.ltu (Int.sub Int.iwordsize n) Int.iwordsize = true). - { unfold Int.ltu; apply zlt_true. - unfold Int.sub. change (Int.unsigned Int.iwordsize) with 32. - rewrite Int.unsigned_repr. omega. - assert (32 < Int.max_unsigned) by reflexivity. omega. } - assert (X: eval_expr ge sp e m le - (Eop (Oshrimm (Int.repr (Int.zwordsize - 1))) (a ::: Enil)) - (Vint (Int.shr i (Int.repr (Int.zwordsize - 1))))). - { EvalOp. } - assert (Y: eval_expr ge sp e m le (shrximm_inner a n) - (Vint (Int.shru (Int.shr i (Int.repr (Int.zwordsize - 1))) (Int.sub Int.iwordsize n)))). - { EvalOp. simpl. rewrite LTU2. auto. } - TrivialExists. - constructor. EvalOp. simpl; eauto. constructor. - simpl. unfold Int.ltu; rewrite zlt_true. rewrite Int.shrx_shr_2 by auto. reflexivity. - change (Int.unsigned Int.iwordsize) with 32; omega. -*) + econstructor; split. EvalOp. + cbn. + rewrite H0. + cbn. + reflexivity. + apply Val.lessdef_refl. Qed. Theorem eval_shl: binary_constructor_sound shl Val.shl. @@ -790,6 +788,7 @@ Theorem eval_intoffloat: exists v, eval_expr ge sp e m le (intoffloat a) v /\ Val.lessdef y v. Proof. intros; unfold intoffloat. TrivialExists. + cbn. rewrite H0. reflexivity. Qed. Theorem eval_intuoffloat: @@ -799,6 +798,7 @@ Theorem eval_intuoffloat: exists v, eval_expr ge sp e m le (intuoffloat a) v /\ Val.lessdef y v. Proof. intros; unfold intuoffloat. TrivialExists. + cbn. rewrite H0. reflexivity. Qed. Theorem eval_floatofintu: @@ -810,6 +810,7 @@ Proof. intros until y; unfold floatofintu. case (floatofintu_match a); intros. InvEval. simpl in H0. TrivialExists. TrivialExists. + cbn. rewrite H0. reflexivity. Qed. Theorem eval_floatofint: @@ -821,6 +822,7 @@ Proof. intros until y; unfold floatofint. case (floatofint_match a); intros. InvEval. simpl in H0. TrivialExists. TrivialExists. + cbn. rewrite H0. reflexivity. Qed. Theorem eval_intofsingle: @@ -830,6 +832,7 @@ Theorem eval_intofsingle: exists v, eval_expr ge sp e m le (intofsingle a) v /\ Val.lessdef y v. Proof. intros; unfold intofsingle. TrivialExists. + cbn. rewrite H0. reflexivity. Qed. Theorem eval_singleofint: @@ -839,6 +842,7 @@ Theorem eval_singleofint: exists v, eval_expr ge sp e m le (singleofint a) v /\ Val.lessdef y v. Proof. intros; unfold singleofint; TrivialExists. + cbn. rewrite H0. reflexivity. Qed. Theorem eval_intuofsingle: @@ -848,6 +852,7 @@ Theorem eval_intuofsingle: exists v, eval_expr ge sp e m le (intuofsingle a) v /\ Val.lessdef y v. Proof. intros; unfold intuofsingle. TrivialExists. + cbn. rewrite H0. reflexivity. Qed. Theorem eval_singleofintu: @@ -857,6 +862,7 @@ Theorem eval_singleofintu: exists v, eval_expr ge sp e m le (singleofintu a) v /\ Val.lessdef y v. Proof. intros; unfold intuofsingle. TrivialExists. + cbn. rewrite H0. reflexivity. Qed. Theorem eval_singleoffloat: unary_constructor_sound singleoffloat Val.singleoffloat. diff --git a/riscV/ValueAOp.v b/riscV/ValueAOp.v index 5670b5fe..f4b7b4d6 100644 --- a/riscV/ValueAOp.v +++ b/riscV/ValueAOp.v @@ -13,6 +13,7 @@ Require Import Coqlib Compopts. Require Import AST Integers Floats Values Memory Globalenvs. Require Import Op RTL ValueDomain. +Require Import Zbits. (** Value analysis for RISC V operators *) @@ -59,10 +60,10 @@ Definition eval_static_operation (op: operation) (vl: list aval): aval := | Omul, v1::v2::nil => mul v1 v2 | Omulhs, v1::v2::nil => mulhs v1 v2 | Omulhu, v1::v2::nil => mulhu v1 v2 - | Odiv, v1::v2::nil => divs v1 v2 - | Odivu, v1::v2::nil => divu v1 v2 - | Omod, v1::v2::nil => mods v1 v2 - | Omodu, v1::v2::nil => modu v1 v2 + | Odiv, v1::v2::nil => divs_total v1 v2 + | Odivu, v1::v2::nil => divu_total v1 v2 + | Omod, v1::v2::nil => mods_total v1 v2 + | Omodu, v1::v2::nil => modu_total v1 v2 | Oand, v1::v2::nil => and v1 v2 | Oandimm n, v1::nil => and v1 (I n) | Oor, v1::v2::nil => or v1 v2 @@ -88,10 +89,10 @@ Definition eval_static_operation (op: operation) (vl: list aval): aval := | Omull, v1::v2::nil => mull v1 v2 | Omullhs, v1::v2::nil => mullhs v1 v2 | Omullhu, v1::v2::nil => mullhu v1 v2 - | Odivl, v1::v2::nil => divls v1 v2 - | Odivlu, v1::v2::nil => divlu v1 v2 - | Omodl, v1::v2::nil => modls v1 v2 - | Omodlu, v1::v2::nil => modlu v1 v2 + | Odivl, v1::v2::nil => divls_total v1 v2 + | Odivlu, v1::v2::nil => divlu_total v1 v2 + | Omodl, v1::v2::nil => modls_total v1 v2 + | Omodlu, v1::v2::nil => modlu_total v1 v2 | Oandl, v1::v2::nil => andl v1 v2 | Oandlimm n, v1::nil => andl v1 (L n) | Oorl, v1::v2::nil => orl v1 v2 @@ -119,20 +120,20 @@ Definition eval_static_operation (op: operation) (vl: list aval): aval := | Odivfs, v1::v2::nil => divfs v1 v2 | Osingleoffloat, v1::nil => singleoffloat v1 | Ofloatofsingle, v1::nil => floatofsingle v1 - | Ointoffloat, v1::nil => intoffloat v1 - | Ointuoffloat, v1::nil => intuoffloat v1 + | Ointoffloat, v1::nil => intoffloat_total v1 + | Ointuoffloat, v1::nil => intuoffloat_total v1 | Ofloatofint, v1::nil => floatofint v1 | Ofloatofintu, v1::nil => floatofintu v1 - | Ointofsingle, v1::nil => intofsingle v1 - | Ointuofsingle, v1::nil => intuofsingle v1 + | Ointofsingle, v1::nil => intofsingle_total v1 + | Ointuofsingle, v1::nil => intuofsingle_total v1 | Osingleofint, v1::nil => singleofint v1 | Osingleofintu, v1::nil => singleofintu v1 - | Olongoffloat, v1::nil => longoffloat v1 - | Olonguoffloat, v1::nil => longuoffloat v1 + | Olongoffloat, v1::nil => longoffloat_total v1 + | Olonguoffloat, v1::nil => longuoffloat_total v1 | Ofloatoflong, v1::nil => floatoflong v1 | Ofloatoflongu, v1::nil => floatoflongu v1 - | Olongofsingle, v1::nil => longofsingle v1 - | Olonguofsingle, v1::nil => longuofsingle v1 + | Olongofsingle, v1::nil => longofsingle_total v1 + | Olonguofsingle, v1::nil => longuofsingle_total v1 | Osingleoflong, v1::nil => singleoflong v1 | Osingleoflongu, v1::nil => singleoflongu v1 | Ocmp c, _ => of_optbool (eval_static_condition c vl) diff --git a/runtime/Makefile b/runtime/Makefile index ed4c1d39..6f70fa87 100644 --- a/runtime/Makefile +++ b/runtime/Makefile @@ -38,11 +38,7 @@ OBJS=i64_dtos.o i64_dtou.o i64_sar.o i64_sdiv.o i64_shl.o \ vararg.o endif -ifeq ($(ARCH),kvx) - AR=kvx-elf-ar -else - AR=ar -endif +AR=ar OBJS+=write_profiling_table.o diff --git a/kvx/InstructionScheduler.ml b/scheduling/InstructionScheduler.ml index 32f394b1..eab0b21a 100644 --- a/kvx/InstructionScheduler.ml +++ b/scheduling/InstructionScheduler.ml @@ -12,6 +12,16 @@ (* *) (* *************************************************************) +let with_destructor dtor stuff f = + try let ret = f stuff in + dtor stuff; + ret + with exn -> dtor stuff; + raise exn;; + +let with_out_channel chan f = with_destructor close_out chan f;; +let with_in_channel chan f = with_destructor close_in chan f;; + (** Schedule instructions on a synchronized pipeline @author David Monniaux, CNRS, VERIMAG *) @@ -844,16 +854,15 @@ let pseudo_boolean_solver = ref "pb_solver" let pseudo_boolean_scheduler pb_type problem = try - let filename_in = "problem.opb" - (* needed only if not using stdout and filename_out = "problem.sol" *) in - let opb_problem = open_out filename_in in - let mapper = pseudo_boolean_print_problem opb_problem problem pb_type in - close_out opb_problem; - - let opb_solution = Unix.open_process_in (!pseudo_boolean_solver ^ " " ^ filename_in) in - let ret = adjust_check_solution mapper (pseudo_boolean_read_solution mapper opb_solution) in - close_in opb_solution; - Some ret + let filename_in = "problem.opb" in + (* needed only if not using stdout and filename_out = "problem.sol" *) + let mapper = + with_out_channel (open_out filename_in) + (fun opb_problem -> + pseudo_boolean_print_problem opb_problem problem pb_type) in + Some (with_in_channel + (Unix.open_process_in (!pseudo_boolean_solver ^ " " ^ filename_in)) + (fun opb_solution -> adjust_check_solution mapper (pseudo_boolean_read_solution mapper opb_solution))) with | Unschedulable -> None;; @@ -1193,23 +1202,23 @@ let ilp_read_solution mapper channel = let ilp_solver = ref "ilp_solver" let problem_nr = ref 0 - + let ilp_scheduler pb_type problem = try let filename_in = Printf.sprintf "problem%05d.lp" !problem_nr and filename_out = Printf.sprintf "problem%05d.sol" !problem_nr in incr problem_nr; - let opb_problem = open_out filename_in in - let mapper = ilp_print_problem opb_problem problem pb_type in - close_out opb_problem; + let mapper = with_out_channel (open_out filename_in) + (fun opb_problem -> ilp_print_problem opb_problem problem pb_type) in begin match Unix.system (!ilp_solver ^ " " ^ filename_in ^ " " ^ filename_out) with | Unix.WEXITED 0 -> - let opb_solution = open_in filename_out in - let ret = adjust_check_solution mapper (ilp_read_solution mapper opb_solution) in - close_in opb_solution; - Some ret + Some (with_in_channel + (open_in filename_out) + (fun opb_solution -> + adjust_check_solution mapper + (ilp_read_solution mapper opb_solution))) | Unix.WEXITED _ -> failwith "failed to start ilp solver" | _ -> None end diff --git a/kvx/InstructionScheduler.mli b/scheduling/InstructionScheduler.mli index 6d27b30c..fb7af3f6 100644 --- a/kvx/InstructionScheduler.mli +++ b/scheduling/InstructionScheduler.mli @@ -33,6 +33,12 @@ type problem = { (** Print problem for human readability. *) val print_problem : out_channel -> problem -> unit;; +(** Get the number of instructions in a problem *) +val get_nr_instructions : problem -> int;; + +(** Get the number of resources in a problem *) +val get_nr_resources : problem -> int;; + (** Scheduling solution. For {i n} instructions to schedule, and 0≤{i i}<{i n}, position {i i} contains the time to which instruction {i i} should be scheduled. Position {i n} contains the final output latency. *) type solution = int array @@ -65,10 +71,10 @@ val list_scheduler : problem -> solution option (** Schedule the problem using the order of instructions without any reordering *) val greedy_scheduler : problem -> solution option -(** Schedule a problem using a scheduler applied in the opposite direction, e.g. for list scheduling from the end instead of the start. *) +(** Schedule a problem using a scheduler applied in the opposite direction, e.g. for list scheduling from the end instead of the start. BUGGY *) val schedule_reversed : scheduler -> problem -> int array option -(** Schedule a problem from the end using a list scheduler. *) +(** Schedule a problem from the end using a list scheduler. BUGGY *) val reverse_list_scheduler : problem -> int array option (** Check that a problem is well-formed. diff --git a/kvx/lib/RTLpath.v b/scheduling/RTLpath.v index 35512652..35512652 100644 --- a/kvx/lib/RTLpath.v +++ b/scheduling/RTLpath.v diff --git a/kvx/lib/RTLpathLivegen.v b/scheduling/RTLpathLivegen.v index 1f0ebe3c..1f0ebe3c 100644 --- a/kvx/lib/RTLpathLivegen.v +++ b/scheduling/RTLpathLivegen.v diff --git a/kvx/lib/RTLpathLivegenaux.ml b/scheduling/RTLpathLivegenaux.ml index dd971db8..dd971db8 100644 --- a/kvx/lib/RTLpathLivegenaux.ml +++ b/scheduling/RTLpathLivegenaux.ml diff --git a/kvx/lib/RTLpathLivegenproof.v b/scheduling/RTLpathLivegenproof.v index 1bf1af72..c6125985 100644 --- a/kvx/lib/RTLpathLivegenproof.v +++ b/scheduling/RTLpathLivegenproof.v @@ -109,13 +109,13 @@ Proof. + (* Iop *) eapply exec_Iop; eauto. erewrite eval_operation_preserved; eauto. + (* Iload *) eapply exec_Iload; eauto. - erewrite eval_addressing_preserved; eauto. + all: erewrite eval_addressing_preserved; eauto. + (* Iload notrap1 *) eapply exec_Iload_notrap1; eauto. - erewrite eval_addressing_preserved; eauto. + all: erewrite eval_addressing_preserved; eauto. + (* Iload notrap2 *) eapply exec_Iload_notrap2; eauto. - erewrite eval_addressing_preserved; eauto. + all: erewrite eval_addressing_preserved; eauto. + (* Istore *) eapply exec_Istore; eauto. - erewrite eval_addressing_preserved; eauto. + all: erewrite eval_addressing_preserved; eauto. + (* Icall *) eapply RTL.exec_Icall; eauto. eapply find_function_preserved; eauto. diff --git a/kvx/lib/RTLpathSE_impl.v b/scheduling/RTLpathSE_impl.v index 87a064d5..87a064d5 100644 --- a/kvx/lib/RTLpathSE_impl.v +++ b/scheduling/RTLpathSE_impl.v diff --git a/scheduling/RTLpathSE_impl_junk.v b/scheduling/RTLpathSE_impl_junk.v new file mode 100644 index 00000000..652f4ca3 --- /dev/null +++ b/scheduling/RTLpathSE_impl_junk.v @@ -0,0 +1,758 @@ +(** Implementation and refinement of the symbolic execution + +* a JUNK VERSION WITHOUT ANY FORMAL PROOF !!! + + *) + +Require Import Coqlib Maps Floats. +Require Import AST Integers Values Events Memory Globalenvs Smallstep. +Require Import Op Registers. +Require Import RTL RTLpath. +Require Import Errors Duplicate. +Require Import RTLpathSE_theory. +Require Import Axioms. + +Local Open Scope error_monad_scope. +Local Open Scope option_monad_scope. + +Require Export Impure.ImpHCons. +Export Notations. +Import HConsing. + +Local Open Scope impure. + +Import ListNotations. +Local Open Scope list_scope. + +Definition XDEBUG {A} (x:A) (k: A -> ?? pstring): ?? unit := RET tt. (* TO REMOVE DEBUG INFO *) +(* Definition XDEBUG {A} (x:A) (k: A -> ?? pstring): ?? unit := DO s <~ k x;; println ("DEBUG simu_check:" +; s). (* TO INSERT DEBUG INFO *) *) + +Definition DEBUG (s: pstring): ?? unit := XDEBUG tt (fun _ => RET s). + +(** * Implementation of Data-structure use in Hash-consing *) + +(** ** Implementation of symbolic values/symbolic memories with hash-consing data *) + +Inductive hsval := + | HSinput (r: reg) (hid:hashcode) + | HSop (op:operation) (hlsv: hlist_sval) (hsm: hsmem) (hid:hashcode) + | HSload (hsm: hsmem) (trap: trapping_mode) (chunk: memory_chunk) (addr:addressing) (hlsv:hlist_sval) (hid:hashcode) +with hlist_sval := + | HSnil (hid:hashcode) + | HScons (hsv: hsval) (hlsv: hlist_sval) (hid:hashcode) +(* symbolic memory *) +with hsmem := + | HSinit (hid:hashcode) + | HSstore (hsm: hsmem) (chunk:memory_chunk) (addr:addressing) (hlsv:hlist_sval) (srce: hsval) (hid:hashcode). + +Scheme hsval_mut := Induction for hsval Sort Prop +with hlist_sval_mut := Induction for hlist_sval Sort Prop +with hsmem_mut := Induction for hsmem Sort Prop. + +Definition hsval_get_hid (hsv: hsval): hashcode := + match hsv with + | HSinput _ hid => hid + | HSop _ _ _ hid => hid + | HSload _ _ _ _ _ hid => hid + end. + +Definition hlist_sval_get_hid (hlsv: hlist_sval): hashcode := + match hlsv with + | HSnil hid => hid + | HScons _ _ hid => hid + end. + +Definition hsmem_get_hid (hsm: hsmem ): hashcode := + match hsm with + | HSinit hid => hid + | HSstore _ _ _ _ _ hid => hid + end. + +Definition hsval_set_hid (hsv: hsval) (hid: hashcode): hsval := + match hsv with + | HSinput r _ => HSinput r hid + | HSop o hlsv hsm _ => HSop o hlsv hsm hid + | HSload hsm trap chunk addr hlsv _ => HSload hsm trap chunk addr hlsv hid + end. + +Definition hlist_sval_set_hid (hlsv: hlist_sval) (hid: hashcode): hlist_sval := + match hlsv with + | HSnil _ => HSnil hid + | HScons hsv hlsv _ => HScons hsv hlsv hid + end. + +Definition hsmem_set_hid (hsm: hsmem ) (hid: hashcode): hsmem := + match hsm with + | HSinit _ => HSinit hid + | HSstore hsm chunk addr hlsv srce _ => HSstore hsm chunk addr hlsv srce hid + end. + + +(* Now, we build the hash-Cons value from a "hash_eq". + +Informal specification: + [hash_eq] must be consistent with the "hashed" constructors defined above. + +We expect that hashinfo values in the code of these "hashed" constructors verify: + + (hash_eq (hdata x) (hdata y) ~> true) <-> (hcodes x)=(hcodes y) +*) + +Definition hsval_hash_eq (sv1 sv2: hsval): ?? bool := + match sv1, sv2 with + | HSinput r1 _, HSinput r2 _ => struct_eq r1 r2 (* NB: really need a struct_eq here ? *) + | HSop op1 lsv1 sm1 _, HSop op2 lsv2 sm2 _ => + DO b1 <~ phys_eq lsv1 lsv2;; + DO b2 <~ phys_eq sm1 sm2;; + if b1 && b2 + then struct_eq op1 op2 (* NB: really need a struct_eq here ? *) + else RET false + | HSload sm1 trap1 chk1 addr1 lsv1 _, HSload sm2 trap2 chk2 addr2 lsv2 _ => + DO b1 <~ phys_eq lsv1 lsv2;; + DO b2 <~ phys_eq sm1 sm2;; + DO b3 <~ struct_eq trap1 trap2;; + DO b4 <~ struct_eq chk1 chk2;; + if b1 && b2 && b3 && b4 + then struct_eq addr1 addr2 + else RET false + | _,_ => RET false + end. + +Definition hlist_sval_hash_eq (lsv1 lsv2: hlist_sval): ?? bool := + match lsv1, lsv2 with + | HSnil _, HSnil _ => RET true + | HScons sv1 lsv1' _, HScons sv2 lsv2' _ => + DO b <~ phys_eq lsv1' lsv2';; + if b + then phys_eq sv1 sv2 + else RET false + | _,_ => RET false + end. + +Definition hsmem_hash_eq (sm1 sm2: hsmem): ?? bool := + match sm1, sm2 with + | HSinit _, HSinit _ => RET true + | HSstore sm1 chk1 addr1 lsv1 sv1 _, HSstore sm2 chk2 addr2 lsv2 sv2 _ => + DO b1 <~ phys_eq lsv1 lsv2;; + DO b2 <~ phys_eq sm1 sm2;; + DO b3 <~ phys_eq sv1 sv2;; + DO b4 <~ struct_eq chk1 chk2;; + if b1 && b2 && b3 && b4 + then struct_eq addr1 addr2 + else RET false + | _,_ => RET false + end. + +Definition hSVAL: hashP hsval := {| hash_eq := hsval_hash_eq; get_hid:=hsval_get_hid; set_hid:=hsval_set_hid |}. +Definition hLSVAL: hashP hlist_sval := {| hash_eq := hlist_sval_hash_eq; get_hid:= hlist_sval_get_hid; set_hid:= hlist_sval_set_hid |}. +Definition hSMEM: hashP hsmem := {| hash_eq := hsmem_hash_eq; get_hid:= hsmem_get_hid; set_hid:= hsmem_set_hid |}. + +Program Definition mk_hash_params: Dict.hash_params hsval := + {| + Dict.test_eq := phys_eq; + Dict.hashing := fun (ht: hsval) => RET (hsval_get_hid ht); + Dict.log := fun hv => + DO hv_name <~ string_of_hashcode (hsval_get_hid hv);; + println ("unexpected undef behavior of hashcode:" +; (CamlStr hv_name)) |}. +Obligation 1. + wlp_simplify. +Qed. + + +(* Symbolic final value -- from hash-consed values +It does not seem useful to hash-consed these final values (because they are final). +*) +Inductive hsfval := + | HSnone + | HScall (sig:signature) (svos: hsval + ident) (lsv:hlist_sval) (res:reg) (pc:node) + | HStailcall (sig:signature) (svos: hsval + ident) (lsv:hlist_sval) + | HSbuiltin (ef:external_function) (sargs: list (builtin_arg hsval)) (res: builtin_res reg) (pc:node) + | HSjumptable (sv: hsval) (tbl: list node) + | HSreturn (res:option hsval) +. + +(** ** Implementation of symbolic states +*) + +(** name : Hash-consed Symbolic Internal state local. *) +Record hsistate_local := + { + (** [hsi_smem] represents the current smem symbolic evaluations. + (we can recover the previous one from smem) *) + hsi_smem:> hsmem; + (** For the values in registers: + 1) we store a list of sval evaluations + 2) we encode the symbolic regset by a PTree *) + hsi_ok_lsval: list hsval; + hsi_sreg:> PTree.t hsval + }. + +(* Syntax and semantics of symbolic exit states *) +Record hsistate_exit := mk_hsistate_exit + { hsi_cond: condition; hsi_scondargs: hlist_sval; hsi_elocal: hsistate_local; hsi_ifso: node }. + + +(** ** Syntax and Semantics of symbolic internal state *) +Record hsistate := { hsi_pc: node; hsi_exits: list hsistate_exit; hsi_local: hsistate_local }. + +(** ** Syntax and Semantics of symbolic state *) +Record hsstate := { hinternal:> hsistate; hfinal: hsfval }. + + +(** * Implementation of symbolic execution *) +Section CanonBuilding. + +Variable hC_hsval: hashinfo hsval -> ?? hsval. +(*Hypothesis hC_hsval_correct: TODO *) + +Variable hC_hlist_sval: hashinfo hlist_sval -> ?? hlist_sval. +(*Hypothesis hC_hlist_sval_correct: TODO *) + +Variable hC_hsmem: hashinfo hsmem -> ?? hsmem. +(*Hypothesis hC_hsval_correct: TODO *) + +(* First, we wrap constructors for hashed values !*) + +Definition hSinput_hcodes (r: reg) := + DO hc <~ hash 1;; + DO hv <~ hash r;; + RET [hc;hv]. +Extraction Inline hSinput_hcodes. + +Definition hSinput (r:reg): ?? hsval := + DO hv <~ hSinput_hcodes r;; + hC_hsval {| hdata:=HSinput r unknown_hid; hcodes :=hv; |}. + + +Definition hSop_hcodes (op:operation) (hlsv: hlist_sval) (hsm: hsmem) := + DO hc <~ hash 2;; + DO hv <~ hash op;; + RET [hc;hv;hlist_sval_get_hid hlsv; hsmem_get_hid hsm]. +Extraction Inline hSop_hcodes. + +Definition hSop (op:operation) (hlsv: hlist_sval) (hsm: hsmem): ?? hsval := + DO hv <~ hSop_hcodes op hlsv hsm;; + hC_hsval {| hdata:=HSop op hlsv hsm unknown_hid; hcodes :=hv |}. + + +Definition hSload_hcodes (hsm: hsmem) (trap: trapping_mode) (chunk: memory_chunk) (addr:addressing) (hlsv:hlist_sval):= + DO hc <~ hash 3;; + DO hv1 <~ hash trap;; + DO hv2 <~ hash chunk;; + DO hv3 <~ hash addr;; + RET [hc;hsmem_get_hid hsm;hv1;hv2;hv3;hlist_sval_get_hid hlsv]. +Extraction Inline hSload_hcodes. + +Definition hSload (hsm: hsmem) (trap: trapping_mode) (chunk: memory_chunk) (addr:addressing) (hlsv:hlist_sval): ?? hsval := + DO hv <~ hSload_hcodes hsm trap chunk addr hlsv;; + hC_hsval {| hdata:=HSload hsm trap chunk addr hlsv unknown_hid; hcodes :=hv |}. + + +Definition hSnil (_: unit): ?? hlist_sval := + hC_hlist_sval {| hdata:=HSnil unknown_hid; hcodes := nil |}. + +Definition hScons (hsv: hsval) (hlsv: hlist_sval): ?? hlist_sval := + hC_hlist_sval {| hdata:=HScons hsv hlsv unknown_hid; hcodes := [hsval_get_hid hsv; hlist_sval_get_hid hlsv] |}. + +Definition hSinit (_: unit): ?? hsmem := + hC_hsmem {| hdata:=HSinit unknown_hid; hcodes := nil |}. + +Definition hSstore_hcodes (hsm: hsmem) (chunk: memory_chunk) (addr:addressing) (hlsv:hlist_sval) (srce: hsval):= + DO hv1 <~ hash chunk;; + DO hv2 <~ hash addr;; + RET [hsmem_get_hid hsm;hv1;hv2;hlist_sval_get_hid hlsv;hsval_get_hid srce]. +Extraction Inline hSstore_hcodes. + +Definition hSstore (hsm: hsmem) (chunk:memory_chunk) (addr:addressing) (hlsv:hlist_sval) (srce: hsval): ?? hsmem := + DO hv <~ hSstore_hcodes hsm chunk addr hlsv srce;; + hC_hsmem {| hdata:=HSstore hsm chunk addr hlsv srce unknown_hid; hcodes := hv |}. + + +Definition hsi_sreg_get (hst: PTree.t hsval) r: ?? hsval := + match PTree.get r hst with + | None => hSinput r + | Some sv => RET sv + end. + +Fixpoint hlist_args (hst: PTree.t hsval) (l: list reg): ?? hlist_sval := + match l with + | nil => hSnil() + | r::l => + DO v <~ hsi_sreg_get hst r;; + DO hlsv <~ hlist_args hst l;; + hScons v hlsv + end. + +(** ** Assignment of memory *) +Definition hslocal_store (hst:hsistate_local) chunk addr args src: ?? hsistate_local := + let pt := hst.(hsi_sreg) in + DO hargs <~ hlist_args pt args;; + DO hsrc <~ hsi_sreg_get pt src;; + DO hm <~ hSstore hst chunk addr hargs hsrc;; + RET {| hsi_smem := hm; + hsi_ok_lsval := hsi_ok_lsval hst; + hsi_sreg:= hsi_sreg hst + |}. + +(** ** Assignment of local state *) + +Definition hsist_set_local (hst: hsistate) (pc: node) (hnxt: hsistate_local): hsistate := + {| hsi_pc := pc; hsi_exits := hst.(hsi_exits); hsi_local:= hnxt |}. + +(** ** Assignment of registers *) + +(* locally new symbolic values during symbolic execution *) +Inductive root_sval: Type := +| Rop (op:operation) +| Rload (trap: trapping_mode) (chunk:memory_chunk) (addr:addressing) +. + +Definition hSop_hSinit (op:operation) (hlsv: hlist_sval): ?? hsval := + DO hsi <~ hSinit ();; + hSop op hlsv hsi (* magically remove the dependency on sm ! *) + . + +Definition root_apply (rsv: root_sval) (lsv: list reg) (hst: hsistate_local) : ?? hsval := + DO hlsv <~ hlist_args hst lsv;; + match rsv with + | Rop op => hSop_hSinit op hlsv + | Rload trap chunk addr => hSload hst trap chunk addr hlsv + end. + +Local Open Scope lazy_bool_scope. + +(* NB: return [false] if the rsv cannot fail *) +Definition may_trap (rsv: root_sval) (lsv: list reg): bool := + match rsv with + | Rop op => is_trapping_op op ||| negb (Nat.eqb (length lsv) (args_of_operation op)) (* cf. lemma is_trapping_op_sound *) + | Rload TRAP _ _ => true + | _ => false + end. + +(* simplify a symbolic value before assignment to a register *) +Definition simplify (rsv: root_sval) (lsv: list reg) (hst: hsistate_local): ?? hsval := + match rsv with + | Rop op => + match is_move_operation op lsv with + | Some arg => hsi_sreg_get hst arg (* optimization of Omove *) + | None => + DO hlsv <~ hlist_args hst lsv;; + hSop_hSinit op hlsv + end + | Rload _ chunk addr => + DO hlsv <~ hlist_args hst lsv;; + hSload hst NOTRAP chunk addr hlsv + end. + +Definition red_PTree_set (r:reg) (sv: hsval) (hst: PTree.t hsval): PTree.t hsval := + match sv with + | HSinput r' _ => + if Pos.eq_dec r r' + then PTree.remove r' hst + else PTree.set r sv hst + | _ => PTree.set r sv hst + end. + +Definition hslocal_set_sreg (hst:hsistate_local) (r:reg) (rsv:root_sval) lsv: ?? hsistate_local := + DO hsiok <~ + (if may_trap rsv lsv + then DO hv <~ root_apply rsv lsv hst;; + XDEBUG hv (fun hv => DO hv_name <~ string_of_hashcode (hsval_get_hid hv);; RET ("-- insert undef behavior of hashcode:" +; (CamlStr hv_name))%string);; + RET (hv::(hsi_ok_lsval hst)) + else RET (hsi_ok_lsval hst));; + DO simp <~ simplify rsv lsv hst;; + RET {| hsi_smem := hst; + hsi_ok_lsval := hsiok; + hsi_sreg := red_PTree_set r simp (hsi_sreg hst) |}. + +(** ** Execution of one instruction *) + +Definition hsiexec_inst (i: instruction) (hst: hsistate): ?? (option hsistate) := + match i with + | Inop pc' => + RET (Some (hsist_set_local hst pc' hst.(hsi_local))) + | Iop op args dst pc' => + DO next <~ hslocal_set_sreg hst.(hsi_local) dst (Rop op) args;; + RET (Some (hsist_set_local hst pc' next)) + | Iload trap chunk addr args dst pc' => + DO next <~ hslocal_set_sreg hst.(hsi_local) dst (Rload trap chunk addr) args;; + RET (Some (hsist_set_local hst pc' next)) + | Istore chunk addr args src pc' => + DO next <~ hslocal_store hst.(hsi_local) chunk addr args src;; + RET (Some (hsist_set_local hst pc' next)) + | Icond cond args ifso ifnot _ => + let prev := hst.(hsi_local) in + DO vargs <~ hlist_args prev args ;; + let ex := {| hsi_cond:=cond; hsi_scondargs:=vargs; hsi_elocal := prev; hsi_ifso := ifso |} in + RET (Some {| hsi_pc := ifnot; hsi_exits := ex::hst.(hsi_exits); hsi_local := prev |}) + | _ => RET None (* TODO jumptable ? *) + end. + +Definition some_or_fail {A} (o: option A) (msg: pstring): ?? A := + match o with + | Some x => RET x + | None => FAILWITH msg + end. + +Fixpoint hsiexec_path (path:nat) (f: function) (hst: hsistate): ?? hsistate := + match path with + | O => RET hst + | S p => + let pc := hst.(hsi_pc) in + XDEBUG pc (fun pc => DO name_pc <~ string_of_Z (Zpos pc);; RET ("- sym exec node: " +; name_pc)%string);; + DO i <~ some_or_fail ((fn_code f)!pc) "hsiexec_path.internal_error.1";; + DO ohst1 <~ hsiexec_inst i hst;; + DO hst1 <~ some_or_fail ohst1 "hsiexec_path.internal_error.2";; + hsiexec_path p f hst1 + end. + +Fixpoint hbuiltin_arg (hst: PTree.t hsval) (arg : builtin_arg reg): ?? builtin_arg hsval := + match arg with + | BA r => + DO v <~ hsi_sreg_get hst r;; + RET (BA v) + | BA_int n => RET (BA_int n) + | BA_long n => RET (BA_long n) + | BA_float f0 => RET (BA_float f0) + | BA_single s => RET (BA_single s) + | BA_loadstack chunk ptr => RET (BA_loadstack chunk ptr) + | BA_addrstack ptr => RET (BA_addrstack ptr) + | BA_loadglobal chunk id ptr => RET (BA_loadglobal chunk id ptr) + | BA_addrglobal id ptr => RET (BA_addrglobal id ptr) + | BA_splitlong ba1 ba2 => + DO v1 <~ hbuiltin_arg hst ba1;; + DO v2 <~ hbuiltin_arg hst ba2;; + RET (BA_splitlong v1 v2) + | BA_addptr ba1 ba2 => + DO v1 <~ hbuiltin_arg hst ba1;; + DO v2 <~ hbuiltin_arg hst ba2;; + RET (BA_addptr v1 v2) + end. + +Fixpoint hbuiltin_args (hst: PTree.t hsval) (args: list (builtin_arg reg)): ?? list (builtin_arg hsval) := + match args with + | nil => RET nil + | a::l => + DO ha <~ hbuiltin_arg hst a;; + DO hl <~ hbuiltin_args hst l;; + RET (ha::hl) + end. + +Definition hsum_left (hst: PTree.t hsval) (ros: reg + ident): ?? (hsval + ident) := + match ros with + | inl r => DO hr <~ hsi_sreg_get hst r;; RET (inl hr) + | inr s => RET (inr s) + end. + +Definition hsexec_final (i: instruction) (hst: PTree.t hsval): ?? hsfval := + match i with + | Icall sig ros args res pc => + DO svos <~ hsum_left hst ros;; + DO sargs <~ hlist_args hst args;; + RET (HScall sig svos sargs res pc) + | Itailcall sig ros args => + DO svos <~ hsum_left hst ros;; + DO sargs <~ hlist_args hst args;; + RET (HStailcall sig svos sargs) + | Ibuiltin ef args res pc => + DO sargs <~ hbuiltin_args hst args;; + RET (HSbuiltin ef sargs res pc) + | Ijumptable reg tbl => + DO sv <~ hsi_sreg_get hst reg;; + RET (HSjumptable sv tbl) + | Ireturn or => + match or with + | Some r => DO hr <~ hsi_sreg_get hst r;; RET (HSreturn (Some hr)) + | None => RET (HSreturn None) + end + | _ => RET (HSnone) + end. + +Definition init_hsistate_local (_:unit): ?? hsistate_local + := DO hm <~ hSinit ();; + RET {| hsi_smem := hm; hsi_ok_lsval := nil; hsi_sreg := PTree.empty hsval |}. + +Definition init_hsistate pc: ?? hsistate + := DO hst <~ init_hsistate_local ();; + RET {| hsi_pc := pc; hsi_exits := nil; hsi_local := hst |}. + +Definition hsexec (f: function) (pc:node): ?? hsstate := + DO path <~ some_or_fail ((fn_path f)!pc) "hsexec.internal_error.1";; + DO hinit <~ init_hsistate pc;; + DO hst <~ hsiexec_path path.(psize) f hinit;; + DO i <~ some_or_fail ((fn_code f)!(hst.(hsi_pc))) "hsexec.internal_error.2";; + DO ohst <~ hsiexec_inst i hst;; + match ohst with + | Some hst' => RET {| hinternal := hst'; hfinal := HSnone |} + | None => DO hsvf <~ hsexec_final i hst.(hsi_local);; + RET {| hinternal := hst; hfinal := hsvf |} + end. + +End CanonBuilding. + +(** * The simulation test of concrete hash-consed symbolic execution *) + +Definition phys_check {A} (x y:A) (msg: pstring): ?? unit := + DO b <~ phys_eq x y;; + assert_b b msg;; + RET tt. + +Definition struct_check {A} (x y:A) (msg: pstring): ?? unit := + DO b <~ struct_eq x y;; + assert_b b msg;; + RET tt. + +Definition option_eq_check {A} (o1 o2: option A): ?? unit := + match o1, o2 with + | Some x1, Some x2 => phys_check x1 x2 "option_eq_check: data physically differ" + | None, None => RET tt + | _, _ => FAILWITH "option_eq_check: structure differs" + end. + +Lemma option_eq_check_correct A (o1 o2: option A): WHEN option_eq_check o1 o2 ~> _ THEN o1=o2. +Proof. + wlp_simplify. +Qed. +Global Opaque option_eq_check. +Global Hint Resolve option_eq_check_correct:wlp. + +Import PTree. + +Fixpoint PTree_eq_check {A} (d1 d2: PTree.t A): ?? unit := + match d1, d2 with + | Leaf, Leaf => RET tt + | Node l1 o1 r1, Node l2 o2 r2 => + option_eq_check o1 o2;; + PTree_eq_check l1 l2;; + PTree_eq_check r1 r2 + | _, _ => FAILWITH "PTree_eq_check: some key is absent" + end. + +Lemma PTree_eq_check_correct A d1: forall (d2: t A), + WHEN PTree_eq_check d1 d2 ~> _ THEN forall x, PTree.get x d1 = PTree.get x d2. +Proof. + induction d1 as [|l1 Hl1 o1 r1 Hr1]; destruct d2 as [|l2 o2 r2]; simpl; + wlp_simplify. destruct x; simpl; auto. +Qed. +Global Opaque PTree_eq_check. + +Fixpoint PTree_frame_eq_check {A} (frame: list positive) (d1 d2: PTree.t A): ?? unit := + match frame with + | nil => RET tt + | k::l => + option_eq_check (PTree.get k d1) (PTree.get k d2);; + PTree_frame_eq_check l d1 d2 + end. + +Lemma PTree_frame_eq_check_correct A l (d1 d2: t A): + WHEN PTree_frame_eq_check l d1 d2 ~> _ THEN forall x, List.In x l -> PTree.get x d1 = PTree.get x d2. +Proof. + induction l as [|k l]; simpl; wlp_simplify. + subst; auto. +Qed. +Global Opaque PTree_frame_eq_check. + +Definition hsilocal_simu_check hst1 hst2 : ?? unit := + DEBUG("? last check");; + phys_check (hsi_smem hst2) (hsi_smem hst1) "hsilocal_simu_check: hsi_smem sets aren't equiv";; + PTree_eq_check (hsi_sreg hst1) (hsi_sreg hst2);; + Sets.assert_list_incl mk_hash_params (hsi_ok_lsval hst2) (hsi_ok_lsval hst1);; + DEBUG("=> last check: OK"). + +Definition revmap_check_single (dm: PTree.t node) (n tn: node) : ?? unit := + DO res <~ some_or_fail (dm ! tn) "revmap_check_single: no mapping for tn";; + struct_check n res "revmap_check_single: n and res are physically different". + +Definition hsilocal_frame_simu_check frame hst1 hst2 : ?? unit := + DEBUG("? frame check");; + phys_check (hsi_smem hst2) (hsi_smem hst1) "hsilocal_frame_simu_check: hsi_smem sets aren't equiv";; + PTree_frame_eq_check frame (hsi_sreg hst1) (hsi_sreg hst2);; + Sets.assert_list_incl mk_hash_params (hsi_ok_lsval hst2) (hsi_ok_lsval hst1);; + DEBUG("=> frame check: OK"). + +Definition hsiexit_simu_check (dm: PTree.t node) (f: RTLpath.function) (hse1 hse2: hsistate_exit): ?? unit := + struct_check (hsi_cond hse1) (hsi_cond hse2) "hsiexit_simu_check: conditions do not match";; + phys_check (hsi_scondargs hse1) (hsi_scondargs hse2) "hsiexit_simu_check: args do not match";; + revmap_check_single dm (hsi_ifso hse1) (hsi_ifso hse2);; + DO path <~ some_or_fail ((fn_path f) ! (hsi_ifso hse1)) "hsiexit_simu_check: internal error";; + hsilocal_frame_simu_check (Regset.elements path.(input_regs)) (hsi_elocal hse1) (hsi_elocal hse2). + +Fixpoint hsiexits_simu_check (dm: PTree.t node) (f: RTLpath.function) (lhse1 lhse2: list hsistate_exit) := + match lhse1,lhse2 with + | nil, nil => RET tt + | hse1 :: lhse1, hse2 :: lhse2 => + hsiexit_simu_check dm f hse1 hse2;; + hsiexits_simu_check dm f lhse1 lhse2 + | _, _ => FAILWITH "siexists_simu_check: lengths do not match" + end. + +Definition hsistate_simu_check (dm: PTree.t node) (f: RTLpath.function) (hst1 hst2: hsistate) := + hsiexits_simu_check dm f (hsi_exits hst1) (hsi_exits hst2);; + hsilocal_simu_check (hsi_local hst1) (hsi_local hst2). + +Fixpoint revmap_check_list (dm: PTree.t node) (ln ln': list node): ?? unit := + match ln, ln' with + | nil, nil => RET tt + | n::ln, n'::ln' => + revmap_check_single dm n n';; + revmap_check_list dm ln ln' + | _, _ => FAILWITH "revmap_check_list: lists have different lengths" + end. + +Definition svos_simu_check (svos1 svos2: hsval + ident) := + match svos1, svos2 with + | inl sv1, inl sv2 => phys_check sv1 sv2 "svos_simu_check: sval mismatch" + | inr id1, inr id2 => phys_check id1 id2 "svos_simu_check: symbol mismatch" + | _, _ => FAILWITH "svos_simu_check: type mismatch" + end. + +Fixpoint builtin_arg_simu_check (bs bs': builtin_arg hsval) := + match bs, bs' with + | BA sv, BA sv' => phys_check sv sv' "builtin_arg_simu_check: sval mismatch" + | BA_splitlong lo hi, BA_splitlong lo' hi' => + builtin_arg_simu_check lo lo';; + builtin_arg_simu_check hi hi' + | BA_addptr b1 b2, BA_addptr b1' b2' => + builtin_arg_simu_check b1 b1';; + builtin_arg_simu_check b2 b2' + | _, _ => struct_check bs bs' "builtin_arg_simu_check: basic mismatch" + end. + +Fixpoint list_builtin_arg_simu_check lbs1 lbs2 := + match lbs1, lbs2 with + | nil, nil => RET tt + | bs1::lbs1, bs2::lbs2 => + builtin_arg_simu_check bs1 bs2;; + list_builtin_arg_simu_check lbs1 lbs2 + | _, _ => FAILWITH "list_builtin_arg_simu_check: length mismatch" + end. + +Definition sfval_simu_check (dm: PTree.t node) (f: RTLpath.function) (pc1 pc2: node) (fv1 fv2: hsfval) := + match fv1, fv2 with + | HSnone, HSnone => revmap_check_single dm pc1 pc2 + | HScall sig1 svos1 lsv1 res1 pc1, HScall sig2 svos2 lsv2 res2 pc2 => + revmap_check_single dm pc1 pc2;; + phys_check sig1 sig2 "sfval_simu_check: Scall different signatures";; + phys_check res1 res2 "sfval_simu_check: Scall res do not match";; + svos_simu_check svos1 svos2;; + phys_check lsv1 lsv2 "sfval_simu_check: Scall args do not match" + | HStailcall sig1 svos1 lsv1, HStailcall sig2 svos2 lsv2 => + phys_check sig1 sig2 "sfval_simu_check: Stailcall different signatures";; + svos_simu_check svos1 svos2;; + phys_check lsv1 lsv2 "sfval_simu_check: Stailcall args do not match" + | HSbuiltin ef1 lbs1 br1 pc1, HSbuiltin ef2 lbs2 br2 pc2 => + revmap_check_single dm pc1 pc2;; + phys_check ef1 ef2 "sfval_simu_check: builtin ef do not match";; + phys_check br1 br2 "sfval_simu_check: builtin br do not match";; + list_builtin_arg_simu_check lbs1 lbs2 + | HSjumptable sv ln, HSjumptable sv' ln' => + revmap_check_list dm ln ln';; + phys_check sv sv' "sfval_simu_check: Sjumptable sval do not match" + | HSreturn osv1, HSreturn osv2 => + option_eq_check osv1 osv2 + | _, _ => FAILWITH "sfval_simu_check: structure mismatch" + end. + +Definition hsstate_simu_check (dm: PTree.t node) (f: RTLpath.function) (hst1 hst2: hsstate) := + hsistate_simu_check dm f (hinternal hst1) (hinternal hst2);; + sfval_simu_check dm f (hsi_pc hst1) (hsi_pc hst2) (hfinal hst1) (hfinal hst2). + +Definition simu_check_single (dm: PTree.t node) (f: RTLpath.function) (tf: RTLpath.function) (m: node * node): ?? unit := + let (pc2, pc1) := m in + (* creating the hash-consing tables *) + DO hC_sval <~ hCons hSVAL;; + DO hC_hlist_sval <~ hCons hLSVAL;; + DO hC_hsmem <~ hCons hSMEM;; + let hsexec := hsexec hC_sval.(hC) hC_hlist_sval.(hC) hC_hsmem.(hC) in + (* performing the hash-consed executions *) + XDEBUG pc1 (fun pc => DO name_pc <~ string_of_Z (Zpos pc);; RET ("entry-point of input superblock: " +; name_pc)%string);; + DO hst1 <~ hsexec f pc1;; + XDEBUG pc2 (fun pc => DO name_pc <~ string_of_Z (Zpos pc);; RET ("entry-point of output superblock: " +; name_pc)%string);; + DO hst2 <~ hsexec tf pc2;; + (* comparing the executions *) + hsstate_simu_check dm f hst1 hst2. + +Lemma simu_check_single_correct dm tf f pc1 pc2: + WHEN simu_check_single dm f tf (pc2, pc1) ~> _ THEN + sexec_simu dm f tf pc1 pc2. +Admitted. +Global Opaque simu_check_single. +Global Hint Resolve simu_check_single_correct: wlp. + +Fixpoint simu_check_rec (dm: PTree.t node) (f: RTLpath.function) (tf: RTLpath.function) lm : ?? unit := + match lm with + | nil => RET tt + | m :: lm => + simu_check_single dm f tf m;; + simu_check_rec dm f tf lm + end. + +Lemma simu_check_rec_correct dm f tf lm: + WHEN simu_check_rec dm f tf lm ~> _ THEN + forall pc1 pc2, In (pc2, pc1) lm -> sexec_simu dm f tf pc1 pc2. +Proof. + induction lm; wlp_simplify. + match goal with + | X: (_,_) = (_,_) |- _ => inversion X; subst + end. + subst; eauto. +Qed. +Global Opaque simu_check_rec. +Global Hint Resolve simu_check_rec_correct: wlp. + +Definition imp_simu_check (dm: PTree.t node) (f: RTLpath.function) (tf: RTLpath.function): ?? unit := + simu_check_rec dm f tf (PTree.elements dm);; + DEBUG("simu_check OK!"). + +Local Hint Resolve PTree.elements_correct: core. +Lemma imp_simu_check_correct dm f tf: + WHEN imp_simu_check dm f tf ~> _ THEN + forall pc1 pc2, dm ! pc2 = Some pc1 -> sexec_simu dm f tf pc1 pc2. +Proof. + wlp_simplify. +Qed. +Global Opaque imp_simu_check. +Global Hint Resolve imp_simu_check_correct: wlp. + +Program Definition aux_simu_check (dm: PTree.t node) (f: RTLpath.function) (tf: RTLpath.function): ?? bool := + DO r <~ + (TRY + imp_simu_check dm f tf;; + RET true + CATCH_FAIL s, _ => + println ("simu_check_failure:" +; s);; + RET false + ENSURE (fun b => b=true -> forall pc1 pc2, dm ! pc2 = Some pc1 -> sexec_simu dm f tf pc1 pc2));; + RET (`r). +Obligation 1. + split; wlp_simplify. discriminate. +Qed. + +Lemma aux_simu_check_correct dm f tf: + WHEN aux_simu_check dm f tf ~> b THEN + b=true -> forall pc1 pc2, dm ! pc2 = Some pc1 -> sexec_simu dm f tf pc1 pc2. +Proof. + unfold aux_simu_check; wlp_simplify. + destruct exta; simpl; auto. +Qed. + +(* Coerce aux_simu_check into a pure function (this is a little unsafe like all oracles in CompCert). *) + +Import UnsafeImpure. + +Definition simu_check (dm: PTree.t node) (f: RTLpath.function) (tf: RTLpath.function) : res unit := + match unsafe_coerce (aux_simu_check dm f tf) with + | Some true => OK tt + | _ => Error (msg "simu_check has failed") + end. + +Lemma simu_check_correct dm f tf: + simu_check dm f tf = OK tt -> + forall pc1 pc2, dm ! pc2 = Some pc1 -> + sexec_simu dm f tf pc1 pc2. +Proof. + unfold simu_check. + destruct (unsafe_coerce (aux_simu_check dm f tf)) as [[|]|] eqn:Hres; simpl; try discriminate. + intros; eapply aux_simu_check_correct; eauto. + eapply unsafe_coerce_not_really_correct; eauto. +Qed.
\ No newline at end of file diff --git a/kvx/lib/RTLpathSE_theory.v b/scheduling/RTLpathSE_theory.v index 06b3a646..06b3a646 100644 --- a/kvx/lib/RTLpathSE_theory.v +++ b/scheduling/RTLpathSE_theory.v diff --git a/kvx/lib/RTLpathScheduler.v b/scheduling/RTLpathScheduler.v index beab405f..beab405f 100644 --- a/kvx/lib/RTLpathScheduler.v +++ b/scheduling/RTLpathScheduler.v diff --git a/kvx/lib/RTLpathScheduleraux.ml b/scheduling/RTLpathScheduleraux.ml index 88f777a5..88f777a5 100644 --- a/kvx/lib/RTLpathScheduleraux.ml +++ b/scheduling/RTLpathScheduleraux.ml diff --git a/kvx/lib/RTLpathSchedulerproof.v b/scheduling/RTLpathSchedulerproof.v index 4ba197b0..4ba197b0 100644 --- a/kvx/lib/RTLpathSchedulerproof.v +++ b/scheduling/RTLpathSchedulerproof.v diff --git a/kvx/lib/RTLpathproof.v b/scheduling/RTLpathproof.v index 20eded97..20eded97 100644 --- a/kvx/lib/RTLpathproof.v +++ b/scheduling/RTLpathproof.v diff --git a/test/kvx/instr/Makefile b/test/kvx/instr/Makefile index e4f964b3..fce32178 100644 --- a/test/kvx/instr/Makefile +++ b/test/kvx/instr/Makefile @@ -1,15 +1,15 @@ SHELL := /bin/bash -KVXC ?= k1-cos-gcc +KVXC ?= kvx-elf-gcc CC ?= gcc CCOMP ?= ccomp OPTIM ?= -O2 CFLAGS ?= $(OPTIM) CCOMPFLAGS ?= $(CFLAGS) -SIMU ?= k1-mppa +SIMU ?= kvx-mppa TIMEOUT ?= --signal=SIGTERM 120s DIFF ?= python2.7 floatcmp.py -reltol .00001 -HARDRUN ?= k1-jtag-runner +HARDRUN ?= kvx-jtag-runner DIR=./ SRCDIR=$(DIR) @@ -64,7 +64,7 @@ simutest: $(X86_GCC_OUT) $(GCC_SIMUOUT) x86out=$(OUTDIR)/$$test.x86-gcc.out;\ gccout=$(OUTDIR)/$$test.gcc.simu.out;\ if grep "__KVX__" -q $$test.c; then\ - printf "$(YELLOW)UNTESTED: $$test.c contains an \`#ifdef __KVX__\`\n";\ + printf "$(YELLOW)UNTESTED: $$test.c contains an \`#ifdef __KVX__\`\n$(NC)";\ elif $(DIFF) $$x86out $$gccout > /dev/null; test $${PIPESTATUS[0]} -ne 0; then\ >&2 printf "$(RED)ERROR: $$x86out and $$gccout differ$(NC)\n";\ else\ @@ -92,7 +92,7 @@ hardtest: $(X86_GCC_OUT) $(GCC_HARDOUT) x86out=$(OUTDIR)/$$test.x86-gcc.out;\ gccout=$(OUTDIR)/$$test.gcc.hard.out;\ if grep "__KVX__" -q $$test.c; then\ - printf "$(YELLOW)UNTESTED: $$test.c contains an \`#ifdef __KVX__\`\n";\ + printf "$(YELLOW)UNTESTED: $$test.c contains an \`#ifdef __KVX__\`\n$(NC)";\ elif $(DIFF) $$x86out $$gccout > /dev/null; test $${PIPESTATUS[0]} -ne 0; then\ >&2 printf "$(RED)ERROR: $$x86out and $$gccout differ$(NC)\n";\ else\ diff --git a/test/kvx/interop/Makefile b/test/kvx/interop/Makefile index a0d4d7da..aa018aac 100644 --- a/test/kvx/interop/Makefile +++ b/test/kvx/interop/Makefile @@ -1,12 +1,12 @@ SHELL := /bin/bash -KVXC ?= k1-cos-gcc +KVXC ?= kvx-elf-gcc CC ?= gcc CCOMP ?= ccomp CFLAGS ?= -O2 -Wno-varargs -SIMU ?= k1-mppa +SIMU ?= kvx-mppa TIMEOUT ?= --signal=SIGTERM 120s -HARDRUN ?= k1-jtag-runner +HARDRUN ?= kvx-jtag-runner DIR=./ SRCDIR=$(DIR) diff --git a/test/kvx/lib/Makefile b/test/kvx/lib/Makefile index 5a947bb3..7df7dd16 100644 --- a/test/kvx/lib/Makefile +++ b/test/kvx/lib/Makefile @@ -1,10 +1,10 @@ -KVXC ?= k1-cos-gcc -K1AR ?= k1-cos-ar +KVXC ?= kvx-elf-gcc +K1AR ?= kvx-elf-ar CC ?= gcc AR ?= gcc-ar CCOMP ?= ccomp CFLAGS ?= -O1 -Wl,--wrap=printf -SIMU ?= k1-mppa +SIMU ?= kvx-mppa TIMEOUT ?= --signal=SIGTERM 60s DIR=./ diff --git a/test/kvx/mmult/Makefile b/test/kvx/mmult/Makefile index e7cd890e..252f8911 100644 --- a/test/kvx/mmult/Makefile +++ b/test/kvx/mmult/Makefile @@ -1,8 +1,8 @@ -KVXC ?= k1-cos-gcc +KVXC ?= kvx-elf-gcc CC ?= gcc CCOMP ?= ccomp CFLAGS ?= -O2 -SIMU ?= k1-mppa +SIMU ?= kvx-mppa TIMEOUT ?= 10s KVXCPATH=$(shell which $(KVXC)) @@ -65,3 +65,7 @@ check: $(CCOMP_OUT) $(STUB_OUT) else\ echo "GOOD kvx: $< succeeded";\ fi + +.PHONY: +clean: + rm -f *.out mmult-test-ccomp-kvx mmult-test-gcc-kvx mmult-test-gcc-x86 diff --git a/test/kvx/prng/Makefile b/test/kvx/prng/Makefile index 68e5ffc9..b97f4aa4 100644 --- a/test/kvx/prng/Makefile +++ b/test/kvx/prng/Makefile @@ -1,8 +1,8 @@ -KVXC ?= k1-cos-gcc +KVXC ?= kvx-elf-gcc CC ?= gcc CCOMP ?= ccomp CFLAGS ?= -O2 -SIMU ?= k1-mppa +SIMU ?= kvx-mppa TIMEOUT ?= 10s KVXCPATH=$(shell which $(KVXC)) @@ -67,3 +67,4 @@ check: $(CCOMP_OUT) $(STUB_OUT) .PHONY: clean: rm -f prng-test-gcc-x86 prng-test-gcc-kvx prng-test-ccomp-kvx + rm -f *.out diff --git a/test/kvx/sort/Makefile b/test/kvx/sort/Makefile index c4090352..1afab6e9 100644 --- a/test/kvx/sort/Makefile +++ b/test/kvx/sort/Makefile @@ -1,8 +1,8 @@ -KVXC ?= k1-cos-gcc +KVXC ?= kvx-elf-gcc CC ?= gcc CCOMP ?= ccomp CFLAGS ?= -O2 -SIMU ?= k1-mppa +SIMU ?= kvx-mppa TIMEOUT ?= 10s KVXCPATH=$(shell which $(KVXC)) @@ -89,3 +89,10 @@ check: $(STUB_OUT) $(CCOMP_OUT) echo "GOOD kvx: $$test succeeded";\ fi;\ done + +.PHONY: +clean: + for test in insertion main merge selection; do\ + rm -f $$test-ccomp-kvx $$test-gcc-kvx $$test-gcc-x86;\ + done + rm -f *.out diff --git a/test/monniaux/picosat-965/onefile/picosat.c b/test/monniaux/picosat-965/onefile/picosat.c index 4f8ee768..e1c18438 100644 --- a/test/monniaux/picosat-965/onefile/picosat.c +++ b/test/monniaux/picosat-965/onefile/picosat.c @@ -1,9765 +1,25 @@ -#define NALARM 1 -#define NZIP 1 -#define NGETRUSAGE 1 -#define NDEBUG 1 - -#include "picosat.h" - -#include <assert.h> -#include <ctype.h> -#include <signal.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -#define GUNZIP "gunzip -c %s" -#define BUNZIP2 "bzcat %s" -#define GZIP "gzip -c -f > %s" - -#ifndef NZIP -FILE * popen (const char *, const char*); -int pclose (FILE *); -#endif - -static PicoSAT * picosat; - -static int lineno; -static FILE *input; -static int inputid; -static FILE *output; -static int verbose; -static int sargc; -static char ** sargv; -static char buffer[100]; -static char *bhead = buffer; -static const char *eob = buffer + 80; -static FILE * incremental_rup_file; -static signed char * sol; - -extern void picosat_enter (PicoSAT *); -extern void picosat_leave (PicoSAT *); - -static int -next (void) -{ - int res = getc (input); - if (res == '\n') - lineno++; - - return res; +typedef struct b b; +b *a; +struct b { + int c; + int d, **clshead; + int **ahead; + unsigned h; +} i; +b *j(); +int k(); +int main() { + a = j(); + k(a); +} +#define e(f) f - g->c +static void m(b *g, int *l) { + if (g) + *g->ahead = l; +} +b *j() { return &i; } +int k(b *g) { + if (g->d) + m(g, e(g->clshead[-1])); + return g->h; } - -static const char * -parse (PicoSAT * picosat, int force) -{ - int ch, sign, lit, vars, clauses; - - lineno = 1; - /* DM inputid = fileno (input); */ - -SKIP_COMMENTS: - ch = next (); - if (ch == 'c') - { - while ((ch = next ()) != EOF && ch != '\n') - ; - goto SKIP_COMMENTS; - } - - if (isspace (ch)) - goto SKIP_COMMENTS; - - if (ch != 'p') -INVALID_HEADER: - return "missing or invalid 'p cnf <variables> <clauses>' header"; - - if (!isspace (next ())) - goto INVALID_HEADER; - - while (isspace (ch = next ())) - ; - - if (ch != 'c' || next () != 'n' || next () != 'f' || !isspace (next ())) - goto INVALID_HEADER; - - while (isspace (ch = next ())) - ; - - if (!isdigit (ch)) - goto INVALID_HEADER; - - vars = ch - '0'; - while (isdigit (ch = next ())) - vars = 10 * vars + (ch - '0'); - - if (!isspace (ch)) - goto INVALID_HEADER; - - while (isspace (ch = next ())) - ; - - if (!isdigit (ch)) - goto INVALID_HEADER; - - clauses = ch - '0'; - while (isdigit (ch = next ())) - clauses = 10 * clauses + (ch - '0'); - - if (!isspace (ch) && ch != '\n' ) - goto INVALID_HEADER; - - if (verbose) - { - fprintf (output, "c parsed header 'p cnf %d %d'\n", vars, clauses); - fflush (output); - } - - picosat_adjust (picosat, vars); - - if (incremental_rup_file) - picosat_set_incremental_rup_file (picosat, incremental_rup_file, vars, clauses); - - lit = 0; -READ_LITERAL: - ch = next (); - - if (ch == 'c') - { - while ((ch = next ()) != EOF && ch != '\n') - ; - goto READ_LITERAL; - } - - if (ch == EOF) - { - if (lit) - return "trailing 0 missing"; - - if (clauses && !force) - return "clause missing"; - - return 0; - } - - if (isspace (ch)) - goto READ_LITERAL; - - sign = 1; - if (ch == '-') - { - sign = -1; - ch = next (); - } - - if (!isdigit (ch)) - return "expected number"; - - lit = ch - '0'; - while (isdigit (ch = next ())) - lit = 10 * lit + (ch - '0'); - - if (!clauses && !force) - return "too many clauses"; - - if (lit) - { - if (lit > vars && !force) - return "maximal variable index exceeded"; - - lit *= sign; - } - else - clauses--; - - picosat_add (picosat, lit); - - goto READ_LITERAL; -} - -static void -bflush (void) -{ - *bhead = 0; - fputs (buffer, output); - fputc ('\n', output); - bhead = buffer; -} - -static void -printi (int i) -{ - char *next; - int l; - -REENTER: - if (bhead == buffer) - *bhead++ = 'v'; - - l = sprintf (bhead, " %d", i); - next = bhead + l; - - if (next >= eob) - { - bflush (); - goto REENTER; - } - else - bhead = next; -} - -static void -printa (PicoSAT * picosat, int partial) -{ - int max_idx = picosat_variables (picosat), i, lit, val; - - assert (bhead == buffer); - - for (i = 1; i <= max_idx; i++) - { - if (partial) - { - val = picosat_deref_partial (picosat, i); - if (!val) - continue; - } - else - val = picosat_deref (picosat, i); - lit = (val > 0) ? i : -i; - printi (lit); - } - - printi (0); - if (bhead > buffer) - bflush (); -} - -static void -blocksol (PicoSAT * picosat) -{ - int max_idx = picosat_variables (picosat), i; - - if (!sol) - { - sol = malloc (max_idx + 1); - memset (sol, 0, max_idx + 1); - } - - for (i = 1; i <= max_idx; i++) - sol[i] = (picosat_deref (picosat, i) > 0) ? 1 : -1; - - for (i = 1; i <= max_idx; i++) - picosat_add (picosat, (sol[i] < 0) ? i : -i); - - picosat_add (picosat, 0); -} - -static int -has_suffix (const char *str, const char *suffix) -{ - const char *tmp = strstr (str, suffix); - if (!tmp) - return 0; - - return str + strlen (str) - strlen (suffix) == tmp; -} - -static void -write_core_variables (PicoSAT * picosat, FILE * file) -{ - int i, max_idx = picosat_variables (picosat), count = 0; - for (i = 1; i <= max_idx; i++) - if (picosat_corelit (picosat, i)) - { - fprintf (file, "%d\n", i); - count++; - } - - if (verbose) - fprintf (output, "c found and wrote %d core variables\n", count); -} - -static int -next_assumption (int start) -{ - char * arg, c; - int res; - res = start + 1; - while (res < sargc) - { - arg = sargv[res++]; - if (!strcmp (arg, "-a")) - { - assert (res < sargc); - break; - } - - if (arg[0] == '-') { - c = arg[1]; - if (c == 'l' || c == 'i' || c == 's' || c == 'o' || c == 't' || - c == 'T' || c == 'r' || c == 'R' || c == 'c' || c == 'V' || - c == 'U' || c == 'A') res++; - } - } - if (res >= sargc) res = 0; - return res; -} - -static void -write_failed_assumptions (PicoSAT * picosat, FILE * file) -{ - int i, lit, count = 0; -#ifndef NDEBUG - int max_idx = picosat_variables (picosat); -#endif - i = 0; - while ((i = next_assumption (i))) { - lit = atoi (sargv[i]); - if (!picosat_failed_assumption (picosat, lit)) continue; - fprintf (file, "%d\n", lit); - count++; - } - if (verbose) - fprintf (output, "c found and wrote %d failed assumptions\n", count); -#ifndef NDEBUG - for (i = 1; i <= max_idx; i++) - if (picosat_failed_assumption (picosat, i)) - count--; -#endif - assert (!count); -} - -static void -write_to_file (PicoSAT * picosat, - const char *name, - const char *type, - void (*writer) (PicoSAT *, FILE *)) -{ - int pclose_file, zipped = has_suffix (name, ".gz"); - FILE *file; - char *cmd; - - if (zipped) - { -#ifdef NZIP - file = NULL; -#else - cmd = malloc (strlen (GZIP) + strlen (name)); - sprintf (cmd, GZIP, name); - file = popen (cmd, "w"); - free (cmd); - pclose_file = 1; -#endif - } - else - { - file = fopen (name, "w"); - pclose_file = 0; - } - - if (file) - { - if (verbose) - fprintf (output, - "c\nc writing %s%s to '%s'\n", - zipped ? "gzipped " : "", type, name); - - writer (picosat, file); - -#ifndef NZIP - if (pclose_file) - pclose (file); - else -#endif - fclose (file); - } - else - fprintf (output, "*** picosat: can not write to '%s'\n", name); -} - -static int catched; - -static void (*sig_int_handler); -static void (*sig_segv_handler); -static void (*sig_abrt_handler); -static void (*sig_term_handler); -#ifndef NALLSIGNALS -static void (*sig_kill_handler); -static void (*sig_xcpu_handler); -static void (*sig_xfsz_handler); -#endif - -static void -resetsighandlers (void) -{ - (void) signal (SIGINT, sig_int_handler); - (void) signal (SIGSEGV, sig_segv_handler); - (void) signal (SIGABRT, sig_abrt_handler); - (void) signal (SIGTERM, sig_term_handler); -#ifndef NALLSIGNALS - (void) signal (SIGKILL, sig_kill_handler); - (void) signal (SIGXCPU, sig_xcpu_handler); - (void) signal (SIGXFSZ, sig_xfsz_handler); -#endif -} - -static int time_limit_in_seconds; -static void (*sig_alarm_handler); -static int ought_to_be_interrupted, interrupt_notified; - -static void -alarm_triggered (int sig) -{ - (void) sig; - assert (sig == SIGALRM); - assert (time_limit_in_seconds); - assert (!ought_to_be_interrupted); - ought_to_be_interrupted = 1; - assert (!interrupt_notified); -} - -static int -interrupt_call_back (void * dummy) -{ - (void) dummy; - if (!ought_to_be_interrupted) - return 0; - if (!interrupt_notified) - { - if (verbose) - { - picosat_message (picosat, 1, ""); - picosat_message (picosat, 1, - "*** TIME LIMIT OF %d SECONDS REACHED ***", - time_limit_in_seconds); - picosat_message (picosat, 1, ""); - } - interrupt_notified = 1; - } - return 1; -} - -static void -setalarm () -{ -#ifndef NALARM - assert (time_limit_in_seconds > 0); - sig_alarm_handler = signal (SIGALRM, alarm_triggered); - alarm (time_limit_in_seconds); - assert (picosat); - picosat_set_interrupt (picosat, 0, interrupt_call_back); -#endif -} - -static void -resetalarm () -{ - assert (time_limit_in_seconds > 0); - (void) signal (SIGALRM, sig_term_handler); -} - -static void -message (int sig) -{ - picosat_message (picosat, 1, ""); - picosat_message (picosat, 1, "*** CAUGHT SIGNAL %d ***", sig); - picosat_message (picosat, 1, ""); -} - -static void -catch (int sig) -{ - if (!catched) - { - message (sig); - catched = 1; - picosat_stats (picosat); - message (sig); - } - - resetsighandlers (); - raise (sig); -} - -static void -setsighandlers (void) -{ - sig_int_handler = signal (SIGINT, catch); - sig_segv_handler = signal (SIGSEGV, catch); - sig_abrt_handler = signal (SIGABRT, catch); - sig_term_handler = signal (SIGTERM, catch); -#ifndef NALLSIGNALS - sig_kill_handler = signal (SIGKILL, catch); - sig_xcpu_handler = signal (SIGXCPU, catch); - sig_xfsz_handler = signal (SIGXFSZ, catch); -#endif -} - -#define USAGE \ -"usage: picosat [ <option> ... ] [ <input> ]\n" \ -"\n" \ -"where <option> is one of the following\n" \ -"\n" \ -" -h print this command line option summary and exit\n" \ -" --version print version and exit\n" \ -" --config print build configuration and exit\n" \ -"\n" \ -" -v enable verbose output\n" \ -" -f ignore invalid header\n" \ -" -n do not print satisfying assignment\n" \ -" -p print formula in DIMACS format and exit\n" \ -" --plain disable preprocessing (failed literal probing)\n" \ -" -a <lit> start with an assumption\n" \ -" -l <limit> set decision limit (no limit per default)\n" \ -" -L <limit> set time limit in seconds (no limit per default)\n" \ -" -P <limit> set propagation limit (no limit per default)\n" \ -" -i [0-3] [0-3]=[FALSE,TRUE,JWH,RAND] initial phase (default 2=JWH)\n" \ -" -s <seed> set random number generator seed (default 0)\n" \ -" -o <output> set output file (<stdout> per default)\n" \ -" -t <trace> generate compact proof trace file\n" \ -" -T <trace> generate extended proof trace file\n" \ -" -r <trace> generate reverse unit propagation proof file\n" \ -" -R <trace> generate reverse unit propagation proof file incrementally\n" \ -" -c <core> generate clausal core file in DIMACS format\n" \ -" -V <core> generate file listing core variables\n" \ -" -U <core> generate file listing used variables\n" \ -" -A <core> generate file listing failed assumptions\n" \ -"\n" \ -" --all enumerate all solutions\n" \ -" --partial generate and print only partial assignment\n" \ -"\n" \ -"and <input> is an optional input file in DIMACS format.\n" - -int -picosat_main (int argc, char **argv) -{ - int res, done, err, print_satisfying_assignment, force, print_formula; - const char *compact_trace_name, *extended_trace_name, * rup_trace_name; - int assumption, assumptions, defaultphase, allsat, partial, plain; - const char * clausal_core_name, * variable_core_name; - const char *input_name, *output_name; - const char * failed_assumptions_name; - int close_input, pclose_input; - long long propagation_limit; - int i, decision_limit; - double start_time; - long long sols; - unsigned seed; - FILE *file; - int trace; - - start_time = picosat_time_stamp (); - - sargc = argc; - sargv = argv; - - clausal_core_name = 0; - variable_core_name = 0; - failed_assumptions_name = 0; - output_name = 0; - compact_trace_name = 0; - extended_trace_name = 0; - rup_trace_name = 0; - incremental_rup_file = 0; - close_input = 0; - pclose_input = 0; - input_name = "<stdin>"; - input = stdin; - output = stdout; - verbose = 0; - done = err = 0; - decision_limit = -1; - propagation_limit = -1; - defaultphase = 2; - assumptions = 0; - force = 0; - allsat = 0; - partial = 0; - trace = 0; - plain = 0; - seed = 0; - sols= 0; - - picosat = 0; - - print_satisfying_assignment = 1; - print_formula = 0; - - for (i = 1; !done && !err && i < argc; i++) - { - if (!strcmp (argv[i], "-h")) - { - fputs (USAGE, output); - done = 1; - } - else if (!strcmp (argv[i], "--version")) - { - fprintf (output, "%s\n", picosat_version ()); - done = 1; - } - else if (!strcmp (argv[i], "--config")) - { - fprintf (output, "%s\n", picosat_config ()); - done = 1; - } - else if (!strcmp (argv[i], "-v")) - { - verbose++; - } - else if (!strcmp (argv[i], "--plain")) - { - plain = 1; - } - else if (!strcmp (argv[i], "-f")) - { - force = 1; - } - else if (!strcmp (argv[i], "-n")) - { - print_satisfying_assignment = 0; - } - else if (!strcmp (argv[i], "--partial")) - { - partial = 1; - } - else if (!strcmp (argv[i], "-p")) - { - print_formula = 1; - } - else if (!strcmp (argv[i], "-l")) - { - if (++i == argc) - { - fprintf (output, "*** picosat: argument to '-l' missing\n"); - err = 1; - } - else - decision_limit = atoi (argv[i]); - } - else if (!strcmp (argv[i], "-L")) - { - if (++i == argc) - { - fprintf (output, "*** picosat: argument to '-L' missing\n"); - err = 1; - } - else - { - time_limit_in_seconds = atoi (argv[i]); - if (time_limit_in_seconds <= 0) - { - fprintf (output, "*** picosat: invalid '-L' argument\n"); - err = 1; - } - } - } - else if (!strcmp (argv[i], "-P")) - { - if (++i == argc) - { - fprintf (output, "*** picosat: argument to '-P' missing\n"); - err = 1; - } - else - propagation_limit = atol /* DM */ (argv[i]); - } - else if (!strcmp (argv[i], "-i")) - { - if (++i == argc) - { - fprintf (output, "*** picosat: argument to '-i' missing\n"); - err = 1; - } - else if (!argv[i][1] && ('0' <= argv[i][0] && argv[i][0] <= '3')) - { - defaultphase = argv[i][0] - '0'; - } - else - { - fprintf (output, "*** picosat: invalid argument to '-i'\n"); - err = 1; - } - } - else if (!strcmp (argv[i], "-a")) - { - if (++i == argc) - { - fprintf (output, "*** picosat: argument to '-a' missing\n"); - err = 1; - } - else if (!atoi (argv[i])) - { - fprintf (output, "*** picosat: argument to '-a' zero\n"); - err = 1; - } - else - { - /* Handle assumptions further down - */ - assumptions++; - } - } - else if (!strcmp (argv[i], "--all")) - { - allsat = 1; - } - else if (!strcmp (argv[i], "-s")) - { - if (++i == argc) - { - fprintf (output, "*** picosat: argument to '-s' missing\n"); - err = 1; - } - else - seed = atoi (argv[i]); - } - else if (!strcmp (argv[i], "-o")) - { - if (output_name) - { - fprintf (output, - "*** picosat: " - "multiple output files '%s' and '%s'\n", - output_name, argv[i]); - err = 1; - } - else if (++i == argc) - { - fprintf (output, "*** picosat: argument ot '-o' missing\n"); - err = 1; - } - else if (!(file = fopen (argv[i], "w"))) - { - fprintf (output, - "*** picosat: " - "can not write output file '%s'\n", argv[i]); - err = 1; - } - else - { - output_name = argv[i]; - output = file; - } - } - else if (!strcmp (argv[i], "-t")) - { - if (compact_trace_name) - { - fprintf (output, - "*** picosat: " - "multiple compact trace files '%s' and '%s'\n", - compact_trace_name, argv[i]); - err = 1; - } - else if (++i == argc) - { - fprintf (output, "*** picosat: argument ot '-t' missing\n"); - err = 1; - } - else - { - compact_trace_name = argv[i]; - trace = 1; - } - } - else if (!strcmp (argv[i], "-T")) - { - if (extended_trace_name) - { - fprintf (output, - "*** picosat: " - "multiple extended trace files '%s' and '%s'\n", - extended_trace_name, argv[i]); - err = 1; - } - else if (++i == argc) - { - fprintf (output, "*** picosat: argument ot '-T' missing\n"); - err = 1; - } - else - { - extended_trace_name = argv[i]; - trace = 1; - } - } - else if (!strcmp (argv[i], "-r")) - { - if (rup_trace_name) - { - fprintf (output, - "*** picosat: " - "multiple RUP trace files '%s' and '%s'\n", - rup_trace_name, argv[i]); - err = 1; - } - else if (++i == argc) - { - fprintf (output, "*** picosat: argument ot '-r' missing\n"); - err = 1; - } - else - { - rup_trace_name = argv[i]; - trace = 1; - } - } - else if (!strcmp (argv[i], "-R")) - { - if (rup_trace_name) - { - fprintf (output, - "*** picosat: " - "multiple RUP trace files '%s' and '%s'\n", - rup_trace_name, argv[i]); - err = 1; - } - else if (++i == argc) - { - fprintf (output, "*** picosat: argument ot '-R' missing\n"); - err = 1; - } - else if (!(file = fopen (argv[i], "w"))) - { - fprintf (output, - "*** picosat: can not write to '%s'\n", argv[i]); - err = 1; - } - else - { - rup_trace_name = argv[i]; - incremental_rup_file = file; - } - } - else if (!strcmp (argv[i], "-c")) - { - if (clausal_core_name) - { - fprintf (output, - "*** picosat: " - "multiple clausal core files '%s' and '%s'\n", - clausal_core_name, argv[i]); - err = 1; - } - else if (++i == argc) - { - fprintf (output, "*** picosat: argument ot '-c' missing\n"); - err = 1; - } - else - { - clausal_core_name = argv[i]; - trace = 1; - } - } - else if (!strcmp (argv[i], "-V")) - { - if (variable_core_name) - { - fprintf (output, - "*** picosat: " - "multiple variable core files '%s' and '%s'\n", - variable_core_name, argv[i]); - err = 1; - } - else if (++i == argc) - { - fprintf (output, "*** picosat: argument ot '-V' missing\n"); - err = 1; - } - else - { - variable_core_name = argv[i]; - trace = 1; - } - } - else if (!strcmp (argv[i], "-A")) - { - if (failed_assumptions_name) - { - fprintf (output, - "*** picosat: " - "multiple failed assumptions files '%s' and '%s'\n", - failed_assumptions_name, argv[i]); - err = 1; - } - else if (++i == argc) - { - fprintf (output, "*** picosat: argument ot '-A' missing\n"); - err = 1; - } - else - failed_assumptions_name = argv[i]; - } - else if (argv[i][0] == '-') - { - fprintf (output, - "*** picosat: " - "unknown command line option '%s' (try '-h')\n", argv[i]); - err = 1; - } - else if (close_input || pclose_input) - { - fprintf (output, - "*** picosat: " - "multiple input files '%s' and '%s'\n", - input_name, argv[i]); - err = 1; - } - else if (has_suffix (argv[i], ".gz")) - { -#ifdef NZIP - file=NULL; - err=1; -#else - char *cmd = malloc (strlen (GUNZIP) + strlen (argv[i])); - sprintf (cmd, GUNZIP, argv[i]); - if ((file = popen (cmd, "r"))) - { - input_name = argv[i]; - pclose_input = 1; - input = file; - } - else - { - fprintf (output, - "*** picosat: " - "can not read compressed input file '%s'\n", argv[i]); - err = 1; - } - free (cmd); -#endif - } - else if (has_suffix (argv[i], ".bz2")) - { -#ifdef NZIP - file=NULL; - err=1; -#else - char *cmd = malloc (strlen (BUNZIP2) + strlen (argv[i])); - sprintf (cmd, BUNZIP2, argv[i]); - if ((file = popen (cmd, "r"))) - { - input_name = argv[i]; - pclose_input = 1; - input = file; - } - else - { - fprintf (output, - "*** picosat: " - "can not read compressed input file '%s'\n", argv[i]); - err = 1; - } - free (cmd); -#endif - } - else if (!(file = fopen (argv[i], "r"))) /* TODO .gz ? */ - { - fprintf (output, - "*** picosat: can not read input file '%s'\n", argv[i]); - err = 1; - } - else - { - input_name = argv[i]; - close_input = 1; - input = file; - } - } - - if (allsat && partial) - { - fprintf (output, - "*** picosat: can not combine '--all' and '--partial'"); - err = 1; - } - - res = PICOSAT_UNKNOWN; - - if (!done && !err) - { - const char *err_msg; - - if (verbose) - { - fprintf (output, - "c PicoSAT SAT Solver Version %s\n", - picosat_version ()); - - fprintf (output, "c %s\n", picosat_copyright ()); - fprintf (output, "c %s\n", picosat_config ()); - } - - picosat = picosat_init (); - - if (verbose) - setsighandlers (); - - if (time_limit_in_seconds) - setalarm (); - - picosat_enter (picosat); - - if (output_name) - picosat_set_output (picosat, output); - - picosat_set_verbosity (picosat, verbose); - picosat_set_plain (picosat, plain); - - if (verbose) fputs ("c\n", output); - - if (trace) - { - if (verbose) - fprintf (output, "c tracing proof\n"); - picosat_enable_trace_generation (picosat); - } - - if (defaultphase) - { - if (verbose) - fprintf (output, "c using %d as default phase\n", defaultphase); - picosat_set_global_default_phase (picosat, defaultphase); - } - - if (propagation_limit >= 0) - { - if (verbose) - fprintf (output, "c propagation limit of %lld propagations\n", - propagation_limit); - picosat_set_propagation_limit (picosat, - (unsigned long long) propagation_limit); - } - - if (partial) - { - if (verbose) - fprintf (output, - "c saving original clauses for partial assignment\n"); - - picosat_save_original_clauses (picosat); - } - - if (verbose) - fprintf (output, "c\nc parsing %s\n", input_name); - - if (verbose) - fflush (output); - - if ((err_msg = parse (picosat, force))) - { - fprintf (output, "%s:%d: %s\n", input_name, lineno, err_msg); - err = 1; - } - else - { -NEXT_SOLUTION: - if (assumptions) - { - i = 0; - while ((i = next_assumption (i))) - { - assert (i < argc); - assumption = atoi (argv[i]); - assert (assumption); - - picosat_assume (picosat, assumption); - - if (verbose) - fprintf (output, "c assumption %d\n", assumption); - } - } - - if (print_formula) - { - picosat_print (picosat, output); - } - else - { - if (verbose) - fprintf (output, - "c initialized %u variables\n" - "c found %u non trivial clauses\n", - picosat_variables (picosat), - picosat_added_original_clauses (picosat)); - - picosat_set_seed (picosat, seed); - if (verbose) - fprintf (output, - "c\nc random number generator seed %u\n", - seed); - - res = picosat_sat (picosat, decision_limit); - - if (res == PICOSAT_UNSATISFIABLE) - { - - if (allsat) - fprintf (output, "s SOLUTIONS %lld\n", sols); - else - fputs ("s UNSATISFIABLE\n", output); - - fflush (output); - - if (compact_trace_name) - write_to_file (picosat, - compact_trace_name, - "compact trace", - picosat_write_compact_trace); - - if (extended_trace_name) - write_to_file (picosat, - extended_trace_name, - "extended trace", - picosat_write_extended_trace); - - if (!incremental_rup_file && rup_trace_name) - write_to_file (picosat, - rup_trace_name, - "rup trace", - picosat_write_rup_trace); - - if (clausal_core_name) - write_to_file (picosat, - clausal_core_name, - "clausal core", - picosat_write_clausal_core); - - if (variable_core_name) - write_to_file (picosat, - variable_core_name, - "variable core", - write_core_variables); - - if (failed_assumptions_name) - write_to_file (picosat, - failed_assumptions_name, - "failed assumptions", - write_failed_assumptions); - } - else if (res == PICOSAT_SATISFIABLE) - { - if (allsat) - { - sols++; - if (verbose) - fprintf (output, "c\nc solution %lld\nc\n", sols); - } - - if (!allsat || print_satisfying_assignment) - fputs ("s SATISFIABLE\n", output); - - if (!allsat || verbose || print_satisfying_assignment) - fflush (output); - - if (print_satisfying_assignment) - printa (picosat, partial); - - if (allsat) - { - blocksol (picosat); - goto NEXT_SOLUTION; - } - } - else - { - fputs ("s UNKNOWN\n", output); - - if (allsat && verbose) - fprintf (output, - "c\nc limit reached after %lld solutions\n", - sols); - fflush (output); - } - } - } - - if (!err && verbose) - { - fputs ("c\n", output); - picosat_stats (picosat); - fprintf (output, - "c %.1f seconds total run time\n", - picosat_time_stamp () - start_time); - } - - if (sol) - { - free (sol); - sol = 0; - } - - picosat_leave (picosat); - - if (time_limit_in_seconds) - resetalarm (); - - if (verbose) - resetsighandlers (); - - picosat_reset (picosat); - } - - if (incremental_rup_file) - fclose (incremental_rup_file); - - if (close_input) - fclose (input); - -#ifndef NZIP - if (pclose_input) - pclose (input); -#endif - - if (output_name) - fclose (output); - - return res; -} -#ifdef VERIMAG_MEASUREMENTS -#include "../clock.h" -#endif - -int picosat_main (int, char **); - -int -main (int argc, char **argv) -{ - -#ifdef VERIMAG_MEASUREMENTS - clock_prepare(); - clock_start(); -#endif - - int ret= picosat_main (argc, argv); - -#ifdef VERIMAG_MEASUREMENTS - clock_stop(); - print_total_clock(); -#endif - - return ret; -} -/**************************************************************************** -Copyright (c) 2006 - 2015, Armin Biere, Johannes Kepler University. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to -deal in the Software without restriction, including without limitation the -rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -sell copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -IN THE SOFTWARE. -****************************************************************************/ - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <assert.h> -#include <limits.h> -#include <ctype.h> -#include <stdarg.h> -#include <stdint.h> - -#include "picosat.h" - -#define INLINE inline - -/* By default code for 'all different constraints' is disabled, since 'NADC' - * is defined. - */ -#define NADC - -/* By default we enable failed literals, since 'NFL' is undefined. - * -#define NFL - */ - -/* By default we 'detach satisfied (large) clauses', e.g. NDSC undefined. - * -#define NDSC - */ - -/* Do not use luby restart schedule instead of inner/outer. - * -#define NLUBY - */ - -/* Enabling this define, will use gnuplot to visualize how the scores evolve. - * -#define VISCORES - */ - -#ifdef VISCORES -// #define WRITEGIF /* ... to generate a video */ -#endif - -#ifdef VISCORES -#ifndef WRITEGIF -#include <unistd.h> /* for 'usleep' */ -#endif -#endif - -#ifdef RCODE -#include <R.h> -#endif - -#define MINRESTART 100 /* minimum restart interval */ -#define MAXRESTART 1000000 /* maximum restart interval */ -#define RDECIDE 1000 /* interval of random decisions */ -#define FRESTART 110 /* restart increase factor in percent */ -#define FREDUCE 110 /* reduce increase factor in percent */ -#define FREDADJ 121 /* reduce increase adjustment factor */ -#define MAXCILS 10 /* maximal number of unrecycled internals */ -#define FFLIPPED 10000 /* flipped reduce factor */ -#define FFLIPPEDPREC 10000000/* flipped reduce factor precision */ -#define INTERRUPTLIM 1024 /* check interrupt after that many decisions */ - -#ifndef TRACE -#define NO_BINARY_CLAUSES /* store binary clauses more compactly */ -#endif - -/* For debugging purposes you may want to define 'LOGGING', which actually - * can be enforced by using './configure.sh --log'. - */ -#ifdef LOGGING -#define LOG(code) do { code; } while (0) -#else -#define LOG(code) do { } while (0) -#endif -#define NOLOG(code) do { } while (0) /* log exception */ -#define ONLYLOG(code) do { code; } while (0) /* force logging */ - -#define FALSE ((Val)-1) -#define UNDEF ((Val)0) -#define TRUE ((Val)1) - -#define COMPACT_TRACECHECK_TRACE_FMT 0 -#define EXTENDED_TRACECHECK_TRACE_FMT 1 -#define RUP_TRACE_FMT 2 - -#define NEWN(p,n) do { (p) = new (ps, sizeof (*(p)) * (n)); } while (0) -#define CLRN(p,n) do { memset ((p), 0, sizeof (*(p)) * (n)); } while (0) -#define CLR(p) CLRN(p,1) -#define DELETEN(p,n) \ - do { delete (ps, p, sizeof (*(p)) * (n)); (p) = 0; } while (0) - -#define RESIZEN(p,old_num,new_num) \ - do { \ - size_t old_size = sizeof (*(p)) * (old_num); \ - size_t new_size = sizeof (*(p)) * (new_num); \ - (p) = resize (ps, (p), old_size, new_size) ; \ - } while (0) - -#define ENLARGE(start,head,end) \ - do { \ - unsigned old_num = (ptrdiff_t)((end) - (start)); \ - size_t new_num = old_num ? (2 * old_num) : 1; \ - unsigned count = (head) - (start); \ - assert ((start) <= (end)); \ - RESIZEN((start),old_num,new_num); \ - (head) = (start) + count; \ - (end) = (start) + new_num; \ - } while (0) - -#define NOTLIT(l) (ps->lits + (1 ^ ((l) - ps->lits))) - -#define LIT2IDX(l) ((ptrdiff_t)((l) - ps->lits) / 2) -#define LIT2IMPLS(l) (ps->impls + (ptrdiff_t)((l) - ps->lits)) -#define LIT2INT(l) ((int)(LIT2SGN(l) * LIT2IDX(l))) -#define LIT2SGN(l) (((ptrdiff_t)((l) - ps->lits) & 1) ? -1 : 1) -#define LIT2VAR(l) (ps->vars + LIT2IDX(l)) -#define LIT2HTPS(l) (ps->htps + (ptrdiff_t)((l) - ps->lits)) -#define LIT2JWH(l) (ps->jwh + ((l) - ps->lits)) - -#ifndef NDSC -#define LIT2DHTPS(l) (ps->dhtps + (ptrdiff_t)((l) - ps->lits)) -#endif - -#ifdef NO_BINARY_CLAUSES -typedef uintptr_t Wrd; -#define ISLITREASON(C) (1&(Wrd)C) -#define LIT2REASON(L) \ - (assert (L->val==TRUE), ((Cls*)(1 + (2*(L - ps->lits))))) -#define REASON2LIT(C) ((Lit*)(ps->lits + ((Wrd)C)/2)) -#endif - -#define ENDOFCLS(c) ((void*)((Lit**)(c)->lits + (c)->size)) - -#define SOC ((ps->oclauses == ps->ohead) ? ps->lclauses : ps->oclauses) -#define EOC (ps->lhead) -#define NXC(p) (((p) + 1 == ps->ohead) ? ps->lclauses : (p) + 1) - -#define OIDX2IDX(idx) (2 * ((idx) + 1)) -#define LIDX2IDX(idx) (2 * (idx) + 1) - -#define ISLIDX(idx) ((idx)&1) - -#define IDX2OIDX(idx) (assert(!ISLIDX(idx)), (idx)/2 - 1) -#define IDX2LIDX(idx) (assert(ISLIDX(idx)), (idx)/2) - -#define EXPORTIDX(idx) \ - ((ISLIDX(idx) ? (IDX2LIDX (idx) + (ps->ohead - ps->oclauses)) : IDX2OIDX(idx)) + 1) - -#define IDX2CLS(i) \ - (assert(i), (ISLIDX(i) ? ps->lclauses : ps->oclauses)[(i)/2 - !ISLIDX(i)]) - -#define IDX2ZHN(i) (assert(i), (ISLIDX(i) ? ps->zhains[(i)/2] : 0)) - -#define CLS2TRD(c) (((Trd*)(c)) - 1) -#define CLS2IDX(c) ((((Trd*)(c)) - 1)->idx) - -#define CLS2ACT(c) \ - ((Act*)((assert((c)->learned)),assert((c)->size>2),ENDOFCLS(c))) - -#define VAR2LIT(v) (ps->lits + 2 * ((v) - ps->vars)) -#define VAR2RNK(v) (ps->rnks + ((v) - ps->vars)) - -#define RNK2LIT(r) (ps->lits + 2 * ((r) - ps->rnks)) -#define RNK2VAR(r) (ps->vars + ((r) - ps->rnks)) - -#define BLK_FILL_BYTES 8 -#define SIZE_OF_BLK (sizeof (Blk) - BLK_FILL_BYTES) - -#define PTR2BLK(void_ptr) \ - ((void_ptr) ? (Blk*)(((char*)(void_ptr)) - SIZE_OF_BLK) : 0) - -#define AVERAGE(a,b) ((b) ? (((double)a) / (double)(b)) : 0.0) -#define PERCENT(a,b) (100.0 * AVERAGE(a,b)) - -#ifndef RCODE -#define ABORT(msg) \ - do { \ - fputs ("*** picosat: " msg "\n", stderr); \ - abort (); \ - } while (0) -#else -#define ABORT(msg) \ - do { \ - Rf_error (msg); \ - } while (0) -#endif - -#define ABORTIF(cond,msg) \ - do { \ - if (!(cond)) break; \ - ABORT (msg); \ - } while (0) - -#define ZEROFLT (0x00000000u) -#define EPSFLT (0x00000001u) -#define INFFLT (0xffffffffu) - -#define FLTCARRY (1u << 25) -#define FLTMSB (1u << 24) -#define FLTMAXMANTISSA (FLTMSB - 1) - -#define FLTMANTISSA(d) ((d) & FLTMAXMANTISSA) -#define FLTEXPONENT(d) ((int)((d) >> 24) - 128) - -#define FLTMINEXPONENT (-128) -#define FLTMAXEXPONENT (127) - -#define CMPSWAPFLT(a,b) \ - do { \ - Flt tmp; \ - if (((a) < (b))) \ - { \ - tmp = (a); \ - (a) = (b); \ - (b) = tmp; \ - } \ - } while (0) - -#define UNPACKFLT(u,m,e) \ - do { \ - (m) = FLTMANTISSA(u); \ - (e) = FLTEXPONENT(u); \ - (m) |= FLTMSB; \ - } while (0) - -#define INSERTION_SORT_LIMIT 10 - -#define SORTING_SWAP(T,p,q) \ -do { \ - T tmp = *(q); \ - *(q) = *(p); \ - *(p) = tmp; \ -} while (0) - -#define SORTING_CMP_SWAP(T,cmp,p,q) \ -do { \ - if ((cmp) (ps, *(p), *(q)) > 0) \ - SORTING_SWAP (T, p, q); \ -} while(0) - -#define QUICKSORT_PARTITION(T,cmp,a,l,r) \ -do { \ - T pivot; \ - int j; \ - i = (l) - 1; /* result in 'i' */ \ - j = (r); \ - pivot = (a)[j]; \ - for (;;) \ - { \ - while ((cmp) (ps, (a)[++i], pivot) < 0) \ - ; \ - while ((cmp) (ps, pivot, (a)[--j]) < 0) \ - if (j == (l)) \ - break; \ - if (i >= j) \ - break; \ - SORTING_SWAP (T, (a) + i, (a) + j); \ - } \ - SORTING_SWAP (T, (a) + i, (a) + (r)); \ -} while(0) - -#define QUICKSORT(T,cmp,a,n) \ -do { \ - int l = 0, r = (n) - 1, m, ll, rr, i; \ - assert (ps->ihead == ps->indices); \ - if (r - l <= INSERTION_SORT_LIMIT) \ - break; \ - for (;;) \ - { \ - m = (l + r) / 2; \ - SORTING_SWAP (T, (a) + m, (a) + r - 1); \ - SORTING_CMP_SWAP (T, cmp, (a) + l, (a) + r - 1); \ - SORTING_CMP_SWAP (T, cmp, (a) + l, (a) + r); \ - SORTING_CMP_SWAP (T, cmp, (a) + r - 1, (a) + r); \ - QUICKSORT_PARTITION (T, cmp, (a), l + 1, r - 1); \ - if (i - l < r - i) \ - { \ - ll = i + 1; \ - rr = r; \ - r = i - 1; \ - } \ - else \ - { \ - ll = l; \ - rr = i - 1; \ - l = i + 1; \ - } \ - if (r - l > INSERTION_SORT_LIMIT) \ - { \ - assert (rr - ll > INSERTION_SORT_LIMIT); \ - if (ps->ihead == ps->eoi) \ - ENLARGE (ps->indices, ps->ihead, ps->eoi); \ - *ps->ihead++ = ll; \ - if (ps->ihead == ps->eoi) \ - ENLARGE (ps->indices, ps->ihead, ps->eoi); \ - *ps->ihead++ = rr; \ - } \ - else if (rr - ll > INSERTION_SORT_LIMIT) \ - { \ - l = ll; \ - r = rr; \ - } \ - else if (ps->ihead > ps->indices) \ - { \ - r = *--ps->ihead; \ - l = *--ps->ihead; \ - } \ - else \ - break; \ - } \ -} while (0) - -#define INSERTION_SORT(T,cmp,a,n) \ -do { \ - T pivot; \ - int l = 0, r = (n) - 1, i, j; \ - for (i = r; i > l; i--) \ - SORTING_CMP_SWAP (T, cmp, (a) + i - 1, (a) + i); \ - for (i = l + 2; i <= r; i++) \ - { \ - j = i; \ - pivot = (a)[i]; \ - while ((cmp) (ps, pivot, (a)[j - 1]) < 0) \ - { \ - (a)[j] = (a)[j - 1]; \ - j--; \ - } \ - (a)[j] = pivot; \ - } \ -} while (0) - -#ifdef NDEBUG -#define CHECK_SORTED(cmp,a,n) do { } while(0) -#else -#define CHECK_SORTED(cmp,a,n) \ -do { \ - int i; \ - for (i = 0; i < (n) - 1; i++) \ - assert ((cmp) (ps, (a)[i], (a)[i + 1]) <= 0); \ -} while(0) -#endif - -#define SORT(T,cmp,a,n) \ -do { \ - T * aa = (a); \ - int nn = (n); \ - QUICKSORT (T, cmp, aa, nn); \ - INSERTION_SORT (T, cmp, aa, nn); \ - assert (ps->ihead == ps->indices); \ - CHECK_SORTED (cmp, aa, nn); \ -} while (0) - -#define WRDSZ (sizeof (long) * 8) - -#ifdef RCODE -#define fprintf(...) do { } while (0) -#define vfprintf(...) do { } while (0) -#define fputs(...) do { } while (0) -#define fputc(...) do { } while (0) -#endif - -typedef unsigned Flt; /* 32 bit deterministic soft float */ -typedef Flt Act; /* clause and variable activity */ -typedef struct Blk Blk; /* allocated memory block */ -typedef struct Cls Cls; /* clause */ -typedef struct Lit Lit; /* literal */ -typedef struct Rnk Rnk; /* variable to score mapping */ -typedef signed char Val; /* TRUE, UNDEF, FALSE */ -typedef struct Var Var; /* variable */ -#ifdef TRACE -typedef struct Trd Trd; /* trace data for clauses */ -typedef struct Zhn Zhn; /* compressed chain (=zain) data */ -typedef unsigned char Znt; /* compressed antecedent data */ -#endif - -#ifdef NO_BINARY_CLAUSES -typedef struct Ltk Ltk; - -struct Ltk -{ - Lit ** start; - unsigned count : WRDSZ == 32 ? 27 : 32; - unsigned ldsize : WRDSZ == 32 ? 5 : 32; -}; -#endif - -struct Lit -{ - Val val; -}; - -struct Var -{ - unsigned mark : 1; /*bit 1*/ - unsigned resolved : 1; /*bit 2*/ - unsigned phase : 1; /*bit 3*/ - unsigned assigned : 1; /*bit 4*/ - unsigned used : 1; /*bit 5*/ - unsigned failed : 1; /*bit 6*/ - unsigned internal : 1; /*bit 7*/ - unsigned usedefphase : 1; /*bit 8*/ - unsigned defphase : 1; /*bit 9*/ - unsigned msspos : 1; /*bit 10*/ - unsigned mssneg : 1; /*bit 11*/ - unsigned humuspos : 1; /*bit 12*/ - unsigned humusneg : 1; /*bit 13*/ - unsigned partial : 1; /*bit 14*/ -#ifdef TRACE - unsigned core : 1; /*bit 15*/ -#endif - unsigned level; - Cls *reason; -#ifndef NADC - Lit ** inado; - Lit ** ado; - Lit *** adotabpos; -#endif -}; - -struct Rnk -{ - Act score; - unsigned pos : 30; /* 0 iff not on heap */ - unsigned moreimportant : 1; - unsigned lessimportant : 1; -}; - -struct Cls -{ - unsigned size; - - unsigned collect:1; /* bit 1 */ - unsigned learned:1; /* bit 2 */ - unsigned locked:1; /* bit 3 */ - unsigned used:1; /* bit 4 */ -#ifndef NDEBUG - unsigned connected:1; /* bit 5 */ -#endif -#ifdef TRACE - unsigned collected:1; /* bit 6 */ - unsigned core:1; /* bit 7 */ -#endif - -#define LDMAXGLUE 25 /* 32 - 7 */ -#define MAXGLUE ((1<<LDMAXGLUE)-1) - - unsigned glue:LDMAXGLUE; - - Cls *next[2]; - Lit *lits[2]; -}; - -#ifdef TRACE -struct Zhn -{ - unsigned ref:31; - unsigned core:1; - Znt * liz; - Znt znt[0]; -}; - -struct Trd -{ - unsigned idx; - Cls cls[0]; -}; -#endif - -struct Blk -{ -#ifndef NDEBUG - union - { - size_t size; /* this is what we really use */ - void *as_two_ptrs[2]; /* 2 * sizeof (void*) alignment of data */ - } - header; -#endif - char data[BLK_FILL_BYTES]; -}; - -enum State -{ - RESET = 0, - READY = 1, - SAT = 2, - UNSAT = 3, - UNKNOWN = 4, -}; - -enum Phase -{ - POSPHASE, - NEGPHASE, - JWLPHASE, - RNDPHASE, -}; - -struct PicoSAT -{ - enum State state; - enum Phase defaultphase; - int last_sat_call_result; - - FILE *out; - char * prefix; - int verbosity; - int plain; - unsigned LEVEL; - unsigned max_var; - unsigned size_vars; - - Lit *lits; - Var *vars; - Rnk *rnks; - Flt *jwh; - Cls **htps; -#ifndef NDSC - Cls **dhtps; -#endif -#ifdef NO_BINARY_CLAUSES - Ltk *impls; - Cls impl, cimpl; - int implvalid, cimplvalid; -#else - Cls **impls; -#endif - Lit **trail, **thead, **eot, **ttail, ** ttail2; -#ifndef NADC - Lit **ttailado; -#endif - unsigned adecidelevel; - Lit **als, **alshead, **alstail, **eoals; - Lit **CLS, **clshead, **eocls; - int *rils, *rilshead, *eorils; - int *cils, *cilshead, *eocils; - int *fals, *falshead, *eofals; - int *mass, szmass; - int *mssass, szmssass; - int *mcsass, nmcsass, szmcsass; - int *humus, szhumus; - Lit *failed_assumption; - int extracted_all_failed_assumptions; - Rnk **heap, **hhead, **eoh; - Cls **oclauses, **ohead, **eoo; /* original clauses */ - Cls **lclauses, **lhead, ** EOL; /* learned clauses */ - int * soclauses, * sohead, * eoso; /* saved original clauses */ - int saveorig; - int partial; -#ifdef TRACE - int trace; - Zhn **zhains, **zhead, **eoz; - int ocore; -#endif - FILE * rup; - int rupstarted; - int rupvariables; - int rupclauses; - Cls *mtcls; - Cls *conflict; - Lit **added, **ahead, **eoa; - Var **marked, **mhead, **eom; - Var **dfs, **dhead, **eod; - Cls **resolved, **rhead, **eor; - unsigned char *levels, *levelshead, *eolevels; - unsigned *dused, *dusedhead, *eodused; - unsigned char *buffer, *bhead, *eob; - Act vinc, lscore, ilvinc, ifvinc; -#ifdef VISCORES - Act fvinc, nvinc; -#endif - Act cinc, lcinc, ilcinc, fcinc; - unsigned srng; - size_t current_bytes; - size_t max_bytes; - size_t recycled; - double seconds, flseconds; - double entered; - unsigned nentered; - int measurealltimeinlib; - char *rline[2]; - int szrline, RCOUNT; - double levelsum; - unsigned iterations; - int reports; - int lastrheader; - unsigned calls; - unsigned decisions; - unsigned restarts; - unsigned simps; - unsigned fsimplify; - unsigned isimplify; - unsigned reductions; - unsigned lreduce; - unsigned lreduceadjustcnt; - unsigned lreduceadjustinc; - unsigned lastreduceconflicts; - unsigned llocked; /* locked large learned clauses */ - unsigned lrestart; -#ifdef NLUBY - unsigned drestart; - unsigned ddrestart; -#else - unsigned lubycnt; - unsigned lubymaxdelta; - int waslubymaxdelta; -#endif - unsigned long long lsimplify; - unsigned long long propagations; - unsigned long long lpropagations; - unsigned fixed; /* top level assignments */ -#ifndef NFL - unsigned failedlits; - unsigned ifailedlits; - unsigned efailedlits; - unsigned flcalls; -#ifdef STATS - unsigned flrounds; - unsigned long long flprops; - unsigned long long floopsed, fltried, flskipped; -#endif - unsigned long long fllimit; - int simplifying; - Lit ** saved; - unsigned saved_size; -#endif - unsigned conflicts; - unsigned contexts; - unsigned internals; - unsigned noclauses; /* current number large original clauses */ - unsigned nlclauses; /* current number large learned clauses */ - unsigned olits; /* current literals in large original clauses */ - unsigned llits; /* current literals in large learned clauses */ - unsigned oadded; /* added original clauses */ - unsigned ladded; /* added learned clauses */ - unsigned loadded; /* added original large clauses */ - unsigned lladded; /* added learned large clauses */ - unsigned addedclauses; /* oadded + ladded */ - unsigned vused; /* used variables */ - unsigned llitsadded; /* added learned literals */ - unsigned long long visits; -#ifdef STATS - unsigned loused; /* used large original clauses */ - unsigned llused; /* used large learned clauses */ - unsigned long long bvisits; - unsigned long long tvisits; - unsigned long long lvisits; - unsigned long long othertrue; - unsigned long long othertrue2; - unsigned long long othertruel; - unsigned long long othertrue2u; - unsigned long long othertruelu; - unsigned long long ltraversals; - unsigned long long traversals; -#ifdef TRACE - unsigned long long antecedents; -#endif - unsigned uips; - unsigned znts; - unsigned assumptions; - unsigned rdecisions; - unsigned sdecisions; - size_t srecycled; - size_t rrecycled; - unsigned long long derefs; -#endif - unsigned minimizedllits; - unsigned nonminimizedllits; -#ifndef NADC - Lit *** ados, *** hados, *** eados; - Lit *** adotab; - unsigned nadotab; - unsigned szadotab; - Cls * adoconflict; - unsigned adoconflicts; - unsigned adoconflictlimit; - int addingtoado; - int adodisabled; -#endif - unsigned long long flips; -#ifdef STATS - unsigned long long FORCED; - unsigned long long assignments; - unsigned inclreduces; - unsigned staticphasedecisions; - unsigned skippedrestarts; -#endif - int * indices, * ihead, *eoi; - unsigned sdflips; - - unsigned long long saved_flips; - unsigned saved_max_var; - unsigned min_flipped; - - void * emgr; - picosat_malloc enew; - picosat_realloc eresize; - picosat_free edelete; - - struct { - void * state; - int (*function) (void *); - } interrupt; - -#ifdef VISCORES - FILE * fviscores; -#endif -}; - -typedef PicoSAT PS; - -static INLINE Flt -packflt (unsigned m, int e) -{ - Flt res; - assert (m < FLTMSB); - assert (FLTMINEXPONENT <= e); - assert (e <= FLTMAXEXPONENT); - res = m | ((unsigned)(e + 128) << 24); - return res; -} - -static Flt -base2flt (unsigned m, int e) -{ - if (!m) - return ZEROFLT; - - if (m < FLTMSB) - { - do - { - if (e <= FLTMINEXPONENT) - return EPSFLT; - - e--; - m <<= 1; - - } - while (m < FLTMSB); - } - else - { - while (m >= FLTCARRY) - { - if (e >= FLTMAXEXPONENT) - return INFFLT; - - e++; - m >>= 1; - } - } - - m &= ~FLTMSB; - return packflt (m, e); -} - -static Flt -addflt (Flt a, Flt b) -{ - unsigned ma, mb, delta; - int ea, eb; - - CMPSWAPFLT (a, b); - if (!b) - return a; - - UNPACKFLT (a, ma, ea); - UNPACKFLT (b, mb, eb); - - assert (ea >= eb); - delta = ea - eb; - if (delta < 32) mb >>= delta; else mb = 0; - if (!mb) - return a; - - ma += mb; - if (ma & FLTCARRY) - { - if (ea == FLTMAXEXPONENT) - return INFFLT; - - ea++; - ma >>= 1; - } - - assert (ma < FLTCARRY); - ma &= FLTMAXMANTISSA; - - return packflt (ma, ea); -} - -static Flt -mulflt (Flt a, Flt b) -{ - unsigned ma, mb; - unsigned long long accu; - int ea, eb; - - CMPSWAPFLT (a, b); - if (!b) - return ZEROFLT; - - UNPACKFLT (a, ma, ea); - UNPACKFLT (b, mb, eb); - - ea += eb; - ea += 24; - if (ea > FLTMAXEXPONENT) - return INFFLT; - - if (ea < FLTMINEXPONENT) - return EPSFLT; - - accu = ma; - accu *= mb; - accu >>= 24; - - if (accu >= FLTCARRY) - { - if (ea == FLTMAXEXPONENT) - return INFFLT; - - ea++; - accu >>= 1; - - if (accu >= FLTCARRY) - return INFFLT; - } - - assert (accu < FLTCARRY); - assert (accu & FLTMSB); - - ma = accu; - ma &= ~FLTMSB; - - return packflt (ma, ea); -} - -static Flt -ascii2flt (const char *str) -{ - Flt ten = base2flt (10, 0); - Flt onetenth = base2flt (26843546, -28); - Flt res = ZEROFLT, tmp, base; - const char *p = str; - int ch; - - ch = *p++; - - if (ch != '.') - { - if (!isdigit (ch)) - return INFFLT; /* better abort ? */ - - res = base2flt (ch - '0', 0); - - while ((ch = *p++)) - { - if (ch == '.') - break; - - if (!isdigit (ch)) - return INFFLT; /* better abort? */ - - res = mulflt (res, ten); - tmp = base2flt (ch - '0', 0); - res = addflt (res, tmp); - } - } - - if (ch == '.') - { - ch = *p++; - if (!isdigit (ch)) - return INFFLT; /* better abort ? */ - - base = onetenth; - tmp = mulflt (base2flt (ch - '0', 0), base); - res = addflt (res, tmp); - - while ((ch = *p++)) - { - if (!isdigit (ch)) - return INFFLT; /* better abort? */ - - base = mulflt (base, onetenth); - tmp = mulflt (base2flt (ch - '0', 0), base); - res = addflt (res, tmp); - } - } - - return res; -} - -#if defined(VISCORES) - -static double -flt2double (Flt f) -{ - double res; - unsigned m; - int e, i; - - UNPACKFLT (f, m, e); - res = m; - - if (e < 0) - { - for (i = e; i < 0; i++) - res *= 0.5; - } - else - { - for (i = 0; i < e; i++) - res *= 2.0; - } - - return res; -} - -#endif - -static INLINE int -log2flt (Flt a) -{ - return FLTEXPONENT (a) + 24; -} - -static INLINE int -cmpflt (Flt a, Flt b) -{ - if (a < b) - return -1; - - if (a > b) - return 1; - - return 0; -} - -static void * -new (PS * ps, size_t size) -{ - size_t bytes; - Blk *b; - - if (!size) - return 0; - - bytes = size + SIZE_OF_BLK; - - if (ps->enew) - b = ps->enew (ps->emgr, bytes); - else - b = malloc (bytes); - - ABORTIF (!b, "out of memory in 'new'"); -#ifndef NDEBUG - b->header.size = size; -#endif - ps->current_bytes += size; - if (ps->current_bytes > ps->max_bytes) - ps->max_bytes = ps->current_bytes; - return b->data; -} - -static void -delete (PS * ps, void *void_ptr, size_t size) -{ - size_t bytes; - Blk *b; - - if (!void_ptr) - { - assert (!size); - return; - } - - assert (size); - b = PTR2BLK (void_ptr); - - assert (size <= ps->current_bytes); - ps->current_bytes -= size; - - assert (b->header.size == size); - - bytes = size + SIZE_OF_BLK; - if (ps->edelete) - ps->edelete (ps->emgr, b, bytes); - else - free (b); -} - -static void * -resize (PS * ps, void *void_ptr, size_t old_size, size_t new_size) -{ - size_t old_bytes, new_bytes; - Blk *b; - - b = PTR2BLK (void_ptr); - - assert (old_size <= ps->current_bytes); - ps->current_bytes -= old_size; - - if ((old_bytes = old_size)) - { - assert (old_size && b && b->header.size == old_size); - old_bytes += SIZE_OF_BLK; - } - else - assert (!b); - - if ((new_bytes = new_size)) - new_bytes += SIZE_OF_BLK; - - if (ps->eresize) - b = ps->eresize (ps->emgr, b, old_bytes, new_bytes); - else - b = realloc (b, new_bytes); - - if (!new_size) - { - assert (!b); - return 0; - } - - ABORTIF (!b, "out of memory in 'resize'"); -#ifndef NDEBUG - b->header.size = new_size; -#endif - - ps->current_bytes += new_size; - if (ps->current_bytes > ps->max_bytes) - ps->max_bytes = ps->current_bytes; - - return b->data; -} - -static INLINE unsigned -int2unsigned (int l) -{ - return (l < 0) ? 1 + 2 * -l : 2 * l; -} - -static INLINE Lit * -int2lit (PS * ps, int l) -{ - return ps->lits + int2unsigned (l); -} - -static INLINE Lit ** -end_of_lits (Cls * c) -{ - return (Lit**)c->lits + c->size; -} - -#if !defined(NDEBUG) || defined(LOGGING) - -static void -dumplits (PS * ps, Lit ** l, Lit ** end) -{ - int first; - Lit ** p; - - if (l == end) - { - /* empty clause */ - } - else if (l + 1 == end) - { - fprintf (ps->out, "%d ", LIT2INT (l[0])); - } - else - { - assert (l + 2 <= end); - first = (abs (LIT2INT (l[0])) > abs (LIT2INT (l[1]))); - fprintf (ps->out, "%d ", LIT2INT (l[first])); - fprintf (ps->out, "%d ", LIT2INT (l[!first])); - for (p = l + 2; p < end; p++) - fprintf (ps->out, "%d ", LIT2INT (*p)); - } - - fputc ('0', ps->out); -} - -static void -dumpcls (PS * ps, Cls * c) -{ - Lit **end; - - if (c) - { - end = end_of_lits (c); - dumplits (ps, c->lits, end); -#ifdef TRACE - if (ps->trace) - fprintf (ps->out, " clause(%u)", CLS2IDX (c)); -#endif - } - else - fputs ("DECISION", ps->out); -} - -static void -dumpclsnl (PS * ps, Cls * c) -{ - dumpcls (ps, c); - fputc ('\n', ps->out); -} - -void -dumpcnf (PS * ps) -{ - Cls **p, *c; - - for (p = SOC; p != EOC; p = NXC (p)) - { - c = *p; - - if (!c) - continue; - -#ifdef TRACE - if (c->collected) - continue; -#endif - - dumpclsnl (ps, *p); - } -} - -#endif - -static INLINE void -delete_prefix (PS * ps) -{ - if (!ps->prefix) - return; - - delete (ps, ps->prefix, strlen (ps->prefix) + 1); - ps->prefix = 0; -} - -static void -new_prefix (PS * ps, const char * str) -{ - delete_prefix (ps); - assert (str); - ps->prefix = new (ps, strlen (str) + 1); - strcpy (ps->prefix, str); -} - -static PS * -init (void * pmgr, - picosat_malloc pnew, picosat_realloc presize, picosat_free pdelete) -{ - PS * ps; - -#if 0 - int count = 3 - !pnew - !presize - !pdelete; - - ABORTIF (count && !pnew, "API usage: missing 'picosat_set_new'"); - ABORTIF (count && !presize, "API usage: missing 'picosat_set_resize'"); - ABORTIF (count && !pdelete, "API usage: missing 'picosat_set_delete'"); -#endif - - ps = pnew ? pnew (pmgr, sizeof *ps) : malloc (sizeof *ps); - ABORTIF (!ps, "failed to allocate memory for PicoSAT manager"); - memset (ps, 0, sizeof *ps); - - ps->emgr = pmgr; - ps->enew = pnew; - ps->eresize = presize; - ps->edelete = pdelete; - - ps->size_vars = 1; - ps->state = RESET; - ps->defaultphase = JWLPHASE; -#ifdef TRACE - ps->ocore = -1; -#endif - ps->lastrheader = -2; -#ifndef NADC - ps->adoconflictlimit = UINT_MAX; -#endif - ps->min_flipped = UINT_MAX; - - NEWN (ps->lits, 2 * ps->size_vars); - NEWN (ps->jwh, 2 * ps->size_vars); - NEWN (ps->htps, 2 * ps->size_vars); -#ifndef NDSC - NEWN (ps->dhtps, 2 * ps->size_vars); -#endif - NEWN (ps->impls, 2 * ps->size_vars); - NEWN (ps->vars, ps->size_vars); - NEWN (ps->rnks, ps->size_vars); - - /* because '0' pos denotes not on heap - */ - ENLARGE (ps->heap, ps->hhead, ps->eoh); - ps->hhead = ps->heap + 1; - - ps->vinc = base2flt (1, 0); /* initial var activity */ - ps->ifvinc = ascii2flt ("1.05"); /* var score rescore factor */ -#ifdef VISCORES - ps->fvinc = ascii2flt ("0.9523809"); /* 1/f = 1/1.05 */ - ps->nvinc = ascii2flt ("0.0476191"); /* 1 - 1/f = 1 - 1/1.05 */ -#endif - ps->lscore = base2flt (1, 90); /* var activity rescore limit */ - ps->ilvinc = base2flt (1, -90); /* inverse of 'lscore' */ - - ps->cinc = base2flt (1, 0); /* initial clause activity */ - ps->fcinc = ascii2flt ("1.001"); /* cls activity rescore factor */ - ps->lcinc = base2flt (1, 90); /* cls activity rescore limit */ - ps->ilcinc = base2flt (1, -90); /* inverse of 'ilcinc' */ - - ps->lreduceadjustcnt = ps->lreduceadjustinc = 100; - ps->lpropagations = ~0ull; - -#ifndef RCODE - ps->out = stdout; -#else - ps->out = 0; -#endif - new_prefix (ps, "c "); - ps->verbosity = 0; - ps->plain = 0; - -#ifdef NO_BINARY_CLAUSES - memset (&ps->impl, 0, sizeof (ps->impl)); - ps->impl.size = 2; - - memset (&ps->cimpl, 0, sizeof (ps->impl)); - ps->cimpl.size = 2; -#endif - -#ifdef VISCORES - ps->fviscores = popen ( - "/usr/bin/gnuplot -background black" - " -xrm 'gnuplot*textColor:white'" - " -xrm 'gnuplot*borderColor:white'" - " -xrm 'gnuplot*axisColor:white'" - , "w"); - fprintf (ps->fviscores, "unset key\n"); - // fprintf (ps->fviscores, "set log y\n"); - fflush (ps->fviscores); - system ("rm -rf /tmp/picosat-viscores"); - system ("mkdir /tmp/picosat-viscores"); - system ("mkdir /tmp/picosat-viscores/data"); -#ifdef WRITEGIF - system ("mkdir /tmp/picosat-viscores/gif"); - fprintf (ps->fviscores, - "set terminal gif giant animate opt size 1024,768 x000000 xffffff" - "\n"); - - fprintf (ps->fviscores, - "set output \"/tmp/picosat-viscores/gif/animated.gif\"\n"); -#endif -#endif - ps->defaultphase = JWLPHASE; - ps->state = READY; - ps->last_sat_call_result = 0; - - return ps; -} - -static size_t -bytes_clause (PS * ps, unsigned size, unsigned learned) -{ - size_t res; - - res = sizeof (Cls); - res += size * sizeof (Lit *); - res -= 2 * sizeof (Lit *); - - if (learned && size > 2) - res += sizeof (Act); /* add activity */ - -#ifdef TRACE - if (ps->trace) - res += sizeof (Trd); /* add trace data */ -#else - (void) ps; -#endif - - return res; -} - -static Cls * -new_clause (PS * ps, unsigned size, unsigned learned) -{ - size_t bytes; - void * tmp; -#ifdef TRACE - Trd *trd; -#endif - Cls *res; - - bytes = bytes_clause (ps, size, learned); - tmp = new (ps, bytes); - -#ifdef TRACE - if (ps->trace) - { - trd = tmp; - - if (learned) - trd->idx = LIDX2IDX (ps->lhead - ps->lclauses); - else - trd->idx = OIDX2IDX (ps->ohead - ps->oclauses); - - res = trd->cls; - } - else -#endif - res = tmp; - - res->size = size; - res->learned = learned; - - res->collect = 0; -#ifndef NDEBUG - res->connected = 0; -#endif - res->locked = 0; - res->used = 0; -#ifdef TRACE - res->core = 0; - res->collected = 0; -#endif - - if (learned && size > 2) - { - Act * p = CLS2ACT (res); - *p = ps->cinc; - } - - return res; -} - -static void -delete_clause (PS * ps, Cls * c) -{ - size_t bytes; -#ifdef TRACE - Trd *trd; -#endif - - bytes = bytes_clause (ps, c->size, c->learned); - -#ifdef TRACE - if (ps->trace) - { - trd = CLS2TRD (c); - delete (ps, trd, bytes); - } - else -#endif - delete (ps, c, bytes); -} - -static void -delete_clauses (PS * ps) -{ - Cls **p; - for (p = SOC; p != EOC; p = NXC (p)) - if (*p) - delete_clause (ps, *p); - - DELETEN (ps->oclauses, ps->eoo - ps->oclauses); - DELETEN (ps->lclauses, ps->EOL - ps->lclauses); - - ps->ohead = ps->eoo = ps->lhead = ps->EOL = 0; -} - -#ifdef TRACE - -static void -delete_zhain (PS * ps, Zhn * zhain) -{ - const Znt *p, *znt; - - assert (zhain); - - znt = zhain->znt; - for (p = znt; *p; p++) - ; - - delete (ps, zhain, sizeof (Zhn) + (p - znt) + 1); -} - -static void -delete_zhains (PS * ps) -{ - Zhn **p, *z; - for (p = ps->zhains; p < ps->zhead; p++) - if ((z = *p)) - delete_zhain (ps, z); - - DELETEN (ps->zhains, ps->eoz - ps->zhains); - ps->eoz = ps->zhead = 0; -} - -#endif - -#ifdef NO_BINARY_CLAUSES -static void -lrelease (PS * ps, Ltk * stk) -{ - if (stk->start) - DELETEN (stk->start, (1 << (stk->ldsize))); - memset (stk, 0, sizeof (*stk)); -} -#endif - -#ifndef NADC - -static INLINE unsigned -llength (Lit ** a) -{ - Lit ** p; - for (p = a; *p; p++) - ; - return p - a; -} - -static INLINE void -resetadoconflict (PS * ps) -{ - assert (ps->adoconflict); - delete_clause (ps, ps->adoconflict); - ps->adoconflict = 0; -} - -static INLINE void -reset_ados (PS * ps) -{ - Lit *** p; - - for (p = ps->ados; p < ps->hados; p++) - DELETEN (*p, llength (*p) + 1); - - DELETEN (ps->ados, ps->eados - ps->ados); - ps->hados = ps->eados = 0; - - DELETEN (ps->adotab, ps->szadotab); - ps->szadotab = ps->nadotab = 0; - - if (ps->adoconflict) - resetadoconflict (ps); - - ps->adoconflicts = 0; - ps->adoconflictlimit = UINT_MAX; - ps->adodisabled = 0; -} - -#endif - -static void -reset (PS * ps) -{ - ABORTIF (!ps || - ps->state == RESET, "API usage: reset without initialization"); - - delete_clauses (ps); -#ifdef TRACE - delete_zhains (ps); -#endif -#ifdef NO_BINARY_CLAUSES - { - unsigned i; - for (i = 2; i <= 2 * ps->max_var + 1; i++) - lrelease (ps, ps->impls + i); - } -#endif -#ifndef NADC - reset_ados (ps); -#endif -#ifndef NFL - DELETEN (ps->saved, ps->saved_size); -#endif - DELETEN (ps->htps, 2 * ps->size_vars); -#ifndef NDSC - DELETEN (ps->dhtps, 2 * ps->size_vars); -#endif - DELETEN (ps->impls, 2 * ps->size_vars); - DELETEN (ps->lits, 2 * ps->size_vars); - DELETEN (ps->jwh, 2 * ps->size_vars); - DELETEN (ps->vars, ps->size_vars); - DELETEN (ps->rnks, ps->size_vars); - DELETEN (ps->trail, ps->eot - ps->trail); - DELETEN (ps->heap, ps->eoh - ps->heap); - DELETEN (ps->als, ps->eoals - ps->als); - DELETEN (ps->CLS, ps->eocls - ps->CLS); - DELETEN (ps->rils, ps->eorils - ps->rils); - DELETEN (ps->cils, ps->eocils - ps->cils); - DELETEN (ps->fals, ps->eofals - ps->fals); - DELETEN (ps->mass, ps->szmass); - DELETEN (ps->mssass, ps->szmssass); - DELETEN (ps->mcsass, ps->szmcsass); - DELETEN (ps->humus, ps->szhumus); - DELETEN (ps->added, ps->eoa - ps->added); - DELETEN (ps->marked, ps->eom - ps->marked); - DELETEN (ps->dfs, ps->eod - ps->dfs); - DELETEN (ps->resolved, ps->eor - ps->resolved); - DELETEN (ps->levels, ps->eolevels - ps->levels); - DELETEN (ps->dused, ps->eodused - ps->dused); - DELETEN (ps->buffer, ps->eob - ps->buffer); - DELETEN (ps->indices, ps->eoi - ps->indices); - DELETEN (ps->soclauses, ps->eoso - ps->soclauses); - delete_prefix (ps); - delete (ps, ps->rline[0], ps->szrline); - delete (ps, ps->rline[1], ps->szrline); - assert (getenv ("LEAK") || !ps->current_bytes); /* found leak if failing */ -#ifdef VISCORES - pclose (ps->fviscores); -#endif - if (ps->edelete) - ps->edelete (ps->emgr, ps, sizeof *ps); - else - free (ps); -} - -inline static void -tpush (PS * ps, Lit * lit) -{ - assert (ps->lits < lit && lit <= ps->lits + 2* ps->max_var + 1); - if (ps->thead == ps->eot) - { - unsigned ttail2count = ps->ttail2 - ps->trail; - unsigned ttailcount = ps->ttail - ps->trail; -#ifndef NADC - unsigned ttailadocount = ps->ttailado - ps->trail; -#endif - ENLARGE (ps->trail, ps->thead, ps->eot); - ps->ttail = ps->trail + ttailcount; - ps->ttail2 = ps->trail + ttail2count; -#ifndef NADC - ps->ttailado = ps->trail + ttailadocount; -#endif - } - - *ps->thead++ = lit; -} - -static INLINE void -assign_reason (PS * ps, Var * v, Cls * reason) -{ -#if defined(NO_BINARY_CLAUSES) && !defined(NDEBUG) - assert (reason != &ps->impl); -#else - (void) ps; -#endif - v->reason = reason; -} - -static void -assign_phase (PS * ps, Lit * lit) -{ - unsigned new_phase, idx; - Var * v = LIT2VAR (lit); - -#ifndef NFL - /* In 'simplifying' mode we only need to keep 'min_flipped' up to date if - * we force assignments on the top level. The other assignments will be - * undone and thus we can keep the old saved value of the phase. - */ - if (!ps->LEVEL || !ps->simplifying) -#endif - { - new_phase = (LIT2SGN (lit) > 0); - - if (v->assigned) - { - ps->sdflips -= ps->sdflips/FFLIPPED; - - if (new_phase != v->phase) - { - assert (FFLIPPEDPREC >= FFLIPPED); - ps->sdflips += FFLIPPEDPREC / FFLIPPED; - ps->flips++; - - idx = LIT2IDX (lit); - if (idx < ps->min_flipped) - ps->min_flipped = idx; - - NOLOG (fprintf (ps->out, - "%sflipped %d\n", - ps->prefix, LIT2INT (lit))); - } - } - - v->phase = new_phase; - v->assigned = 1; - } - - lit->val = TRUE; - NOTLIT (lit)->val = FALSE; -} - -inline static void -assign (PS * ps, Lit * lit, Cls * reason) -{ - Var * v = LIT2VAR (lit); - assert (lit->val == UNDEF); -#ifdef STATS - ps->assignments++; -#endif - v->level = ps->LEVEL; - assign_phase (ps, lit); - assign_reason (ps, v, reason); - tpush (ps, lit); -} - -inline static int -cmp_added (PS * ps, Lit * k, Lit * l) -{ - Val a = k->val, b = l->val; - Var *u, *v; - int res; - - if (a == UNDEF && b != UNDEF) - return -1; - - if (a != UNDEF && b == UNDEF) - return 1; - - u = LIT2VAR (k); - v = LIT2VAR (l); - - if (a != UNDEF) - { - assert (b != UNDEF); - res = v->level - u->level; - if (res) - return res; /* larger level first */ - } - - res = cmpflt (VAR2RNK (u)->score, VAR2RNK (v)->score); - if (res) - return res; /* smaller activity first */ - - return u - v; /* smaller index first */ -} - -static INLINE void -sorttwolits (Lit ** v) -{ - Lit * a = v[0], * b = v[1]; - - assert (a != b); - - if (a < b) - return; - - v[0] = b; - v[1] = a; -} - -inline static void -sortlits (PS * ps, Lit ** v, unsigned size) -{ - if (size == 2) - sorttwolits (v); /* same order with and with out 'NO_BINARY_CLAUSES' */ - else - SORT (Lit *, cmp_added, v, size); -} - -#ifdef NO_BINARY_CLAUSES -static INLINE Cls * -setimpl (PS * ps, Lit * a, Lit * b) -{ - assert (!ps->implvalid); - assert (ps->impl.size == 2); - - ps->impl.lits[0] = a; - ps->impl.lits[1] = b; - - sorttwolits (ps->impl.lits); - ps->implvalid = 1; - - return &ps->impl; -} - -static INLINE void -resetimpl (PS * ps) -{ - ps->implvalid = 0; -} - -static Cls * -setcimpl (PS * ps, Lit * a, Lit * b) -{ - assert (!ps->cimplvalid); - assert (ps->cimpl.size == 2); - - ps->cimpl.lits[0] = a; - ps->cimpl.lits[1] = b; - - sorttwolits (ps->cimpl.lits); - ps->cimplvalid = 1; - - return &ps->cimpl; -} - -static INLINE void -resetcimpl (PS * ps) -{ - assert (ps->cimplvalid); - ps->cimplvalid = 0; -} - -#endif - -static INLINE int -cmp_ptr (PS * ps, void *l, void *k) -{ - (void) ps; - return ((char*)l) - (char*)k; /* arbitrarily already reverse */ -} - -static int -cmp_rnk (Rnk * r, Rnk * s) -{ - if (!r->moreimportant && s->moreimportant) - return -1; - - if (r->moreimportant && !s->moreimportant) - return 1; - - if (!r->lessimportant && s->lessimportant) - return 1; - - if (r->lessimportant && !s->lessimportant) - return -1; - - if (r->score < s->score) - return -1; - - if (r->score > s->score) - return 1; - - return -cmp_ptr (0, r, s); -} - -static void -hup (PS * ps, Rnk * v) -{ - int upos, vpos; - Rnk *u; - -#ifndef NFL - assert (!ps->simplifying); -#endif - - vpos = v->pos; - - assert (0 < vpos); - assert (vpos < ps->hhead - ps->heap); - assert (ps->heap[vpos] == v); - - while (vpos > 1) - { - upos = vpos / 2; - - u = ps->heap[upos]; - - if (cmp_rnk (u, v) > 0) - break; - - ps->heap[vpos] = u; - u->pos = vpos; - - vpos = upos; - } - - ps->heap[vpos] = v; - v->pos = vpos; -} - -static Cls *add_simplified_clause (PS *, int); - -inline static void -add_antecedent (PS * ps, Cls * c) -{ - assert (c); - -#ifdef NO_BINARY_CLAUSES - if (ISLITREASON (c)) - return; - - if (c == &ps->impl) - return; -#elif defined(STATS) && defined(TRACE) - ps->antecedents++; -#endif - if (ps->rhead == ps->eor) - ENLARGE (ps->resolved, ps->rhead, ps->eor); - - assert (ps->rhead < ps->eor); - *ps->rhead++ = c; -} - -#ifdef TRACE - -#ifdef NO_BINARY_CLAUSES -#error "can not combine TRACE and NO_BINARY_CLAUSES" -#endif - -#endif /* TRACE */ - -static INLINE void -add_lit (PS * ps, Lit * lit) -{ - assert (lit); - - if (ps->ahead == ps->eoa) - ENLARGE (ps->added, ps->ahead, ps->eoa); - - *ps->ahead++ = lit; -} - -static INLINE void -push_var_as_marked (PS * ps, Var * v) -{ - if (ps->mhead == ps->eom) - ENLARGE (ps->marked, ps->mhead, ps->eom); - - *ps->mhead++ = v; -} - -static INLINE void -mark_var (PS * ps, Var * v) -{ - assert (!v->mark); - v->mark = 1; - push_var_as_marked (ps, v); -} - -#ifdef NO_BINARY_CLAUSES - -static Cls * -impl2reason (PS * ps, Lit * lit) -{ - Lit * other; - Cls * res; - other = ps->impl.lits[0]; - if (lit == other) - other = ps->impl.lits[1]; - assert (other->val == FALSE); - res = LIT2REASON (NOTLIT (other)); - resetimpl (ps); - return res; -} - -#endif - -/* Whenever we have a top level derived unit we really should derive a unit - * clause otherwise the resolutions in 'add_simplified_clause' become - * incorrect. - */ -static Cls * -resolve_top_level_unit (PS * ps, Lit * lit, Cls * reason) -{ - unsigned count_resolved; - Lit **p, **eol, *other; - Var *u, *v; - - assert (ps->rhead == ps->resolved); - assert (ps->ahead == ps->added); - - add_lit (ps, lit); - add_antecedent (ps, reason); - count_resolved = 1; - v = LIT2VAR (lit); - - eol = end_of_lits (reason); - for (p = reason->lits; p < eol; p++) - { - other = *p; - u = LIT2VAR (other); - if (u == v) - continue; - - add_antecedent (ps, u->reason); - count_resolved++; - } - - /* Some of the literals could be assumptions. If at least one - * variable is not an assumption, we should resolve. - */ - if (count_resolved >= 2) - { -#ifdef NO_BINARY_CLAUSES - if (reason == &ps->impl) - resetimpl (ps); -#endif - reason = add_simplified_clause (ps, 1); -#ifdef NO_BINARY_CLAUSES - if (reason->size == 2) - { - assert (reason == &ps->impl); - reason = impl2reason (ps, lit); - } -#endif - assign_reason (ps, v, reason); - } - else - { - ps->ahead = ps->added; - ps->rhead = ps->resolved; - } - - return reason; -} - -static void -fixvar (PS * ps, Var * v) -{ - Rnk * r; - - assert (VAR2LIT (v) != UNDEF); - assert (!v->level); - - ps->fixed++; - - r = VAR2RNK (v); - r->score = INFFLT; - -#ifndef NFL - if (ps->simplifying) - return; -#endif - - if (!r->pos) - return; - - hup (ps, r); -} - -static INLINE void -use_var (PS * ps, Var * v) -{ - if (v->used) - return; - - v->used = 1; - ps->vused++; -} - -static void -assign_forced (PS * ps, Lit * lit, Cls * reason) -{ - Var *v; - - assert (reason); - assert (lit->val == UNDEF); - -#ifdef STATS - ps->FORCED++; -#endif - assign (ps, lit, reason); - -#ifdef NO_BINARY_CLAUSES - assert (reason != &ps->impl); - if (ISLITREASON (reason)) - { - reason = setimpl (ps, lit, NOTLIT (REASON2LIT (reason))); - assert (reason); - } -#endif - LOG ( fprintf (ps->out, - "%sassign %d at level %d by ", - ps->prefix, LIT2INT (lit), ps->LEVEL); - dumpclsnl (ps, reason)); - - v = LIT2VAR (lit); - if (!ps->LEVEL) - use_var (ps, v); - - if (!ps->LEVEL && reason->size > 1) - { - reason = resolve_top_level_unit (ps, lit, reason); - assert (reason); - } - -#ifdef NO_BINARY_CLAUSES - if (ISLITREASON (reason) || reason == &ps->impl) - { - /* DO NOTHING */ - } - else -#endif - { - assert (!reason->locked); - reason->locked = 1; - if (reason->learned && reason->size > 2) - ps->llocked++; - } - -#ifdef NO_BINARY_CLAUSES - if (reason == &ps->impl) - resetimpl (ps); -#endif - - if (!ps->LEVEL) - fixvar (ps, v); -} - -#ifdef NO_BINARY_CLAUSES - -static void -lpush (PS * ps, Lit * lit, Cls * c) -{ - int pos = (c->lits[0] == lit); - Ltk * s = LIT2IMPLS (lit); - unsigned oldsize, newsize; - - assert (c->size == 2); - - if (!s->start) - { - assert (!s->count); - assert (!s->ldsize); - NEWN (s->start, 1); - } - else - { - oldsize = (1 << (s->ldsize)); - assert (s->count <= oldsize); - if (s->count == oldsize) - { - newsize = 2 * oldsize; - RESIZEN (s->start, oldsize, newsize); - s->ldsize++; - } - } - - s->start[s->count++] = c->lits[pos]; -} - -#endif - -static void -connect_head_tail (PS * ps, Lit * lit, Cls * c) -{ - Cls ** s; - assert (c->size >= 1); - if (c->size == 2) - { -#ifdef NO_BINARY_CLAUSES - lpush (ps, lit, c); - return; -#else - s = LIT2IMPLS (lit); -#endif - } - else - s = LIT2HTPS (lit); - - if (c->lits[0] != lit) - { - assert (c->size >= 2); - assert (c->lits[1] == lit); - c->next[1] = *s; - } - else - c->next[0] = *s; - - *s = c; -} - -#ifdef TRACE -static void -zpush (PS * ps, Zhn * zhain) -{ - assert (ps->trace); - - if (ps->zhead == ps->eoz) - ENLARGE (ps->zhains, ps->zhead, ps->eoz); - - *ps->zhead++ = zhain; -} - -static INLINE int -cmp_resolved (PS * ps, Cls * c, Cls * d) -{ -#ifndef NDEBUG - assert (ps->trace); -#else - (void) ps; -#endif - return CLS2IDX (c) - CLS2IDX (d); -} - -static INLINE void -bpushc (PS * ps, unsigned char ch) -{ - if (ps->bhead == ps->eob) - ENLARGE (ps->buffer, ps->bhead, ps->eob); - - *ps->bhead++ = ch; -} - -static INLINE void -bpushu (PS * ps, unsigned u) -{ - while (u & ~0x7f) - { - bpushc (ps, u | 0x80); - u >>= 7; - } - - bpushc (ps, u); -} - -static INLINE void -bpushd (PS * ps, unsigned prev, unsigned this) -{ - unsigned delta; - assert (prev < this); - delta = this - prev; - bpushu (ps, delta); -} - -static void -add_zhain (PS * ps) -{ - unsigned prev, this, count, rcount; - Cls **p, *c; - Zhn *res; - - assert (ps->trace); - assert (ps->bhead == ps->buffer); - assert (ps->rhead > ps->resolved); - - rcount = ps->rhead - ps->resolved; - SORT (Cls *, cmp_resolved, ps->resolved, rcount); - - prev = 0; - for (p = ps->resolved; p < ps->rhead; p++) - { - c = *p; - this = CLS2TRD (c)->idx; - bpushd (ps, prev, this); - prev = this; - } - bpushc (ps, 0); - - count = ps->bhead - ps->buffer; - - res = new (ps, sizeof (Zhn) + count); - res->core = 0; - res->ref = 0; - memcpy (res->znt, ps->buffer, count); - - ps->bhead = ps->buffer; -#ifdef STATS - ps->znts += count - 1; -#endif - zpush (ps, res); -} - -#endif - -static void -add_resolved (PS * ps, int learned) -{ -#if defined(STATS) || defined(TRACE) - Cls **p, *c; - - for (p = ps->resolved; p < ps->rhead; p++) - { - c = *p; - if (c->used) - continue; - - c->used = 1; - - if (c->size <= 2) - continue; - -#ifdef STATS - if (c->learned) - ps->llused++; - else - ps->loused++; -#endif - } -#endif - -#ifdef TRACE - if (learned && ps->trace) - add_zhain (ps); -#else - (void) learned; -#endif - ps->rhead = ps->resolved; -} - -static void -incjwh (PS * ps, Cls * c) -{ - Lit **p, *lit, ** eol; - Flt * f, inc, sum; - unsigned size = 0; - Var * v; - Val val; - - eol = end_of_lits (c); - - for (p = c->lits; p < eol; p++) - { - lit = *p; - val = lit->val; - - if (val && ps->LEVEL > 0) - { - v = LIT2VAR (lit); - if (v->level > 0) - val = UNDEF; - } - - if (val == TRUE) - return; - - if (val != FALSE) - size++; - } - - inc = base2flt (1, -size); - - for (p = c->lits; p < eol; p++) - { - lit = *p; - f = LIT2JWH (lit); - sum = addflt (*f, inc); - *f = sum; - } -} - -static void -write_rup_header (PS * ps, FILE * file) -{ - char line[80]; - int i; - - sprintf (line, "%%RUPD32 %u %u", ps->rupvariables, ps->rupclauses); - - fputs (line, file); - for (i = 255 - strlen (line); i >= 0; i--) - fputc (' ', file); - - fputc ('\n', file); - fflush (file); -} - -static Cls * -add_simplified_clause (PS * ps, int learned) -{ - unsigned num_true, num_undef, num_false, size, count_resolved; - Lit **p, **q, *lit, ** end; - unsigned litlevel, glue; - Cls *res, * reason; - int reentered; - Val val; - Var *v; -#if !defined(NDEBUG) && defined(TRACE) - unsigned idx; -#endif - - reentered = 0; - -REENTER: - - size = ps->ahead - ps->added; - - add_resolved (ps, learned); - - if (learned) - { - ps->ladded++; - ps->llitsadded += size; - if (size > 2) - { - ps->lladded++; - ps->nlclauses++; - ps->llits += size; - } - } - else - { - ps->oadded++; - if (size > 2) - { - ps->loadded++; - ps->noclauses++; - ps->olits += size; - } - } - - ps->addedclauses++; - assert (ps->addedclauses == ps->ladded + ps->oadded); - -#ifdef NO_BINARY_CLAUSES - if (size == 2) - res = setimpl (ps, ps->added[0], ps->added[1]); - else -#endif - { - sortlits (ps, ps->added, size); - - if (learned) - { - if (ps->lhead == ps->EOL) - { - ENLARGE (ps->lclauses, ps->lhead, ps->EOL); - - /* A very difficult to find bug, which only occurs if the - * learned clauses stack is immediately allocated before the - * original clauses stack without padding. In this case, we - * have 'SOC == EOC', which terminates all loops using the - * idiom 'for (p = SOC; p != EOC; p = NXC(p))' immediately. - * Unfortunately this occurred in 'fix_clause_lits' after - * using a recent version of the memory allocator of 'Google' - * perftools in the context of one large benchmark for - * our SMT solver 'Boolector'. - */ - if (ps->EOL == ps->oclauses) - ENLARGE (ps->lclauses, ps->lhead, ps->EOL); - } - -#if !defined(NDEBUG) && defined(TRACE) - idx = LIDX2IDX (ps->lhead - ps->lclauses); -#endif - } - else - { - if (ps->ohead == ps->eoo) - { - ENLARGE (ps->oclauses, ps->ohead, ps->eoo); - if (ps->EOL == ps->oclauses) - ENLARGE (ps->oclauses, ps->ohead, ps->eoo); /* ditto */ - } - -#if !defined(NDEBUG) && defined(TRACE) - idx = OIDX2IDX (ps->ohead - ps->oclauses); -#endif - } - - assert (ps->EOL != ps->oclauses); /* ditto */ - - res = new_clause (ps, size, learned); - - glue = 0; - - if (learned) - { - assert (ps->dusedhead == ps->dused); - - for (p = ps->added; p < ps->ahead; p++) - { - lit = *p; - if (lit->val) - { - litlevel = LIT2VAR (lit)->level; - assert (litlevel <= ps->LEVEL); - while (ps->levels + litlevel >= ps->levelshead) - { - if (ps->levelshead >= ps->eolevels) - ENLARGE (ps->levels, ps->levelshead, ps->eolevels); - assert (ps->levelshead < ps->eolevels); - *ps->levelshead++ = 0; - } - if (!ps->levels[litlevel]) - { - if (ps->dusedhead >= ps->eodused) - ENLARGE (ps->dused, ps->dusedhead, ps->eodused); - assert (ps->dusedhead < ps->eodused); - *ps->dusedhead++ = litlevel; - ps->levels[litlevel] = 1; - glue++; - } - } - else - glue++; - } - - while (ps->dusedhead > ps->dused) - { - litlevel = *--ps->dusedhead; - assert (ps->levels + litlevel < ps->levelshead); - assert (ps->levels[litlevel]); - ps->levels[litlevel] = 0; - } - } - - assert (glue <= MAXGLUE); - res->glue = glue; - -#if !defined(NDEBUG) && defined(TRACE) - if (ps->trace) - assert (CLS2IDX (res) == idx); -#endif - if (learned) - *ps->lhead++ = res; - else - *ps->ohead++ = res; - -#if !defined(NDEBUG) && defined(TRACE) - if (ps->trace && learned) - assert (ps->zhead - ps->zhains == ps->lhead - ps->lclauses); -#endif - assert (ps->lhead != ps->oclauses); /* ditto */ - } - - if (learned && ps->rup) - { - if (!ps->rupstarted) - { - write_rup_header (ps, ps->rup); - ps->rupstarted = 1; - } - } - - num_true = num_undef = num_false = 0; - - q = res->lits; - for (p = ps->added; p < ps->ahead; p++) - { - lit = *p; - *q++ = lit; - - if (learned && ps->rup) - fprintf (ps->rup, "%d ", LIT2INT (lit)); - - val = lit->val; - - num_true += (val == TRUE); - num_undef += (val == UNDEF); - num_false += (val == FALSE); - } - assert (num_false + num_true + num_undef == size); - - if (learned && ps->rup) - fputs ("0\n", ps->rup); - - ps->ahead = ps->added; /* reset */ - - if (!reentered) // TODO merge - if (size > 0) - { - assert (size <= 2 || !reentered); // TODO remove - connect_head_tail (ps, res->lits[0], res); - if (size > 1) - connect_head_tail (ps, res->lits[1], res); - } - - if (size == 0) - { - if (!ps->mtcls) - ps->mtcls = res; - } - -#ifdef NO_BINARY_CLAUSES - if (size != 2) -#endif -#ifndef NDEBUG - res->connected = 1; -#endif - - LOG ( fprintf (ps->out, "%s%s ", ps->prefix, learned ? "learned" : "original"); - dumpclsnl (ps, res)); - - /* Shrink clause by resolving it against top level assignments. - */ - if (!ps->LEVEL && num_false > 0) - { - assert (ps->ahead == ps->added); - assert (ps->rhead == ps->resolved); - - count_resolved = 1; - add_antecedent (ps, res); - - end = end_of_lits (res); - for (p = res->lits; p < end; p++) - { - lit = *p; - v = LIT2VAR (lit); - use_var (ps, v); - - if (lit->val == FALSE) - { - add_antecedent (ps, v->reason); - count_resolved++; - } - else - add_lit (ps, lit); - } - - assert (count_resolved >= 2); - - learned = 1; -#ifdef NO_BINARY_CLAUSES - if (res == &ps->impl) - resetimpl (ps); -#endif - reentered = 1; - goto REENTER; /* and return simplified clause */ - } - - if (!num_true && num_undef == 1) /* unit clause */ - { - lit = 0; - for (p = res->lits; p < res->lits + size; p++) - { - if ((*p)->val == UNDEF) - lit = *p; - - v = LIT2VAR (*p); - use_var (ps, v); - } - assert (lit); - - reason = res; -#ifdef NO_BINARY_CLAUSES - if (size == 2) - { - Lit * other = res->lits[0]; - if (other == lit) - other = res->lits[1]; - - assert (other->val == FALSE); - reason = LIT2REASON (NOTLIT (other)); - } -#endif - assign_forced (ps, lit, reason); - num_true++; - } - - if (num_false == size && !ps->conflict) - { -#ifdef NO_BINARY_CLAUSES - if (res == &ps->impl) - ps->conflict = setcimpl (ps, res->lits[0], res->lits[1]); - else -#endif - ps->conflict = res; - } - - if (!learned && !num_true && num_undef) - incjwh (ps, res); - -#ifdef NO_BINARY_CLAUSES - if (res == &ps->impl) - resetimpl (ps); -#endif - return res; -} - -static int -trivial_clause (PS * ps) -{ - Lit **p, **q, *prev; - Var *v; - - SORT (Lit *, cmp_ptr, ps->added, ps->ahead - ps->added); - - prev = 0; - q = ps->added; - for (p = q; p < ps->ahead; p++) - { - Lit *this = *p; - - v = LIT2VAR (this); - - if (prev == this) /* skip repeated literals */ - continue; - - /* Top level satisfied ? - */ - if (this->val == TRUE && !v->level) - return 1; - - if (prev == NOTLIT (this))/* found pair of dual literals */ - return 1; - - *q++ = prev = this; - } - - ps->ahead = q; /* shrink */ - - return 0; -} - -static void -simplify_and_add_original_clause (PS * ps) -{ -#ifdef NO_BINARY_CLAUSES - Cls * c; -#endif - if (trivial_clause (ps)) - { - ps->ahead = ps->added; - - if (ps->ohead == ps->eoo) - ENLARGE (ps->oclauses, ps->ohead, ps->eoo); - - *ps->ohead++ = 0; - - ps->addedclauses++; - ps->oadded++; - } - else - { - if (ps->CLS != ps->clshead) - add_lit (ps, NOTLIT (ps->clshead[-1])); - -#ifdef NO_BINARY_CLAUSES - c = -#endif - add_simplified_clause (ps, 0); -#ifdef NO_BINARY_CLAUSES - if (c == &ps->impl) assert (!ps->implvalid); -#endif - } -} - -#ifndef NADC - -static void -add_ado (PS * ps) -{ - unsigned len = ps->ahead - ps->added; - Lit ** ado, ** p, ** q, *lit; - Var * v, * u; - -#ifdef TRACE - assert (!ps->trace); -#endif - - ABORTIF (ps->ados < ps->hados && llength (ps->ados[0]) != len, - "internal: non matching all different constraint object lengths"); - - if (ps->hados == ps->eados) - ENLARGE (ps->ados, ps->hados, ps->eados); - - NEWN (ado, len + 1); - *ps->hados++ = ado; - - p = ps->added; - q = ado; - u = 0; - while (p < ps->ahead) - { - lit = *p++; - v = LIT2VAR (lit); - ABORTIF (v->inado, - "internal: variable in multiple all different objects"); - v->inado = ado; - if (!u && !lit->val) - u = v; - *q++ = lit; - } - - assert (q == ado + len); - *q++ = 0; - - /* TODO simply do a conflict test as in propado */ - - ABORTIF (!u, - "internal: " - "adding fully instantiated all different object not implemented yet"); - - assert (u); - assert (u->inado == ado); - assert (!u->ado); - u->ado = ado; - - ps->ahead = ps->added; -} - -#endif - -static void -hdown (PS * ps, Rnk * r) -{ - unsigned end, rpos, cpos, opos; - Rnk *child, *other; - - assert (r->pos > 0); - assert (ps->heap[r->pos] == r); - - end = ps->hhead - ps->heap; - rpos = r->pos; - - for (;;) - { - cpos = 2 * rpos; - if (cpos >= end) - break; - - opos = cpos + 1; - child = ps->heap[cpos]; - - if (cmp_rnk (r, child) < 0) - { - if (opos < end) - { - other = ps->heap[opos]; - - if (cmp_rnk (child, other) < 0) - { - child = other; - cpos = opos; - } - } - } - else if (opos < end) - { - child = ps->heap[opos]; - - if (cmp_rnk (r, child) >= 0) - break; - - cpos = opos; - } - else - break; - - ps->heap[rpos] = child; - child->pos = rpos; - rpos = cpos; - } - - r->pos = rpos; - ps->heap[rpos] = r; -} - -static Rnk * -htop (PS * ps) -{ - assert (ps->hhead > ps->heap + 1); - return ps->heap[1]; -} - -static Rnk * -hpop (PS * ps) -{ - Rnk *res, *last; - unsigned end; - - assert (ps->hhead > ps->heap + 1); - - res = ps->heap[1]; - res->pos = 0; - - end = --ps->hhead - ps->heap; - if (end == 1) - return res; - - last = ps->heap[end]; - - ps->heap[last->pos = 1] = last; - hdown (ps, last); - - return res; -} - -inline static void -hpush (PS * ps, Rnk * r) -{ - assert (!r->pos); - - if (ps->hhead == ps->eoh) - ENLARGE (ps->heap, ps->hhead, ps->eoh); - - r->pos = ps->hhead++ - ps->heap; - ps->heap[r->pos] = r; - hup (ps, r); -} - -static INLINE void -fix_trail_lits (PS * ps, long delta) -{ - Lit **p; - for (p = ps->trail; p < ps->thead; p++) - *p += delta; -} - -#ifdef NO_BINARY_CLAUSES -static void -fix_impl_lits (PS * ps, long delta) -{ - Ltk * s; - Lit ** p; - - for (s = ps->impls + 2; s <= ps->impls + 2 * ps->max_var + 1; s++) - for (p = s->start; p < s->start + s->count; p++) - *p += delta; -} -#endif - -static void -fix_clause_lits (PS * ps, long delta) -{ - Cls **p, *clause; - Lit **q, *lit, **eol; - - for (p = SOC; p != EOC; p = NXC (p)) - { - clause = *p; - if (!clause) - continue; - - q = clause->lits; - eol = end_of_lits (clause); - while (q < eol) - { - assert (q - clause->lits <= (int) clause->size); - lit = *q; - lit += delta; - *q++ = lit; - } - } -} - -static INLINE void -fix_added_lits (PS * ps, long delta) -{ - Lit **p; - for (p = ps->added; p < ps->ahead; p++) - *p += delta; -} - -static INLINE void -fix_assumed_lits (PS * ps, long delta) -{ - Lit **p; - for (p = ps->als; p < ps->alshead; p++) - *p += delta; -} - -static INLINE void -fix_cls_lits (PS * ps, long delta) -{ - Lit **p; - for (p = ps->CLS; p < ps->clshead; p++) - *p += delta; -} - -static INLINE void -fix_heap_rnks (PS * ps, long delta) -{ - Rnk **p; - - for (p = ps->heap + 1; p < ps->hhead; p++) - *p += delta; -} - -#ifndef NADC - -static INLINE void -fix_ado (long delta, Lit ** ado) -{ - Lit ** p; - for (p = ado; *p; p++) - *p += delta; -} - -static INLINE void -fix_ados (PS * ps, long delta) -{ - Lit *** p; - - for (p = ps->ados; p < ps->hados; p++) - fix_ado (delta, *p); -} - -#endif - -static void -enlarge (PS * ps, unsigned new_size_vars) -{ - long rnks_delta, lits_delta; - Lit *old_lits = ps->lits; - Rnk *old_rnks = ps->rnks; - - RESIZEN (ps->lits, 2 * ps->size_vars, 2 * new_size_vars); - RESIZEN (ps->jwh, 2 * ps->size_vars, 2 * new_size_vars); - RESIZEN (ps->htps, 2 * ps->size_vars, 2 * new_size_vars); -#ifndef NDSC - RESIZEN (ps->dhtps, 2 * ps->size_vars, 2 * new_size_vars); -#endif - RESIZEN (ps->impls, 2 * ps->size_vars, 2 * new_size_vars); - RESIZEN (ps->vars, ps->size_vars, new_size_vars); - RESIZEN (ps->rnks, ps->size_vars, new_size_vars); - - if ((lits_delta = ps->lits - old_lits)) - { - fix_trail_lits (ps, lits_delta); - fix_clause_lits (ps, lits_delta); - fix_added_lits (ps, lits_delta); - fix_assumed_lits (ps, lits_delta); - fix_cls_lits (ps, lits_delta); -#ifdef NO_BINARY_CLAUSES - fix_impl_lits (ps, lits_delta); -#endif -#ifndef NADC - fix_ados (ps, lits_delta); -#endif - } - - if ((rnks_delta = ps->rnks - old_rnks)) - { - fix_heap_rnks (ps, rnks_delta); - } - - assert (ps->mhead == ps->marked); - - ps->size_vars = new_size_vars; -} - -static void -unassign (PS * ps, Lit * lit) -{ - Cls *reason; - Var *v; - Rnk *r; - - assert (lit->val == TRUE); - - LOG ( fprintf (ps->out, "%sunassign %d\n", ps->prefix, LIT2INT (lit))); - - v = LIT2VAR (lit); - reason = v->reason; - -#ifdef NO_BINARY_CLAUSES - assert (reason != &ps->impl); - if (ISLITREASON (reason)) - { - /* DO NOTHING */ - } - else -#endif - if (reason) - { - assert (reason->locked); - reason->locked = 0; - if (reason->learned && reason->size > 2) - { - assert (ps->llocked > 0); - ps->llocked--; - } - } - - lit->val = UNDEF; - NOTLIT (lit)->val = UNDEF; - - r = VAR2RNK (v); - if (!r->pos) - hpush (ps, r); - -#ifndef NDSC - { - Cls * p, * next, ** q; - - q = LIT2DHTPS (lit); - p = *q; - *q = 0; - - while (p) - { - Lit * other = p->lits[0]; - - if (other == lit) - { - other = p->lits[1]; - q = p->next + 1; - } - else - { - assert (p->lits[1] == lit); - q = p->next; - } - - next = *q; - *q = *LIT2HTPS (other); - *LIT2HTPS (other) = p; - p = next; - } - } -#endif - -#ifndef NADC - if (v->adotabpos) - { - assert (ps->nadotab); - assert (*v->adotabpos == v->ado); - - *v->adotabpos = 0; - v->adotabpos = 0; - - ps->nadotab--; - } -#endif -} - -static Cls * -var2reason (PS * ps, Var * var) -{ - Cls * res = var->reason; -#ifdef NO_BINARY_CLAUSES - Lit * this, * other; - if (ISLITREASON (res)) - { - this = VAR2LIT (var); - if (this->val == FALSE) - this = NOTLIT (this); - - other = REASON2LIT (res); - assert (other->val == TRUE); - assert (this->val == TRUE); - res = setimpl (ps, NOTLIT (other), this); - } -#else - (void) ps; -#endif - return res; -} - -static INLINE void -mark_clause_to_be_collected (Cls * c) -{ - assert (!c->collect); - c->collect = 1; -} - -static void -undo (PS * ps, unsigned new_level) -{ - Lit *lit; - Var *v; - - while (ps->thead > ps->trail) - { - lit = *--ps->thead; - v = LIT2VAR (lit); - if (v->level == new_level) - { - ps->thead++; /* fix pre decrement */ - break; - } - - unassign (ps, lit); - } - - ps->LEVEL = new_level; - ps->ttail = ps->thead; - ps->ttail2 = ps->thead; -#ifndef NADC - ps->ttailado = ps->thead; -#endif - -#ifdef NO_BINARY_CLAUSES - if (ps->conflict == &ps->cimpl) - resetcimpl (ps); -#endif -#ifndef NADC - if (ps->conflict && ps->conflict == ps->adoconflict) - resetadoconflict (ps); -#endif - ps->conflict = ps->mtcls; - if (ps->LEVEL < ps->adecidelevel) - { - assert (ps->als < ps->alshead); - ps->adecidelevel = 0; - ps->alstail = ps->als; - } - LOG ( fprintf (ps->out, "%sback to level %u\n", ps->prefix, ps->LEVEL)); -} - -#ifndef NDEBUG - -static int -clause_satisfied (Cls * c) -{ - Lit **p, **eol, *lit; - - eol = end_of_lits (c); - for (p = c->lits; p < eol; p++) - { - lit = *p; - if (lit->val == TRUE) - return 1; - } - - return 0; -} - -static void -original_clauses_satisfied (PS * ps) -{ - Cls **p, *c; - - for (p = ps->oclauses; p < ps->ohead; p++) - { - c = *p; - - if (!c) - continue; - - if (c->learned) - continue; - - assert (clause_satisfied (c)); - } -} - -static void -assumptions_satisfied (PS * ps) -{ - Lit *lit, ** p; - - for (p = ps->als; p < ps->alshead; p++) - { - lit = *p; - assert (lit->val == TRUE); - } -} - -#endif - -static void -sflush (PS * ps) -{ -#ifdef HAS_FLOAT - double now = picosat_time_stamp (); - double delta = now - ps->entered; - delta = (delta < 0) ? 0 : delta; - ps->seconds += delta; - ps->entered = now; -#endif -} - -static double -mb (PS * ps) -{ - return ps->current_bytes / (double) (1 << 20); -} - -static INLINE double -avglevel (PS * ps) -{ - return ps->decisions ? ps->levelsum / ps->decisions : 0.0; -} - -static void -rheader (PS * ps) -{ - assert (ps->lastrheader <= ps->reports); - - if (ps->lastrheader == ps->reports) - return; - - ps->lastrheader = ps->reports; - - fprintf (ps->out, "%s\n", ps->prefix); - fprintf (ps->out, "%s %s\n", ps->prefix, ps->rline[0]); - fprintf (ps->out, "%s %s\n", ps->prefix, ps->rline[1]); - fprintf (ps->out, "%s\n", ps->prefix); -} - -static unsigned -dynamic_flips_per_assignment_per_mille (PS * ps) -{ - assert (FFLIPPEDPREC >= 1000); - return ps->sdflips / (FFLIPPEDPREC / 1000); -} - -#ifdef NLUBY - -static int -high_agility (PS * ps) -{ - return dynamic_flips_per_assignment_per_mille (ps) >= 200; -} - -static int -very_high_agility (PS * ps) -{ - return dynamic_flips_per_assignment_per_mille (ps) >= 250; -} - -#else - -static int -medium_agility (PS * ps) -{ - return dynamic_flips_per_assignment_per_mille (ps) >= 230; -} - -#endif - -static void -relemdata (PS * ps) -{ - char *p; - int x; - - if (ps->reports < 0) - { - /* strip trailing white space - */ - for (x = 0; x <= 1; x++) - { - p = ps->rline[x] + strlen (ps->rline[x]); - while (p-- > ps->rline[x]) - { - if (*p != ' ') - break; - - *p = 0; - } - } - - rheader (ps); - } - else - fputc ('\n', ps->out); - - ps->RCOUNT = 0; -} - -static void -relemhead (PS * ps, const char * name, int fp, double val) -{ - int x, y, len, size; - const char *fmt; - unsigned tmp, e; - - if (ps->reports < 0) - { - x = ps->RCOUNT & 1; - y = (ps->RCOUNT / 2) * 12 + x * 6; - - if (ps->RCOUNT == 1) - sprintf (ps->rline[1], "%6s", ""); - - len = strlen (name); - while (ps->szrline <= len + y + 1) - { - size = ps->szrline ? 2 * ps->szrline : 128; - ps->rline[0] = resize (ps, ps->rline[0], ps->szrline, size); - ps->rline[1] = resize (ps, ps->rline[1], ps->szrline, size); - ps->szrline = size; - } - - fmt = (len <= 6) ? "%6s%10s" : "%-10s%4s"; - sprintf (ps->rline[x] + y, fmt, name, ""); - } - else if (val < 0) - { - assert (fp); - - if (val > -100 && (tmp = val * 10.0 - 0.5) > -1000.0) - { - fprintf (ps->out, "-%4.1f ", -tmp / 10.0); - } - else - { - tmp = -val / 10.0 + 0.5; - e = 1; - while (tmp >= 100) - { - tmp /= 10; - e++; - } - - fprintf (ps->out, "-%2ue%u ", tmp, e); - } - } - else - { - if (fp && val < 1000 && (tmp = val * 10.0 + 0.5) < 10000) - { - fprintf (ps->out, "%5.1f ", tmp / 10.0); - } - else if (!fp && (tmp = val) < 100000) - { - fprintf (ps->out, "%5u ", tmp); - } - else - { - tmp = val / 10.0 + 0.5; - e = 1; - - while (tmp >= 1000) - { - tmp /= 10; - e++; - } - - fprintf (ps->out, "%3ue%u ", tmp, e); - } - } - - ps->RCOUNT++; -} - -inline static void -relem (PS * ps, const char *name, int fp, double val) -{ - if (name) - relemhead (ps, name, fp, val); - else - relemdata (ps); -} - -static unsigned -reduce_limit_on_lclauses (PS * ps) -{ - unsigned res = ps->lreduce; - res += ps->llocked; - return res; -} - -static void -report (PS * ps, int replevel, char type) -{ - int rounds; - -#ifdef RCODE - (void) type; -#endif - - if (ps->verbosity < replevel) - return; - - sflush (ps); - - if (!ps->reports) - ps->reports = -1; - - for (rounds = (ps->reports < 0) ? 2 : 1; rounds; rounds--) - { - if (ps->reports >= 0) - fprintf (ps->out, "%s%c ", ps->prefix, type); -#ifdef DMONNIAUX_DISABLE - - relem (ps, "seconds", 1, ps->seconds); - relem (ps, "level", 1, avglevel (ps)); - assert (ps->fixed <= ps->max_var); - relem (ps, "variables", 0, ps->max_var - ps->fixed); - relem (ps, "used", 1, PERCENT (ps->vused, ps->max_var)); - relem (ps, "original", 0, ps->noclauses); - relem (ps, "conflicts", 0, ps->conflicts); - // relem (ps, "decisions", 0, ps->decisions); - // relem (ps, "conf/dec", 1, PERCENT(ps->conflicts,ps->decisions)); - // relem (ps, "limit", 0, reduce_limit_on_lclauses (ps)); - relem (ps, "learned", 0, ps->nlclauses); - // relem (ps, "limit", 1, PERCENT (ps->nlclauses, reduce_limit_on_lclauses (ps))); - relem (ps, "limit", 0, ps->lreduce); -#ifdef STATS - relem (ps, "learning", 1, PERCENT (ps->llused, ps->lladded)); -#endif - relem (ps, "agility", 1, dynamic_flips_per_assignment_per_mille (ps) / 10.0); - // relem (ps, "original", 0, ps->noclauses); - relem (ps, "MB", 1, mb (ps)); - // relem (ps, "lladded", 0, ps->lladded); - // relem (ps, "llused", 0, ps->llused); - - relem (ps, 0, 0, 0); -#endif - - ps->reports++; - } - - /* Adapt this to the number of rows in your terminal. - */ - #define ROWS 25 - - if (INT_MOD(ps->reports, (ROWS - 3)) == (ROWS - 4)) - rheader (ps); - - fflush (ps->out); -} - -static int -bcp_queue_is_empty (PS * ps) -{ - if (ps->ttail != ps->thead) - return 0; - - if (ps->ttail2 != ps->thead) - return 0; - -#ifndef NADC - if (ps->ttailado != ps->thead) - return 0; -#endif - - return 1; -} - -static int -satisfied (PS * ps) -{ - assert (!ps->mtcls); - assert (!ps->failed_assumption); - if (ps->alstail < ps->alshead) - return 0; - assert (!ps->conflict); - assert (bcp_queue_is_empty (ps)); - return ps->thead == ps->trail + ps->max_var; /* all assigned */ -} - -static void -vrescore (PS * ps) -{ - Rnk *p, *eor = ps->rnks + ps->max_var; - for (p = ps->rnks + 1; p <= eor; p++) - if (p->score != INFFLT) - p->score = mulflt (p->score, ps->ilvinc); - ps->vinc = mulflt (ps->vinc, ps->ilvinc);; -#ifdef VISCORES - ps->nvinc = mulflt (ps->nvinc, ps->lscore);; -#endif -} - -static void -inc_score (PS * ps, Var * v) -{ - Flt score; - Rnk *r; - -#ifndef NFL - if (ps->simplifying) - return; -#endif - - if (!v->level) - return; - - if (v->internal) - return; - - r = VAR2RNK (v); - score = r->score; - - assert (score != INFFLT); - - score = addflt (score, ps->vinc); - assert (score < INFFLT); - r->score = score; - if (r->pos > 0) - hup (ps, r); - - if (score > ps->lscore) - vrescore (ps); -} - -static void -inc_activity (PS * ps, Cls * c) -{ - Act *p; - - if (!c->learned) - return; - - if (c->size <= 2) - return; - - p = CLS2ACT (c); - *p = addflt (*p, ps->cinc); -} - -static INLINE unsigned -hashlevel (unsigned l) -{ - return 1u << (l & 31); -} - -static INLINE void -push (PS * ps, Var * v) -{ - if (ps->dhead == ps->eod) - ENLARGE (ps->dfs, ps->dhead, ps->eod); - - *ps->dhead++ = v; -} - -static INLINE Var * -pop (PS * ps) -{ - assert (ps->dfs < ps->dhead); - return *--ps->dhead; -} - -static void -analyze (PS * ps) -{ - unsigned open, minlevel, siglevels, l, old, i, orig; - Lit *this, *other, **p, **q, **eol; - Var *v, *u, **m, *start, *uip; - Cls *c; - - assert (ps->conflict); - - assert (ps->ahead == ps->added); - assert (ps->mhead == ps->marked); - assert (ps->rhead == ps->resolved); - - /* First, search for First UIP variable and mark all resolved variables. - * At the same time determine the minimum decision level involved. - * Increase activities of resolved variables. - */ - q = ps->thead; - open = 0; - minlevel = ps->LEVEL; - siglevels = 0; - uip = 0; - - c = ps->conflict; - - for (;;) - { - add_antecedent (ps, c); - inc_activity (ps, c); - eol = end_of_lits (c); - for (p = c->lits; p < eol; p++) - { - other = *p; - - if (other->val == TRUE) - continue; - - assert (other->val == FALSE); - - u = LIT2VAR (other); - if (u->mark) - continue; - - u->mark = 1; - inc_score (ps, u); - use_var (ps, u); - - if (u->level == ps->LEVEL) - { - open++; - } - else - { - push_var_as_marked (ps, u); - - if (u->level) - { - /* The statistics counter 'nonminimizedllits' sums up the - * number of literals that would be added if only the - * 'first UIP' scheme for learned clauses would be used - * and no clause minimization. - */ - ps->nonminimizedllits++; - - if (u->level < minlevel) - minlevel = u->level; - - siglevels |= hashlevel (u->level); - } - else - { - assert (!u->level); - assert (u->reason); - } - } - } - - do - { - if (q == ps->trail) - { - uip = 0; - goto DONE_FIRST_UIP; - } - - this = *--q; - uip = LIT2VAR (this); - } - while (!uip->mark); - - uip->mark = 0; - - c = var2reason (ps, uip); -#ifdef NO_BINARY_CLAUSES - if (c == &ps->impl) - resetimpl (ps); -#endif - open--; - if ((!open && ps->LEVEL) || !c) - break; - - assert (c); - } - -DONE_FIRST_UIP: - - if (uip) - { - assert (ps->LEVEL); - this = VAR2LIT (uip); - this += (this->val == TRUE); - ps->nonminimizedllits++; - ps->minimizedllits++; - add_lit (ps, this); -#ifdef STATS - if (uip->reason) - ps->uips++; -#endif - } - else - assert (!ps->LEVEL); - - /* Second, try to mark more intermediate variables, with the goal to - * minimize the conflict clause. This is a DFS from already marked - * variables backward through the implication graph. It tries to reach - * other marked variables. If the search reaches an unmarked decision - * variable or a variable assigned below the minimum level of variables in - * the first uip learned clause or a level on which no variable has been - * marked, then the variable from which the DFS is started is not - * redundant. Otherwise the start variable is redundant and will - * eventually be removed from the learned clause in step 4. We initially - * implemented BFS, but then profiling revelead that this step is a bottle - * neck for certain incremental applications. After switching to DFS this - * hot spot went away. - */ - orig = ps->mhead - ps->marked; - for (i = 0; i < orig; i++) - { - start = ps->marked[i]; - - assert (start->mark); - assert (start != uip); - assert (start->level < ps->LEVEL); - - if (!start->reason) - continue; - - old = ps->mhead - ps->marked; - assert (ps->dhead == ps->dfs); - push (ps, start); - - while (ps->dhead > ps->dfs) - { - u = pop (ps); - assert (u->mark); - - c = var2reason (ps, u); -#ifdef NO_BINARY_CLAUSES - if (c == &ps->impl) - resetimpl (ps); -#endif - if (!c || - ((l = u->level) && - (l < minlevel || ((hashlevel (l) & ~siglevels))))) - { - while (ps->mhead > ps->marked + old) /* reset all marked */ - (*--ps->mhead)->mark = 0; - - ps->dhead = ps->dfs; /* and DFS stack */ - break; - } - - eol = end_of_lits (c); - for (p = c->lits; p < eol; p++) - { - v = LIT2VAR (*p); - if (v->mark) - continue; - - mark_var (ps, v); - push (ps, v); - } - } - } - - for (m = ps->marked; m < ps->mhead; m++) - { - v = *m; - - assert (v->mark); - assert (!v->resolved); - - use_var (ps, v); - - c = var2reason (ps, v); - if (!c) - continue; - -#ifdef NO_BINARY_CLAUSES - if (c == &ps->impl) - resetimpl (ps); -#endif - eol = end_of_lits (c); - for (p = c->lits; p < eol; p++) - { - other = *p; - - u = LIT2VAR (other); - if (!u->level) - continue; - - if (!u->mark) /* 'MARKTEST' */ - break; - } - - if (p != eol) - continue; - - add_antecedent (ps, c); - v->resolved = 1; - } - - for (m = ps->marked; m < ps->mhead; m++) - { - v = *m; - - assert (v->mark); - v->mark = 0; - - if (v->resolved) - { - v->resolved = 0; - continue; - } - - this = VAR2LIT (v); - if (this->val == TRUE) - this++; /* actually NOTLIT */ - - add_lit (ps, this); - ps->minimizedllits++; - } - - assert (ps->ahead <= ps->eoa); - assert (ps->rhead <= ps->eor); - - ps->mhead = ps->marked; -} - -static void -fanalyze (PS * ps) -{ - Lit ** eol, ** p, * lit; - Cls * c, * reason; - Var * v, * u; - int next; - -#ifndef RCODE - double start = picosat_time_stamp (); -#endif - - assert (ps->failed_assumption); - assert (ps->failed_assumption->val == FALSE); - - v = LIT2VAR (ps->failed_assumption); - reason = var2reason (ps, v); - if (!reason) return; -#ifdef NO_BINARY_CLAUSES - if (reason == &ps->impl) - resetimpl (ps); -#endif - - eol = end_of_lits (reason); - for (p = reason->lits; p != eol; p++) - { - lit = *p; - u = LIT2VAR (lit); - if (u == v) continue; - if (u->reason) break; - } - if (p == eol) return; - - assert (ps->ahead == ps->added); - assert (ps->mhead == ps->marked); - assert (ps->rhead == ps->resolved); - - next = 0; - mark_var (ps, v); - add_lit (ps, NOTLIT (ps->failed_assumption)); - - do - { - v = ps->marked[next++]; - use_var (ps, v); - if (v->reason) - { - reason = var2reason (ps, v); -#ifdef NO_BINARY_CLAUSES - if (reason == &ps->impl) - resetimpl (ps); -#endif - add_antecedent (ps, reason); - eol = end_of_lits (reason); - for (p = reason->lits; p != eol; p++) - { - lit = *p; - u = LIT2VAR (lit); - if (u == v) continue; - if (u->mark) continue; - mark_var (ps, u); - } - } - else - { - lit = VAR2LIT (v); - if (lit->val == TRUE) lit = NOTLIT (lit); - add_lit (ps, lit); - } - } - while (ps->marked + next < ps->mhead); - - c = add_simplified_clause (ps, 1); - v = LIT2VAR (ps->failed_assumption); - reason = v->reason; -#ifdef NO_BINARY_CLAUSES - if (!ISLITREASON (reason)) -#endif - { - assert (reason->locked); - reason->locked = 0; - if (reason->learned && reason->size > 2) - { - assert (ps->llocked > 0); - ps->llocked--; - } - } - -#ifdef NO_BINARY_CLAUSES - if (c == &ps->impl) - { - c = impl2reason (ps, NOTLIT (ps->failed_assumption)); - } - else -#endif - { - assert (c->learned); - assert (!c->locked); - c->locked = 1; - if (c->size > 2) - { - ps->llocked++; - assert (ps->llocked > 0); - } - } - - v->reason = c; - - while (ps->mhead > ps->marked) - (*--ps->mhead)->mark = 0; - - if (ps->verbosity) - fprintf (ps->out, "%sfanalyze took %.1f seconds\n", - ps->prefix, picosat_time_stamp () - start); -} - -/* Propagate assignment of 'this' to 'FALSE' by visiting all binary clauses in - * which 'this' occurs. - */ -inline static void -prop2 (PS * ps, Lit * this) -{ -#ifdef NO_BINARY_CLAUSES - Lit ** l, ** start; - Ltk * lstk; -#else - Cls * c, ** p; - Cls * next; -#endif - Lit * other; - Val tmp; - - assert (this->val == FALSE); - -#ifdef NO_BINARY_CLAUSES - lstk = LIT2IMPLS (this); - start = lstk->start; - l = start + lstk->count; - while (l != start) - { - /* The counter 'visits' is the number of clauses that are - * visited during propagations of assignments. - */ - ps->visits++; -#ifdef STATS - ps->bvisits++; -#endif - other = *--l; - tmp = other->val; - - if (tmp == TRUE) - { -#ifdef STATS - ps->othertrue++; - ps->othertrue2++; - if (LIT2VAR (other)->level < ps->LEVEL) - ps->othertrue2u++; -#endif - continue; - } - - if (tmp != FALSE) - { - assign_forced (ps, other, LIT2REASON (NOTLIT(this))); - continue; - } - - if (ps->conflict == &ps->cimpl) - resetcimpl (ps); - ps->conflict = setcimpl (ps, this, other); - } -#else - /* Traverse all binary clauses with 'this'. Head/Tail pointers for binary - * clauses do not have to be modified here. - */ - p = LIT2IMPLS (this); - for (c = *p; c; c = next) - { - ps->visits++; -#ifdef STATS - ps->bvisits++; -#endif - assert (!c->collect); -#ifdef TRACE - assert (!c->collected); -#endif - assert (c->size == 2); - - other = c->lits[0]; - if (other == this) - { - next = c->next[0]; - other = c->lits[1]; - } - else - next = c->next[1]; - - tmp = other->val; - - if (tmp == TRUE) - { -#ifdef STATS - ps->othertrue++; - ps->othertrue2++; - if (LIT2VAR (other)->level < ps->LEVEL) - ps->othertrue2u++; -#endif - continue; - } - - if (tmp == FALSE) - ps->conflict = c; - else - assign_forced (ps, other, c); /* unit clause */ - } -#endif /* !defined(NO_BINARY_CLAUSES) */ -} - -#ifndef NDSC -static int -should_disconnect_head_tail (PS * ps, Lit * lit) -{ - unsigned litlevel; - Var * v; - - assert (lit->val == TRUE); - - v = LIT2VAR (lit); - litlevel = v->level; - - if (!litlevel) - return 1; - -#ifndef NFL - if (ps->simplifying) - return 0; -#endif - - return litlevel < ps->LEVEL; -} -#endif - -inline static void -propl (PS * ps, Lit * this) -{ - Lit **l, *other, *prev, *new_lit, **eol; - Cls *next, **htp_ptr, **new_htp_ptr; - Cls *c; -#ifdef STATS - unsigned size; -#endif - - htp_ptr = LIT2HTPS (this); - assert (this->val == FALSE); - - /* Traverse all non binary clauses with 'this'. Head/Tail pointers are - * updated as well. - */ - for (c = *htp_ptr; c; c = next) - { - ps->visits++; -#ifdef STATS - size = c->size; - assert (size >= 3); - ps->traversals++; /* other is dereferenced at least */ - - if (size == 3) - ps->tvisits++; - else if (size >= 4) - { - ps->lvisits++; - ps->ltraversals++; - } -#endif -#ifdef TRACE - assert (!c->collected); -#endif - assert (c->size > 0); - - other = c->lits[0]; - if (other != this) - { - assert (c->size != 1); - c->lits[0] = this; - c->lits[1] = other; - next = c->next[1]; - c->next[1] = c->next[0]; - c->next[0] = next; - } - else if (c->size == 1) /* With assumptions we need to - * traverse unit clauses as well. - */ - { - assert (!ps->conflict); - ps->conflict = c; - break; - } - else - { - assert (other == this && c->size > 1); - other = c->lits[1]; - next = c->next[0]; - } - assert (other == c->lits[1]); - assert (this == c->lits[0]); - assert (next == c->next[0]); - assert (!c->collect); - - if (other->val == TRUE) - { -#ifdef STATS - ps->othertrue++; - ps->othertruel++; -#endif -#ifndef NDSC - if (should_disconnect_head_tail (ps, other)) - { - new_htp_ptr = LIT2DHTPS (other); - c->next[0] = *new_htp_ptr; - *new_htp_ptr = c; -#ifdef STATS - ps->othertruelu++; -#endif - *htp_ptr = next; - continue; - } -#endif - htp_ptr = c->next; - continue; - } - - l = c->lits + 1; - eol = (Lit**) c->lits + c->size; - prev = this; - - while (++l != eol) - { -#ifdef STATS - if (size >= 3) - { - ps->traversals++; - if (size > 3) - ps->ltraversals++; - } -#endif - new_lit = *l; - *l = prev; - prev = new_lit; - if (new_lit->val != FALSE) break; - } - - if (l == eol) - { - while (l > c->lits + 2) - { - new_lit = *--l; - *l = prev; - prev = new_lit; - } - assert (c->lits[0] == this); - - assert (other == c->lits[1]); - if (other->val == FALSE) /* found conflict */ - { - assert (!ps->conflict); - ps->conflict = c; - return; - } - - assign_forced (ps, other, c); /* unit clause */ - htp_ptr = c->next; - } - else - { - assert (new_lit->val == TRUE || new_lit->val == UNDEF); - c->lits[0] = new_lit; - // *l = this; - new_htp_ptr = LIT2HTPS (new_lit); - c->next[0] = *new_htp_ptr; - *new_htp_ptr = c; - *htp_ptr = next; - } - } -} - -#ifndef NADC - -static unsigned primes[] = { 996293, 330643, 753947, 500873 }; - -#define PRIMES ((sizeof primes)/sizeof *primes) - -static unsigned -hash_ado (PS * ps, Lit ** ado, unsigned salt) -{ - unsigned i, res, tmp; - Lit ** p, * lit; - - assert (salt < PRIMES); - - i = salt; - res = 0; - - for (p = ado; (lit = *p); p++) - { - assert (lit->val); - - tmp = res >> 31; - res <<= 1; - - if (lit->val > 0) - res |= 1; - - assert (i < PRIMES); - res *= primes[i++]; - if (i == PRIMES) - i = 0; - - res += tmp; - } - - return res & (ps->szadotab - 1); -} - -static unsigned -cmp_ado (Lit ** a, Lit ** b) -{ - Lit ** p, ** q, * l, * k; - int res; - - for (p = a, q = b; (l = *p); p++, q++) - { - k = *q; - assert (k); - if ((res = (l->val - k->val))) - return res; - } - - assert (!*q); - - return 0; -} - -static Lit *** -find_ado (PS * ps, Lit ** ado) -{ - Lit *** res, ** other; - unsigned pos, delta; - - pos = hash_ado (ps, ado, 0); - assert (pos < ps->szadotab); - res = ps->adotab + pos; - - other = *res; - if (!other || !cmp_ado (other, ado)) - return res; - - delta = hash_ado (ps, ado, 1); - if (!(delta & 1)) - delta++; - - assert (delta & 1); - assert (delta < ps->szadotab); - - for (;;) - { - pos += delta; - if (pos >= ps->szadotab) - pos -= ps->szadotab; - - assert (pos < ps->szadotab); - res = ps->adotab + pos; - other = *res; - if (!other || !cmp_ado (other, ado)) - return res; - } -} - -static void -enlarge_adotab (PS * ps) -{ - /* TODO make this generic */ - - ABORTIF (ps->szadotab, - "internal: all different objects table needs larger initial size"); - assert (!ps->nadotab); - ps->szadotab = 10000; - NEWN (ps->adotab, ps->szadotab); - CLRN (ps->adotab, ps->szadotab); -} - -static int -propado (PS * ps, Var * v) -{ - Lit ** p, ** q, *** adotabpos, **ado, * lit; - Var * u; - - if (ps->LEVEL && ps->adodisabled) - return 1; - - assert (!ps->conflict); - assert (!ps->adoconflict); - assert (VAR2LIT (v)->val != UNDEF); - assert (!v->adotabpos); - - if (!v->ado) - return 1; - - assert (v->inado); - - for (p = v->ado; (lit = *p); p++) - if (lit->val == UNDEF) - { - u = LIT2VAR (lit); - assert (!u->ado); - u->ado = v->ado; - v->ado = 0; - - return 1; - } - - if (4 * ps->nadotab >= 3 * ps->szadotab) /* at least 75% filled */ - enlarge_adotab (ps); - - adotabpos = find_ado (ps, v->ado); - ado = *adotabpos; - - if (!ado) - { - ps->nadotab++; - v->adotabpos = adotabpos; - *adotabpos = v->ado; - return 1; - } - - assert (ado != v->ado); - - ps->adoconflict = new_clause (ps, 2 * llength (ado), 1); - q = ps->adoconflict->lits; - - for (p = ado; (lit = *p); p++) - *q++ = lit->val == FALSE ? lit : NOTLIT (lit); - - for (p = v->ado; (lit = *p); p++) - *q++ = lit->val == FALSE ? lit : NOTLIT (lit); - - assert (q == ENDOFCLS (ps->adoconflict)); - ps->conflict = ps->adoconflict; - ps->adoconflicts++; - return 0; -} - -#endif - -static void -bcp (PS * ps) -{ - int props = 0; - assert (!ps->conflict); - - if (ps->mtcls) - return; - - for (;;) - { - if (ps->ttail2 < ps->thead) /* prioritize implications */ - { - props++; - prop2 (ps, NOTLIT (*ps->ttail2++)); - } - else if (ps->ttail < ps->thead) /* unit clauses or clauses with length > 2 */ - { - if (ps->conflict) break; - propl (ps, NOTLIT (*ps->ttail++)); - if (ps->conflict) break; - } -#ifndef NADC - else if (ps->ttailado < ps->thead) - { - if (ps->conflict) break; - propado (ps, LIT2VAR (*ps->ttailado++)); - if (ps->conflict) break; - } -#endif - else - break; /* all assignments propagated, so break */ - } - - ps->propagations += props; -} - -static unsigned -drive (PS * ps) -{ - unsigned res, vlevel; - Lit **p; - Var *v; - - res = 0; - for (p = ps->added; p < ps->ahead; p++) - { - v = LIT2VAR (*p); - vlevel = v->level; - assert (vlevel <= ps->LEVEL); - if (vlevel < ps->LEVEL && vlevel > res) - res = vlevel; - } - - return res; -} - -#ifdef VISCORES - -static void -viscores (PS * ps) -{ - Rnk *p, *eor = ps->rnks + ps->max_var; - char name[100], cmd[200]; - FILE * data; - Flt s; - int i; - - for (p = ps->rnks + 1; p <= ps->eor; p++) - { - s = p->score; - if (s == INFFLT) - continue; - s = mulflt (s, ps->nvinc); - assert (flt2double (s) <= 1.0); - } - - sprintf (name, "/tmp/picosat-viscores/data/%08u", ps->conflicts); - sprintf (cmd, "sort -n|nl>%s", name); - - data = popen (cmd, "w"); - for (p = ps->rnks + 1; p <= ps->eor; p++) - { - s = p->score; - if (s == INFFLT) - continue; - s = mulflt (s, ps->nvinc); - fprintf (data, "%lf %d\n", 100.0 * flt2double (s), (int)(p - ps->rnks)); - } - fflush (data); - pclose (data); - - for (i = 0; i < 8; i++) - { - sprintf (cmd, "awk '$3%%8==%d' %s>%s.%d", i, name, name, i); - system (cmd); - } - - fprintf (ps->fviscores, "set title \"%u\"\n", ps->conflicts); - fprintf (ps->fviscores, "plot [0:%u] 0, 100 * (1 - 1/1.1), 100", ps->max_var); - - for (i = 0; i < 8; i++) - fprintf (ps->fviscores, - ", \"%s.%d\" using 1:2:3 with labels tc lt %d", - name, i, i + 1); - - fputc ('\n', ps->fviscores); - fflush (ps->fviscores); -#ifndef WRITEGIF - usleep (50000); /* refresh rate of 20 Hz */ -#endif -} - -#endif - -static void -crescore (PS * ps) -{ - Cls **p, *c; - Act *a; - Flt factor; - int l = log2flt (ps->cinc); - assert (l > 0); - factor = base2flt (1, -l); - - for (p = ps->lclauses; p != ps->lhead; p++) - { - c = *p; - - if (!c) - continue; - -#ifdef TRACE - if (c->collected) - continue; -#endif - assert (c->learned); - - if (c->size <= 2) - continue; - - a = CLS2ACT (c); - *a = mulflt (*a, factor); - } - - ps->cinc = mulflt (ps->cinc, factor); -} - -static void -inc_vinc (PS * ps) -{ -#ifdef VISCORES - ps->nvinc = mulflt (ps->nvinc, ps->fvinc); -#endif - ps->vinc = mulflt (ps->vinc, ps->ifvinc); -} - -inline static void -inc_max_var (PS * ps) -{ - Lit *lit; - Rnk *r; - Var *v; - - assert (ps->max_var < ps->size_vars); - - if (ps->max_var + 1 == ps->size_vars) - enlarge (ps, ps->size_vars + 2*(ps->size_vars + 3) / 4); /* +25% */ - - ps->max_var++; /* new index of variable */ - assert (ps->max_var); /* no unsigned overflow */ - - assert (ps->max_var < ps->size_vars); - - lit = ps->lits + 2 * ps->max_var; - lit[0].val = lit[1].val = UNDEF; - - memset (ps->htps + 2 * ps->max_var, 0, 2 * sizeof *ps->htps); -#ifndef NDSC - memset (ps->dhtps + 2 * ps->max_var, 0, 2 * sizeof *ps->dhtps); -#endif - memset (ps->impls + 2 * ps->max_var, 0, 2 * sizeof *ps->impls); - memset (ps->jwh + 2 * ps->max_var, 0, 2 * sizeof *ps->jwh); - - v = ps->vars + ps->max_var; /* initialize variable components */ - CLR (v); - - r = ps->rnks + ps->max_var; /* initialize rank */ - CLR (r); - - hpush (ps, r); -} - -static void -force (PS * ps, Cls * c) -{ - Lit ** p, ** eol, * lit, * forced; - Cls * reason; - - forced = 0; - reason = c; - - eol = end_of_lits (c); - for (p = c->lits; p < eol; p++) - { - lit = *p; - if (lit->val == UNDEF) - { - assert (!forced); - forced = lit; -#ifdef NO_BINARY_CLAUSES - if (c == &ps->impl) - reason = LIT2REASON (NOTLIT (p[p == c->lits ? 1 : -1])); -#endif - } - else - assert (lit->val == FALSE); - } - -#ifdef NO_BINARY_CLAUSES - if (c == &ps->impl) - resetimpl (ps); -#endif - if (!forced) - return; - - assign_forced (ps, forced, reason); -} - -static INLINE void -inc_lreduce (PS * ps) -{ -#ifdef STATS - ps->inclreduces++; -#endif - ps->lreduce *= FREDUCE; - ps->lreduce /= 100; - report (ps, 1, '+'); -} - -static void -backtrack (PS * ps) -{ - unsigned new_level; - Cls * c; - - ps->conflicts++; - LOG ( fprintf (ps->out, "%sconflict ", ps->prefix); dumpclsnl (ps, ps->conflict)); - - analyze (ps); - new_level = drive (ps); - // TODO: why not? assert (new_level != 1 || (ps->ahead - ps->added) == 2); - c = add_simplified_clause (ps, 1); - undo (ps, new_level); - force (ps, c); - - if ( -#ifndef NFL - !ps->simplifying && -#endif - !--ps->lreduceadjustcnt) - { - /* With FREDUCE==110 and FREDADJ=121 we stir 'lreduce' to be - * proportional to 'sqrt(conflicts)'. In earlier version we actually - * used 'FREDADJ=150', which results in 'lreduce' to approximate - * 'conflicts^(log(1.1)/log(1.5))' which is close to the fourth root - * of 'conflicts', since log(1.1)/log(1.5)=0.235 (as observed by - * Donald Knuth). The square root is the same we get by a Glucose - * style increase, which simply adds a constant at every reduction. - * This would be way simpler to implement but for now we keep the more - * complicated code using the adjust increments and counters. - */ - ps->lreduceadjustinc *= FREDADJ; ps->lreduceadjustinc /= 100; ps->lreduceadjustcnt - = ps->lreduceadjustinc; - inc_lreduce (ps); - } - - if (ps->verbosity >= 4 && !(INT_MOD(ps->conflicts, 1000))) - report (ps, 4, 'C'); -} - -static void -inc_cinc (PS * ps) -{ - ps->cinc = mulflt (ps->cinc, ps->fcinc); - if (ps->lcinc < ps->cinc) - crescore (ps); -} - -static void -incincs (PS * ps) -{ - inc_vinc (ps); - inc_cinc (ps); -#ifdef VISCORES - viscores (ps); -#endif -} - -static void -disconnect_clause (PS * ps, Cls * c) -{ - assert (c->connected); - - if (c->size > 2) - { - if (c->learned) - { - assert (ps->nlclauses > 0); - ps->nlclauses--; - - assert (ps->llits >= c->size); - ps->llits -= c->size; - } - else - { - assert (ps->noclauses > 0); - ps->noclauses--; - - assert (ps->olits >= c->size); - ps->olits -= c->size; - } - } - -#ifndef NDEBUG - c->connected = 0; -#endif -} - -static int -clause_is_toplevel_satisfied (PS * ps, Cls * c) -{ - Lit *lit, **p, **eol = end_of_lits (c); - Var *v; - - for (p = c->lits; p < eol; p++) - { - lit = *p; - if (lit->val == TRUE) - { - v = LIT2VAR (lit); - if (!v->level) - return 1; - } - } - - return 0; -} - -static int -collect_clause (PS * ps, Cls * c) -{ - assert (c->collect); - c->collect = 0; - -#ifdef TRACE - assert (!c->collected); - c->collected = 1; -#endif - disconnect_clause (ps, c); - -#ifdef TRACE - if (ps->trace && (!c->learned || c->used)) - return 0; -#endif - delete_clause (ps, c); - - return 1; -} - -static size_t -collect_clauses (PS * ps) -{ - Cls *c, **p, **q, * next; - Lit * lit, * eol; - size_t res; - int i; - - res = ps->current_bytes; - - eol = ps->lits + 2 * ps->max_var + 1; - for (lit = ps->lits + 2; lit <= eol; lit++) - { - for (i = 0; i <= 1; i++) - { - if (i) - { -#ifdef NO_BINARY_CLAUSES - Ltk * lstk = LIT2IMPLS (lit); - Lit ** r, ** s; - r = lstk->start; - if (lit->val != TRUE || LIT2VAR (lit)->level) - for (s = r; s < lstk->start + lstk->count; s++) - { - Lit * other = *s; - Var *v = LIT2VAR (other); - if (v->level || - other->val != TRUE) - *r++ = other; - } - lstk->count = r - lstk->start; - continue; -#else - p = LIT2IMPLS (lit); -#endif - } - else - p = LIT2HTPS (lit); - - for (c = *p; c; c = next) - { - q = c->next; - if (c->lits[0] != lit) - q++; - - next = *q; - if (c->collect) - *p = next; - else - p = q; - } - } - } - -#ifndef NDSC - for (lit = ps->lits + 2; lit <= eol; lit++) - { - p = LIT2DHTPS (lit); - while ((c = *p)) - { - Lit * other = c->lits[0]; - if (other == lit) - { - q = c->next + 1; - } - else - { - assert (c->lits[1] == lit); - q = c->next; - } - - if (c->collect) - *p = *q; - else - p = q; - } - } -#endif - - for (p = SOC; p != EOC; p = NXC (p)) - { - c = *p; - - if (!c) - continue; - - if (!c->collect) - continue; - - if (collect_clause (ps, c)) - *p = 0; - } - -#ifdef TRACE - if (!ps->trace) -#endif - { - q = ps->oclauses; - for (p = q; p < ps->ohead; p++) - if ((c = *p)) - *q++ = c; - ps->ohead = q; - - q = ps->lclauses; - for (p = q; p < ps->lhead; p++) - if ((c = *p)) - *q++ = c; - ps->lhead = q; - } - - assert (ps->current_bytes <= res); - res -= ps->current_bytes; - ps->recycled += res; - - LOG ( fprintf (ps->out, "%scollected %ld bytes\n", ps->prefix, (long)res)); - - return res; -} - -static INLINE int -need_to_reduce (PS * ps) -{ - return ps->nlclauses >= reduce_limit_on_lclauses (ps); -} - -#ifdef NLUBY - -static void -inc_drestart (PS * ps) -{ - ps->drestart *= FRESTART; - ps->drestart /= 100; - - if (ps->drestart >= MAXRESTART) - ps->drestart = MAXRESTART; -} - -static void -inc_ddrestart (PS * ps) -{ - ps->ddrestart *= FRESTART; - ps->ddrestart /= 100; - - if (ps->ddrestart >= MAXRESTART) - ps->ddrestart = MAXRESTART; -} - -#else - -static unsigned -luby (unsigned i) -{ - unsigned k; - for (k = 1; k < 32; k++) - if (i == (1u << k) - 1) - return 1u << (k - 1); - - for (k = 1;; k++) - if ((1u << (k - 1)) <= i && i < (1u << k) - 1) - return luby (i - (1u << (k-1)) + 1); -} - -#endif - -#ifndef NLUBY -static void -inc_lrestart (PS * ps, int skip) -{ - unsigned delta; - - delta = 100 * luby (++ps->lubycnt); - ps->lrestart = ps->conflicts + delta; - - if (ps->waslubymaxdelta) - report (ps, 1, skip ? 'N' : 'R'); - else - report (ps, 2, skip ? 'n' : 'r'); - - if (delta > ps->lubymaxdelta) - { - ps->lubymaxdelta = delta; - ps->waslubymaxdelta = 1; - } - else - ps->waslubymaxdelta = 0; -} -#endif - -static void -init_restart (PS * ps) -{ -#ifdef NLUBY - /* TODO: why is it better in incremental usage to have smaller initial - * outer restart interval? - */ - ps->ddrestart = ps->calls > 1 ? MINRESTART : 1000; - ps->drestart = MINRESTART; - ps->lrestart = ps->conflicts + ps->drestart; -#else - ps->lubycnt = 0; - ps->lubymaxdelta = 0; - ps->waslubymaxdelta = 0; - inc_lrestart (ps, 0); -#endif -} - -static void -restart (PS * ps) -{ - int skip; -#ifdef NLUBY - char kind; - int outer; - - inc_drestart (ps); - outer = (ps->drestart >= ps->ddrestart); - - if (outer) - skip = very_high_agility (ps); - else - skip = high_agility (ps); -#else - skip = medium_agility (ps); -#endif - -#ifdef STATS - if (skip) - ps->skippedrestarts++; -#endif - - assert (ps->conflicts >= ps->lrestart); - - if (!skip) - { - ps->restarts++; - assert (ps->LEVEL > 1); - LOG ( fprintf (ps->out, "%srestart %u\n", ps->prefix, ps->restarts)); - undo (ps, 0); - } - -#ifdef NLUBY - if (outer) - { - kind = skip ? 'N' : 'R'; - inc_ddrestart (ps); - ps->drestart = MINRESTART; - } - else if (skip) - { - kind = 'n'; - } - else - { - kind = 'r'; - } - - assert (ps->drestart <= MAXRESTART); - ps->lrestart = ps->conflicts + ps->drestart; - assert (ps->lrestart > ps->conflicts); - - report (outer ? 1 : 2, kind); -#else - inc_lrestart (ps, skip); -#endif -} - -inline static void -assign_decision (PS * ps, Lit * lit) -{ - assert (!ps->conflict); - - ps->LEVEL++; - - LOG ( fprintf (ps->out, "%snew level %u\n", ps->prefix, ps->LEVEL)); - LOG ( fprintf (ps->out, - "%sassign %d at level %d <= DECISION\n", - ps->prefix, LIT2INT (lit), ps->LEVEL)); - - assign (ps, lit, 0); -} - -#ifndef NFL - -static INLINE int -lit_has_binary_clauses (PS * ps, Lit * lit) -{ -#ifdef NO_BINARY_CLAUSES - Ltk* lstk = LIT2IMPLS (lit); - return lstk->count != 0; -#else - return *LIT2IMPLS (lit) != 0; -#endif -} - -static void -flbcp (PS * ps) -{ -#ifdef STATS - unsigned long long propagaions_before_bcp = ps->propagations; -#endif - bcp (ps); -#ifdef STATS - ps->flprops += ps->propagations - propagaions_before_bcp; -#endif -} - -inline static int -cmp_inverse_rnk (PS * ps, Rnk * a, Rnk * b) -{ - (void) ps; - return -cmp_rnk (a, b); -} - -inline static Flt -rnk2jwh (PS * ps, Rnk * r) -{ - Flt res, sum, pjwh, njwh; - Lit * plit, * nlit; - - plit = RNK2LIT (r); - nlit = plit + 1; - - pjwh = *LIT2JWH (plit); - njwh = *LIT2JWH (nlit); - - res = mulflt (pjwh, njwh); - - sum = addflt (pjwh, njwh); - sum = mulflt (sum, base2flt (1, -10)); - res = addflt (res, sum); - - return res; -} - -static int -cmp_inverse_jwh_rnk (PS * ps, Rnk * r, Rnk * s) -{ - Flt a = rnk2jwh (ps, r); - Flt b = rnk2jwh (ps, s); - int res = cmpflt (a, b); - - if (res) - return -res; - - return cmp_inverse_rnk (ps, r, s); -} - -static void -faillits (PS * ps) -{ - unsigned i, j, old_trail_count, common, saved_count; - unsigned new_saved_size, oldladded = ps->ladded; - unsigned long long limit, delta; - Lit * lit, * other, * pivot; - Rnk * r, ** p, ** q; - int new_trail_count; - double started; - - if (ps->plain) - return; - - if (ps->heap + 1 >= ps->hhead) - return; - - if (ps->propagations < ps->fllimit) - return; - - sflush (ps); - started = ps->seconds; - - ps->flcalls++; -#ifdef STATSA - ps->flrounds++; -#endif - delta = ps->propagations/10; - if (delta >= 100*1000*1000) delta = 100*1000*1000; - else if (delta <= 100*1000) delta = 100*1000; - - limit = ps->propagations + delta; - ps->fllimit = ps->propagations; - - assert (!ps->LEVEL); - assert (ps->simplifying); - - if (ps->flcalls <= 1) - SORT (Rnk *, cmp_inverse_jwh_rnk, ps->heap + 1, ps->hhead - (ps->heap + 1)); - else - SORT (Rnk *, cmp_inverse_rnk, ps->heap + 1, ps->hhead - (ps->heap + 1)); - - i = 1; /* NOTE: heap starts at position '1' */ - - while (ps->propagations < limit) - { - if (ps->heap + i == ps->hhead) - { - if (ps->ladded == oldladded) - break; - - i = 1; -#ifdef STATS - ps->flrounds++; -#endif - oldladded = ps->ladded; - } - - assert (ps->heap + i < ps->hhead); - - r = ps->heap[i++]; - lit = RNK2LIT (r); - - if (lit->val) - continue; - - if (!lit_has_binary_clauses (ps, NOTLIT (lit))) - { -#ifdef STATS - ps->flskipped++; -#endif - continue; - } - -#ifdef STATS - ps->fltried++; -#endif - LOG ( fprintf (ps->out, "%strying %d as failed literal\n", - ps->prefix, LIT2INT (lit))); - - assign_decision (ps, lit); - old_trail_count = ps->thead - ps->trail; - flbcp (ps); - - if (ps->conflict) - { -EXPLICITLY_FAILED_LITERAL: - LOG ( fprintf (ps->out, "%sfound explicitly failed literal %d\n", - ps->prefix, LIT2INT (lit))); - - ps->failedlits++; - ps->efailedlits++; - - backtrack (ps); - flbcp (ps); - - if (!ps->conflict) - continue; - -CONTRADICTION: - assert (!ps->LEVEL); - backtrack (ps); - assert (ps->mtcls); - - goto RETURN; - } - - if (ps->propagations >= limit) - { - undo (ps, 0); - break; - } - - lit = NOTLIT (lit); - - if (!lit_has_binary_clauses (ps, NOTLIT (lit))) - { -#ifdef STATS - ps->flskipped++; -#endif - undo (ps, 0); - continue; - } - -#ifdef STATS - ps->fltried++; -#endif - LOG ( fprintf (ps->out, "%strying %d as failed literals\n", - ps->prefix, LIT2INT (lit))); - - new_trail_count = ps->thead - ps->trail; - saved_count = new_trail_count - old_trail_count; - - if (saved_count > ps->saved_size) - { - new_saved_size = ps->saved_size ? 2 * ps->saved_size : 1; - while (saved_count > new_saved_size) - new_saved_size *= 2; - - RESIZEN (ps->saved, ps->saved_size, new_saved_size); - ps->saved_size = new_saved_size; - } - - for (j = 0; j < saved_count; j++) - ps->saved[j] = ps->trail[old_trail_count + j]; - - undo (ps, 0); - - assign_decision (ps, lit); - flbcp (ps); - - if (ps->conflict) - goto EXPLICITLY_FAILED_LITERAL; - - pivot = (ps->thead - ps->trail <= new_trail_count) ? lit : NOTLIT (lit); - - common = 0; - for (j = 0; j < saved_count; j++) - if ((other = ps->saved[j])->val == TRUE) - ps->saved[common++] = other; - - undo (ps, 0); - - LOG (if (common) - fprintf (ps->out, - "%sfound %d literals implied by %d and %d\n", - ps->prefix, common, - LIT2INT (NOTLIT (lit)), LIT2INT (lit))); - -#if 1 // set to zero to disable 'lifting' - for (j = 0; - j < common - /* TODO: For some Velev benchmarks, extracting the common implicit - * failed literals took quite some time. This needs to be fixed by - * a dedicated analyzer. Up to then we bound the number of - * propagations in this loop as well. - */ - && ps->propagations < limit + delta - ; j++) - { - other = ps->saved[j]; - - if (other->val == TRUE) - continue; - - assert (!other->val); - - LOG ( fprintf (ps->out, - "%sforcing %d as forced implicitly failed literal\n", - ps->prefix, LIT2INT (other))); - - assert (pivot != NOTLIT (other)); - assert (pivot != other); - - assign_decision (ps, NOTLIT (other)); - flbcp (ps); - - assert (ps->LEVEL == 1); - - if (ps->conflict) - { - backtrack (ps); - assert (!ps->LEVEL); - } - else - { - assign_decision (ps, pivot); - flbcp (ps); - - backtrack (ps); - - if (ps->LEVEL) - { - assert (ps->LEVEL == 1); - - flbcp (ps); - - if (ps->conflict) - { - backtrack (ps); - assert (!ps->LEVEL); - } - else - { - assign_decision (ps, NOTLIT (pivot)); - flbcp (ps); - backtrack (ps); - - if (ps->LEVEL) - { - assert (ps->LEVEL == 1); - flbcp (ps); - - if (!ps->conflict) - { -#ifdef STATS - ps->floopsed++; -#endif - undo (ps, 0); - continue; - } - - backtrack (ps); - } - - assert (!ps->LEVEL); - } - - assert (!ps->LEVEL); - } - } - assert (!ps->LEVEL); - flbcp (ps); - - ps->failedlits++; - ps->ifailedlits++; - - if (ps->conflict) - goto CONTRADICTION; - } -#endif - } - - ps->fllimit += 9 * (ps->propagations - ps->fllimit); /* 10% for failed literals */ - -RETURN: - - /* First flush top level assigned literals. Those are prohibited from - * being pushed up the heap during 'faillits' since 'simplifying' is set. - */ - assert (ps->heap < ps->hhead); - for (p = q = ps->heap + 1; p < ps->hhead; p++) - { - r = *p; - lit = RNK2LIT (r); - if (lit->val) - r->pos = 0; - else - *q++ = r; - } - - /* Then resort with respect to EVSIDS score and fix positions. - */ - SORT (Rnk *, cmp_inverse_rnk, ps->heap + 1, ps->hhead - (ps->heap + 1)); - for (p = ps->heap + 1; p < ps->hhead; p++) - (*p)->pos = p - ps->heap; - - sflush (ps); - ps->flseconds += ps->seconds - started; -} - -#endif - -static void -simplify (PS * ps, int forced) -{ - Lit * lit, * notlit, ** t; - unsigned collect, delta; -#ifdef STATS - size_t bytes_collected; -#endif - int * q, ilit; - Cls **p, *c; - Var * v; - -#ifndef NDEDBUG - (void) forced; -#endif - - assert (!ps->mtcls); - assert (!satisfied (ps)); - assert (forced || ps->lsimplify <= ps->propagations); - assert (forced || ps->fsimplify <= ps->fixed); - - if (ps->LEVEL) - undo (ps, 0); -#ifndef NFL - ps->simplifying = 1; - faillits (ps); - ps->simplifying = 0; - - if (ps->mtcls) - return; -#endif - - if (ps->cils != ps->cilshead) - { - assert (ps->ttail == ps->thead); - assert (ps->ttail2 == ps->thead); - ps->ttail = ps->trail; - for (t = ps->trail; t < ps->thead; t++) - { - lit = *t; - v = LIT2VAR (lit); - if (v->internal) - { - assert (LIT2INT (lit) < 0); - assert (lit->val == TRUE); - unassign (ps, lit); - } - else - *ps->ttail++ = lit; - } - ps->ttail2 = ps->thead = ps->ttail; - - for (q = ps->cils; q != ps->cilshead; q++) - { - ilit = *q; - assert (0 < ilit && ilit <= (int) ps->max_var); - v = ps->vars + ilit; - assert (v->internal); - v->level = 0; - v->reason = 0; - lit = int2lit (ps, -ilit); - assert (lit->val == UNDEF); - lit->val = TRUE; - notlit = NOTLIT (lit); - assert (notlit->val == UNDEF); - notlit->val = FALSE; - } - } - - collect = 0; - for (p = SOC; p != EOC; p = NXC (p)) - { - c = *p; - if (!c) - continue; - -#ifdef TRACE - if (c->collected) - continue; -#endif - - if (c->locked) - continue; - - assert (!c->collect); - if (clause_is_toplevel_satisfied (ps, c)) - { - mark_clause_to_be_collected (c); - collect++; - } - } - - LOG ( fprintf (ps->out, "%scollecting %d clauses\n", ps->prefix, collect)); -#ifdef STATS - bytes_collected = -#endif - collect_clauses (ps); -#ifdef STATS - ps->srecycled += bytes_collected; -#endif - - if (ps->cils != ps->cilshead) - { - for (q = ps->cils; q != ps->cilshead; q++) - { - ilit = *q; - assert (0 < ilit && ilit <= (int) ps->max_var); - assert (ps->vars[ilit].internal); - if (ps->rilshead == ps->eorils) - ENLARGE (ps->rils, ps->rilshead, ps->eorils); - *ps->rilshead++ = ilit; - lit = int2lit (ps, -ilit); - assert (lit->val == TRUE); - lit->val = UNDEF; - notlit = NOTLIT (lit); - assert (notlit->val == FALSE); - notlit->val = UNDEF; - } - ps->cilshead = ps->cils; - } - - delta = 10 * (ps->olits + ps->llits) + 100000; - if (delta > 2000000) - delta = 2000000; - ps->lsimplify = ps->propagations + delta; - ps->fsimplify = ps->fixed; - ps->simps++; - report (ps, 1, 's'); -} - -static void -iteration (PS * ps) -{ - assert (!ps->LEVEL); - assert (bcp_queue_is_empty (ps)); - assert (ps->isimplify < ps->fixed); - - ps->iterations++; - report (ps, 2, 'i'); -#ifdef NLUBY - ps->drestart = MINRESTART; - ps->lrestart = ps->conflicts + ps->drestart; -#else - init_restart (ps); -#endif - ps->isimplify = ps->fixed; -} - -static int -cmp_glue_activity_size (PS * ps, Cls * c, Cls * d) -{ - Act a, b, * p, * q; - - (void) ps; - - assert (c->learned); - assert (d->learned); - - if (c->glue < d->glue) // smaller glue preferred - return 1; - - if (c->glue > d->glue) - return -1; - - p = CLS2ACT (c); - q = CLS2ACT (d); - a = *p; - b = *q; - - if (a < b) // then higher activity - return -1; - - if (b < a) - return 1; - - if (c->size < d->size) // then smaller size - return 1; - - if (c->size > d->size) - return -1; - - return 0; -} - -static void -reduce (PS * ps, unsigned percentage) -{ - unsigned redcount, lcollect, collect, target; -#ifdef STATS - size_t bytes_collected; -#endif - Cls **p, *c; - - assert (ps->rhead == ps->resolved); - - ps->lastreduceconflicts = ps->conflicts; - - assert (percentage <= 100); - LOG ( fprintf (ps->out, - "%sreducing %u%% learned clauses\n", - ps->prefix, percentage)); - - while (ps->nlclauses - ps->llocked > (unsigned)(ps->eor - ps->resolved)) - ENLARGE (ps->resolved, ps->rhead, ps->eor); - - collect = 0; - lcollect = 0; - - for (p = ((ps->fsimplify < ps->fixed) ? SOC : ps->lclauses); p != EOC; p = NXC (p)) - { - c = *p; - if (!c) - continue; - -#ifdef TRACE - if (c->collected) - continue; -#endif - - if (c->locked) - continue; - - assert (!c->collect); - if (ps->fsimplify < ps->fixed && clause_is_toplevel_satisfied (ps, c)) - { - mark_clause_to_be_collected (c); - collect++; - - if (c->learned && c->size > 2) - lcollect++; - - continue; - } - - if (!c->learned) - continue; - - if (c->size <= 2) - continue; - - assert (ps->rhead < ps->eor); - *ps->rhead++ = c; - } - assert (ps->rhead <= ps->eor); - - ps->fsimplify = ps->fixed; - - redcount = ps->rhead - ps->resolved; - SORT (Cls *, cmp_glue_activity_size, ps->resolved, redcount); - - assert (ps->nlclauses >= lcollect); - target = ps->nlclauses - lcollect + 1; - - target = (percentage * target + 99) / 100; - - if (target >= redcount) - target = redcount; - - ps->rhead = ps->resolved + target; - while (ps->rhead > ps->resolved) - { - c = *--ps->rhead; - mark_clause_to_be_collected (c); - - collect++; - if (c->learned && c->size > 2) /* just for consistency */ - lcollect++; - } - - if (collect) - { - ps->reductions++; -#ifdef STATS - bytes_collected = -#endif - collect_clauses (ps); -#ifdef STATS - ps->rrecycled += bytes_collected; -#endif - report (ps, 2, '-'); - } - - if (!lcollect) - inc_lreduce (ps); /* avoid dead lock */ - - assert (ps->rhead == ps->resolved); -} - -static void -init_reduce (PS * ps) -{ - // lreduce = loadded / 2; - ps->lreduce = 1000; - - if (ps->lreduce < 100) - ps->lreduce = 100; - - if (ps->verbosity) - fprintf (ps->out, - "%s\n%sinitial reduction limit %u clauses\n%s\n", - ps->prefix, ps->prefix, ps->lreduce, ps->prefix); -} - -static INLINE unsigned -rng (PS * ps) -{ - unsigned res = ps->srng; - ps->srng *= 1664525u; - ps->srng += 1013904223u; - NOLOG ( fprintf (ps->out, "%srng () = %u\n", ps->prefix, res)); - return res; -} - -static unsigned -rrng (PS * ps, unsigned low, unsigned high) -{ - unsigned long long tmp; - unsigned res, elements; - assert (low <= high); - elements = high - low + 1; - tmp = rng (ps); - tmp *= elements; - tmp >>= 32; - tmp += low; - res = tmp; - NOLOG ( fprintf (ps->out, "%srrng (ps, %u, %u) = %u\n", ps->prefix, low, high, res)); - assert (low <= res); - assert (res <= high); - return res; -} - -static Lit * -decide_phase (PS * ps, Lit * lit) -{ - Lit * not_lit = NOTLIT (lit); - Var *v = LIT2VAR (lit); - - assert (LIT2SGN (lit) > 0); - if (v->usedefphase) - { - if (v->defphase) - { - /* assign to TRUE */ - } - else - { - /* assign to FALSE */ - lit = not_lit; - } - } - else if (!v->assigned) - { -#ifdef STATS - ps->staticphasedecisions++; -#endif - if (ps->defaultphase == POSPHASE) - { - /* assign to TRUE */ - } - else if (ps->defaultphase == NEGPHASE) - { - /* assign to FALSE */ - lit = not_lit; - } - else if (ps->defaultphase == RNDPHASE) - { - /* randomly assign default phase */ - if (rrng (ps, 1, 2) != 2) - lit = not_lit; - } - else if (*LIT2JWH(lit) <= *LIT2JWH (not_lit)) - { - /* assign to FALSE (Jeroslow-Wang says there are more short - * clauses with negative occurence of this variable, so satisfy - * those, to minimize BCP) - */ - lit = not_lit; - } - else - { - /* assign to TRUE (... but strictly more positive occurrences) */ - } - } - else - { - /* repeat last phase: phase saving heuristic */ - - if (v->phase) - { - /* assign to TRUE (last phase was TRUE as well) */ - } - else - { - /* assign to FALSE (last phase was FALSE as well) */ - lit = not_lit; - } - } - - return lit; -} - -static unsigned -gcd (unsigned a, unsigned b) -{ - unsigned tmp; - - assert (a); - assert (b); - - if (a < b) - { - tmp = a; - a = b; - b = tmp; - } - - while (b) - { - assert (a >= b); - tmp = b; - b = INT_MOD(a, b); - a = tmp; - } - - return a; -} - -static Lit * -rdecide (PS * ps) -{ - unsigned idx, delta, spread; - Lit * res; - - spread = RDECIDE; - if (rrng (ps, 1, spread) != 2) - return 0; - - assert (1 <= ps->max_var); - idx = rrng (ps, 1, ps->max_var); - res = int2lit (ps, idx); - - if (res->val != UNDEF) - { - delta = rrng (ps, 1, ps->max_var); - while (gcd (delta, ps->max_var) != 1) - delta--; - - assert (1 <= delta); - assert (delta <= ps->max_var); - - do { - idx += delta; - if (idx > ps->max_var) - idx -= ps->max_var; - res = int2lit (ps, idx); - } while (res->val != UNDEF); - } - -#ifdef STATS - ps->rdecisions++; -#endif - res = decide_phase (ps, res); - LOG ( fprintf (ps->out, "%srdecide %d\n", ps->prefix, LIT2INT (res))); - - return res; -} - -static Lit * -sdecide (PS * ps) -{ - Lit *res; - Rnk *r; - - for (;;) - { - r = htop (ps); - res = RNK2LIT (r); - if (res->val == UNDEF) break; - (void) hpop (ps); - NOLOG ( fprintf (ps->out, - "%shpop %u %u %u\n", - ps->prefix, r - ps->rnks, - FLTMANTISSA(r->score), - FLTEXPONENT(r->score))); - } - -#ifdef STATS - ps->sdecisions++; -#endif - res = decide_phase (ps, res); - - LOG ( fprintf (ps->out, "%ssdecide %d\n", ps->prefix, LIT2INT (res))); - - return res; -} - -static Lit * -adecide (PS * ps) -{ - Lit *lit; - Var * v; - - assert (ps->als < ps->alshead); - assert (!ps->failed_assumption); - - while (ps->alstail < ps->alshead) - { - lit = *ps->alstail++; - - if (lit->val == FALSE) - { - ps->failed_assumption = lit; - v = LIT2VAR (lit); - - use_var (ps, v); - - LOG ( fprintf (ps->out, "%sfirst failed assumption %d\n", - ps->prefix, LIT2INT (ps->failed_assumption))); - fanalyze (ps); - return 0; - } - - if (lit->val == TRUE) - { - v = LIT2VAR (lit); - if (v->level > ps->adecidelevel) - ps->adecidelevel = v->level; - continue; - } - -#ifdef STATS - ps->assumptions++; -#endif - LOG ( fprintf (ps->out, "%sadecide %d\n", ps->prefix, LIT2INT (lit))); - ps->adecidelevel = ps->LEVEL + 1; - - return lit; - } - - return 0; -} - -static void -decide (PS * ps) -{ - Lit * lit; - - assert (!satisfied (ps)); - assert (!ps->conflict); - - if (ps->alstail < ps->alshead && (lit = adecide (ps))) - ; - else if (ps->failed_assumption) - return; - else if (satisfied (ps)) - return; - else if (!(lit = rdecide (ps))) - lit = sdecide (ps); - - assert (lit); - assign_decision (ps, lit); - - ps->levelsum += ps->LEVEL; - ps->decisions++; -} - -static int -sat (PS * ps, int l) -{ - int count = 0, backtracked; - - if (!ps->conflict) - bcp (ps); - - if (ps->conflict) - backtrack (ps); - - if (ps->mtcls) - return PICOSAT_UNSATISFIABLE; - - if (satisfied (ps)) - goto SATISFIED; - - if (ps->lsimplify <= ps->propagations) - simplify (ps, 0); - - if (ps->mtcls) - return PICOSAT_UNSATISFIABLE; - - if (satisfied (ps)) - goto SATISFIED; - - init_restart (ps); - - if (!ps->lreduce) - init_reduce (ps); - - ps->isimplify = ps->fixed; - backtracked = 0; - - for (;;) - { - if (!ps->conflict) - bcp (ps); - - if (ps->conflict) - { - incincs (ps); - backtrack (ps); - - if (ps->mtcls) - return PICOSAT_UNSATISFIABLE; - backtracked = 1; - continue; - } - - if (satisfied (ps)) - { -SATISFIED: -#ifndef NDEBUG - original_clauses_satisfied (ps); - assumptions_satisfied (ps); -#endif - return PICOSAT_SATISFIABLE; - } - - if (backtracked) - { - backtracked = 0; - if (!ps->LEVEL && ps->isimplify < ps->fixed) - iteration (ps); - } - - if (l >= 0 && count >= l) /* decision limit reached ? */ - return PICOSAT_UNKNOWN; - - if (ps->interrupt.function && /* external interrupt */ - count > 0 && !(INT_MOD(count, INTERRUPTLIM)) && - ps->interrupt.function (ps->interrupt.state)) - return PICOSAT_UNKNOWN; - - if (ps->propagations >= ps->lpropagations)/* propagation limit reached ? */ - return PICOSAT_UNKNOWN; - -#ifndef NADC - if (!ps->adodisabled && ps->adoconflicts >= ps->adoconflictlimit) - { - assert (bcp_queue_is_empty (ps)); - return PICOSAT_UNKNOWN; - } -#endif - - if (ps->fsimplify < ps->fixed && ps->lsimplify <= ps->propagations) - { - simplify (ps, 0); - if (!bcp_queue_is_empty (ps)) - continue; -#ifndef NFL - if (ps->mtcls) - return PICOSAT_UNSATISFIABLE; - - if (satisfied (ps)) - return PICOSAT_SATISFIABLE; - - assert (!ps->LEVEL); -#endif - } - - if (need_to_reduce (ps)) - reduce (ps, 50); - - if (ps->conflicts >= ps->lrestart && ps->LEVEL > 2) - restart (ps); - - decide (ps); - if (ps->failed_assumption) - return PICOSAT_UNSATISFIABLE; - count++; - } -} - -static void -rebias (PS * ps) -{ - Cls ** p, * c; - Var * v; - - for (v = ps->vars + 1; v <= ps->vars + ps->max_var; v++) - v->assigned = 0; - - memset (ps->jwh, 0, 2 * (ps->max_var + 1) * sizeof *ps->jwh); - - for (p = ps->oclauses; p < ps->ohead; p++) - { - c = *p; - - if (!c) - continue; - - if (c->learned) - continue; - - incjwh (ps, c); - } -} - -#ifdef TRACE - -static unsigned -core (PS * ps) -{ - unsigned idx, prev, this, delta, i, lcore, vcore; - unsigned *stack, *shead, *eos; - Lit **q, **eol, *lit; - Cls *c, *reason; - Znt *p, byte; - Zhn *zhain; - Var *v; - - assert (ps->trace); - - assert (ps->mtcls || ps->failed_assumption); - if (ps->ocore >= 0) - return ps->ocore; - - lcore = ps->ocore = vcore = 0; - - stack = shead = eos = 0; - ENLARGE (stack, shead, eos); - - if (ps->mtcls) - { - idx = CLS2IDX (ps->mtcls); - *shead++ = idx; - } - else - { - assert (ps->failed_assumption); - v = LIT2VAR (ps->failed_assumption); - reason = v->reason; - assert (reason); - idx = CLS2IDX (reason); - *shead++ = idx; - } - - while (shead > stack) - { - idx = *--shead; - zhain = IDX2ZHN (idx); - - if (zhain) - { - if (zhain->core) - continue; - - zhain->core = 1; - lcore++; - - c = IDX2CLS (idx); - if (c) - { - assert (!c->core); - c->core = 1; - } - - i = 0; - delta = 0; - prev = 0; - for (p = zhain->znt; (byte = *p); p++, i += 7) - { - delta |= (byte & 0x7f) << i; - if (byte & 0x80) - continue; - - this = prev + delta; - assert (prev < this); /* no overflow */ - - if (shead == eos) - ENLARGE (stack, shead, eos); - *shead++ = this; - - prev = this; - delta = 0; - i = -7; - } - } - else - { - c = IDX2CLS (idx); - - assert (c); - assert (!c->learned); - - if (c->core) - continue; - - c->core = 1; - ps->ocore++; - - eol = end_of_lits (c); - for (q = c->lits; q < eol; q++) - { - lit = *q; - v = LIT2VAR (lit); - if (v->core) - continue; - - v->core = 1; - vcore++; - - if (!ps->failed_assumption) continue; - if (lit != ps->failed_assumption) continue; - - reason = v->reason; - if (!reason) continue; - if (reason->core) continue; - - idx = CLS2IDX (reason); - if (shead == eos) - ENLARGE (stack, shead, eos); - *shead++ = idx; - } - } - } - - DELETEN (stack, eos - stack); - - if (ps->verbosity) - fprintf (ps->out, - "%s%u core variables out of %u (%.1f%%)\n" - "%s%u core original clauses out of %u (%.1f%%)\n" - "%s%u core learned clauses out of %u (%.1f%%)\n", - ps->prefix, vcore, ps->max_var, PERCENT (vcore, ps->max_var), - ps->prefix, ps->ocore, ps->oadded, PERCENT (ps->ocore, ps->oadded), - ps->prefix, lcore, ps->ladded, PERCENT (lcore, ps->ladded)); - - return ps->ocore; -} - -static void -trace_lits (PS * ps, Cls * c, FILE * file) -{ - Lit **p, **eol = end_of_lits (c); - - assert (c); - assert (c->core); - - for (p = c->lits; p < eol; p++) - fprintf (file, "%d ", LIT2INT (*p)); - - fputc ('0', file); -} - -static void -write_idx (PS * ps, unsigned idx, FILE * file) -{ - fprintf (file, "%ld", EXPORTIDX (idx)); -} - -static void -trace_clause (PS * ps, unsigned idx, Cls * c, FILE * file, int fmt) -{ - assert (c); - assert (c->core); - assert (fmt == RUP_TRACE_FMT || !c->learned); - assert (CLS2IDX (c) == idx); - - if (fmt != RUP_TRACE_FMT) - { - write_idx (ps, idx, file); - fputc (' ', file); - } - - trace_lits (ps, c, file); - - if (fmt != RUP_TRACE_FMT) - fputs (" 0", file); - - fputc ('\n', file); -} - -static void -trace_zhain (PS * ps, unsigned idx, Zhn * zhain, FILE * file, int fmt) -{ - unsigned prev, this, delta, i; - Znt *p, byte; - Cls * c; - - assert (zhain); - assert (zhain->core); - - write_idx (ps, idx, file); - fputc (' ', file); - - if (fmt == EXTENDED_TRACECHECK_TRACE_FMT) - { - c = IDX2CLS (idx); - assert (c); - trace_lits (ps, c, file); - } - else - { - assert (fmt == COMPACT_TRACECHECK_TRACE_FMT); - putc ('*', file); - } - - i = 0; - delta = 0; - prev = 0; - - for (p = zhain->znt; (byte = *p); p++, i += 7) - { - delta |= (byte & 0x7f) << i; - if (byte & 0x80) - continue; - - this = prev + delta; - - putc (' ', file); - write_idx (ps, this, file); - - prev = this; - delta = 0; - i = -7; - } - - fputs (" 0\n", file); -} - -static void -write_core (PS * ps, FILE * file) -{ - Lit **q, **eol; - Cls **p, *c; - - fprintf (file, "p cnf %u %u\n", ps->max_var, core (ps)); - - for (p = SOC; p != EOC; p = NXC (p)) - { - c = *p; - - if (!c || c->learned || !c->core) - continue; - - eol = end_of_lits (c); - for (q = c->lits; q < eol; q++) - fprintf (file, "%d ", LIT2INT (*q)); - - fputs ("0\n", file); - } -} - -#endif - -static void -write_trace (PS * ps, FILE * file, int fmt) -{ -#ifdef TRACE - Cls *c, ** p; - Zhn *zhain; - unsigned i; - - core (ps); - - if (fmt == RUP_TRACE_FMT) - { - ps->rupvariables = picosat_variables (ps), - ps->rupclauses = picosat_added_original_clauses (ps); - write_rup_header (ps, file); - } - - for (p = SOC; p != EOC; p = NXC (p)) - { - c = *p; - - if (ps->oclauses <= p && p < ps->eoo) - { - i = OIDX2IDX (p - ps->oclauses); - assert (!c || CLS2IDX (c) == i); - } - else - { - assert (ps->lclauses <= p && p < ps->EOL); - i = LIDX2IDX (p - ps->lclauses); - } - - zhain = IDX2ZHN (i); - - if (zhain) - { - if (zhain->core) - { - if (fmt == RUP_TRACE_FMT) - trace_clause (ps,i, c, file, fmt); - else - trace_zhain (ps, i, zhain, file, fmt); - } - } - else if (c) - { - if (fmt != RUP_TRACE_FMT && c) - { - if (c->core) - trace_clause (ps, i, c, file, fmt); - } - } - } -#else - (void) file; - (void) fmt; - (void) ps; -#endif -} - -static void -write_core_wrapper (PS * ps, FILE * file, int fmt) -{ - (void) fmt; -#ifdef TRACE - write_core (ps, file); -#else - (void) ps; - (void) file; -#endif -} - -static Lit * -import_lit (PS * ps, int lit, int nointernal) -{ - Lit * res; - Var * v; - - ABORTIF (lit == INT_MIN, "API usage: INT_MIN literal"); - ABORTIF (abs (lit) > (int) ps->max_var && ps->CLS != ps->clshead, - "API usage: new variable index after 'picosat_push'"); - - if (abs (lit) <= (int) ps->max_var) - { - res = int2lit (ps, lit); - v = LIT2VAR (res); - if (nointernal && v->internal) - ABORT ("API usage: trying to import invalid literal"); - else if (!nointernal && !v->internal) - ABORT ("API usage: trying to import invalid context"); - } - else - { - while (abs (lit) > (int) ps->max_var) - inc_max_var (ps); - res = int2lit (ps, lit); - } - - return res; -} - -#ifdef TRACE -static void -reset_core (PS * ps) -{ - Cls ** p, * c; - Zhn ** q, * z; - unsigned i; - - for (i = 1; i <= ps->max_var; i++) - ps->vars[i].core = 0; - - for (p = SOC; p != EOC; p = NXC (p)) - if ((c = *p)) - c->core = 0; - - for (q = ps->zhains; q != ps->zhead; q++) - if ((z = *q)) - z->core = 0; - - ps->ocore = -1; -} -#endif - -static void -reset_assumptions (PS * ps) -{ - Lit ** p; - - ps->failed_assumption = 0; - - if (ps->extracted_all_failed_assumptions) - { - for (p = ps->als; p < ps->alshead; p++) - LIT2VAR (*p)->failed = 0; - - ps->extracted_all_failed_assumptions = 0; - } - - ps->alstail = ps->alshead = ps->als; - ps->adecidelevel = 0; -} - -static INLINE void -check_ready (PS * ps) -{ - ABORTIF (!ps || ps->state == RESET, "API usage: uninitialized"); -} - -static INLINE void -check_sat_state (PS * ps) -{ - ABORTIF (ps->state != SAT, "API usage: expected to be in SAT state"); -} - -static INLINE void -check_unsat_state (PS * ps) -{ - ABORTIF (ps->state != UNSAT, "API usage: expected to be in UNSAT state"); -} - -static INLINE void -check_sat_or_unsat_or_unknown_state (PS * ps) -{ - ABORTIF (ps->state != SAT && ps->state != UNSAT && ps->state != UNKNOWN, - "API usage: expected to be in SAT, UNSAT, or UNKNOWN state"); -} - -static void -reset_partial (PS * ps) -{ - unsigned idx; - if (!ps->partial) - return; - for (idx = 1; idx <= ps->max_var; idx++) - ps->vars[idx].partial = 0; - ps->partial = 0; -} - -static void -reset_incremental_usage (PS * ps) -{ - unsigned num_non_false; - Lit * lit, ** q; - - check_sat_or_unsat_or_unknown_state (ps); - - LOG ( fprintf (ps->out, "%sRESET incremental usage\n", ps->prefix)); - - if (ps->LEVEL) - undo (ps, 0); - - reset_assumptions (ps); - - if (ps->conflict) - { - num_non_false = 0; - for (q = ps->conflict->lits; q < end_of_lits (ps->conflict); q++) - { - lit = *q; - if (lit->val != FALSE) - num_non_false++; - } - - // assert (num_non_false >= 2); // TODO: why this assertion? -#ifdef NO_BINARY_CLAUSES - if (ps->conflict == &ps->cimpl) - resetcimpl (ps); -#endif -#ifndef NADC - if (ps->conflict == ps->adoconflict) - resetadoconflict (ps); -#endif - ps->conflict = 0; - } - -#ifdef TRACE - reset_core (ps); -#endif - - reset_partial (ps); - - ps->saved_flips = ps->flips; - ps->min_flipped = UINT_MAX; - ps->saved_max_var = ps->max_var; - - ps->state = READY; -} - -static void -enter (PS * ps) -{ - if (ps->nentered++) - return; - - check_ready (ps); - ps->entered = picosat_time_stamp (); -} - -static INLINE void -leave (PS * ps) -{ - assert (ps->nentered); - if (--ps->nentered) - return; - - sflush (ps); -} - -static void -check_trace_support_and_execute (PS * ps, - FILE * file, - void (*f)(PS*,FILE*,int), int fmt) -{ - check_ready (ps); - check_unsat_state (ps); -#ifdef TRACE - ABORTIF (!ps->trace, "API usage: tracing disabled"); - enter (ps); - f (ps, file, fmt); - leave (ps); -#else - (void) file; - (void) fmt; - (void) f; - ABORT ("compiled without trace support"); -#endif -} - -static void -extract_all_failed_assumptions (PS * ps) -{ - Lit ** p, ** eol; - Var * v, * u; - int pos; - Cls * c; - - assert (!ps->extracted_all_failed_assumptions); - - assert (ps->failed_assumption); - assert (ps->mhead == ps->marked); - - if (ps->marked == ps->eom) - ENLARGE (ps->marked, ps->mhead, ps->eom); - - v = LIT2VAR (ps->failed_assumption); - mark_var (ps, v); - pos = 0; - - while (pos < ps->mhead - ps->marked) - { - v = ps->marked[pos++]; - assert (v->mark); - c = var2reason (ps, v); - if (!c) - continue; - eol = end_of_lits (c); - for (p = c->lits; p < eol; p++) - { - u = LIT2VAR (*p); - if (!u->mark) - mark_var (ps, u); - } -#ifdef NO_BINARY_CLAUSES - if (c == &ps->impl) - resetimpl (ps); -#endif - } - - for (p = ps->als; p < ps->alshead; p++) - { - u = LIT2VAR (*p); - if (!u->mark) continue; - u->failed = 1; - LOG ( fprintf (ps->out, - "%sfailed assumption %d\n", - ps->prefix, LIT2INT (*p))); - } - - while (ps->mhead > ps->marked) - (*--ps->mhead)->mark = 0; - - ps->extracted_all_failed_assumptions = 1; -} - -const char * -picosat_copyright (void) -{ - return "Copyright (c) 2006 - 2014 Armin Biere JKU Linz"; -} - -PicoSAT * -picosat_init (void) -{ - return init (0, 0, 0, 0); -} - -PicoSAT * -picosat_minit (void * pmgr, - picosat_malloc pnew, - picosat_realloc presize, - picosat_free pfree) -{ - ABORTIF (!pnew, "API usage: zero 'picosat_malloc' argument"); - ABORTIF (!presize, "API usage: zero 'picosat_realloc' argument"); - ABORTIF (!pfree, "API usage: zero 'picosat_free' argument"); - return init (pmgr, pnew, presize, pfree); -} - - -void -picosat_adjust (PS * ps, int new_max_var) -{ - unsigned new_size_vars; - - ABORTIF (abs (new_max_var) > (int) ps->max_var && ps->CLS != ps->clshead, - "API usage: adjusting variable index after 'picosat_push'"); - enter (ps); - - new_max_var = abs (new_max_var); - new_size_vars = new_max_var + 1; - - if (ps->size_vars < new_size_vars) - enlarge (ps, new_size_vars); - - while (ps->max_var < (unsigned) new_max_var) - inc_max_var (ps); - - leave (ps); -} - -int -picosat_inc_max_var (PS * ps) -{ - if (ps->measurealltimeinlib) - enter (ps); - else - check_ready (ps); - - inc_max_var (ps); - - if (ps->measurealltimeinlib) - leave (ps); - - return ps->max_var; -} - -int -picosat_context (PS * ps) -{ - return ps->clshead == ps->CLS ? 0 : LIT2INT (ps->clshead[-1]); -} - -int -picosat_push (PS * ps) -{ - int res; - Lit *lit; - Var * v; - - if (ps->measurealltimeinlib) - enter (ps); - else - check_ready (ps); - - if (ps->state != READY) - reset_incremental_usage (ps); - - if (ps->rils != ps->rilshead) - { - res = *--ps->rilshead; - assert (ps->vars[res].internal); - } - else - { - inc_max_var (ps); - res = ps->max_var; - v = ps->vars + res; - assert (!v->internal); - v->internal = 1; - ps->internals++; - LOG ( fprintf (ps->out, "%snew internal variable index %d\n", ps->prefix, res)); - } - - lit = int2lit (ps, res); - - if (ps->clshead == ps->eocls) - ENLARGE (ps->CLS, ps->clshead, ps->eocls); - *ps->clshead++ = lit; - - ps->contexts++; - - LOG ( fprintf (ps->out, "%snew context %d at depth %ld after push\n", - ps->prefix, res, (long)(ps->clshead - ps->CLS))); - - if (ps->measurealltimeinlib) - leave (ps); - - return res; -} - -int -picosat_pop (PS * ps) -{ - Lit * lit; - int res; - ABORTIF (ps->CLS == ps->clshead, "API usage: too many 'picosat_pop'"); - ABORTIF (ps->added != ps->ahead, "API usage: incomplete clause"); - - if (ps->measurealltimeinlib) - enter (ps); - else - check_ready (ps); - - if (ps->state != READY) - reset_incremental_usage (ps); - - assert (ps->CLS < ps->clshead); - lit = *--ps->clshead; - LOG ( fprintf (ps->out, "%sclosing context %d at depth %ld after pop\n", - ps->prefix, LIT2INT (lit), (long)(ps->clshead - ps->CLS) + 1)); - - if (ps->cilshead == ps->eocils) - ENLARGE (ps->cils, ps->cilshead, ps->eocils); - *ps->cilshead++ = LIT2INT (lit); - - if (ps->cilshead - ps->cils > MAXCILS) { - LOG ( fprintf (ps->out, - "%srecycling %ld interals with forced simplification\n", - ps->prefix, (long)(ps->cilshead - ps->cils))); - simplify (ps, 1); - } - - res = picosat_context (ps); - if (res) - LOG ( fprintf (ps->out, "%snew context %d at depth %ld after pop\n", - ps->prefix, res, (long)(ps->clshead - ps->CLS))); - else - LOG ( fprintf (ps->out, "%souter most context reached after pop\n", ps->prefix)); - - if (ps->measurealltimeinlib) - leave (ps); - - return res; -} - -void -picosat_set_verbosity (PS * ps, int new_verbosity_level) -{ - check_ready (ps); - ps->verbosity = new_verbosity_level; -} - -void -picosat_set_plain (PS * ps, int new_plain_value) -{ - check_ready (ps); - ps->plain = new_plain_value; -} - -int -picosat_enable_trace_generation (PS * ps) -{ - int res = 0; - check_ready (ps); -#ifdef TRACE - ABORTIF (ps->addedclauses, - "API usage: trace generation enabled after adding clauses"); - res = ps->trace = 1; -#endif - return res; -} - -void -picosat_set_incremental_rup_file (PS * ps, FILE * rup_file, int m, int n) -{ - check_ready (ps); - assert (!ps->rupstarted); - ps->rup = rup_file; - ps->rupvariables = m; - ps->rupclauses = n; -} - -void -picosat_set_output (PS * ps, FILE * output_file) -{ - check_ready (ps); - ps->out = output_file; -} - -void -picosat_measure_all_calls (PS * ps) -{ - check_ready (ps); - ps->measurealltimeinlib = 1; -} - -void -picosat_set_prefix (PS * ps, const char * str) -{ - check_ready (ps); - new_prefix (ps, str); -} - -void -picosat_set_seed (PS * ps, unsigned s) -{ - check_ready (ps); - ps->srng = s; -} - -void -picosat_reset (PS * ps) -{ - check_ready (ps); - reset (ps); -} - -int -picosat_add (PS * ps, int int_lit) -{ - int res = ps->oadded; - Lit *lit; - - if (ps->measurealltimeinlib) - enter (ps); - else - check_ready (ps); - - ABORTIF (ps->rup && ps->rupstarted && ps->oadded >= (unsigned)ps->rupclauses, - "API usage: adding too many clauses after RUP header written"); -#ifndef NADC - ABORTIF (ps->addingtoado, - "API usage: 'picosat_add' and 'picosat_add_ado_lit' mixed"); -#endif - if (ps->state != READY) - reset_incremental_usage (ps); - - if (ps->saveorig) - { - if (ps->sohead == ps->eoso) - ENLARGE (ps->soclauses, ps->sohead, ps->eoso); - - *ps->sohead++ = int_lit; - } - - if (int_lit) - { - lit = import_lit (ps, int_lit, 1); - add_lit (ps, lit); - } - else - simplify_and_add_original_clause (ps); - - if (ps->measurealltimeinlib) - leave (ps); - - return res; -} - -int -picosat_add_arg (PS * ps, ...) -{ - int lit; - va_list ap; - va_start (ap, ps); - while ((lit = va_arg (ap, int))) - (void) picosat_add (ps, lit); - va_end (ap); - return picosat_add (ps, 0); -} - -int -picosat_add_lits (PS * ps, int * lits) -{ - const int * p; - int lit; - for (p = lits; (lit = *p); p++) - (void) picosat_add (ps, lit); - return picosat_add (ps, 0); -} - -void -picosat_add_ado_lit (PS * ps, int external_lit) -{ -#ifndef NADC - Lit * internal_lit; - - if (ps->measurealltimeinlib) - enter (ps); - else - check_ready (ps); - - if (ps->state != READY) - reset_incremental_usage (ps); - - ABORTIF (!ps->addingtoado && ps->ahead > ps->added, - "API usage: 'picosat_add' and 'picosat_add_ado_lit' mixed"); - - if (external_lit) - { - ps->addingtoado = 1; - internal_lit = import_lit (ps, external_lit, 1); - add_lit (ps, internal_lit); - } - else - { - ps->addingtoado = 0; - add_ado (ps); - } - if (ps->measurealltimeinlib) - leave (ps); -#else - (void) ps; - (void) external_lit; - ABORT ("compiled without all different constraint support"); -#endif -} - -static void -assume (PS * ps, Lit * lit) -{ - if (ps->alshead == ps->eoals) - { - assert (ps->alstail == ps->als); - ENLARGE (ps->als, ps->alshead, ps->eoals); - ps->alstail = ps->als; - } - - *ps->alshead++ = lit; - LOG ( fprintf (ps->out, "%sassumption %d\n", ps->prefix, LIT2INT (lit))); -} - -static void -assume_contexts (PS * ps) -{ - Lit ** p; - if (ps->als != ps->alshead) - return; - for (p = ps->CLS; p != ps->clshead; p++) - assume (ps, *p); -} - -#ifndef RCODE -static const char * enumstr (int i) { - int last = INT_MOD(i, 10); - if (last == 1) return "st"; - if (last == 2) return "nd"; - if (last == 3) return "rd"; - return "th"; -} -#endif - -static int -tderef (PS * ps, int int_lit) -{ - Lit * lit; - Var * v; - - assert (abs (int_lit) <= (int) ps->max_var); - - lit = int2lit (ps, int_lit); - - v = LIT2VAR (lit); - if (v->level > 0) - return 0; - - if (lit->val == TRUE) - return 1; - - if (lit->val == FALSE) - return -1; - - return 0; -} - -static int -pderef (PS * ps, int int_lit) -{ - Lit * lit; - Var * v; - - assert (abs (int_lit) <= (int) ps->max_var); - - v = ps->vars + abs (int_lit); - if (!v->partial) - return 0; - - lit = int2lit (ps, int_lit); - - if (lit->val == TRUE) - return 1; - - if (lit->val == FALSE) - return -1; - - return 0; -} - -static void -minautarky (PS * ps) -{ - unsigned * occs, maxoccs, tmpoccs, npartial; - int * p, * c, lit, best, val; -#ifdef LOGGING - int tl; -#endif - - assert (!ps->partial); - - npartial = 0; - - NEWN (occs, 2*ps->max_var + 1); - CLRN (occs, 2*ps->max_var + 1); - occs += ps->max_var; - for (p = ps->soclauses; p < ps->sohead; p++) - occs[*p]++; - assert (occs[0] == ps->oadded); - - for (c = ps->soclauses; c < ps->sohead; c = p + 1) - { -#ifdef LOGGING - tl = 0; -#endif - best = 0; - maxoccs = 0; - for (p = c; (lit = *p); p++) - { - val = tderef (ps, lit); - if (val < 0) - continue; - if (val > 0) - { -#ifdef LOGGING - tl = 1; -#endif - best = lit; - maxoccs = occs[lit]; - } - - val = pderef (ps, lit); - if (val > 0) - break; - if (val < 0) - continue; - val = int2lit (ps, lit)->val; - assert (val); - if (val < 0) - continue; - tmpoccs = occs[lit]; - if (best && tmpoccs <= maxoccs) - continue; - best = lit; - maxoccs = tmpoccs; - } - if (!lit) - { - assert (best); - LOG ( fprintf (ps->out, "%sautark %d with %d occs%s\n", - ps->prefix, best, maxoccs, tl ? " (top)" : "")); - ps->vars[abs (best)].partial = 1; - npartial++; - } - for (p = c; (lit = *p); p++) - { - assert (occs[lit] > 0); - occs[lit]--; - } - } - occs -= ps->max_var; - DELETEN (occs, 2*ps->max_var + 1); - ps->partial = 1; - - if (ps->verbosity) - fprintf (ps->out, - "%sautarky of size %u out of %u satisfying all clauses (%.1f%%)\n", - ps->prefix, npartial, ps->max_var, PERCENT (npartial, ps->max_var)); -} - -void -picosat_assume (PS * ps, int int_lit) -{ - Lit *lit; - - if (ps->measurealltimeinlib) - enter (ps); - else - check_ready (ps); - - if (ps->state != READY) - reset_incremental_usage (ps); - - assume_contexts (ps); - lit = import_lit (ps, int_lit, 1); - assume (ps, lit); - - if (ps->measurealltimeinlib) - leave (ps); -} - -int -picosat_sat (PS * ps, int l) -{ - int res; - char ch; - - enter (ps); - - ps->calls++; - LOG ( fprintf (ps->out, "%sSTART call %u\n", ps->prefix, ps->calls)); - - if (ps->added < ps->ahead) - { -#ifndef NADC - if (ps->addingtoado) - ABORT ("API usage: incomplete all different constraint"); - else -#endif - ABORT ("API usage: incomplete clause"); - } - - if (ps->state != READY) - reset_incremental_usage (ps); - - assume_contexts (ps); - - res = sat (ps, l); - - assert (ps->state == READY); - - switch (res) - { - case PICOSAT_UNSATISFIABLE: - ch = '0'; - ps->state = UNSAT; - break; - case PICOSAT_SATISFIABLE: - ch = '1'; - ps->state = SAT; - break; - default: - ch = '?'; - ps->state = UNKNOWN; - break; - } - - if (ps->verbosity) - { - report (ps, 1, ch); - rheader (ps); - } - - leave (ps); - LOG ( fprintf (ps->out, "%sEND call %u result %d\n", ps->prefix, ps->calls, res)); - - ps->last_sat_call_result = res; - - return res; -} - -int -picosat_res (PS * ps) -{ - return ps->last_sat_call_result; -} - -int -picosat_deref (PS * ps, int int_lit) -{ - Lit *lit; - - check_ready (ps); - check_sat_state (ps); - ABORTIF (!int_lit, "API usage: can not deref zero literal"); - ABORTIF (ps->mtcls, "API usage: deref after empty clause generated"); - -#ifdef STATS - ps->derefs++; -#endif - - if (abs (int_lit) > (int) ps->max_var) - return 0; - - lit = int2lit (ps, int_lit); - - if (lit->val == TRUE) - return 1; - - if (lit->val == FALSE) - return -1; - - return 0; -} - -int -picosat_deref_toplevel (PS * ps, int int_lit) -{ - check_ready (ps); - ABORTIF (!int_lit, "API usage: can not deref zero literal"); - -#ifdef STATS - ps->derefs++; -#endif - if (abs (int_lit) > (int) ps->max_var) - return 0; - - return tderef (ps, int_lit); -} - -int -picosat_inconsistent (PS * ps) -{ - check_ready (ps); - return ps->mtcls != 0; -} - -int -picosat_corelit (PS * ps, int int_lit) -{ - check_ready (ps); - check_unsat_state (ps); - ABORTIF (!int_lit, "API usage: zero literal can not be in core"); - - assert (ps->mtcls || ps->failed_assumption); - -#ifdef TRACE - { - int res = 0; - ABORTIF (!ps->trace, "tracing disabled"); - if (ps->measurealltimeinlib) - enter (ps); - core (ps); - if (abs (int_lit) <= (int) ps->max_var) - res = ps->vars[abs (int_lit)].core; - assert (!res || ps->failed_assumption || ps->vars[abs (int_lit)].used); - if (ps->measurealltimeinlib) - leave (ps); - return res; - } -#else - ABORT ("compiled without trace support"); - return 0; -#endif -} - -int -picosat_coreclause (PS * ps, int ocls) -{ - check_ready (ps); - check_unsat_state (ps); - - ABORTIF (ocls < 0, "API usage: negative original clause index"); - ABORTIF (ocls >= (int)ps->oadded, "API usage: original clause index exceeded"); - - assert (ps->mtcls || ps->failed_assumption); - -#ifdef TRACE - { - Cls ** clsptr, * c; - int res = 0; - - ABORTIF (!ps->trace, "tracing disabled"); - if (ps->measurealltimeinlib) - enter (ps); - core (ps); - clsptr = ps->oclauses + ocls; - assert (clsptr < ps->ohead); - c = *clsptr; - if (c) - res = c->core; - if (ps->measurealltimeinlib) - leave (ps); - - return res; - } -#else - ABORT ("compiled without trace support"); - return 0; -#endif -} - -int -picosat_failed_assumption (PS * ps, int int_lit) -{ - Lit * lit; - Var * v; - ABORTIF (!int_lit, "API usage: zero literal as assumption"); - check_ready (ps); - check_unsat_state (ps); - if (ps->mtcls) - return 0; - assert (ps->failed_assumption); - if (abs (int_lit) > (int) ps->max_var) - return 0; - if (!ps->extracted_all_failed_assumptions) - extract_all_failed_assumptions (ps); - lit = import_lit (ps, int_lit, 1); - v = LIT2VAR (lit); - return v->failed; -} - -int -picosat_failed_context (PS * ps, int int_lit) -{ - Lit * lit; - Var * v; - ABORTIF (!int_lit, "API usage: zero literal as context"); - ABORTIF (abs (int_lit) > (int) ps->max_var, "API usage: invalid context"); - check_ready (ps); - check_unsat_state (ps); - assert (ps->failed_assumption); - if (!ps->extracted_all_failed_assumptions) - extract_all_failed_assumptions (ps); - lit = import_lit (ps, int_lit, 0); - v = LIT2VAR (lit); - return v->failed; -} - -const int * -picosat_failed_assumptions (PS * ps) -{ - Lit ** p, * lit; - Var * v; - int ilit; - - ps->falshead = ps->fals; - check_ready (ps); - check_unsat_state (ps); - if (!ps->mtcls) - { - assert (ps->failed_assumption); - if (!ps->extracted_all_failed_assumptions) - extract_all_failed_assumptions (ps); - - for (p = ps->als; p < ps->alshead; p++) - { - lit = *p; - v = LIT2VAR (*p); - if (!v->failed) - continue; - ilit = LIT2INT (lit); - if (ps->falshead == ps->eofals) - ENLARGE (ps->fals, ps->falshead, ps->eofals); - *ps->falshead++ = ilit; - } - } - if (ps->falshead == ps->eofals) - ENLARGE (ps->fals, ps->falshead, ps->eofals); - *ps->falshead++ = 0; - return ps->fals; -} - -const int * -picosat_mus_assumptions (PS * ps, void * s, void (*cb)(void*,const int*), int fix) -{ - int i, j, ilit, len, nwork, * work, res; - signed char * redundant; - Lit ** p, * lit; - int failed; - Var * v; -#ifndef NDEBUG - int oldlen; -#endif -#ifndef RCODE - int norig = ps->alshead - ps->als; -#endif - - check_ready (ps); - check_unsat_state (ps); - len = 0; - if (!ps->mtcls) - { - assert (ps->failed_assumption); - if (!ps->extracted_all_failed_assumptions) - extract_all_failed_assumptions (ps); - - for (p = ps->als; p < ps->alshead; p++) - if (LIT2VAR (*p)->failed) - len++; - } - - if (ps->mass) - DELETEN (ps->mass, ps->szmass); - ps->szmass = len + 1; - NEWN (ps->mass, ps->szmass); - - i = 0; - for (p = ps->als; p < ps->alshead; p++) - { - lit = *p; - v = LIT2VAR (lit); - if (!v->failed) - continue; - ilit = LIT2INT (lit); - assert (i < len); - ps->mass[i++] = ilit; - } - assert (i == len); - ps->mass[i] = 0; - if (ps->verbosity) - fprintf (ps->out, - "%sinitial set of failed assumptions of size %d out of %d (%.0f%%)\n", - ps->prefix, len, norig, PERCENT (len, norig)); - if (cb) - cb (s, ps->mass); - - nwork = len; - NEWN (work, nwork); - for (i = 0; i < len; i++) - work[i] = ps->mass[i]; - - NEWN (redundant, nwork); - CLRN (redundant, nwork); - - for (i = 0; i < nwork; i++) - { - if (redundant[i]) - continue; - - if (ps->verbosity > 1) - fprintf (ps->out, - "%strying to drop %d%s assumption %d\n", - ps->prefix, i, enumstr (i), work[i]); - for (j = 0; j < nwork; j++) - { - if (i == j) continue; - if (j < i && fix) continue; - if (redundant[j]) continue; - picosat_assume (ps, work[j]); - } - - res = picosat_sat (ps, -1); - if (res == 10) - { - if (ps->verbosity > 1) - fprintf (ps->out, - "%sfailed to drop %d%s assumption %d\n", - ps->prefix, i, enumstr (i), work[i]); - - if (fix) - { - picosat_add (ps, work[i]); - picosat_add (ps, 0); - } - } - else - { - assert (res == 20); - if (ps->verbosity > 1) - fprintf (ps->out, - "%ssuceeded to drop %d%s assumption %d\n", - ps->prefix, i, enumstr (i), work[i]); - redundant[i] = 1; - for (j = 0; j < nwork; j++) - { - failed = picosat_failed_assumption (ps, work[j]); - if (j <= i) - { - assert ((j < i && fix) || redundant[j] == !failed); - continue; - } - - if (!failed) - { - redundant[j] = -1; - if (ps->verbosity > 1) - fprintf (ps->out, - "%salso suceeded to drop %d%s assumption %d\n", - ps->prefix, j, enumstr (j), work[j]); - } - } - -#ifndef NDEBUG - oldlen = len; -#endif - len = 0; - for (j = 0; j < nwork; j++) - if (!redundant[j]) - ps->mass[len++] = work[j]; - ps->mass[len] = 0; - assert (len < oldlen); - - if (fix) - { - picosat_add (ps, -work[i]); - picosat_add (ps, 0); - } - -#ifndef NDEBUG - for (j = 0; j <= i; j++) - assert (redundant[j] >= 0); -#endif - for (j = i + 1; j < nwork; j++) - { - if (redundant[j] >= 0) - continue; - - if (fix) - { - picosat_add (ps, -work[j]); - picosat_add (ps, 0); - } - - redundant[j] = 1; - } - - if (ps->verbosity) - fprintf (ps->out, - "%sreduced set of failed assumptions of size %d out of %d (%.0f%%)\n", - ps->prefix, len, norig, PERCENT (len, norig)); - if (cb) - cb (s, ps->mass); - } - } - - DELETEN (work, nwork); - DELETEN (redundant, nwork); - - if (ps->verbosity) - { - fprintf (ps->out, "%sreinitializing unsat state\n", ps->prefix); - fflush (ps->out); - } - - for (i = 0; i < len; i++) - picosat_assume (ps, ps->mass[i]); - -#ifndef NDEBUG - res = -#endif - picosat_sat (ps, -1); - assert (res == 20); - - if (!ps->mtcls) - { - assert (!ps->extracted_all_failed_assumptions); - extract_all_failed_assumptions (ps); - } - - return ps->mass; -} - -static const int * -mss (PS * ps, int * a, int size) -{ - int i, j, k, res; - - assert (!ps->mtcls); - - if (ps->szmssass) - DELETEN (ps->mssass, ps->szmssass); - - ps->szmssass = 0; - ps->mssass = 0; - - ps->szmssass = size + 1; - NEWN (ps->mssass, ps->szmssass); - - LOG ( fprintf (ps->out, "%ssearch MSS over %d assumptions\n", ps->prefix, size)); - - k = 0; - for (i = k; i < size; i++) - { - for (j = 0; j < k; j++) - picosat_assume (ps, ps->mssass[j]); - - LOG ( fprintf (ps->out, - "%strying to add assumption %d to MSS : %d\n", - ps->prefix, i, a[i])); - - picosat_assume (ps, a[i]); - - res = picosat_sat (ps, -1); - if (res == 10) - { - LOG ( fprintf (ps->out, - "%sadding assumption %d to MSS : %d\n", ps->prefix, i, a[i])); - - ps->mssass[k++] = a[i]; - - for (j = i + 1; j < size; j++) - { - if (picosat_deref (ps, a[j]) <= 0) - continue; - - LOG ( fprintf (ps->out, - "%salso adding assumption %d to MSS : %d\n", - ps->prefix, j, a[j])); - - ps->mssass[k++] = a[j]; - - if (++i != j) - { - int tmp = a[i]; - a[i] = a[j]; - a[j] = tmp; - } - } - } - else - { - assert (res == 20); - - LOG ( fprintf (ps->out, - "%signoring assumption %d in MSS : %d\n", ps->prefix, i, a[i])); - } - } - ps->mssass[k] = 0; - LOG ( fprintf (ps->out, "%sfound MSS of size %d\n", ps->prefix, k)); - - return ps->mssass; -} - -static void -reassume (PS * ps, const int * a, int size) -{ - int i; - LOG ( fprintf (ps->out, "%sreassuming all assumptions\n", ps->prefix)); - for (i = 0; i < size; i++) - picosat_assume (ps, a[i]); -} - -const int * -picosat_maximal_satisfiable_subset_of_assumptions (PS * ps) -{ - const int * res; - int i, *a, size; - - ABORTIF (ps->mtcls, - "API usage: CNF inconsistent (use 'picosat_inconsistent')"); - - enter (ps); - - size = ps->alshead - ps->als; - NEWN (a, size); - - for (i = 0; i < size; i++) - a[i] = LIT2INT (ps->als[i]); - - res = mss (ps, a, size); - reassume (ps, a, size); - - DELETEN (a, size); - - leave (ps); - - return res; -} - -static void -check_mss_flags_clean (PS * ps) -{ -#ifndef NDEBUG - unsigned i; - for (i = 1; i <= ps->max_var; i++) - { - assert (!ps->vars[i].msspos); - assert (!ps->vars[i].mssneg); - } -#else - (void) ps; -#endif -} - -static void -push_mcsass (PS * ps, int lit) -{ - if (ps->nmcsass == ps->szmcsass) - { - ps->szmcsass = ps->szmcsass ? 2*ps->szmcsass : 1; - RESIZEN (ps->mcsass, ps->nmcsass, ps->szmcsass); - } - - ps->mcsass[ps->nmcsass++] = lit; -} - -static const int * -next_mss (PS * ps, int mcs) -{ - int i, *a, size, mssize, mcsize, lit, inmss; - const int * res, * p; - Var * v; - - if (ps->mtcls) return 0; - - check_mss_flags_clean (ps); - - if (mcs && ps->mcsass) - { - DELETEN (ps->mcsass, ps->szmcsass); - ps->nmcsass = ps->szmcsass = 0; - ps->mcsass = 0; - } - - size = ps->alshead - ps->als; - NEWN (a, size); - - for (i = 0; i < size; i++) - a[i] = LIT2INT (ps->als[i]); - - (void) picosat_sat (ps, -1); - - //TODO short cut for 'picosat_res () == 10'? - - if (ps->mtcls) - { - assert (picosat_res (ps) == 20); - res = 0; - goto DONE; - } - - res = mss (ps, a, size); - - if (ps->mtcls) - { - res = 0; - goto DONE; - } - - for (p = res; (lit = *p); p++) - { - v = ps->vars + abs (lit); - if (lit < 0) - { - assert (!v->msspos); - v->mssneg = 1; - } - else - { - assert (!v->mssneg); - v->msspos = 1; - } - } - - mssize = p - res; - mcsize = INT_MIN; - - for (i = 0; i < size; i++) - { - lit = a[i]; - v = ps->vars + abs (lit); - if (lit > 0 && v->msspos) - inmss = 1; - else if (lit < 0 && v->mssneg) - inmss = 1; - else - inmss = 0; - - if (mssize < mcsize) - { - if (inmss) - picosat_add (ps, -lit); - } - else - { - if (!inmss) - picosat_add (ps, lit); - } - - if (!inmss && mcs) - push_mcsass (ps, lit); - } - picosat_add (ps, 0); - if (mcs) - push_mcsass (ps, 0); - - for (i = 0; i < size; i++) - { - lit = a[i]; - v = ps->vars + abs (lit); - v->msspos = 0; - v->mssneg = 0; - } - -DONE: - - reassume (ps, a, size); - DELETEN (a, size); - - return res; -} - -const int * -picosat_next_maximal_satisfiable_subset_of_assumptions (PS * ps) -{ - const int * res; - enter (ps); - res = next_mss (ps, 0); - leave (ps); - return res; -} - -const int * -picosat_next_minimal_correcting_subset_of_assumptions (PS * ps) -{ - const int * res, * tmp; - enter (ps); - tmp = next_mss (ps, 1); - res = tmp ? ps->mcsass : 0; - leave (ps); - return res; -} - -const int * -picosat_humus (PS * ps, - void (*callback)(void*state,int nmcs,int nhumus), - void * state) -{ - int lit, nmcs, j, nhumus; - const int * mcs, * p; - unsigned i; - Var * v; - enter (ps); -#ifndef NDEBUG - for (i = 1; i <= ps->max_var; i++) - { - v = ps->vars + i; - assert (!v->humuspos); - assert (!v->humusneg); - } -#endif - nhumus = nmcs = 0; - while ((mcs = picosat_next_minimal_correcting_subset_of_assumptions (ps))) - { - for (p = mcs; (lit = *p); p++) - { - v = ps->vars + abs (lit); - if (lit < 0) - { - if (!v->humusneg) - { - v->humusneg = 1; - nhumus++; - } - } - else - { - if (!v->humuspos) - { - v->humuspos = 1; - nhumus++; - } - } - } - nmcs++; - LOG ( fprintf (ps->out, - "%smcs %d of size %d humus %d\n", - ps->prefix, nmcs, (int)(p - mcs), nhumus)); - if (callback) - callback (state, nmcs, nhumus); - } - assert (!ps->szhumus); - ps->szhumus = 1; - for (i = 1; i <= ps->max_var; i++) - { - v = ps->vars + i; - if (v->humuspos) - ps->szhumus++; - if (v->humusneg) - ps->szhumus++; - } - assert (nhumus + 1 == ps->szhumus); - NEWN (ps->humus, ps->szhumus); - j = 0; - for (i = 1; i <= ps->max_var; i++) - { - v = ps->vars + i; - if (v->humuspos) - { - assert (j < nhumus); - ps->humus[j++] = (int) i; - } - if (v->humusneg) - { - assert (j < nhumus); - assert (i < INT_MAX); - ps->humus[j++] = - (int) i; - } - } - assert (j == nhumus); - assert (j < ps->szhumus); - ps->humus[j] = 0; - leave (ps); - return ps->humus; -} - -int -picosat_usedlit (PS * ps, int int_lit) -{ - int res; - check_ready (ps); - check_sat_or_unsat_or_unknown_state (ps); - ABORTIF (!int_lit, "API usage: zero literal can not be used"); - int_lit = abs (int_lit); - res = (int_lit <= (int) ps->max_var) ? ps->vars[int_lit].used : 0; - return res; -} - -void -picosat_write_clausal_core (PS * ps, FILE * file) -{ - check_trace_support_and_execute (ps, file, write_core_wrapper, 0); -} - -void -picosat_write_compact_trace (PS * ps, FILE * file) -{ - check_trace_support_and_execute (ps, file, write_trace, - COMPACT_TRACECHECK_TRACE_FMT); -} - -void -picosat_write_extended_trace (PS * ps, FILE * file) -{ - check_trace_support_and_execute (ps, file, write_trace, - EXTENDED_TRACECHECK_TRACE_FMT); -} - -void -picosat_write_rup_trace (PS * ps, FILE * file) -{ - check_trace_support_and_execute (ps, file, write_trace, RUP_TRACE_FMT); -} - -size_t -picosat_max_bytes_allocated (PS * ps) -{ - check_ready (ps); - return ps->max_bytes; -} - -void -picosat_set_propagation_limit (PS * ps, unsigned long long l) -{ - ps->lpropagations = l; -} - -unsigned long long -picosat_propagations (PS * ps) -{ - return ps->propagations; -} - -unsigned long long -picosat_visits (PS * ps) -{ - return ps->visits; -} - -unsigned long long -picosat_decisions (PS * ps) -{ - return ps->decisions; -} - -int -picosat_variables (PS * ps) -{ - check_ready (ps); - return (int) ps->max_var; -} - -int -picosat_added_original_clauses (PS * ps) -{ - check_ready (ps); - return (int) ps->oadded; -} - -void -picosat_stats (PS * ps) -{ -#ifndef RCODE - unsigned redlits; -#endif -#ifdef STATS - check_ready (ps); - assert (ps->sdecisions + ps->rdecisions + ps->assumptions == ps->decisions); -#endif - if (ps->calls > 1) - fprintf (ps->out, "%s%u calls\n", ps->prefix, ps->calls); - if (ps->contexts) - { - fprintf (ps->out, "%s%u contexts", ps->prefix, ps->contexts); -#ifdef STATS - fprintf (ps->out, " %u internal variables", ps->internals); -#endif - fprintf (ps->out, "\n"); - } - fprintf (ps->out, "%s%u iterations\n", ps->prefix, ps->iterations); - fprintf (ps->out, "%s%u restarts", ps->prefix, ps->restarts); -#ifdef STATS - fprintf (ps->out, " (%u skipped)", ps->skippedrestarts); -#endif - fputc ('\n', ps->out); -#ifndef NFL - fprintf (ps->out, "%s%u failed literals", ps->prefix, ps->failedlits); -#ifdef STATS - fprintf (ps->out, - ", %u calls, %u rounds, %llu propagations", - ps->flcalls, ps->flrounds, ps->flprops); -#endif - fputc ('\n', ps->out); -#ifdef STATS - fprintf (ps->out, - "%sfl: %u = %.1f%% implicit, %llu oopsed, %llu tried, %llu skipped\n", - ps->prefix, - ps->ifailedlits, PERCENT (ps->ifailedlits, ps->failedlits), - ps->floopsed, ps->fltried, ps->flskipped); -#endif -#endif - fprintf (ps->out, "%s%u conflicts", ps->prefix, ps->conflicts); -#ifdef STATS - fprintf (ps->out, " (%u uips = %.1f%%)\n", ps->uips, PERCENT(ps->uips,ps->conflicts)); -#else - fputc ('\n', ps->out); -#endif -#ifndef NADC - fprintf (ps->out, "%s%u adc conflicts\n", ps->prefix, ps->adoconflicts); -#endif -#ifdef STATS - fprintf (ps->out, "%s%llu dereferenced literals\n", ps->prefix, ps->derefs); -#endif - fprintf (ps->out, "%s%u decisions", ps->prefix, ps->decisions); -#ifdef STATS - fprintf (ps->out, " (%u random = %.2f%%", - ps->rdecisions, PERCENT (ps->rdecisions, ps->decisions)); - fprintf (ps->out, ", %u assumptions", ps->assumptions); - fputc (')', ps->out); -#endif - fputc ('\n', ps->out); -#ifdef STATS - fprintf (ps->out, - "%s%u static phase decisions (%.1f%% of all variables)\n", - ps->prefix, - ps->staticphasedecisions, PERCENT (ps->staticphasedecisions, ps->max_var)); -#endif - fprintf (ps->out, "%s%u fixed variables\n", ps->prefix, ps->fixed); - assert (ps->nonminimizedllits >= ps->minimizedllits); -#ifndef RCODE - redlits = ps->nonminimizedllits - ps->minimizedllits; -#endif - fprintf (ps->out, "%s%u learned literals\n", ps->prefix, ps->llitsadded); - fprintf (ps->out, "%s%.1f%% deleted literals\n", - ps->prefix, PERCENT (redlits, ps->nonminimizedllits)); - -#ifdef STATS -#ifdef TRACE - fprintf (ps->out, - "%s%llu antecedents (%.1f antecedents per clause", - ps->prefix, ps->antecedents, AVERAGE (ps->antecedents, ps->conflicts)); - if (ps->trace) - fprintf (ps->out, ", %.1f bytes/antecedent)", AVERAGE (ps->znts, ps->antecedents)); - fputs (")\n", ps->out); -#endif - - fprintf (ps->out, "%s%llu propagations (%.1f propagations per decision)\n", - ps->prefix, ps->propagations, AVERAGE (ps->propagations, ps->decisions)); - fprintf (ps->out, "%s%llu visits (%.1f per propagation)\n", - ps->prefix, ps->visits, AVERAGE (ps->visits, ps->propagations)); - fprintf (ps->out, - "%s%llu binary clauses visited (%.1f%% %.1f per propagation)\n", - ps->prefix, ps->bvisits, - PERCENT (ps->bvisits, ps->visits), - AVERAGE (ps->bvisits, ps->propagations)); - fprintf (ps->out, - "%s%llu ternary clauses visited (%.1f%% %.1f per propagation)\n", - ps->prefix, ps->tvisits, - PERCENT (ps->tvisits, ps->visits), - AVERAGE (ps->tvisits, ps->propagations)); - fprintf (ps->out, - "%s%llu large clauses visited (%.1f%% %.1f per propagation)\n", - ps->prefix, ps->lvisits, - PERCENT (ps->lvisits, ps->visits), - AVERAGE (ps->lvisits, ps->propagations)); - fprintf (ps->out, "%s%llu other true (%.1f%% of visited clauses)\n", - ps->prefix, ps->othertrue, PERCENT (ps->othertrue, ps->visits)); - fprintf (ps->out, - "%s%llu other true in binary clauses (%.1f%%)" - ", %llu upper (%.1f%%)\n", - ps->prefix, ps->othertrue2, PERCENT (ps->othertrue2, ps->othertrue), - ps->othertrue2u, PERCENT (ps->othertrue2u, ps->othertrue2)); - fprintf (ps->out, - "%s%llu other true in large clauses (%.1f%%)" - ", %llu upper (%.1f%%)\n", - ps->prefix, ps->othertruel, PERCENT (ps->othertruel, ps->othertrue), - ps->othertruelu, PERCENT (ps->othertruelu, ps->othertruel)); - fprintf (ps->out, "%s%llu ternary and large traversals (%.1f per visit)\n", - ps->prefix, ps->traversals, AVERAGE (ps->traversals, ps->visits)); - fprintf (ps->out, "%s%llu large traversals (%.1f per large visit)\n", - ps->prefix, ps->ltraversals, AVERAGE (ps->ltraversals, ps->lvisits)); - fprintf (ps->out, "%s%llu assignments\n", ps->prefix, ps->assignments); -#else - fprintf (ps->out, "%s%llu propagations\n", ps->prefix, picosat_propagations (ps)); - fprintf (ps->out, "%s%llu visits\n", ps->prefix, picosat_visits (ps)); -#endif - fprintf (ps->out, "%s%.1f%% variables used\n", ps->prefix, PERCENT (ps->vused, ps->max_var)); - - sflush (ps); - fprintf (ps->out, "%s%.1f seconds in library\n", ps->prefix, ps->seconds); - fprintf (ps->out, "%s%.1f megaprops/second\n", - ps->prefix, AVERAGE (ps->propagations / 1e6f, ps->seconds)); - fprintf (ps->out, "%s%.1f megavisits/second\n", - ps->prefix, AVERAGE (ps->visits / 1e6f, ps->seconds)); - fprintf (ps->out, "%sprobing %.1f seconds %.0f%%\n", - ps->prefix, ps->flseconds, PERCENT (ps->flseconds, ps->seconds)); -#ifdef STATS - fprintf (ps->out, - "%srecycled %.1f MB in %u reductions\n", - ps->prefix, ps->rrecycled / (double) (1 << 20), ps->reductions); - fprintf (ps->out, - "%srecycled %.1f MB in %u simplifications\n", - ps->prefix, ps->srecycled / (double) (1 << 20), ps->simps); -#else - fprintf (ps->out, "%s%u simplifications\n", ps->prefix, ps->simps); - fprintf (ps->out, "%s%u reductions\n", ps->prefix, ps->reductions); - fprintf (ps->out, "%s%.1f MB recycled\n", ps->prefix, ps->recycled / (double) (1 << 20)); -#endif - fprintf (ps->out, "%s%.1f MB maximally allocated\n", - ps->prefix, picosat_max_bytes_allocated (ps) / (double) (1 << 20)); -} - -#ifndef NGETRUSAGE -#include <sys/time.h> -#include <sys/resource.h> -#include <sys/unistd.h> -#endif - -double -picosat_time_stamp (void) -{ - double res = -1; -#ifndef NGETRUSAGE - struct rusage u; - res = 0; - if (!getrusage (RUSAGE_SELF, &u)) - { - res += u.ru_utime.tv_sec + 1e-6 * u.ru_utime.tv_usec; - res += u.ru_stime.tv_sec + 1e-6 * u.ru_stime.tv_usec; - } -#endif - return res; -} - -double -picosat_seconds (PS * ps) -{ - check_ready (ps); - return ps->seconds; -} - -void -picosat_print (PS * ps, FILE * file) -{ -#ifdef NO_BINARY_CLAUSES - Lit * lit, *other, * last; - Ltk * stack; -#endif - Lit **q, **eol; - Cls **p, *c; - unsigned n; - - if (ps->measurealltimeinlib) - enter (ps); - else - check_ready (ps); - - n = 0; - n += ps->alshead - ps->als; - - for (p = SOC; p != EOC; p = NXC (p)) - { - c = *p; - - if (!c) - continue; - -#ifdef TRACE - if (c->collected) - continue; -#endif - n++; - } - -#ifdef NO_BINARY_CLAUSES - last = int2lit (ps, -ps->max_var); - for (lit = int2lit (ps, 1); lit <= last; lit++) - { - stack = LIT2IMPLS (lit); - eol = stack->start + stack->count; - for (q = stack->start; q < eol; q++) - if (*q >= lit) - n++; - } -#endif - - fprintf (file, "p cnf %d %u\n", ps->max_var, n); - - for (p = SOC; p != EOC; p = NXC (p)) - { - c = *p; - if (!c) - continue; - -#ifdef TRACE - if (c->collected) - continue; -#endif - - eol = end_of_lits (c); - for (q = c->lits; q < eol; q++) - fprintf (file, "%d ", LIT2INT (*q)); - - fputs ("0\n", file); - } - -#ifdef NO_BINARY_CLAUSES - last = int2lit (ps, -ps->max_var); - for (lit = int2lit (ps, 1); lit <= last; lit++) - { - stack = LIT2IMPLS (lit); - eol = stack->start + stack->count; - for (q = stack->start; q < eol; q++) - if ((other = *q) >= lit) - fprintf (file, "%d %d 0\n", LIT2INT (lit), LIT2INT (other)); - } -#endif - - { - Lit **r; - for (r = ps->als; r < ps->alshead; r++) - fprintf (file, "%d 0\n", LIT2INT (*r)); - } - - fflush (file); - - if (ps->measurealltimeinlib) - leave (ps); -} - -void -picosat_enter (PS * ps) -{ - enter (ps); -} - -void -picosat_leave (PS * ps) -{ - leave (ps); -} - -void -picosat_message (PS * ps, int vlevel, const char * fmt, ...) -{ - va_list ap; - - if (vlevel > ps->verbosity) - return; - - fputs (ps->prefix, ps->out); - va_start (ap, fmt); - vfprintf (ps->out, fmt, ap); - va_end (ap); - fputc ('\n', ps->out); -} - -int -picosat_changed (PS * ps) -{ - int res; - - check_ready (ps); - check_sat_state (ps); - - res = (ps->min_flipped <= ps->saved_max_var); - assert (!res || ps->saved_flips != ps->flips); - - return res; -} - -void -picosat_reset_phases (PS * ps) -{ - rebias (ps); -} - -void -picosat_reset_scores (PS * ps) -{ - Rnk * r; - ps->hhead = ps->heap + 1; - for (r = ps->rnks + 1; r <= ps->rnks + ps->max_var; r++) - { - CLR (r); - hpush (ps, r); - } -} - -void -picosat_remove_learned (PS * ps, unsigned percentage) -{ - enter (ps); - reset_incremental_usage (ps); - reduce (ps, percentage); - leave (ps); -} - -void -picosat_set_global_default_phase (PS * ps, int phase) -{ - check_ready (ps); - ABORTIF (phase < 0, "API usage: 'picosat_set_global_default_phase' " - "with negative argument"); - ABORTIF (phase > 3, "API usage: 'picosat_set_global_default_phase' " - "with argument > 3"); - ps->defaultphase = phase; -} - -void -picosat_set_default_phase_lit (PS * ps, int int_lit, int phase) -{ - unsigned newphase; - Lit * lit; - Var * v; - - check_ready (ps); - - lit = import_lit (ps, int_lit, 1); - v = LIT2VAR (lit); - - if (phase) - { - newphase = (int_lit < 0) == (phase < 0); - v->defphase = v->phase = newphase; - v->usedefphase = v->assigned = 1; - } - else - { - v->usedefphase = v->assigned = 0; - } -} - -void -picosat_set_more_important_lit (PS * ps, int int_lit) -{ - Lit * lit; - Var * v; - Rnk * r; - - check_ready (ps); - - lit = import_lit (ps, int_lit, 1); - v = LIT2VAR (lit); - r = VAR2RNK (v); - - ABORTIF (r->lessimportant, "can not mark variable more and less important"); - - if (r->moreimportant) - return; - - r->moreimportant = 1; - - if (r->pos) - hup (ps, r); -} - -void -picosat_set_less_important_lit (PS * ps, int int_lit) -{ - Lit * lit; - Var * v; - Rnk * r; - - check_ready (ps); - - lit = import_lit (ps, int_lit, 1); - v = LIT2VAR (lit); - r = VAR2RNK (v); - - ABORTIF (r->moreimportant, "can not mark variable more and less important"); - - if (r->lessimportant) - return; - - r->lessimportant = 1; - - if (r->pos) - hdown (ps, r); -} - -#ifndef NADC - -unsigned -picosat_ado_conflicts (PS * ps) -{ - check_ready (ps); - return ps->adoconflicts; -} - -void -picosat_disable_ado (PS * ps) -{ - check_ready (ps); - assert (!ps->adodisabled); - ps->adodisabled = 1; -} - -void -picosat_enable_ado (PS * ps) -{ - check_ready (ps); - assert (ps->adodisabled); - ps->adodisabled = 0; -} - -void -picosat_set_ado_conflict_limit (PS * ps, unsigned newadoconflictlimit) -{ - check_ready (ps); - ps->adoconflictlimit = newadoconflictlimit; -} - -#endif - -void -picosat_simplify (PS * ps) -{ - enter (ps); - reset_incremental_usage (ps); - simplify (ps, 1); - leave (ps); -} - -int -picosat_haveados (void) -{ -#ifndef NADC - return 1; -#else - return 0; -#endif -} - -void -picosat_save_original_clauses (PS * ps) -{ - if (ps->saveorig) return; - ABORTIF (ps->oadded, "API usage: 'picosat_save_original_clauses' too late"); - ps->saveorig = 1; -} - -void picosat_set_interrupt (PicoSAT * ps, - void * external_state, - int (*interrupted)(void * external_state)) -{ - ps->interrupt.state = external_state; - ps->interrupt.function = interrupted; -} - -int -picosat_deref_partial (PS * ps, int int_lit) -{ - check_ready (ps); - check_sat_state (ps); - ABORTIF (!int_lit, "API usage: can not partial deref zero literal"); - ABORTIF (ps->mtcls, "API usage: deref partial after empty clause generated"); - ABORTIF (!ps->saveorig, "API usage: 'picosat_save_original_clauses' missing"); - -#ifdef STATS - ps->derefs++; -#endif - - if (!ps->partial) - minautarky (ps); - - return pderef (ps, int_lit); -} -#include "config.h" - -const char * -picosat_version (void) -{ - return PICOSAT_VERSION; -} - -const char * -picosat_config (void) -{ - return PICOSAT_CC " " PICOSAT_CFLAGS; -} - diff --git a/test/monniaux/rules.mk b/test/monniaux/rules.mk index 2bd70afd..07b33b59 100644 --- a/test/monniaux/rules.mk +++ b/test/monniaux/rules.mk @@ -21,7 +21,7 @@ MEASURES?=time ALL_CFLAGS+=-Wall -D__KVX_COS__ -DMAX_MEASURES=$(MAX_MEASURES) #ALL_CFLAGS+=-g ALL_GCCFLAGS+=$(ALL_CFLAGS) -std=c99 -Wextra -Werror=implicit -ALL_CCOMPFLAGS+=$(ALL_CFLAGS) +ALL_CCOMPFLAGS+=$(ALL_CFLAGS) # -fprofile-use= ../compcert_profiling.dat # The compilers KVX_CC?=kvx-elf-gcc @@ -38,10 +38,10 @@ GCC2FLAGS?=$(ALL_GCCFLAGS) -O2 GCC3FLAGS?=$(ALL_GCCFLAGS) -O3 GCC4FLAGS?= CCOMP0FLAGS?=$(ALL_CCOMPFLAGS) -O2 -CCOMP1FLAGS?=$(ALL_CCOMPFLAGS) -O2 -ftracelinearize -CCOMP2FLAGS?=$(ALL_CCOMPFLAGS) -O2 -ftracelinearize -fduplicate 1 -fprepass -fprepass= list -fall-loads-nontrap -CCOMP3FLAGS?=$(ALL_CCOMPFLAGS) -O2 -ftracelinearize -fduplicate 2 -fprepass -fprepass= list -fall-loads-nontrap -CCOMP4FLAGS?=$(ALL_CCOMPFLAGS) -O2 -ftracelinearize -fduplicate 1 -fprepass -fprepass= revlist -fall-loads-nontrap +CCOMP1FLAGS?=$(ALL_CCOMPFLAGS) -O2 -ftracelinearize -fduplicate 0 +CCOMP2FLAGS?=$(ALL_CCOMPFLAGS) -O2 -ftracelinearize -fduplicate 0 -fprepass= list +CCOMP3FLAGS?=$(ALL_CCOMPFLAGS) -O2 -ftracelinearize -fduplicate 0 -fprepass= revlist +CCOMP4FLAGS?=$(ALL_CCOMPFLAGS) -O2 -ftracelinearize -fduplicate 0 -fprepass= zigzag # Prefix names GCC0PREFIX?=.gcc.o0 @@ -51,9 +51,9 @@ GCC3PREFIX?=.gcc.o3 GCC4PREFIX?= CCOMP0PREFIX?=.ccomp CCOMP1PREFIX?=.ccomp.linearize -CCOMP2PREFIX?=.ccomp.prepass1 -CCOMP3PREFIX?=.ccomp.prepass2 -CCOMP4PREFIX?=.ccomp.revprepass1 +CCOMP2PREFIX?=.ccomp.list +CCOMP3PREFIX?=.ccomp.revlist +CCOMP4PREFIX?=.ccomp.zigzag # List of outfiles, updated by gen_rules OUTFILES:= diff --git a/test/monniaux/scheduling/mal_schedule.c b/test/monniaux/scheduling/mal_schedule.c new file mode 100644 index 00000000..a6ba967f --- /dev/null +++ b/test/monniaux/scheduling/mal_schedule.c @@ -0,0 +1,14 @@ +#include <stdint.h> +int16_t meuh; +extern int uv_encode(double, double, int); +void f(int *ab, int e) { + uint32_t *ao = (uint32_t *)ab; + int16_t *aq = &meuh; + while (e) { + int ar, as; + ar = 1. / 2147483647; + as = uv_encode(5, *aq, *ab); + if (as) + *ao++ = ar; + } +} diff --git a/test/monniaux/yarpgen/Makefile b/test/monniaux/yarpgen/Makefile index c790d6e9..24dd19c3 100644 --- a/test/monniaux/yarpgen/Makefile +++ b/test/monniaux/yarpgen/Makefile @@ -16,7 +16,7 @@ YARPGEN+=-m $(BITS) CFLAGS+=-m$(BITS) endif -MAX=19 # AUXR bug should be 129 +MAX=129 PREFIX=ran%06.f CCOMPOPTS=-static diff --git a/x86/PrepassSchedulingOracle.ml b/x86/PrepassSchedulingOracle.ml new file mode 100644 index 00000000..7b6a1b14 --- /dev/null +++ b/x86/PrepassSchedulingOracle.ml @@ -0,0 +1,5 @@ +open RTL +open Registers + +(* Do not do anything *) +let schedule_sequence (seqa : (instruction*Regset.t) array) = None |