Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Seeking an array index

Author: Rémi Coulom

Date: 13:49:35 01/05/05

Go up one level in this thread


On January 04, 2005 at 17:43:08, Christophe Drieu wrote:

>On January 04, 2005 at 12:49:03, Rémi Coulom wrote:
>
>>
>>I would write
>>for (i = N; --i >= 0;)
>>In my experience, it is usually faster than
>>for (i = 0; i < N; i++)
>>if you do not care about the order of the loop. But that may depend on the
>>compiler/processor. Try both and measure time.
>>
>>Rémi
>
>
>I Rémi, i just try this
>
>int main()
>{
>        int i;
>	int a,b;
>
>	a=0;
>	b=1;
>	for (i=0;i<100;i++) {
>		a=a^b;
>		b=a^b;
>		a=b^a;
>	}
>	a=0;
>	b=1;
>	for (i=100;--i>=0;) {
>		a=a^b;
>		b=a^b;
>		a=b^a;
>	}
>
>        return 0;
>}
>
>
>This is what Microsoft compiler give me
>
>; Line 8
>	xor	eax, eax
>; Line 9
>	mov	ecx, 1
>	mov	edx, 100				; 00000064H
>	npad	4
>$L865:
>; Line 11
>	xor	eax, ecx
>; Line 12
>	xor	ecx, eax
>; Line 13
>	xor	eax, ecx
>	dec	edx
>	jne	SHORT $L865
>; Line 15
>	xor	eax, eax
>; Line 16
>	mov	ecx, 1
>	mov	edx, 100				; 00000064H
>$L869:
>; Line 18
>	xor	eax, ecx
>; Line 19
>	xor	ecx, eax
>; Line 20
>	xor	eax, ecx
>	dec	edx
>	jne	SHORT $L869
>; Line 23
>	xor	eax, eax
>; Line 24
>	ret	0
>
>I don't see any difference.
>
>Regards

Is the compiler clever enough to do it as well when the loop variable is used as
an array index? I wonder what code it would generate for the routine that finds
the maximum.

Rémi



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.