]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/sparc/sparc32/strlen.S
Update.
[thirdparty/glibc.git] / sysdeps / sparc / sparc32 / strlen.S
CommitLineData
ae6b8730
RH
1/* Determine the length of a string.
2 For SPARC v7.
3 Copyright (C) 1996, 1999 Free Software Foundation, Inc.
4 Contributed by Jakub Jelinek <jj@ultra.linux.cz>.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 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 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public
17 License along with the GNU C Library; see the file COPYING.LIB. If not,
18 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20
21#include <sysdep.h>
22
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 */
37
38 .text
39 .align 4
4010: ldub [%o0], %o5
41 cmp %o5, 0
42 be 1f
43 add %o0, 1, %o0
44 andcc %o0, 3, %g0
45 be 4f
46 or %o4, %lo(0x80808080), %o3
47 ldub [%o0], %o5
48 cmp %o5, 0
49 be 2f
50 add %o0, 1, %o0
51 andcc %o0, 3, %g0
52 be 5f
53 sethi %hi(0x01010101), %o4
54 ldub [%o0], %o5
55 cmp %o5, 0
56 be 3f
57 add %o0, 1, %o0
58 b 11f
59 or %o4, %lo(0x01010101), %o2
601: retl
61 mov 0, %o0
622: retl
63 mov 1, %o0
643: retl
65 mov 2, %o0
66
67ENTRY(strlen)
68 mov %o0, %o1
69 andcc %o0, 3, %g0
70 bne 10b
71 sethi %hi(0x80808080), %o4
72 or %o4, %lo(0x80808080), %o3
734: sethi %hi(0x01010101), %o4
745: or %o4, %lo(0x01010101), %o2
7511: ld [%o0], %o5
7612: sub %o5, %o2, %o4
77#ifdef EIGHTBIT_NOT_RARE
78 andn %o4, %o5, %o4
79#endif
80 andcc %o4, %o3, %g0
81 be 11b
82 add %o0, 4, %o0
83
84 srl %o5, 24, %g5
85 andcc %g5, 0xff, %g0
86 be 13f
87 add %o0, -4, %o4
88 srl %o5, 16, %g5
89 andcc %g5, 0xff, %g0
90 be 13f
91 add %o4, 1, %o4
92 srl %o5, 8, %g5
93 andcc %g5, 0xff, %g0
94 be 13f
95 add %o4, 1, %o4
96 andcc %o5, 0xff, %g0
97 bne,a 12b
98 ld [%o0], %o5
99 add %o4, 1, %o4
10013: retl
101 sub %o4, %o1, %o0
102END(strlen)