The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: SittingDuck on November 02, 2005, 05:52:50 PM

Title: Jump speed
Post by: SittingDuck on November 02, 2005, 05:52:50 PM
Why do jumps take so long? Is it to do with the prefetch cache?
Title: Re: Jump speed
Post by: Tedd on November 03, 2005, 11:44:26 AM
Yes.
Straight jumps (jmp) aren't so bad, it's the conditionals (jz, jnz, jc, jnc, .....) that cause the problems since the processor doesn't know whether the jump will be taken until it gets to it, and by then it's a bit late for prediction.
A simple version of the way it works is that the first time you get to a conditional jump it will be predicated as being taken if it jumps backwards, and not taken if forwards (this is because loops usually jump backwards, and exists from loops jump forwards.) Then, jumps are remembered (up to a limit) and the next time they're encountered are predicted as going the same way as the previous time. There are extra things for predicting patterns of jumps, but let's not get into that :wink