]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/x86_64/strlen.S
Replace FSF snail mail address with URLs.
[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, see
18 <http://www.gnu.org/licenses/>. */
19
20 #include <sysdep.h>
21
22
23 .text
24 ENTRY(strlen)
25 xor %rax, %rax
26 mov %edi, %ecx
27 and $0x3f, %ecx
28 pxor %xmm0, %xmm0
29 cmp $0x30, %ecx
30 ja L(next)
31 movdqu (%rdi), %xmm1
32 pcmpeqb %xmm1, %xmm0
33 pmovmskb %xmm0, %edx
34 test %edx, %edx
35 jnz L(exit_less16)
36 mov %rdi, %rax
37 and $-16, %rax
38 jmp L(align16_start)
39 L(next):
40 mov %rdi, %rax
41 and $-16, %rax
42 pcmpeqb (%rax), %xmm0
43 mov $-1, %esi
44 sub %rax, %rcx
45 shl %cl, %esi
46 pmovmskb %xmm0, %edx
47 and %esi, %edx
48 jnz L(exit)
49 L(align16_start):
50 pxor %xmm0, %xmm0
51 pxor %xmm1, %xmm1
52 pxor %xmm2, %xmm2
53 pxor %xmm3, %xmm3
54 .p2align 4
55 L(align16_loop):
56 pcmpeqb 16(%rax), %xmm0
57 pmovmskb %xmm0, %edx
58 test %edx, %edx
59 jnz L(exit16)
60
61 pcmpeqb 32(%rax), %xmm1
62 pmovmskb %xmm1, %edx
63 test %edx, %edx
64 jnz L(exit32)
65
66 pcmpeqb 48(%rax), %xmm2
67 pmovmskb %xmm2, %edx
68 test %edx, %edx
69 jnz L(exit48)
70
71 pcmpeqb 64(%rax), %xmm3
72 pmovmskb %xmm3, %edx
73 lea 64(%rax), %rax
74 test %edx, %edx
75 jz L(align16_loop)
76 L(exit):
77 sub %rdi, %rax
78 L(exit_less16):
79 bsf %rdx, %rdx
80 add %rdx, %rax
81 ret
82 .p2align 4
83 L(exit16):
84 sub %rdi, %rax
85 bsf %rdx, %rdx
86 lea 16(%rdx,%rax), %rax
87 ret
88 .p2align 4
89 L(exit32):
90 sub %rdi, %rax
91 bsf %rdx, %rdx
92 lea 32(%rdx,%rax), %rax
93 ret
94 .p2align 4
95 L(exit48):
96 sub %rdi, %rax
97 bsf %rdx, %rdx
98 lea 48(%rdx,%rax), %rax
99 ret
100 END(strlen)
101 libc_hidden_builtin_def (strlen)