egcs-problem 1.0.2
H.J. Lu
hjl@lucon.org
Sun Apr 5 21:29:00 GMT 1998
> This is the "linux asm" problem that I haven't been able to look at
> for the last month or so due to personal and company commitments.
>
> Basically there's a couple problems:
>
> * The linux x86 asm for strstr is totally bogus.
Does the code below make sense?
>
> * GCC does not issue a warning/error when it encouters the bogus
> asm and instead generates incorrect code.
Agreed. I don't think it is too hard to issue an error.
Thanks.
--
H.J. Lu (hjl@gnu.org)
----
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),"m" (ct)
:"cx","dx","di","si");
return __res;
}
int count_substring_matches(char **haystacks, char **needles)
{
int hits=0, i, j;
for(i=0; haystacks[i]; i++) {
for(j=0; needles[j]; j++) {
if (strstr(haystacks[i], needles[j])) hits++;
}
}
return hits;
}
main ()
{
char * haystacks [] = {"foobar", 0};
char * needles [] = {"foo", 0};
if (count_substring_matches (haystacks, needles ) != 1)
abort ();
return 0;
}
More information about the Gcc
mailing list