| 1 |
use wide::*; |
| 2 |
|
| 3 |
#[test] |
| 4 |
fn size_align() { |
| 5 |
assert_eq!(core::mem::size_of::<i16x16>(), 32); |
| 6 |
assert_eq!(core::mem::align_of::<i16x16>(), 32); |
| 7 |
} |
| 8 |
|
| 9 |
#[test] |
| 10 |
fn basic_traits() { |
| 11 |
crate::test_basic_traits::<i16x16, _, 16>(); |
| 12 |
} |
| 13 |
|
| 14 |
#[test] |
| 15 |
fn impl_add_for_i16x16() { |
| 16 |
let a = i16x16::from([ |
| 17 |
1, |
| 18 |
2, |
| 19 |
i16::MAX - 1, |
| 20 |
i16::MAX - 1, |
| 21 |
15, |
| 22 |
20, |
| 23 |
5000, |
| 24 |
2990, |
| 25 |
1, |
| 26 |
2, |
| 27 |
i16::MAX - 1, |
| 28 |
i16::MAX - 1, |
| 29 |
15, |
| 30 |
20, |
| 31 |
5000, |
| 32 |
2990, |
| 33 |
]); |
| 34 |
let b = i16x16::from([ |
| 35 |
17, 18, 1, 2, 20, 5, 900, 900, 17, 18, 1, 2, 20, 5, 900, 900, |
| 36 |
]); |
| 37 |
let expected = i16x16::from([ |
| 38 |
18, |
| 39 |
20, |
| 40 |
i16::MAX, |
| 41 |
i16::MIN, |
| 42 |
35, |
| 43 |
25, |
| 44 |
5900, |
| 45 |
3890, |
| 46 |
18, |
| 47 |
20, |
| 48 |
i16::MAX, |
| 49 |
i16::MIN, |
| 50 |
35, |
| 51 |
25, |
| 52 |
5900, |
| 53 |
3890, |
| 54 |
]); |
| 55 |
let actual = a + b; |
| 56 |
assert_eq!(expected, actual); |
| 57 |
} |
| 58 |
|
| 59 |
#[test] |
| 60 |
fn impl_sub_for_i16x16() { |
| 61 |
let a = i16x16::from([ |
| 62 |
1, |
| 63 |
2, |
| 64 |
i16::MIN + 1, |
| 65 |
i16::MIN, |
| 66 |
15, |
| 67 |
20, |
| 68 |
5000, |
| 69 |
2990, |
| 70 |
1, |
| 71 |
2, |
| 72 |
i16::MIN + 1, |
| 73 |
i16::MIN, |
| 74 |
15, |
| 75 |
20, |
| 76 |
5000, |
| 77 |
2990, |
| 78 |
]); |
| 79 |
let b = i16x16::from([ |
| 80 |
17, -18, 1, 1, 20, 5, 900, 900, 17, -18, 1, 1, 20, 5, 900, 900, |
| 81 |
]); |
| 82 |
let expected = i16x16::from([ |
| 83 |
-16, |
| 84 |
20, |
| 85 |
i16::MIN, |
| 86 |
i16::MAX, |
| 87 |
-5, |
| 88 |
15, |
| 89 |
4100, |
| 90 |
2090, |
| 91 |
-16, |
| 92 |
20, |
| 93 |
i16::MIN, |
| 94 |
i16::MAX, |
| 95 |
-5, |
| 96 |
15, |
| 97 |
4100, |
| 98 |
2090, |
| 99 |
]); |
| 100 |
let actual = a - b; |
| 101 |
assert_eq!(expected, actual); |
| 102 |
} |
| 103 |
|
| 104 |
#[test] |
| 105 |
fn impl_saturating_add_for_i16x16() { |
| 106 |
let a = i16x16::from([ |
| 107 |
1, |
| 108 |
2, |
| 109 |
i16::MAX - 1, |
| 110 |
i16::MAX - 1, |
| 111 |
15, |
| 112 |
20, |
| 113 |
5000, |
| 114 |
2990, |
| 115 |
1, |
| 116 |
2, |
| 117 |
i16::MAX - 1, |
| 118 |
i16::MAX - 1, |
| 119 |
15, |
| 120 |
20, |
| 121 |
5000, |
| 122 |
2990, |
| 123 |
]); |
| 124 |
let b = i16x16::from([ |
| 125 |
17, 18, 1, 2, 20, 5, 900, 900, 17, 18, 1, 2, 20, 5, 900, 900, |
| 126 |
]); |
| 127 |
let expected = i16x16::from([ |
| 128 |
18, |
| 129 |
20, |
| 130 |
i16::MAX, |
| 131 |
i16::MAX, |
| 132 |
35, |
| 133 |
25, |
| 134 |
5900, |
| 135 |
3890, |
| 136 |
18, |
| 137 |
20, |
| 138 |
i16::MAX, |
| 139 |
i16::MAX, |
| 140 |
35, |
| 141 |
25, |
| 142 |
5900, |
| 143 |
3890, |
| 144 |
]); |
| 145 |
let actual = a.saturating_add(b); |
| 146 |
assert_eq!(expected, actual); |
| 147 |
} |
| 148 |
|
| 149 |
#[test] |
| 150 |
fn impl_saturating_sub_for_i16x16() { |
| 151 |
let a = i16x16::from([ |
| 152 |
1, |
| 153 |
2, |
| 154 |
i16::MIN + 1, |
| 155 |
i16::MIN, |
| 156 |
15, |
| 157 |
20, |
| 158 |
5000, |
| 159 |
2990, |
| 160 |
1, |
| 161 |
2, |
| 162 |
i16::MIN + 1, |
| 163 |
i16::MIN, |
| 164 |
15, |
| 165 |
20, |
| 166 |
5000, |
| 167 |
2990, |
| 168 |
]); |
| 169 |
let b = i16x16::from([ |
| 170 |
17, -18, 1, 1, 20, 5, 900, 900, 17, -18, 1, 1, 20, 5, 900, 900, |
| 171 |
]); |
| 172 |
let expected = i16x16::from([ |
| 173 |
-16, |
| 174 |
20, |
| 175 |
i16::MIN, |
| 176 |
i16::MIN, |
| 177 |
-5, |
| 178 |
15, |
| 179 |
4100, |
| 180 |
2090, |
| 181 |
-16, |
| 182 |
20, |
| 183 |
i16::MIN, |
| 184 |
i16::MIN, |
| 185 |
-5, |
| 186 |
15, |
| 187 |
4100, |
| 188 |
2090, |
| 189 |
]); |
| 190 |
let actual = a.saturating_sub(b); |
| 191 |
assert_eq!(expected, actual); |
| 192 |
} |
| 193 |
|
| 194 |
#[test] |
| 195 |
fn impl_mul_scale_i16x16() { |
| 196 |
let a = i16x16::from([ |
| 197 |
0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, |
| 198 |
1400, 1500, |
| 199 |
]); |
| 200 |
let b = i16x16::from([ |
| 201 |
0, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000, |
| 202 |
2100, 2200, 2300, |
| 203 |
]); |
| 204 |
let actual = a.mul_scale_round(b); |
| 205 |
let expected = i16x16::from([ |
| 206 |
0, 3, 6, 10, 15, 20, 26, 32, 39, 47, 55, 64, 73, 83, 94, 105, |
| 207 |
]); |
| 208 |
assert_eq!(expected, actual); |
| 209 |
} |
| 210 |
|
| 211 |
#[test] |
| 212 |
fn impl_mul_scale_n_i16x16() { |
| 213 |
let a = i16x16::from([ |
| 214 |
0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, |
| 215 |
1400, 1500, |
| 216 |
]); |
| 217 |
let actual = a.mul_scale_round_n(16400); // slightly higher than 0.5 to test rounding |
| 218 |
let expected = i16x16::from([ |
| 219 |
0, 50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 551, 601, 651, 701, 751, |
| 220 |
]); |
| 221 |
assert_eq!(expected, actual); |
| 222 |
} |
| 223 |
|
| 224 |
#[test] |
| 225 |
fn impl_mul_for_i16x16() { |
| 226 |
let a = i16x16::from([ |
| 227 |
1, |
| 228 |
2, |
| 229 |
i16::MIN + 1, |
| 230 |
i16::MIN, |
| 231 |
2, |
| 232 |
3, |
| 233 |
4, |
| 234 |
5, |
| 235 |
1, |
| 236 |
2, |
| 237 |
i16::MIN + 1, |
| 238 |
i16::MIN, |
| 239 |
2, |
| 240 |
3, |
| 241 |
4, |
| 242 |
5, |
| 243 |
]); |
| 244 |
let b = |
| 245 |
i16x16::from([17, -18, 1, 1, -1, -2, -6, 3, 17, -18, 1, 1, -1, -2, -6, 3]); |
| 246 |
let expected = i16x16::from([ |
| 247 |
17, |
| 248 |
-36, |
| 249 |
i16::MIN + 1, |
| 250 |
i16::MIN, |
| 251 |
-2, |
| 252 |
-6, |
| 253 |
-24, |
| 254 |
15, |
| 255 |
17, |
| 256 |
-36, |
| 257 |
i16::MIN + 1, |
| 258 |
i16::MIN, |
| 259 |
-2, |
| 260 |
-6, |
| 261 |
-24, |
| 262 |
15, |
| 263 |
]); |
| 264 |
let actual = a * b; |
| 265 |
assert_eq!(expected, actual); |
| 266 |
} |
| 267 |
|
| 268 |
#[test] |
| 269 |
fn impl_bitand_for_i16x16() { |
| 270 |
let a = i16x16::from([0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1]); |
| 271 |
let b = i16x16::from([0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1]); |
| 272 |
let expected = i16x16::from([0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1]); |
| 273 |
let actual = a & b; |
| 274 |
assert_eq!(expected, actual); |
| 275 |
} |
| 276 |
|
| 277 |
#[test] |
| 278 |
fn impl_bitor_for_i16x16() { |
| 279 |
let a = i16x16::from([0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1]); |
| 280 |
let b = i16x16::from([0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1]); |
| 281 |
let expected = i16x16::from([0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1]); |
| 282 |
let actual = a | b; |
| 283 |
assert_eq!(expected, actual); |
| 284 |
} |
| 285 |
|
| 286 |
#[test] |
| 287 |
fn impl_bitxor_for_i16x16() { |
| 288 |
let a = i16x16::from([0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1]); |
| 289 |
let b = i16x16::from([0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1]); |
| 290 |
let expected = i16x16::from([0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0]); |
| 291 |
let actual = a ^ b; |
| 292 |
assert_eq!(expected, actual); |
| 293 |
} |
| 294 |
|
| 295 |
#[test] |
| 296 |
fn impl_shl_for_i16x16() { |
| 297 |
let a = i16x16::from([ |
| 298 |
1, |
| 299 |
2, |
| 300 |
i16::MAX - 1, |
| 301 |
i16::MAX - 1, |
| 302 |
128, |
| 303 |
255, |
| 304 |
590, |
| 305 |
5667, |
| 306 |
1, |
| 307 |
2, |
| 308 |
i16::MAX - 1, |
| 309 |
i16::MAX - 1, |
| 310 |
128, |
| 311 |
255, |
| 312 |
590, |
| 313 |
5667, |
| 314 |
]); |
| 315 |
let b = 2; |
| 316 |
let expected = i16x16::from([ |
| 317 |
1 << 2, |
| 318 |
2 << 2, |
| 319 |
(i16::MAX - 1) << 2, |
| 320 |
(i16::MAX - 1) << 2, |
| 321 |
128 << 2, |
| 322 |
255 << 2, |
| 323 |
590 << 2, |
| 324 |
5667 << 2, |
| 325 |
1 << 2, |
| 326 |
2 << 2, |
| 327 |
(i16::MAX - 1) << 2, |
| 328 |
(i16::MAX - 1) << 2, |
| 329 |
128 << 2, |
| 330 |
255 << 2, |
| 331 |
590 << 2, |
| 332 |
5667 << 2, |
| 333 |
]); |
| 334 |
let actual = a << b; |
| 335 |
assert_eq!(expected, actual); |
| 336 |
} |
| 337 |
|
| 338 |
#[test] |
| 339 |
fn impl_shr_for_i16x16() { |
| 340 |
let a = i16x16::from([ |
| 341 |
1, |
| 342 |
2, |
| 343 |
i16::MAX - 1, |
| 344 |
i16::MAX - 1, |
| 345 |
128, |
| 346 |
255, |
| 347 |
590, |
| 348 |
5667, |
| 349 |
1, |
| 350 |
2, |
| 351 |
i16::MAX - 1, |
| 352 |
i16::MAX - 1, |
| 353 |
128, |
| 354 |
255, |
| 355 |
590, |
| 356 |
5667, |
| 357 |
]); |
| 358 |
let b = 2; |
| 359 |
let expected = i16x16::from([ |
| 360 |
1 >> 2, |
| 361 |
2 >> 2, |
| 362 |
(i16::MAX - 1) >> 2, |
| 363 |
(i16::MAX - 1) >> 2, |
| 364 |
128 >> 2, |
| 365 |
255 >> 2, |
| 366 |
590 >> 2, |
| 367 |
5667 >> 2, |
| 368 |
1 >> 2, |
| 369 |
2 >> 2, |
| 370 |
(i16::MAX - 1) >> 2, |
| 371 |
(i16::MAX - 1) >> 2, |
| 372 |
128 >> 2, |
| 373 |
255 >> 2, |
| 374 |
590 >> 2, |
| 375 |
5667 >> 2, |
| 376 |
]); |
| 377 |
let actual = a >> b; |
| 378 |
assert_eq!(expected, actual); |
| 379 |
} |
| 380 |
|
| 381 |
#[test] |
| 382 |
fn impl_i16x16_cmp_eq() { |
| 383 |
let a = i16x16::from([1, 2, 3, 4, 2, 1, 8, 2, 1, 2, 3, 4, 2, 1, 8, 2]); |
| 384 |
let b = i16x16::from([2_i16; 16]); |
| 385 |
let expected = |
| 386 |
i16x16::from([0, -1, 0, 0, -1, 0, 0, -1, 0, -1, 0, 0, -1, 0, 0, -1]); |
| 387 |
let actual = a.cmp_eq(b); |
| 388 |
assert_eq!(expected, actual); |
| 389 |
} |
| 390 |
|
| 391 |
#[test] |
| 392 |
fn impl_i16x16_cmp_gt() { |
| 393 |
let a = i16x16::from([1, 2, 9, 4, 1, 2, 8, 10, 1, 2, 9, 4, 1, 2, 8, 10]); |
| 394 |
let b = i16x16::from([5_i16; 16]); |
| 395 |
let expected = |
| 396 |
i16x16::from([0, 0, -1, 0, 0, 0, -1, -1, 0, 0, -1, 0, 0, 0, -1, -1]); |
| 397 |
let actual = a.cmp_gt(b); |
| 398 |
assert_eq!(expected, actual); |
| 399 |
} |
| 400 |
|
| 401 |
#[test] |
| 402 |
fn impl_i16x16_cmp_lt() { |
| 403 |
let a = i16x16::from([1, 2, 9, 4, 1, 2, 8, 10, 1, 2, 9, 4, 1, 2, 8, 10]); |
| 404 |
let b = i16x16::from([5_i16; 16]); |
| 405 |
let expected = |
| 406 |
i16x16::from([-1, -1, 0, -1, -1, -1, 0, 0, -1, -1, 0, -1, -1, -1, 0, 0]); |
| 407 |
let actual = a.cmp_lt(b); |
| 408 |
assert_eq!(expected, actual); |
| 409 |
|
| 410 |
let expected = i16x16::from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); |
| 411 |
let actual = a.cmp_lt(a); |
| 412 |
assert_eq!(expected, actual); |
| 413 |
} |
| 414 |
|
| 415 |
#[test] |
| 416 |
fn impl_i16x16_blend() { |
| 417 |
let use_t: i16 = -1; |
| 418 |
let t = i16x16::from([1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8]); |
| 419 |
let f = i16x16::from([ |
| 420 |
17, 18, 19, 20, 25, 30, 50, 90, 17, 18, 19, 20, 25, 30, 50, 90, |
| 421 |
]); |
| 422 |
let mask = i16x16::from([ |
| 423 |
use_t, 0, use_t, 0, 0, 0, 0, use_t, use_t, 0, use_t, 0, 0, 0, 0, use_t, |
| 424 |
]); |
| 425 |
let expected = |
| 426 |
i16x16::from([1, 18, 3, 20, 25, 30, 50, 8, 1, 18, 3, 20, 25, 30, 50, 8]); |
| 427 |
let actual = mask.blend(t, f); |
| 428 |
assert_eq!(expected, actual); |
| 429 |
} |
| 430 |
|
| 431 |
#[test] |
| 432 |
fn impl_i16x16_abs() { |
| 433 |
let a = i16x16::from([ |
| 434 |
-1, |
| 435 |
2, |
| 436 |
-3, |
| 437 |
i16::MIN, |
| 438 |
6, |
| 439 |
-15, |
| 440 |
-19, |
| 441 |
9, |
| 442 |
-1, |
| 443 |
2, |
| 444 |
-3, |
| 445 |
i16::MIN, |
| 446 |
6, |
| 447 |
-15, |
| 448 |
-19, |
| 449 |
9, |
| 450 |
]); |
| 451 |
let expected = i16x16::from([ |
| 452 |
1, |
| 453 |
2, |
| 454 |
3, |
| 455 |
i16::MIN, |
| 456 |
6, |
| 457 |
15, |
| 458 |
19, |
| 459 |
9, |
| 460 |
1, |
| 461 |
2, |
| 462 |
3, |
| 463 |
i16::MIN, |
| 464 |
6, |
| 465 |
15, |
| 466 |
19, |
| 467 |
9, |
| 468 |
]); |
| 469 |
let actual = a.abs(); |
| 470 |
assert_eq!(expected, actual); |
| 471 |
} |
| 472 |
|
| 473 |
#[test] |
| 474 |
fn impl_i16x16_max() { |
| 475 |
let a = i16x16::from([ |
| 476 |
1, |
| 477 |
2, |
| 478 |
i16::MIN + 1, |
| 479 |
i16::MIN, |
| 480 |
6, |
| 481 |
-8, |
| 482 |
12, |
| 483 |
9, |
| 484 |
1, |
| 485 |
2, |
| 486 |
i16::MIN + 1, |
| 487 |
i16::MIN, |
| 488 |
6, |
| 489 |
-8, |
| 490 |
12, |
| 491 |
9, |
| 492 |
]); |
| 493 |
let b = i16x16::from([ |
| 494 |
17, -18, 1, 1, 19, -5, -1, -9, 17, -18, 1, 1, 19, -5, -1, -9, |
| 495 |
]); |
| 496 |
let expected = |
| 497 |
i16x16::from([17, 2, 1, 1, 19, -5, 12, 9, 17, 2, 1, 1, 19, -5, 12, 9]); |
| 498 |
let actual = a.max(b); |
| 499 |
assert_eq!(expected, actual); |
| 500 |
|
| 501 |
crate::test_random_vector_vs_scalar(|a: i16x16, b| a.max(b), |a, b| a.max(b)); |
| 502 |
} |
| 503 |
|
| 504 |
#[test] |
| 505 |
fn impl_i16x16_min() { |
| 506 |
let a = i16x16::from([ |
| 507 |
1, |
| 508 |
2, |
| 509 |
i16::MIN + 1, |
| 510 |
i16::MIN, |
| 511 |
6, |
| 512 |
-8, |
| 513 |
12, |
| 514 |
9, |
| 515 |
1, |
| 516 |
2, |
| 517 |
i16::MIN + 1, |
| 518 |
i16::MIN, |
| 519 |
6, |
| 520 |
-8, |
| 521 |
12, |
| 522 |
9, |
| 523 |
]); |
| 524 |
let b = i16x16::from([ |
| 525 |
17, -18, 1, 1, 19, -5, -1, -9, 17, -18, 1, 1, 19, -5, -1, -9, |
| 526 |
]); |
| 527 |
let expected = i16x16::from([ |
| 528 |
1, |
| 529 |
-18, |
| 530 |
i16::MIN + 1, |
| 531 |
i16::MIN, |
| 532 |
6, |
| 533 |
-8, |
| 534 |
-1, |
| 535 |
-9, |
| 536 |
1, |
| 537 |
-18, |
| 538 |
i16::MIN + 1, |
| 539 |
i16::MIN, |
| 540 |
6, |
| 541 |
-8, |
| 542 |
-1, |
| 543 |
-9, |
| 544 |
]); |
| 545 |
let actual = a.min(b); |
| 546 |
assert_eq!(expected, actual); |
| 547 |
|
| 548 |
crate::test_random_vector_vs_scalar(|a: i16x16, b| a.min(b), |a, b| a.min(b)); |
| 549 |
} |
| 550 |
|
| 551 |
#[test] |
| 552 |
fn impl_from_i8x16() { |
| 553 |
let a = i8x16::from([ |
| 554 |
10, |
| 555 |
2, |
| 556 |
-3, |
| 557 |
4, |
| 558 |
5, |
| 559 |
-6, |
| 560 |
7, |
| 561 |
8, |
| 562 |
9, |
| 563 |
7, |
| 564 |
i8::MAX, |
| 565 |
12, |
| 566 |
13, |
| 567 |
6, |
| 568 |
55, |
| 569 |
i8::MIN, |
| 570 |
]); |
| 571 |
|
| 572 |
let actual = i16x16::from_i8x16(a); |
| 573 |
|
| 574 |
let expected = i16x16::from([ |
| 575 |
10, |
| 576 |
2, |
| 577 |
-3, |
| 578 |
4, |
| 579 |
5, |
| 580 |
-6, |
| 581 |
7, |
| 582 |
8, |
| 583 |
9, |
| 584 |
7, |
| 585 |
i8::MAX as i16, |
| 586 |
12, |
| 587 |
13, |
| 588 |
6, |
| 589 |
55, |
| 590 |
i8::MIN as i16, |
| 591 |
]); |
| 592 |
|
| 593 |
assert_eq!(expected, actual); |
| 594 |
} |
| 595 |
|
| 596 |
#[test] |
| 597 |
fn test_i16x16_move_mask() { |
| 598 |
let indexes = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; |
| 599 |
|
| 600 |
for x in 0..256 { |
| 601 |
// multiply by prime number to mix bits a bit |
| 602 |
let i = x * 251; |
| 603 |
|
| 604 |
let a = |
| 605 |
i16x16::from(indexes.map(|x| if i & (1 << x) != 0 { -1 } else { 0 })); |
| 606 |
|
| 607 |
assert_eq!(a.move_mask(), i); |
| 608 |
} |
| 609 |
|
| 610 |
let a = |
| 611 |
i16x16::from([-1, 0, -2, -3, -1, 0, -2, -3, -1, 0, -1, 0, -1, 0, -1, 0]); |
| 612 |
|
| 613 |
let expected = 0b0101010111011101; |
| 614 |
let actual = a.move_mask(); |
| 615 |
assert_eq!(expected, actual); |
| 616 |
} |
| 617 |
|
| 618 |
#[test] |
| 619 |
fn test_i16x16_any() { |
| 620 |
let a = i16x16::from([0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); |
| 621 |
assert!(a.any()); |
| 622 |
|
| 623 |
let a = i16x16::from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0]); |
| 624 |
assert!(a.any()); |
| 625 |
|
| 626 |
// |
| 627 |
let a = i16x16::from([0; 16]); |
| 628 |
assert!(!a.any()); |
| 629 |
} |
| 630 |
|
| 631 |
#[test] |
| 632 |
fn test_i16x16_all() { |
| 633 |
let a = i16x16::from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0]); |
| 634 |
assert!(!a.all()); |
| 635 |
// |
| 636 |
let a = i16x16::from([-1; 16]); |
| 637 |
assert!(a.all()); |
| 638 |
} |
| 639 |
|
| 640 |
#[test] |
| 641 |
fn test_i16x16_none() { |
| 642 |
let a = i16x16::from([0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); |
| 643 |
assert!(!a.none()); |
| 644 |
|
| 645 |
let a = i16x16::from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0]); |
| 646 |
assert!(!a.none()); |
| 647 |
|
| 648 |
// |
| 649 |
let a = i16x16::from([0; 16]); |
| 650 |
assert!(a.none()); |
| 651 |
} |
| 652 |
|
| 653 |
#[test] |
| 654 |
fn impl_i16x16_reduce_add() { |
| 655 |
let p = |
| 656 |
i16x16::from([1, 2, 3, 4, 5, 6, 7, 9, 10, 20, 30, 40, 50, 60, 70, 90]); |
| 657 |
assert_eq!(p.reduce_add(), 407); |
| 658 |
} |
| 659 |
|
| 660 |
#[test] |
| 661 |
fn impl_dot_for_i16x16() { |
| 662 |
let a = i16x16::from([ |
| 663 |
1, |
| 664 |
2, |
| 665 |
3, |
| 666 |
4, |
| 667 |
5, |
| 668 |
6, |
| 669 |
i16::MIN + 1, |
| 670 |
i16::MIN, |
| 671 |
10, |
| 672 |
20, |
| 673 |
30, |
| 674 |
40, |
| 675 |
50, |
| 676 |
60, |
| 677 |
i16::MAX - 1, |
| 678 |
i16::MAX, |
| 679 |
]); |
| 680 |
let b = i16x16::from([ |
| 681 |
17, -18, 190, -20, 21, -22, 3, 2, 170, -180, 1900, -200, 210, -220, 30, 20, |
| 682 |
]); |
| 683 |
let expected = |
| 684 |
i32x8::from([-19, 490, -27, -163837, -1900, 49000, -2700, 1638320]); |
| 685 |
let actual = a.dot(b); |
| 686 |
assert_eq!(expected, actual); |
| 687 |
} |
| 688 |
|
| 689 |
#[test] |
| 690 |
fn impl_i16x16_reduce_min() { |
| 691 |
for i in 0..8 { |
| 692 |
let mut v = [i16::MAX; 16]; |
| 693 |
v[i] = i16::MIN; |
| 694 |
let p = i16x16::from(v); |
| 695 |
assert_eq!(p.reduce_min(), i16::MIN); |
| 696 |
} |
| 697 |
} |
| 698 |
|
| 699 |
#[test] |
| 700 |
fn impl_i16x16_reduce_max() { |
| 701 |
for i in 0..8 { |
| 702 |
let mut v = [i16::MIN; 16]; |
| 703 |
v[i] = i16::MAX; |
| 704 |
let p = i16x16::from(v); |
| 705 |
assert_eq!(p.reduce_min(), i16::MIN); |
| 706 |
} |
| 707 |
} |
| 708 |
|
| 709 |
#[cfg(feature = "serde")] |
| 710 |
#[test] |
| 711 |
fn impl_i16x16_ser_de_roundtrip() { |
| 712 |
let serialized = |
| 713 |
bincode::serialize(&i16x16::ZERO).expect("serialization failed"); |
| 714 |
let deserialized = |
| 715 |
bincode::deserialize(&serialized).expect("deserializaion failed"); |
| 716 |
assert_eq!(i16x16::ZERO, deserialized); |
| 717 |
} |