PS: I've readded LKML to CC, since I think that this is a problem with the
ASM template
On Mon, 27 Jun 2005 20:59:20 +0200
Andreas Kies <[email protected]> wrote:
> Them it works, but that's not a solution at all. "volatile" destroys more
> or less all optimizations.
Yes... I know, it was just to see what was the problem.
The problem is that GCC is caching in registers the value of "ptr[0]" and/or
"ptr[1]" and/or "ptr[2]".
A little better workaround would be to add "memory" to clobbered registers
in the asm template:
static inline int strcmp(const char * cs,const char * ct)
{
int d0, d1;
register int __res;
__asm__ __volatile__(
"1:\tlodsb\n\t"
"scasb\n\t"
"jne 2f\n\t"
"testb %%al,%%al\n\t"
"jne 1b\n\t"
"xorl %%eax,%%eax\n\t"
"jmp 3f\n"
"2:\tsbbl %%eax,%%eax\n\t"
"orb $1,%%al\n"
"3:"
:"=a" (__res), "=&S" (d0), "=&D" (d1)
:"1" (cs),"2" (ct)
: "memory"); // <--- workaround
return __res;
}
In this way GCC puts everything is cached in register back to memory when
you call strcmp()... but you can argue that this isn't optimal.
I don't know if there is a better way... basically you need to tell GCC to
NOT cache these values.
I think that nobody hits this bug because the typical usage is different...
something like this:
...
char *str = "Hello!"; // or even char str[] = "Hello!";
...
strcmp (str, other_str);
...
In this way "Hello!" _IS_ allocated in memory and "str" points to it.... GCC
optimizations can't hurt here (I hope ;).
CONCLUSION: I think that it should be fixed... but adding "memory" doesn't
seems The Right Thing to do.
--
Paolo Ornati
Linux 2.6.12.1 on x86_64
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[Index of Archives]
[Kernel Newbies]
[Netfilter]
[Bugtraq]
[Photo]
[Stuff]
[Gimp]
[Yosemite News]
[MIPS Linux]
[ARM Linux]
[Linux Security]
[Linux RAID]
[Video 4 Linux]
[Linux for the blind]
[Linux Resources]