This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
bug report
- To: egcs-bugs at egcs dot cygnus dot com
- Subject: bug report
- From: Holger dot Maass at t-online dot de (Holger Maaß)
- Date: Sun, 16 Jan 2000 00:51:18 +0100
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 :-).