bytecodealliance / wasmtime

A fast and secure runtime for WebAssembly
https://wasmtime.dev/
Apache License 2.0
15.08k stars 1.26k forks source link

[cranelift] Avoid 64-bit imul_imm if possible on all architectures #4686

Open MaxGraey opened 2 years ago

MaxGraey commented 2 years ago

Feature

Not all architectures has a fast 64-bit imul + imm. But even on modern like SnB-family and AMD Ryzen it takes 3 cycle latency, 1c throughput which not always faster lea + shl / add combination. So I propose use lowering to lea + shl / add for non-power of two constants at least for imm < 400 with low hamming weight and 64-bit imul only if this possible. Similar to GCC:

https://godbolt.org/z/aG7bPer9v

bjorn3 commented 2 years ago

for non-power of two constants at least for imm < 400

Should this check for a low hamming weight rather than a max value?

MaxGraey commented 2 years ago

low hamming weight rather than a max value?

Yeah, perhaps this will be better