Open gnzlbg opened 5 years ago
We should add an unsafe shuffle1_dyn_unchecked API that has undefined behavior if the index is out-of-bounds and not 0x80.
We should change shuffle1_dyn to panic! if any index is out-of-bounds and not 0x80 (that is, shuffle1_dyn checks the indices and calls shuffle1_dyn_unchecked).
Both APIs should set the resulting lane to 0 if the index is 0x80 - we can provide a: const SHUFFLE1_DYN_ZERO: usize = 0x80; constant for this.Both APIs should set the resulting lane to 0 if the index is 0x80 - we can provide a: const SHUFFLE1_DYN_ZERO: usize = 0x80; constant for this.
I'd prefer the following, which is equally as consistent across architectures, and is defined in more cases: instead of the "return-zero" case being ==0x80
, instead make it >=0x80
. On all of x86_64, ARM, MIPS, RISCV it has a zero-cost implementation. On PPC64 I'd guess (although I don't know that ISA) it still has a 3-instruction sequence (compare to 0x80, shuffle, andnot), but this time the comparison is >=
instead of ==
.
With >=0x80
the implementation is defined in more cases, which is more useful for users (admittedly it constrains future hardware implementors). An especially useful case is that we'd like an index of 0xFF
to return zero; this comes up naturally when ORing with m8
mask objects.
Currently,
shuffle1_dyn
is a safe function, but if the index is out-of-bounds its behavior is undefined: it willpanic!
in some archs, and return an unspecified lane value in others - this is a bug (allowing safe Rust to have UB).[ ] We should add an
unsafe
shuffle1_dyn_unchecked
API that has undefined behavior if the index is out-of-bounds and not0x80
.[ ] We should change
shuffle1_dyn
topanic!
if any index is out-of-bounds and not0x80
(that is,shuffle1_dyn
checks the indices and callsshuffle1_dyn_unchecked
).[ ] Both APIs should set the resulting lane to
0
if the index is0x80
- we can provide a:const SHUFFLE1_DYN_ZERO: usize = 0x80;
constant for this.See https://github.com/WebAssembly/simd/issues/68 , https://github.com/WebAssembly/simd/issues/24, https://github.com/WebAssembly/simd/pull/71
where @zeux mentioned: