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