Skip to content

bitreverse_exprt: Expression to reverse the order of bits #6581

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 2 commits into from
Jan 28, 2022

Conversation

tautschnig
Copy link
Collaborator

Clang has a __builtin_bitreverse (and at some point GCC might as well:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=50481).

Creating this as a draft: the actual implementation in the back-end is yet to be added, as are tests.

  • Each commit message has a non-empty body, explaining why the change was made.
  • Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • n/a The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • n/a My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

@codecov
Copy link

codecov bot commented Jan 21, 2022

Codecov Report

Merging #6581 (57e7b2c) into develop (9d91abc) will increase coverage by 0.00%.
The diff coverage is 80.00%.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #6581   +/-   ##
========================================
  Coverage    76.65%   76.65%           
========================================
  Files         1578     1579    +1     
  Lines       181219   181294   +75     
========================================
+ Hits        138907   138973   +66     
- Misses       42312    42321    +9     
Impacted Files Coverage Δ
src/ansi-c/expr2c_class.h 100.00% <ø> (ø)
src/solvers/flattening/boolbv.h 62.50% <ø> (ø)
src/util/simplify_expr_class.h 90.47% <ø> (ø)
src/ansi-c/expr2c.cpp 65.78% <10.00%> (-0.27%) ⬇️
src/ansi-c/c_typecheck_expr.cpp 76.53% <71.42%> (-0.04%) ⬇️
src/solvers/flattening/boolbv_bitreverse.cpp 85.71% <85.71%> (ø)
src/util/simplify_expr_int.cpp 85.09% <92.85%> (+0.22%) ⬆️
src/solvers/flattening/boolbv.cpp 80.50% <100.00%> (+0.11%) ⬆️
src/solvers/smt2/smt2_conv.cpp 67.57% <100.00%> (+0.05%) ⬆️
src/util/bitvector_expr.cpp 94.59% <100.00%> (+0.65%) ⬆️
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 23306ee...57e7b2c. Read the comment docs.

Copy link
Contributor

@chrisr-diffblue chrisr-diffblue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks great to me. Given the effort that went into removing unstructure exceptions in the error reporting previously, it seems a shame to be adding a throw 0 back in here - so could I kindly ask if that could be replaced with a structured exception? It'd be an approval from me if that were done :-)

Comment on lines 3250 to 3252
error().source_location = f_op.source_location();
error() << identifier << " expects one operand" << eom;
throw 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throw a structured exception?

Suggested change
error().source_location = f_op.source_location();
error() << identifier << " expects one operand" << eom;
throw 0;
std::ostringstream error_message;
error_message << expr.source_location().as_string() << ": " << identifier
<< " expects expects one operand";
throw invalid_source_file_exceptiont{error_message.str()};

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, but I really wish we had #5837 (with its two dependencies) in place to make things even more structured!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And now also includes a test for this one :-)

@tautschnig tautschnig self-assigned this Jan 22, 2022
Copy link
Contributor

@chrisr-diffblue chrisr-diffblue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks for the updates - looks great to me... And given that I poked a raw nerve on the structured exception point - feel free to assign any PRs that need reviews/comments on that front to me. 👍

Clang has a __builtin_bitreverse (and at some point GCC might as well:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=50481).
If a back-end isn't sharing aware, repeated occurrence of the
operand-to-reverse could be costly.
@tautschnig tautschnig assigned tautschnig and unassigned kroening Jan 28, 2022
@tautschnig tautschnig merged commit 59155f9 into diffblue:develop Jan 28, 2022
@tautschnig tautschnig deleted the feature/bitreverse branch January 28, 2022 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants