2 ms·
Definitely an advantage because AFAIK that doesn't go through the ALU but instead uses the dedicated address calculation unit, which is going to be faster than
by userbinator 8y ago
Definitely an advantage because AFAIK that doesn't go through the ALU but instead uses the dedicated address calculation unit, which is going to be faster than a multiply instruction.
A related lea trick is combining a shift, add, add (or subtract) immediate, and mov into a single instruction that doesn't modify flags, i.e.
lea eax, [1234+ebx+ecx*4]
performs the equivalent of:
eax = ebx + ecx*4 + 1234
- BeeOnRope 8y agoNot anymore, at least on modern Intel - lea instructions go through the ALU like other ALU instructions. It's still an advantage over mul in this case, because it is a so-called "two component lea" which only has two components (base reg and index reg) so it takes 1 cycle latency and can execute at a throughput of 2 per cycle, versus 3 cycles latency and 1 per cycle for mul.
- CalChris 8y agoThat is a complex rather than simple LEA instruction. There's a difference for Haswell and above. Being complex (3 operands), it takes 3 cycles rather than 1 cycle for fast LEAs (1 or 2 operands). It is also restricted to only the slow path port, port 1, instead of using ports 1 or 5 for fast path LEAs. ADD has 4 ports. So Intel says in Section 3.5.1.2 of the Intel® 64 and IA-32 Architectures Optimization Reference Manual: Assembly/Compiler Coding Rule 33. (ML impact, L generality) If an LEA instruction using the scaled index is on the critical path, a sequence with ADDs may be better. If code density and bandwidth out of the trace cache are the critical factor, then use the LEA instruction.