summaryrefslogtreecommitdiff
path: root/ext/ed25519-amd64-asm/heap_rootreplaced.s
blob: 8fe385b47a3de6a7d84fba96cc5f6d033f8263a5 (plain)
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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476

# qhasm: int64 hp

# qhasm: int64 hlen

# qhasm: int64 sp

# qhasm: int64 pp

# qhasm: input hp

# qhasm: input hlen

# qhasm: input sp

# qhasm: int64 prc

# qhasm: int64 plc

# qhasm: int64 pc

# qhasm: int64 d

# qhasm: int64 spp

# qhasm: int64 sprc

# qhasm: int64 spc

# qhasm: int64 c0

# qhasm: int64 c1

# qhasm: int64 c2

# qhasm: int64 c3

# qhasm: int64 t0

# qhasm: int64 t1

# qhasm: int64 t2

# qhasm: int64 t3

# qhasm: int64 p0

# qhasm: int64 p1

# qhasm: int64 p2

# qhasm: int64 p3

# qhasm:   int64 caller1

# qhasm:   int64 caller2

# qhasm:   int64 caller3

# qhasm:   int64 caller4

# qhasm:   int64 caller5

# qhasm:   int64 caller6

# qhasm:   int64 caller7

# qhasm:   caller caller1

# qhasm:   caller caller2

# qhasm:   caller caller3

# qhasm:   caller caller4

# qhasm:   caller caller5

# qhasm:   caller caller6

# qhasm:   caller caller7

# qhasm:   stack64 caller1_stack

# qhasm:   stack64 caller2_stack

# qhasm:   stack64 caller3_stack

# qhasm:   stack64 caller4_stack

# qhasm:   stack64 caller5_stack

# qhasm:   stack64 caller6_stack

# qhasm:   stack64 caller7_stack

# qhasm: enter crypto_sign_ed25519_amd64_64_heap_rootreplaced
.text
.p2align 5
.globl _crypto_sign_ed25519_amd64_64_heap_rootreplaced
.globl crypto_sign_ed25519_amd64_64_heap_rootreplaced
_crypto_sign_ed25519_amd64_64_heap_rootreplaced:
crypto_sign_ed25519_amd64_64_heap_rootreplaced:
mov %rsp,%r11
and $31,%r11
add $64,%r11
sub %r11,%rsp

# qhasm: caller1_stack = caller1
# asm 1: movq <caller1=int64#9,>caller1_stack=stack64#1
# asm 2: movq <caller1=%r11,>caller1_stack=0(%rsp)
movq %r11,0(%rsp)

# qhasm: caller2_stack = caller2
# asm 1: movq <caller2=int64#10,>caller2_stack=stack64#2
# asm 2: movq <caller2=%r12,>caller2_stack=8(%rsp)
movq %r12,8(%rsp)

# qhasm: caller3_stack = caller3
# asm 1: movq <caller3=int64#11,>caller3_stack=stack64#3
# asm 2: movq <caller3=%r13,>caller3_stack=16(%rsp)
movq %r13,16(%rsp)

# qhasm: caller4_stack = caller4
# asm 1: movq <caller4=int64#12,>caller4_stack=stack64#4
# asm 2: movq <caller4=%r14,>caller4_stack=24(%rsp)
movq %r14,24(%rsp)

# qhasm: caller5_stack = caller5
# asm 1: movq <caller5=int64#13,>caller5_stack=stack64#5
# asm 2: movq <caller5=%r15,>caller5_stack=32(%rsp)
movq %r15,32(%rsp)

# qhasm: caller6_stack = caller6
# asm 1: movq <caller6=int64#14,>caller6_stack=stack64#6
# asm 2: movq <caller6=%rbx,>caller6_stack=40(%rsp)
movq %rbx,40(%rsp)

# qhasm: caller7_stack = caller7
# asm 1: movq <caller7=int64#15,>caller7_stack=stack64#7
# asm 2: movq <caller7=%rbp,>caller7_stack=48(%rsp)
movq %rbp,48(%rsp)

# qhasm: pp = 0
# asm 1: mov  $0,>pp=int64#4
# asm 2: mov  $0,>pp=%rcx
mov  $0,%rcx

# qhasm: siftdownloop:
._siftdownloop:

# qhasm: prc = pp
# asm 1: mov  <pp=int64#4,>prc=int64#5
# asm 2: mov  <pp=%rcx,>prc=%r8
mov  %rcx,%r8

# qhasm: prc *= 2
# asm 1: imulq  $2,<prc=int64#5,>prc=int64#5
# asm 2: imulq  $2,<prc=%r8,>prc=%r8
imulq  $2,%r8,%r8

