OSDN Git Service

2984ea156411a84b4e1cc267e52df09178284d96
[uclinux-h8/uClibc.git] / libc / string / sparc / sparc32 / stpcpy.S
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>.
6
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.
11
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.
16
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/>.  */
20
21         /* Normally, this uses ((xword - 0x01010101) & 0x80808080) test
22            to find out if any byte in xword could be zero. This is fast, but
23            also gives false alarm for any byte in range 0x81-0xff. It does
24            not matter for correctness, as if this test tells us there could
25            be some zero byte, we check it byte by byte, but if bytes with
26            high bits set are common in the strings, then this will give poor
27            performance. You can #define EIGHTBIT_NOT_RARE and the algorithm
28            will use one tick slower, but more precise test
29            ((xword - 0x01010101) & (~xword) & 0x80808080),
30            which does not give any false alarms (but if some bits are set,
31            one cannot assume from it which bytes are zero and which are not).
32            It is yet to be measured, what is the correct default for glibc
33            in these days for an average user.
34          */
35
36         .text
37         .align          4
38 10:     ldub            [%o1], %o5
39         stb             %o5, [%o0]
40         cmp             %o5, 0
41         add             %o0, 1, %o0
42         be              1f
43          add            %o1, 1, %o1
44         andcc           %o1, 3, %g0
45         be              4f
46          or             %o4, %lo(0x80808080), %o3
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              5f
55          sethi          %hi(0x01010101), %o4
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         b               6f
63          or             %o4, %lo(0x01010101), %o2
64 1:      retl
65          add            %o0, -1, %o0
66
67 ENTRY(stpcpy)
68         andcc           %o1, 3, %g0
69         bne             10b
70          sethi          %hi(0x80808080), %o4
71         or              %o4, %lo(0x80808080), %o3
72 4:      sethi           %hi(0x01010101), %o4
73 5:      or              %o4, %lo(0x01010101), %o2
74 6:      andcc           %o0, 3, %g0
75         bne             16f
76          sub            %g0, 4, %g1
77
78 11:     add             %g1, 4, %g1
79         ld              [%o1 + %g1], %o5
80         sub             %o5, %o2, %o4
81 #ifdef EIGHTBIT_NOT_RARE
82         andn            %o4, %o5, %o4
83 #endif
84         andcc           %o4, %o3, %g0
85         be,a            11b
86          st             %o5, [%o0 + %g1]
87
88         /* Check every byte. */
89         srl             %o5, 24, %g5
90         andcc           %g5, 0xff, %g0
91         be              14f
92          srl            %o5, 16, %g5
93         andcc           %g5, 0xff, %g0
94         be              13f
95          srl            %o5, 8, %g5
96         andcc           %g5, 0xff, %g0
97         be              12f
98          andcc          %o5, 0xff, %g0
99         bne             11b
100          st             %o5, [%o0 + %g1]
101         add             %o0, %g1, %o0
102         retl
103          add            %o0, 3, %o0
104 12:     srl             %o5, 16, %o5
105         sth             %o5, [%o0 + %g1]
106         add             %g1, 2, %g1
107         stb             %g0, [%o0 + %g1]
108         retl
109          add            %o0, %g1, %o0
110 13:     srl             %o5, 16, %o5
111         sth             %o5, [%o0 + %g1]
112         add             %g1, 1, %g1
113         retl
114          add            %o0, %g1, %o0
115 14:     stb             %g0, [%o0 + %g1]
116         retl
117          add            %o0, %g1, %o0
118
119 15:     srl             %o5, 24, %o4
120         srl             %o5, 16, %g1
121         stb             %o4, [%o0]
122         srl             %o5, 8, %g4
123         stb             %g1, [%o0 + 1]
124         stb             %g4, [%o0 + 2]
125         stb             %o5, [%o0 + 3]
126         add             %o0, 4, %o0
127 16:     ld              [%o1], %o5
128         sub             %o5, %o2, %o4
129         andcc           %o4, %o3, %g0
130         be              15b
131          add            %o1, 4, %o1
132
133         /* Check every byte. */
134         srl             %o5, 24, %g5
135         andcc           %g5, 0xff, %g4
136         be              19f
137          stb            %g4, [%o0]
138         srl             %o5, 16, %g5
139         andcc           %g5, 0xff, %g4
140         be              18f
141          stb            %g4, [%o0 + 1]
142         srl             %o5, 8, %g5
143         andcc           %g5, 0xff, %g4
144         be              17f
145          stb            %g4, [%o0 + 2]
146         andcc           %o5, 0xff, %g4
147         stb             %g4, [%o0 + 3]
148         bne             16b
149          add            %o0, 4, %o0
150         retl
151          sub            %o0, 1, %o0
152 17:     retl
153          add            %o0, 2, %o0
154 18:     retl
155          add            %o0, 1, %o0
156 19:     retl
157          nop
158 END(stpcpy)
159
160 libc_hidden_def(stpcpy)