2 #![allow(non_camel_case_types)]
6 // Test that the simd_reduce_{op} intrinsics produce the correct results.
8 #![feature(repr_simd, platform_intrinsics)]
9 #[allow(non_camel_case_types)]
12 #[derive(Copy, Clone)]
13 struct i32x4(pub i32, pub i32, pub i32, pub i32);
16 #[derive(Copy, Clone)]
17 struct u32x4(pub u32, pub u32, pub u32, pub u32);
20 #[derive(Copy, Clone)]
21 struct f32x4(pub f32, pub f32, pub f32, pub f32);
24 #[derive(Copy, Clone)]
25 struct b8x4(pub i8, pub i8, pub i8, pub i8);
27 extern "platform-intrinsic" {
28 fn simd_reduce_add_unordered<T, U>(x: T) -> U;
29 fn simd_reduce_mul_unordered<T, U>(x: T) -> U;
30 fn simd_reduce_add_ordered<T, U>(x: T, acc: U) -> U;
31 fn simd_reduce_mul_ordered<T, U>(x: T, acc: U) -> U;
32 fn simd_reduce_min<T, U>(x: T) -> U;
33 fn simd_reduce_max<T, U>(x: T) -> U;
34 fn simd_reduce_min_nanless<T, U>(x: T) -> U;
35 fn simd_reduce_max_nanless<T, U>(x: T) -> U;
36 fn simd_reduce_and<T, U>(x: T) -> U;
37 fn simd_reduce_or<T, U>(x: T) -> U;
38 fn simd_reduce_xor<T, U>(x: T) -> U;
39 fn simd_reduce_all<T>(x: T) -> bool;
40 fn simd_reduce_any<T>(x: T) -> bool;
45 let x = i32x4(1, -2, 3, 4);
46 let r: i32 = simd_reduce_add_unordered(x);
48 let r: i32 = simd_reduce_mul_unordered(x);
49 assert_eq!(r, -24_i32);
50 let r: i32 = simd_reduce_add_ordered(x, -1);
52 let r: i32 = simd_reduce_mul_ordered(x, -1);
53 assert_eq!(r, 24_i32);
55 let r: i32 = simd_reduce_min(x);
56 assert_eq!(r, -2_i32);
57 let r: i32 = simd_reduce_max(x);
60 let x = i32x4(-1, -1, -1, -1);
61 let r: i32 = simd_reduce_and(x);
62 assert_eq!(r, -1_i32);
63 let r: i32 = simd_reduce_or(x);
64 assert_eq!(r, -1_i32);
65 let r: i32 = simd_reduce_xor(x);
68 let x = i32x4(-1, -1, 0, -1);
69 let r: i32 = simd_reduce_and(x);
71 let r: i32 = simd_reduce_or(x);
72 assert_eq!(r, -1_i32);
73 let r: i32 = simd_reduce_xor(x);
74 assert_eq!(r, -1_i32);
78 let x = u32x4(1, 2, 3, 4);
79 let r: u32 = simd_reduce_add_unordered(x);
80 assert_eq!(r, 10_u32);
81 let r: u32 = simd_reduce_mul_unordered(x);
82 assert_eq!(r, 24_u32);
83 let r: u32 = simd_reduce_add_ordered(x, 1);
84 assert_eq!(r, 11_u32);
85 let r: u32 = simd_reduce_mul_ordered(x, 2);
86 assert_eq!(r, 48_u32);
88 let r: u32 = simd_reduce_min(x);
90 let r: u32 = simd_reduce_max(x);
94 let x = u32x4(t, t, t, t);
95 let r: u32 = simd_reduce_and(x);
97 let r: u32 = simd_reduce_or(x);
99 let r: u32 = simd_reduce_xor(x);
100 assert_eq!(r, 0_u32);
102 let x = u32x4(t, t, 0, t);
103 let r: u32 = simd_reduce_and(x);
104 assert_eq!(r, 0_u32);
105 let r: u32 = simd_reduce_or(x);
107 let r: u32 = simd_reduce_xor(x);
112 let x = f32x4(1., -2., 3., 4.);
113 let r: f32 = simd_reduce_add_unordered(x);
114 assert_eq!(r, 6_f32);
115 let r: f32 = simd_reduce_mul_unordered(x);
116 assert_eq!(r, -24_f32);
117 let r: f32 = simd_reduce_add_ordered(x, 0.);
118 assert_eq!(r, 6_f32);
119 let r: f32 = simd_reduce_mul_ordered(x, 1.);
120 assert_eq!(r, -24_f32);
121 let r: f32 = simd_reduce_add_ordered(x, 1.);
122 assert_eq!(r, 7_f32);
123 let r: f32 = simd_reduce_mul_ordered(x, 2.);
124 assert_eq!(r, -48_f32);
126 let r: f32 = simd_reduce_min(x);
127 assert_eq!(r, -2_f32);
128 let r: f32 = simd_reduce_max(x);
129 assert_eq!(r, 4_f32);
130 let r: f32 = simd_reduce_min_nanless(x);
131 assert_eq!(r, -2_f32);
132 let r: f32 = simd_reduce_max_nanless(x);
133 assert_eq!(r, 4_f32);
137 let x = b8x4(!0, !0, !0, !0);
138 let r: bool = simd_reduce_all(x);
140 let r: bool = simd_reduce_any(x);
143 let x = b8x4(!0, !0, 0, !0);
144 let r: bool = simd_reduce_all(x);
145 assert_eq!(r, false);
146 let r: bool = simd_reduce_any(x);
149 let x = b8x4(0, 0, 0, 0);
150 let r: bool = simd_reduce_all(x);
151 assert_eq!(r, false);
152 let r: bool = simd_reduce_any(x);
153 assert_eq!(r, false);