# qhasm: pc = prc
# asm 1: mov  <prc=int64#5,>pc=int64#6
# asm 2: mov  <prc=%r8,>pc=%r9
mov  %r8,%r9

# qhasm: prc += 2
# asm 1: add  $2,<prc=int64#5
# asm 2: add  $2,<prc=%r8
add  $2,%r8

# qhasm: pc += 1
# asm 1: add  $1,<pc=int64#6
# asm 2: add  $1,<pc=%r9
add  $1,%r9

# qhasm: unsigned>? hlen - prc
# asm 1: cmp  <prc=int64#5,<hlen=int64#2
# asm 2: cmp  <prc=%r8,<hlen=%rsi
cmp  %r8,%rsi
# comment:fp stack unchanged by jump

# qhasm: goto siftuploop if !unsigned>
jbe ._siftuploop

# qhasm: sprc = *(uint64 *)(hp + prc * 8)
# asm 1: movq   (<hp=int64#1,<prc=int64#5,8),>sprc=int64#7
# asm 2: movq   (<hp=%rdi,<prc=%r8,8),>sprc=%rax
movq   (%rdi,%r8,8),%rax

# qhasm: sprc <<= 5
# asm 1: shl  $5,<sprc=int64#7
# asm 2: shl  $5,<sprc=%rax
shl  $5,%rax

# qhasm: sprc += sp
# asm 1: add  <sp=int64#3,<sprc=int64#7
# asm 2: add  <sp=%rdx,<sprc=%rax
add  %rdx,%rax

# qhasm: spc = *(uint64 *)(hp + pc * 8)
# asm 1: movq   (<hp=int64#1,<pc=int64#6,8),>spc=int64#8
# asm 2: movq   (<hp=%rdi,<pc=%r9,8),>spc=%r10
movq   (%rdi,%r9,8),%r10

# qhasm: spc <<= 5
# asm 1: shl  $5,<spc=int64#8
# asm 2: shl  $5,<spc=%r10
shl  $5,%r10

# qhasm: spc += sp
# asm 1: add  <sp=int64#3,<spc=int64#8
# asm 2: add  <sp=%rdx,<spc=%r10
add  %rdx,%r10

# qhasm: c0 = *(uint64 *)(spc +  0)
# asm 1: movq   0(<spc=int64#8),>c0=int64#9
# asm 2: movq   0(<spc=%r10),>c0=%r11
movq   0(%r10),%r11

# qhasm: c1 = *(uint64 *)(spc +  8)
# asm 1: movq   8(<spc=int64#8),>c1=int64#10
# asm 2: movq   8(<spc=%r10),>c1=%r12
movq   8(%r10),%r12

# qhasm: c2 = *(uint64 *)(spc + 16)
# asm 1: movq   16(<spc=int64#8),>c2=int64#11
# asm 2: movq   16(<spc=%r10),>c2=%r13
movq   16(%r10),%r13

# qhasm: c3 = *(uint64 *)(spc + 24)
# asm 1: movq   24(<spc=int64#8),>c3=int64#12
# asm 2: movq   24(<spc=%r10),>c3=%r14
movq   24(%r10),%r14

# qhasm: carry? c0 -= *(uint64 *)(sprc +  0)
# asm 1: subq 0(<sprc=int64#7),<c0=int64#9
# asm 2: subq 0(<sprc=%rax),<c0=%r11
subq 0(%rax),%r11

# qhasm: carry? c1 -= *(uint64 *)(sprc +  8) - carry
# asm 1: sbbq 8(<sprc=int64#7),<c1=int64#10
# asm 2: sbbq 8(<sprc=%rax),<c1=%r12
sbbq 8(%rax),%r12

# qhasm: carry? c2 -= *(uint64 *)(sprc + 16) - carry
# asm 1: sbbq 16(<sprc=int64#7),<c2=int64#11
# asm 2: sbbq 16(<sprc=%rax),<c2=%r13
sbbq 16(%rax),%r13

# qhasm: carry? c3 -= *(uint64 *)(sprc + 24) - carry
# asm 1: sbbq 24(<sprc=int64#7),<c3=int64#12
# asm 2: sbbq 24(<sprc=%rax),<c3=%r14
sbbq 24(%rax),%r14

# qhasm: pc = prc if carry
# asm 1: cmovc <prc=int64#5,<pc=int64#6
# asm 2: cmovc <prc=%r8,<pc=%r9
cmovc %r8,%r9

# qhasm: spc = sprc if carry
# asm 1: cmovc <sprc=int64#7,<spc=int64#8
# asm 2: cmovc <sprc=%rax,<spc=%r10
cmovc %rax,%r10

