Update copyright notices with scripts/update-copyrights
[glibc.git] / sysdeps / sparc / sparc64 / rawmemchr.S
blob0d106c0095f735763ef36c6984844d0f69ab98e6
1 /* rawmemchr (str, ch) -- Return pointer to first occurrence of CH in STR.
2    For SPARC v9.
3    Copyright (C) 1999-2014 Free Software Foundation, Inc.
4    This file is part of the GNU C Library.
5    Contributed by Jakub Jelinek <jj@ultra.linux.cz>.
6    This version is developed using the same algorithm as the fast C
7    version which carries the following introduction:
8    Based on strlen implementation by Torbjorn Granlund (tege@sics.se),
9    with help from Dan Sahlin (dan@sics.se) and
10    commentary by Jim Blandy (jimb@ai.mit.edu);
11    adaptation to memchr suggested by Dick Karpinski (dick@cca.ucsf.edu),
12    and implemented by Roland McGrath (roland@ai.mit.edu).
14    The GNU C Library is free software; you can redistribute it and/or
15    modify it under the terms of the GNU Lesser General Public
16    License as published by the Free Software Foundation; either
17    version 2.1 of the License, or (at your option) any later version.
19    The GNU C Library is distributed in the hope that it will be useful,
20    but WITHOUT ANY WARRANTY; without even the implied warranty of
21    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22    Lesser General Public License for more details.
24    You should have received a copy of the GNU Lesser General Public
25    License along with the GNU C Library; if not, see
26    <http://www.gnu.org/licenses/>.  */
28 #include <sysdep.h>
29 #include <asm/asi.h>
30 #ifndef XCC
31 #define XCC xcc
32 #define USE_BPR
33         .register       %g2, #scratch
34         .register       %g3, #scratch
35 #endif
37         /* Normally, this uses
38            ((xword - 0x0101010101010101) & 0x8080808080808080) test
39            to find out if any byte in xword could be zero. This is fast, but
40            also gives false alarm for any byte in range 0x81-0xff. It does
41            not matter for correctness, as if this test tells us there could
42            be some zero byte, we check it byte by byte, but if bytes with
43            high bits set are common in the strings, then this will give poor
44            performance. You can #define EIGHTBIT_NOT_RARE and the algorithm
45            will use one tick slower, but more precise test
46            ((xword - 0x0101010101010101) & (~xword) & 0x8080808080808080),
47            which does not give any false alarms (but if some bits are set,
48            one cannot assume from it which bytes are zero and which are not).
49            It is yet to be measured, what is the correct default for glibc
50            in these days for an average user.
51          */
53         .text
54         .align          32
55 ENTRY(__rawmemchr)
56         and             %o1, 0xff, %o1                  /* IEU0         Group           */
57         sethi           %hi(0x01010101), %g1            /* IEU1                         */
58         ldub            [%o0], %o3                      /* Load                         */
59         sll             %o1, 8, %o4                     /* IEU0         Group           */
61         or              %g1, %lo(0x01010101), %g1       /* IEU1                         */
62         sllx            %g1, 32, %g2                    /* IEU0         Group           */
63         or              %o4, %o1, %o4                   /* IEU1                         */
64         andcc           %o0, 7, %g0                     /* IEU1         Group           */
66         sll             %o4, 16, %g5                    /* IEU0                         */
67         or              %o4, %g5, %o4                   /* IEU0         Group           */
68         or              %g1, %g2, %g1                   /* IEU1                         */
69         bne,pn          %icc, 32f                       /* CTI                          */
71          sllx           %o4, 32, %g5                    /* IEU0         Group           */
72         cmp             %o3, %o1                        /* IEU1                         */
73         be,pn           %icc, 30f                       /* CTI                          */
74          sllx           %g1, 7, %g2                     /* IEU0         Group           */
76 18:     ldx             [%o0], %o3                      /* Load                         */
77         or              %o4, %g5, %o4                   /* IEU1                         */
78         add             %o0, 8, %o0                     /* IEU0         Group           */
79 19:     xor             %o3, %o4, %o3                   /* IEU0         Group           */
81         sub             %o3, %g1, %o2                   /* IEU0         Group           */
82 #ifdef EIGHTBIT_NOT_RARE
83         andn            %o2, %o3, %o5                   /* IEU0         Group           */
84         ldxa            [%o0] ASI_PNF, %o3              /* Load                         */
85         andcc           %o5, %g2, %g0                   /* IEU1         Group           */
86 #else
87         ldxa            [%o0] ASI_PNF, %o3              /* Load                         */
88         andcc           %o2, %g2, %g0                   /* IEU1         Group           */
89 #endif
90         be,pt           %xcc, 19b                       /* CTI                          */
92          add            %o0, 8, %o0                     /* IEU0                         */
93         addcc           %o2, %g1, %g3                   /* IEU1         Group           */
94         srlx            %o2, 32, %o2                    /* IEU0                         */
95 20:     andcc           %o2, %g2, %g0                   /* IEU1         Group           */
97         be,pn           %xcc, 21f                       /* CTI                          */
98          srlx           %g3, 56, %o2                    /* IEU0                         */
99         andcc           %o2, 0xff, %g0                  /* IEU1         Group           */
100         be,pn           %icc, 29f                       /* CTI                          */
102          srlx           %g3, 48, %o2                    /* IEU0                         */
103         andcc           %o2, 0xff, %g0                  /* IEU1         Group           */
104         be,pn           %icc, 28f                       /* CTI                          */
105          srlx           %g3, 40, %o2                    /* IEU0                         */
107         andcc           %o2, 0xff, %g0                  /* IEU1         Group           */
108         be,pn           %icc, 27f                       /* CTI                          */
109          srlx           %g3, 32, %o2                    /* IEU0                         */
110         andcc           %o2, 0xff, %g0                  /* IEU1         Group           */
112         be,pn           %icc, 26f                       /* CTI                          */
113 21:      srlx           %g3, 24, %o2                    /* IEU0                         */
114         andcc           %o2, 0xff, %g0                  /* IEU1         Group           */
115         be,pn           %icc, 25f                       /* CTI                          */
117          srlx           %g3, 16, %o2                    /* IEU0                         */
118         andcc           %o2, 0xff, %g0                  /* IEU1         Group           */
119         be,pn           %icc, 24f                       /* CTI                          */
120          srlx           %g3, 8, %o2                     /* IEU0                         */
122         andcc           %o2, 0xff, %g0                  /* IEU1         Group           */
123         be,pn           %icc, 23f                       /* CTI                          */
124          xor            %o3, %o4, %o3                   /* IEU0                         */
125         andcc           %g3, 0xff, %g0                  /* IEU1         Group           */
127         be,pn           %icc, 22f                       /* CTI                          */
128          sub            %o3, %g1, %o2                   /* IEU0                         */
129         ldxa            [%o0] ASI_PNF, %o3              /* Load                         */
130         andcc           %o2, %g2, %g0                   /* IEU1         Group           */
132         be,pt           %xcc, 19b                       /* CTI                          */
133          add            %o0, 8, %o0                     /* IEU0                         */
134         addcc           %o2, %g1, %g3                   /* IEU1         Group           */
135         ba,pt           %xcc, 20b                       /* CTI                          */
137          srlx           %o2, 32, %o2                    /* IEU0                         */
139         .align          16
140 22:     retl                                            /* CTI+IEU1     Group           */
141          add            %o0, -9, %o0                    /* IEU0                         */
142 23:     retl                                            /* CTI+IEU1     Group           */
143          add            %o0, -10, %o0                   /* IEU0                         */
145 24:     retl                                            /* CTI+IEU1     Group           */
146          add            %o0, -11, %o0                   /* IEU0                         */
147 25:     retl                                            /* CTI+IEU1     Group           */
148          add            %o0, -12, %o0                   /* IEU0                         */
150 26:     retl                                            /* CTI+IEU1     Group           */
151          add            %o0, -13, %o0                   /* IEU0                         */
152 27:     retl                                            /* CTI+IEU1     Group           */
153          add            %o0, -14, %o0                   /* IEU0                         */
155 28:     retl                                            /* CTI+IEU1     Group           */
156          add            %o0, -15, %o0                   /* IEU0                         */
157 29:     retl                                            /* CTI+IEU1     Group           */
158          add            %o0, -16, %o0                   /* IEU0                         */
160 30:     retl                                            /* CTI+IEU1     Group           */
161          nop                                            /* IEU0                         */
163         .align          16
164 32:     andcc           %o0, 7, %g0                     /* IEU1         Group           */
165         be,a,pn         %icc, 18b                       /* CTI                          */
166          sllx           %g1, 7, %g2                     /* IEU0                         */
167         add             %o0, 1, %o0                     /* IEU0         Group           */
169         cmp             %o3, %o1                        /* IEU1                         */
170         bne,a,pt        %icc, 32b                       /* CTI                          */
171          lduba          [%o0] ASI_PNF, %o3              /* Load                         */
172         retl                                            /* CTI+IEU1     Group           */
174          add            %o0, -1, %o0                    /* IEU0                         */
175 END(__rawmemchr)
177 libc_hidden_def (__rawmemchr)
178 weak_alias (__rawmemchr, rawmemchr)