Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Optimization

AtexAtex Posts: 268Member
Looking purely at speed ( clock ticks ) which code executes faster ?[code][color=Blue]mov eax,gs:[edi+4]

-or-

add edi,4
mov eax,gs:[edi][/color][/code]

Comments

  • anthrax11anthrax11 Posts: 511Member
    I'd say the second one is slower, because the addition is a read-modify-write operation, so edi will be tied up for several uops. This is bad, since the second instruction depends on edi. Also, the first one takes less space, so it fits into cache better.

    However, the second code may improve performance if you insert some other instruction between add and mov. If that instruction doesn't use edi, then it could be fed into another pipeline and executed in parallel.
Sign In or Register to comment.