# qhasm: spc -= sp
# asm 1: sub  <sp=int64#3,<spc=int64#8
# asm 2: sub  <sp=%rdx,<spc=%r10
sub  %rdx,%r10

# qhasm: (uint64) spc >>= 5
# asm 1: shr  $5,<spc=int64#8
# asm 2: shr  $5,<spc=%r10
shr  $5,%r10

# qhasm: spp = *(uint64 *)(hp + pp * 8)
# asm 1: movq   (<hp=int64#1,<pp=int64#4,8),>spp=int64#5
# asm 2: movq   (<hp=%rdi,<pp=%rcx,8),>spp=%r8
movq   (%rdi,%rcx,8),%r8

# qhasm: *(uint64 *)(hp + pp * 8) = spc
# asm 1: movq  <spc=int64#8,(<hp=int64#1,<pp=int64#4,8)
# asm 2: movq  <spc=%r10,(<hp=%rdi,<pp=%rcx,8)
movq  %r10,(%rdi,%rcx,8)

# qhasm: *(uint64 *)(hp + pc * 8) = spp
# asm 1: movq  <spp=int64#5,(<hp=int64#1,<pc=int64#6,8)
# asm 2: movq  <spp=%r8,(<hp=%rdi,<pc=%r9,8)
movq  %r8,(%rdi,%r9,8)

# qhasm: pp = pc
# asm 1: mov  <pc=int64#6,>pp=int64#4
# asm 2: mov  <pc=%r9,>pp=%rcx
mov  %r9,%rcx
# comment:fp stack unchanged by jump

# qhasm: goto siftdownloop
jmp ._siftdownloop

# qhasm: siftuploop:
._siftuploop:

# qhasm: pc = pp
# asm 1: mov  <pp=int64#4,>pc=int64#2
# asm 2: mov  <pp=%rcx,>pc=%rsi
mov  %rcx,%rsi

# qhasm: pp -= 1
# asm 1: sub  $1,<pp=int64#4
# asm 2: sub  $1,<pp=%rcx
sub  $1,%rcx

# qhasm: (uint64) pp >>= 1
# asm 1: shr  $1,<pp=int64#4
# asm 2: shr  $1,<pp=%rcx
shr  $1,%rcx

# qhasm: unsigned>? pc - 0 
# asm 1: cmp  $0,<pc=int64#2
# asm 2: cmp  $0,<pc=%rsi
cmp  $0,%rsi
# comment:fp stack unchanged by jump

# qhasm: goto end if !unsigned>
jbe ._end

# qhasm: spp = *(uint64 *)(hp + pp * 8)
# asm 1: movq   (<hp=int64#1,<pp=int64#4,8),>spp=int64#5
# asm 2: movq   (<hp=%rdi,<pp=%rcx,8),>spp=%r8
movq   (%rdi,%rcx,8),%r8

# qhasm: spc = *(uint64 *)(hp + pc * 8)
# asm 1: movq   (<hp=int64#1,<pc=int64#2,8),>spc=int64#6
# asm 2: movq   (<hp=%rdi,<pc=%rsi,8),>spc=%r9
movq   (%rdi,%rsi,8),%r9

# qhasm: spp <<= 5
# asm 1: shl  $5,<spp=int64#5
# asm 2: shl  $5,<spp=%r8
shl  $5,%r8

# qhasm: spc <<= 5
# asm 1: shl  $5,<spc=int64#6
# asm 2: shl  $5,<spc=%r9
shl  $5,%r9

# qhasm: spc += sp
# asm 1: add  <sp=int64#3,<spc=int64#6
# asm 2: add  <sp=%rdx,<spc=%r9
add  %rdx,%r9

# qhasm: spp += sp
# asm 1: add  <sp=int64#3,<spp=int64#5
# asm 2: add  <sp=%rdx,<spp=%r8
add  %rdx,%r8

# qhasm: c0 = *(uint64 *)(spc +  0)
# asm 1: movq   0(<spc=int64#6),>c0=int64#7
# asm 2: movq   0(<spc=%r9),>c0=%rax
movq   0(%r9),%rax

# qhasm: c1 = *(uint64 *)(spc +  8)
# asm 1: movq   8(<spc=int64#6),>c1=int64#8
# asm 2: movq   8(<spc=%r9),>c1=%r10
movq   8(%r9),%r10

# qhasm: c2 = *(uint64 *)(spc + 16)
# asm 1: movq   16(<spc=int64#6),>c2=int64#9
# asm 2: movq   16(<spc=%r9),>c2=%r11
movq   16(%r9),%r11

