summaryrefslogtreecommitdiffstats
path: root/src/test/ui/simd/simd-bitmask.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/test/ui/simd/simd-bitmask.rs
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/simd/simd-bitmask.rs')
-rw-r--r--src/test/ui/simd/simd-bitmask.rs52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/test/ui/simd/simd-bitmask.rs b/src/test/ui/simd/simd-bitmask.rs
new file mode 100644
index 000000000..14ee2e741
--- /dev/null
+++ b/src/test/ui/simd/simd-bitmask.rs
@@ -0,0 +1,52 @@
+//run-pass
+//ignore-endian-big behavior of simd_select_bitmask is endian-specific
+#![feature(repr_simd, platform_intrinsics)]
+
+extern "platform-intrinsic" {
+ fn simd_bitmask<T, U>(v: T) -> U;
+ fn simd_select_bitmask<T, U>(m: T, a: U, b: U) -> U;
+}
+
+#[derive(Copy, Clone)]
+#[repr(simd)]
+struct Simd<T, const N: usize>([T; N]);
+
+fn main() {
+ unsafe {
+ let v = Simd::<i8, 4>([-1, 0, -1, 0]);
+ let i: u8 = simd_bitmask(v);
+ let a: [u8; 1] = simd_bitmask(v);
+
+ assert_eq!(i, 0b0101);
+ assert_eq!(a, [0b0101]);
+
+ let v = Simd::<i8, 16>([0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, -1, 0]);
+ let i: u16 = simd_bitmask(v);
+ let a: [u8; 2] = simd_bitmask(v);
+
+ assert_eq!(i, 0b0101000000001100);
+ assert_eq!(a, [0b1100, 0b01010000]);
+ }
+
+ unsafe {
+ let a = Simd::<i32, 8>([0, 1, 2, 3, 4, 5, 6, 7]);
+ let b = Simd::<i32, 8>([8, 9, 10, 11, 12, 13, 14, 15]);
+ let e = [0, 9, 2, 11, 12, 13, 14, 15];
+
+ let r = simd_select_bitmask(0b0101u8, a, b);
+ assert_eq!(r.0, e);
+
+ let r = simd_select_bitmask([0b0101u8], a, b);
+ assert_eq!(r.0, e);
+
+ let a = Simd::<i32, 16>([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]);
+ let b = Simd::<i32, 16>([16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]);
+ let e = [16, 17, 2, 3, 20, 21, 22, 23, 24, 25, 26, 27, 12, 29, 14, 31];
+
+ let r = simd_select_bitmask(0b0101000000001100u16, a, b);
+ assert_eq!(r.0, e);
+
+ let r = simd_select_bitmask([0b1100u8, 0b01010000u8], a, b);
+ assert_eq!(r.0, e);
+ }
+}