Skip to content

Commit 6910a4e

Browse files
Fix to_fp_signed (#7034)
1 parent ea3628e commit 6910a4e

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

src/ast/fpa/fpa2bv_converter.cpp

+5-11
Original file line numberDiff line numberDiff line change
@@ -3039,7 +3039,7 @@ void fpa2bv_converter::mk_to_fp_signed(func_decl * f, unsigned num, expr * const
30393039
// Special case: x == 0 -> +zero
30403040
expr_ref c1(m), v1(m);
30413041
c1 = is_zero;
3042-
v1 = pzero; // No -zero? zeros_consistent_4.smt2 requires +zero.
3042+
v1 = pzero; // No -zero (IEEE754)
30433043

30443044
// Special case: x != 0
30453045
expr_ref sign_bit(m), exp_too_large(m), sig_4(m), exp_2(m), rest(m);
@@ -3048,18 +3048,13 @@ void fpa2bv_converter::mk_to_fp_signed(func_decl * f, unsigned num, expr * const
30483048
rest = m_bv_util.mk_extract(bv_sz - 2, 0, x);
30493049
dbg_decouple("fpa2bv_to_fp_signed_rest", rest);
30503050
is_neg = m.mk_eq(sign_bit, bv1_1);
3051-
neg_x = m_bv_util.mk_bv_neg(x);
3051+
neg_x = m_bv_util.mk_bv_neg(x); // overflow ok, x_abs is now unsigned.
30523052
x_abs = m.mk_ite(is_neg, neg_x, x);
30533053
dbg_decouple("fpa2bv_to_fp_signed_is_neg", is_neg);
3054+
dbg_decouple("fpa2bv_to_fp_signed_x_abs", x_abs);
30543055
// x_abs has an extra bit in the front.
30553056
// x_abs is [bv_sz-1, bv_sz-2] . [bv_sz-3 ... 0] * 2^(bv_sz-2)
30563057
// bv_sz-2 is the "1.0" bit for the rounder.
3057-
expr_ref is_max_neg(m);
3058-
is_max_neg = m.mk_and(is_neg, m.mk_eq(rest, m_bv_util.mk_numeral(0, bv_sz-1)));
3059-
dbg_decouple("fpa2bv_to_fp_signed_is_max_neg", is_max_neg);
3060-
3061-
x_abs = m.mk_ite(is_max_neg, m_bv_util.mk_concat(bv1_1, m_bv_util.mk_numeral(0, bv_sz-1)), x_abs);
3062-
dbg_decouple("fpa2bv_to_fp_signed_x_abs", x_abs);
30633058

30643059
expr_ref lz(m);
30653060
mk_leading_zeros(x_abs, bv_sz, lz);
@@ -3094,7 +3089,6 @@ void fpa2bv_converter::mk_to_fp_signed(func_decl * f, unsigned num, expr * const
30943089
expr_ref s_exp(m), exp_rest(m);
30953090
s_exp = m_bv_util.mk_bv_sub(m_bv_util.mk_numeral(bv_sz - 2, bv_sz), lz);
30963091
// s_exp = (bv_sz-2) + (-lz) signed
3097-
s_exp = m.mk_ite(is_max_neg, m_bv_util.mk_bv_sub(s_exp, m_bv_util.mk_numeral(1, bv_sz)), s_exp);
30983092
SASSERT(m_bv_util.get_bv_size(s_exp) == bv_sz);
30993093
dbg_decouple("fpa2bv_to_fp_signed_s_exp", s_exp);
31003094

@@ -3109,7 +3103,7 @@ void fpa2bv_converter::mk_to_fp_signed(func_decl * f, unsigned num, expr * const
31093103

31103104
TRACE("fpa2bv_to_fp_signed", tout << "exp worst case sz: " << exp_worst_case_sz << std::endl;);
31113105

3112-
if (exp_sz < exp_worst_case_sz) {
3106+
if (exp_sz <= exp_worst_case_sz) {
31133107
// exp_sz < exp_worst_case_sz and exp >= 0.
31143108
// Take the maximum legal exponent; this
31153109
// allows us to keep the most precision.
@@ -3188,7 +3182,7 @@ void fpa2bv_converter::mk_to_fp_unsigned(func_decl * f, unsigned num, expr * con
31883182
// Special case: x == 0 -> +zero
31893183
expr_ref c1(m), v1(m);
31903184
c1 = is_zero;
3191-
v1 = pzero; // No nzero?
3185+
v1 = pzero; // No -zero (IEEE754)
31923186

31933187
// Special case: x != 0
31943188
expr_ref exp_too_large(m), sig_4(m), exp_2(m);

0 commit comments

Comments
 (0)