-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Add ror and rol functions for rotating bits #33937
Conversation
Welcome, and thanks for the contribution! This is a very nice and tidy first PR, great work. The only thing it needs is a compat annotation in the docstrings of the added functions, e.g.
|
Could at least one of the examples show wrap-around? |
Do we really need two functions for this, since Should we call it |
This is great, thank you! It looks like constant folding can handle the
This would, of course, just rely upon duck-typing (the lack of a |
This comment has been minimized.
This comment has been minimized.
I don't think it fits the generic definition of |
That's a very good point. |
One thing that I think would be helpful would be a first-class |
I know that llvm and assembly gives these rather cryptic names (fshl and fshr, https://llvm.org/docs/LangRef.html#llvm-fshl-intrinsic), but I feel like these may be just far enough outside the standard lexicon that they should use names instead of abbreviations. Maybe rotateright and rotateleft?
True, but the complementary set of shift operators ( |
I still don't understand why we need two functions here when a negative shift works fine. If we don't like |
|
Ok, nice. I guess now the question is which way should be the default rotation direction? Is it just me or does left rotation, i.e. towards more significant bits, seem like the natural positive direction? |
Here are some cases of functions named bitrotate:
They all consider positive shifts to rotate left and negative shifts to rotate right. It seems like the primary reason for having left and right rotate functions is this potential ambiguity. |
I tried to keep it consistent with |
"Left" and "right" are ambiguous labels.
|
That's also what all the versions I linked to do. It also makes more sense to me that positive bit rotation should increase the power of each bit while negative bit rotation should decrease it. |
I had missed that you updated this to shift bits in the right (left) direction. This looks good to me. |
You seem to have force pushed over my merge of this, in which I tweaked the NEWS entry for |
Thanks for the contribution! |
Closes: #11592