Welcome to mirror list, hosted at ThFree Co, Russian Federation.

strchr.c « xscale « machine « libc « newlib - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6ea5032b051438ad5190f9fd52eec36da2953181 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#if defined __thumb__

#include "../../string/strchr.c"

#else

#include <string.h>
#include "xscale.h"

char *
strchr (const char *s, int c)
{
  unsigned int c2;
  asm (PRELOADSTR ("%0") : : "r" (s));

  c &= 0xff;

#ifndef __OPTIMIZE_SIZE__
  /* Skip unaligned part.  */
  if ((long)s & 3)
    {
      s--;
      do
	{
	  int c2 = *++s;
	  if (c2 == c)
	    return (char *)s;
	  if (c2 == '\0')
	    return 0;
	}
      while (((long)s & 3) != 0);
    }

  c2 = c + (c << 8);
  c2 += c2 << 16;

  /* Load two constants:
     R6 = 0xfefefeff [ == ~(0x80808080 << 1) ]
     R5 = 0x80808080  */

  asm (PRELOADSTR ("%0") "
	mov	r5, #0x80
	add	r5, r5, #0x8000
	add	r5, r5, r5, lsl #16
	mvn	r6, r5, lsl #1

	sub	%0, %0, #4
0:
	ldr	r1, [%0, #4]!
"	PRELOADSTR ("%0") "
	add	r3, r1, r6
	bic	r3, r3, r1
	ands	r2, r3, r5
	bne	1f
	eor	r2, r1, %1
	add	r3, r2, r6
	bic	r3, r3, r2
	ands	r1, r3, r5
	beq	0b
1:"
       : "=&r" (s)
       : "r" (c2), "0" (s)
       : "r2", "r3", "r5", "r6", "cc");
#endif

  while (*s && *s != c)
    s++;
  if (*s == c)
    return (char *)s;
  return NULL;
}

#endif