@@ -1954,6 +1954,10 @@ Definition divs (v w: aval) :=
1954
1954
|| Int.eq i1 (Int.repr Int.min_signed) && Int.eq i2 Int.mone
1955
1955
then if va_strict tt then Vbot else ntop
1956
1956
else I (Int.divs i1 i2)
1957
+ | (I i2 | IU i2), _ =>
1958
+ if Int.eq i2 Int.zero
1959
+ then if va_strict tt then Vbot else ntop
1960
+ else sgn (provenance v) (srange v + 1 - Z.log2 (Z.abs (Int.signed i2)))
1957
1961
| _, _ => ntop2 v w
1958
1962
end .
1959
1963
@@ -1962,24 +1966,47 @@ Lemma divs_sound:
1962
1966
Proof .
1963
1967
intros. destruct v; destruct w; try discriminate; simpl in H1.
1964
1968
destruct orb eqn:E; inv H1.
1965
- inv H; inv H0; auto with va; simpl; rewrite E; constructor.
1969
+ rename i0 into j.
1970
+ assert (E': Int.eq j Int.zero = false). { apply orb_false_elim in E. tauto. }
1971
+ assert (Int.signed j <> 0).
1972
+ { red; intros. rewrite <- (Int.repr_signed j) in E. rewrite H1 in E. discriminate. }
1973
+ set (q := srange x + 1 - Z.log2 (Z.abs (Int.signed j))).
1974
+ set (q1 := Z.max 0 ((srange x - 1) + 1 - Z.log2 (Z.abs (Int.signed j)))).
1975
+ assert (Z.max 1 q - 1 = q1) by lia.
1976
+ assert (vmatch (Vint (Int.divs i j)) (sgn (provenance x) q)).
1977
+ { apply srange_sound in H. destruct H as [A B]. apply range_is_sgn in B; auto.
1978
+ apply vmatch_sgn'. apply is_sgn_range. lia.
1979
+ rewrite ! H2. apply Zdiv_signed_range; auto. lia. }
1980
+ unfold divs; inv H; inv H0; auto with va; rewrite ? E, ? E'; auto with va.
1966
1981
Qed .
1967
1982
1968
1983
Definition divu (v w: aval) :=
1969
- match w, v with
1970
- | (I i2 | IU i2), (I i1 | IU i1) =>
1971
- if Int.eq i2 Int.zero
1972
- then if va_strict tt then Vbot else ntop
1973
- else I (Int.divu i1 i2)
1974
- | _, _ => ntop2 v w
1984
+ match w with
1985
+ | I i2 | IU i2 =>
1986
+ if Int.eq i2 Int.zero then
1987
+ if va_strict tt then Vbot else ntop
1988
+ else
1989
+ match v with
1990
+ | I i1 | IU i1 => I (Int.divu i1 i2)
1991
+ | _ => uns (provenance v) (urange v - Z.log2 (Int.unsigned i2))
1992
+ end
1993
+ | _ => ntop2 v w
1975
1994
end .
1976
1995
1977
1996
Lemma divu_sound:
1978
1997
forall v w u x y, vmatch v x -> vmatch w y -> Val.divu v w = Some u -> vmatch u (divu x y).
1979
1998
Proof .
1980
1999
intros. destruct v; destruct w; try discriminate; simpl in H1.
1981
- destruct (Int.eq i0 Int.zero) eqn:E; inv H1.
1982
- inv H; inv H0; auto with va; simpl; rewrite E; constructor.
2000
+ rename i0 into j. destruct (Int.eq j Int.zero) eqn:E; inv H1.
2001
+ assert (Int.unsigned j <> 0).
2002
+ { red; intros. rewrite <- (Int.repr_unsigned j) in E. rewrite H1 in E. discriminate. }
2003
+ assert (0 < Int.unsigned j).
2004
+ { pose proof (Int.unsigned_range j). lia. }
2005
+ assert (vmatch (Vint (Int.divu i j)) (uns (provenance x) (urange x - Z.log2 (Int.unsigned j)))).
2006
+ { apply urange_sound in H. destruct H as [A B]. apply range_is_uns in B; auto.
2007
+ apply vmatch_uns'. apply is_uns_range. lia.
2008
+ apply Zdiv_unsigned_range; auto. }
2009
+ unfold divu; inv H; inv H0; auto with va; rewrite E; auto with va.
1983
2010
Qed .
1984
2011
1985
2012
Definition mods (v w: aval) :=
0 commit comments