memset.S revision 93000
11541Srgrimes/* 21541Srgrimes * Copyright (c) 1993 Winning Strategies, Inc. 31541Srgrimes * All rights reserved. 41541Srgrimes * 51541Srgrimes * Redistribution and use in source and binary forms, with or without 61541Srgrimes * modification, are permitted provided that the following conditions 71541Srgrimes * are met: 81541Srgrimes * 1. Redistributions of source code must retain the above copyright 91541Srgrimes * notice, this list of conditions and the following disclaimer. 101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111541Srgrimes * notice, this list of conditions and the following disclaimer in the 121541Srgrimes * documentation and/or other materials provided with the distribution. 131541Srgrimes * 3. All advertising materials mentioning features or use of this software 141541Srgrimes * must display the following acknowledgement: 151541Srgrimes * This product includes software developed by Winning Strategies, Inc. 161541Srgrimes * 4. The name of the author may not be used to endorse or promote products 171541Srgrimes * derived from this software without specific prior written permission 181541Srgrimes * 191541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 201541Srgrimes * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 211541Srgrimes * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 221541Srgrimes * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 231541Srgrimes * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 241541Srgrimes * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 251541Srgrimes * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 261541Srgrimes * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 271541Srgrimes * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 281541Srgrimes * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 291541Srgrimes */ 301541Srgrimes 311541Srgrimes#include <machine/asm.h> 321541Srgrimes__FBSDID("$FreeBSD: head/lib/libc/i386/string/memset.S 93000 2002-03-23 02:44:19Z obrien $"); 331541Srgrimes 341541Srgrimes/* 351541Srgrimes * memset(void *b, int c, size_t len) 361541Srgrimes * write len bytes of value c (converted to an unsigned char) to 371541Srgrimes * the string b. 3822521Sdyson * 3927375Sbde * Written by: 401541Srgrimes * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. 411541Srgrimes */ 422177Spaul 435247SbdeENTRY(memset) 442177Spaul pushl %edi 451541Srgrimes pushl %ebx 461541Srgrimes movl 12(%esp),%edi 471541Srgrimes movzbl 16(%esp),%eax /* unsigned char, zero extend */ 4824477Sbde movl 20(%esp),%ecx 4924477Sbde pushl %edi /* push address of buffer */ 5024477Sbde 5124477Sbde cld /* set fill direction forward */ 5224477Sbde 5322521Sdyson /* 5422521Sdyson * if the string is too short, it's really not worth the overhead 5522521Sdyson * of aligning to word boundries, etc. So we jump to a plain 5622521Sdyson * unaligned set. 5722521Sdyson */ 5822521Sdyson cmpl $0x0f,%ecx 5922521Sdyson jle L1 601541Srgrimes 6122521Sdyson movb %al,%ah /* copy char to all bytes in word */ 6222521Sdyson movl %eax,%edx 6322521Sdyson sall $16,%eax 6422521Sdyson orl %edx,%eax 6522521Sdyson 6622521Sdyson movl %edi,%edx /* compute misalignment */ 6722521Sdyson negl %edx 681541Srgrimes andl $3,%edx 691541Srgrimes movl %ecx,%ebx 701541Srgrimes subl %edx,%ebx 711541Srgrimes 7212117Sdyson movl %edx,%ecx /* set until word aligned */ 731541Srgrimes rep 741541Srgrimes stosb 751541Srgrimes 7612117Sdyson movl %ebx,%ecx 7722521Sdyson shrl $2,%ecx /* set by words */ 7822521Sdyson rep 7922521Sdyson stosl 8022521Sdyson 811541Srgrimes movl %ebx,%ecx /* set remainder by bytes */ 821541Srgrimes andl $3,%ecx 831541SrgrimesL1: rep 8422521Sdyson stosb 8522521Sdyson 8622521Sdyson popl %eax /* pop address of buffer */ 8722521Sdyson popl %ebx 8822521Sdyson popl %edi 8922521Sdyson ret 9027375Sbde