-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathsort_amd64.s
372 lines (344 loc) · 7.46 KB
/
sort_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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
// Code generated by command: go run sort_asm.go -pkg qsort -out ../qsort/sort_amd64.s -stubs ../qsort/sort_amd64.go. DO NOT EDIT.
//go:build !purego
#include "textflag.h"
// func distributeForward64(data []uint64, scratch []uint64, limit int, lo int, hi int) int
// Requires: CMOV
TEXT ·distributeForward64(SB), NOSPLIT, $0-80
MOVQ data_base+0(FP), AX
MOVQ scratch_base+24(FP), CX
MOVQ limit+48(FP), DX
MOVQ lo+56(FP), BX
MOVQ hi+64(FP), SI
LEAQ (AX)(BX*8), BX
LEAQ (AX)(SI*8), SI
LEAQ -8(CX)(DX*8), CX
MOVQ (AX), DI
XORQ R8, R8
XORQ R9, R9
NEGQ DX
loop:
MOVQ (BX), R10
CMPQ R10, DI
MOVQ BX, R11
CMOVQCC CX, R11
MOVQ R10, (R11)(R8*8)
CMC
SBBQ R9, R8
ADDQ $0x08, BX
CMPQ BX, SI
JA done
CMPQ R8, DX
JNE loop
done:
SUBQ AX, BX
LEAQ (BX)(R8*8), BX
SHRQ $0x03, BX
DECQ BX
MOVQ BX, ret+72(FP)
RET
// func distributeBackward64(data []uint64, scratch []uint64, limit int, lo int, hi int) int
// Requires: CMOV
TEXT ·distributeBackward64(SB), NOSPLIT, $0-80
MOVQ data_base+0(FP), AX
MOVQ scratch_base+24(FP), CX
MOVQ limit+48(FP), DX
MOVQ lo+56(FP), BX
MOVQ hi+64(FP), SI
LEAQ (AX)(BX*8), BX
LEAQ (AX)(SI*8), SI
MOVQ (AX), DI
XORQ R8, R8
XORQ R9, R9
CMPQ SI, BX
JBE done
loop:
MOVQ (SI), R10
CMPQ R10, DI
MOVQ CX, R11
CMOVQCC SI, R11
MOVQ R10, (R11)(R8*8)
ADCQ R9, R8
SUBQ $0x08, SI
CMPQ SI, BX
JBE done
CMPQ R8, DX
JNE loop
done:
SUBQ AX, SI
LEAQ (SI)(R8*8), SI
SHRQ $0x03, SI
MOVQ SI, ret+72(FP)
RET
// func insertionsort128NoSwap(data []struct{hi uint64; lo uint64}, base int, swap func(int, int))
// Requires: AVX
TEXT ·insertionsort128NoSwap(SB), NOSPLIT, $0-40
MOVQ data_base+0(FP), AX
MOVQ data_len+8(FP), CX
SHLQ $0x04, CX
ADDQ AX, CX
TESTQ AX, CX
JE done
VPCMPEQB X0, X0, X0
VPSLLQ $0x3f, X0, X0
MOVQ AX, DX
outer:
ADDQ $0x10, DX
CMPQ DX, CX
JAE done
VMOVDQU (DX), X1
MOVQ DX, BX
inner:
VMOVDQU -16(BX), X2
VPCMPEQQ X1, X2, X3
VPADDQ X1, X0, X4
VPADDQ X2, X0, X5
VPCMPGTQ X4, X5, X4
VMOVMSKPD X3, SI
VMOVMSKPD X4, DI
NOTL SI
BSFL SI, R8
BTSL R8, DI
JAE outer
VMOVDQU X2, (BX)
VMOVDQU X1, -16(BX)
SUBQ $0x10, BX
CMPQ BX, AX
JA inner
JMP outer
done:
RET
// func distributeForward128(data []struct{hi uint64; lo uint64}, scratch []struct{hi uint64; lo uint64}, limit int, lo int, hi int) int
// Requires: AVX, CMOV
TEXT ·distributeForward128(SB), NOSPLIT, $0-80
MOVQ data_base+0(FP), AX
MOVQ scratch_base+24(FP), CX
MOVQ limit+48(FP), DX
MOVQ lo+56(FP), BX
MOVQ hi+64(FP), SI
SHLQ $0x04, DX
SHLQ $0x04, BX
SHLQ $0x04, SI
LEAQ (AX)(BX*1), BX
LEAQ (AX)(SI*1), SI
LEAQ -16(CX)(DX*1), CX
VPCMPEQB X0, X0, X0
VPSLLQ $0x3f, X0, X0
VMOVDQU (AX), X1
XORQ R8, R8
XORQ R9, R9
NEGQ DX
loop:
VMOVDQU (BX), X2
VPCMPEQQ X2, X1, X3
VPADDQ X2, X0, X4
VPADDQ X1, X0, X5
VPCMPGTQ X4, X5, X4
VMOVMSKPD X3, R10
VMOVMSKPD X4, R11
NOTL R10
BSFL R10, DI
BTSL DI, R11
MOVQ BX, R10
CMOVQCC CX, R10
VMOVDQU X2, (R10)(R8*1)
SETCC R9
SHLQ $0x04, R9
SUBQ R9, R8
ADDQ $0x10, BX
CMPQ BX, SI
JA done
CMPQ R8, DX
JNE loop
done:
SUBQ AX, BX
LEAQ (BX)(R8*1), BX
SHRQ $0x04, BX
DECQ BX
MOVQ BX, ret+72(FP)
RET
// func distributeBackward128(data []struct{hi uint64; lo uint64}, scratch []struct{hi uint64; lo uint64}, limit int, lo int, hi int) int
// Requires: AVX, CMOV
TEXT ·distributeBackward128(SB), NOSPLIT, $0-80
MOVQ data_base+0(FP), AX
MOVQ scratch_base+24(FP), CX
MOVQ limit+48(FP), DX
MOVQ lo+56(FP), BX
MOVQ hi+64(FP), SI
SHLQ $0x04, DX
SHLQ $0x04, BX
SHLQ $0x04, SI
LEAQ (AX)(BX*1), BX
LEAQ (AX)(SI*1), SI
VPCMPEQB X0, X0, X0
VPSLLQ $0x3f, X0, X0
VMOVDQU (AX), X1
XORQ R8, R8
XORQ R9, R9
CMPQ SI, BX
JBE done
loop:
VMOVDQU (SI), X2
VPCMPEQQ X2, X1, X3
VPADDQ X2, X0, X4
VPADDQ X1, X0, X5
VPCMPGTQ X4, X5, X4
VMOVMSKPD X3, R10
VMOVMSKPD X4, R11
NOTL R10
BSFL R10, DI
BTSL DI, R11
MOVQ CX, R10
CMOVQCC SI, R10
VMOVDQU X2, (R10)(R8*1)
SETCS R9
SHLQ $0x04, R9
ADDQ R9, R8
SUBQ $0x10, SI
CMPQ SI, BX
JBE done
CMPQ R8, DX
JNE loop
done:
SUBQ AX, SI
LEAQ (SI)(R8*1), SI
SHRQ $0x04, SI
MOVQ SI, ret+72(FP)
RET
// func insertionsort256NoSwap(data []struct{a uint64; b uint64; c uint64; d uint64}, base int, swap func(int, int))
// Requires: AVX, AVX2
TEXT ·insertionsort256NoSwap(SB), NOSPLIT, $0-40
MOVQ data_base+0(FP), AX
MOVQ data_len+8(FP), CX
SHLQ $0x05, CX
ADDQ AX, CX
TESTQ AX, CX
JE done
VPCMPEQB Y0, Y0, Y0
VPSLLQ $0x3f, Y0, Y0
MOVQ AX, DX
outer:
ADDQ $0x20, DX
CMPQ DX, CX
JAE done
VMOVDQU (DX), Y1
MOVQ DX, BX
inner:
VMOVDQU -32(BX), Y2
VPCMPEQQ Y1, Y2, Y3
VPADDQ Y1, Y0, Y4
VPADDQ Y2, Y0, Y5
VPCMPGTQ Y4, Y5, Y4
VMOVMSKPD Y3, SI
VMOVMSKPD Y4, DI
NOTL SI
BSFL SI, R8
BTSL R8, DI
JAE outer
VMOVDQU Y2, (BX)
VMOVDQU Y1, -32(BX)
SUBQ $0x20, BX
CMPQ BX, AX
JA inner
JMP outer
done:
VZEROUPPER
RET
// func distributeForward256(data []struct{a uint64; b uint64; c uint64; d uint64}, scratch []struct{a uint64; b uint64; c uint64; d uint64}, limit int, lo int, hi int) int
// Requires: AVX, AVX2, CMOV
TEXT ·distributeForward256(SB), NOSPLIT, $0-80
MOVQ data_base+0(FP), AX
MOVQ scratch_base+24(FP), CX
MOVQ limit+48(FP), DX
MOVQ lo+56(FP), BX
MOVQ hi+64(FP), SI
SHLQ $0x05, DX
SHLQ $0x05, BX
SHLQ $0x05, SI
LEAQ (AX)(BX*1), BX
LEAQ (AX)(SI*1), SI
LEAQ -32(CX)(DX*1), CX
VPCMPEQB Y0, Y0, Y0
VPSLLQ $0x3f, Y0, Y0
VMOVDQU (AX), Y1
XORQ R8, R8
XORQ R9, R9
NEGQ DX
loop:
VMOVDQU (BX), Y2
VPCMPEQQ Y2, Y1, Y3
VPADDQ Y2, Y0, Y4
VPADDQ Y1, Y0, Y5
VPCMPGTQ Y4, Y5, Y4
VMOVMSKPD Y3, R10
VMOVMSKPD Y4, R11
NOTL R10
BSFL R10, DI
BTSL DI, R11
MOVQ BX, R10
CMOVQCC CX, R10
VMOVDQU Y2, (R10)(R8*1)
SETCC R9
SHLQ $0x05, R9
SUBQ R9, R8
ADDQ $0x20, BX
CMPQ BX, SI
JA done
CMPQ R8, DX
JNE loop
done:
SUBQ AX, BX
LEAQ (BX)(R8*1), BX
SHRQ $0x05, BX
DECQ BX
MOVQ BX, ret+72(FP)
VZEROUPPER
RET
// func distributeBackward256(data []struct{a uint64; b uint64; c uint64; d uint64}, scratch []struct{a uint64; b uint64; c uint64; d uint64}, limit int, lo int, hi int) int
// Requires: AVX, AVX2, CMOV
TEXT ·distributeBackward256(SB), NOSPLIT, $0-80
MOVQ data_base+0(FP), AX
MOVQ scratch_base+24(FP), CX
MOVQ limit+48(FP), DX
MOVQ lo+56(FP), BX
MOVQ hi+64(FP), SI
SHLQ $0x05, DX
SHLQ $0x05, BX
SHLQ $0x05, SI
LEAQ (AX)(BX*1), BX
LEAQ (AX)(SI*1), SI
VPCMPEQB Y0, Y0, Y0
VPSLLQ $0x3f, Y0, Y0
VMOVDQU (AX), Y1
XORQ R8, R8
XORQ R9, R9
CMPQ SI, BX
JBE done
loop:
VMOVDQU (SI), Y2
VPCMPEQQ Y2, Y1, Y3
VPADDQ Y2, Y0, Y4
VPADDQ Y1, Y0, Y5
VPCMPGTQ Y4, Y5, Y4
VMOVMSKPD Y3, R10
VMOVMSKPD Y4, R11
NOTL R10
BSFL R10, DI
BTSL DI, R11
MOVQ CX, R10
CMOVQCC SI, R10
VMOVDQU Y2, (R10)(R8*1)
SETCS R9
SHLQ $0x05, R9
ADDQ R9, R8
SUBQ $0x20, SI
CMPQ SI, BX
JBE done
CMPQ R8, DX
JNE loop
done:
SUBQ AX, SI
LEAQ (SI)(R8*1), SI
SHRQ $0x05, SI
MOVQ SI, ret+72(FP)
VZEROUPPER
RET