/*-1* Copyright (c) 2003 Tim J. Robbins.2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12*13* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND14* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE15* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE16* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE17* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL18* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS19* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)20* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT21* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY22* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF23* SUCH DAMAGE.24*/2526#include <machine/asm.h>27/*28* wchar_t *29* wmemchr(const wchar_t *buf, wchar_t c, size_t n) --30* Search the wide character array `buf', which has length `n',31* the character `c', return a pointer to it if found, or NULL on32* failure.33*/34ENTRY(wmemchr)35pushl %edi36pushl %ebx37movl 12(%esp),%edi /* Buffer */38movl 16(%esp),%eax /* Wide character */39movl 20(%esp),%ecx /* Length of buffer */4041/*42* Search in chunks of 8 wide characters (32 bytes).43*/44movl %ecx,%ebx45shrl $3,%ecx46jz small47.p2align 4,0x9048bigloop:cmpl %eax,(%edi)49je found50cmpl %eax,4(%edi)51je found452cmpl %eax,8(%edi)53je found854cmpl %eax,12(%edi)55je found1256cmpl %eax,16(%edi)57je found1658cmpl %eax,20(%edi)59je found2060cmpl %eax,24(%edi)61je found2462cmpl %eax,28(%edi)63je found2864leal 32(%edi),%edi65decl %ecx66jnz bigloop67jmp small68found: movl %edi,%eax69popl %ebx70popl %edi71ret72found4: leal 4(%edi),%edi73jmp found74found8: leal 8(%edi),%edi75jmp found76found12:leal 12(%edi),%edi77jmp found78found16:leal 16(%edi),%edi79jmp found80found20:leal 20(%edi),%edi81jmp found82found24:leal 24(%edi),%edi83jmp found84found28:leal 28(%edi),%edi85jmp found8687/*88* Search remaining part of string.89*/90small: movl %ebx,%ecx91andl $7,%ecx92jz no93.p2align 2,0x9094smltop: cmpl %eax,(%edi)95je found96leal 4(%edi),%edi97decl %ecx98jnz smltop99no: xorl %eax,%eax100popl %ebx101popl %edi102ret103END(wmemchr)104105.section .note.GNU-stack,"",%progbits106107108