| 1 |
use wide::*; |
| 2 |
|
| 3 |
#[test] |
| 4 |
fn size_align() { |
| 5 |
assert_eq!(core::mem::size_of::<i8x16>(), 16); |
| 6 |
assert_eq!(core::mem::align_of::<i8x16>(), 16); |
| 7 |
} |
| 8 |
|
| 9 |
#[test] |
| 10 |
fn basic_traits() { |
| 11 |
crate::test_basic_traits::<i8x16, _, 16>(); |
| 12 |
} |
| 13 |
|
| 14 |
#[test] |
| 15 |
fn impl_add_for_i8x16() { |
| 16 |
let a = |
| 17 |
i8x16::from([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 126, 127]); |
| 18 |
let b = |
| 19 |
i8x16::from([17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 1, 1]); |
| 20 |
let expected = i8x16::from([ |
| 21 |
18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 127, -128, |
| 22 |
]); |
| 23 |
let actual = a + b; |
| 24 |
assert_eq!(expected, actual); |
| 25 |
} |
| 26 |
|
| 27 |
#[test] |
| 28 |
fn impl_sub_for_i8x16() { |
| 29 |
let a = i8x16::from([ |
| 30 |
1, |
| 31 |
2, |
| 32 |
3, |
| 33 |
4, |
| 34 |
5, |
| 35 |
6, |
| 36 |
7, |
| 37 |
8, |
| 38 |
9, |
| 39 |
10, |
| 40 |
11, |
| 41 |
12, |
| 42 |
13, |
| 43 |
14, |
| 44 |
i8::MIN + 1, |
| 45 |
i8::MIN, |
| 46 |
]); |
| 47 |
let b = |
| 48 |
i8x16::from([17, 27, -1, 20, 21, -8, 23, 0, 1, 2, -9, 28, 64, 30, 1, 1]); |
| 49 |
let expected = i8x16::from([ |
| 50 |
-16, |
| 51 |
-25, |
| 52 |
4, |
| 53 |
-16, |
| 54 |
-16, |
| 55 |
14, |
| 56 |
-16, |
| 57 |
8, |
| 58 |
8, |
| 59 |
8, |
| 60 |
20, |
| 61 |
-16, |
| 62 |
-51, |
| 63 |
-16, |
| 64 |
i8::MIN, |
| 65 |
i8::MAX, |
| 66 |
]); |
| 67 |
let actual = a - b; |
| 68 |
assert_eq!(expected, actual); |
| 69 |
} |
| 70 |
|
| 71 |
#[test] |
| 72 |
fn impl_saturating_add_for_i8x16() { |
| 73 |
let a = |
| 74 |
i8x16::from([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 126, 127]); |
| 75 |
let b = |
| 76 |
i8x16::from([17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 1, 1]); |
| 77 |
let expected = i8x16::from([ |
| 78 |
18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 127, 127, |
| 79 |
]); |
| 80 |
let actual = a.saturating_add(b); |
| 81 |
assert_eq!(expected, actual); |
| 82 |
} |
| 83 |
|
| 84 |
#[test] |
| 85 |
fn impl_saturating_sub_for_i8x16() { |
| 86 |
let a = i8x16::from([ |
| 87 |
1, |
| 88 |
2, |
| 89 |
3, |
| 90 |
4, |
| 91 |
5, |
| 92 |
6, |
| 93 |
7, |
| 94 |
8, |
| 95 |
9, |
| 96 |
10, |
| 97 |
11, |
| 98 |
12, |
| 99 |
13, |
| 100 |
14, |
| 101 |
i8::MIN + 1, |
| 102 |
i8::MIN, |
| 103 |
]); |
| 104 |
let b = |
| 105 |
i8x16::from([17, 27, -1, 20, 21, -8, 23, 0, 1, 2, -9, 28, 64, 30, 1, 1]); |
| 106 |
let expected = i8x16::from([ |
| 107 |
-16, |
| 108 |
-25, |
| 109 |
4, |
| 110 |
-16, |
| 111 |
-16, |
| 112 |
14, |
| 113 |
-16, |
| 114 |
8, |
| 115 |
8, |
| 116 |
8, |
| 117 |
20, |
| 118 |
-16, |
| 119 |
-51, |
| 120 |
-16, |
| 121 |
i8::MIN, |
| 122 |
i8::MIN, |
| 123 |
]); |
| 124 |
let actual = a.saturating_sub(b); |
| 125 |
assert_eq!(expected, actual); |
| 126 |
} |
| 127 |
|
| 128 |
#[test] |
| 129 |
fn impl_bitand_for_i8x16() { |
| 130 |
let a = i8x16::from([0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1]); |
| 131 |
let b = i8x16::from([0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]); |
| 132 |
let expected = i8x16::from([0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1]); |
| 133 |
let actual = a & b; |
| 134 |
assert_eq!(expected, actual); |
| 135 |
} |
| 136 |
|
| 137 |
#[test] |
| 138 |
fn impl_bitor_for_i8x16() { |
| 139 |
let a = i8x16::from([0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1]); |
| 140 |
let b = i8x16::from([0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]); |
| 141 |
let expected = i8x16::from([0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1]); |
| 142 |
let actual = a | b; |
| 143 |
assert_eq!(expected, actual); |
| 144 |
} |
| 145 |
|
| 146 |
#[test] |
| 147 |
fn impl_bitxor_for_i8x16() { |
| 148 |
let a = i8x16::from([0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1]); |
| 149 |
let b = i8x16::from([0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]); |
| 150 |
let expected = i8x16::from([0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0]); |
| 151 |
let actual = a ^ b; |
| 152 |
assert_eq!(expected, actual); |
| 153 |
} |
| 154 |
|
| 155 |
#[test] |
| 156 |
fn impl_i8x16_cmp_eq() { |
| 157 |
let a = i8x16::from([1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]); |
| 158 |
let b = i8x16::from([2_i8; 16]); |
| 159 |
let expected = |
| 160 |
i8x16::from([0, -1, 0, 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, -1, 0, 0]); |
| 161 |
let actual = a.cmp_eq(b); |
| 162 |
assert_eq!(expected, actual); |
| 163 |
} |
| 164 |
|
| 165 |
#[test] |
| 166 |
fn impl_i8x16_cmp_gt() { |
| 167 |
let a = i8x16::from([1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]); |
| 168 |
let b = i8x16::from([2_i8; 16]); |
| 169 |
let expected = |
| 170 |
i8x16::from([0, 0, -1, -1, 0, 0, -1, -1, 0, 0, -1, -1, 0, 0, -1, -1]); |
| 171 |
let actual = a.cmp_gt(b); |
| 172 |
assert_eq!(expected, actual); |
| 173 |
} |
| 174 |
|
| 175 |
#[test] |
| 176 |
fn impl_i8x16_cmp_lt() { |
| 177 |
let a = i8x16::from([1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]); |
| 178 |
let b = i8x16::from([2_i8; 16]); |
| 179 |
let expected = |
| 180 |
i8x16::from([-1, 0, 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, -1, 0, 0, 0]); |
| 181 |
let actual = a.cmp_lt(b); |
| 182 |
assert_eq!(expected, actual); |
| 183 |
|
| 184 |
let expected = i8x16::from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); |
| 185 |
let actual = a.cmp_lt(a); |
| 186 |
assert_eq!(expected, actual); |
| 187 |
} |
| 188 |
|
| 189 |
#[test] |
| 190 |
fn impl_i8x16_blend() { |
| 191 |
let use_t: i8 = -1; |
| 192 |
let t = |
| 193 |
i8x16::from([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 126, 127]); |
| 194 |
let f = |
| 195 |
i8x16::from([17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 1, 1]); |
| 196 |
let mask = i8x16::from([ |
| 197 |
use_t, 0, use_t, 0, use_t, 0, use_t, 0, use_t, 0, use_t, 0, use_t, 0, |
| 198 |
use_t, 0, |
| 199 |
]); |
| 200 |
let expected = |
| 201 |
i8x16::from([1, 18, 3, 20, 5, 22, 7, 24, 9, 26, 11, 28, 13, 30, 126, 1]); |
| 202 |
let actual = mask.blend(t, f); |
| 203 |
assert_eq!(expected, actual); |
| 204 |
} |
| 205 |
|
| 206 |
#[test] |
| 207 |
fn impl_i8x16_abs() { |
| 208 |
let a = i8x16::from([ |
| 209 |
-1, |
| 210 |
2, |
| 211 |
-3, |
| 212 |
4, |
| 213 |
5, |
| 214 |
-6, |
| 215 |
7, |
| 216 |
8, |
| 217 |
9, |
| 218 |
-10, |
| 219 |
-11, |
| 220 |
12, |
| 221 |
13, |
| 222 |
-14, |
| 223 |
-126, |
| 224 |
i8::MIN, |
| 225 |
]); |
| 226 |
let expected = |
| 227 |
i8x16::from([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 126, i8::MIN]); |
| 228 |
let actual = a.abs(); |
| 229 |
assert_eq!(expected, actual); |
| 230 |
} |
| 231 |
|
| 232 |
#[test] |
| 233 |
fn impl_i8x16_unsigned_abs() { |
| 234 |
let a = i8x16::from([ |
| 235 |
-1, |
| 236 |
2, |
| 237 |
-3, |
| 238 |
4, |
| 239 |
5, |
| 240 |
-6, |
| 241 |
7, |
| 242 |
8, |
| 243 |
9, |
| 244 |
-10, |
| 245 |
-11, |
| 246 |
12, |
| 247 |
13, |
| 248 |
-14, |
| 249 |
-126, |
| 250 |
i8::MIN, |
| 251 |
]); |
| 252 |
let expected = u8x16::from([ |
| 253 |
1, |
| 254 |
2, |
| 255 |
3, |
| 256 |
4, |
| 257 |
5, |
| 258 |
6, |
| 259 |
7, |
| 260 |
8, |
| 261 |
9, |
| 262 |
10, |
| 263 |
11, |
| 264 |
12, |
| 265 |
13, |
| 266 |
14, |
| 267 |
126, |
| 268 |
i8::MIN as u8, |
| 269 |
]); |
| 270 |
let actual = a.unsigned_abs(); |
| 271 |
assert_eq!(expected, actual); |
| 272 |
} |
| 273 |
|
| 274 |
#[test] |
| 275 |
fn impl_i8x16_max() { |
| 276 |
let a = |
| 277 |
i8x16::from([10, 2, -3, 4, 5, -6, 7, 8, 9, 7, -11, 12, 13, 6, 55, i8::MIN]); |
| 278 |
let b = i8x16::from([ |
| 279 |
-1, |
| 280 |
2, |
| 281 |
-3, |
| 282 |
4, |
| 283 |
5, |
| 284 |
-6, |
| 285 |
7, |
| 286 |
8, |
| 287 |
9, |
| 288 |
-10, |
| 289 |
-11, |
| 290 |
12, |
| 291 |
13, |
| 292 |
-14, |
| 293 |
-126, |
| 294 |
i8::MIN + 1, |
| 295 |
]); |
| 296 |
let expected = |
| 297 |
i8x16::from([10, 2, -3, 4, 5, -6, 7, 8, 9, 7, -11, 12, 13, 6, 55, -127]); |
| 298 |
let actual = a.max(b); |
| 299 |
assert_eq!(expected, actual); |
| 300 |
|
| 301 |
crate::test_random_vector_vs_scalar(|a: i8x16, b| a.max(b), |a, b| a.max(b)); |
| 302 |
} |
| 303 |
|
| 304 |
#[test] |
| 305 |
fn impl_i8x16_min() { |
| 306 |
let a = |
| 307 |
i8x16::from([10, 2, -3, 4, 5, -6, 7, 8, 9, 7, -11, 12, 13, 6, 55, i8::MIN]); |
| 308 |
let b = i8x16::from([ |
| 309 |
-1, |
| 310 |
2, |
| 311 |
-3, |
| 312 |
4, |
| 313 |
5, |
| 314 |
-6, |
| 315 |
7, |
| 316 |
8, |
| 317 |
9, |
| 318 |
-10, |
| 319 |
-11, |
| 320 |
12, |
| 321 |
13, |
| 322 |
-14, |
| 323 |
-126, |
| 324 |
i8::MIN + 1, |
| 325 |
]); |
| 326 |
let expected = i8x16::from([ |
| 327 |
-1, |
| 328 |
2, |
| 329 |
-3, |
| 330 |
4, |
| 331 |
5, |
| 332 |
-6, |
| 333 |
7, |
| 334 |
8, |
| 335 |
9, |
| 336 |
-10, |
| 337 |
-11, |
| 338 |
12, |
| 339 |
13, |
| 340 |
-14, |
| 341 |
-126, |
| 342 |
i8::MIN, |
| 343 |
]); |
| 344 |
let actual = a.min(b); |
| 345 |
assert_eq!(expected, actual); |
| 346 |
|
| 347 |
crate::test_random_vector_vs_scalar(|a: i8x16, b| a.min(b), |a, b| a.min(b)); |
| 348 |
} |
| 349 |
|
| 350 |
#[test] |
| 351 |
fn impl_from_i16x16_truncate() { |
| 352 |
let src = i16x16::new([ |
| 353 |
10000, 1001, 2, 3, 4, 5, 6, 32767, 10000, 1001, 2, 128, -129, -128, 127, |
| 354 |
255, |
| 355 |
]); |
| 356 |
|
| 357 |
let expected = i8x16::new([ |
| 358 |
16, -23, 2, 3, 4, 5, 6, -1, 16, -23, 2, -128, 127, -128, 127, -1, |
| 359 |
]); |
| 360 |
|
| 361 |
let result = i8x16::from_i16x16_truncate(src); |
| 362 |
|
| 363 |
assert_eq!(result, expected); |
| 364 |
} |
| 365 |
|
| 366 |
#[test] |
| 367 |
fn impl_from_i16x16_saturate() { |
| 368 |
let src = i16x16::new([ |
| 369 |
10000, 1001, 2, 3, 4, 5, 6, 32767, 10000, 1001, 2, 128, -129, -128, 127, |
| 370 |
255, |
| 371 |
]); |
| 372 |
|
| 373 |
let expected = i8x16::new([ |
| 374 |
127, 127, 2, 3, 4, 5, 6, 127, 127, 127, 2, 127, -128, -128, 127, 127, |
| 375 |
]); |
| 376 |
|
| 377 |
let result = i8x16::from_i16x16_saturate(src); |
| 378 |
|
| 379 |
assert_eq!(result, expected); |
| 380 |
} |
| 381 |
|
| 382 |
#[test] |
| 383 |
fn test_i8x16_move_mask() { |
| 384 |
let a = |
| 385 |
i8x16::from([-1, 0, -2, -3, -1, 0, -2, -3, -1, 0, -1, 0, -1, 0, -1, 0]); |
| 386 |
let expected = 0b0101010111011101; |
| 387 |
let actual = a.move_mask(); |
| 388 |
assert_eq!(expected, actual); |
| 389 |
} |
| 390 |
|
| 391 |
#[test] |
| 392 |
fn test_i8x16_any() { |
| 393 |
let a = i8x16::from([0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); |
| 394 |
assert!(a.any()); |
| 395 |
|
| 396 |
let a = i8x16::from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0]); |
| 397 |
assert!(a.any()); |
| 398 |
|
| 399 |
// |
| 400 |
let a = i8x16::from([0; 16]); |
| 401 |
assert!(!a.any()); |
| 402 |
} |
| 403 |
|
| 404 |
#[test] |
| 405 |
fn test_i8x16_all() { |
| 406 |
let a = i8x16::from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0]); |
| 407 |
assert!(!a.all()); |
| 408 |
// |
| 409 |
let a = i8x16::from([-1; 16]); |
| 410 |
assert!(a.all()); |
| 411 |
} |
| 412 |
|
| 413 |
#[test] |
| 414 |
fn test_i8x16_none() { |
| 415 |
let a = i8x16::from([0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); |
| 416 |
assert!(!a.none()); |
| 417 |
|
| 418 |
let a = i8x16::from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0]); |
| 419 |
assert!(!a.none()); |
| 420 |
|
| 421 |
// |
| 422 |
let a = i8x16::from([0; 16]); |
| 423 |
assert!(a.none()); |
| 424 |
} |
| 425 |
|
| 426 |
#[test] |
| 427 |
fn impl_from_i8_slice() { |
| 428 |
let src = [0, 1_i8, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]; |
| 429 |
|
| 430 |
let result = i8x16::from_slice_unaligned(&src[1..17]); |
| 431 |
|
| 432 |
let expected = |
| 433 |
i8x16::new([1_i8, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]); |
| 434 |
assert_eq!(result, expected); |
| 435 |
} |
| 436 |
|
| 437 |
#[test] |
| 438 |
fn test_i8x16_swizzle() { |
| 439 |
let a = i8x16::from([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]); |
| 440 |
let b = i8x16::from([15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]); |
| 441 |
let expected = |
| 442 |
i8x16::from([16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]); |
| 443 |
let actual = a.swizzle(b); |
| 444 |
assert_eq!(expected, actual); |
| 445 |
|
| 446 |
let b = i8x16::from([15, 17, -13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, -1, 0]); |
| 447 |
let expected = |
| 448 |
i8x16::from([16, 0, 0, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 0, 1]); |
| 449 |
let actual = a.swizzle(b); |
| 450 |
assert_eq!(expected, actual); |
| 451 |
} |
| 452 |
|
| 453 |
#[test] |
| 454 |
fn test_i8x16_swizzle_relaxed() { |
| 455 |
let a = i8x16::from([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]); |
| 456 |
let b = i8x16::from([15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]); |
| 457 |
let expected = |
| 458 |
i8x16::from([16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]); |
| 459 |
let actual = a.swizzle_relaxed(b); |
| 460 |
assert_eq!(expected, actual); |
| 461 |
|
| 462 |
let b = |
| 463 |
i8x16::from([15, -17, -13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, -1, 0]); |
| 464 |
let expected = |
| 465 |
i8x16::from([16, 0, 0, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 0, 1]); |
| 466 |
let actual = a.swizzle_relaxed(b); |
| 467 |
assert_eq!(expected, actual); |
| 468 |
} |
| 469 |
|
| 470 |
#[cfg(feature = "serde")] |
| 471 |
#[test] |
| 472 |
fn impl_i8x16_ser_de_roundtrip() { |
| 473 |
let serialized = |
| 474 |
bincode::serialize(&i8x16::ZERO).expect("serialization failed"); |
| 475 |
let deserialized = |
| 476 |
bincode::deserialize(&serialized).expect("deserializaion failed"); |
| 477 |
assert_eq!(i8x16::ZERO, deserialized); |
| 478 |
} |