wmemchr.S revision 302408
112891Swpaul/*-
212891Swpaul * Copyright (c) 2003 Tim J. Robbins.
312891Swpaul * All rights reserved.
412891Swpaul *
512891Swpaul * Redistribution and use in source and binary forms, with or without
612891Swpaul * modification, are permitted provided that the following conditions
712891Swpaul * are met:
812891Swpaul * 1. Redistributions of source code must retain the above copyright
912891Swpaul *    notice, this list of conditions and the following disclaimer.
1012891Swpaul * 2. Redistributions in binary form must reproduce the above copyright
1112891Swpaul *    notice, this list of conditions and the following disclaimer in the
1212891Swpaul *    documentation and/or other materials provided with the distribution.
1312891Swpaul *
1412891Swpaul * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1512891Swpaul * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1612891Swpaul * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1712891Swpaul * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1812891Swpaul * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1912891Swpaul * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2012891Swpaul * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2112891Swpaul * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2212891Swpaul * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2312891Swpaul * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2412891Swpaul * SUCH DAMAGE.
2512891Swpaul */
2612891Swpaul
2712891Swpaul#include <machine/asm.h>
2812891Swpaul__FBSDID("$FreeBSD: stable/11/lib/libc/i386/string/wmemchr.S 217106 2011-01-07 16:08:40Z kib $");
2912891Swpaul
3012891Swpaul/*
3112891Swpaul * wchar_t *
3212891Swpaul * wmemchr(const wchar_t *buf, wchar_t c, size_t n) --
3312891Swpaul *	Search the wide character array `buf', which has length `n',
34114601Sobrien *	the character `c', return a pointer to it if found, or NULL on
35114601Sobrien *	failure.
3630827Scharnier */
3720818SwpaulENTRY(wmemchr)
3812891Swpaul	pushl	%edi
3930827Scharnier	pushl	%ebx
4030827Scharnier	movl	12(%esp),%edi		/* Buffer */
4112891Swpaul	movl	16(%esp),%eax		/* Wide character */
4212891Swpaul	movl	20(%esp),%ecx		/* Length of buffer */
4312891Swpaul
4412891Swpaul	/*
4512891Swpaul	 * Search in chunks of 8 wide characters (32 bytes).
4612891Swpaul	 */
4712891Swpaul	movl	%ecx,%ebx
4812997Swpaul	shrl	$3,%ecx
4912891Swpaul	jz	small
5012891Swpaul.p2align 4,0x90
5112891Swpaulbigloop:cmpl	%eax,(%edi)
5228042Swpaul	je	found
5328042Swpaul	cmpl	%eax,4(%edi)
5428042Swpaul	je	found4
5528042Swpaul	cmpl	%eax,8(%edi)
5628042Swpaul	je	found8
5790298Sdes	cmpl	%eax,12(%edi)
5890298Sdes	je	found12
5946186Swpaul	cmpl	%eax,16(%edi)
6046186Swpaul	je	found16
6146186Swpaul	cmpl	%eax,20(%edi)
6246186Swpaul	je	found20
6346186Swpaul	cmpl	%eax,24(%edi)
6446186Swpaul	je	found24
6546186Swpaul	cmpl	%eax,28(%edi)
6646186Swpaul	je	found28
6746186Swpaul	leal	32(%edi),%edi
6846186Swpaul	decl	%ecx
6914262Swpaul	jnz	bigloop
7014262Swpaul	jmp	small
7114262Swpaulfound:	movl	%edi,%eax
7214262Swpaul	popl	%ebx
7312891Swpaul	popl	%edi
7412891Swpaul	ret
7512891Swpaulfound4:	leal	4(%edi),%edi
7612891Swpaul	jmp	found
7712891Swpaulfound8:	leal	8(%edi),%edi
7812891Swpaul	jmp	found
7919161Swpaulfound12:leal	12(%edi),%edi
8019161Swpaul	jmp	found
8119161Swpaulfound16:leal	16(%edi),%edi
8212891Swpaul	jmp	found
8319161Swpaulfound20:leal	20(%edi),%edi
8412891Swpaul	jmp	found
8512891Swpaulfound24:leal	24(%edi),%edi
8612891Swpaul	jmp	found
8712891Swpaulfound28:leal	28(%edi),%edi
8812891Swpaul	jmp	found
8912891Swpaul
9012891Swpaul	/*
9112891Swpaul	 * Search remaining part of string.
9212891Swpaul	 */
9312891Swpaulsmall:	movl	%ebx,%ecx
9412891Swpaul	andl	$7,%ecx
9512891Swpaul	jz	no
9619161Swpaul.p2align 2,0x90
9719161Swpaulsmltop:	cmpl	%eax,(%edi)
9819161Swpaul	je	found
9912891Swpaul	leal	4(%edi),%edi
10019161Swpaul	decl	%ecx
10112891Swpaul	jnz	smltop
10212891Swpaulno:	xorl	%eax,%eax
10312891Swpaul	popl	%ebx
10412891Swpaul	popl	%edi
10512891Swpaul	ret
10612891SwpaulEND(wmemchr)
10712891Swpaul
10812891Swpaul	.section .note.GNU-stack,"",%progbits
10912891Swpaul