]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/x86_64/memchr.S
* sysdeps/x86_64/memchr.S: New file.
[thirdparty/glibc.git] / sysdeps / x86_64 / memchr.S
1 /* strlen(str) -- determine the length of the string STR.
2 Copyright (C) 2009 Free Software Foundation, Inc.
3 Contributed by Ulrich Drepper <drepper@redhat.com>.
4 This file is part of the GNU C Library.
5
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.
10
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.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
20
21 #include <sysdep.h>
22
23
24 .text
25 ENTRY (memchr)
26 movd %esi, %xmm1
27 movq %rdi, %rcx
28 punpcklbw %xmm1, %xmm1
29 andq $~15, %rdi
30 punpcklbw %xmm1, %xmm1
31 orl $0xffffffff, %esi
32 movdqa (%rdi), %xmm0
33 pshufd $0, %xmm1, %xmm1
34 subq %rdi, %rcx
35 pcmpeqb %xmm1, %xmm0
36 addq %rcx, %rdx
37 shl %cl, %esi
38 pmovmskb %xmm0, %ecx
39 andl %esi, %ecx
40 movl $0, %esi
41 jnz 1f
42 cmpq %rsi, %rdx
43 jle 3f
44
45 2: movdqa 16(%rdi,%rsi), %xmm0
46 leaq 16(%rsi), %rsi
47 pcmpeqb %xmm1, %xmm0
48 pmovmskb %xmm0, %ecx
49 testl %ecx, %ecx
50 jnz 1f
51 cmpq %rsi, %rdx
52 jg 2b
53
54 3: xorl %eax, %eax
55 ret
56
57 1: leaq (%rdi,%rsi), %rax
58 bsfl %ecx, %ecx
59 addq %rcx, %rax
60 addq %rcx, %rsi
61 cmpq %rsi, %rdx
62 jle 3b
63 ret
64 END (memchr)
65
66 strong_alias (memchr, __memchr)
67 libc_hidden_builtin_def (memchr)