# qhasm: c3 = *(uint64 *)(spc + 24)
# asm 1: movq   24(<spc=int64#6),>c3=int64#10
# asm 2: movq   24(<spc=%r9),>c3=%r12
movq   24(%r9),%r12

# qhasm: carry? c0 -= *(uint64 *)(spp +  0)
# asm 1: subq 0(<spp=int64#5),<c0=int64#7
# asm 2: subq 0(<spp=%r8),<c0=%rax
subq 0(%r8),%rax

# qhasm: carry? c1 -= *(uint64 *)(spp +  8) - carry
# asm 1: sbbq 8(<spp=int64#5),<c1=int64#8
# asm 2: sbbq 8(<spp=%r8),<c1=%r10
sbbq 8(%r8),%r10

# qhasm: carry? c2 -= *(uint64 *)(spp + 16) - carry
# asm 1: sbbq 16(<spp=int64#5),<c2=int64#9
# asm 2: sbbq 16(<spp=%r8),<c2=%r11
sbbq 16(%r8),%r11

# qhasm: carry? c3 -= *(uint64 *)(spp + 24) - carry
# asm 1: sbbq 24(<spp=int64#5),<c3=int64#10
# asm 2: sbbq 24(<spp=%r8),<c3=%r12
sbbq 24(%r8),%r12
# comment:fp stack unchanged by jump

# qhasm: goto end if carry
jc ._end

# qhasm: spc -= sp
# asm 1: sub  <sp=int64#3,<spc=int64#6
# asm 2: sub  <sp=%rdx,<spc=%r9
sub  %rdx,%r9

# qhasm: (uint64) spc >>= 5
# asm 1: shr  $5,<spc=int64#6
# asm 2: shr  $5,<spc=%r9
shr  $5,%r9

# qhasm: spp -= sp
# asm 1: sub  <sp=int64#3,<spp=int64#5
# asm 2: sub  <sp=%rdx,<spp=%r8
sub  %rdx,%r8

# qhasm: (uint64) spp >>= 5
# asm 1: shr  $5,<spp=int64#5
# asm 2: shr  $5,<spp=%r8
shr  $5,%r8

# qhasm: *(uint64 *)(hp + pp * 8) = spc
# asm 1: movq  <spc=int64#6,(<hp=int64#1,<pp=int64#4,8)
# asm 2: movq  <spc=%r9,(<hp=%rdi,<pp=%rcx,8)
movq  %r9,(%rdi,%rcx,8)

# qhasm: *(uint64 *)(hp + pc * 8) = spp
# asm 1: movq  <spp=int64#5,(<hp=int64#1,<pc=int64#2,8)
# asm 2: movq  <spp=%r8,(<hp=%rdi,<pc=%rsi,8)
movq  %r8,(%rdi,%rsi,8)
# comment:fp stack unchanged by jump

# qhasm: goto siftuploop
jmp ._siftuploop

# qhasm: end:
._end:

# qhasm: caller1 = caller1_stack
# asm 1: movq <caller1_stack=stack64#1,>caller1=int64#9
# asm 2: movq <caller1_stack=0(%rsp),>caller1=%r11
movq 0(%rsp),%r11

# qhasm: caller2 = caller2_stack
# asm 1: movq <caller2_stack=stack64#2,>caller2=int64#10
# asm 2: movq <caller2_stack=8(%rsp),>caller2=%r12
movq 8(%rsp),%r12

# qhasm: caller3 = caller3_stack
# asm 1: movq <caller3_stack=stack64#3,>caller3=int64#11
# asm 2: movq <caller3_stack=16(%rsp),>caller3=%r13
movq 16(%rsp),%r13

# qhasm: caller4 = caller4_stack
# asm 1: movq <caller4_stack=stack64#4,>caller4=int64#12
# asm 2: movq <caller4_stack=24(%rsp),>caller4=%r14
movq 24(%rsp),%r14

# qhasm: caller5 = caller5_stack
# asm 1: movq <caller5_stack=stack64#5,>caller5=int64#13
# asm 2: movq <caller5_stack=32(%rsp),>caller5=%r15
movq 32(%rsp),%r15

# qhasm: caller6 = caller6_stack
# asm 1: movq <caller6_stack=stack64#6,>caller6=int64#14
# asm 2: movq <caller6_stack=40(%rsp),>caller6=%rbx
movq 40(%rsp),%rbx

# qhasm: caller7 = caller7_stack
# asm 1: movq <caller7_stack=stack64#7,>caller7=int64#15
# asm 2: movq <caller7_stack=48(%rsp),>caller7=%rbp
movq 48(%rsp),%rbp

# qhasm: leave
add %r11,%rsp
mov %rdi,%rax
mov %rsi,%rdx
ret