]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/sparc/sparc32/memchr.S
Prefer https to http for gnu.org and fsf.org URLs
[thirdparty/glibc.git] / sysdeps / sparc / sparc32 / memchr.S
CommitLineData
ae6b8730
RH
1/* memchr (str, ch, n) -- Return pointer to first occurrence of CH in STR less
2 than N.
3 For SPARC v7.
04277e02 4 Copyright (C) 1996-2019 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>.
ae6b8730
RH
8 This version is developed using the same algorithm as the fast C
9 version which carries the following introduction:
ae6b8730
RH
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
41bdb6e2
AJ
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.
ae6b8730
RH
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
41bdb6e2 24 Lesser General Public License for more details.
ae6b8730 25
41bdb6e2 26 You should have received a copy of the GNU Lesser General Public
59ba27a6 27 License along with the GNU C Library; if not, see
5a82c748 28 <https://www.gnu.org/licenses/>. */
ae6b8730
RH
29
30#include <sysdep.h>
31
32 .text
33 .align 4
043cee37
RM
34ENTRY(__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
ae6b8730
RH
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
721: retl
73 sub %o0, 1, %o0
043cee37 7410: sethi %hi(0x80808080), %o4
ae6b8730
RH
75 or %o4, %lo(0x80808080), %o3
764: sethi %hi(0x01010101), %o5
775: and %o2, 3, %g1
787: andcc %o2, 0xfffffffc, %o2
79 be 0f
62f29da7 80 or %o5, %lo(0x01010101), %g6
ae6b8730
RH
81 ld [%o0], %g4
826: xor %g4, %g2, %g5
83 add %o0, 4, %o0
62f29da7 84 sub %g5, %g6, %g5
ae6b8730
RH
85 andcc %g5, %o3, %g0
86 bne 8f
87 subcc %o2, 4, %o2
88 bne,a 6b
89 ld [%o0], %g4
900: cmp %g1, 0
911: 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
1079: retl
108 clr %o0
109
110 /* Check every byte. */
2ed5fd9a 1118: srl %g4, 24, %g5
ae6b8730
RH
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
1311: retl
132 sub %o0, 1, %o0
1332: retl
134 sub %o0, 2, %o0
1353: retl
136 sub %o0, 3, %o0
1374: retl
138 sub %o0, 4, %o0
abf70633
GM
139END(__memchr)
140
141weak_alias (__memchr, memchr)
85dd1003 142libc_hidden_builtin_def (memchr)