Remove powerpc64 bounded-pointers code.
[glibc.git] / sysdeps / powerpc / powerpc64 / strchr.S
blobd2d8cd361a09cc949a5f5b9d8e9bb932b7c509f1
1 /* Optimized strchr implementation for PowerPC64.
2    Copyright (C) 1997-2013 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, see
17    <http://www.gnu.org/licenses/>.  */
19 #include <sysdep.h>
21 /* See strlen.s for comments on how this works.  */
23 /* char * [r3] strchr (const char *s [r3] , int c [r4] )  */
25 ENTRY (strchr)
26         CALL_MCOUNT 2
28 #define rTMP1   r0
29 #define rRTN    r3      /* outgoing result */
30 #define rSTR    r8      /* current word pointer */
31 #define rCHR    r4      /* byte we're looking for, spread over the whole word */
32 #define rWORD   r5      /* the current word */
33 #define rCLZB   rCHR    /* leading zero byte count */
34 #define rFEFE   r6      /* constant 0xfefefefefefefeff (-0x0101010101010101) */
35 #define r7F7F   r7      /* constant 0x7f7f7f7f7f7f7f7f */
36 #define rTMP2   r9
37 #define rIGN    r10     /* number of bits we should ignore in the first word */
38 #define rMASK   r11     /* mask with the bits to ignore set to 0 */
39 #define rTMP3   r12
41         dcbt    0,rRTN
42         rlwimi  rCHR, rCHR, 8, 16, 23
43         li      rMASK, -1
44         rlwimi  rCHR, rCHR, 16, 0, 15
45         rlwinm  rIGN, rRTN, 3, 26, 28
46         insrdi  rCHR, rCHR, 32, 0
47         lis     rFEFE, -0x101
48         lis     r7F7F, 0x7f7f
49         clrrdi  rSTR, rRTN, 3
50         addi    rFEFE, rFEFE, -0x101
51         addi    r7F7F, r7F7F, 0x7f7f
52         sldi    rTMP1, rFEFE, 32
53         insrdi  r7F7F, r7F7F, 32, 0
54         add     rFEFE, rFEFE, rTMP1
55 /* Test the first (partial?) word.  */
56         ld      rWORD, 0(rSTR)
57         srd     rMASK, rMASK, rIGN
58         orc     rWORD, rWORD, rMASK
59         add     rTMP1, rFEFE, rWORD
60         nor     rTMP2, r7F7F, rWORD
61         and.    rTMP1, rTMP1, rTMP2
62         xor     rTMP3, rCHR, rWORD
63         orc     rTMP3, rTMP3, rMASK
64         b       L(loopentry)
66 /* The loop.  */
68 L(loop):ldu rWORD, 8(rSTR)
69         and.    rTMP1, rTMP1, rTMP2
70 /* Test for 0.  */
71         add     rTMP1, rFEFE, rWORD
72         nor     rTMP2, r7F7F, rWORD
73         bne     L(foundit)
74         and.    rTMP1, rTMP1, rTMP2
75 /* Start test for the bytes we're looking for.  */
76         xor     rTMP3, rCHR, rWORD
77 L(loopentry):
78         add     rTMP1, rFEFE, rTMP3
79         nor     rTMP2, r7F7F, rTMP3
80         beq     L(loop)
81 /* There is a zero byte in the word, but may also be a matching byte (either
82    before or after the zero byte).  In fact, we may be looking for a
83    zero byte, in which case we return a match.  We guess that this hasn't
84    happened, though.  */
85 L(missed):
86         and.    rTMP1, rTMP1, rTMP2
87         li      rRTN, 0
88         beqlr
89 /* It did happen. Decide which one was first...
90    I'm not sure if this is actually faster than a sequence of
91    rotates, compares, and branches (we use it anyway because it's shorter).  */
92         and     rFEFE, r7F7F, rWORD
93         or      rMASK, r7F7F, rWORD
94         and     rTMP1, r7F7F, rTMP3
95         or      rIGN, r7F7F, rTMP3
96         add     rFEFE, rFEFE, r7F7F
97         add     rTMP1, rTMP1, r7F7F
98         nor     rWORD, rMASK, rFEFE
99         nor     rTMP2, rIGN, rTMP1
100         cmpld   rWORD, rTMP2
101         bgtlr
102         cntlzd  rCLZB, rTMP2
103         srdi    rCLZB, rCLZB, 3
104         add     rRTN, rSTR, rCLZB
105         blr
107 L(foundit):
108         and     rTMP1, r7F7F, rTMP3
109         or      rIGN, r7F7F, rTMP3
110         add     rTMP1, rTMP1, r7F7F
111         nor     rTMP2, rIGN, rTMP1
112         cntlzd  rCLZB, rTMP2
113         subi    rSTR, rSTR, 8
114         srdi    rCLZB, rCLZB, 3
115         add     rRTN, rSTR, rCLZB
116         blr
117 END (strchr)
119 weak_alias (strchr, index)
120 libc_hidden_builtin_def (strchr)