LoongArch: Update ulps
[glibc.git] / sysdeps / sparc / sparc32 / memchr.S
blob6968a3ae16abc03e688a4f8c52e1e8cb685c0abb
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-2024 Free Software Foundation, Inc.
5    This file is part of the GNU C Library.
7    The GNU C Library is free software; you can redistribute it and/or
8    modify it under the terms of the GNU Lesser General Public
9    License as published by the Free Software Foundation; either
10    version 2.1 of the License, or (at your option) any later version.
12    The GNU C Library is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15    Lesser General Public License for more details.
17    You should have received a copy of the GNU Lesser General Public
18    License along with the GNU C Library; if not, see
19    <https://www.gnu.org/licenses/>.  */
21 #include <sysdep.h>
23         .text
24         .align          4
25 ENTRY(__memchr)
26         andcc           %o1, 0xff, %o1
27         sll             %o1, 8, %g6
28         andcc           %o0, 3, %g0
29         or              %o1, %g6, %g6
30         sll             %g6, 16, %o3
31         be              10f
32          or             %o3, %g6, %g2
33         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 10:     sethi           %hi(0x80808080), %o4
66         or              %o4, %lo(0x80808080), %o3
67 4:      sethi           %hi(0x01010101), %o5
68 5:      and             %o2, 3, %g1
69 7:      andcc           %o2, 0xfffffffc, %o2
70         be              0f
71          or             %o5, %lo(0x01010101), %g6
72         ld              [%o0], %g4
73 6:      xor             %g4, %g2, %g5
74         add             %o0, 4, %o0
75         sub             %g5, %g6, %g5
76         andcc           %g5, %o3, %g0
77         bne             8f
78          subcc          %o2, 4, %o2
79         bne,a           6b
80          ld             [%o0], %g4
81 0:      cmp             %g1, 0
82 1:      be              9f
83          add            %o0, 4, %o0
84         ldub            [%o0 - 4], %g4
85         cmp             %g4, %o1
86         be              4f
87          cmp            %g1, 1
88         be              9f
89          ldub           [%o0 - 3], %g4
90         cmp             %g4, %o1
91         be              3f
92          cmp            %g1, 2
93         be              9f
94          ldub           [%o0 - 2], %g4
95         cmp             %g4, %o1
96         be              2f
97          nop
98 9:      retl
99          clr            %o0
101         /* Check every byte. */
102 8:      srl             %g4, 24, %g5
103         and             %g5, 0xff, %g5
104         cmp             %g5, %o1
105         be              4f
106          srl            %g4, 16, %g5
107         and             %g5, 0xff, %g5
108         cmp             %g5, %o1
109         be              3f
110          srl            %g4, 8, %g5
111         and             %g5, 0xff, %g5
112         cmp             %g5, %o1
113         be              2f
114          and            %g4, 0xff, %g5
115         cmp             %g5, %o1
116         be              1f
117          cmp            %o2, 0
118         bne,a           6b
119          ld             [%o0], %g4
120         b               1b
121          cmp            %g1, 0
122 1:      retl
123          sub            %o0, 1, %o0
124 2:      retl
125          sub            %o0, 2, %o0
126 3:      retl
127          sub            %o0, 3, %o0
128 4:      retl
129          sub            %o0, 4, %o0
130 END(__memchr)
132 weak_alias (__memchr, memchr)
133 libc_hidden_builtin_def (memchr)