-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstage2-parsing_amd64.s
260 lines (237 loc) · 4.25 KB
/
stage2-parsing_amd64.s
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
//+build !noasm !appengine
// See Input struct
#define INPUT_BASE 0x38
// See Output struct
#define COLUMNS_BASE 0x0
#define INDEX_OFFSET 0x8
#define ROWS_BASE 0x10
#define LINE_OFFSET 0x18
#define INPUT_STAGE2_SEPARATOR_MASK 0
#define INPUT_STAGE2_DELIMITER_MASK 8
#define INPUT_STAGE2_QUOTE_MASK 16
#define Y_DELIMITER Y4
#define Y_SEPARATOR Y5
#define Y_QUOTE_CHAR Y6
// func stage2_parse_test(input *Input, offset uint64, output *Output)
TEXT ·stage2_parse_test(SB), 7, $0
MOVQ input+0(FP), DX
MOVQ offset+8(FP), DI
MOVQ output+16(FP), R9
CALL ·stage2_parse(SB)
RET
// func stage2_parse()
TEXT ·stage2_parse(SB), 7, $0
MOVL $0x40, BX
MOVQ (DX), SI
BSFQ SI, SI
CMOVQEQ BX, SI
MOVQ 0x8(DX), R8
BSFQ R8, R8
CMOVQEQ BX, R8
MOVQ 0x10(DX), R10
BSFQ R10, R10
CMOVQEQ BX, R10
label1:
CMPQ SI, R8
JGE label5
CMPQ SI, R10
JGE label5
CMPQ 0x18(DX), $0x0
JNE label4
MOVQ 0x28(DX), R11
TESTQ R11, R11
JBE label2
INCQ R11
LEAQ (SI)(DI*1), R12
CMPQ R12, R11
JE label2
CMPQ 0x30(DX), $0x0
JNE label2
MOVQ R12, 0x30(DX)
label2:
MOVQ $0x0, 0x28(DX)
MOVQ (R9), R11
TESTB AL, (R11)
MOVQ 0x8(R9), AX
MOVQ 0x38(DX), R12
ADDQ 0x20(R9), R12
MOVQ R12, (R11)(AX*8)
MOVQ 0x8(R9), R11
LEAQ 0x1(R11), AX
MOVQ AX, 0x8(R9)
MOVQ (R9), R12
TESTB AL, (R12)
MOVQ 0x28(R9), R13
MOVQ SI, CX
SUBQ R13, SI
ADDQ DI, SI
SUBQ 0x20(R9), SI
MOVQ SI, 0x8(R12)(R11*8)
INCQ 0x8(R9)
LEAQ (CX)(DI*1), SI
LEAQ 0x1(SI), SI
MOVQ SI, 0x20(R9)
MOVQ $0x0, 0x28(R9)
LEAQ (CX)(DI*1), SI
MOVQ SI, 0x20(DX)
label3:
MOVQ (DX), SI
CMPQ CX, $0x40
SBBQ R11, R11
MOVQ $-0x2, R12
SHLQ CL, R12
ANDQ R11, R12
ANDQ SI, R12
BSFQ R12, SI
MOVQ R12, (DX)
CMOVQEQ BX, SI
JMP label1
label4:
MOVQ SI, CX
JMP label3
label5:
CMPQ R8, SI
JGE label13
CMPQ R8, R10
JGE label13
CMPQ 0x18(DX), $0x0
JNE label12
MOVQ 0x28(DX), R11
TESTQ R11, R11
JBE label6
INCQ R11
LEAQ (R8)(DI*1), R12
CMPQ R12, R11
JE label6
CMPQ 0x30(DX), $0x0
JNE label6
MOVQ R12, 0x30(DX)
label6:
MOVQ $0x0, 0x28(DX)
MOVQ 0x28(R9), R11
MOVQ R8, CX
SUBQ R11, R8
ADDQ DI, R8
MOVQ 0x20(R9), R11
CMPQ R11, R8
JNE label11
MOVQ (R9), R8
TESTB AL, (R8)
MOVQ 0x8(R9), AX
MOVQ $0x0, (R8)(AX*8)
label7:
MOVQ 0x8(R9), R8
LEAQ 0x1(R8), AX
MOVQ AX, 0x8(R9)
MOVQ (R9), R11
TESTB AL, (R11)
MOVQ 0x28(R9), R12
MOVQ CX, R13
SUBQ R12, CX
LEAQ (CX)(DI*1), R12
SUBQ 0x20(R9), R12
MOVQ R12, 0x8(R11)(R8*8)
MOVQ 0x8(R9), AX
LEAQ 0x1(AX), R8
MOVQ R8, 0x8(R9)
LEAQ (R13)(DI*1), R11
LEAQ 0x1(R11), R11
MOVQ R11, 0x20(R9)
MOVQ $0x0, 0x28(R9)
LEAQ (R13)(DI*1), R11
SHRQ $0x1, R8
MOVQ 0x30(R9), R12
SUBQ R12, R8
CMPQ R8, $0x1
JNE label10
MOVQ (R9), R8
TESTB AL, (R8)
MOVQ (R8)(AX*8), R8
TESTQ R8, R8
JNE label10
label8:
MOVQ 0x8(R9), R8
SHRQ $0x1, R8
MOVQ R8, 0x30(R9)
MOVQ R11, 0x20(DX)
label9:
MOVQ 0x8(DX), R8
CMPQ R13, $0x40
SBBQ R11, R11
MOVQ R13, CX
MOVQ $-0x2, R12
SHLQ CL, R12
ANDQ R11, R12
ANDQ R8, R12
BSFQ R12, R8
MOVQ R12, 0x8(DX)
CMOVQEQ BX, R8
JMP label1
label10:
MOVQ 0x10(R9), R8
TESTB AL, (R8)
MOVQ 0x18(R9), AX
MOVQ R12, (R8)(AX*8)
MOVQ 0x18(R9), R8
LEAQ 0x1(R8), AX
MOVQ AX, 0x18(R9)
MOVQ 0x10(R9), R12
TESTB AL, (R12)
MOVQ 0x8(R9), R14
SHRQ $0x1, R14
SUBQ 0x30(R9), R14
MOVQ R14, 0x8(R12)(R8*8)
INCQ 0x18(R9)
JMP label8
label11:
MOVQ (R9), R8
TESTB AL, (R8)
MOVQ 0x8(R9), AX
MOVQ 0x38(DX), R12
ADDQ R12, R11
MOVQ R11, (R8)(AX*8)
JMP label7
label12:
MOVQ R8, R13
JMP label9
label13:
CMPQ R10, SI
JGE label17
CMPQ R10, R8
JGE label17
CMPQ 0x18(DX), $0x0
JNE label16
MOVQ 0x20(DX), R11
INCQ R11
LEAQ (R10)(DI*1), R12
CMPQ R11, R12
JE label14
CMPQ 0x30(DX), $0x0
JNE label14
MOVQ R12, 0x30(DX)
label14:
INCQ 0x20(R9)
label15:
MOVQ 0x18(DX), R11
NOTQ R11
MOVQ R11, 0x18(DX)
MOVQ 0x10(DX), R11
CMPQ R10, $0x40
SBBQ R12, R12
MOVQ R10, CX
MOVQ $-0x2, R13
SHLQ CL, R13
ANDQ R13, R12
ANDQ R11, R12
BSFQ R12, R11
MOVQ R12, 0x10(DX)
CMOVQEQ BX, R11
MOVQ R11, R10
JMP label1
label16:
INCQ 0x28(R9)
LEAQ (R10)(DI*1), R11
MOVQ R11, 0x28(DX)
JMP label15
label17:
RET