-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[Cranelift] add type-aware rotate operations #12764
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -128,6 +128,49 @@ macro_rules! isle_common_prelude_methods { | |
| Imm64::new((x >> y) & ty_mask) | ||
| } | ||
|
|
||
| #[inline] | ||
| fn imm64_rotl(&mut self, ty: Type, x: Imm64, y: Imm64) -> Imm64 { | ||
| let bits = ty.bits(); | ||
| assert!(bits <= 64); | ||
|
|
||
| let ty_mask = self.ty_mask(ty); | ||
| let x = (x.bits() as u64) & ty_mask; | ||
|
|
||
| // Mask off any excess rotate bits so the rotate stays within `ty`. | ||
| let shift_mask = bits - 1; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we put a |
||
| let y = ((y.bits() as u64) & u64::from(shift_mask)) as u32; | ||
|
|
||
| // In Rust, x >> 64 or x << 64 panics. | ||
| let result = if y == 0 { | ||
| x | ||
| } else { | ||
| (x << y) | (x >> (u32::from(bits) - y)) | ||
| }; | ||
|
|
||
| Imm64::new((result & ty_mask) as i64) | ||
| } | ||
|
|
||
| #[inline] | ||
| fn imm64_rotr(&mut self, ty: Type, x: Imm64, y: Imm64) -> Imm64 { | ||
| let bits = ty.bits(); | ||
| assert!(bits <= 64); | ||
|
|
||
| let ty_mask = self.ty_mask(ty); | ||
| let x = (x.bits() as u64) & ty_mask; | ||
|
|
||
| // Mask off any excess rotate bits so the rotate stays within `ty`. | ||
| let shift_mask = bits - 1; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Likewise here (debug-assert power-of-two). |
||
| let y = ((y.bits() as u64) & u64::from(shift_mask)) as u32; | ||
|
|
||
| let result = if y == 0 { | ||
| x | ||
| } else { | ||
| (x >> y) | (x << (u32::from(bits) - y)) | ||
| }; | ||
|
|
||
| Imm64::new((result & ty_mask) as i64) | ||
| } | ||
|
|
||
| #[inline] | ||
| fn i64_sextend_u64(&mut self, ty: Type, x: u64) -> i64 { | ||
| let shift_amt = core::cmp::max(0, 64 - ty.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.
Now that we have these helpers in the prelude, we should be able to implement rotl/rotr constant propagation rules too, right? It seems odd to have just the rule in this PR (for rotr-of-select-of-constants) -- can we add simple cprop as well?