bzero.S revision 184548
1193326Sed/*
2193326Sed * Copyright (c) 1993 Winning Strategies, Inc.
3193326Sed * All rights reserved.
4193326Sed *
5193326Sed * Redistribution and use in source and binary forms, with or without
6193326Sed * modification, are permitted provided that the following conditions
7193326Sed * are met:
8193326Sed * 1. Redistributions of source code must retain the above copyright
9193326Sed *    notice, this list of conditions and the following disclaimer.
10198092Srdivacky * 2. Redistributions in binary form must reproduce the above copyright
11193326Sed *    notice, this list of conditions and the following disclaimer in the
12193326Sed *    documentation and/or other materials provided with the distribution.
13193326Sed * 3. All advertising materials mentioning features or use of this software
14193326Sed *    must display the following acknowledgement:
15193326Sed *      This product includes software developed by Winning Strategies, Inc.
16193326Sed * 4. The name of the author may not be used to endorse or promote products
17193326Sed *    derived from this software without specific prior written permission
18193326Sed *
19249423Sdim * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20193326Sed * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21193326Sed * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22193326Sed * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23198092Srdivacky * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24193326Sed * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25193326Sed * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26193326Sed * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27193326Sed * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28193326Sed * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29193326Sed */
30193326Sed
31198092Srdivacky#include <machine/asm.h>
32193326Sed__FBSDID("$FreeBSD: head/lib/libc/i386/string/bzero.S 184548 2008-11-02 01:28:47Z peter $");
33198092Srdivacky
34193326Sed/*
35193326Sed * bzero (void *b, size_t len)
36193326Sed *	write len zero bytes to the string b.
37193326Sed *
38198092Srdivacky * Written by:
39193326Sed *	J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc.
40193326Sed */
41193326Sed
42193326SedENTRY(bzero)
43198092Srdivacky	pushl	%edi
44193326Sed	pushl	%ebx
45193326Sed	movl	12(%esp),%edi
46193326Sed	movl	16(%esp),%ecx
47198092Srdivacky
48193326Sed	cld				/* set fill direction forward */
49193326Sed	xorl	%eax,%eax		/* set fill data to 0 */
50193326Sed
51193326Sed	/*
52193326Sed	 * if the string is too short, it's really not worth the overhead
53193326Sed	 * of aligning to word boundries, etc.  So we jump to a plain
54193326Sed	 * unaligned set.
55193326Sed	 */
56193326Sed	cmpl	$0x0f,%ecx
57193326Sed	jle	L1
58198092Srdivacky
59193326Sed	movl	%edi,%edx		/* compute misalignment */
60198092Srdivacky	negl	%edx
61193326Sed	andl	$3,%edx
62193326Sed	movl	%ecx,%ebx
63198092Srdivacky	subl	%edx,%ebx
64193326Sed
65198092Srdivacky	movl	%edx,%ecx		/* zero until word aligned */
66193326Sed	rep
67193326Sed	stosb
68193326Sed
69193326Sed	movl	%ebx,%ecx		/* zero by words */
70198092Srdivacky	shrl	$2,%ecx
71193326Sed	rep
72193326Sed	stosl
73193326Sed
74198092Srdivacky	movl	%ebx,%ecx
75193326Sed	andl	$3,%ecx			/* zero remainder by bytes */
76193326SedL1:	rep
77193326Sed	stosb
78193326Sed
79193326Sed	popl	%ebx
80198092Srdivacky	popl	%edi
81193326Sed	ret
82193326SedEND(bzero)
83193326Sed