optimization - gcc optimisation with LEA -
this question has answer here:
- what's purpose of lea instruction? 14 answers
i'm fiddling gcc's optimisation options , found these lines:
int bla(int moo) { return moo * 384; }
are translated these:
0: 8d 04 7f lea (%rdi,%rdi,2),%eax 3: c1 e0 07 shl $0x7,%eax 6: c3 retq
i understand shifting represents multiplication 2^7. , first line must multiplication 3.
so utterly perplexed "lea" line. isn't lea supposed load address?
lea (%ebx, %esi, 2), %edi
nothing more computing ebx + esi*2
, storing result in edi
.
even if lea
designed compute , store effective address, can , used optimization trick perform calculation on not memory address.
lea (%rdi,%rdi,2),%eax shl $0x7,%eax
is equivalent :
eax = rdi + rdi*2; eax = eax * 128;
and since moo
in rdi
, stores moo*384
in eax
Comments
Post a Comment