-
Notifications
You must be signed in to change notification settings - Fork 989
Cleanup RTLIL::Const
#5316
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
Cleanup RTLIL::Const
#5316
Conversation
From taking a look at the changes in rtlil.cc and rtlil.h, this does look very promising |
4a7b22e
to
d9ef383
Compare
d9ef383
to
cd370bf
Compare
I've added a bunch of tests to Writing these tests revealed a regression due to my changes --- I was computing the hash value of a |
The upgrade from |
Providing only a const_iterator was a deliberate decision, I wonder if there are scenarios where somebody could accidentally get a bitvectorizing iterator when they only need a const_iterator. I'm guessing the purpose of the |
Both of those unconditionally bitvectorize, so I think nothing is changing here. |
The non-const iterator does not bitvectorize --- unless/until you write through the iterator, in which case it does. But if you're modifying bits then you would need to bitvectorize anyway, since currently we don't allow modifying the packed bits.
No. It's to catch writes to through the iterator, so we turn those into
Right! This code does not add support for patching string-backed consts. |
cd370bf
to
0f1d460
Compare
By the way, I didn't mention this anywhere, but maybe it's not obvious: we really benefit here from small-string optimization in the C++ standard library. I.e. for small strings (<= 15 bytes typically, which certainly includes the very common 32-bit constants), the string is not heap-allocated but instead stored directly in the |
There's a message in that last test log that makes no sense to me:
The relevant code is
so it's pretty obvious that I can't reproduce any test failures running UBSAN locally. I'll rebase to main and re-push and see if the error persists. |
It's complaining about the left hand side. Shifting 1 into the sign bit is UB in C. |
0f1d460
to
9d97862
Compare
You probably want |
9d97862
to
98a4072
Compare
Huh. Which means left-shift of any negative value is UB in C! I never knew that. Odd that it doesn't get reported locally. Possibly that got changed in my version of clang because C++20 makes left-shift of a negative number defined behavior. Anyway, fixed it (I hope) using |
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.
This looks good, mostly based on what @widlarizer had already reviewed and me reviewing a few specific things after coordinating internally on what was still left.
In particular, `Const::resize()`, `Const::set()`, and `Const::iterator`.
…ecaying to vector<State>
Now that we only call `bitvectorize()` in non-const methods, we can move the casting-away-const to only happen in `bitvectorize()`, which is deprecated so only some plugins (maybe) are using it. This means `const` `Const` methods don't change the underlying data, which means they'll be safe to use from multiple threads if/when we want to do that.
98a4072
to
fee2b89
Compare
What are the reasons/motivation for this change?
#5312 explains how
Const
is currently very inefficient. This PR fixes a lot of that.Explain how this is achieved.
The main piece of work here is to remove all direct calls to
Const::bits()
. We add some new APIs toConst
that callers can use instead. Then we make theConst(long long)
constructor use the packed bits representation (i.e.std::string
), and update variousConst
methods to work with that representation instead of downconverting tovector<State>
. On one of our large circuits, this significantly reduces the time spend inOptMergePass::hash_cell_parameters()
.I realize this is a huge PR. I should probably break it up into smaller PRs for actual review and merging. I'm putting it here so people can see what it looks like.
If applicable, please suggest to reviewers how they can test the change.
This shouldn't change any behavior. FWIW, after I created all the big patches to remove all calls to
Const::bits()
and got them to compile, Yosys tests only revealed one bug. So the number of latent bugs not caught by tests should hopefully be correspondingly low.