4 ms·
The example here is trivially safe but more general SIMD safety is going to be extremely difficult to analyze for safety, possibly intractable. For example, it
by jandrewrogers 2y ago
The example here is trivially safe but more general SIMD safety is going to be extremely difficult to analyze for safety, possibly intractable.
For example, it is perfectly legal to dereference a vector pointer that references illegal memory if you mask the illegal addresses. This is a useful trick and common in e.g. idiomatic AVX-512 code. The mask registers are almost always computed at runtime so it would be effectively impossible to determine if a potentially illegal dereference is actually illegal at compile-time.
I suspect we’ll be hand-rolling unsafe SIMD for a long time. The different ISAs are too different, inconsistent, and weird. A compiler that could make this clean and safe is like fusion power, it has always been 10 years away my entire career.
- vlovich123 2y agoPresumably a bounds check on the mask could be done or a safe variant exposed that does that trick under the hood. But yeah I don’t disagree that it’s “safe SIMD” is unlikely to scratch the itch for various applications but hopefully at least it’ll scratch a lot of them enough that the remaining unsafe is reduced.
- fooker 2y agoNo, a bounds check beats the purpose of simd in these cases
- vlovich123 2y agoNot necessarily if you can hoist the bounds check outside of the loop somehow.