4 ms·
> These addressing modes are useful and easy to understand, and the address generation units do double-duty as low-latency, high-throughput add-and-shift units,
by nkurz 6y ago
> These addressing modes are useful and easy to understand, and the address generation units do double-duty as low-latency, high-throughput add-and-shift units, via the LEA instruction.
While I think you are right that LEA exists because of the memory addressing modes, at least on Intel (and I'm pretty sure AMD) it's been a long time since it's actually been executed on the address generation units. Instead, it's [mostly] treated as just another arithmetic instruction and executed on the same integer ALU's that execute all the other simple integer math. According to Agner (https://www.agner.org/optimize/instruction_tables.pdf https://www.agner.org/optimize/instruction_tables.pdf) it's been this way at least since the original Pentium.
Does anyone know what the last mainstream processor was that actually executed LEA on the AGU? And whether there any less mainstream processors that still do?
[mostly] I say mostly because there are a few odd addressing modes that have longer than usual latencies, and a because the 3 argument form also takes longer than the usual 1 cycle latency. It's still executed on a standard integer port, though, and not on the AGU.
- jeffbee 6y agoSure, but there's still something special/magic about LEA. For one the ports on which it dispatches are different from the ones available for ADD or SHL, even though is it effectively capable of SHL with register and immediate operands. And it's odd that 2- and 3-component address is 1 uop. Even though it's in the kitchen sink with all the other arithmetic, it's still a special case, rather than being decomposed into several adds, shifts, and moves.
- spc476 6y agoGenerally speaking, the LEA instruction will never modify the flags, while ADD and SHL will.