]>
Commit | Line | Data |
---|---|---|
8f5ca04b RM |
1 | /* strcspn (str, ss) -- Return the length of the initial segement of STR |
2 | which contains no characters from SS. | |
5929563f | 3 | For Intel 80x86, x>=3. |
568035b7 | 4 | Copyright (C) 1994-2013 Free Software Foundation, Inc. |
5929563f UD |
5 | Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu> |
6 | Bug fixes by Alan Modra <Alan@SPRI.Levels.UniSA.Edu.Au> | |
7 | This file is part of the GNU C Library. | |
8 | ||
9 | The GNU C Library is free software; you can redistribute it and/or | |
41bdb6e2 AJ |
10 | modify it under the terms of the GNU Lesser General Public |
11 | License as published by the Free Software Foundation; either | |
12 | version 2.1 of the License, or (at your option) any later version. | |
5929563f UD |
13 | |
14 | The GNU C Library is distributed in the hope that it will be useful, | |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
41bdb6e2 | 17 | Lesser General Public License for more details. |
5929563f | 18 | |
41bdb6e2 | 19 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 PE |
20 | License along with the GNU C Library; if not, see |
21 | <http://www.gnu.org/licenses/>. */ | |
8f5ca04b RM |
22 | |
23 | #include <sysdep.h> | |
24 | #include "asm-syntax.h" | |
25 | ||
2366713d | 26 | #define PARMS 4 /* no space for saved regs */ |
3f02f778 | 27 | #define RTN PARMS |
2366713d JM |
28 | #define STR RTN |
29 | #define STOP STR+4 | |
8f5ca04b RM |
30 | |
31 | .text | |
2366713d | 32 | ENTRY (strpbrk) |
3f02f778 GM |
33 | |
34 | movl STR(%esp), %edx | |
35 | movl STOP(%esp), %eax | |
8f5ca04b RM |
36 | |
37 | /* First we create a table with flags for all possible characters. | |
38 | For the ASCII (7bit/8bit) or ISO-8859-X character sets which are | |
39 | supported by the C string functions we have 256 characters. | |
40 | Before inserting marks for the stop characters we clear the whole | |
41 | table. The unrolled form is much faster than a loop. */ | |
42 | xorl %ecx, %ecx /* %ecx = 0 !!! */ | |
43 | ||
44 | pushl %ecx /* make a 256 bytes long block filled with 0 */ | |
1ad9da69 | 45 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 46 | pushl %ecx |
1ad9da69 | 47 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 48 | pushl %ecx |
1ad9da69 | 49 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 50 | pushl %ecx |
1ad9da69 | 51 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 52 | pushl %ecx |
1ad9da69 | 53 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 54 | pushl %ecx |
1ad9da69 | 55 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 56 | pushl %ecx |
1ad9da69 | 57 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 58 | pushl %ecx |
1ad9da69 | 59 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 60 | pushl %ecx |
1ad9da69 | 61 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 62 | pushl %ecx |
1ad9da69 | 63 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 64 | pushl %ecx |
1ad9da69 | 65 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 66 | pushl %ecx |
1ad9da69 | 67 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 68 | pushl %ecx |
1ad9da69 | 69 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 70 | pushl %ecx |
1ad9da69 | 71 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 72 | pushl %ecx |
1ad9da69 | 73 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 74 | pushl %ecx |
1ad9da69 | 75 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 76 | pushl %ecx |
1ad9da69 | 77 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 78 | pushl %ecx |
1ad9da69 | 79 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 80 | pushl %ecx |
1ad9da69 | 81 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 82 | pushl %ecx |
1ad9da69 | 83 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 84 | pushl %ecx |
1ad9da69 | 85 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 86 | pushl %ecx |
1ad9da69 | 87 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 88 | pushl %ecx |
1ad9da69 | 89 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 90 | pushl %ecx |
1ad9da69 | 91 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 92 | pushl %ecx |
1ad9da69 | 93 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 94 | pushl %ecx |
1ad9da69 | 95 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 96 | pushl %ecx |
1ad9da69 | 97 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 98 | pushl %ecx |
1ad9da69 | 99 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 100 | pushl %ecx |
1ad9da69 | 101 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 102 | pushl %ecx |
1ad9da69 | 103 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 104 | pushl %ecx |
1ad9da69 | 105 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 106 | pushl %ecx |
1ad9da69 | 107 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 108 | pushl %ecx |
1ad9da69 | 109 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 110 | pushl %ecx |
1ad9da69 | 111 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 112 | pushl %ecx |
1ad9da69 | 113 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 114 | pushl %ecx |
1ad9da69 | 115 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 116 | pushl %ecx |
1ad9da69 | 117 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 118 | pushl %ecx |
1ad9da69 | 119 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 120 | pushl %ecx |
1ad9da69 | 121 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 122 | pushl %ecx |
1ad9da69 | 123 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 124 | pushl %ecx |
1ad9da69 | 125 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 126 | pushl %ecx |
1ad9da69 | 127 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 128 | pushl %ecx |
1ad9da69 | 129 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 130 | pushl %ecx |
1ad9da69 | 131 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 132 | pushl %ecx |
1ad9da69 | 133 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 134 | pushl %ecx |
1ad9da69 | 135 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 136 | pushl %ecx |
1ad9da69 | 137 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 138 | pushl %ecx |
1ad9da69 | 139 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 140 | pushl %ecx |
1ad9da69 | 141 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 142 | pushl %ecx |
1ad9da69 | 143 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 144 | pushl %ecx |
1ad9da69 | 145 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 146 | pushl %ecx |
1ad9da69 | 147 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 148 | pushl %ecx |
1ad9da69 | 149 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 150 | pushl %ecx |
1ad9da69 | 151 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 152 | pushl %ecx |
1ad9da69 | 153 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 154 | pushl %ecx |
1ad9da69 | 155 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 156 | pushl %ecx |
1ad9da69 | 157 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 158 | pushl %ecx |
1ad9da69 | 159 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 160 | pushl $0 /* These immediate values make the label 2 */ |
1ad9da69 | 161 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 162 | pushl $0 /* to be aligned on a 16 byte boundary to */ |
1ad9da69 | 163 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 164 | pushl $0 /* get a better performance of the loop. */ |
1ad9da69 | 165 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 166 | pushl $0 |
1ad9da69 | 167 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 168 | pushl $0 |
1ad9da69 | 169 | cfi_adjust_cfa_offset (4) |
8f5ca04b | 170 | pushl $0 |
1ad9da69 | 171 | cfi_adjust_cfa_offset (4) |
8f5ca04b RM |
172 | |
173 | /* For understanding the following code remember that %ecx == 0 now. | |
174 | Although all the following instruction only modify %cl we always | |
175 | have a correct zero-extended 32-bit value in %ecx. */ | |
176 | ||
177 | /* Don't change the "testb $0xff,%%cl" to "testb %%cl,%%cl". We want | |
178 | longer instructions so that the next loop aligns without adding nops. */ | |
179 | ||
5929563f | 180 | L(2): movb (%eax), %cl /* get byte from stopset */ |
8f5ca04b | 181 | testb %cl, %cl /* is NUL char? */ |
5929563f | 182 | jz L(1) /* yes => start compare loop */ |
8f5ca04b RM |
183 | movb %cl, (%esp,%ecx) /* set corresponding byte in stopset table */ |
184 | ||
185 | movb 1(%eax), %cl /* get byte from stopset */ | |
186 | testb $0xff, %cl /* is NUL char? */ | |
5929563f | 187 | jz L(1) /* yes => start compare loop */ |
8f5ca04b RM |
188 | movb %cl, (%esp,%ecx) /* set corresponding byte in stopset table */ |
189 | ||
190 | movb 2(%eax), %cl /* get byte from stopset */ | |
191 | testb $0xff, %cl /* is NUL char? */ | |
5929563f | 192 | jz L(1) /* yes => start compare loop */ |
8f5ca04b RM |
193 | movb %cl, (%esp,%ecx) /* set corresponding byte in stopset table */ |
194 | ||
195 | movb 3(%eax), %cl /* get byte from stopset */ | |
196 | addl $4, %eax /* increment stopset pointer */ | |
197 | movb %cl, (%esp,%ecx) /* set corresponding byte in stopset table */ | |
198 | testb $0xff, %cl /* is NUL char? */ | |
5929563f | 199 | jnz L(2) /* no => process next dword from stopset */ |
8f5ca04b | 200 | |
5929563f | 201 | L(1): leal -4(%edx), %eax /* prepare loop */ |
8f5ca04b RM |
202 | |
203 | /* We use a neat trick for the following loop. Normally we would | |
204 | have to test for two termination conditions | |
205 | 1. a character in the stopset was found | |
206 | and | |
207 | 2. the end of the string was found | |
382466e0 | 208 | But as a sign that the character is in the stopset we store its |
8f5ca04b RM |
209 | value in the table. But the value of NUL is NUL so the loop |
210 | terminates for NUL in every case. */ | |
211 | ||
5929563f | 212 | L(3): addl $4, %eax /* adjust pointer for full loop round */ |
8f5ca04b RM |
213 | |
214 | movb (%eax), %cl /* get byte from string */ | |
215 | cmpb %cl, (%esp,%ecx) /* is it contained in stopset? */ | |
5929563f | 216 | je L(4) /* yes => return */ |
8f5ca04b RM |
217 | |
218 | movb 1(%eax), %cl /* get byte from string */ | |
219 | cmpb %cl, (%esp,%ecx) /* is it contained in stopset? */ | |
5929563f | 220 | je L(5) /* yes => return */ |
8f5ca04b RM |
221 | |
222 | movb 2(%eax), %cl /* get byte from string */ | |
223 | cmpb %cl, (%esp,%ecx) /* is it contained in stopset? */ | |
5929563f | 224 | je L(6) /* yes => return */ |
8f5ca04b RM |
225 | |
226 | movb 3(%eax), %cl /* get byte from string */ | |
227 | cmpb %cl, (%esp,%ecx) /* is it contained in stopset? */ | |
5929563f | 228 | jne L(3) /* yes => return */ |
8f5ca04b RM |
229 | |
230 | incl %eax /* adjust pointer */ | |
5929563f UD |
231 | L(6): incl %eax |
232 | L(5): incl %eax | |
8f5ca04b | 233 | |
5929563f | 234 | L(4): addl $256, %esp /* remove stopset */ |
1ad9da69 | 235 | cfi_adjust_cfa_offset (-256) |
8f5ca04b RM |
236 | |
237 | orb %cl, %cl /* was last character NUL? */ | |
2fc08826 GM |
238 | jnz L(7) /* no => return pointer */ |
239 | xorl %eax, %eax | |
8f5ca04b | 240 | |
2366713d JM |
241 | L(7): ret |
242 | END (strpbrk) | |
85dd1003 | 243 | libc_hidden_builtin_def (strpbrk) |