Sort sysdeps/powerpc/fpu/libm-test-ulps
[glibc.git] / sysdeps / x86_64 / strrchr.S
bloba5397e70f5aca44b093aee7b250a9c162b308334
1 /* strrchr (str, ch) -- Return pointer to last occurrence of CH in STR.
2    For AMD x86-64.
3    Copyright (C) 2009 Free Software Foundation, Inc.
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 (strrchr)
25         movd    %esi, %xmm1
26         movq    %rdi, %rcx
27         punpcklbw %xmm1, %xmm1
28         andq    $~15, %rdi
29         pxor    %xmm2, %xmm2
30         punpcklbw %xmm1, %xmm1
31         orl     $0xffffffff, %esi
32         movdqa  (%rdi), %xmm0
33         pshufd  $0, %xmm1, %xmm1
34         subq    %rdi, %rcx
35         movdqa  %xmm0, %xmm3
36         leaq    16(%rdi), %rdi
37         pcmpeqb %xmm1, %xmm0
38         pcmpeqb %xmm2, %xmm3
39         shl     %cl, %esi
40         pmovmskb %xmm0, %edx
41         pmovmskb %xmm3, %ecx
42         andl    %esi, %edx
43         andl    %esi, %ecx
44         xorl    %eax, %eax
45         movl    %edx, %esi
46         orl     %ecx, %esi
47         jnz     1f
49 2:      movdqa  (%rdi), %xmm0
50         leaq    16(%rdi), %rdi
51         movdqa  %xmm0, %xmm3
52         pcmpeqb %xmm1, %xmm0
53         pcmpeqb %xmm2, %xmm3
54         pmovmskb %xmm0, %edx
55         pmovmskb %xmm3, %ecx
56         movl    %edx, %esi
57         orl     %ecx, %esi
58         jz      2b
60 1:      bsfl    %ecx, %r9d
61         movl    $0xffffffff, %r8d
62         movl    $31, %ecx
63         jnz     5f
65         bsrl    %edx, %edx
66         jz      2b
67         leaq    -16(%rdi,%rdx), %rax
68         jmp     2b
70 5:      subl    %r9d, %ecx
71         shrl    %cl, %r8d
72         andl    %r8d, %edx
73         bsrl    %edx, %edx
74         jz      4f
75         leaq    -16(%rdi,%rdx), %rax
76 4:      ret
77 END (strrchr)
79 weak_alias (strrchr, rindex)
80 libc_hidden_builtin_def (strrchr)