1112129Stjr/*-
2112129Stjr * Copyright (c) 2003 Tim J. Robbins.
3112129Stjr * All rights reserved.
4112129Stjr *
5112129Stjr * Redistribution and use in source and binary forms, with or without
6112129Stjr * modification, are permitted provided that the following conditions
7112129Stjr * are met:
8112129Stjr * 1. Redistributions of source code must retain the above copyright
9112129Stjr *    notice, this list of conditions and the following disclaimer.
10112129Stjr * 2. Redistributions in binary form must reproduce the above copyright
11112129Stjr *    notice, this list of conditions and the following disclaimer in the
12112129Stjr *    documentation and/or other materials provided with the distribution.
13112129Stjr *
14112129Stjr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15112129Stjr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16112129Stjr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17112129Stjr * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18112129Stjr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19112129Stjr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20112129Stjr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21112129Stjr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22112129Stjr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23112129Stjr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24112129Stjr * SUCH DAMAGE.
25112129Stjr */
26112129Stjr
27112129Stjr#include <machine/asm.h>
28112129Stjr__FBSDID("$FreeBSD$");
29112129Stjr
30112129Stjr/*
31112129Stjr * wchar_t *
32112129Stjr * wmemchr(const wchar_t *buf, wchar_t c, size_t n) --
33112129Stjr *	Search the wide character array `buf', which has length `n',
34112129Stjr *	the character `c', return a pointer to it if found, or NULL on
35112129Stjr *	failure.
36112129Stjr */
37112129StjrENTRY(wmemchr)
38112129Stjr	pushl	%edi
39112129Stjr	pushl	%ebx
40112129Stjr	movl	12(%esp),%edi		/* Buffer */
41112129Stjr	movl	16(%esp),%eax		/* Wide character */
42112129Stjr	movl	20(%esp),%ecx		/* Length of buffer */
43112129Stjr
44112129Stjr	/*
45112129Stjr	 * Search in chunks of 8 wide characters (32 bytes).
46112129Stjr	 */
47112129Stjr	movl	%ecx,%ebx
48112129Stjr	shrl	$3,%ecx
49112129Stjr	jz	small
50112129Stjr.p2align 4,0x90
51112129Stjrbigloop:cmpl	%eax,(%edi)
52112129Stjr	je	found
53112129Stjr	cmpl	%eax,4(%edi)
54112129Stjr	je	found4
55112129Stjr	cmpl	%eax,8(%edi)
56112129Stjr	je	found8
57112129Stjr	cmpl	%eax,12(%edi)
58112129Stjr	je	found12
59112129Stjr	cmpl	%eax,16(%edi)
60112129Stjr	je	found16
61112129Stjr	cmpl	%eax,20(%edi)
62112129Stjr	je	found20
63112129Stjr	cmpl	%eax,24(%edi)
64112129Stjr	je	found24
65112129Stjr	cmpl	%eax,28(%edi)
66112129Stjr	je	found28
67112129Stjr	leal	32(%edi),%edi
68112129Stjr	decl	%ecx
69112129Stjr	jnz	bigloop
70112129Stjr	jmp	small
71112129Stjrfound:	movl	%edi,%eax
72112129Stjr	popl	%ebx
73112129Stjr	popl	%edi
74112129Stjr	ret
75112129Stjrfound4:	leal	4(%edi),%edi
76112129Stjr	jmp	found
77112129Stjrfound8:	leal	8(%edi),%edi
78112129Stjr	jmp	found
79112129Stjrfound12:leal	12(%edi),%edi
80112129Stjr	jmp	found
81112129Stjrfound16:leal	16(%edi),%edi
82112129Stjr	jmp	found
83112129Stjrfound20:leal	20(%edi),%edi
84112129Stjr	jmp	found
85112129Stjrfound24:leal	24(%edi),%edi
86112129Stjr	jmp	found
87112129Stjrfound28:leal	28(%edi),%edi
88112129Stjr	jmp	found
89112129Stjr
90112129Stjr	/*
91112129Stjr	 * Search remaining part of string.
92112129Stjr	 */
93112129Stjrsmall:	movl	%ebx,%ecx
94112129Stjr	andl	$7,%ecx
95112129Stjr	jz	no
96112132Stjr.p2align 2,0x90
97112129Stjrsmltop:	cmpl	%eax,(%edi)
98112129Stjr	je	found
99112129Stjr	leal	4(%edi),%edi
100112129Stjr	decl	%ecx
101112129Stjr	jnz	smltop
102112129Stjrno:	xorl	%eax,%eax
103112129Stjr	popl	%ebx
104112129Stjr	popl	%edi
105112129Stjr	ret
106184548SpeterEND(wmemchr)
107217106Skib
108217106Skib	.section .note.GNU-stack,"",%progbits
109