OSDN Git Service

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