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 sptr at which the character c1 appears;
32 / or NULL if
not found in chars; doesn
't stop at \0.
34 / Fast assembly language version of the following C-program memchr
35 / which represents the `standard' for the C-library.
38 / memchr
(const void
*sptr
, int c1
, size_t n
)
41 / unsigned char c
= (unsigned char
)c1;
42 / const unsigned char
*sp
= sptr;
46 / return
((void
*)--sp
);
58 ENTRY
(memchr
) /* (void *s, uchar_t c, size_t n) */
59 movl
%esi
, %eax
/ move
"c" to
%eax
60 cmpq $
4, %rdx
/ if number of bytes
< 4
62 testq $
3, %rdi
/ if
%rdi
not word aligned
66 movl
(%rdi
), %ecx
/ move
1 word from
(%rdi
) to
%ecx
67 cmpb
%cl
, %al
/ if the first byte is
%al
68 je
.L4 / goto .L4 (found)
69 cmpb
%ch
, %al
/ if the second byte is
%al
70 je
.L5 / goto .L5 (found)
71 shrl $
16, %ecx
/ right shift
16-bit
72 cmpb
%cl
, %al
/ if the third byte is
%al
73 je
.L6 / goto .L6 (found)
74 cmpb
%ch
, %al
/ if the fourth is
%al
75 je
.L7 / goto .L7 (found)
76 subq $
4, %rdx
/ decrement number of bytes by
4
77 addq $
4, %rdi
/ next word
78 cmpq $
4, %rdx
/ if number of bytes
>= 4
81 cmpq $
0, %rdx
/ if number of bytes
== 0
82 jz
.L8 / goto .L8 (not found)
83 cmpb
(%rdi
), %al
/ if
a byte in
(%rdi
) is
%al
84 je
.L4 / goto .L4 (found)
85 decq
%rdx
/ decrement number of bytes by
1
90 xorl
%eax
, %eax
/ not found
94 cmpq $
0, %rdx
/ if number of bytes
== 0
95 jz
.L8 / goto .L8 (not found)
96 cmpb
(%rdi
), %al
/ if
a byte in
(%rdi
) is
%al
97 je
.L4 / goto .L4 (found)
99 decq
%rdx
/ decrement number of bytes by
1
100 testq $
3, %rdi
/ if
%rdi
not word aligned
102 cmpq $
4, %rdx
/ if number of bytes
>= 4
103 jae
.L3 / goto .L3 (word aligned)
107 / found at the fourth byte
110 / found at the third byte
113 / found at the second byte
116 / found at the first byte