memset.S revision 93000
118334Speter/* 250506Sobrien * Copyright (c) 1993 Winning Strategies, Inc. 318334Speter * All rights reserved. 418334Speter * 518334Speter * Redistribution and use in source and binary forms, with or without 618334Speter * modification, are permitted provided that the following conditions 718334Speter * are met: 818334Speter * 1. Redistributions of source code must retain the above copyright 918334Speter * notice, this list of conditions and the following disclaimer. 1018334Speter * 2. Redistributions in binary form must reproduce the above copyright 1118334Speter * notice, this list of conditions and the following disclaimer in the 1218334Speter * documentation and/or other materials provided with the distribution. 1318334Speter * 3. All advertising materials mentioning features or use of this software 1418334Speter * must display the following acknowledgement: 1518334Speter * This product includes software developed by Winning Strategies, Inc. 1618334Speter * 4. The name of the author may not be used to endorse or promote products 1718334Speter * derived from this software without specific prior written permission 1818334Speter * 1918334Speter * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 2018334Speter * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 2118334Speter * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2218334Speter * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2318334Speter * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2418334Speter * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2518334Speter * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2618334Speter * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2718334Speter * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2818334Speter * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2918334Speter */ 3050506Sobrien 3118334Speter#include <machine/asm.h> 3218334Speter__FBSDID("$FreeBSD: head/lib/libc/i386/string/memset.S 93000 2002-03-23 02:44:19Z obrien $"); 3318334Speter 3418334Speter/* 3518334Speter * memset(void *b, int c, size_t len) 3618334Speter * write len bytes of value c (converted to an unsigned char) to 3718334Speter * the string b. 3818334Speter * 3918334Speter * Written by: 4018334Speter * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. 4118334Speter */ 4218334Speter 4318334SpeterENTRY(memset) 4418334Speter pushl %edi 4518334Speter pushl %ebx 4618334Speter movl 12(%esp),%edi 4718334Speter movzbl 16(%esp),%eax /* unsigned char, zero extend */ 4818334Speter movl 20(%esp),%ecx 4918334Speter pushl %edi /* push address of buffer */ 5018334Speter 5118334Speter cld /* set fill direction forward */ 5218334Speter 5318334Speter /* 5418334Speter * if the string is too short, it's really not worth the overhead 5518334Speter * of aligning to word boundries, etc. So we jump to a plain 5650506Sobrien * unaligned set. 5750506Sobrien */ 5850506Sobrien cmpl $0x0f,%ecx 5950506Sobrien jle L1 6018334Speter 6118334Speter movb %al,%ah /* copy char to all bytes in word */ 6218334Speter movl %eax,%edx 6318334Speter sall $16,%eax 6418334Speter orl %edx,%eax 6518334Speter 6618334Speter movl %edi,%edx /* compute misalignment */ 6718334Speter negl %edx 6818334Speter andl $3,%edx 6918334Speter movl %ecx,%ebx 7018334Speter subl %edx,%ebx 7118334Speter 7218334Speter movl %edx,%ecx /* set until word aligned */ 7318334Speter rep 7418334Speter stosb 7518334Speter 7618334Speter movl %ebx,%ecx 7718334Speter shrl $2,%ecx /* set by words */ 7818334Speter rep 7918334Speter stosl 8018334Speter 8118334Speter movl %ebx,%ecx /* set remainder by bytes */ 8218334Speter andl $3,%ecx 8318334SpeterL1: rep 8418334Speter stosb 8518334Speter 8618334Speter popl %eax /* pop address of buffer */ 8718334Speter popl %ebx 8818334Speter popl %edi 8918334Speter ret 9050506Sobrien