OSDN Git Service

ldso: Fix compile-error on noMMU
[uclinux-h8/uClibc.git] / libc / string / sparc / sparc64 / strlen.S
1 /* Determine the length of a string.  For SPARC v9.
2    Copyright (C) 1998, 1999, 2003 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4    Contributed by Jan Vondrak <jvon4518@ss1000.ms.mff.cuni.cz> and
5                   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 #include <asm/asi.h>
22
23         /* Normally, this uses
24            ((xword - 0x0101010101010101) & 0x8080808080808080) 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 - 0x0101010101010101) & (~xword) & 0x8080808080808080),
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          */
38
39         .text
40         .align          32
41 ENTRY(strlen)
42         sethi           %hi(0x01010101), %g1            /* IEU0         Group           */
43         ldub            [%o0], %o3                      /* Load                         */
44         or              %g1, %lo(0x01010101), %g1       /* IEU0         Group           */
45         mov             %o0, %o1                        /* IEU1                         */
46
47         sllx            %g1, 32, %g4                    /* IEU0         Group           */
48         andcc           %o0, 7, %g0                     /* IEU1                         */
49         or              %g1, %g4, %g1                   /* IEU0         Group           */
50         brz,pn          %o3, 13f                        /* CTI+IEU1                     */
51
52          sllx           %g1, 7, %g4                     /* IEU0         Group           */
53         bne,a,pn        %icc, 15f                       /* CTI                          */
54          add            %o0, 1, %o0                     /* IEU1                         */
55                                                         /* %g1 = 0x0101010101010101     *
56                                                          * %g4 = 0x8080808080808080     *
57                                                          * %o0 = string pointer         *
58                                                          * %o1 = start of string        */
59 1:      ldx             [%o0], %o3                      /* Load         Group           */
60
61         add             %o0, 8, %o0                     /* IEU1                         */
62 2:      sub             %o3, %g1, %o2                   /* IEU0         Group           */
63 #ifdef EIGHTBIT_NOT_RARE
64         andn            %o2, %o3, %o5                   /* IEU0         Group           */
65         ldxa            [%o0] ASI_PNF, %o3              /* Load                         */
66         andcc           %o5, %g4, %g0                   /* IEU1         Group           */
67 #else
68         ldxa            [%o0] ASI_PNF, %o3              /* Load                         */
69         andcc           %o2, %g4, %g0                   /* IEU1         Group           */
70 #endif
71
72         be,pt           %xcc, 2b                        /* CTI                          */
73          add            %o0, 8, %o0                     /* IEU0                         */
74         addcc           %o2, %g1, %g5                   /* IEU1         Group           */
75 #ifdef EIGHTBIT_NOT_RARE
76         srlx            %o5, 32, %o5                    /* IEU0                         */
77
78 3:      andcc           %o5, %g4, %g0                   /* IEU1         Group           */
79 #else
80         srlx            %o2, 32, %o2                    /* IEU0                         */
81
82 3:      andcc           %o2, %g4, %g0                   /* IEU1         Group           */
83 #endif
84         be,pn           %xcc, 4f                        /* CTI                          */
85          srlx           %g5, 56, %o2                    /* IEU0                         */
86         andcc           %o2, 0xff, %g0                  /* IEU1         Group           */
87
88         be,pn           %icc, 12f                       /* CTI                          */
89          srlx           %g5, 48, %o2                    /* IEU0                         */
90         andcc           %o2, 0xff, %g0                  /* IEU1         Group           */
91         be,pn           %icc, 11f                       /* CTI                          */
92
93          srlx           %g5, 40, %o2                    /* IEU0                         */
94         andcc           %o2, 0xff, %g0                  /* IEU1         Group           */
95         be,pn           %icc, 10f                       /* CTI                          */
96          srlx           %g5, 32, %o2                    /* IEU0                         */
97
98         andcc           %o2, 0xff, %g0                  /* IEU1         Group           */
99         be,pn           %icc, 9f                        /* CTI                          */
100 4:       srlx           %g5, 24, %o2                    /* IEU0                         */
101         andcc           %o2, 0xff, %g0                  /* IEU1         Group           */
102
103         be,pn           %icc, 8f                        /* CTI                          */
104          srlx           %g5, 16, %o2                    /* IEU0                         */
105         andcc           %o2, 0xff, %g0                  /* IEU1         Group           */
106         be,pn           %icc, 7f                        /* CTI                          */
107
108          srlx           %g5, 8, %o2                     /* IEU0                         */
109         andcc           %o2, 0xff, %g0                  /* IEU1         Group           */
110         be,pn           %icc, 6f                        /* CTI                          */
111          sub            %o3, %g1, %o2                   /* IEU0                         */
112
113         andcc           %g5, 0xff, %g0                  /* IEU1         Group           */
114         be,pn           %icc, 5f                        /* CTI                          */
115          ldxa           [%o0] ASI_PNF, %o3              /* Load                         */
116         andcc           %o2, %g4, %g0                   /* IEU1         Group           */
117
118         be,pt           %xcc, 2b                        /* CTI                          */
119          add            %o0, 8, %o0                     /* IEU0                         */
120         addcc           %o2, %g1, %g5                   /* IEU1         Group           */
121         ba,pt           %xcc, 3b                        /* CTI                          */
122
123          srlx           %o2, 32, %o2                    /* IEU0                         */
124 5:      add             %o0, -9, %o0                    /* IEU0         Group           */
125         retl                                            /* CTI+IEU1     Group           */
126          sub            %o0, %o1, %o0                   /* IEU0                         */
127
128 6:      add             %o0, -10, %o0                   /* IEU0         Group           */
129         retl                                            /* CTI+IEU1     Group           */
130          sub            %o0, %o1, %o0                   /* IEU0                         */
131 7:      add             %o0, -11, %o0                   /* IEU0         Group           */
132
133         retl                                            /* CTI+IEU1     Group           */
134          sub            %o0, %o1, %o0                   /* IEU0                         */
135 8:      add             %o0, -12, %o0                   /* IEU0         Group           */
136         retl                                            /* CTI+IEU1     Group           */
137
138          sub            %o0, %o1, %o0                   /* IEU0                         */
139 9:      add             %o0, -13, %o0                   /* IEU0         Group           */
140         retl                                            /* CTI+IEU1     Group           */
141          sub            %o0, %o1, %o0                   /* IEU0                         */
142
143 10:     add             %o0, -14, %o0                   /* IEU0         Group           */
144         retl                                            /* CTI+IEU1     Group           */
145          sub            %o0, %o1, %o0                   /* IEU0                         */
146 11:     add             %o0, -15, %o0                   /* IEU0         Group           */
147
148         retl                                            /* CTI+IEU1     Group           */
149          sub            %o0, %o1, %o0                   /* IEU0                         */
150 12:     add             %o0, -16, %o0                   /* IEU0         Group           */
151         retl                                            /* CTI+IEU1     Group           */
152
153          sub            %o0, %o1, %o0                   /* IEU0                         */
154 13:     retl                                            /* CTI+IEU1     Group           */
155          mov            0, %o0                          /* IEU0                         */
156         nop
157
158 15:     ldub            [%o0], %o3                      /* Load         Group           */
159 16:     andcc           %o0, 7, %g0                     /* IEU1                         */
160         be,pn           %icc, 1b                        /* CTI                          */
161          nop                                            /* IEU0         Group           */
162
163         add             %o0, 1, %o0                     /* IEU1                         */
164         andcc           %o3, 0xff, %g0                  /* IEU1         Group           */
165         bne,a,pt        %icc, 16b                       /* CTI                          */
166          lduba          [%o0] ASI_PNF, %o3              /* Load                         */
167
168         add             %o0, -1, %o0                    /* IEU0         Group           */
169         retl                                            /* CTI+IEU1     Group           */
170          sub            %o0, %o1, %o0                   /* IEU0                         */
171 END(strlen)
172 libc_hidden_def(strlen)