public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* wrong constraints "=g" at include/asm-i386/string.h, line 186?
@ 2007-07-26 11:58 Jian-Xin Lai
  2007-07-26 15:21 ` H. Peter Anvin
  0 siblings, 1 reply; 4+ messages in thread
From: Jian-Xin Lai @ 2007-07-26 11:58 UTC (permalink / raw)
  To: linux-kernel

Hi,

The kernel version is 2.6.20.7. In include/asm-i386/string.h, line 169~185:
static inline char * strrchr(const char * s, int c)
{
int d0, d1;
register char * __res;
__asm__ __volatile__(
        "movb %%al,%%ah\n"
        "1:\tlodsb\n\t"
        "cmpb %%ah,%%al\n\t"
        "jne 2f\n\t"
        "leal -1(%%esi),%0\n"                                    (*)
        "2:\ttestb %%al,%%al\n\t"
        "jne 1b"
        :"=g" (__res), "=&S" (d0), "=&a" (d1)               (**)
        :"0" (0),"1" (s),"2" (c)
        :"memory");
return __res;
}

The 'lea' instruction needs a register here (*), but "g" (**) means
any registers, memory or immediate integer. Is it correct? If the
compiler do not place the __res into a register, the compilation will
fail. Should it be "r"?
Thank you very much.

-- 
Regards,
Lai Jian-Xin

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: wrong constraints "=g" at include/asm-i386/string.h, line 186?
  2007-07-26 11:58 wrong constraints "=g" at include/asm-i386/string.h, line 186? Jian-Xin Lai
@ 2007-07-26 15:21 ` H. Peter Anvin
  2007-07-27  2:45   ` Jian-Xin Lai
  0 siblings, 1 reply; 4+ messages in thread
From: H. Peter Anvin @ 2007-07-26 15:21 UTC (permalink / raw)
  To: Jian-Xin Lai; +Cc: linux-kernel

Jian-Xin Lai wrote:
> Hi,
> 
> The kernel version is 2.6.20.7. In include/asm-i386/string.h, line 169~185:
> static inline char * strrchr(const char * s, int c)
> {
> int d0, d1;
> register char * __res;
> __asm__ __volatile__(
>        "movb %%al,%%ah\n"
>        "1:\tlodsb\n\t"
>        "cmpb %%ah,%%al\n\t"
>        "jne 2f\n\t"
>        "leal -1(%%esi),%0\n"                                    (*)
>        "2:\ttestb %%al,%%al\n\t"
>        "jne 1b"
>        :"=g" (__res), "=&S" (d0), "=&a" (d1)               (**)
>        :"0" (0),"1" (s),"2" (c)
>        :"memory");
> return __res;
> }
> 
> The 'lea' instruction needs a register here (*), but "g" (**) means
> any registers, memory or immediate integer. Is it correct? If the
> compiler do not place the __res into a register, the compilation will
> fail. Should it be "r"?
> Thank you very much.
> 

Yes, it should be "r", and it looks like the author hacked around the
fact they had the wrong constraints by using the "register" keyword on
the variable declaration.

	-hpa

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: wrong constraints "=g" at include/asm-i386/string.h, line 186?
  2007-07-26 15:21 ` H. Peter Anvin
@ 2007-07-27  2:45   ` Jian-Xin Lai
  2007-07-27  4:32     ` H. Peter Anvin
  0 siblings, 1 reply; 4+ messages in thread
From: Jian-Xin Lai @ 2007-07-27  2:45 UTC (permalink / raw)
  To: H. Peter Anvin; +Cc: linux-kernel

But as we know, the kerword 'register' is only a suggestion. The
language specification does not force to put the 'register' variable
into a register.
Putting the variable onto stack does not violate anything, but the
assembler will fail.
I think the hack does not really work. THX.

2007/7/26, H. Peter Anvin <hpa@zytor.com>:
> Jian-Xin Lai wrote:
> > Hi,
> >
> > The kernel version is 2.6.20.7. In include/asm-i386/string.h, line 169~185:
> > static inline char * strrchr(const char * s, int c)
> > {
> > int d0, d1;
> > register char * __res;
> > __asm__ __volatile__(
> >        "movb %%al,%%ah\n"
> >        "1:\tlodsb\n\t"
> >        "cmpb %%ah,%%al\n\t"
> >        "jne 2f\n\t"
> >        "leal -1(%%esi),%0\n"                                    (*)
> >        "2:\ttestb %%al,%%al\n\t"
> >        "jne 1b"
> >        :"=g" (__res), "=&S" (d0), "=&a" (d1)               (**)
> >        :"0" (0),"1" (s),"2" (c)
> >        :"memory");
> > return __res;
> > }
> >
> > The 'lea' instruction needs a register here (*), but "g" (**) means
> > any registers, memory or immediate integer. Is it correct? If the
> > compiler do not place the __res into a register, the compilation will
> > fail. Should it be "r"?
> > Thank you very much.
> >
>
> Yes, it should be "r", and it looks like the author hacked around the
> fact they had the wrong constraints by using the "register" keyword on
> the variable declaration.
>
>        -hpa
>


-- 
Regards,
Lai Jian-Xin

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: wrong constraints "=g" at include/asm-i386/string.h, line 186?
  2007-07-27  2:45   ` Jian-Xin Lai
@ 2007-07-27  4:32     ` H. Peter Anvin
  0 siblings, 0 replies; 4+ messages in thread
From: H. Peter Anvin @ 2007-07-27  4:32 UTC (permalink / raw)
  To: Jian-Xin Lai; +Cc: linux-kernel

Jian-Xin Lai wrote:
> But as we know, the kerword 'register' is only a suggestion. The
> language specification does not force to put the 'register' variable
> into a register.
> Putting the variable onto stack does not violate anything, but the
> assembler will fail.
> I think the hack does not really work. THX.

Well, gcc is a bit more strict than that, but it's ugly and should be fixed.

	-hpa

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-07-27  4:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-26 11:58 wrong constraints "=g" at include/asm-i386/string.h, line 186? Jian-Xin Lai
2007-07-26 15:21 ` H. Peter Anvin
2007-07-27  2:45   ` Jian-Xin Lai
2007-07-27  4:32     ` H. Peter Anvin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox