Re: egcs 1.0.1 miscompiles Linux 2.0.33

Linus Torvalds (torvalds@transmeta.com)
1 Mar 1998 21:40:32 GMT


In article <3643.888784179@hurl.cygnus.com>,
Jeffrey A Law <law@cygnus.com> wrote:
>
>extern inline char * strstr(const char * cs,const char * ct)
>{
>register char * __res;
>__asm__ __volatile__(
> "cld\n\t" "movl %4,%%edi\n\t"
> "repne\n\t"
> "scasb\n\t"
> "notl %%ecx\n\t"
> "decl %%ecx\n\t"
> "movl %%ecx,%%edx\n"
> "1:\tmovl %4,%%edi\n\t"
> "movl %%esi,%%eax\n\t"
> "movl %%edx,%%ecx\n\t"
> "repe\n\t"
> "cmpsb\n\t"
> "je 2f\n\t"
> "xchgl %%eax,%%esi\n\t"
> "incl %%esi\n\t"
> "cmpb $0,-1(%%eax)\n\t"
> "jne 1b\n\t"
> "xorl %%eax,%%eax\n\t"
> "2:"
> :"=a" (__res):"0" (0),"c" (0xffffffff),"S" (cs),"g" (ct)
> :"cx","dx","di","si");
>return __res;
>}
>
>This asm has some serious problems. Any attempt to fix the compiler
>to be more strict with how it uses registers which are clobbered by
>the asm is going to lead to problems.
>
>Note that cx and si are mentioned in both the input and clobber
>list. This is wrong.

It has always worked before, and it is also the natural way to do this.
How would you specify that you want something in an input register but
that gcc must not use it for anything else?

Before you tell me to use the construct

"=c" (dummy).. :"1" (0xffffffff)

I have two arguments against that:

- it requires a dummy variable, which is just silly to export to the C
level, and can be rather painful in macro expansion.

- it is "more wrong" than the current code with clobbers: it would
still allow gcc to use %ecx as an input to something else _too_ in
case the value 0xffffffff shows up in some other expression (let's
say that "ct" had that value, and gcc would decide that it can use
%ecx for "ct" because ct has a constraint of "g" that would allow
it).

In short, not only does the "use this register for input but consider it
clobbered otherwise" semantics make sense, there is no other way to
specify that than to use the above kind of construct.

I agree that it may be harder for the compiler to get right, but that
doesn't change the fact that it's a valid use and that we have a valid
need for it.

So ignore the actual x86 code, tell me how you _think_ it should work.
I claim that the current gcc asm syntax doesn't give me much choice -
even though I agree with you that it looks strange to have a clobber
that is also an input.

Linus

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu