2.9
[glibc/nacl-glibc.git] / sysdeps / sparc / sparc32 / stpcpy.S
blob222bc2a445cb438435c62caebed1a351c1bea14e
1 /* Copy SRC to DEST returning the address of the terminating '\0' in DEST.
2    For SPARC v7.
3    Copyright (C) 1996, 1999, 2002, 2004 Free Software Foundation, Inc.
4    This file is part of the GNU C Library.
5    Contributed by Jakub Jelinek <jj@ultra.linux.cz>.
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, write to the Free
19    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20    02111-1307 USA.  */
22 #include <sysdep.h>
24         /* Normally, this uses ((xword - 0x01010101) & 0x80808080) test
25            to find out if any byte in xword could be zero. This is fast, but
26            also gives false alarm for any byte in range 0x81-0xff. It does
27            not matter for correctness, as if this test tells us there could
28            be some zero byte, we check it byte by byte, but if bytes with
29            high bits set are common in the strings, then this will give poor
30            performance. You can #define EIGHTBIT_NOT_RARE and the algorithm
31            will use one tick slower, but more precise test
32            ((xword - 0x01010101) & (~xword) & 0x80808080),
33            which does not give any false alarms (but if some bits are set,
34            one cannot assume from it which bytes are zero and which are not).
35            It is yet to be measured, what is the correct default for glibc
36            in these days for an average user.
37          */
39         .text
40         .align          4
42 ENTRY(__stpcpy)
43         andcc           %o1, 3, %g0
44         be              20f
45          sethi          %hi(0x80808080), %o4
47         ldub            [%o1], %o5
48         stb             %o5, [%o0]
49         cmp             %o5, 0
50         add             %o0, 1, %o0
51         be              1f
52          add            %o1, 1, %o1
53         andcc           %o1, 3, %g0
54         be              4f
55          or             %o4, %lo(0x80808080), %o3
56         ldub            [%o1], %o5
57         stb             %o5, [%o0]
58         cmp             %o5, 0
59         add             %o0, 1, %o0
60         be              1f
61          add            %o1, 1, %o1
62         andcc           %o1, 3, %g0
63         be              5f
64          sethi          %hi(0x01010101), %o4
65         ldub            [%o1], %o5
66         stb             %o5, [%o0]
67         cmp             %o5, 0
68         add             %o0, 1, %o0
69         be              1f
70          add            %o1, 1, %o1
71         b               6f
72          or             %o4, %lo(0x01010101), %o2
73 1:      retl
74          add            %o0, -1, %o0
76 20:     or              %o4, %lo(0x80808080), %o3
77 4:      sethi           %hi(0x01010101), %o4
78 5:      or              %o4, %lo(0x01010101), %o2
79 6:      andcc           %o0, 3, %g0
80         bne             16f
81          sub            %g0, 4, %g1
83 11:     add             %g1, 4, %g1
84         ld              [%o1 + %g1], %o5
85         sub             %o5, %o2, %o4
86 #ifdef EIGHTBIT_NOT_RARE
87         andn            %o4, %o5, %o4
88 #endif
89         andcc           %o4, %o3, %g0
90         be,a            11b
91          st             %o5, [%o0 + %g1]
93         /* Check every byte. */
94         srl             %o5, 24, %g5
95         andcc           %g5, 0xff, %g0
96         be              14f
97          srl            %o5, 16, %g5
98         andcc           %g5, 0xff, %g0
99         be              13f
100          srl            %o5, 8, %g5
101         andcc           %g5, 0xff, %g0
102         be              12f
103          andcc          %o5, 0xff, %g0
104         bne             11b
105          st             %o5, [%o0 + %g1]
106         add             %o0, %g1, %o0
107         retl
108          add            %o0, 3, %o0
109 12:     srl             %o5, 16, %o5
110         sth             %o5, [%o0 + %g1]
111         add             %g1, 2, %g1
112         stb             %g0, [%o0 + %g1]
113         retl
114          add            %o0, %g1, %o0
115 13:     srl             %o5, 16, %o5
116         sth             %o5, [%o0 + %g1]
117         add             %g1, 1, %g1
118         retl
119          add            %o0, %g1, %o0
120 14:     stb             %g0, [%o0 + %g1]
121         retl
122          add            %o0, %g1, %o0
124 15:     srl             %o5, 24, %o4
125         srl             %o5, 16, %g1
126         stb             %o4, [%o0]
127         srl             %o5, 8, %g4
128         stb             %g1, [%o0 + 1]
129         stb             %g4, [%o0 + 2]
130         stb             %o5, [%o0 + 3]
131         add             %o0, 4, %o0
132 16:     ld              [%o1], %o5
133         sub             %o5, %o2, %o4
134         andcc           %o4, %o3, %g0
135         be              15b
136          add            %o1, 4, %o1
138         /* Check every byte. */
139         srl             %o5, 24, %g5
140         andcc           %g5, 0xff, %g4
141         be              19f
142          stb            %g4, [%o0]
143         srl             %o5, 16, %g5
144         andcc           %g5, 0xff, %g4
145         be              18f
146          stb            %g4, [%o0 + 1]
147         srl             %o5, 8, %g5
148         andcc           %g5, 0xff, %g4
149         be              17f
150          stb            %g4, [%o0 + 2]
151         andcc           %o5, 0xff, %g4
152         stb             %g4, [%o0 + 3]
153         bne             16b
154          add            %o0, 4, %o0
155         retl
156          sub            %o0, 1, %o0
157 17:     retl
158          add            %o0, 2, %o0
159 18:     retl
160          add            %o0, 1, %o0
161 19:     retl
162          nop
163 END(__stpcpy)
165 weak_alias (__stpcpy, stpcpy)
166 libc_hidden_def (__stpcpy)
167 libc_hidden_builtin_def (stpcpy)