Re: profiles of gcc available

Przemek Klosowski (przemek@rrdjazz.nist.gov)
Wed, 13 Nov 1996 17:40:34 -0500

A simple example suffices - compile the following on your x86 box
and on an ALPHA, say with -O2:

void copy(char *s, char *d)
{
while (*d++ = *s++)
;
}

This code uses three instructions in the loop on my m68k machine -
including the jump (which is one more than necessary). I would be
surprised if the number of instructions on an ALPHA would be less
than ten. On the granddaddy of supercomputers, the Cray Y-MP, it
takes over 80 instructions.

That is an interesting exercise in watching compiler microoptimization.
On Intel, gcc 2.7.2 -O2, this is translated to
.L7:
movb (%ecx),%al
movb %al,(%edx)
incl %ecx
incl %edx
testb %al,%al
jne .L7

Since there is no autoincrement mode on Intel, the increments have to be there.
I don't know enough of Intel assembly language to tell if it can be improved upon.

BTW, gcc without optimization does a jump to a jump at the end of the loop; the
rest of the code is identical.

On Alpha/Linux, using the same version of gcc, the above code is
$34:
ldq_u $3,0($16)
ldq_u $2,0($17)
extbl $3,$16,$3
mskbl $2,$17,$2
insbl $3,$17,$1
addq $16,1,$16
bis $1,$2,$1
stq_u $1,0($17)
addq $17,1,$17
bne $3,$34

while on Alpha/Digital using DEC cc:

# 3 while (*d++ = *s++)
.set noat
lda $28, 1($16)
ldq_u $0, 0($16)
extqh $0, $28, $0
sra $0, 56, $0
.set at
.set noat
ldq_u $28, 0($17)
insbl $0, $17, $1
mskbl $28, $17, $28
bis $28, $1, $28
stq_u $28, 0($17)
.set at
addq $17, 1, $17
addq $16, 1, $16
beq $0, $33
.align 3
$32:
.loc 2 4
# 4 ;
.set noat
lda $28, 1($16)
ldq_u $0, 0($16)
extqh $0, $28, $0
sra $0, 56, $0
.set at
.set noat
ldq_u $28, 0($17)
insbl $0, $17, $2
mskbl $28, $17, $28
bis $28, $2, $28
stq_u $28, 0($17)
.set at
addq $17, 1, $17
addq $16, 1, $16
bne $0, $32
.loc 2 5
# 5 }
$33:

Funny, the DEC version doesn't strike me as faster, even if it fills
latencies/scheduling better (I haven't timed it, though).

p

--
To unsubscribe: send e-mail to axp-list-request@redhat.com with
'unsubscribe' as the subject.  Do not send it to axp-list@redhat.com



Feedback | Store | News | Support | Product Errata | About Us | Linux Info | Search | JumpWords
No Frames | Show Frames

Copyright © 1995-1997 Red Hat Software. Legal notices