(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / sysdeps / sparc / sparc32 / stpcpy.S
blob937fed35f85717716945cf22da0722d961f77427
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
41 10:     ldub            [%o1], %o5
42         stb             %o5, [%o0]
43         cmp             %o5, 0
44         add             %o0, 1, %o0
45         be              1f
46          add            %o1, 1, %o1
47         andcc           %o1, 3, %g0
48         be              4f
49          or             %o4, %lo(0x80808080), %o3
50         ldub            [%o1], %o5
51         stb             %o5, [%o0]
52         cmp             %o5, 0
53         add             %o0, 1, %o0
54         be              1f
55          add            %o1, 1, %o1
56         andcc           %o1, 3, %g0
57         be              5f
58          sethi          %hi(0x01010101), %o4
59         ldub            [%o1], %o5
60         stb             %o5, [%o0]
61         cmp             %o5, 0
62         add             %o0, 1, %o0
63         be              1f
64          add            %o1, 1, %o1
65         b               6f
66          or             %o4, %lo(0x01010101), %o2
67 1:      retl
68          add            %o0, -1, %o0
70 ENTRY(__stpcpy)
71         andcc           %o1, 3, %g0
72         bne             10b
73          sethi          %hi(0x80808080), %o4
74         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
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]
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
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
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)
163 weak_alias(__stpcpy, stpcpy)
164 libc_hidden_def (__stpcpy)
165 libc_hidden_builtin_def (stpcpy)