xref: /freebsd/lib/libc/i386/string/wmemchr.S (revision 93ab75867017bed8892f9f3b1e1bbd6120d49fcd)
134d4e913STim J. Robbins/*-
234d4e913STim J. Robbins * Copyright (c) 2003 Tim J. Robbins.
334d4e913STim J. Robbins * All rights reserved.
434d4e913STim J. Robbins *
534d4e913STim J. Robbins * Redistribution and use in source and binary forms, with or without
634d4e913STim J. Robbins * modification, are permitted provided that the following conditions
734d4e913STim J. Robbins * are met:
834d4e913STim J. Robbins * 1. Redistributions of source code must retain the above copyright
934d4e913STim J. Robbins *    notice, this list of conditions and the following disclaimer.
1034d4e913STim J. Robbins * 2. Redistributions in binary form must reproduce the above copyright
1134d4e913STim J. Robbins *    notice, this list of conditions and the following disclaimer in the
1234d4e913STim J. Robbins *    documentation and/or other materials provided with the distribution.
1334d4e913STim J. Robbins *
1434d4e913STim J. Robbins * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1534d4e913STim J. Robbins * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1634d4e913STim J. Robbins * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1734d4e913STim J. Robbins * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1834d4e913STim J. Robbins * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1934d4e913STim J. Robbins * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2034d4e913STim J. Robbins * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2134d4e913STim J. Robbins * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2234d4e913STim J. Robbins * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2334d4e913STim J. Robbins * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2434d4e913STim J. Robbins * SUCH DAMAGE.
2534d4e913STim J. Robbins */
2634d4e913STim J. Robbins
2734d4e913STim J. Robbins#include <machine/asm.h>
2834d4e913STim J. Robbins__FBSDID("$FreeBSD$");
2934d4e913STim J. Robbins
3034d4e913STim J. Robbins/*
3134d4e913STim J. Robbins * wchar_t *
3234d4e913STim J. Robbins * wmemchr(const wchar_t *buf, wchar_t c, size_t n) --
3334d4e913STim J. Robbins *	Search the wide character array `buf', which has length `n',
3434d4e913STim J. Robbins *	the character `c', return a pointer to it if found, or NULL on
3534d4e913STim J. Robbins *	failure.
3634d4e913STim J. Robbins */
3734d4e913STim J. RobbinsENTRY(wmemchr)
3834d4e913STim J. Robbins	pushl	%edi
3934d4e913STim J. Robbins	pushl	%ebx
4034d4e913STim J. Robbins	movl	12(%esp),%edi		/* Buffer */
4134d4e913STim J. Robbins	movl	16(%esp),%eax		/* Wide character */
4234d4e913STim J. Robbins	movl	20(%esp),%ecx		/* Length of buffer */
4334d4e913STim J. Robbins
4434d4e913STim J. Robbins	/*
4534d4e913STim J. Robbins	 * Search in chunks of 8 wide characters (32 bytes).
4634d4e913STim J. Robbins	 */
4734d4e913STim J. Robbins	movl	%ecx,%ebx
4834d4e913STim J. Robbins	shrl	$3,%ecx
4934d4e913STim J. Robbins	jz	small
5034d4e913STim J. Robbins.p2align 4,0x90
5134d4e913STim J. Robbinsbigloop:cmpl	%eax,(%edi)
5234d4e913STim J. Robbins	je	found
5334d4e913STim J. Robbins	cmpl	%eax,4(%edi)
5434d4e913STim J. Robbins	je	found4
5534d4e913STim J. Robbins	cmpl	%eax,8(%edi)
5634d4e913STim J. Robbins	je	found8
5734d4e913STim J. Robbins	cmpl	%eax,12(%edi)
5834d4e913STim J. Robbins	je	found12
5934d4e913STim J. Robbins	cmpl	%eax,16(%edi)
6034d4e913STim J. Robbins	je	found16
6134d4e913STim J. Robbins	cmpl	%eax,20(%edi)
6234d4e913STim J. Robbins	je	found20
6334d4e913STim J. Robbins	cmpl	%eax,24(%edi)
6434d4e913STim J. Robbins	je	found24
6534d4e913STim J. Robbins	cmpl	%eax,28(%edi)
6634d4e913STim J. Robbins	je	found28
6734d4e913STim J. Robbins	leal	32(%edi),%edi
6834d4e913STim J. Robbins	decl	%ecx
6934d4e913STim J. Robbins	jnz	bigloop
7034d4e913STim J. Robbins	jmp	small
7134d4e913STim J. Robbinsfound:	movl	%edi,%eax
7234d4e913STim J. Robbins	popl	%ebx
7334d4e913STim J. Robbins	popl	%edi
7434d4e913STim J. Robbins	ret
7534d4e913STim J. Robbinsfound4:	leal	4(%edi),%edi
7634d4e913STim J. Robbins	jmp	found
7734d4e913STim J. Robbinsfound8:	leal	8(%edi),%edi
7834d4e913STim J. Robbins	jmp	found
7934d4e913STim J. Robbinsfound12:leal	12(%edi),%edi
8034d4e913STim J. Robbins	jmp	found
8134d4e913STim J. Robbinsfound16:leal	16(%edi),%edi
8234d4e913STim J. Robbins	jmp	found
8334d4e913STim J. Robbinsfound20:leal	20(%edi),%edi
8434d4e913STim J. Robbins	jmp	found
8534d4e913STim J. Robbinsfound24:leal	24(%edi),%edi
8634d4e913STim J. Robbins	jmp	found
8734d4e913STim J. Robbinsfound28:leal	28(%edi),%edi
8834d4e913STim J. Robbins	jmp	found
8934d4e913STim J. Robbins
9034d4e913STim J. Robbins	/*
9134d4e913STim J. Robbins	 * Search remaining part of string.
9234d4e913STim J. Robbins	 */
9334d4e913STim J. Robbinssmall:	movl	%ebx,%ecx
9434d4e913STim J. Robbins	andl	$7,%ecx
9534d4e913STim J. Robbins	jz	no
961609edcaSTim J. Robbins.p2align 2,0x90
9734d4e913STim J. Robbinssmltop:	cmpl	%eax,(%edi)
9834d4e913STim J. Robbins	je	found
9934d4e913STim J. Robbins	leal	4(%edi),%edi
10034d4e913STim J. Robbins	decl	%ecx
10134d4e913STim J. Robbins	jnz	smltop
10234d4e913STim J. Robbinsno:	xorl	%eax,%eax
10334d4e913STim J. Robbins	popl	%ebx
10434d4e913STim J. Robbins	popl	%edi
10534d4e913STim J. Robbins	ret
106ed820052SPeter WemmEND(wmemchr)
107*93ab7586SKonstantin Belousov
108*93ab7586SKonstantin Belousov	.section .note.GNU-stack,"",%progbits
109