[Proposal]: New operator for rotate shift #4685
Unanswered
anchurcn
asked this question in
Language Ideas
Replies: 1 comment 2 replies
-
This def feels like something a method could be exposed for. It could presumably be implemented by the jit with whatever smarts are needed. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
New operator for rotate shift
Summary
Bits operation is common in primitive integers.
There have been SHR(Shift Right) operator and SHL(Shift Left) operator for unsigned integers.
Also SAR(Shift Arithmetic Right) operator and SAL(Shift Arithmetic Left) operator are for signed integers.
But there are no operators for rotate shift operations.
Motivation
If we want transform 0xAABBCCDD into 0xDDAABBCC,
we need to write a long expression.
If new operators come, we have a more elegant way.
Assume >>> is a new operator for ROR(Rotate Right) operation.
Detailed design
IL may not have direct instructions for ROR or ROL, we can just express it as
(value << (nBits - n) | value >> n) or (value << (nBits - n) | value >> n) in IL.
But I think JIT compiler will generate the best assembly for the target platform.
Drawbacks
Alternatives
Unresolved questions
Design meetings
Beta Was this translation helpful? Give feedback.
All reactions