This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: a C routine to optimize GCC for


Vincent Diepeveen <diep@xs4all.nl> writes:

> Is it so hard to replace the above by PRO instructions?

Even the new x86 backend in gcc 2.96 snapshots do not generate CMOV
instructions for your code :(

However, I found that if the function is rewritten like this:

	int board[64],sweep[20],Pindex[64],snelbord[64];

	int tryalles(void)
	{
	   int ut,ua,summation=0;

	   for( ua = 0 ; ua < 16 ; ua++ ) {
	     int b = board[ua];
	     ut = 0;
	     if( !sweep[snelbord[ua]] )
	       ut = b;
	     summation += Pindex[ut];
	   }
	   return(summation);
	}

the compiler will generate a CMOV instruction. (I also removed the
pointer arithmetic, but that is not really necessary.) I don't know
why this rewrite helps. gcc 2.95 generates the following assembler
code:

	.file	"test61.c"
	.version	"01.01"
gcc2_compiled.:
.text
	.align 4
.globl tryalles
	.type	 tryalles,@function
tryalles:
	pushl %ebp
	pushl %edi
	pushl %esi
	pushl %ebx
	xorl %esi,%esi
	movl $sweep,%ebp
	movl $Pindex,%edi
	xorl %ecx,%ecx
	movl $15,%ebx
	.p2align 4,,7
.L6:
	movl snelbord(%ecx),%edx
	xorl %eax,%eax
	sall $2,%edx
	cmpl $0,(%edx,%ebp)
	cmove board(%ecx),%eax
	addl (%edi,%eax,4),%esi
	addl $4,%ecx
	decl %ebx
	jns .L6
	movl %esi,%eax
	popl %ebx
	popl %esi
	popl %edi
	popl %ebp
	ret
.Lfe1:
	.size	 tryalles,.Lfe1-tryalles
	.comm	board,256,32
	.comm	sweep,80,32
	.comm	Pindex,256,32
	.comm	snelbord,256,32
	.ident	"GCC: (GNU) 2.95.2 19990906 (prerelease)"


>        sall $2,%eax           <== where do we need this shift instruction for?
>        cmpl $0,(%eax,%edi)

The only way I could find to get rid of the sall instruction was to
declare the sweep or snelbord array as a char[]. Does the sall
instruction really make the code slower?

-- 
Peter Österlund          Email:     peter.osterlund@mailbox.swipnet.se
Sköndalsvägen 35                    f90-pos@nada.kth.se
S-128 66 Sköndal         Home page: http://home1.swipnet.se/~w-15919
Sweden                   Phone:     +46 8 942647

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]