2.9
[glibc/nacl-glibc.git] / sysdeps / sparc / sparc32 / strlen.S
blobed92f20e28742ee0688938b783273988bfc07de0
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
42 ENTRY(strlen)
43         mov             %o0, %o1
44         andcc           %o0, 3, %g0
45         be              20f
46          sethi          %hi(0x80808080), %o4
48         ldub            [%o0], %o5
49         cmp             %o5, 0
50         be              21f
51          add            %o0, 1, %o0
52         andcc           %o0, 3, %g0
53         be              4f
54          or             %o4, %lo(0x80808080), %o3
55         ldub            [%o0], %o5
56         cmp             %o5, 0
57         be              22f
58          add            %o0, 1, %o0
59         andcc           %o0, 3, %g0
60         be              5f
61          sethi          %hi(0x01010101), %o4
62         ldub            [%o0], %o5
63         cmp             %o5, 0
64         be              23f
65          add            %o0, 1, %o0
66         b               11f
67          or             %o4, %lo(0x01010101), %o2
68 21:     retl
69          mov            0, %o0
70 22:     retl
71          mov            1, %o0
72 23:     retl
73          mov            2, %o0
75 20:     or              %o4, %lo(0x80808080), %o3
76 4:      sethi           %hi(0x01010101), %o4
77 5:      or              %o4, %lo(0x01010101), %o2
78 11:     ld              [%o0], %o5
79 12:     sub             %o5, %o2, %o4
80 #ifdef EIGHTBIT_NOT_RARE
81         andn            %o4, %o5, %o4
82 #endif
83         andcc           %o4, %o3, %g0
84         be              11b
85          add            %o0, 4, %o0
87         srl             %o5, 24, %g5
88         andcc           %g5, 0xff, %g0
89         be              13f
90          add            %o0, -4, %o4
91         srl             %o5, 16, %g5
92         andcc           %g5, 0xff, %g0
93         be              13f
94          add            %o4, 1, %o4
95         srl             %o5, 8, %g5
96         andcc           %g5, 0xff, %g0
97         be              13f
98          add            %o4, 1, %o4
99         andcc           %o5, 0xff, %g0
100         bne,a           12b
101          ld             [%o0], %o5
102         add             %o4, 1, %o4
103 13:     retl
104          sub            %o4, %o1, %o0
105 END(strlen)
106 libc_hidden_builtin_def (strlen)