Skip to content

Commit

Permalink
[fix, bitwuzla] Returned API calls to construct Shl, Shr and AShr exp…
Browse files Browse the repository at this point in the history
…ressions.
  • Loading branch information
S1eGa committed Nov 20, 2023
1 parent a9ae83d commit f2304ff
Showing 1 changed file with 3 additions and 30 deletions.
33 changes: 3 additions & 30 deletions lib/Solver/BitwuzlaBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,7 @@ Term BitwuzlaBuilder::bvVarLeftShift(Term expr, Term shift) {
Term shiftAsBv = castToBitVector(shift);

unsigned width = getBVLength(exprAsBv);
Term res = bvZero(width);

// construct a big if-then-elif-elif-... with one case per possible shift
// amount
for (int i = width - 1; i >= 0; i--) {
res = iteExpr(eqExpr(shiftAsBv, bvConst32(width, i)),
bvLeftShift(exprAsBv, i), res);
}
Term res = mk_term(Kind::BV_SHL, {exprAsBv, shiftAsBv});

// If overshifting, shift to zero
Term ex = bvLtExpr(shiftAsBv, bvConst32(getBVLength(shiftAsBv), width));
Expand All @@ -209,14 +202,7 @@ Term BitwuzlaBuilder::bvVarRightShift(Term expr, Term shift) {
Term shiftAsBv = castToBitVector(shift);

unsigned width = getBVLength(exprAsBv);
Term res = bvZero(width);

// construct a big if-then-elif-elif-... with one case per possible shift
// amount
for (int i = width - 1; i >= 0; i--) {
res = iteExpr(eqExpr(shiftAsBv, bvConst32(width, i)),
bvRightShift(exprAsBv, i), res);
}
Term res = mk_term(Kind::BV_SHR, {exprAsBv, shiftAsBv});

// If overshifting, shift to zero
Term ex = bvLtExpr(shiftAsBv, bvConst32(getBVLength(shiftAsBv), width));
Expand All @@ -232,20 +218,7 @@ Term BitwuzlaBuilder::bvVarArithRightShift(Term expr, Term shift) {

unsigned width = getBVLength(exprAsBv);

// get the sign bit to fill with
Term signedBool = bvBoolExtract(exprAsBv, width - 1);

// start with the result if shifting by width-1
Term res = constructAShrByConstant(exprAsBv, width - 1, signedBool);

// construct a big if-then-elif-elif-... with one case per possible shift
// amount
// XXX more efficient to move the ite on the sign outside all exprs?
// XXX more efficient to sign extend, right shift, then extract lower bits?
for (int i = width - 2; i >= 0; i--) {
res = iteExpr(eqExpr(shiftAsBv, bvConst32(width, i)),
constructAShrByConstant(exprAsBv, i, signedBool), res);
}
Term res = mk_term(Kind::BV_ASHR, {exprAsBv, shiftAsBv});

// If overshifting, shift to zero
Term ex = bvLtExpr(shiftAsBv, bvConst32(getBVLength(shiftAsBv), width));
Expand Down

0 comments on commit f2304ff

Please sign in to comment.