Replace FSF snail mail address with URLs.
[glibc.git] / sysdeps / x86_64 / strnlen.S
blob7b38bf424044433da4e3e36f6d562af3c2faac31
1 /* strnlen(str,maxlen) -- determine the length of the string STR up to MAXLEN.
2    Copyright (C) 2010 Free Software Foundation, Inc.
3    Contributed by Ulrich Drepper <drepper@redhat.com>.
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/>.  */
20 #include <sysdep.h>
23         .text
24 ENTRY(__strnlen)
25         movq    %rsi, %rax
26         testq   %rsi, %rsi
27         jz      3f
28         pxor    %xmm2, %xmm2
29         movq    %rdi, %rcx
30         movq    %rdi, %r8
31         movq    $16, %r9
32         andq    $~15, %rdi
33         movdqa  %xmm2, %xmm1
34         pcmpeqb (%rdi), %xmm2
35         orl     $0xffffffff, %r10d
36         subq    %rdi, %rcx
37         shll    %cl, %r10d
38         subq    %rcx, %r9
39         pmovmskb %xmm2, %edx
40         andl    %r10d, %edx
41         jnz     1f
42         subq    %r9, %rsi
43         jbe     3f
45 2:      movdqa  16(%rdi), %xmm0
46         leaq    16(%rdi), %rdi
47         pcmpeqb %xmm1, %xmm0
48         pmovmskb %xmm0, %edx
49         testl   %edx, %edx
50         jnz     1f
51         subq    $16, %rsi
52         jnbe    2b
53 3:      ret
55 1:      subq    %r8, %rdi
56         bsfl    %edx, %edx
57         addq    %rdi, %rdx
58         cmpq    %rdx, %rax
59         cmovnbq %rdx, %rax
60         ret
61 END(__strnlen)
62 weak_alias (__strnlen, strnlen)
63 libc_hidden_def (strnlen)