]> git.proxmox.com Git - rustc.git/blame - src/test/codegen/simd-intrinsic/simd-intrinsic-generic-bitmask.rs
New upstream version 1.66.0+dfsg1
[rustc.git] / src / test / codegen / simd-intrinsic / simd-intrinsic-generic-bitmask.rs
CommitLineData
9fa01778 1// compile-flags: -C no-prepopulate-passes
cdc7bbd5 2//
9fa01778
XL
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)]
11pub struct u32x2(u32, u32);
12
13#[repr(simd)]
14#[derive(Copy, Clone)]
15pub struct i32x2(i32, i32);
16
17#[repr(simd)]
18#[derive(Copy, Clone)]
19pub struct i8x16(
20 i8, i8, i8, i8, i8, i8, i8, i8,
21 i8, i8, i8, i8, i8, i8, i8, i8,
22);
23
24
25extern "platform-intrinsic" {
26 fn simd_bitmask<T, U>(x: T) -> U;
27}
28
e74abb32
XL
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
9fa01778
XL
35// CHECK-LABEL: @bitmask_int
36#[no_mangle]
37pub unsafe fn bitmask_int(x: i32x2) -> u8 {
e74abb32 38 // CHECK: [[A:%[0-9]+]] = lshr <2 x i32> %{{x|_2}}, <i32 31, i32 31>
9fa01778
XL
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]
47pub unsafe fn bitmask_uint(x: u32x2) -> u8 {
e74abb32 48 // CHECK: [[A:%[0-9]+]] = lshr <2 x i32> %{{x|_2}}, <i32 31, i32 31>
9fa01778
XL
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]
57pub unsafe fn bitmask_int16(x: i8x16) -> u16 {
e74abb32 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>
9fa01778
XL
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}