4 ms·
I am surprised to see lea so high on the list. Back when I last wrote x86 assembly code (early 2000s), it was considered slow, but perhaps that has changed.
by fmela 11y ago
I am surprised to see lea so high on the list. Back when I last wrote x86 assembly code (early 2000s), it was considered slow, but perhaps that has changed.
- astrange 11y ago'lea' is a fast way to multiply by 3, for instance. It's also faster than two adds.
- e12e 11y agoI came across: http://www.realworldtech.com/haswell-cpu/4/ http://www.realworldtech.com/haswell-cpu/4/ And older, about amd64 in general (x86/32bit is quite different from 64bit): "lea -0x30(%edx,%esi,8),%esi Compute the address %edx+8*%esi-48, but don’t refer to the contents of memory. Instead, store the address itself into register %esi. This is the “load effective address” instruction: its binary coding is short, it doesn’t tie up the integer unit, and it doesn’t set the flags." http://people.freebsd.org/~lstewart/references/amd64.pdf http://people.freebsd.org/~lstewart/references/amd64.pdf [ed: in general the purpose of lea is to get the address of things in c/pascal arrays (pointer to array+offset) -- as I understand it. I don't know if it's used for other tricks by optimizing (c) compilers much -- but taking the address of an item in an array (say a character in a C string) sounds like it would be fairly common. If lea is fast(er) on amd64 using the dedicated operand would make sense.]
- fmela 11y agoYeah, despite it's name, lea is an arithmetic instruction; it doesn't reference memory (although it was designed with computing memory addresses in mind). You can do some neat arithmetic tricks with lea, because it computes register1 + register2<<shift + offset.