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("loong64", notags, zeroLOONG64, copyLOONG64)
38 gen("ppc64x", tagsPPC64x, zeroPPC64x, copyPPC64x)
39 gen("mips64x", tagsMIPS64x, zeroMIPS64x, copyMIPS64x)
40 gen("riscv64", notags, zeroRISCV64, copyRISCV64)
41 }
42
43 func gen(arch string, tags, zero, copy func(io.Writer)) {
44 var buf bytes.Buffer
45
46 fmt.Fprintln(&buf, "// Code generated by mkduff.go; DO NOT EDIT.")
47 fmt.Fprintln(&buf, "// Run go generate from src/runtime to update.")
48 fmt.Fprintln(&buf, "// See mkduff.go for comments.")
49 tags(&buf)
50 fmt.Fprintln(&buf, "#include \"textflag.h\"")
51 fmt.Fprintln(&buf)
52 zero(&buf)
53 fmt.Fprintln(&buf)
54 copy(&buf)
55
56 if err := os.WriteFile("duff_"+arch+".s", buf.Bytes(), 0644); err != nil {
57 log.Fatalln(err)
58 }
59 }
60
61 func notags(w io.Writer) { fmt.Fprintln(w) }
62
63 func zeroAMD64(w io.Writer) {
64
65
66
67 fmt.Fprintln(w, "TEXT runtime·duffzero<ABIInternal>(SB), NOSPLIT|NOFRAME, $0-0")
68 for i := 0; i < 16; i++ {
69 fmt.Fprintln(w, "\tMOVUPS\tX15,(DI)")
70 fmt.Fprintln(w, "\tMOVUPS\tX15,16(DI)")
71 fmt.Fprintln(w, "\tMOVUPS\tX15,32(DI)")
72 fmt.Fprintln(w, "\tMOVUPS\tX15,48(DI)")
73 fmt.Fprintln(w, "\tLEAQ\t64(DI),DI")
74 fmt.Fprintln(w)
75 }
76 fmt.Fprintln(w, "\tRET")
77 }
78
79 func copyAMD64(w io.Writer) {
80
81
82
83
84
85
86 fmt.Fprintln(w, "TEXT runtime·duffcopy<ABIInternal>(SB), NOSPLIT|NOFRAME, $0-0")
87 for i := 0; i < 64; i++ {
88 fmt.Fprintln(w, "\tMOVUPS\t(SI), X0")
89 fmt.Fprintln(w, "\tADDQ\t$16, SI")
90 fmt.Fprintln(w, "\tMOVUPS\tX0, (DI)")
91 fmt.Fprintln(w, "\tADDQ\t$16, DI")
92 fmt.Fprintln(w)
93 }
94 fmt.Fprintln(w, "\tRET")
95 }
96
97 func zero386(w io.Writer) {
98
99
100
101 fmt.Fprintln(w, "TEXT runtime·duffzero(SB), NOSPLIT, $0-0")
102 for i := 0; i < 128; i++ {
103 fmt.Fprintln(w, "\tSTOSL")
104 }
105 fmt.Fprintln(w, "\tRET")
106 }
107
108 func copy386(w io.Writer) {
109
110
111
112
113
114
115 fmt.Fprintln(w, "TEXT runtime·duffcopy(SB), NOSPLIT, $0-0")
116 for i := 0; i < 128; i++ {
117 fmt.Fprintln(w, "\tMOVL\t(SI), CX")
118 fmt.Fprintln(w, "\tADDL\t$4, SI")
119 fmt.Fprintln(w, "\tMOVL\tCX, (DI)")
120 fmt.Fprintln(w, "\tADDL\t$4, DI")
121 fmt.Fprintln(w)
122 }
123 fmt.Fprintln(w, "\tRET")
124 }
125
126 func zeroARM(w io.Writer) {
127
128
129
130 fmt.Fprintln(w, "TEXT runtime·duffzero(SB), NOSPLIT, $0-0")
131 for i := 0; i < 128; i++ {
132 fmt.Fprintln(w, "\tMOVW.P\tR0, 4(R1)")
133 }
134 fmt.Fprintln(w, "\tRET")
135 }
136
137 func copyARM(w io.Writer) {
138
139
140
141
142 fmt.Fprintln(w, "TEXT runtime·duffcopy(SB), NOSPLIT, $0-0")
143 for i := 0; i < 128; i++ {
144 fmt.Fprintln(w, "\tMOVW.P\t4(R1), R0")
145 fmt.Fprintln(w, "\tMOVW.P\tR0, 4(R2)")
146 fmt.Fprintln(w)
147 }
148 fmt.Fprintln(w, "\tRET")
149 }
150
151 func zeroARM64(w io.Writer) {
152
153
154
155 fmt.Fprintln(w, "TEXT runtime·duffzero<ABIInternal>(SB), NOSPLIT|NOFRAME, $0-0")
156 for i := 0; i < 63; i++ {
157 fmt.Fprintln(w, "\tSTP.P\t(ZR, ZR), 16(R20)")
158 }
159 fmt.Fprintln(w, "\tSTP\t(ZR, ZR), (R20)")
160 fmt.Fprintln(w, "\tRET")
161 }
162
163 func copyARM64(w io.Writer) {
164
165
166
167
168 fmt.Fprintln(w, "TEXT runtime·duffcopy<ABIInternal>(SB), NOSPLIT|NOFRAME, $0-0")
169
170 for i := 0; i < 64; i++ {
171 fmt.Fprintln(w, "\tLDP.P\t16(R20), (R26, R27)")
172 fmt.Fprintln(w, "\tSTP.P\t(R26, R27), 16(R21)")
173 fmt.Fprintln(w)
174 }
175 fmt.Fprintln(w, "\tRET")
176 }
177
178 func zeroLOONG64(w io.Writer) {
179
180
181
182 fmt.Fprintln(w, "TEXT runtime·duffzero<ABIInternal>(SB), NOSPLIT|NOFRAME, $0-0")
183 for i := 0; i < 128; i++ {
184 fmt.Fprintln(w, "\tMOVV\tR0, (R20)")
185 fmt.Fprintln(w, "\tADDV\t$8, R20")
186 }
187 fmt.Fprintln(w, "\tRET")
188 }
189
190 func copyLOONG64(w io.Writer) {
191 fmt.Fprintln(w, "TEXT runtime·duffcopy<ABIInternal>(SB), NOSPLIT|NOFRAME, $0-0")
192 for i := 0; i < 128; i++ {
193 fmt.Fprintln(w, "\tMOVV\t(R20), R30")
194 fmt.Fprintln(w, "\tADDV\t$8, R20")
195 fmt.Fprintln(w, "\tMOVV\tR30, (R21)")
196 fmt.Fprintln(w, "\tADDV\t$8, R21")
197 fmt.Fprintln(w)
198 }
199 fmt.Fprintln(w, "\tRET")
200 }
201
202 func tagsPPC64x(w io.Writer) {
203 fmt.Fprintln(w)
204 fmt.Fprintln(w, "//go:build ppc64 || ppc64le")
205 fmt.Fprintln(w)
206 }
207
208 func zeroPPC64x(w io.Writer) {
209
210
211
212 fmt.Fprintln(w, "TEXT runtime·duffzero<ABIInternal>(SB), NOSPLIT|NOFRAME, $0-0")
213 for i := 0; i < 128; i++ {
214 fmt.Fprintln(w, "\tMOVDU\tR0, 8(R20)")
215 }
216 fmt.Fprintln(w, "\tRET")
217 }
218
219 func copyPPC64x(w io.Writer) {
220
221 fmt.Fprintln(w, "TEXT runtime·duffcopy<ABIInternal>(SB), NOSPLIT|NOFRAME, $0-0")
222 for i := 0; i < 128; i++ {
223 fmt.Fprintln(w, "\tMOVDU\t8(R20), R5")
224 fmt.Fprintln(w, "\tMOVDU\tR5, 8(R21)")
225 }
226 fmt.Fprintln(w, "\tRET")
227 }
228
229 func tagsMIPS64x(w io.Writer) {
230 fmt.Fprintln(w)
231 fmt.Fprintln(w, "//go:build mips64 || mips64le")
232 fmt.Fprintln(w)
233 }
234
235 func zeroMIPS64x(w io.Writer) {
236
237
238
239 fmt.Fprintln(w, "TEXT runtime·duffzero(SB), NOSPLIT|NOFRAME, $0-0")
240 for i := 0; i < 128; i++ {
241 fmt.Fprintln(w, "\tMOVV\tR0, 8(R1)")
242 fmt.Fprintln(w, "\tADDV\t$8, R1")
243 }
244 fmt.Fprintln(w, "\tRET")
245 }
246
247 func copyMIPS64x(w io.Writer) {
248 fmt.Fprintln(w, "TEXT runtime·duffcopy(SB), NOSPLIT|NOFRAME, $0-0")
249 for i := 0; i < 128; i++ {
250 fmt.Fprintln(w, "\tMOVV\t(R1), R23")
251 fmt.Fprintln(w, "\tADDV\t$8, R1")
252 fmt.Fprintln(w, "\tMOVV\tR23, (R2)")
253 fmt.Fprintln(w, "\tADDV\t$8, R2")
254 fmt.Fprintln(w)
255 }
256 fmt.Fprintln(w, "\tRET")
257 }
258
259 func zeroRISCV64(w io.Writer) {
260
261
262
263 fmt.Fprintln(w, "TEXT runtime·duffzero<ABIInternal>(SB), NOSPLIT|NOFRAME, $0-0")
264 for i := 0; i < 128; i++ {
265 fmt.Fprintln(w, "\tMOV\tZERO, (X25)")
266 fmt.Fprintln(w, "\tADD\t$8, X25")
267 }
268 fmt.Fprintln(w, "\tRET")
269 }
270
271 func copyRISCV64(w io.Writer) {
272
273
274
275 fmt.Fprintln(w, "TEXT runtime·duffcopy<ABIInternal>(SB), NOSPLIT|NOFRAME, $0-0")
276 for i := 0; i < 128; i++ {
277 fmt.Fprintln(w, "\tMOV\t(X24), X31")
278 fmt.Fprintln(w, "\tADD\t$8, X24")
279 fmt.Fprintln(w, "\tMOV\tX31, (X25)")
280 fmt.Fprintln(w, "\tADD\t$8, X25")
281 fmt.Fprintln(w)
282 }
283 fmt.Fprintln(w, "\tRET")
284 }
285
View as plain text