]> git.saurik.com Git - apple/libc.git/blame - i386/gen/bzero.s
Libc-262.2.12.tar.gz
[apple/libc.git] / i386 / gen / bzero.s
CommitLineData
5b2abdfb
A
1/*
2 * Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
734aad71
A
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
5b2abdfb
A
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
734aad71
A
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
5b2abdfb
A
23 * @APPLE_LICENSE_HEADER_END@
24 */
25/*
26 * Copyright (c) 1993 Winning Strategies, Inc.
27 * All rights reserved.
28 *
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
31 * are met:
32 * 1. Redistributions of source code must retain the above copyright
33 * notice, this list of conditions and the following disclaimer.
34 * 2. Redistributions in binary form must reproduce the above copyright
35 * notice, this list of conditions and the following disclaimer in the
36 * documentation and/or other materials provided with the distribution.
37 * 3. All advertising materials mentioning features or use of this software
38 * must display the following acknowledgement:
39 * This product includes software developed by Winning Strategies, Inc.
40 * 4. The name of the author may not be used to endorse or promote products
41 * derived from this software withough specific prior written permission
42 *
43 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
44 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
45 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
46 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
47 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
49 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
50 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
51 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
52 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53 *
54 */
55
56#include <architecture/i386/asm_help.h>
57
58/*
59 * bzero (void *b, size_t len)
60 * write len zero bytes to the string b.
61 *
62 * Written by:
63 * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc.
64 */
65
66TEXT
67LEAF(_bzero,0)
68 pushl %edi
69 pushl %ebx
70 movl 12(%esp),%edi
71 movl 16(%esp),%ecx
72
73 cld /* set fill direction forward */
74 xorl %eax,%eax /* set fill data to 0 */
75
76 /*
77 * if the string is too short, it's really not worth the overhead
78 * of aligning to word boundries, etc. So we jump to a plain
79 * unaligned set.
80 */
81 cmpl $0x0f,%ecx
82 jle L1
83
84 movl %edi,%edx /* compute misalignment */
85 negl %edx
86 andl $3,%edx
87 movl %ecx,%ebx
88 subl %edx,%ebx
89
90 movl %edx,%ecx /* zero until word aligned */
91 rep
92 stosb
93
94 movl %ebx,%ecx /* zero by words */
95 shrl $2,%ecx
96 rep
97 stosl
98
99 movl %ebx,%ecx
100 andl $3,%ecx /* zero remainder by bytes */
101L1: rep
102 stosb
103
104 popl %ebx
105 popl %edi
106END(_bzero)