4 ms·
I looked at the disassembly of both of those in https://godbolt.org/ https://godbolt.org/ and it looks like for some reason Rust puts the loop variables x,y and
by trishume 8y ago
I looked at the disassembly of both of those in https://godbolt.org/ https://godbolt.org/ and it looks like for some reason Rust puts the loop variables x,y and z on the stack and the loads them off the stack. This causes a bunch of L1 hits instead of register hits in the tight loop, causing the 2x slowdown.
I have no idea why LLVM misses optimizing this in Rust's case. Likely it is fed much trickier IR. It also misses the optimization that it does in the C case of lifting the xx and zz multiplications to the appropriate loop level.