usr/src/lib/libc/i386/gen/strchr.s
author Mark J. Nelson <Mark.J.Nelson@Sun.COM>
Wed, 06 Aug 2008 16:29:39 -0600
changeset 7298 b69e27387f74
parent 0 68f95e015346
permissions -rw-r--r--
6733918 Teamware has retired, please welcome your new manager, Mercurial 4758439 some files use "current date" sccs keywords 6560843 asm sources should not rely on .file "%M%" for naming STT_FILE symbols 6560958 Solaris:: perl modules should not use SCCS keywords in version information 6729074 webrev doesn't deal well with remote ssh hg parents
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     1
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     2
 * CDDL HEADER START
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     3
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     4
 * The contents of this file are subject to the terms of the
7298
b69e27387f74 6733918 Teamware has retired, please welcome your new manager, Mercurial
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents: 0
diff changeset
     5
 * Common Development and Distribution License (the "License").
b69e27387f74 6733918 Teamware has retired, please welcome your new manager, Mercurial
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents: 0
diff changeset
     6
 * You may not use this file except in compliance with the License.
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     7
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     8
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     9
 * or http://www.opensolaris.org/os/licensing.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    10
 * See the License for the specific language governing permissions
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    11
 * and limitations under the License.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    12
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    13
 * When distributing Covered Code, include this CDDL HEADER in each
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    14
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    15
 * If applicable, add the following below this CDDL HEADER, with the
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    16
 * fields enclosed by brackets "[]" replaced with your own identifying
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    17
 * information: Portions Copyright [yyyy] [name of copyright owner]
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    18
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    19
 * CDDL HEADER END
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    20
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    21
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    22
 * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    23
 * Use is subject to license terms.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    24
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    25
7298
b69e27387f74 6733918 Teamware has retired, please welcome your new manager, Mercurial
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents: 0
diff changeset
    26
	.file	"strchr.s"
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    27
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    28
#include "SYS.h"
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    29
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    30
	ENTRY(strchr)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    31
	mov 4(%esp), %ecx		/ src string here
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    32
	mov 8(%esp), %edx		/ character to find
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    33
	mov %ecx, %eax			/ save src
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    34
	and $3, %ecx			/ check if src is aligned
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    35
	jz prepword			/ search wordwise if it is
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    36
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    37
	cmpb %dl, (%eax)		/ src == char?
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    38
	jz done
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    39
	cmpb $0, (%eax)			/ src == 0?
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    40
	jz not_found
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    41
	add $1, %eax			/ increment src
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    42
	cmp $3, %ecx			/ check alignment
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    43
	jz prepword
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    44
	cmpb %dl, (%eax)		/ src byte contains char?
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    45
	jz done
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    46
	cmpb $0, (%eax)			/ src byte == 0?
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    47
	jz not_found
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    48
	add $1, %eax			/ increment src ptr
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    49
	cmp $2, %ecx			/ check alignment
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    50
	jz prepword
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    51
	cmpb %dl, (%eax) 		/ check this byte
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    52
	jz done
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    53
	cmpb $0, (%eax)			/ is byte zero?
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    54
	jz not_found
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    55
	add $1, %eax			/ increment src ptr
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    56
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    57
prepword:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    58
	push %ebx			/ save regs per calling convention
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    59
	push %esi
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    60
	and $0xff, %edx			/ only want 1st byte
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    61
	mov %edx, %ebx			/ copy character across all bytes in wd
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    62
	shl $8, %edx
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    63
	or %ebx, %edx
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    64
	mov %edx, %ebx
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    65
	shl $16, %edx
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    66
	or %ebx, %edx
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    67
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    68
	.align 16			/ align loop for max performance
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    69
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    70
searchchar:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    71
	mov (%eax), %esi		/ load src word
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    72
	add $4, %eax			/ increment src by four
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    73
	mov %esi, %ebx			/ copy word
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    74
	lea -0x01010101(%esi), %ecx	/ (word - 0x01010101)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    75
	xor %edx, %ebx			/ tmpword = word ^ char	
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    76
	not %esi			/ ~word
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    77
	and $0x80808080, %esi		/ ~word & 0x80808080
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    78
	and %ecx, %esi			/ (wd - 0x01010101) & ~wd & 0x80808080
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    79
	jnz has_zero_byte
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    80
	lea -0x01010101(%ebx), %ecx	/ repeat with tmpword
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    81
	not %ebx
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    82
	and $0x80808080, %ebx
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    83
	and %ecx, %ebx
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    84
	jz searchchar			/ repeat if char not found
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    85
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    86
found_char:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    87
	add $0x01010101, %ecx		/ restore tmpword
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    88
	pop %esi			/ restore esi ebx as per calling cvntn
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    89
	pop %ebx
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    90
	test $0x000000ff, %ecx		/ look for character's position in word
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    91
	jz done0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    92
	test $0x0000ff00, %ecx
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    93
	jz done1
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    94
	test $0x00ff0000, %ecx
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    95
	jz done2
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    96
done3:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    97
	sub $1, %eax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    98
	ret
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    99
done2:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   100
	sub $2, %eax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   101
	ret
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   102
done1:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   103
	sub $3, %eax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   104
	ret
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   105
done0:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   106
	sub $4, %eax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   107
	ret
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   108
has_zero_byte:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   109
	add $0x01010101, %ecx		/ restore registers here
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   110
	pop %esi
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   111
	pop %ebx
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   112
	cmpb %dl, %cl			/ check for character
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   113
	je done0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   114
	testb %cl, %cl			/ check for null byte
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   115
	jz not_found
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   116
	cmpb %dh, %ch			/ continue checking for char, null
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   117
	je done1
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   118
	testb %ch, %ch
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   119
	jz not_found
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   120
	shr $16, %ecx			/ put bytes 2,3 into 8-but registers
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   121
	cmpb %dl, %cl
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   122
	je done2
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   123
	testb %cl, %cl
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   124
	jz not_found
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   125
	cmpb %dh, %ch			/ repeat checking last 2 bytes
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   126
	je done3
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   127
	testb %ch, %ch
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   128
	jz not_found
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   129
	sub $1, %eax			/ correct for last loop iteration
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   130
done:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   131
	ret
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   132
not_found:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   133
	xor %eax, %eax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   134
	ret
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   135
	SET_SIZE(strchr)