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