xref: /freebsd/lib/libc/i386/string/wmemchr.S (revision 1d386b48a555f61cb7325543adbbb5c3f3407a66)
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/*
2934d4e913STim J. Robbins * wchar_t *
3034d4e913STim J. Robbins * wmemchr(const wchar_t *buf, wchar_t c, size_t n) --
3134d4e913STim J. Robbins *	Search the wide character array `buf', which has length `n',
3234d4e913STim J. Robbins *	the character `c', return a pointer to it if found, or NULL on
3334d4e913STim J. Robbins *	failure.
3434d4e913STim J. Robbins */
3534d4e913STim J. RobbinsENTRY(wmemchr)
3634d4e913STim J. Robbins	pushl	%edi
3734d4e913STim J. Robbins	pushl	%ebx
3834d4e913STim J. Robbins	movl	12(%esp),%edi		/* Buffer */
3934d4e913STim J. Robbins	movl	16(%esp),%eax		/* Wide character */
4034d4e913STim J. Robbins	movl	20(%esp),%ecx		/* Length of buffer */
4134d4e913STim J. Robbins
4234d4e913STim J. Robbins	/*
4334d4e913STim J. Robbins	 * Search in chunks of 8 wide characters (32 bytes).
4434d4e913STim J. Robbins	 */
4534d4e913STim J. Robbins	movl	%ecx,%ebx
4634d4e913STim J. Robbins	shrl	$3,%ecx
4734d4e913STim J. Robbins	jz	small
4834d4e913STim J. Robbins.p2align 4,0x90
4934d4e913STim J. Robbinsbigloop:cmpl	%eax,(%edi)
5034d4e913STim J. Robbins	je	found
5134d4e913STim J. Robbins	cmpl	%eax,4(%edi)
5234d4e913STim J. Robbins	je	found4
5334d4e913STim J. Robbins	cmpl	%eax,8(%edi)
5434d4e913STim J. Robbins	je	found8
5534d4e913STim J. Robbins	cmpl	%eax,12(%edi)
5634d4e913STim J. Robbins	je	found12
5734d4e913STim J. Robbins	cmpl	%eax,16(%edi)
5834d4e913STim J. Robbins	je	found16
5934d4e913STim J. Robbins	cmpl	%eax,20(%edi)
6034d4e913STim J. Robbins	je	found20
6134d4e913STim J. Robbins	cmpl	%eax,24(%edi)
6234d4e913STim J. Robbins	je	found24
6334d4e913STim J. Robbins	cmpl	%eax,28(%edi)
6434d4e913STim J. Robbins	je	found28
6534d4e913STim J. Robbins	leal	32(%edi),%edi
6634d4e913STim J. Robbins	decl	%ecx
6734d4e913STim J. Robbins	jnz	bigloop
6834d4e913STim J. Robbins	jmp	small
6934d4e913STim J. Robbinsfound:	movl	%edi,%eax
7034d4e913STim J. Robbins	popl	%ebx
7134d4e913STim J. Robbins	popl	%edi
7234d4e913STim J. Robbins	ret
7334d4e913STim J. Robbinsfound4:	leal	4(%edi),%edi
7434d4e913STim J. Robbins	jmp	found
7534d4e913STim J. Robbinsfound8:	leal	8(%edi),%edi
7634d4e913STim J. Robbins	jmp	found
7734d4e913STim J. Robbinsfound12:leal	12(%edi),%edi
7834d4e913STim J. Robbins	jmp	found
7934d4e913STim J. Robbinsfound16:leal	16(%edi),%edi
8034d4e913STim J. Robbins	jmp	found
8134d4e913STim J. Robbinsfound20:leal	20(%edi),%edi
8234d4e913STim J. Robbins	jmp	found
8334d4e913STim J. Robbinsfound24:leal	24(%edi),%edi
8434d4e913STim J. Robbins	jmp	found
8534d4e913STim J. Robbinsfound28:leal	28(%edi),%edi
8634d4e913STim J. Robbins	jmp	found
8734d4e913STim J. Robbins
8834d4e913STim J. Robbins	/*
8934d4e913STim J. Robbins	 * Search remaining part of string.
9034d4e913STim J. Robbins	 */
9134d4e913STim J. Robbinssmall:	movl	%ebx,%ecx
9234d4e913STim J. Robbins	andl	$7,%ecx
9334d4e913STim J. Robbins	jz	no
941609edcaSTim J. Robbins.p2align 2,0x90
9534d4e913STim J. Robbinssmltop:	cmpl	%eax,(%edi)
9634d4e913STim J. Robbins	je	found
9734d4e913STim J. Robbins	leal	4(%edi),%edi
9834d4e913STim J. Robbins	decl	%ecx
9934d4e913STim J. Robbins	jnz	smltop
10034d4e913STim J. Robbinsno:	xorl	%eax,%eax
10134d4e913STim J. Robbins	popl	%ebx
10234d4e913STim J. Robbins	popl	%edi
10334d4e913STim J. Robbins	ret
104ed820052SPeter WemmEND(wmemchr)
105*93ab7586SKonstantin Belousov
106*93ab7586SKonstantin Belousov	.section .note.GNU-stack,"",%progbits
107