|
| 1 | +#![feature(portable_simd)] |
| 2 | +use core_simd::simd::prelude::*; |
| 3 | + |
| 4 | +#[cfg(target_arch = "wasm32")] |
| 5 | +use wasm_bindgen_test::*; |
| 6 | + |
| 7 | +#[cfg(target_arch = "wasm32")] |
| 8 | +wasm_bindgen_test_configure!(run_in_browser); |
| 9 | + |
| 10 | +#[test] |
| 11 | +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] |
| 12 | +fn masked_load_store() { |
| 13 | + let mut arr = [u8::MAX; 7]; |
| 14 | + |
| 15 | + u8x4::splat(0).masked_store(&mut arr[5..], Mask::from_array([false, true, false, true])); |
| 16 | + // write to index 8 is OOB and dropped |
| 17 | + assert_eq!(arr, [255u8, 255, 255, 255, 255, 255, 0]); |
| 18 | + |
| 19 | + u8x4::from_array([0, 1, 2, 3]).masked_store(&mut arr[1..], Mask::splat(true)); |
| 20 | + assert_eq!(arr, [255u8, 0, 1, 2, 3, 255, 0]); |
| 21 | + |
| 22 | + // read from index 8 is OOB and dropped |
| 23 | + assert_eq!( |
| 24 | + u8x4::masked_load_or(&arr[4..], u8x4::splat(42)), |
| 25 | + u8x4::from_array([3, 255, 0, 42]) |
| 26 | + ); |
| 27 | + assert_eq!( |
| 28 | + u8x4::masked_load_select( |
| 29 | + &arr[4..], |
| 30 | + Mask::from_array([true, false, true, true]), |
| 31 | + u8x4::splat(42) |
| 32 | + ), |
| 33 | + u8x4::from_array([3, 42, 0, 42]) |
| 34 | + ); |
| 35 | +} |
0 commit comments