Skip to content

Bitvectors are now hexadecimal #3107

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 1 commit into from
Nov 5, 2018
Merged

Bitvectors are now hexadecimal #3107

merged 1 commit into from
Nov 5, 2018

Conversation

kroening
Copy link
Member

@kroening kroening commented Oct 6, 2018

  • Each commit message has a non-empty body, explaining why the change was made.
  • My contribution is formatted in line with CODING_STANDARD.md.
  • Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • 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).
  • My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • White-space or formatting changes outside the feature-related changed lines are in commits of their own.

Note that an alternative would be to go to a binary representation, which is not much different compared to this PR. This would save another 2x in memory, but has the disadvantage that ireps are then more difficult to read.

This will require a bump in the goto-binary version number, which I would prefer to do together with a few other changes.

@kroening
Copy link
Member Author

Now cleaned up! The B256 option is now in a separate PR.

@kroening kroening mentioned this pull request Oct 19, 2018
5 tasks
Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

This PR failed Diffblue compatibility checks (cbmc commit: 6b999bc).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/88546710
Status will be re-evaluated on next push.
Please contact @peterschrammel, @thk123, or @allredj for support.

Common spurious failures:

  • the cbmc commit has disappeared in the mean time (e.g. in a force-push)
  • the author is not in the list of contributors (e.g. first-time contributors).

The incompatibility may have been introduced by an earlier PR. In that case merging this
PR should be avoided unless it fixes the current incompatibility.

Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

Passed Diffblue compatibility checks (cbmc commit: 0e37e1f).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/88550170

Copy link
Collaborator

@tautschnig tautschnig left a comment

Choose a reason for hiding this comment

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

Sorry, still an incomplete review, sending the below comments and will do further reviews once those are addressed.


char nibble = src[src.size() - 1 - nibble_index];

DATA_INVARIANT(isxdigit(nibble), "");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Still to be addressed.

return src[src.size() - 1 - bit_index] == '1';

// The representation is hex, most significant nibble first.
const auto nibble_index = bit_index >> 2;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe leave the optimisation that "divide by 4" is a shift by 2 to the compiler? I don't think doing those optimisations help readability.

const auto nibble_index = bit_index >> 2;

if(nibble_index >= src.size())
return false;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This needs to be changed now that #3196 has been merged to re-instate the PRECONDITION.

if(nibble_index >= src.size())
return false;

char nibble = src[src.size() - 1 - nibble_index];
Copy link
Collaborator

Choose a reason for hiding this comment

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

const

@@ -299,12 +323,36 @@ bool get_bvrep_bit(
irep_idt
make_bvrep(const std::size_t width, const std::function<bool(std::size_t)> f)
{
std::string result(width, ' ');
std::string result;
result.reserve(width / 4 + 1);
Copy link
Collaborator

Choose a reason for hiding this comment

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

  1. If doing the division-by-power-of-two-is-shift then it should be done everywhere (or, my preference: nowhere)
  2. (width + 3) / 4 will avoid reserving an unnecessary extra space.

std::string result(width, ' ');
std::string result;
result.reserve(width / 4 + 1);
unsigned nibble = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

char?


return result;
nibble |= ((unsigned)f(i)) << bit_in_nibble;
Copy link
Collaborator

Choose a reason for hiding this comment

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

What about:

if(f(i))
  nibble |= 1u << bit_in_nibble;

Not sure to what extent performance would differ given the additional branch, though.


// drop leading zeros
while(!result.empty() && result.back() == '0')
result.resize(result.size() - 1);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use rfind and a single resize.

@kroening kroening assigned tautschnig and unassigned kroening Oct 19, 2018
@kroening kroening force-pushed the hex-bitvectors5 branch 2 times, most recently from a91718a to b366d8b Compare October 20, 2018 09:16
Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

Passed Diffblue compatibility checks (cbmc commit: b366d8b).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/88622003

@tautschnig tautschnig assigned kroening and unassigned tautschnig Oct 20, 2018
@tautschnig tautschnig assigned martin-cs and unassigned kroening Oct 20, 2018
@kroening kroening force-pushed the hex-bitvectors5 branch 3 times, most recently from a9826b6 to 103d74c Compare October 23, 2018 16:21
Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

This PR failed Diffblue compatibility checks (cbmc commit: a9826b6).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/88886344
Status will be re-evaluated on next push.
Please contact @peterschrammel, @thk123, or @allredj for support.

Common spurious failures:

  • the cbmc commit has disappeared in the mean time (e.g. in a force-push)
  • the author is not in the list of contributors (e.g. first-time contributors).

The incompatibility may have been introduced by an earlier PR. In that case merging this
PR should be avoided unless it fixes the current incompatibility.

Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

Passed Diffblue compatibility checks (cbmc commit: 103d74c).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/88888437

Simultaneously leading zeros are dropped.  This reduces the memory
consumption of bit-vectors by 4x or more.
Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

✔️
Passed Diffblue compatibility checks (cbmc commit: c7c4110).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/90285596

Copy link
Collaborator

@martin-cs martin-cs left a comment

Choose a reason for hiding this comment

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

I think everything I raised has been resolved or removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants