Update copyright notices with scripts/update-copyrights
[glibc.git] / sysdeps / sparc / sparc32 / memchr.S
blob088e538d7775c25adfeec4f59ad0d97a15e055ae
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-2014 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).
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.
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.
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/>.  */
30 #include <sysdep.h>
32         .text
33         .align          4
34 ENTRY(__memchr)
35         andcc           %o1, 0xff, %o1
36         sll             %o1, 8, %g6
37         andcc           %o0, 3, %g0
38         or              %o1, %g6, %g6
39         sll             %g6, 16, %o3
40         be              10f
41          or             %o3, %g6, %g2
42         cmp             %o2, 0
43         be              9f
44          sethi          %hi(0x80808080), %o4
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              4f
53          or             %o4, %lo(0x80808080), %o3
54         ldub            [%o0], %g4
55         cmp             %g4, %o1
56         be              1f
57          add            %o0, 1, %o0
58         subcc           %o2, 1, %o2
59         be              9f
60          andcc          %o0, 3, %g0
61         be              5f
62          sethi          %hi(0x01010101), %o5
63         ldub            [%o0], %g4
64         cmp             %g4, %o1
65         be              1f
66          add            %o0, 1, %o0
67         subcc           %o2, 1, %o2
68         bne,a           7f
69          and            %o2, 3, %g1
70         retl
71          clr            %o0
72 1:      retl
73          sub            %o0, 1, %o0
74 10:     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
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)
141 weak_alias (__memchr, memchr)
142 libc_hidden_builtin_def (memchr)