~linaro-toolchain-dev/cortex-strings/trunk

« back to all changes in this revision

Viewing changes to reference/newlib-xscale/strchr.c

  • Committer: Michael Hope
  • Date: 2011-08-31 23:54:55 UTC
  • Revision ID: michael.hope@linaro.org-20110831235455-1knk9yxvfcoxlm3a
Added the XScale specific routines from Newlib 1.19.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <string.h>
 
2
#include "xscale.h"
 
3
#undef strchr
 
4
 
 
5
char *
 
6
strchr (const char *s, int c)
 
7
{
 
8
  unsigned int c2;
 
9
  asm (PRELOADSTR ("%0") : : "r" (s));
 
10
 
 
11
  c &= 0xff;
 
12
 
 
13
#ifndef __OPTIMIZE_SIZE__
 
14
  /* Skip unaligned part.  */
 
15
  if ((long)s & 3)
 
16
    {
 
17
      s--;
 
18
      do
 
19
        {
 
20
          int c2 = *++s;
 
21
          if (c2 == c)
 
22
            return (char *)s;
 
23
          if (c2 == '\0')
 
24
            return 0;
 
25
        }
 
26
      while (((long)s & 3) != 0);
 
27
    }
 
28
 
 
29
  c2 = c + (c << 8);
 
30
  c2 += c2 << 16;
 
31
 
 
32
  /* Load two constants:
 
33
     R6 = 0xfefefeff [ == ~(0x80808080 << 1) ]
 
34
     R5 = 0x80808080  */
 
35
 
 
36
  asm (PRELOADSTR ("%0") "\n\
 
37
        mov     r5, #0x80\n\
 
38
        add     r5, r5, #0x8000\n\
 
39
        add     r5, r5, r5, lsl #16\n\
 
40
        mvn     r6, r5, lsl #1\n\
 
41
\n\
 
42
        sub     %0, %0, #4\n\
 
43
0:\n\
 
44
        ldr     r1, [%0, #4]!\n\
 
45
"       PRELOADSTR ("%0") "\n\
 
46
        add     r3, r1, r6\n\
 
47
        bic     r3, r3, r1\n\
 
48
        ands    r2, r3, r5\n\
 
49
        bne     1f\n\
 
50
        eor     r2, r1, %1\n\
 
51
        add     r3, r2, r6\n\
 
52
        bic     r3, r3, r2\n\
 
53
        ands    r1, r3, r5\n\
 
54
        beq     0b\n\
 
55
1:"
 
56
       : "=&r" (s)
 
57
       : "r" (c2), "0" (s)
 
58
       : "r1", "r2", "r3", "r5", "r6", "cc");
 
59
#endif
 
60
 
 
61
  while (*s && *s != c)
 
62
    s++;
 
63
  if (*s == c)
 
64
    return (char *)s;
 
65
  return NULL;
 
66
}