Re: while ();



På 30 Jan 2006 13:57:31 -0800, skrev <robertwessel2@xxxxxxxxx>:

and it certainly wount matter
at all then, because 3 iterations will be closer to nothing.


Obviously the notion that a loop with few iterations might be inside a
big loop has escaped you.

?? :)

If you have a million iterations around a
small loop of two or three iterations the performance of the small loop
will most certainly matter, and with that few iterations branch
(mis)prediction will be a significant issue.

:) Wrong! Following is code to show you wrong.

main:

rdtsc | push eax edx

mov ecx 1_000_000
..while ecx > 0
    mov ebx 3
    While ebx > 0
        dec ebx
    End_While
    dec ecx
..End_While

rdtsc | pop ecx ebx

sub eax ebx
sbb edx ecx
int 3

******************************************************
result (varies in the 5th digit from right)
0112_A91D
******************************************************


This is an inner loop doing 3 times as much

rdtsc | push eax edx

mov ecx 1_000_000
..while ecx > 0
    mov ebx 3
    While ebx > 0
        dec ebx
        dec esi
        dec edi
    End_While
    dec ecx
..End_While

rdtsc | pop ecx ebx

sub eax ebx
sbb edx ecx
int 3
call 'KERNEL32.ExitProcess' 0

******************************************************
result (also varies in the 5th digit from right)
0112_DC16
******************************************************

What you claim is irrelevant from a optimization perspective.

.



Relevant Pages