1 | /* Copy SRC to DEST returning the address of the terminating '\0' in DEST. |
2 | For SPARC v7. |
3 | Copyright (C) 1996-2024 Free Software Foundation, Inc. |
4 | This file is part of the GNU C Library. |
5 | |
6 | The GNU C Library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Lesser General Public |
8 | License as published by the Free Software Foundation; either |
9 | version 2.1 of the License, or (at your option) any later version. |
10 | |
11 | The GNU C Library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Lesser General Public License for more details. |
15 | |
16 | You should have received a copy of the GNU Lesser General Public |
17 | License along with the GNU C Library; if not, see |
18 | <https://www.gnu.org/licenses/>. */ |
19 | |
20 | #include <sysdep.h> |
21 | |
22 | /* Normally, this uses ((xword - 0x01010101) & 0x80808080) test |
23 | to find out if any byte in xword could be zero. This is fast, but |
24 | also gives false alarm for any byte in range 0x81-0xff. It does |
25 | not matter for correctness, as if this test tells us there could |
26 | be some zero byte, we check it byte by byte, but if bytes with |
27 | high bits set are common in the strings, then this will give poor |
28 | performance. You can #define EIGHTBIT_NOT_RARE and the algorithm |
29 | will use one tick slower, but more precise test |
30 | ((xword - 0x01010101) & (~xword) & 0x80808080), |
31 | which does not give any false alarms (but if some bits are set, |
32 | one cannot assume from it which bytes are zero and which are not). |
33 | It is yet to be measured, what is the correct default for glibc |
34 | in these days for an average user. |
35 | */ |
36 | |
37 | .text |
38 | .align 4 |
39 | |
40 | ENTRY(__stpcpy) |
41 | andcc %o1, 3, %g0 |
42 | be 20f |
43 | sethi %hi(0x80808080), %o4 |
44 | |
45 | ldub [%o1], %o5 |
46 | stb %o5, [%o0] |
47 | cmp %o5, 0 |
48 | add %o0, 1, %o0 |
49 | be 1f |
50 | add %o1, 1, %o1 |
51 | andcc %o1, 3, %g0 |
52 | be 4f |
53 | or %o4, %lo(0x80808080), %o3 |
54 | ldub [%o1], %o5 |
55 | stb %o5, [%o0] |
56 | cmp %o5, 0 |
57 | add %o0, 1, %o0 |
58 | be 1f |
59 | add %o1, 1, %o1 |
60 | andcc %o1, 3, %g0 |
61 | be 5f |
62 | sethi %hi(0x01010101), %o4 |
63 | ldub [%o1], %o5 |
64 | stb %o5, [%o0] |
65 | cmp %o5, 0 |
66 | add %o0, 1, %o0 |
67 | be 1f |
68 | add %o1, 1, %o1 |
69 | b 6f |
70 | or %o4, %lo(0x01010101), %o2 |
71 | 1: retl |
72 | add %o0, -1, %o0 |
73 | |
74 | 20: or %o4, %lo(0x80808080), %o3 |
75 | 4: sethi %hi(0x01010101), %o4 |
76 | 5: or %o4, %lo(0x01010101), %o2 |
77 | 6: andcc %o0, 3, %g0 |
78 | bne 16f |
79 | sub %g0, 4, %g1 |
80 | |
81 | 11: add %g1, 4, %g1 |
82 | ld [%o1 + %g1], %o5 |
83 | sub %o5, %o2, %o4 |
84 | #ifdef EIGHTBIT_NOT_RARE |
85 | andn %o4, %o5, %o4 |
86 | #endif |
87 | andcc %o4, %o3, %g0 |
88 | be,a 11b |
89 | st %o5, [%o0 + %g1] |
90 | |
91 | /* Check every byte. */ |
92 | srl %o5, 24, %g5 |
93 | andcc %g5, 0xff, %g0 |
94 | be 14f |
95 | srl %o5, 16, %g5 |
96 | andcc %g5, 0xff, %g0 |
97 | be 13f |
98 | srl %o5, 8, %g5 |
99 | andcc %g5, 0xff, %g0 |
100 | be 12f |
101 | andcc %o5, 0xff, %g0 |
102 | bne 11b |
103 | st %o5, [%o0 + %g1] |
104 | add %o0, %g1, %o0 |
105 | retl |
106 | add %o0, 3, %o0 |
107 | 12: srl %o5, 16, %o5 |
108 | sth %o5, [%o0 + %g1] |
109 | add %g1, 2, %g1 |
110 | stb %g0, [%o0 + %g1] |
111 | retl |
112 | add %o0, %g1, %o0 |
113 | 13: srl %o5, 16, %o5 |
114 | sth %o5, [%o0 + %g1] |
115 | add %g1, 1, %g1 |
116 | retl |
117 | add %o0, %g1, %o0 |
118 | 14: stb %g0, [%o0 + %g1] |
119 | retl |
120 | add %o0, %g1, %o0 |
121 | |
122 | 15: srl %o5, 24, %o4 |
123 | srl %o5, 16, %g1 |
124 | stb %o4, [%o0] |
125 | srl %o5, 8, %g4 |
126 | stb %g1, [%o0 + 1] |
127 | stb %g4, [%o0 + 2] |
128 | stb %o5, [%o0 + 3] |
129 | add %o0, 4, %o0 |
130 | 16: ld [%o1], %o5 |
131 | sub %o5, %o2, %o4 |
132 | andcc %o4, %o3, %g0 |
133 | be 15b |
134 | add %o1, 4, %o1 |
135 | |
136 | /* Check every byte. */ |
137 | srl %o5, 24, %g5 |
138 | andcc %g5, 0xff, %g4 |
139 | be 19f |
140 | stb %g4, [%o0] |
141 | srl %o5, 16, %g5 |
142 | andcc %g5, 0xff, %g4 |
143 | be 18f |
144 | stb %g4, [%o0 + 1] |
145 | srl %o5, 8, %g5 |
146 | andcc %g5, 0xff, %g4 |
147 | be 17f |
148 | stb %g4, [%o0 + 2] |
149 | andcc %o5, 0xff, %g4 |
150 | stb %g4, [%o0 + 3] |
151 | bne 16b |
152 | add %o0, 4, %o0 |
153 | retl |
154 | sub %o0, 1, %o0 |
155 | 17: retl |
156 | add %o0, 2, %o0 |
157 | 18: retl |
158 | add %o0, 1, %o0 |
159 | 19: retl |
160 | nop |
161 | END(__stpcpy) |
162 | |
163 | weak_alias (__stpcpy, stpcpy) |
164 | libc_hidden_def (__stpcpy) |
165 | libc_hidden_builtin_def (stpcpy) |
166 | |