The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: James Ladd on September 11, 2005, 02:25:57 AM

Title: OPTIMISATION and stalls ?
Post by: James Ladd on September 11, 2005, 02:25:57 AM
I read elsewhere that code like this

mov esi, addr
mov eax, [esi + struct.field]


Caused a stall of some sort because esi was being set and then immediately read.
If this is true, then how can you avoid it ?

Can you avoid it in all sitations ?

Do you have an example of avoiding it ?

rgs, striker.
Title: Re: OPTIMISATION and stalls ?
Post by: hutch-- on September 11, 2005, 04:21:09 AM
James,

It looks like a normal read after write stall and about all you can do is try and put some other instruction between the two. From memory if you have a 4 instruction spacing you fully avoid the proglem but note that its only a problem with high speed loop code, apar from tha it just does not matter.
Title: Re: OPTIMISATION and stalls ?
Post by: AeroASM on September 11, 2005, 12:37:03 PM
If you think of the processor as executing one instruction, completing it and then moving on to the next, there is no stall. The stall is because modern processors have a pipeline: they start executing one instruction before the previous one has finished. The stall is very small, only a few clock ticks, so it is only worth avoiding in code which is looped heavily.