|
|
|
|
|
by Const-me
1643 days ago
|
|
> that can easily be fixed Theoretically, yes. Practically, I think that’s a “sufficiently smart compiler” class of problems, insanely hard to solve. Especially given that WASM is a JIT compiler, it simply doesn’t have time for expensive optimizations. Integer SIMD is weird on AMD64. Even state of the art C++ compilers fail to emit optimal code for rather simple use cases. A trivial example is computing sum of bytes: I’m yet to see a compiler which would optimize that code into _mm[256]_sad_epu8 / _mm[256]_add_epi64 instructions. |
|
Detecting every way of doing a 32-bit multiply with a 64-bit mul operator is impossible, yes. But there only needs to be one way of doing it that the compilers knows about, and then people can use that idiom.
It's not pretty, but it works. Compare the common scalar int rotate: x86 can do it in one instruction, but C doesn't have an operator for it. The way to do it in C is to use an idiom that optimizers are known to recognize[1].
1: https://blog.regehr.org/archives/1063