bzero.S revision 1.2 1 /*-
2 * Copyright (c) 2006 The NetBSD Foundation, Inc.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to The NetBSD Foundation
6 * by Ross Harvey.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the NetBSD
19 * Foundation, Inc. and its contributors.
20 * 4. Neither the name of The NetBSD Foundation nor the names of its
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
25 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
28 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 */
36
37 #include <machine/asm.h>
38
39 .file "bzero.c"
40 ENTRY(bzero)
41 mr 5, 4 # translate to memcpy signature
42 li 4, 0 # add missing memcpy param
43 ENTRY(memset)
44 cmpldi 7, 5, 7 # only optimize if len >= 8
45 mr 9, 3
46 ble 7, 2f
47 rldicl. 0, 3, 0, 61 # only optimize if aligned
48 beq 0, 4f
49 2:
50 cmpdi 7, 5, 0
51 beqlr 7
52 3:
53 mtctr 5
54 rldicl 0, 4, 0, 56
55 .p2align 4, , 15
56 2:
57 stb 0, 0(9) # byte-at-a-time loop
58 addi 9, 9, 1
59 bdnz 2b
60 blr # done
61 4:
62 rldicl 4, 4, 0, 56 # construct parallel store
63 cmpldi 7, 5, 31
64 mr 10, 3
65 sldi 0, 4, 8
66 or 0, 0, 4
67 sldi 9, 0, 16
68 or 0, 0, 9
69 sldi 11, 0, 32
70 or 0, 0, 11
71 ble 7, 5f
72 addi 9, 5, -32
73 srdi 9, 9, 5
74 addi 9, 9, 1
75 mtctr 9
76 .p2align 4, , 15
77 2:
78 std 0, 0(10) # 8-way + unrolled store loop
79 std 0, 8(10)
80 addi 5, 5, -32 # schedule count decrement
81 std 0, 16(10)
82 std 0, 24(10)
83 addi 10, 10, 32
84 bdnz 2b
85 cmpldi 7, 5, 7
86 ble 7, 8f
87 5:
88 addi 9, 5, -8
89 srdi 9, 9, 3
90 addi 9, 9, 1
91 mtctr 9
92 .p2align 4, , 15
93 14:
94 std 0, 0(10) # 8-way not-unrolled loop
95 addi 5, 5, -8
96 addi 10, 10, 8
97 bdnz 14b
98 8:
99 cmpdi 7, 5, 0
100 mr 9, 10
101 bne 7, 3b
102 blr
103 .long 0
104 .byte 0, 0, 0, 0, 0, 0, 0, 0
105 .size .memset, .-.memset
106