This is the mail archive of the mailing list for the glibc project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] i386: Fix GCC running out of registers for bits/string.h

On Monday 13 June 2005 18:07, Maciej W. Rozycki wrote:
> On Mon, 13 Jun 2005, Denis Vlasenko wrote:
> > > > //gcc4 compiles this just fine with:
> > > > //gcc -O2 -fomit-frame-pointer
> > > 
> > >  I'm not sure why you chose the non-PIC variation, which works for me as 
> > > is...  Anyway, if I substitute your code with the PIC variant, it still 
> > > works -- probably the code involved is too trivial.

Please see updated testcase. Unfortunately I can't make it fail,
but one peculiarity is already noted. See comments.

> > My code is a bit different (it explicitly clobbers ebx - see asm outputs),
> > maybe that avoids triggering GCC misbehavior.
>  The problem is %ebx is fixed for PIC, so this is a no-no, I'm afraid.  

Huh I didn't khow that. Fixed.

> > >  There have been two similar bugs filed against GCC already (#15482 and 
> > > #21291), but I've decided it's different enough to file it separately -- 
> > > this is now bug #22045.

Note is added.

> Well, as long as there is a tab between a mnemonic and its operand, it's 
> fine with me; I prefer spaces after commas as well to make operands 
> clearer.  This is the way I write asms myself.  Trailing control 
> characters don't bother me.

How do you like this style?

//Use gcc -O2 -fomit-frame-pointer [-fPIC] -c/-S

#include <alloca.h>

#define NL "\n"

inline int
strcspn (__const char *__s, __const char *__reject)
	unsigned long int __eax, __ecx, __edi;
	unsigned long int __reg;
	char *__esi;

	__asm__ __volatile__(NL
	"	cld" NL
	"	movl	%5, %%edi" NL
	"	repne; scasb" NL
	"	notl	%%ecx" NL
	"	leal	-1(%%ecx), %2" NL
	"1:" NL
	"	lodsb" NL
	"	testb	%%al, %%al" NL
	"	je	2f" NL
	"	movl	%5, %%edi" NL
	"	movl	%2, %%ecx" NL
	"	repne; scasb" NL
	"	jne	1b" NL
	"2:" NL
	: "=&S" (__esi), "=&a" (__eax), "=&r" (__reg), "=&c" (__ecx), "=&D" (__edi)
	: "g" (__reject), "0" (__s), "1" (0), "2" (0xffffffff)
		//, "m" ( *(struct { char __x[0xfffffff]; } *)__s)
	: "cc");

	return (__esi - 1) - __s;

int t(int n, char* s) {
	char *p = alloca(n);
	return strcspn("abcd",s);

/* gcc version 3.4.3 code:
        movl    REJECT, %edi
        repne; scasb
        notl    %ecx
        leal    -1(%ecx), %REG
        testb   %al, %al
        je      2f
        movl    REJECT, %edi
        movl    %REG, %ecx
        repne; scasb
        jne     1b

with "r" (__reject) constraint:
    no -fPIC: REJECT = edx
    -fPIC: does not compile (not enough free regs)
with "g" (__reject):
    no -fPIC: REJECT = stack slot! (instead of using a reg like "r" case)
    -fPIC: REJECT = stack slot
REG is ebx or ebp, depending on PICness.

gcc 4.0.0: same

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