Formerly alpha/memchr.c.~2~

This commit is contained in:
Roland McGrath 1992-11-25 19:02:23 +00:00
parent fd725b9471
commit d207263b8c
1 changed files with 15 additions and 8 deletions

View File

@ -44,22 +44,29 @@ memchr (const void *s, int c, size_t n)
for (;;) for (;;)
{ {
int mask; const unsigned long int longword = *longword_ptr++;
asm ("cmpbge %1, %2, %0" int ge, le;
: "=r" (mask) : "r" (charmask), "r" (*longword_ptr++));
if (mask) /* Set bits in GE if bytes in CHARMASK are >= bytes in LONGWORD. */
asm ("cmpbge %1, %2, %0" : "=r" (ge) : "r" (charmask), "r" (longword));
/* Set bits in LE if bytes in CHARMASK are <= bytes in LONGWORD. */
asm ("cmpbge %2, %1, %0" : "=r" (le) : "r" (charmask), "r" (longword));
/* Bytes that are both <= and >= are == to C. */
if (ge & le)
{ {
/* Which of the bytes was the C? */ /* Which of the bytes was the C? */
const char *cp = (const char *) (longword_ptr - 1); const char *cp = (const char *) (longword_ptr - 1);
if (cp[0] == c) if (cp[0] == c)
return cp - str; return cp;
if (cp[1] == c) if (cp[1] == c)
return cp - str + 1; return &cp[1];
if (cp[2] == c) if (cp[2] == c)
return cp - str + 2; return &cp[2];
return cp - str + 3; return &cp[3];
} }
} }
} }