]> git.lizzy.rs Git - rust.git/blob - src/test/ui/simd/simd-intrinsic-generic-comparison.rs
Update tests to remove old numeric constants
[rust.git] / src / test / ui / simd / simd-intrinsic-generic-comparison.rs
1 // run-pass
2 // ignore-emscripten FIXME(#45351) hits an LLVM assert
3
4 #![feature(repr_simd, platform_intrinsics, concat_idents)]
5 #![allow(non_camel_case_types)]
6
7 #[repr(simd)]
8 #[derive(Copy, Clone)]
9 struct i32x4(i32, i32, i32, i32);
10 #[repr(simd)]
11 #[derive(Copy, Clone)]
12 struct u32x4(pub u32, pub u32, pub u32, pub u32);
13 #[repr(simd)]
14 #[derive(Copy, Clone)]
15 struct f32x4(pub f32, pub f32, pub f32, pub f32);
16
17 extern "platform-intrinsic" {
18     fn simd_eq<T, U>(x: T, y: T) -> U;
19     fn simd_ne<T, U>(x: T, y: T) -> U;
20     fn simd_lt<T, U>(x: T, y: T) -> U;
21     fn simd_le<T, U>(x: T, y: T) -> U;
22     fn simd_gt<T, U>(x: T, y: T) -> U;
23     fn simd_ge<T, U>(x: T, y: T) -> U;
24 }
25
26 macro_rules! cmp {
27     ($method: ident($lhs: expr, $rhs: expr)) => {{
28         let lhs = $lhs;
29         let rhs = $rhs;
30         let e: u32x4 = concat_idents!(simd_, $method)($lhs, $rhs);
31         // assume the scalar version is correct/the behaviour we want.
32         assert!((e.0 != 0) == lhs.0 .$method(&rhs.0));
33         assert!((e.1 != 0) == lhs.1 .$method(&rhs.1));
34         assert!((e.2 != 0) == lhs.2 .$method(&rhs.2));
35         assert!((e.3 != 0) == lhs.3 .$method(&rhs.3));
36     }}
37 }
38 macro_rules! tests {
39     ($($lhs: ident, $rhs: ident;)*) => {{
40         $(
41             (|| {
42                 cmp!(eq($lhs, $rhs));
43                 cmp!(ne($lhs, $rhs));
44
45                 // test both directions
46                 cmp!(lt($lhs, $rhs));
47                 cmp!(lt($rhs, $lhs));
48
49                 cmp!(le($lhs, $rhs));
50                 cmp!(le($rhs, $lhs));
51
52                 cmp!(gt($lhs, $rhs));
53                 cmp!(gt($rhs, $lhs));
54
55                 cmp!(ge($lhs, $rhs));
56                 cmp!(ge($rhs, $lhs));
57             })();
58             )*
59     }}
60 }
61 fn main() {
62     // 13 vs. -100 tests that we get signed vs. unsigned comparisons
63     // correct (i32: 13 > -100, u32: 13 < -100).    let i1 = i32x4(10, -11, 12, 13);
64     let i1 = i32x4(10, -11, 12, 13);
65     let i2 = i32x4(5, -5, 20, -100);
66     let i3 = i32x4(10, -11, 20, -100);
67
68     let u1 = u32x4(10, !11+1, 12, 13);
69     let u2 = u32x4(5, !5+1, 20, !100+1);
70     let u3 = u32x4(10, !11+1, 20, !100+1);
71
72     let f1 = f32x4(10.0, -11.0, 12.0, 13.0);
73     let f2 = f32x4(5.0, -5.0, 20.0, -100.0);
74     let f3 = f32x4(10.0, -11.0, 20.0, -100.0);
75
76     unsafe {
77         tests! {
78             i1, i1;
79             u1, u1;
80             f1, f1;
81
82             i1, i2;
83             u1, u2;
84             f1, f2;
85
86             i1, i3;
87             u1, u3;
88             f1, f3;
89         }
90     }
91
92     // NAN comparisons are special:
93     // -11 (*)    13
94     // -5        -100 (*)
95     let f4 = f32x4(f32::NAN, f1.1, f32::NAN, f2.3);
96
97     unsafe {
98         tests! {
99             f1, f4;
100             f2, f4;
101             f4, f4;
102         }
103     }
104 }