-
Notifications
You must be signed in to change notification settings - Fork 277
simplify extractbits_exprt
representation
#8246
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,43 +17,28 @@ bvt boolbvt::convert_extractbits(const extractbits_exprt &expr) | |
|
||
auto const &src_bv = convert_bv(expr.src()); | ||
|
||
auto const maybe_upper_as_int = numeric_cast<mp_integer>(expr.upper()); | ||
auto const maybe_lower_as_int = numeric_cast<mp_integer>(expr.lower()); | ||
auto const maybe_index_as_int = numeric_cast<mp_integer>(expr.index()); | ||
|
||
// We only do constants for now. | ||
// Should implement a shift here. | ||
if(!maybe_upper_as_int.has_value() || !maybe_lower_as_int.has_value()) | ||
if(!maybe_index_as_int.has_value()) | ||
return conversion_failed(expr); | ||
|
||
auto upper_as_int = maybe_upper_as_int.value(); | ||
auto lower_as_int = maybe_lower_as_int.value(); | ||
auto index_as_int = maybe_index_as_int.value(); | ||
|
||
DATA_INVARIANT_WITH_DIAGNOSTICS( | ||
upper_as_int >= 0 && upper_as_int < src_bv.size(), | ||
"upper end of extracted bits must be within the bitvector", | ||
index_as_int >= 0 && index_as_int < src_bv.size(), | ||
"index of extractbits must be within the bitvector", | ||
expr.find_source_location(), | ||
irep_pretty_diagnosticst{expr}); | ||
|
||
DATA_INVARIANT_WITH_DIAGNOSTICS( | ||
lower_as_int >= 0 && lower_as_int < src_bv.size(), | ||
"lower end of extracted bits must be within the bitvector", | ||
index_as_int + bv_width - 1 < src_bv.size(), | ||
"index+width-1 of extractbits must be within the bitvector", | ||
expr.find_source_location(), | ||
irep_pretty_diagnosticst{expr}); | ||
|
||
DATA_INVARIANT( | ||
lower_as_int <= upper_as_int, | ||
"upper bound must be greater or equal to lower bound"); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing invariants because that case is simply not possible seems like a good thing. |
||
// now lower_as_int <= upper_as_int | ||
|
||
DATA_INVARIANT_WITH_DIAGNOSTICS( | ||
(upper_as_int - lower_as_int + 1) == bv_width, | ||
"the difference between upper and lower end of the range must have the " | ||
"same width as the resulting bitvector type", | ||
expr.find_source_location(), | ||
irep_pretty_diagnosticst{expr}); | ||
|
||
const std::size_t offset = numeric_cast_v<std::size_t>(lower_as_int); | ||
const std::size_t offset = numeric_cast_v<std::size_t>(index_as_int); | ||
|
||
bvt result_bv(src_bv.begin() + offset, src_bv.begin() + offset + bv_width); | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,8 +28,7 @@ Author: Romain Brenguier, [email protected] | |
/// in octuple precision. | ||
exprt get_exponent(const exprt &src, const ieee_float_spect &spec) | ||
{ | ||
const extractbits_exprt exp_bits( | ||
src, spec.f + spec.e - 1, spec.f, unsignedbv_typet(spec.e)); | ||
const extractbits_exprt exp_bits(src, spec.f, unsignedbv_typet(spec.e)); | ||
|
||
// Exponent is in biased form (numbers from -128 to 127 are encoded with | ||
// integer from 0 to 255) we have to remove the bias. | ||
|
@@ -44,7 +43,7 @@ exprt get_exponent(const exprt &src, const ieee_float_spect &spec) | |
/// \return An unsigned value representing the fractional part. | ||
exprt get_fraction(const exprt &src, const ieee_float_spect &spec) | ||
{ | ||
return extractbits_exprt(src, spec.f - 1, 0, unsignedbv_typet(spec.f)); | ||
return extractbits_exprt(src, 0, unsignedbv_typet(spec.f)); | ||
} | ||
|
||
/// Gets the significand as a java integer, looking for the hidden bit. | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this result in syntactically invalid C being generated? If so, is that a problem and would it be better to throw some kind of error or have an invariant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The expr2X functions are designed to generate some string when given an unknown expression -- this should be added to the documentation.