c++ - Why would a compiler generate this assembly? -


while stepping through qt code came across following. function qmainwindowlayout::invalidate() has following implementation:

void qmainwindowlayout::invalidate() { qlayout::invalidate() minsize = szhint = qsize(); } 

it compiled this:

<invalidate()>        push   %rbx <invalidate()+1>      mov    %rdi,%rbx <invalidate()+4>      callq  0x7ffff4fd9090 <qlayout::invalidate()> <invalidate()+9>      movl   $0xffffffff,0x564(%rbx) <invalidate()+19>     movl   $0xffffffff,0x568(%rbx) <invalidate()+29>     mov    0x564(%rbx),%rax <invalidate()+36>     mov    %rax,0x56c(%rbx) <invalidate()+43>     pop    %rbx <invalidate()+44>     retq 

the assembly invalidate+9 invalidate+36 seems stupid. first code writes -1 %rbx+0x564 , %rbx+0x568, loads -1 %rbx+0x564 register write out %rbx+0x56c. seems compiler should able optimize move immediate.

so stupid code (and if so, why wouldn't compiler optimize it?) or somehow clever , faster using move immediate?

(note: code normal release library build shipped ubuntu, presumably compiled gcc in optimize mode. minsize , szhint variables normal variables of type qsize.)

not sure you're correct when you're saying it's stupid. think compiler might trying optimize code size here. there no 64-bit immediate memory mov instruction. compiler has generate 2 mov instructions did above. each of them 10 bytes, 2 moves generated 14 bytes. it's been written there no memory latency not think you'll take performance hit here.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -