Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix precondition of conditionalNegate() #6

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions core/convert.h
Original file line number Diff line number Diff line change
Expand Up @@ -483,17 +483,23 @@ template <class t>

// Put the result together
bwt roundSigWidth(rounded.significand.getWidth());
prop msbSet(rounded.significand.extract(roundSigWidth - 1,
roundSigWidth - 1).isAllOnes());
// -2^{n-1} is the only safe "overflow" case
prop safeOverflow(input.getSign() &&
msbSet &&
rounded.significand.extract(roundSigWidth - 2,
0).isAllZeros());
prop undefinedResult(earlyUndefinedResult ||
rounded.incrementExponent || // Definite Overflow
(rounded.significand.extract(roundSigWidth - 1,
roundSigWidth - 1).isAllOnes() &&
!(input.getSign() && rounded.significand.extract(roundSigWidth - 2, 0).isAllZeros()))); // -2^{n-1} is the only safe "overflow" case


sbv result(ITE(undefinedResult,
undefValue,
conditionalNegate<t,sbv,prop>(input.getSign(), rounded.significand.toSigned())));

rounded.incrementExponent || // Definite Overflow
(msbSet && !safeOverflow));

sbv definedResult(
ITE(safeOverflow,
rounded.significand.toSigned(),
conditionalNegate<t,sbv,prop>(input.getSign(),
rounded.significand.toSigned())));
sbv result(ITE(undefinedResult, undefValue, definedResult));
return result;
}

Expand Down
8 changes: 6 additions & 2 deletions core/operations.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,12 @@ namespace symfpu {
bv conditionalNegate (const prop &p, const bv &b) {
typename t::bwt w(b.getWidth());
PRECONDITION(w >= 2);
PRECONDITION(IMPLIES(p, !(b.extract(w - 1, w - 1).isAllOnes() &&
b.extract(w - 2, 0).isAllZeros())));
// We may be tempted to check that we are not trying to negate the smallest
// value that can be represented using two's complement (i.e., `100...0`).
// This is problematic, however, in cases where we apply
// `conditionalNegate()` conditionally (e.g., in `convertFloatToSBV()`),
// because the arguments to the branches are evaluated eagerly, so the
// assertion fails, even though the result is not used.

return bv(ITE(p, -b, b));
}
Expand Down