bzero.S revision 1.2 1 /* $NetBSD: bzero.S,v 1.2 2003/10/06 05:30:21 matt Exp $ */
2
3 /* $OpenBSD: bzero.S,v 1.3 2001/06/04 23:14:02 mickey Exp $ */
4
5 /*
6 * (c) Copyright 1988 HEWLETT-PACKARD COMPANY
7 *
8 * To anyone who acknowledges that this file is provided "AS IS"
9 * without any express or implied warranty:
10 * permission to use, copy, modify, and distribute this file
11 * for any purpose is hereby granted without fee, provided that
12 * the above copyright notice and this notice appears in all
13 * copies, and that the name of Hewlett-Packard Company not be
14 * used in advertising or publicity pertaining to distribution
15 * of the software without specific, written prior permission.
16 * Hewlett-Packard Company makes no representations about the
17 * suitability of this software for any purpose.
18 */
19 /*
20 * Copyright (c) 1990,1994 The University of Utah and
21 * the Computer Systems Laboratory (CSL). All rights reserved.
22 *
23 * THE UNIVERSITY OF UTAH AND CSL PROVIDE THIS SOFTWARE IN ITS "AS IS"
24 * CONDITION, AND DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
25 * WHATSOEVER RESULTING FROM ITS USE.
26 *
27 * CSL requests users of this software to return to csl-dist (at) cs.utah.edu any
28 * improvements that they make and grant CSL redistribution rights.
29 *
30 * Utah $Hdr: bzero.s 1.9 94/12/14$
31 * Author: Bob Wheeler, University of Utah CSL
32 */
33
34 #include <machine/asm.h>
35
36 #ifdef SYSLIBC_SCCS
37 .text
38 .asciz "$OpenBSD: bzero.S,v 1.3 2001/06/04 23:14:02 mickey Exp $"
39 .align 4
40 #endif
41
42 /*
43 * void
44 * bzero(dst, count)
45 * void *dst;
46 * size_t count;
47 */
48 LEAF_ENTRY(bzero)
49 comb,>=,n %r0,%arg1,$bzero_exit
50
51 /*
52 * If we need to clear less than a word do it a byte at a time
53 */
54
55 comib,>>,n 4,%arg1,$bzero_bytes
56
57 /*
58 * Since we are only clearing memory the alignment restrictions
59 * are simplified. Figure out how many "extra" bytes we need to
60 * store with stbys.
61 */
62
63 extru %arg0,31,2,%t1
64 add %arg1,%t1,%arg1
65
66 /*
67 * We will zero the destination in blocks of 16 bytes as long as we
68 * can and then we'll go to the 4 byte moves.
69 */
70
71 comib,>>= 15, %arg1, $bzero_word
72 addi -16, %arg1, %arg1
73
74 $bzero_loop_16:
75 stbys,b,m %r0,4(%arg0)
76 stwm %r0,4(%arg0)
77 stwm %r0,4(%arg0)
78 stwm %r0,4(%arg0)
79 comib,<< 15, %arg1, $bzero_loop_16
80 addi -16, %arg1, %arg1
81
82 /*
83 * see if there is anything left that needs to be zeroed in a word
84 * move. Since the count was decremented by 16, add 12 to test if
85 * there are any full word moves left to do.
86 */
87
88 $bzero_word:
89 addib,<,n 12,%arg1,$bzero_cleanup
90
91 $bzero_loop_4:
92 addib,>= -4,%arg1,$bzero_loop_4
93 stbys,b,m %r0,4(%arg0)
94
95 /*
96 * zero the last bytes that may be unaligned on a word boundary
97 */
98
99 $bzero_cleanup:
100 addib,=,n 4,%arg1,$bzero_exit
101 add %arg0,%arg1,%arg0
102 b $bzero_exit
103 stbys,e %r0,0(%arg0)
104 b,n $bzero_exit
105
106
107 /*
108 * zero by bytes
109 */
110
111 $bzero_bytes:
112 addib,> -1,%arg1,$bzero_bytes
113 stbs,ma %r0,1(%arg0)
114
115 $bzero_exit:
116 bv,n %r0(%rp)
117 EXIT(bzero)
118
119 .end
120