-
Notifications
You must be signed in to change notification settings - Fork 42
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
Refactor PRegSet. #178
Refactor PRegSet. #178
Conversation
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.
Thanks very much for this contribution! Two minor-nit comments below reflecting some preferences but nothing major; happy to have this generalization.
src/lib.rs
Outdated
/// Splits the given register index into parts to access the internal bit array. | ||
const fn split_index(reg: PReg) -> (usize, usize) { | ||
let index = reg.index(); | ||
(index / Self::BITS, index % Self::BITS) |
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.
It should be optimized via strength reduction but just to be sure in unoptimized builds: could we use shifts and masking here instead? AFAIK, BITS
will always be a power of two.
src/lib.rs
Outdated
let bits = self.bits.get_mut(self.cur)?; | ||
if *bits != 0 { | ||
let bit = bits.trailing_zeros(); | ||
*bits ^= 1 << bit; |
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.
Can we stick with the &= !(1 << bit)
form we had before, here? Equivalent in this case and not a huge deal either way, just a preference, but this form for me is slightly more clear in intent (clearing a bit, vs. XOR which I ordinarily see for flipping the bit).
The changes will make it easier to increase the number of physical registers and register classes in the future.
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.
Thanks!
The changes will make it easier to increase the number of physical registers and register classes in the future.