auto increment in simple mac loop is not created.

Tal Agmon Tal.Agmon@ceva-dsp.com
Wed Jul 18 17:36:00 GMT 2007


Hi,

I'm compiling the following c code with -O2 on ia64-linux, xtensa-linux,
bfin targets, gcc-4.2.0:

int loop(int a[], int b[],int sum)
  {
    unsigned int i;
    for (i = 0; i < 100; i++)
      sum+=a[i]*b[i];
    return sum;
  }

I don't see any auto increment of the pointers inside the loop in any
one of them.
(You can see below the assembly code outputted by each one).

I'm writing new DSP port and naturally auto increment inside such a loop
is extremely important.
Am I missing something here?

Thanks,
Tal.

xtensa-linux output:

        .file   "loop_pointers.c"
        .global __mulsi3
        .text
        .literal_position
        .literal .LC2, __mulsi3@PLT
        .align  4
        .global loop
        .type   loop, @function
loop:
        .frame  sp, 32
        entry   sp, 32
        l32i.n  a11, a2, 0
        l32r    a5, .LC2
        l32i.n  a10, a3, 0
        mov.n   a6, a2
        callx8  a5
        add.n   a2, a4, a10
        movi.n  a7, 4
        movi    a4, 0x190
.L2:
        add.n   a8, a7, a3
        add.n   a9, a7, a6
        l32i.n  a10, a8, 0
        l32i.n  a11, a9, 0
        addi.n  a7, a7, 4
        callx8  a5
        add.n   a2, a2, a10
        bne     a7, a4, .L2
        retw.n
        .size   loop, .- loop
        .ident  "GCC: (GNU) 4.2.0"

Ia64-linux output:

	.file	"loop_pointers.c"
	.pred.safe_across_calls p1-p5,p16-p63
	.text
	.align 16
	.global loop#
	.proc loop#
loop:
	.prologue
	.mmb
	ld4 r15 = [r33]
	ld4 r14 = [r32]
	nop 0
	.mmi
	setf.sig f9 = r34
	addl r17 = 4, r0
	.save ar.lc, r2
	mov r2 = ar.lc
	.body
	;;
	.mmi
	setf.sig f7 = r15
	setf.sig f8 = r14
	mov ar.lc = 98
	;;
	.mmf
	nop 0
	nop 0
	xma.l f6 = f7, f8, f9
.L2:
	.mmi
	add r14 = r17, r33
	add r16 = r17, r32
	adds r17 = 4, r17
	;;
	.mmi
	ld4 r15 = [r14]
	ld4 r14 = [r16]
	nop 0
	;;
	.mmi
	setf.sig f7 = r15
	setf.sig f8 = r14
	nop 0
	;;
	.mfb
	nop 0
	xma.l f6 = f7, f8, f6
	br.cloop.sptk.few .L2
	;;
	.mib
	getf.sig r8 = f6
	mov ar.lc = r2
	br.ret.sptk.many b0
	.endp loop#
	.ident	"GCC: (GNU) 4.2.0"


bfin output:

.file "loop_pointers.c";
.text;
	.align 4
.global _loop;
.type _loop, STT_FUNC;
_loop:
	[--sp] = ( p5:3 );

	P3 = R0;
	P4 = R1;
	LINK 0;
	P0 = 4 (X);
	P5 = 99 (X);
	R1 = [P3];
	R0 = [P4];
	R0 *= R1;
	R2 = R2 + R0;
	LSETUP (L$L$2, L$L$8) LC1 = P5;
L$L$2:
	P2 = P0 + P4;
	P1 = P0 + P3;
	R0 = [P2];
	R1 = [P1];
	R0 *= R1;
	P0 += 4;
L$L$8:
	R2 = R2 + R0;
	UNLINK;
	R0 = R2;
	( p5:3 ) = [sp++];

	rts;
	.size	_loop, .-_loop
	.ident	"GCC: (GNU) 4.2.0"






More information about the Gcc mailing list