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)
54 pushl %edi / save register variable
55 movl 8(%esp), %eax / %eax = string address
56 movb 12(%esp), %cl / %cl = char sought
57 movl $0, %edi / %edi = NULL (current occurrence)
59 testl $3, %eax / if %eax not word aligned
63 movl (%eax), %edx / move 1 word from (%eax) to %edx
64 cmpb %cl, %dl / if the fist byte is not %cl
66 movl %eax, %edi / save this address to %edi
68 cmpb $0, %dl / if a null termination
71 cmpb %cl, %dh / if the second byte is not %cl
73 leal 1(%eax), %edi / save this address to %edi
75 cmpb $0, %dh / if a null termination
78 shrl $16, %edx / right shift 16-bit
79 cmpb %cl, %dl / if the third byte is not %cl
81 leal 2(%eax), %edi / save this address to %edi
83 cmpb $0, %dl / if a null termination
86 cmpb %cl, %dh / if the fourth byte is not %cl
88 leal 3(%eax), %edi / save this address to %edi
90 cmpb $0, %dh / if a null termination
93 addl $4, %eax / next word
97 movb (%eax), %dl / move 1 byte from (%eax) to %dl
98 cmpb %cl, %dl / if %dl is not %cl
100 movl %eax, %edi / save this address to %edi
102 cmpb $0, %dl / if a null termination
105 incl %eax / next byte
106 testl $3, %eax / if %eax not word aligned
108 jmp .L3 / goto .L3 (word aligned)
111 movl %edi, %eax / %edi points to the last occurrence or NULL
112 popl %edi / restore register variable