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 2005 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
31 mov
4(%esp
), %ecx
/ src string here
32 mov
8(%esp
), %edx
/ character to find
33 mov
%ecx
, %eax
/ save src
34 and $
3, %ecx
/ check if src is aligned
35 jz prepword
/ search wordwise if it is
37 cmpb
%dl
, (%eax
) / src
== char?
39 cmpb $
0, (%eax
) / src
== 0?
41 add $
1, %eax
/ increment src
42 cmp $
3, %ecx
/ check alignment
44 cmpb
%dl
, (%eax
) / src byte contains char?
46 cmpb $
0, (%eax
) / src byte
== 0?
48 add $
1, %eax
/ increment src ptr
49 cmp $
2, %ecx
/ check alignment
51 cmpb
%dl
, (%eax
) / check this byte
53 cmpb $
0, (%eax
) / is byte zero?
55 add $
1, %eax
/ increment src ptr
58 push
%ebx
/ save regs per calling convention
60 and $
0xff, %edx
/ only want
1st byte
61 mov
%edx
, %ebx
/ copy character across all bytes in wd
68 .align 16 / align loop for max performance
71 mov
(%eax
), %esi
/ load src word
72 add $
4, %eax
/ increment src by four
73 mov
%esi
, %ebx
/ copy word
74 lea
-0x01010101(%esi
), %ecx
/ (word
- 0x01010101)
75 xor %edx
, %ebx
/ tmpword
= word ^ char
77 and $
0x80808080, %esi
/ ~word
& 0x80808080
78 and %ecx
, %esi
/ (wd
- 0x01010101) & ~wd
& 0x80808080
80 lea
-0x01010101(%ebx
), %ecx
/ repeat with tmpword
84 jz searchchar
/ repeat if char
not found
87 add $
0x01010101, %ecx
/ restore tmpword
88 pop
%esi
/ restore esi ebx as per calling cvntn
90 test $
0x000000ff, %ecx
/ look for character
's position in word
92 test $0x0000ff00, %ecx
94 test $0x00ff0000, %ecx
109 add $0x01010101, %ecx / restore registers here
112 cmpb %dl, %cl / check for character
114 testb %cl, %cl / check for null byte
116 cmpb %dh, %ch / continue checking for char, null
120 shr $16, %ecx / put bytes 2,3 into 8-but registers
125 cmpb %dh, %ch / repeat checking last 2 bytes
129 sub $1, %eax / correct for last loop iteration