]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/uclibc/lib/contrib/uclibc/libc/string/sparc/sparc32/strlen.S
update
[l4.git] / l4 / pkg / uclibc / lib / contrib / uclibc / libc / string / sparc / sparc32 / strlen.S
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>.
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            [%o0], %o5
39         cmp             %o5, 0
40         be              1f
41          add            %o0, 1, %o0
42         andcc           %o0, 3, %g0
43         be              4f
44          or             %o4, %lo(0x80808080), %o3
45         ldub            [%o0], %o5
46         cmp             %o5, 0
47         be              2f
48          add            %o0, 1, %o0
49         andcc           %o0, 3, %g0
50         be              5f
51          sethi          %hi(0x01010101), %o4
52         ldub            [%o0], %o5
53         cmp             %o5, 0
54         be              3f
55          add            %o0, 1, %o0
56         b               11f
57          or             %o4, %lo(0x01010101), %o2
58 1:      retl
59          mov            0, %o0
60 2:      retl
61          mov            1, %o0
62 3:      retl
63          mov            2, %o0
64
65 ENTRY(strlen)
66         mov             %o0, %o1
67         andcc           %o0, 3, %g0
68         bne             10b
69          sethi          %hi(0x80808080), %o4
70         or              %o4, %lo(0x80808080), %o3
71 4:      sethi           %hi(0x01010101), %o4
72 5:      or              %o4, %lo(0x01010101), %o2
73 11:     ld              [%o0], %o5
74 12:     sub             %o5, %o2, %o4
75 #ifdef EIGHTBIT_NOT_RARE
76         andn            %o4, %o5, %o4
77 #endif
78         andcc           %o4, %o3, %g0
79         be              11b
80          add            %o0, 4, %o0
81
82         srl             %o5, 24, %g5
83         andcc           %g5, 0xff, %g0
84         be              13f
85          add            %o0, -4, %o4
86         srl             %o5, 16, %g5
87         andcc           %g5, 0xff, %g0
88         be              13f
89          add            %o4, 1, %o4
90         srl             %o5, 8, %g5
91         andcc           %g5, 0xff, %g0
92         be              13f
93          add            %o4, 1, %o4
94         andcc           %o5, 0xff, %g0
95         bne,a           12b
96          ld             [%o0], %o5
97         add             %o4, 1, %o4
98 13:     retl
99          sub            %o4, %o1, %o0
100 END(strlen)
101 libc_hidden_def(strlen)