@@ -1201,22 +1201,31 @@ literalt bv_utilst::lt_or_le(
1201
1201
size_t start;
1202
1202
size_t i;
1203
1203
1204
- compareBelow = prop.new_variables (bv0.size ());
1205
- result = prop.new_variable ();
1206
-
1207
1204
if (rep == representationt::SIGNED)
1208
1205
{
1206
+ if (top0.is_false () && top1.is_true ())
1207
+ return const_literal (false );
1208
+ else if (top0.is_true () && top1.is_false ())
1209
+ return const_literal (true );
1210
+
1209
1211
INVARIANT (
1210
1212
bv0.size () >= 2 , " signed bitvectors should have at least two bits" );
1211
- start = compareBelow.size () - 2 ;
1213
+ compareBelow = prop.new_variables (bv0.size () - 1 );
1214
+ start = compareBelow.size () - 1 ;
1212
1215
1213
- literalt firstComp=compareBelow[start];
1216
+ literalt &firstComp = compareBelow[start];
1217
+ if (top0.is_false ())
1218
+ firstComp = !top1;
1219
+ else if (top0.is_true ())
1220
+ firstComp = top1;
1221
+ else if (top1.is_false ())
1222
+ firstComp = !top0;
1223
+ else if (top1.is_true ())
1224
+ firstComp = top0;
1214
1225
1215
- // When comparing signs we are comparing the top bit
1216
- #ifdef INCLUDE_REDUNDANT_CLAUSES
1217
- prop.l_set_to_true (compareBelow[start + 1 ])
1218
- #endif
1226
+ result = prop.new_variable ();
1219
1227
1228
+ // When comparing signs we are comparing the top bit
1220
1229
// Four cases...
1221
1230
prop.lcnf (top0, top1, firstComp); // + + compare needed
1222
1231
prop.lcnf (top0, !top1, !result); // + - result false and no compare needed
@@ -1231,8 +1240,10 @@ literalt bv_utilst::lt_or_le(
1231
1240
else
1232
1241
{
1233
1242
// Unsigned is much easier
1243
+ compareBelow = prop.new_variables (bv0.size () - 1 );
1244
+ compareBelow.push_back (const_literal (true ));
1234
1245
start = compareBelow.size () - 1 ;
1235
- prop.l_set_to_true (compareBelow[start] );
1246
+ result = prop.new_variable ( );
1236
1247
}
1237
1248
1238
1249
// Determine the output
@@ -1241,6 +1252,16 @@ literalt bv_utilst::lt_or_le(
1241
1252
i = start;
1242
1253
do
1243
1254
{
1255
+ if (compareBelow[i].is_false ())
1256
+ continue ;
1257
+ else if (compareBelow[i].is_true ())
1258
+ {
1259
+ if (bv0[i].is_false () && bv1[i].is_true ())
1260
+ return const_literal (true );
1261
+ else if (bv0[i].is_true () && bv1[i].is_false ())
1262
+ return const_literal (false );
1263
+ }
1264
+
1244
1265
prop.lcnf (!compareBelow[i], bv0[i], !bv1[i], result);
1245
1266
prop.lcnf (!compareBelow[i], !bv0[i], bv1[i], !result);
1246
1267
}
0 commit comments