Skip to content

Commit

Permalink
[fix, bitwuzla] Implemented sign extension for widths greater then 64.
Browse files Browse the repository at this point in the history
  • Loading branch information
S1eGa committed Nov 20, 2023
1 parent 7b524ea commit a9ae83d
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/Solver/BitwuzlaBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,18 @@ Term BitwuzlaBuilder::bvSignExtend(Term src, unsigned width) {
Term srcAsBv = castToBitVector(src);
unsigned src_width = srcAsBv.sort().bv_size();
assert(src_width <= width && "attempted to extend longer data");
assert(width < CHAR_BIT * sizeof(uint64_t) &&
"bitwuzla does not support sext for width more than 64 bit");
return mk_term(Kind::BV_SIGN_EXTEND, {srcAsBv}, {width - src_width});

if (width <= 64) {
return mk_term(Kind::BV_SIGN_EXTEND, {srcAsBv}, {width - src_width});
}

Term signBit = bvBoolExtract(srcAsBv, src_width - 1);
Term zeroExtended =
mk_term(Kind::BV_CONCAT, {bvZero(width - src_width), src});
Term oneExtended =
mk_term(Kind::BV_CONCAT, {bvMinusOne(width - src_width), src});

return mk_term(Kind::ITE, {signBit, oneExtended, zeroExtended});
}

Term BitwuzlaBuilder::writeExpr(Term array, Term index, Term value) {
Expand Down

0 comments on commit a9ae83d

Please sign in to comment.