]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/x86_64/strlen.S
28f828780e9b6449aa1ac077c53586ab0ec5e50d
[thirdparty/glibc.git] / sysdeps / x86_64 / strlen.S
1 /* strlen(str) -- determine the length of the string STR.
2 Copyright (C) 2009, 2010 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(strlen)
26 xor %rax, %rax
27 mov %edi, %ecx
28 and $0x3f, %ecx
29 pxor %xmm0, %xmm0
30 cmp $0x30, %ecx
31 ja L(next)
32 movdqu (%rdi), %xmm1
33 pcmpeqb %xmm1, %xmm0
34 pmovmskb %xmm0, %edx
35 test %edx, %edx
36 jnz L(exit_less16)
37 mov %rdi, %rax
38 and $-16, %rax
39 jmp L(align16_start)
40 L(next):
41 mov %rdi, %rax
42 and $-16, %rax
43 pcmpeqb (%rax), %xmm0
44 mov $-1, %esi
45 sub %rax, %rcx
46 shl %cl, %esi
47 pmovmskb %xmm0, %edx
48 and %esi, %edx
49 jnz L(exit)
50 L(align16_start):
51 pxor %xmm0, %xmm0
52 pxor %xmm1, %xmm1
53 pxor %xmm2, %xmm2
54 pxor %xmm3, %xmm3
55 .p2align 4
56 L(align16_loop):
57 pcmpeqb 16(%rax), %xmm0
58 pmovmskb %xmm0, %edx
59 test %edx, %edx
60 jnz L(exit16)
61
62 pcmpeqb 32(%rax), %xmm1
63 pmovmskb %xmm1, %edx
64 test %edx, %edx
65 jnz L(exit32)
66
67 pcmpeqb 48(%rax), %xmm2
68 pmovmskb %xmm2, %edx
69 test %edx, %edx
70 jnz L(exit48)
71
72 pcmpeqb 64(%rax), %xmm3
73 pmovmskb %xmm3, %edx
74 lea 64(%rax), %rax
75 test %edx, %edx
76 jz L(align16_loop)
77 L(exit):
78 sub %rdi, %rax
79 L(exit_less16):
80 bsf %rdx, %rdx
81 add %rdx, %rax
82 ret
83 .p2align 4
84 L(exit16):
85 sub %rdi, %rax
86 bsf %rdx, %rdx
87 lea 16(%rdx,%rax), %rax
88 ret
89 .p2align 4
90 L(exit32):
91 sub %rdi, %rax
92 bsf %rdx, %rdx
93 lea 32(%rdx,%rax), %rax
94 ret
95 .p2align 4
96 L(exit48):
97 sub %rdi, %rax
98 bsf %rdx, %rdx
99 lea 48(%rdx,%rax), %rax
100 ret
101 END(strlen)
102 libc_hidden_builtin_def (strlen)