Debian Codegraph @

debian/missing-sources/wide/tests/all_tests/t_i32x4.rs

raw
1 use wide::*;
2
3 #[test]
4 fn size_align() {
5 assert_eq!(core::mem::size_of::<i32x4>(), 16);
6 assert_eq!(core::mem::align_of::<i32x4>(), 16);
7 }
8
9 #[test]
10 fn basic_traits() {
11 crate::test_basic_traits::<i32x4, _, 4>();
12 }
13
14 #[test]
15 fn impl_add_for_i32x4() {
16 let a = i32x4::from([1, 2, i32::MAX - 1, i32::MAX - 1]);
17 let b = i32x4::from([17, 18, 1, 2]);
18 let expected = i32x4::from([18, 20, i32::MAX, i32::MIN]);
19 let actual = a + b;
20 assert_eq!(expected, actual);
21 }
22
23 #[test]
24 fn impl_sub_for_i32x4() {
25 let a = i32x4::from([1, 2, i32::MIN + 1, i32::MIN]);
26 let b = i32x4::from([17, -18, 1, 1]);
27 let expected = i32x4::from([-16, 20, i32::MIN, i32::MAX]);
28 let actual = a - b;
29 assert_eq!(expected, actual);
30 }
31
32 #[test]
33 fn impl_mul_for_i32x4() {
34 let a = i32x4::from([1, 2, i32::MIN + 1, i32::MIN]);
35 let b = i32x4::from([17, -18, 1, 1]);
36 let expected = i32x4::from([17, -36, i32::MIN + 1, i32::MIN]);
37 let actual = a * b;
38 assert_eq!(expected, actual);
39 }
40
41 #[test]
42 fn impl_bitand_for_i32x4() {
43 let a = i32x4::from([0, 0, 1, 1]);
44 let b = i32x4::from([0, 1, 0, 1]);
45 let expected = i32x4::from([0, 0, 0, 1]);
46 let actual = a & b;
47 assert_eq!(expected, actual);
48 }
49
50 #[test]
51 fn impl_bitor_for_i32x4() {
52 let a = i32x4::from([0, 0, 1, 1]);
53 let b = i32x4::from([0, 1, 0, 1]);
54 let expected = i32x4::from([0, 1, 1, 1]);
55 let actual = a | b;
56 assert_eq!(expected, actual);
57 }
58
59 #[test]
60 fn impl_bitxor_for_i32x4() {
61 let a = i32x4::from([0, 0, 1, 1]);
62 let b = i32x4::from([0, 1, 0, 1]);
63 let expected = i32x4::from([0, 1, 1, 0]);
64 let actual = a ^ b;
65 assert_eq!(expected, actual);
66 }
67
68 #[test]
69 fn impl_shl_for_i32x4() {
70 let a = i32x4::from([1, 2, i32::MAX - 1, i32::MAX - 1]);
71 let b = 2;
72 let expected =
73 i32x4::from([1 << 2, 2 << 2, (i32::MAX - 1) << 2, (i32::MAX - 1) << 2]);
74 let actual = a << b;
75 assert_eq!(expected, actual);
76 }
77
78 #[test]
79 fn impl_shr_for_i32x4() {
80 let a = i32x4::from([1, 2, i32::MAX - 1, i32::MAX - 1]);
81 let b = 2;
82 let expected =
83 i32x4::from([1 >> 2, 2 >> 2, (i32::MAX - 1) >> 2, (i32::MAX - 1) >> 2]);
84 let actual = a >> b;
85 assert_eq!(expected, actual);
86 }
87
88 #[test]
89 fn impl_i32x4_cmp_eq() {
90 let a = i32x4::from([1, 2, 3, 4]);
91 let b = i32x4::from([2_i32; 4]);
92 let expected = i32x4::from([0, -1, 0, 0]);
93 let actual = a.cmp_eq(b);
94 assert_eq!(expected, actual);
95 }
96
97 #[test]
98 fn impl_i32x4_cmp_gt() {
99 let a = i32x4::from([1, 2, 3, 4]);
100 let b = i32x4::from([2_i32; 4]);
101 let expected = i32x4::from([0, 0, -1, -1]);
102 let actual = a.cmp_gt(b);
103 assert_eq!(expected, actual);
104 }
105
106 #[test]
107 fn impl_i32x4_cmp_lt() {
108 let a = i32x4::from([1, 2, 3, 4]);
109 let b = i32x4::from([2_i32; 4]);
110 let expected = i32x4::from([-1, 0, 0, 0]);
111 let actual = a.cmp_lt(b);
112 assert_eq!(expected, actual);
113
114 let expected = i32x4::from([0, 0, 0, 0]);
115 let actual = a.cmp_lt(a);
116 assert_eq!(expected, actual);
117 }
118
119 #[test]
120 fn impl_i32x4_blend() {
121 let use_t: i32 = -1;
122 let t = i32x4::from([1, 2, 3, 4]);
123 let f = i32x4::from([17, 18, 19, 20]);
124 let mask = i32x4::from([use_t, 0, use_t, 0]);
125 let expected = i32x4::from([1, 18, 3, 20]);
126 let actual = mask.blend(t, f);
127 assert_eq!(expected, actual);
128 }
129
130 #[test]
131 fn impl_i32x4_abs() {
132 let a = i32x4::from([-1, 2, -3, i32::MIN]);
133 let expected = i32x4::from([1, 2, 3, i32::MIN]);
134 let actual = a.abs();
135 assert_eq!(expected, actual);
136 }
137
138 #[test]
139 fn impl_i32x4_unsigned_abs() {
140 let a = i32x4::from([-1, 2, -3, i32::MIN]);
141 let expected = u32x4::from([1, 2, 3, i32::MIN as u32]);
142 let actual = a.unsigned_abs();
143 assert_eq!(expected, actual);
144 }
145
146 #[test]
147 fn impl_i32x4_max() {
148 let a = i32x4::from([1, 2, i32::MIN + 1, i32::MIN]);
149 let b = i32x4::from([17, -18, 1, 1]);
150 let expected = i32x4::from([17, 2, 1, 1]);
151 let actual = a.max(b);
152 assert_eq!(expected, actual);
153
154 crate::test_random_vector_vs_scalar(|a: i32x4, b| a.max(b), |a, b| a.max(b));
155 }
156
157 #[test]
158 fn impl_i32x4_min() {
159 let a = i32x4::from([1, 2, i32::MIN + 1, i32::MIN]);
160 let b = i32x4::from([17, -18, 1, 1]);
161 let expected = i32x4::from([1, -18, i32::MIN + 1, i32::MIN]);
162 let actual = a.min(b);
163 assert_eq!(expected, actual);
164
165 crate::test_random_vector_vs_scalar(|a: i32x4, b| a.min(b), |a, b| a.min(b));
166 }
167
168 #[test]
169 fn impl_i32x4_round_float() {
170 let a = i32x4::from([-1, 30, i32::MIN, i32::MAX]);
171 let expected = f32x4::from([-1.0, 30.0, i32::MIN as f32, i32::MAX as f32]);
172 let actual = a.round_float();
173 assert_eq!(expected, actual);
174 }
175
176 #[test]
177 fn test_i32x4_move_mask() {
178 let a = i32x4::from([-1, 0, -2, -3]);
179 let expected = 0b1101;
180 let actual = a.move_mask();
181 assert_eq!(expected, actual);
182 //
183 let a = i32x4::from([i32::MAX, 0, 2, -3]);
184 let expected = 0b1000;
185 let actual = a.move_mask();
186 assert_eq!(expected, actual);
187
188 crate::test_random_vector_vs_scalar_reduce(
189 |a: i32x4| a.move_mask(),
190 0i32,
191 |acc, a, idx| acc | if a < 0 { 1 << idx } else { 0 },
192 );
193 }
194
195 #[test]
196 fn test_i32x4_any() {
197 let a = i32x4::from([0, 0, 0, -1]);
198 assert!(a.any());
199 //
200 let a = i32x4::from([0, 0, 0, 0]);
201 assert!(!a.any());
202 }
203
204 #[test]
205 fn test_i32x4_all() {
206 let a = i32x4::from([0, 0, 0, -1]);
207 assert!(!a.all());
208 //
209 let a = i32x4::from([-1; 4]);
210 assert!(a.all());
211 }
212
213 #[test]
214 fn test_i32x4_none() {
215 let a = i32x4::from([0, 0, 0, -1]);
216 assert!(!a.none());
217 //
218 let a = i32x4::from([0; 4]);
219 assert!(a.none());
220 }
221
222 #[test]
223 fn impl_i32x4_reduce_add() {
224 let p = i32x4::from([10000000, 20000000, 30000000, -40000000]);
225 assert_eq!(p.reduce_add(), 20000000);
226 }
227
228 #[test]
229 fn impl_i32x4_reduce_min() {
230 for i in 0..4 {
231 let mut v = [i32::MAX; 4];
232 v[i] = i32::MIN;
233 let p = i32x4::from(v);
234 assert_eq!(p.reduce_min(), i32::MIN);
235 }
236 }
237
238 #[test]
239 fn impl_i32x4_reduce_max() {
240 for i in 0..4 {
241 let mut v = [i32::MIN; 4];
242 v[i] = i32::MAX;
243 let p = i32x4::from(v);
244 assert_eq!(p.reduce_max(), i32::MAX);
245 }
246 }
247
248 #[test]
249 fn impl_i32x4_shr_each() {
250 let a = i32x4::from([15313, 52322, -1, 4]);
251 let shift = i32x4::from([1, 30, 8, 33 /* test masking behavior */]);
252 let expected = i32x4::from([7656, 0, -1, 2]);
253 let actual = a >> shift;
254 assert_eq!(expected, actual);
255
256 crate::test_random_vector_vs_scalar(
257 |a: i32x4, b| a >> b,
258 |a, b| a.wrapping_shr(b as u32),
259 );
260 }
261 #[test]
262 fn impl_i32x4_shl_each() {
263 let a = i32x4::from([15313, 52322, -1, 4]);
264 let shift = i32x4::from([1, 30, 8, 33 /* test masking behavior */]);
265 let expected = i32x4::from([30626, -2147483648, -256, 8]);
266 let actual = a << shift;
267 assert_eq!(expected, actual);
268
269 crate::test_random_vector_vs_scalar(
270 |a: i32x4, b| a << b,
271 |a, b| a.wrapping_shl(b as u32),
272 );
273 }
274
275 #[test]
276 fn impl_i32x4_mul_widen() {
277 let a = i32x4::from([1, 2, 3 * -1000000, i32::MAX]);
278 let b = i32x4::from([5, 6, 7 * -1000000, i32::MIN]);
279 let expected = i64x4::from([
280 1 * 5,
281 2 * 6,
282 3 * 7 * 1000000 * 1000000,
283 i32::MIN as i64 * i32::MAX as i64,
284 ]);
285 let actual = a.mul_widen(b);
286 assert_eq!(expected, actual);
287
288 crate::test_random_vector_vs_scalar(
289 |a: i32x4, b| a.mul_widen(b),
290 |a, b| a as i64 * b as i64,
291 );
292 }
293
294 #[test]
295 fn impl_i32x4_transpose() {
296 let a = [
297 i32x4::from([1, 2, 3, 4]),
298 i32x4::from([5, 6, 7, 8]),
299 i32x4::from([9, 10, 11, 12]),
300 i32x4::from([13, 14, 15, 16]),
301 ];
302 let a_t = [
303 i32x4::from([1, 5, 9, 13]),
304 i32x4::from([2, 6, 10, 14]),
305 i32x4::from([3, 7, 11, 15]),
306 i32x4::from([4, 8, 12, 16]),
307 ];
308 assert_eq!(i32x4::transpose(a), a_t);
309 }
310
311 #[cfg(feature = "serde")]
312 #[test]
313 fn impl_i32x4_ser_de_roundtrip() {
314 let serialized =
315 bincode::serialize(&i32x4::ZERO).expect("serialization failed");
316 let deserialized =
317 bincode::deserialize(&serialized).expect("deserializaion failed");
318 assert_eq!(i32x4::ZERO, deserialized);
319 }