]> git.lizzy.rs Git - rust.git/blob - tests/codegen/simd-intrinsic/simd-intrinsic-generic-bitmask.rs
Rollup merge of #104965 - zacklukem:p-option-as_ref-docs, r=scottmcm
[rust.git] / tests / codegen / simd-intrinsic / simd-intrinsic-generic-bitmask.rs
1 // compile-flags: -C no-prepopulate-passes
2 //
3
4 #![crate_type = "lib"]
5
6 #![feature(repr_simd, platform_intrinsics)]
7 #![allow(non_camel_case_types)]
8
9 #[repr(simd)]
10 #[derive(Copy, Clone)]
11 pub struct u32x2(u32, u32);
12
13 #[repr(simd)]
14 #[derive(Copy, Clone)]
15 pub struct i32x2(i32, i32);
16
17 #[repr(simd)]
18 #[derive(Copy, Clone)]
19 pub struct i8x16(
20     i8, i8, i8, i8, i8, i8, i8, i8,
21     i8, i8, i8, i8, i8, i8, i8, i8,
22 );
23
24
25 extern "platform-intrinsic" {
26     fn simd_bitmask<T, U>(x: T) -> U;
27 }
28
29 // NOTE(eddyb) `%{{x|_2}}` is used because on some targets (e.g. WASM)
30 // SIMD vectors are passed directly, resulting in `%x` being a vector,
31 // while on others they're passed indirectly, resulting in `%x` being
32 // a pointer to a vector, and `%_2` a vector loaded from that pointer.
33 // This is controlled by the target spec option `simd_types_indirect`.
34
35 // CHECK-LABEL: @bitmask_int
36 #[no_mangle]
37 pub unsafe fn bitmask_int(x: i32x2) -> u8 {
38     // CHECK: [[A:%[0-9]+]] = lshr <2 x i32> %{{x|_2}}, <i32 31, i32 31>
39     // CHECK: [[B:%[0-9]+]] = trunc <2 x i32> [[A]] to <2 x i1>
40     // CHECK: [[C:%[0-9]+]] = bitcast <2 x i1> [[B]] to i2
41     // CHECK: %{{[0-9]+}} = zext i2 [[C]] to i8
42     simd_bitmask(x)
43 }
44
45 // CHECK-LABEL: @bitmask_uint
46 #[no_mangle]
47 pub unsafe fn bitmask_uint(x: u32x2) -> u8 {
48     // CHECK: [[A:%[0-9]+]] = lshr <2 x i32> %{{x|_2}}, <i32 31, i32 31>
49     // CHECK: [[B:%[0-9]+]] = trunc <2 x i32> [[A]] to <2 x i1>
50     // CHECK: [[C:%[0-9]+]] = bitcast <2 x i1> [[B]] to i2
51     // CHECK: %{{[0-9]+}} = zext i2 [[C]] to i8
52     simd_bitmask(x)
53 }
54
55 // CHECK-LABEL: @bitmask_int16
56 #[no_mangle]
57 pub unsafe fn bitmask_int16(x: i8x16) -> u16 {
58     // CHECK: [[A:%[0-9]+]] = lshr <16 x i8> %{{x|_2}}, <i8 7, i8 7, i8 7, i8 7, i8 7, i8 7, i8 7, i8 7, i8 7, i8 7, i8 7, i8 7, i8 7, i8 7, i8 7, i8 7>
59     // CHECK: [[B:%[0-9]+]] = trunc <16 x i8> [[A]] to <16 x i1>
60     // CHECK: %{{[0-9]+}} = bitcast <16 x i1> [[B]] to i16
61     // CHECK-NOT: zext
62     simd_bitmask(x)
63 }