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