@@ -432,12 +432,11 @@ literalt bv_utilst::overflow_add(
432432 // An overflow occurs if the signs of the two operands are the same
433433 // and the sign of the sum is the opposite.
434434
435- literalt old_sign=op0[op0. size ()- 1 ] ;
436- literalt sign_the_same= prop.lequal (op0[op0. size ()- 1 ], op1[op1. size ()- 1 ] );
435+ literalt old_sign = sign_bit (op0) ;
436+ literalt sign_the_same = prop.lequal (sign_bit (op0), sign_bit (op1) );
437437
438438 bvt result=add (op0, op1);
439- return
440- prop.land (sign_the_same, prop.lxor (result[result.size ()-1 ], old_sign));
439+ return prop.land (sign_the_same, prop.lxor (sign_bit (result), old_sign));
441440 }
442441 else if (rep==representationt::UNSIGNED)
443442 {
@@ -457,7 +456,7 @@ literalt bv_utilst::overflow_sub(
457456 // x is negative, always representable, and
458457 // thus not an overflow.
459458 literalt op1_is_int_min=is_int_min (op1);
460- literalt op0_is_negative=op0[op0. size ()- 1 ] ;
459+ literalt op0_is_negative = sign_bit (op0) ;
461460
462461 return
463462 prop.lselect (op1_is_int_min,
@@ -557,7 +556,7 @@ bvt bv_utilst::shift(const bvt &src, const shiftt s, std::size_t dist)
557556 case shiftt::SHIFT_ARIGHT:
558557 // src.size()-i won't underflow as i<src.size()
559558 // Then, if dist<src.size()-i, then i+dist<src.size()
560- l=( dist< src.size ()-i? src[i+ dist]:src[src. size ()- 1 ]); // sign bit
559+ l = dist < src.size () - i ? src[i + dist] : sign_bit (src);
561560 break ;
562561
563562 case shiftt::SHIFT_LRIGHT:
@@ -608,7 +607,7 @@ literalt bv_utilst::overflow_negate(const bvt &bv)
608607 bvt should_be_zeros (bv);
609608 should_be_zeros.pop_back ();
610609
611- return prop.land (bv[bv. size () - 1 ] , !prop.lor (should_be_zeros));
610+ return prop.land (sign_bit (bv) , !prop.lor (should_be_zeros));
612611}
613612
614613void bv_utilst::incrementer (
@@ -1005,8 +1004,8 @@ bvt bv_utilst::signed_multiplier(const bvt &op0, const bvt &op1)
10051004 if (op0.empty () || op1.empty ())
10061005 return bvt ();
10071006
1008- literalt sign0=op0[op0. size ()- 1 ] ;
1009- literalt sign1=op1[op1. size ()- 1 ] ;
1007+ literalt sign0 = sign_bit (op0) ;
1008+ literalt sign1 = sign_bit (op1) ;
10101009
10111010 bvt neg0=cond_negate (op0, sign0);
10121011 bvt neg1=cond_negate (op1, sign1);
@@ -1034,7 +1033,7 @@ bvt bv_utilst::cond_negate(const bvt &bv, const literalt cond)
10341033bvt bv_utilst::absolute_value (const bvt &bv)
10351034{
10361035 PRECONDITION (!bv.empty ());
1037- return cond_negate (bv, bv[bv. size ()- 1 ] );
1036+ return cond_negate (bv, sign_bit (bv) );
10381037}
10391038
10401039bvt bv_utilst::cond_negate_no_overflow (const bvt &bv, literalt cond)
@@ -1051,15 +1050,15 @@ bvt bv_utilst::signed_multiplier_no_overflow(
10511050 if (op0.empty () || op1.empty ())
10521051 return bvt ();
10531052
1054- literalt sign0=op0[op0. size ()- 1 ] ;
1055- literalt sign1=op1[op1. size ()- 1 ] ;
1053+ literalt sign0 = sign_bit (op0) ;
1054+ literalt sign1 = sign_bit (op1) ;
10561055
10571056 bvt neg0=cond_negate_no_overflow (op0, sign0);
10581057 bvt neg1=cond_negate_no_overflow (op1, sign1);
10591058
10601059 bvt result=unsigned_multiplier_no_overflow (neg0, neg1);
10611060
1062- prop.l_set_to_false (result[result. size () - 1 ] );
1061+ prop.l_set_to_false (sign_bit (result) );
10631062
10641063 literalt result_sign=prop.lxor (sign0, sign1);
10651064
@@ -1112,8 +1111,8 @@ void bv_utilst::signed_divider(
11121111
11131112 bvt _op0 (op0), _op1 (op1);
11141113
1115- literalt sign_0=_op0[_op0. size ()- 1 ] ;
1116- literalt sign_1=_op1[_op1. size ()- 1 ] ;
1114+ literalt sign_0 = sign_bit (_op0) ;
1115+ literalt sign_1 = sign_bit (_op1) ;
11171116
11181117 bvt neg_0=negate (_op0), neg_1=negate (_op1);
11191118
@@ -1409,9 +1408,6 @@ literalt bv_utilst::lt_or_le(
14091408{
14101409 PRECONDITION (bv0.size () == bv1.size ());
14111410
1412- literalt top0=bv0[bv0.size ()-1 ],
1413- top1=bv1[bv1.size ()-1 ];
1414-
14151411#ifdef COMPACT_LT_OR_LE
14161412 if (prop.has_set_to () && prop.cnf_handled_well ())
14171413 {
@@ -1422,6 +1418,8 @@ literalt bv_utilst::lt_or_le(
14221418
14231419 if (rep == representationt::SIGNED)
14241420 {
1421+ literalt top0 = sign_bit (bv0), top1 = sign_bit (bv1);
1422+
14251423 if (top0.is_false () && top1.is_true ())
14261424 return const_literal (false );
14271425 else if (top0.is_true () && top1.is_false ())
@@ -1524,7 +1522,7 @@ literalt bv_utilst::lt_or_le(
15241522 literalt result;
15251523
15261524 if (rep==representationt::SIGNED)
1527- result= prop.lxor (prop.lequal (top0, top1 ), carry);
1525+ result = prop.lxor (prop.lequal (sign_bit (bv0), sign_bit (bv1) ), carry);
15281526 else
15291527 {
15301528 INVARIANT (
0 commit comments