1 /* Optimized memchr with sse2
2 Copyright (C) 2011-2013 Free Software Foundation, Inc.
3 Contributed by Intel Corporation.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
24 # define CFI_PUSH(REG) \
25 cfi_adjust_cfa_offset (4); \
26 cfi_rel_offset (REG, 0)
28 # define CFI_POP(REG) \
29 cfi_adjust_cfa_offset (-4); \
32 # define PUSH(REG) pushl REG; CFI_PUSH (REG)
33 # define POP(REG) popl REG; CFI_POP (REG)
39 # ifndef USE_AS_RAWMEMCHR
41 # define RETURN POP(%edi); ret; CFI_PUSH(%edi);
45 # define MEMCHR __memchr_sse2_bsf
52 movd STR2(%esp), %xmm1
54 # ifndef USE_AS_RAWMEMCHR
61 punpcklbw %xmm1, %xmm1
62 punpcklbw %xmm1, %xmm1
65 pshufd $0, %xmm1, %xmm1
72 /* Check if there is a match. */
75 je L(unaligned_no_match_1)
76 /* Check which byte is a match. */
79 # ifndef USE_AS_RAWMEMCHR
87 L(unaligned_no_match_1):
88 # ifndef USE_AS_RAWMEMCHR
107 # ifndef USE_AS_RAWMEMCHR
113 /* Handle unaligned string. */
115 # ifndef USE_AS_RAWMEMCHR
128 /* Check if there is a match. */
130 /* Remove the leading bytes. */
133 je L(unaligned_no_match)
134 /* Check which byte is a match. */
137 # ifndef USE_AS_RAWMEMCHR
150 L(unaligned_no_match):
151 # ifndef USE_AS_RAWMEMCHR
161 /* Loop start on aligned string. */
163 # ifndef USE_AS_RAWMEMCHR
175 # ifndef USE_AS_RAWMEMCHR
176 movdqa 16(%edi), %xmm2
178 movdqa 16(%edx), %xmm2
185 # ifndef USE_AS_RAWMEMCHR
186 movdqa 32(%edi), %xmm3
188 movdqa 32(%edx), %xmm3
195 # ifndef USE_AS_RAWMEMCHR
196 movdqa 48(%edi), %xmm4
198 movdqa 48(%edx), %xmm4
202 # ifndef USE_AS_RAWMEMCHR
211 # ifndef USE_AS_RAWMEMCHR
218 # ifndef USE_AS_RAWMEMCHR
230 # ifndef USE_AS_RAWMEMCHR
231 movdqa 16(%edi), %xmm2
233 movdqa 16(%edx), %xmm2
240 # ifndef USE_AS_RAWMEMCHR
241 movdqa 32(%edi), %xmm3
243 movdqa 32(%edx), %xmm3
250 # ifndef USE_AS_RAWMEMCHR
251 movdqa 48(%edi), %xmm3
253 movdqa 48(%edx), %xmm3
258 # ifndef USE_AS_RAWMEMCHR
266 # ifndef USE_AS_RAWMEMCHR
277 # ifndef USE_AS_RAWMEMCHR
281 movdqa 16(%edi), %xmm2
282 movdqa 32(%edi), %xmm3
283 movdqa 48(%edi), %xmm4
286 movdqa 16(%edx), %xmm2
287 movdqa 32(%edx), %xmm3
288 movdqa 48(%edx), %xmm4
300 # ifndef USE_AS_RAWMEMCHR
309 # ifndef USE_AS_RAWMEMCHR
323 # ifndef USE_AS_RAWMEMCHR
324 movdqa 32(%edi), %xmm3
326 movdqa 32(%edx), %xmm3
331 # ifndef USE_AS_RAWMEMCHR
332 pcmpeqb 48(%edi), %xmm1
334 pcmpeqb 48(%edx), %xmm1
343 # ifndef USE_AS_RAWMEMCHR
344 lea 48(%edi, %eax), %eax
347 lea 48(%edx, %eax), %eax
351 # ifndef USE_AS_RAWMEMCHR
364 movdqa 16(%edi), %xmm2
370 movdqa 32(%edi), %xmm3
378 pcmpeqb 48(%edi), %xmm1
395 pcmpeqb 16(%edi), %xmm1
405 # ifndef USE_AS_RAWMEMCHR
406 lea -16(%eax, %edi), %eax
409 lea -16(%eax, %edx), %eax
416 # ifndef USE_AS_RAWMEMCHR
427 # ifndef USE_AS_RAWMEMCHR
428 lea 16(%eax, %edi), %eax
431 lea 16(%eax, %edx), %eax
438 # ifndef USE_AS_RAWMEMCHR
439 lea 32(%eax, %edi), %eax
442 lea 32(%eax, %edx), %eax
446 # ifndef USE_AS_RAWMEMCHR
463 lea 16(%edi, %eax), %eax
473 lea 32(%edi, %eax), %eax
483 lea 48(%edi, %eax), %eax
489 # ifndef USE_AS_RAWMEMCHR