Re:Zlib-rs is faster than C
by vlovich123 on Monday March 17, 2025 @02:00AM
(#43385562)
Presumably 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.
No, a bounds check beats the purpose of simd in these cases
Re:Zlib-rs is faster than C
by vlovich123 on Monday March 17, 2025 @12:37PM
(#43390317)
Not necessarily if you can hoist the bounds check outside of the loop somehow.
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.