Re:Reverse-engineering the conditional jump circuitry in the...
by rot13xor on Monday January 23, 2023 @06:57PM
(#34496931)
I always wondered why x86 has LEA when its functionality can be replicated by ADD. It has to do with LEA and ADD being able to run in parallel because LEA uses a separate ALU in the address calculation part of the chip, not the main ALU.
[ Parent
| on HN ]
Re:Reverse-engineering the conditional jump circuitry in the...
by shadowofneptune on Monday January 23, 2023 @07:31PM
(#34497286)
LEA only got more powerful in later models as the restraints on registers were removed and more addressing modes got added. Now it can do several additions and a multiplication in a single operation. Reusing that memory hardware/instruction format is a clever ISA decision.
Re:Reverse-engineering the conditional jump circuitry in the...
by Gordonjcp on Tuesday January 24, 2023 @03:54AM
(#34501225)
Wait, so if you were imaginative enough with how you use registers to calculate addresses you could abuse LEA as a DSP MAC (multiply/accumulate) instruction?
Re:Reverse-engineering the conditional jump circuitry in the...
by moefh on Tuesday January 24, 2023 @04:15AM
(#34501376)
Compilers do it all the time, for example GCC compiles "x*4 + y" to a single LEA instruction: https://godbolt.org/z/TvdW5sK4b
Re:Reverse-engineering the conditional jump circuitry in the...
by Gordonjcp on Tuesday January 24, 2023 @09:03AM
(#34503635)
Aha, playing with it, it looks like the multiply is just a shift because if you try to do anything other than powers of two it has to break it down into more instructions.
Still clever, though. I guess it's to make it easier and quicker to index over words or multiples of words?
Re:Reverse-engineering the conditional jump circuitry in the...
by rep_lodsb on Tuesday January 24, 2023 @09:40AM
(#34504111)
* * *
Re:Reverse-engineering the conditional jump circuitry in the...
by peterfirefly on Tuesday January 24, 2023 @06:52AM
(#34502453)
The system might choose to use relocations for LEA and not for ADD -- this is of course not relevant for stack relative addressing and struct member addressing on the heap. I think I ran into this when coding assembler for DOS in the late 80's.
LEA also gets the "register + offset" thing done in a single instruction instead of two (MOV + ADD). It's also really easy for both assembler programmers and (dumb) compilers.
The "run in parallel" stuff is you looking at modern(ish) CPUs and thinking the original 8086 looked anything like that inside.