bug report
Holger MaaÃÂ
Holger.Maass@t-online.de
Sat Jan 15 15:51:00 GMT 2000
Hi egcs team,
I have a problem with egcs, version pgcc-2.91.66 19990314 (egcs-1.1.2
release).
The following code (in foo.c)
#define __fastcall __attribute__ ((regparm(3)))
unsigned reverse_bits(unsigned value, int len) __fastcall;
:
:
:
unsigned reverse_bits(unsigned code, int len)
{
unsigned res = 0;
asm ("decl %1
rev1:
rcrl $1,%2
rcll $1,%0
loop rev1" : "=r" (res) : "c" (len), "d" (code));
return res;
}
compiled on a pentium as
gcc -fomit-frame-pointer -O2 -S foo.c
gives me that (taken from foo.s):
.align 16
.globl reverse_bits
.type reverse_bits,@function
reverse_bits:
movl %edx,%ecx
movl %eax,%edx
#APP
decl %ecx
rev1:
rcrl $1,%edx
rcll $1,%eax
loop rev1
#NO_APP
ret
As you can see, the compiler ignores the `unsigned res = 0' statement.
That's not a good idea because the code above works properly only with a
`len' argument of 32. My work around is inserting an additional
statement `xorl %0,%0' just before the `rev1:' label. That's not nasty
so far, but I don't know, whether its my mistake or is there a mistake
in the compilers optimization routine.
MfG Holger (Holger.Maass@t-online.de)
P.S.: MfG means "Mit freundlichen Gruessen" and based on a german song
which caricatured the nuisance to abbreviate all and anything :-).
More information about the Gcc-bugs
mailing list