]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/sparc/sparc32/memchr.S
Update.
[thirdparty/glibc.git] / sysdeps / sparc / sparc32 / memchr.S
1 /* memchr (str, ch, n) -- Return pointer to first occurrence of CH in STR less
2 than N.
3 For SPARC v7.
4 Copyright (C) 1996, 1999, 2000, 2003 Free Software Foundation, Inc.
5 This file is part of the GNU C Library.
6 Contributed by Jakub Jelinek <jj@ultra.linux.cz> and
7 David S. Miller <davem@caip.rutgers.edu>.
8 This version is developed using the same algorithm as the fast C
9 version which carries the following introduction:
10 Based on strlen implementation by Torbjorn Granlund (tege@sics.se),
11 with help from Dan Sahlin (dan@sics.se) and
12 commentary by Jim Blandy (jimb@ai.mit.edu);
13 adaptation to memchr suggested by Dick Karpinski (dick@cca.ucsf.edu),
14 and implemented by Roland McGrath (roland@ai.mit.edu).
15
16 The GNU C Library is free software; you can redistribute it and/or
17 modify it under the terms of the GNU Lesser General Public
18 License as published by the Free Software Foundation; either
19 version 2.1 of the License, or (at your option) any later version.
20
21 The GNU C Library is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 Lesser General Public License for more details.
25
26 You should have received a copy of the GNU Lesser General Public
27 License along with the GNU C Library; if not, write to the Free
28 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
29 02111-1307 USA. */
30
31 #include <sysdep.h>
32
33 .text
34 .align 4
35 0: cmp %o2, 0
36 be 9f
37 sethi %hi(0x80808080), %o4
38 ldub [%o0], %g4
39 cmp %g4, %o1
40 be 1f
41 add %o0, 1, %o0
42 subcc %o2, 1, %o2
43 be 9f
44 andcc %o0, 3, %g0
45 be 4f
46 or %o4, %lo(0x80808080), %o3
47 ldub [%o0], %g4
48 cmp %g4, %o1
49 be 1f
50 add %o0, 1, %o0
51 subcc %o2, 1, %o2
52 be 9f
53 andcc %o0, 3, %g0
54 be 5f
55 sethi %hi(0x01010101), %o5
56 ldub [%o0], %g4
57 cmp %g4, %o1
58 be 1f
59 add %o0, 1, %o0
60 subcc %o2, 1, %o2
61 bne,a 7f
62 and %o2, 3, %g1
63 retl
64 clr %o0
65 1: retl
66 sub %o0, 1, %o0
67
68 ENTRY(__memchr)
69 andcc %o1, 0xff, %o1
70 sll %o1, 8, %g6
71 andcc %o0, 3, %g0
72 or %o1, %g6, %g6
73 sll %g6, 16, %o3
74 bne 0b
75 or %o3, %g6, %g2
76 sethi %hi(0x80808080), %o4
77 or %o4, %lo(0x80808080), %o3
78 4: sethi %hi(0x01010101), %o5
79 5: and %o2, 3, %g1
80 7: andcc %o2, 0xfffffffc, %o2
81 be 0f
82 or %o5, %lo(0x01010101), %g6
83 ld [%o0], %g4
84 6: xor %g4, %g2, %g5
85 add %o0, 4, %o0
86 sub %g5, %g6, %g5
87 andcc %g5, %o3, %g0
88 bne 8f
89 subcc %o2, 4, %o2
90 bne,a 6b
91 ld [%o0], %g4
92 0: cmp %g1, 0
93 1: be 9f
94 add %o0, 4, %o0
95 ldub [%o0 - 4], %g4
96 cmp %g4, %o1
97 be 4f
98 cmp %g1, 1
99 be 9f
100 ldub [%o0 - 3], %g4
101 cmp %g4, %o1
102 be 3f
103 cmp %g1, 2
104 be 9f
105 ldub [%o0 - 2], %g4
106 cmp %g4, %o1
107 be 2f
108 nop
109 9: retl
110 clr %o0
111
112 /* Check every byte. */
113 8: srl %g4, 24, %g5
114 and %g5, 0xff, %g5
115 cmp %g5, %o1
116 be 4f
117 srl %g4, 16, %g5
118 and %g5, 0xff, %g5
119 cmp %g5, %o1
120 be 3f
121 srl %g4, 8, %g5
122 and %g5, 0xff, %g5
123 cmp %g5, %o1
124 be 2f
125 and %g4, 0xff, %g5
126 cmp %g5, %o1
127 be 1f
128 cmp %o2, 0
129 bne,a 6b
130 ld [%o0], %g4
131 b 1b
132 cmp %g1, 0
133 1: retl
134 sub %o0, 1, %o0
135 2: retl
136 sub %o0, 2, %o0
137 3: retl
138 sub %o0, 3, %o0
139 4: retl
140 sub %o0, 4, %o0
141 END(__memchr)
142
143 weak_alias (__memchr, memchr)
144 #if !__BOUNDED_POINTERS__
145 weak_alias (__memchr, __ubp_memchr)
146 #endif