OSDN Git Service

Use strong_alias everywhere instead of .global/.set. Correct some cases where the...
[uclinux-h8/uClibc.git] / libc / string / 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         .text
32         .align          4
33 0:      cmp             %o2, 0
34         be              9f
35          sethi          %hi(0x80808080), %o4
36         ldub            [%o0], %g4
37         cmp             %g4, %o1
38         be              1f
39          add            %o0, 1, %o0
40         subcc           %o2, 1, %o2
41         be              9f
42          andcc          %o0, 3, %g0
43         be              4f
44          or             %o4, %lo(0x80808080), %o3
45         ldub            [%o0], %g4
46         cmp             %g4, %o1
47         be              1f
48          add            %o0, 1, %o0
49         subcc           %o2, 1, %o2
50         be              9f
51          andcc          %o0, 3, %g0
52         be              5f
53          sethi          %hi(0x01010101), %o5
54         ldub            [%o0], %g4
55         cmp             %g4, %o1
56         be              1f
57          add            %o0, 1, %o0
58         subcc           %o2, 1, %o2
59         bne,a           7f
60          and            %o2, 3, %g1
61         retl
62          clr            %o0
63 1:      retl
64          sub            %o0, 1, %o0
65
66 ENTRY(__memchr)
67         andcc           %o1, 0xff, %o1
68         sll             %o1, 8, %g6
69         andcc           %o0, 3, %g0
70         or              %o1, %g6, %g6
71         sll             %g6, 16, %o3
72         bne             0b
73          or             %o3, %g6, %g2
74         sethi           %hi(0x80808080), %o4
75         or              %o4, %lo(0x80808080), %o3
76 4:      sethi           %hi(0x01010101), %o5
77 5:      and             %o2, 3, %g1
78 7:      andcc           %o2, 0xfffffffc, %o2
79         be              0f
80          or             %o5, %lo(0x01010101), %g6
81         ld              [%o0], %g4
82 6:      xor             %g4, %g2, %g5
83         add             %o0, 4, %o0
84         sub             %g5, %g6, %g5
85         andcc           %g5, %o3, %g0
86         bne             8f
87          subcc          %o2, 4, %o2
88         bne,a           6b
89          ld             [%o0], %g4
90 0:      cmp             %g1, 0
91 1:      be              9f
92          add            %o0, 4, %o0
93         ldub            [%o0 - 4], %g4
94         cmp             %g4, %o1
95         be              4f
96          cmp            %g1, 1
97         be              9f
98          ldub           [%o0 - 3], %g4
99         cmp             %g4, %o1
100         be              3f
101          cmp            %g1, 2
102         be              9f
103          ldub           [%o0 - 2], %g4
104         cmp             %g4, %o1
105         be              2f
106          nop
107 9:      retl
108          clr            %o0
109
110         /* Check every byte. */
111 8:      srl             %g4, 24, %g5
112         and             %g5, 0xff, %g5
113         cmp             %g5, %o1
114         be              4f
115          srl            %g4, 16, %g5
116         and             %g5, 0xff, %g5
117         cmp             %g5, %o1
118         be              3f
119          srl            %g4, 8, %g5
120         and             %g5, 0xff, %g5
121         cmp             %g5, %o1
122         be              2f
123          and            %g4, 0xff, %g5
124         cmp             %g5, %o1
125         be              1f
126          cmp            %o2, 0
127         bne,a           6b
128          ld             [%o0], %g4
129         b               1b
130          cmp            %g1, 0
131 1:      retl
132          sub            %o0, 1, %o0
133 2:      retl
134          sub            %o0, 2, %o0
135 3:      retl
136          sub            %o0, 3, %o0
137 4:      retl
138          sub            %o0, 4, %o0
139 END(__memchr)
140 strong_alias(__memchr,memchr)
141
142 #if !__BOUNDED_POINTERS__
143 weak_alias(__memchr,__ubp_memchr)
144 #endif