(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / sysdeps / sparc / sparc32 / strlen.S
blob76466ec9dd2b557eabf71481aedb93c771677180
1 /* Determine the length of a string.
2    For SPARC v7.
3    Copyright (C) 1996, 1999, 2003 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            [%o0], %o5
42         cmp             %o5, 0
43         be              1f
44          add            %o0, 1, %o0
45         andcc           %o0, 3, %g0
46         be              4f
47          or             %o4, %lo(0x80808080), %o3
48         ldub            [%o0], %o5
49         cmp             %o5, 0
50         be              2f
51          add            %o0, 1, %o0
52         andcc           %o0, 3, %g0
53         be              5f
54          sethi          %hi(0x01010101), %o4
55         ldub            [%o0], %o5
56         cmp             %o5, 0
57         be              3f
58          add            %o0, 1, %o0
59         b               11f
60          or             %o4, %lo(0x01010101), %o2
61 1:      retl
62          mov            0, %o0
63 2:      retl
64          mov            1, %o0
65 3:      retl
66          mov            2, %o0
68 ENTRY(strlen)
69         mov             %o0, %o1
70         andcc           %o0, 3, %g0
71         bne             10b
72          sethi          %hi(0x80808080), %o4
73         or              %o4, %lo(0x80808080), %o3
74 4:      sethi           %hi(0x01010101), %o4
75 5:      or              %o4, %lo(0x01010101), %o2
76 11:     ld              [%o0], %o5
77 12:     sub             %o5, %o2, %o4
78 #ifdef EIGHTBIT_NOT_RARE
79         andn            %o4, %o5, %o4
80 #endif
81         andcc           %o4, %o3, %g0
82         be              11b
83          add            %o0, 4, %o0
85         srl             %o5, 24, %g5
86         andcc           %g5, 0xff, %g0
87         be              13f
88          add            %o0, -4, %o4
89         srl             %o5, 16, %g5
90         andcc           %g5, 0xff, %g0
91         be              13f
92          add            %o4, 1, %o4
93         srl             %o5, 8, %g5
94         andcc           %g5, 0xff, %g0
95         be              13f
96          add            %o4, 1, %o4
97         andcc           %o5, 0xff, %g0
98         bne,a           12b
99          ld             [%o0], %o5
100         add             %o4, 1, %o4
101 13:     retl
102          sub            %o4, %o1, %o0
103 END(strlen)
104 libc_hidden_builtin_def (strlen)