4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
31 / Returns the pointer in sp at which the character c last
32 / appears; NULL if no found
34 / Fast assembly language version of the following C-program strrchr
35 / which represents the `standard
' for the C-library.
38 / strrchr(const char *sp, int c)
53 ENTRY(strrchr) /* (char *s, int c) */
54 movl $0, %eax / %rax = NULL (current occurrence)
55 movl %esi, %ecx / %cl == char to search for
56 testq $3, %rdi / if %rdi not word aligned
60 movl (%rdi), %edx / move 1 word from (%rdi) to %edx
61 cmpb %cl, %dl / if the fist byte is not %cl
63 movq %rdi, %rax / save this address to %rax
65 cmpb $0, %dl / if a null termination
68 cmpb %cl, %dh / if the second byte is not %cl
70 leaq 1(%rdi), %rax / save this address to %rax
72 cmpb $0, %dh / if a null termination
75 shrl $16, %edx / right shift 16-bit
76 cmpb %cl, %dl / if the third byte is not %cl
78 leaq 2(%rdi), %rax / save this address to %rax
80 cmpb $0, %dl / if a null termination
83 cmpb %cl, %dh / if the fourth byte is not %cl
85 leaq 3(%rdi), %rax / save this address to %rax
87 cmpb $0, %dh / if a null termination
90 addq $4, %rdi / next word
94 movb (%rdi), %dl / move 1 byte from (%rdi) to %dl
95 cmpb %cl, %dl / if %dl is not %cl
97 movq %rdi, %rax / save this address to %rax
99 cmpb $0, %dl / if a null termination
102 incq %rdi / next byte
103 testq $3, %rdi / if %rdi not word aligned
105 jmp .L3 / goto .L3 (word aligned)
108 ret / %rax points to the last occurrence or NULL