]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/powerpc/powerpc64/strcspn.S
4ebc2532bd0804ca9d6b4fe72550b5923c2b58cc
[thirdparty/glibc.git] / sysdeps / powerpc / powerpc64 / strcspn.S
1 /* Optimized strcspn implementation for PowerPC64.
2 Copyright (C) 2014-2015 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
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.
9
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.
14
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/>. */
18
19 #include <sysdep.h>
20
21 /* size_t [r3] strcspn (const char [r4] *s, const char [r5] *reject) */
22
23 EALIGN (strcspn, 4, 0)
24 CALL_MCOUNT 3
25
26 /* The idea to speed up the algorithm is to create a lookup table
27 for fast check if input character should be considered. For ASCII
28 or ISO-8859-X character sets it has 256 positions. */
29
30 /* PPC64 ELF ABI stack is aligned to 16 bytes. */
31 addi r9,r1,-256
32 /* Clear the table with 0 values */
33 li r6, 0
34 li r8, 4
35 mtctr r8
36 mr r10, r9
37 .align 4
38 L(zerohash):
39 std r6, 0(r10)
40 std r6, 8(r10)
41 std r6, 16(r10)
42 std r6, 24(r10)
43 std r6, 32(r10)
44 std r6, 40(r10)
45 std r6, 48(r10)
46 std r6, 56(r10)
47 addi r10, r10, 64
48 bdnz L(zerohash)
49
50 lbz r10,0(r4)
51 cmpdi cr7,r10,0 /* reject[0] == '\0' ? */
52 li r8,1
53 beq cr7,L(finish_table) /* If reject[0] == '\0' skip */
54
55 /* Initialize the table as:
56 for (i=0; reject[i]; i++
57 table[reject[i]]] = 1 */
58 .align 4
59 L(init_table):
60 stbx r8,r9,r10
61 lbzu r10,1(r4)
62 cmpdi cr7,r10,0 /* If reject[0] == '\0' finish */
63 bne cr7,L(init_table)
64 L(finish_table):
65 /* set table[0] = 1 */
66 li r10,1
67 stb r10,0(r9)
68 li r10,0
69 b L(mainloop)
70
71 /* Unrool the loop 4 times and check using the table as:
72 i = 0;
73 while (1)
74 {
75 if (table[input[i++]] == 1)
76 return i - 1;
77 if (table[input[i++]] == 1)
78 return i - 1;
79 if (table[input[i++]] == 1)
80 return i - 1;
81 if (table[input[i++]] == 1)
82 return i - 1;
83 } */
84 .align 4
85 L(unroll):
86 lbz r8,1(r3)
87 addi r10,r10,4
88 lbzx r8,r9,r8
89 cmpwi r7,r8,1
90 beq cr7,L(end)
91 lbz r8,2(r3)
92 addi r3,r3,4
93 lbzx r8,r9,r8
94 cmpwi cr7,r8,1
95 beq cr7,L(end2)
96 lbz r8,3(r7)
97 lbzx r8,r9,r8
98 cmpwi cr7,r8,1
99 beq cr7,L(end3)
100 L(mainloop):
101 lbz r8,0(r3)
102 mr r7,r3
103 addi r6,r10,1
104 addi r4,r10,2
105 addi r5,r10,3
106 lbzx r8,r9,8
107 cmpwi cr7,r8,1
108 bne cr7,L(unroll)
109 mr r3,r10
110 blr
111
112 .align 4
113 L(end):
114 mr r3,r6
115 blr
116
117 .align 4
118 L(end2):
119 mr r3,r4
120 blr
121
122 .align 4
123 L(end3):
124 mr r3,r5
125 blr
126 END (strcspn)
127 libc_hidden_builtin_def (strcspn)