1 /* rawmemchr optimized with SSE2.
2 Copyright (C) 2017-2024 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 <https://www.gnu.org/licenses/>. */
19 #include <isa-level.h>
22 /* MINIMUM_X86_ISA_LEVEL <= 2 because there is no V2 implementation
23 so we need this to build for ISA V2 builds. */
24 #if ISA_SHOULD_BUILD (2)
27 # define RAWMEMCHR __rawmemchr_sse2
35 punpcklbw %xmm1, %xmm1
36 punpcklbw %xmm1, %xmm1
39 pshufd $0, %xmm1, %xmm1
46 /* Check if there is a match. */
62 /* Check if there is a match. */
64 /* Remove the leading bytes. */
67 je L(unaligned_no_match)
68 /* Check which byte is a match. */
76 L(unaligned_no_match):
87 movdqa 16(%rdi), %xmm2
93 movdqa 32(%rdi), %xmm3
99 movdqa 48(%rdi), %xmm4
115 movdqa 16(%rdi), %xmm2
121 movdqa 32(%rdi), %xmm3
127 movdqa 48(%rdi), %xmm3
140 movdqa 16(%rdi), %xmm2
141 movdqa 32(%rdi), %xmm3
142 movdqa 48(%rdi), %xmm4
169 movdqa 32(%rdi), %xmm3
172 pcmpeqb 48(%rdi), %xmm1
179 lea 48(%rdi, %rax), %rax
185 lea -16(%rax, %rdi), %rax
197 lea 16(%rax, %rdi), %rax
203 lea 32(%rax, %rdi), %rax