-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
add simd_splat intrinsic
#151346
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 simd_splat intrinsic
#151346
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
folkertdev marked this conversation as resolved.
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| //@ compile-flags: -Copt-level=3 | ||
| #![crate_type = "lib"] | ||
| #![no_std] | ||
| #![feature(repr_simd, core_intrinsics)] | ||
| use core::intrinsics::simd::simd_splat; | ||
|
|
||
| #[path = "../../auxiliary/minisimd.rs"] | ||
| mod minisimd; | ||
| use minisimd::*; | ||
|
|
||
| // Test that `simd_splat` produces the canonical LLVM splat sequence. | ||
|
|
||
| #[no_mangle] | ||
| unsafe fn int(x: u16) -> u16x2 { | ||
| // CHECK-LABEL: int | ||
| // CHECK: start: | ||
| // CHECK-NEXT: %0 = insertelement <2 x i16> poison, i16 %x, i64 0 | ||
| // CHECK-NEXT: %1 = shufflevector <2 x i16> %0, <2 x i16> poison, <2 x i32> zeroinitializer | ||
|
Comment on lines
+17
to
+18
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. I remember LLVM had added a special splat syntax for producing this...
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. I don't see a way to do that in the C API, though, and I'm not sure if that is supported by the minimal LLVM version we support right now. I'm willing to r+ this Now as we can fix it later, but is there something I'm missing?
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. noting for posterity, nikic says:
and we are currently in the belief that this particular pattern gets rewritten into the
Contributor
Author
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.
My reading (based on some experiments) is that this means a compile-time known value. you can use define <2 x i16> @square2(i16 %x) local_unnamed_addr #0 {
ret <2 x i16> splat (i16 1)
}but it won't use local variables, this fails: define <2 x i16> @square2(i16 %x) local_unnamed_addr #0 {
ret <2 x i16> splat (i16 %x)
}with
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.
Ahhh, okay. |
||
| // CHECK-NEXT: store | ||
| // CHECK-NEXT: ret | ||
| simd_splat(x) | ||
| } | ||
|
|
||
| #[no_mangle] | ||
| unsafe fn float(x: f32) -> f32x4 { | ||
| // CHECK-LABEL: float | ||
| // CHECK: start: | ||
| // CHECK-NEXT: %0 = insertelement <4 x float> poison, float %x, i64 0 | ||
| // CHECK-NEXT: %1 = shufflevector <4 x float> %0, <4 x float> poison, <4 x i32> zeroinitializer | ||
| // CHECK-NEXT: store | ||
| // CHECK-NEXT: ret | ||
| simd_splat(x) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| //@ run-pass | ||
| #![feature(repr_simd, core_intrinsics)] | ||
|
|
||
| #[path = "../../../auxiliary/minisimd.rs"] | ||
| mod minisimd; | ||
| use minisimd::*; | ||
|
|
||
| use std::intrinsics::simd::simd_splat; | ||
|
|
||
| fn main() { | ||
| unsafe { | ||
| let x: Simd<u32, 1> = simd_splat(123u32); | ||
| let y: Simd<u32, 1> = const { simd_splat(123u32) }; | ||
| assert_eq!(x.into_array(), [123; 1]); | ||
| assert_eq!(x.into_array(), y.into_array()); | ||
|
|
||
| let x: u16x2 = simd_splat(42u16); | ||
| let y: u16x2 = const { simd_splat(42u16) }; | ||
| assert_eq!(x.into_array(), [42; 2]); | ||
| assert_eq!(x.into_array(), y.into_array()); | ||
|
|
||
| let x: u128x4 = simd_splat(42u128); | ||
| let y: u128x4 = const { simd_splat(42u128) }; | ||
| assert_eq!(x.into_array(), [42; 4]); | ||
| assert_eq!(x.into_array(), y.into_array()); | ||
|
|
||
| let x: i32x4 = simd_splat(-7i32); | ||
| let y: i32x4 = const { simd_splat(-7i32) }; | ||
| assert_eq!(x.into_array(), [-7; 4]); | ||
| assert_eq!(x.into_array(), y.into_array()); | ||
|
|
||
| let x: f32x4 = simd_splat(42.0f32); | ||
| let y: f32x4 = const { simd_splat(42.0f32) }; | ||
| assert_eq!(x.into_array(), [42.0; 4]); | ||
| assert_eq!(x.into_array(), y.into_array()); | ||
|
|
||
| let x: f64x2 = simd_splat(42.0f64); | ||
| let y: f64x2 = const { simd_splat(42.0f64) }; | ||
| assert_eq!(x.into_array(), [42.0; 2]); | ||
| assert_eq!(x.into_array(), y.into_array()); | ||
|
|
||
| static ZERO: u8 = 0u8; | ||
| let x: Simd<*const u8, 2> = simd_splat(&raw const ZERO); | ||
| let y: Simd<*const u8, 2> = const { simd_splat(&raw const ZERO) }; | ||
| assert_eq!(x.into_array(), [&raw const ZERO; 2]); | ||
| assert_eq!(x.into_array(), y.into_array()); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.