Hi,

What is the real cost of a conditionnal jump ?

ex:

mov ecx, 5

@@:
; instructions.
dec ecx
jnz @B

Thanks

PS: i try to understand the optimization with asm, and so i try to understand how we can count cycles (ex: with pipeline U and V, ...). But in fact, we have the cost for mov, etc. but what is the cost of a conditionnal jump ?

Where can i find documents which explain optimizations (ex: pipeline U and V, ...)
Posted on 2003-01-29 06:44:05 by DarkEmpire
DarkEmpire,

The problem with conditional jumps is that they are hard to predict internally in the processor as they can either jump or just fall through.

What you try and do in your code if its possible is to set the condition so that it falls through in most instances and try and design code that minimises the number of conditional jumps so you get less problems.

When a jump is taken, the pipelines must wait until the location can be scheduled into the correct sequence in the pipelines so while a fall through does not effect the scheduling, taking the jump does.

Agner Fog's optimisation is very good in this area and so is the design info from Intel which you can download from their site.

Regards,

hutch@movsd.com
Posted on 2003-01-29 17:47:16 by hutch--
Modern CPU always predict jumps backward to be taken and jumps forward not to be taken
On a missprediction you get a delay of up to 20 clocks ... so a constantly misspredicted jump can make your code 10x slower on average.

However CPU will try to adapt to a patern in jumps : so if the forward jump is always taken after a few loops the CPU will "understand" that and start predicting it to be taken... but if the situation changes again (because of data/algorithm) then you are in trouble....

IMHO this stuff is stupid... but such is life... we can not make our own home made CPU's... yet :)
Posted on 2003-01-30 06:34:39 by BogdanOntanu