1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
diff --git a/testdata/benchmarks/asm-plain.go b/testdata/benchmarks/asm-plain.go
index e5ee89730f98a022ccb7cae0e0b8672e371519fd..fdeb4ed02563288d3a57de549a6cdefbbbf732e7 100644
--- a/testdata/benchmarks/asm-plain.go
+++ b/testdata/benchmarks/asm-plain.go
@@ -1,6 +1,6 @@
-// Code generated by command: go run asm.go -out asm-plain.s -stubs asm-plain.go -pkg yenc. DO NOT EDIT.
+// Code generated by command: go run asm-plain_gen.go -pkg yenc -stubs asm-plain.go -out asm-plain.s. DO NOT EDIT.
package yenc
// yenc encode using x86 assembler instructions
-func Assembler(input []byte, output []byte)
+func AssemblerPlain(input []byte, output []byte)
diff --git a/testdata/benchmarks/asm-plain.s b/testdata/benchmarks/asm-plain.s
index 652ad4022198f791b65b06cbf015ae4bb879eb4b..ca9b7be10a847b7ce4a7e65216ef7f6bc2d69315 100644
--- a/testdata/benchmarks/asm-plain.s
+++ b/testdata/benchmarks/asm-plain.s
@@ -1,8 +1,8 @@
-// Code generated by command: go run asm.go -out asm-plain.s -stubs asm-plain.go -pkg yenc. DO NOT EDIT.
+// Code generated by command: go run asm-plain_gen.go -pkg yenc -stubs asm-plain.go -out asm-plain.s. DO NOT EDIT.
#include "textflag.h"
-DATA consts<>+0(SB)/1, $0x00
+DATA consts<>+0(SB)/1, $0x01
DATA consts<>+1(SB)/1, $0x00
DATA consts<>+2(SB)/1, $0x00
DATA consts<>+3(SB)/1, $0x00
@@ -12,10 +12,10 @@ DATA consts<>+6(SB)/1, $0x00
DATA consts<>+7(SB)/1, $0x00
DATA consts<>+8(SB)/1, $0x00
DATA consts<>+9(SB)/1, $0x00
-DATA consts<>+10(SB)/1, $0x0a
+DATA consts<>+10(SB)/1, $0x01
DATA consts<>+11(SB)/1, $0x00
DATA consts<>+12(SB)/1, $0x00
-DATA consts<>+13(SB)/1, $0x0d
+DATA consts<>+13(SB)/1, $0x01
DATA consts<>+14(SB)/1, $0x00
DATA consts<>+15(SB)/1, $0x00
DATA consts<>+16(SB)/1, $0x00
@@ -63,7 +63,7 @@ DATA consts<>+57(SB)/1, $0x00
DATA consts<>+58(SB)/1, $0x00
DATA consts<>+59(SB)/1, $0x00
DATA consts<>+60(SB)/1, $0x00
-DATA consts<>+61(SB)/1, $0x3d
+DATA consts<>+61(SB)/1, $0x01
DATA consts<>+62(SB)/1, $0x00
DATA consts<>+63(SB)/1, $0x00
DATA consts<>+64(SB)/1, $0x00
@@ -260,13 +260,13 @@ DATA consts<>+254(SB)/1, $0x00
DATA consts<>+255(SB)/1, $0x00
GLOBL consts<>(SB), RODATA|NOPTR, $256
-// func Assembler(input []byte, output []byte)
-TEXT ·Assembler(SB), NOSPLIT, $0-48
+// func AssemblerPlain(input []byte, output []byte)
+TEXT ·AssemblerPlain(SB), NOSPLIT, $0-48
// load input, input length, and output
MOVQ input_base+0(FP), AX
MOVQ input_len+8(FP), CX
MOVQ output_base+24(FP), DX
- LEAQ consts<>+0(SB), BX
+ LEAQ consts<>+0(SB), SI
encode_loop:
// when there are 0 byte left to encode, we're done
@@ -274,7 +274,7 @@ CMPQ CX, $0x00
JZ done
// load the next input value
- MOVB (AX), BL
+ MOVBQZX (AX), BX
// decrement number of bytes to be loaded and move the input pointer to the next byte
DECQ CX
@@ -284,13 +284,7 @@ // add 42
ADDB $0x2a, BL
// check if it's 0, 10, 13, or 61 and escape if so
- CMPB BL, $0x00
- JE escape
- CMPB BL, $0x0a
- JE escape
- CMPB BL, $0x0d
- JE escape
- CMPB BL, $0x3d
+ CMPB (SI)(BX*1), $0x01
JE escape
escape_done:
diff --git a/testdata/benchmarks/asm-plain_gen.go b/testdata/benchmarks/asm-plain_gen.go
index f7cfcbec6b7bc173840e3afc935300b09432e414..2851029775b9898a28a7dd14e7e516be1a297164 100644
--- a/testdata/benchmarks/asm-plain_gen.go
+++ b/testdata/benchmarks/asm-plain_gen.go
@@ -24,7 +24,7 @@ Comment("load input, input length, and output")
input := Load(Param("input").Base(), GP64())
inputLen := Load(Param("input").Len(), GP64())
output := Load(Param("output").Base(), GP64())
- value := GP8()
+ value := GP64()
LTPtr := Mem{Base: GP64()}
LEAQ(data, LTPtr.Base)
@@ -34,37 +34,31 @@ CMPQ(inputLen, Imm(0))
JZ(LabelRef("done"))
Comment("load the next input value")
- MOVB(Mem{Base: input}, value)
+ MOVBQZX(Mem{Base: input}, value)
+
Comment("decrement number of bytes to be loaded and move the input pointer to the next byte")
DECQ(inputLen)
INCQ(input)
Comment("add 42")
- ADDB(U8(0x2a), value)
+ ADDB(U8(0x2a), value.As8())
Comment("check if it's 0, 10, 13, or 61 and escape if so")
- // CMPB(LTPtr.Idx(value, 1), Imm(0x00))
- CMPB(value, Imm(0x00))
- JE(LabelRef("escape"))
- CMPB(value, Imm(0x0a))
- JE(LabelRef("escape"))
- CMPB(value, Imm(0x0d))
- JE(LabelRef("escape"))
- CMPB(value, Imm(0x3d))
+ CMPB(LTPtr.Idx(value, 1), U8(1))
JE(LabelRef("escape"))
// or fallthrough
Label("escape_done")
Comment("return encoded character")
- MOVB(value, Mem{Base: output})
+ MOVB(value.As8(), Mem{Base: output})
ADDQ(Imm(1), output)
JMP(LabelRef("encode_loop"))
// end of encode loop
Label("escape")
Comment("add 64")
- ADDB(U8(64), value)
+ ADDB(U8(64), value.As8())
Comment("write escape character to output")
MOVB(Imm(0x3d), Mem{Base: output})
ADDQ(Imm(1), output)
diff --git a/testdata/benchmarks/go.mod b/testdata/benchmarks/go.mod
index 6f06a09b52c8618c00e0ba247549acbe1b72ebc9..e02f3fa37f267d53ab03dc8badef91b96131925a 100644
--- a/testdata/benchmarks/go.mod
+++ b/testdata/benchmarks/go.mod
@@ -1,3 +1,10 @@
module benchmarks
go 1.19
+
+require (
+ github.com/mmcloughlin/avo v0.5.0 // indirect
+ golang.org/x/mod v0.6.0 // indirect
+ golang.org/x/sys v0.1.0 // indirect
+ golang.org/x/tools v0.2.0 // indirect
+)
diff --git a/testdata/benchmarks/yenc_test.go b/testdata/benchmarks/yenc_test.go
index fd129dccecf777c7e386a858c8e851ee32d966af..8cb29e61fc9146a283cbdcf1aefa39c480cddcbe 100644
--- a/testdata/benchmarks/yenc_test.go
+++ b/testdata/benchmarks/yenc_test.go
@@ -53,7 +53,7 @@ }{
{"bootleg-simd", YEncBootlegSIMD},
{"assembler", func(in [8]byte) []byte {
out := make([]byte, 16)
- Assembler(in[:], out)
+ AssemblerPlain(in[:], out)
return out
}},
}
@@ -190,7 +190,7 @@ }{
{"bootleg-simd", YEncBootlegSIMD},
{"assembler", func(in [8]byte) []byte {
out := make([]byte, 16)
- Assembler(in[:], out)
+ AssemblerPlain(in[:], out)
return out
}},
}
@@ -230,7 +230,7 @@ }{
{"bootleg-simd", YEncBootlegSIMD},
{"assembler", func(in [8]byte) []byte {
out := make([]byte, 16)
- Assembler(in[:], out)
+ AssemblerPlain(in[:], out)
return out
}},
}
@@ -284,7 +284,7 @@ fn func([16]byte) []byte
}{
{"assembler", func(in [16]byte) []byte {
out := make([]byte, 32)
- Assembler(in[:], out)
+ AssemblerPlain(in[:], out)
return out
}},
}
@@ -337,7 +337,7 @@ fn func([16]byte) []byte
}{
{"assembler", func(in [16]byte) []byte {
out := make([]byte, 32)
- Assembler(in[:], out)
+ AssemblerPlain(in[:], out)
return out
}},
}
@@ -400,7 +400,7 @@ fn func([64]byte) []byte
}{
{"assembler", func(in [64]byte) []byte {
out := make([]byte, 128)
- Assembler(in[:], out)
+ AssemblerPlain(in[:], out)
return out
}},
}
|