Source file
src/runtime/mkduff.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package main
25
26 import (
27 "bytes"
28 "fmt"
29 "io"
30 "log"
31 "os"
32 )
33
34 func main() {
35 gen("386", notags, zero386, copy386)
36 gen("arm", notags, zeroARM, copyARM)
37 gen("ppc64x", tagsPPC64x, zeroPPC64x, copyPPC64x)
38 gen("mips64x", tagsMIPS64x, zeroMIPS64x, copyMIPS64x)
39 }
40
41 func gen(arch string, tags, zero, copy func(io.Writer)) {
42 var buf bytes.Buffer
43
44 fmt.Fprintln(&buf, "// Code generated by mkduff.go; DO NOT EDIT.")
45 fmt.Fprintln(&buf, "// Run go generate from src/runtime to update.")
46 fmt.Fprintln(&buf, "// See mkduff.go for comments.")
47 tags(&buf)
48 fmt.Fprintln(&buf, "#include \"textflag.h\"")
49 fmt.Fprintln(&buf)
50 zero(&buf)
51 fmt.Fprintln(&buf)
52 copy(&buf)
53
54 if err := os.WriteFile("duff_"+arch+".s", buf.Bytes(), 0644); err != nil {
55 log.Fatalln(err)
56 }
57 }
58
59 func notags(w io.Writer) { fmt.Fprintln(w) }
60
61 func zeroAMD64(w io.Writer) {
62
63
64
65 fmt.Fprintln(w, "TEXT runtime·duffzero<ABIInternal>(SB), NOSPLIT|NOFRAME, $0-0")
66 for i := 0; i < 16; i++ {
67 fmt.Fprintln(w, "\tMOVUPS\tX15,(DI)")
68 fmt.Fprintln(w, "\tMOVUPS\tX15,16(DI)")
69 fmt.Fprintln(w, "\tMOVUPS\tX15,32(DI)")
70 fmt.Fprintln(w, "\tMOVUPS\tX15,48(DI)")
71 fmt.Fprintln(w, "\tLEAQ\t64(DI),DI")
72 fmt.Fprintln(w)
73 }
74 fmt.Fprintln(w, "\tRET")
75 }
76
77 func copyAMD64(w io.Writer) {
78
79
80
81
82
83
84 fmt.Fprintln(w, "TEXT runtime·duffcopy<ABIInternal>(SB), NOSPLIT|NOFRAME, $0-0")
85 for i := 0; i < 64; i++ {
86 fmt.Fprintln(w, "\tMOVUPS\t(SI), X0")
87 fmt.Fprintln(w, "\tADDQ\t$16, SI")
88 fmt.Fprintln(w, "\tMOVUPS\tX0, (DI)")
89 fmt.Fprintln(w, "\tADDQ\t$16, DI")
90 fmt.Fprintln(w)
91 }
92 fmt.Fprintln(w, "\tRET")
93 }
94
95 func zero386(w io.Writer) {
96
97
98
99 fmt.Fprintln(w, "TEXT runtime·duffzero(SB), NOSPLIT, $0-0")
100 for i := 0; i < 128; i++ {
101 fmt.Fprintln(w, "\tSTOSL")
102 }
103 fmt.Fprintln(w, "\tRET")
104 }
105
106 func copy386(w io.Writer) {
107
108
109
110
111
112
113 fmt.Fprintln(w, "TEXT runtime·duffcopy(SB), NOSPLIT, $0-0")
114 for i := 0; i < 128; i++ {
115 fmt.Fprintln(w, "\tMOVL\t(SI), CX")
116 fmt.Fprintln(w, "\tADDL\t$4, SI")
117 fmt.Fprintln(w, "\tMOVL\tCX, (DI)")
118 fmt.Fprintln(w, "\tADDL\t$4, DI")
119 fmt.Fprintln(w)
120 }
121 fmt.Fprintln(w, "\tRET")
122 }
123
124 func zeroARM(w io.Writer) {
125
126
127
128 fmt.Fprintln(w, "TEXT runtime·duffzero(SB), NOSPLIT, $0-0")
129 for i := 0; i < 128; i++ {
130 fmt.Fprintln(w, "\tMOVW.P\tR0, 4(R1)")
131 }
132 fmt.Fprintln(w, "\tRET")
133 }
134
135 func copyARM(w io.Writer) {
136
137
138
139
140 fmt.Fprintln(w, "TEXT runtime·duffcopy(SB), NOSPLIT, $0-0")
141 for i := 0; i < 128; i++ {
142 fmt.Fprintln(w, "\tMOVW.P\t4(R1), R0")
143 fmt.Fprintln(w, "\tMOVW.P\tR0, 4(R2)")
144 fmt.Fprintln(w)
145 }
146 fmt.Fprintln(w, "\tRET")
147 }
148
149 func zeroARM64(w io.Writer) {
150
151
152
153 fmt.Fprintln(w, "TEXT runtime·duffzero<ABIInternal>(SB), NOSPLIT|NOFRAME, $0-0")
154 for i := 0; i < 63; i++ {
155 fmt.Fprintln(w, "\tSTP.P\t(ZR, ZR), 16(R20)")
156 }
157 fmt.Fprintln(w, "\tSTP\t(ZR, ZR), (R20)")
158 fmt.Fprintln(w, "\tRET")
159 }
160
161 func copyARM64(w io.Writer) {
162
163
164
165
166 fmt.Fprintln(w, "TEXT runtime·duffcopy<ABIInternal>(SB), NOSPLIT|NOFRAME, $0-0")
167
168 for i := 0; i < 64; i++ {
169 fmt.Fprintln(w, "\tLDP.P\t16(R20), (R26, R27)")
170 fmt.Fprintln(w, "\tSTP.P\t(R26, R27), 16(R21)")
171 fmt.Fprintln(w)
172 }
173 fmt.Fprintln(w, "\tRET")
174 }
175
176 func tagsPPC64x(w io.Writer) {
177 fmt.Fprintln(w)
178 fmt.Fprintln(w, "//go:build ppc64 || ppc64le")
179 fmt.Fprintln(w)
180 }
181
182 func zeroPPC64x(w io.Writer) {
183
184
185
186 fmt.Fprintln(w, "TEXT runtime·duffzero<ABIInternal>(SB), NOSPLIT|NOFRAME, $0-0")
187 for i := 0; i < 128; i++ {
188 fmt.Fprintln(w, "\tMOVDU\tR0, 8(R20)")
189 }
190 fmt.Fprintln(w, "\tRET")
191 }
192
193 func copyPPC64x(w io.Writer) {
194
195 fmt.Fprintln(w, "TEXT runtime·duffcopy<ABIInternal>(SB), NOSPLIT|NOFRAME, $0-0")
196 for i := 0; i < 128; i++ {
197 fmt.Fprintln(w, "\tMOVDU\t8(R20), R5")
198 fmt.Fprintln(w, "\tMOVDU\tR5, 8(R21)")
199 }
200 fmt.Fprintln(w, "\tRET")
201 }
202
203 func tagsMIPS64x(w io.Writer) {
204 fmt.Fprintln(w)
205 fmt.Fprintln(w, "//go:build mips64 || mips64le")
206 fmt.Fprintln(w)
207 }
208
209 func zeroMIPS64x(w io.Writer) {
210
211
212
213 fmt.Fprintln(w, "TEXT runtime·duffzero(SB), NOSPLIT|NOFRAME, $0-0")
214 for i := 0; i < 128; i++ {
215 fmt.Fprintln(w, "\tMOVV\tR0, 8(R1)")
216 fmt.Fprintln(w, "\tADDV\t$8, R1")
217 }
218 fmt.Fprintln(w, "\tRET")
219 }
220
221 func copyMIPS64x(w io.Writer) {
222 fmt.Fprintln(w, "TEXT runtime·duffcopy(SB), NOSPLIT|NOFRAME, $0-0")
223 for i := 0; i < 128; i++ {
224 fmt.Fprintln(w, "\tMOVV\t(R1), R23")
225 fmt.Fprintln(w, "\tADDV\t$8, R1")
226 fmt.Fprintln(w, "\tMOVV\tR23, (R2)")
227 fmt.Fprintln(w, "\tADDV\t$8, R2")
228 fmt.Fprintln(w)
229 }
230 fmt.Fprintln(w, "\tRET")
231 }
232
View as plain text