From: Roland McGrath Date: Wed, 25 Nov 1992 19:02:23 +0000 (+0000) Subject: Formerly alpha/memchr.c.~2~ X-Git-Tag: glibc-2.16-ports-before-merge~4317 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d207263b8ca8588753bc8e0853342d9772692e70;p=thirdparty%2Fglibc.git Formerly alpha/memchr.c.~2~ --- diff --git a/sysdeps/alpha/memchr.c b/sysdeps/alpha/memchr.c index 01a8c3eeac5..3c9477ed4dd 100644 --- a/sysdeps/alpha/memchr.c +++ b/sysdeps/alpha/memchr.c @@ -44,22 +44,29 @@ memchr (const void *s, int c, size_t n) for (;;) { - int mask; - asm ("cmpbge %1, %2, %0" - : "=r" (mask) : "r" (charmask), "r" (*longword_ptr++)); - if (mask) + const unsigned long int longword = *longword_ptr++; + int ge, le; + + /* 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? */ const char *cp = (const char *) (longword_ptr - 1); if (cp[0] == c) - return cp - str; + return cp; if (cp[1] == c) - return cp - str + 1; + return &cp[1]; if (cp[2] == c) - return cp - str + 2; - return cp - str + 3; + return &cp[2]; + return &cp[3]; } } }