| 1 |
use wide::*; |
| 2 |
|
| 3 |
#[test] |
| 4 |
fn size_align() { |
| 5 |
assert_eq!(core::mem::size_of::<i32x8>(), 32); |
| 6 |
assert_eq!(core::mem::align_of::<i32x8>(), 32); |
| 7 |
} |
| 8 |
|
| 9 |
#[test] |
| 10 |
fn basic_traits() { |
| 11 |
crate::test_basic_traits::<i32x8, _, 8>(); |
| 12 |
} |
| 13 |
|
| 14 |
#[test] |
| 15 |
fn impl_add_for_i32x8() { |
| 16 |
let a = i32x8::from([1, 2, i32::MAX - 1, i32::MAX - 1, 15, 20, 5000, 2990]); |
| 17 |
let b = i32x8::from([17, 18, 1, 2, 20, 5, 900, 900]); |
| 18 |
let expected = i32x8::from([18, 20, i32::MAX, i32::MIN, 35, 25, 5900, 3890]); |
| 19 |
let actual = a + b; |
| 20 |
assert_eq!(expected, actual); |
| 21 |
} |
| 22 |
|
| 23 |
#[test] |
| 24 |
fn impl_sub_for_i32x8() { |
| 25 |
let a = i32x8::from([1, 2, i32::MIN + 1, i32::MIN, 15, 20, 5000, 2990]); |
| 26 |
let b = i32x8::from([17, -18, 1, 1, 20, 5, 900, 900]); |
| 27 |
let expected = i32x8::from([-16, 20, i32::MIN, i32::MAX, -5, 15, 4100, 2090]); |
| 28 |
let actual = a - b; |
| 29 |
assert_eq!(expected, actual); |
| 30 |
} |
| 31 |
|
| 32 |
#[test] |
| 33 |
fn impl_mul_for_i32x8() { |
| 34 |
let a = i32x8::from([1, 2, i32::MIN + 1, i32::MIN, 2, 3, 4, 5]); |
| 35 |
let b = i32x8::from([17, -18, 1, 1, -1, -2, -6, 3]); |
| 36 |
let expected = |
| 37 |
i32x8::from([17, -36, i32::MIN + 1, i32::MIN, -2, -6, -24, 15]); |
| 38 |
let actual = a * b; |
| 39 |
assert_eq!(expected, actual); |
| 40 |
} |
| 41 |
|
| 42 |
#[test] |
| 43 |
fn impl_bitand_for_i32x8() { |
| 44 |
let a = i32x8::from([0, 0, 1, 1, 1, 0, 0, 1]); |
| 45 |
let b = i32x8::from([0, 1, 0, 1, 0, 1, 1, 1]); |
| 46 |
let expected = i32x8::from([0, 0, 0, 1, 0, 0, 0, 1]); |
| 47 |
let actual = a & b; |
| 48 |
assert_eq!(expected, actual); |
| 49 |
} |
| 50 |
|
| 51 |
#[test] |
| 52 |
fn impl_bitor_for_i32x8() { |
| 53 |
let a = i32x8::from([0, 0, 1, 1, 1, 0, 0, 1]); |
| 54 |
let b = i32x8::from([0, 1, 0, 1, 0, 1, 1, 1]); |
| 55 |
let expected = i32x8::from([0, 1, 1, 1, 1, 1, 1, 1]); |
| 56 |
let actual = a | b; |
| 57 |
assert_eq!(expected, actual); |
| 58 |
} |
| 59 |
|
| 60 |
#[test] |
| 61 |
fn impl_bitxor_for_i32x8() { |
| 62 |
let a = i32x8::from([0, 0, 1, 1, 1, 0, 0, 1]); |
| 63 |
let b = i32x8::from([0, 1, 0, 1, 0, 1, 1, 1]); |
| 64 |
let expected = i32x8::from([0, 1, 1, 0, 1, 1, 1, 0]); |
| 65 |
let actual = a ^ b; |
| 66 |
assert_eq!(expected, actual); |
| 67 |
} |
| 68 |
|
| 69 |
#[test] |
| 70 |
fn impl_shl_for_i32x8() { |
| 71 |
let a = i32x8::from([1, 2, i32::MAX - 1, i32::MAX - 1, 128, 255, 590, 5667]); |
| 72 |
let b = 2; |
| 73 |
let expected = i32x8::from([ |
| 74 |
1 << 2, |
| 75 |
2 << 2, |
| 76 |
(i32::MAX - 1) << 2, |
| 77 |
(i32::MAX - 1) << 2, |
| 78 |
128 << 2, |
| 79 |
255 << 2, |
| 80 |
590 << 2, |
| 81 |
5667 << 2, |
| 82 |
]); |
| 83 |
let actual = a << b; |
| 84 |
assert_eq!(expected, actual); |
| 85 |
} |
| 86 |
|
| 87 |
#[test] |
| 88 |
fn impl_shr_for_i32x8() { |
| 89 |
let a = i32x8::from([1, 2, i32::MAX - 1, i32::MAX - 1, 128, 255, 590, 5667]); |
| 90 |
let b = 2; |
| 91 |
let expected = i32x8::from([ |
| 92 |
1 >> 2, |
| 93 |
2 >> 2, |
| 94 |
(i32::MAX - 1) >> 2, |
| 95 |
(i32::MAX - 1) >> 2, |
| 96 |
128 >> 2, |
| 97 |
255 >> 2, |
| 98 |
590 >> 2, |
| 99 |
5667 >> 2, |
| 100 |
]); |
| 101 |
let actual = a >> b; |
| 102 |
assert_eq!(expected, actual); |
| 103 |
} |
| 104 |
|
| 105 |
#[test] |
| 106 |
fn impl_i32x8_cmp_eq() { |
| 107 |
let a = i32x8::from([1, 2, 3, 4, 2, 1, 8, 2]); |
| 108 |
let b = i32x8::from([2_i32; 8]); |
| 109 |
let expected = i32x8::from([0, -1, 0, 0, -1, 0, 0, -1]); |
| 110 |
let actual = a.cmp_eq(b); |
| 111 |
assert_eq!(expected, actual); |
| 112 |
} |
| 113 |
|
| 114 |
#[test] |
| 115 |
fn impl_i32x8_cmp_gt() { |
| 116 |
let a = i32x8::from([1, 2, 9, 4, 1, 2, 8, 10]); |
| 117 |
let b = i32x8::from([5_i32; 8]); |
| 118 |
let expected = i32x8::from([0, 0, -1, 0, 0, 0, -1, -1]); |
| 119 |
let actual = a.cmp_gt(b); |
| 120 |
assert_eq!(expected, actual); |
| 121 |
} |
| 122 |
|
| 123 |
#[test] |
| 124 |
fn impl_i32x8_cmp_lt() { |
| 125 |
let a = i32x8::from([1, 2, 9, 4, 1, 2, 8, 10]); |
| 126 |
let b = i32x8::from([5_i32; 8]); |
| 127 |
let expected = i32x8::from([-1, -1, 0, -1, -1, -1, 0, 0]); |
| 128 |
let actual = a.cmp_lt(b); |
| 129 |
assert_eq!(expected, actual); |
| 130 |
|
| 131 |
let expected = i32x8::from([0, 0, 0, 0, 0, 0, 0, 0]); |
| 132 |
let actual = a.cmp_lt(a); |
| 133 |
assert_eq!(expected, actual); |
| 134 |
} |
| 135 |
|
| 136 |
#[test] |
| 137 |
fn impl_i32x8_blend() { |
| 138 |
let use_t: i32 = -1; |
| 139 |
let t = i32x8::from([1, 2, 3, 4, 5, 6, 7, 8]); |
| 140 |
let f = i32x8::from([17, 18, 19, 20, 25, 30, 50, 90]); |
| 141 |
let mask = i32x8::from([use_t, 0, use_t, 0, 0, 0, 0, use_t]); |
| 142 |
let expected = i32x8::from([1, 18, 3, 20, 25, 30, 50, 8]); |
| 143 |
let actual = mask.blend(t, f); |
| 144 |
assert_eq!(expected, actual); |
| 145 |
} |
| 146 |
|
| 147 |
#[test] |
| 148 |
fn impl_i32x8_abs() { |
| 149 |
let a = i32x8::from([-1, 2, -3, i32::MIN, 6, -15, -19, 9]); |
| 150 |
let expected = i32x8::from([1, 2, 3, i32::MIN, 6, 15, 19, 9]); |
| 151 |
let actual = a.abs(); |
| 152 |
assert_eq!(expected, actual); |
| 153 |
} |
| 154 |
|
| 155 |
#[test] |
| 156 |
fn impl_i32x8_unsigned_abs() { |
| 157 |
let a = i32x8::from([-1, 2, -3, i32::MIN, 6, -15, -19, 9]); |
| 158 |
let expected = u32x8::from([1, 2, 3, i32::MIN as u32, 6, 15, 19, 9]); |
| 159 |
let actual = a.unsigned_abs(); |
| 160 |
assert_eq!(expected, actual); |
| 161 |
} |
| 162 |
|
| 163 |
#[test] |
| 164 |
fn impl_i32x8_max() { |
| 165 |
let a = i32x8::from([1, 2, i32::MIN + 1, i32::MIN, 6, -8, 12, 9]); |
| 166 |
let b = i32x8::from([17, -18, 1, 1, 19, -5, -1, -9]); |
| 167 |
let expected = i32x8::from([17, 2, 1, 1, 19, -5, 12, 9]); |
| 168 |
let actual = a.max(b); |
| 169 |
assert_eq!(expected, actual); |
| 170 |
|
| 171 |
crate::test_random_vector_vs_scalar(|a: i32x8, b| a.max(b), |a, b| a.max(b)); |
| 172 |
} |
| 173 |
|
| 174 |
#[test] |
| 175 |
fn impl_i32x8_min() { |
| 176 |
let a = i32x8::from([1, 2, i32::MIN + 1, i32::MIN, 6, -8, 12, 9]); |
| 177 |
let b = i32x8::from([17, -18, 1, 1, 19, -5, -1, -9]); |
| 178 |
let expected = i32x8::from([1, -18, i32::MIN + 1, i32::MIN, 6, -8, -1, -9]); |
| 179 |
let actual = a.min(b); |
| 180 |
assert_eq!(expected, actual); |
| 181 |
|
| 182 |
crate::test_random_vector_vs_scalar(|a: i32x8, b| a.min(b), |a, b| a.min(b)); |
| 183 |
} |
| 184 |
|
| 185 |
#[test] |
| 186 |
fn impl_i32x8_round_float() { |
| 187 |
let a = i32x8::from([-1, 30, i32::MIN, i32::MAX, 29, 35, -8, 0]); |
| 188 |
let expected = f32x8::from([ |
| 189 |
-1.0, |
| 190 |
30.0, |
| 191 |
i32::MIN as f32, |
| 192 |
i32::MAX as f32, |
| 193 |
29.0, |
| 194 |
35.0, |
| 195 |
-8.0, |
| 196 |
0.0, |
| 197 |
]); |
| 198 |
let actual = a.round_float(); |
| 199 |
assert_eq!(expected, actual); |
| 200 |
} |
| 201 |
|
| 202 |
#[test] |
| 203 |
fn impl_transpose_for_i32x8() { |
| 204 |
let a = [ |
| 205 |
i32x8::new([0, 1, 2, 3, 4, 5, 6, 7]), |
| 206 |
i32x8::new([8, 9, 10, 11, 12, 13, 14, 15]), |
| 207 |
i32x8::new([16, 17, 18, 19, 20, 21, 22, 23]), |
| 208 |
i32x8::new([24, 25, 26, 27, 28, 29, 30, 31]), |
| 209 |
i32x8::new([32, 33, 34, 35, 36, 37, 38, 39]), |
| 210 |
i32x8::new([40, 41, 42, 43, 44, 45, 46, 47]), |
| 211 |
i32x8::new([48, 49, 50, 51, 52, 53, 54, 55]), |
| 212 |
i32x8::new([ |
| 213 |
5600000, 5700000, 5800000, 5900000, 6000000, 6100000, 6200000, 6300000, |
| 214 |
]), |
| 215 |
]; |
| 216 |
|
| 217 |
let result = i32x8::transpose(a); |
| 218 |
|
| 219 |
let expected = [ |
| 220 |
i32x8::new([0, 8, 16, 24, 32, 40, 48, 5600000]), |
| 221 |
i32x8::new([1, 9, 17, 25, 33, 41, 49, 5700000]), |
| 222 |
i32x8::new([2, 10, 18, 26, 34, 42, 50, 5800000]), |
| 223 |
i32x8::new([3, 11, 19, 27, 35, 43, 51, 5900000]), |
| 224 |
i32x8::new([4, 12, 20, 28, 36, 44, 52, 6000000]), |
| 225 |
i32x8::new([5, 13, 21, 29, 37, 45, 53, 6100000]), |
| 226 |
i32x8::new([6, 14, 22, 30, 38, 46, 54, 6200000]), |
| 227 |
i32x8::new([7, 15, 23, 31, 39, 47, 55, 6300000]), |
| 228 |
]; |
| 229 |
|
| 230 |
assert_eq!(result, expected); |
| 231 |
} |
| 232 |
|
| 233 |
#[test] |
| 234 |
fn impl_from_i16x8() { |
| 235 |
let a = i16x8::from([1, 2, 3, 4, 5, 6, i16::MIN + 1, i16::MIN]); |
| 236 |
let actual = i32x8::from_i16x8(a); |
| 237 |
let expected = |
| 238 |
i32x8::from([1, 2, 3, 4, 5, 6, (i16::MIN + 1) as i32, i16::MIN as i32]); |
| 239 |
|
| 240 |
assert_eq!(actual, expected); |
| 241 |
} |
| 242 |
|
| 243 |
#[test] |
| 244 |
fn impl_from_u16x8() { |
| 245 |
let a = u16x8::from([1, 2, 3, 4, 5, i16::MAX as u16, u16::MAX - 1, u16::MAX]); |
| 246 |
let actual = i32x8::from_u16x8(a); |
| 247 |
let expected = i32x8::from([ |
| 248 |
1, |
| 249 |
2, |
| 250 |
3, |
| 251 |
4, |
| 252 |
5, |
| 253 |
i16::MAX as i32, |
| 254 |
(u16::MAX - 1) as i32, |
| 255 |
u16::MAX as i32, |
| 256 |
]); |
| 257 |
|
| 258 |
assert_eq!(actual, expected); |
| 259 |
|
| 260 |
crate::test_random_vector_vs_scalar( |
| 261 |
|a: u16x8, _b| i32x8::from_u16x8(a), |
| 262 |
|a, _b| a as u32 as i32, |
| 263 |
); |
| 264 |
} |
| 265 |
|
| 266 |
#[test] |
| 267 |
fn test_i16x8_move_mask() { |
| 268 |
let a = i16x8::from([-1, 0, -2, -3, -1, 0, -2, -3]); |
| 269 |
let expected = 0b11011101; |
| 270 |
let actual = a.move_mask(); |
| 271 |
assert_eq!(expected, actual); |
| 272 |
// |
| 273 |
let a = i16x8::from([1, 0, 2, -3, 1, 0, 2, -3]); |
| 274 |
let expected = 0b10001000; |
| 275 |
let actual = a.move_mask(); |
| 276 |
assert_eq!(expected, actual); |
| 277 |
|
| 278 |
crate::test_random_vector_vs_scalar_reduce( |
| 279 |
|a: i32x8| a.move_mask(), |
| 280 |
0i32, |
| 281 |
|acc, a, idx| acc | if a < 0 { 1 << idx } else { 0 }, |
| 282 |
); |
| 283 |
} |
| 284 |
|
| 285 |
#[test] |
| 286 |
fn test_i32x8_any() { |
| 287 |
let a = i32x8::from([0, 0, 0, -1, 0, 0, 0, 0]); |
| 288 |
assert!(a.any()); |
| 289 |
// |
| 290 |
let a = i32x8::from([0, 0, 0, 0, 0, 0, 0, 0]); |
| 291 |
assert!(!a.any()); |
| 292 |
|
| 293 |
crate::test_random_vector_vs_scalar_reduce( |
| 294 |
|a: i32x8| a.any(), |
| 295 |
false, |
| 296 |
|acc, a, _idx| acc | (a < 0), |
| 297 |
); |
| 298 |
} |
| 299 |
|
| 300 |
#[test] |
| 301 |
fn test_i32x8_all() { |
| 302 |
let a = i32x8::from([0, 0, 0, -1, 0, 0, 0, 0]); |
| 303 |
assert!(!a.all()); |
| 304 |
// |
| 305 |
let a = i32x8::from([-1; 8]); |
| 306 |
assert!(a.all()); |
| 307 |
|
| 308 |
crate::test_random_vector_vs_scalar_reduce( |
| 309 |
|a: i32x8| a.all(), |
| 310 |
true, |
| 311 |
|acc, a, _idx| acc & (a < 0), |
| 312 |
); |
| 313 |
} |
| 314 |
|
| 315 |
#[test] |
| 316 |
fn test_i32x8_none() { |
| 317 |
let a = i32x8::from([0, 0, 0, -1, 0, 0, 0, 0]); |
| 318 |
assert!(!a.none()); |
| 319 |
// |
| 320 |
let a = i32x8::from([0; 8]); |
| 321 |
assert!(a.none()); |
| 322 |
|
| 323 |
crate::test_random_vector_vs_scalar_reduce( |
| 324 |
|a: i32x8| a.none(), |
| 325 |
true, |
| 326 |
|acc, a, _idx| acc & !(a < 0), |
| 327 |
); |
| 328 |
} |
| 329 |
|
| 330 |
#[test] |
| 331 |
fn impl_i32x8_reduce_add() { |
| 332 |
let p = i32x8::from([ |
| 333 |
10000000, 20000000, 30000000, 40000000, 50000000, 60000000, 70000000, |
| 334 |
90000000, |
| 335 |
]); |
| 336 |
assert_eq!(p.reduce_add(), 370000000); |
| 337 |
} |
| 338 |
|
| 339 |
#[test] |
| 340 |
fn impl_i32x8_reduce_min() { |
| 341 |
for i in 0..8 { |
| 342 |
let mut v = [i32::MAX; 8]; |
| 343 |
v[i] = i32::MIN; |
| 344 |
let p = i32x8::from(v); |
| 345 |
assert_eq!(p.reduce_min(), i32::MIN); |
| 346 |
} |
| 347 |
} |
| 348 |
|
| 349 |
#[test] |
| 350 |
fn impl_i32x8_reduce_max() { |
| 351 |
for i in 0..8 { |
| 352 |
let mut v = [i32::MIN; 8]; |
| 353 |
v[i] = i32::MAX; |
| 354 |
let p = i32x8::from(v); |
| 355 |
assert_eq!(p.reduce_max(), i32::MAX); |
| 356 |
} |
| 357 |
} |
| 358 |
|
| 359 |
#[test] |
| 360 |
fn impl_i32x4_shr_each() { |
| 361 |
let a = u32x8::from([15313, 52322, u32::MAX, 4, 10, 20, 30, 40]); |
| 362 |
let shift = |
| 363 |
u32x8::from([1, 30, 8, 33 /* test masking behavior */, 1, 2, 3, 4]); |
| 364 |
let expected = u32x8::from([7656, 0, 16777215, 2, 5, 5, 3, 2]); |
| 365 |
let actual = a >> shift; |
| 366 |
assert_eq!(expected, actual); |
| 367 |
|
| 368 |
crate::test_random_vector_vs_scalar( |
| 369 |
|a: i32x8, b| a >> b, |
| 370 |
|a, b| a.wrapping_shr(b as u32), |
| 371 |
); |
| 372 |
} |
| 373 |
#[test] |
| 374 |
fn impl_i32x8_shl_each() { |
| 375 |
let a = i32x8::from([15313, 52322, -1, 4, 1, 2, 3, 4]); |
| 376 |
let shift = |
| 377 |
i32x8::from([1, 30, 8, 33 /* test masking behavior */, 1, 2, 3, 4]); |
| 378 |
let expected = i32x8::from([30626, -2147483648, -256, 8, 2, 8, 24, 64]); |
| 379 |
let actual = a << shift; |
| 380 |
assert_eq!(expected, actual); |
| 381 |
|
| 382 |
crate::test_random_vector_vs_scalar( |
| 383 |
|a: i32x8, b| a << b, |
| 384 |
|a, b| a.wrapping_shl(b as u32), |
| 385 |
); |
| 386 |
} |
| 387 |
|
| 388 |
#[cfg(feature = "serde")] |
| 389 |
#[test] |
| 390 |
fn impl_i32x8_ser_de_roundtrip() { |
| 391 |
let serialized = |
| 392 |
bincode::serialize(&i32x8::ZERO).expect("serialization failed"); |
| 393 |
let deserialized = |
| 394 |
bincode::deserialize(&serialized).expect("deserializaion failed"); |
| 395 |
assert_eq!(i32x8::ZERO, deserialized); |
| 396 |
} |