-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Add SIMD funnel shift and round-to-even intrinsics #142078
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: master
Are you sure you want to change the base?
Conversation
r? @wesleywiser rustbot has assigned @wesleywiser. Use |
Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr Some changes occurred to the platform-builtins intrinsics. Make sure the cc @antoyo, @GuillaumeGomez, @bjorn3, @calebzulawski, @programmerjake |
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.
I believe you'd also need to implement this operation in MIRI.
Please add Miri to the list. :) (Doesn't have to be in the first PR.) |
Both |
You should be able to have more or less the same implementation for cg_gcc by putting the code in this file. The complicated part is to find the equivalent intrinsic names for GCC. |
If you want to block this PR on submitting a T-libs-api ACP, you can do that, but I don't see why you would. |
I only found the intrinsic name for x86 as
I don't think this should blocked on adding these to int types, just thought this might be a nice place to discuss it. I will go ahead and submit an independent ACP for that |
It seems GCC doesn't have an arch-independent builtin for this, so I guess it's better for this PR to not implement the intrinsic for cg_gcc. |
ok thanks |
Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 Some changes occurred in compiler/rustc_codegen_gcc |
I have implemented |
The Miri subtree was changed cc @rust-lang/miri |
library/core/src/intrinsics/simd.rs
Outdated
pub unsafe fn simd_fshl<T>(a: T, b: T, shift: T) -> T; | ||
|
||
/// Funnel Shifts vector right elementwise, with UB on overflow. | ||
/// | ||
/// Concatenates `a` and `b` elementwise (with `a` in the most significant half), | ||
/// creating a vector of the same length, but with each element being twice as | ||
/// wide. Then shift this vector right elementwise by `shift`, shifting in zeros, | ||
/// and extract the least significant half of each of the elements. If `a` and `b` | ||
/// are the same, this is equivalent to an elementwise rotate right operation. | ||
/// | ||
/// `T` must be a vector of integers. | ||
/// | ||
/// # Safety | ||
/// | ||
/// Each element of `shift` must be less than `<int>::BITS`. | ||
#[rustc_intrinsic] | ||
#[rustc_nounwind] | ||
pub unsafe fn simd_fshr<T>(a: T, b: T, shift: T) -> T; |
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.
So, I have been thinking and I can't get over the bit where the current mnemonic sounds like it has something to do with floats in my head. I think we might want to call out these names as simd_funnel_shl
and simd_funnel_shr
? I looked around and we get names like __funnelshift_lc
and __funnelshift_rc
for similar intrinsics (e.g. CUDA), and I know that some languages actually do support shifts on floats, with... sometimes interesting semantics.
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.
Yeah, simd_funnel_sh{l,r}
sounds nice enough (with the scalar functions as funnel_sh{l,r}
). I will change the name
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.
I have changed the names. Btw @workingjubilee as you seem to be interested, should I r?
you?
simd_fsh{l,r}
and simd_round_ties_even
This PR adds 3 new SIMD intrinsics
simd_funnel_shl
- funnel shift leftsimd_funnel_shr
- funnel shift rightsimd_round_ties_even
(vector version ofround_ties_even_fN
)TODO: implement
simd_fsh{l,r}
in miri, cg_gcc and cg_clif#t-compiler > More SIMD intrinsics
@rustbot label T-compiler T-libs A-intrinsics F-core_intrinsics
cc @workingjubilee