3 ms·
> Unfortunately, LEA became very slow in the recent generations of CPUs. Intel doesn’t suggest this will change. lea is a pretty common instruction even in non
by rwmj 3y ago
> Unfortunately, LEA became very slow in the recent generations of CPUs. Intel doesn’t suggest this will change.
lea is a pretty common instruction even in non-OCaml code so this is annoying. I wonder if this has changed since 2014?
$ objdump -d /usr/bin/ls | grep '\blea\b' | wc -l
908
$ objdump -d /usr/bin/ls | wc -l
21398
4.2% of all instructions, and that's an underestimate because the raw objdump -d output contains blank lines, nops, etc.
For an OCaml 4.14 program (/usr/bin/virt-v2v), I got 38886 / 432937 which is 9.0%.
For OCaml 5 using the flambda optimizer, 36531 / 480357 = 7.6%
- orra 3y ago> I wonder if this has changed since 2014? Good question. Probably not. LLVM reduced the number of LEAs in 2017. https://reviews.llvm.org/D32277 https://reviews.llvm.org/D32277 Also, Golang is gradually reducing the number of slow LEAs. https://github.com/golang/go/issues/21735 https://github.com/golang/go/issues/21735 > grep '\blea\b' | wc -l This maybe isn't sophisticated enough? The other links seem to explain two operand LEA isn't so problematic.
- rwmj 3y agoLooks like there have been proposals to eliminate use of 3 operand lea in OCaml code (not accepted sadly): https://github.com/ocaml/ocaml/pull/8531 https://github.com/ocaml/ocaml/pull/8531 https://github.com/ocaml/ocaml/issues/9850 https://github.com/ocaml/ocaml/issues/9850
- asddubs 3y agonot outright rejected either though, the PRs just both died
- saagarjha 3y agoNot all leas, just the three-operand version described in the post. The less complex ones are heavily used for address construction and (less commonly) just normal arithmetic since they can help with port usage.
- devit 3y agoYes, Zen 2+ can execute 4 two-operand LEAs per cycles (according to Agner Fog), and apparently Sapphire Rapids can execute 5 LEAs of any 32/64-bit kind per cycle (according to Intel).
- rollcat 3y agoCommon in program text != common in hot code paths. To estimate the actual impact, you'd have to run the code in a profiler.