Skip to content

Commit 722a7b7

Browse files
committed
curve25519: fix confusing SP adjustments
The curve25519 assembly routines do very non-Go-ABI SP adjustments. These would thoroughly confuse traceback if it were to fire in one of these functions (say, because of a signal). Plus, we're about to make the assembler track SP balance through more operations (which it should have done all along), and the SP alignment performed by these functions is going to make the assembler think the SP is out of balance. Fix this by eliminating the SP alignment prologue from all four assembly functions. They don't do any operations that care about SP alignment, so this is simply unnecessary. square and freeze don't even use the stack for anything other that saving what were presumably "callee save" registers in some other ABI, so for these we can eliminate the stack frame entirely. Change-Id: If9dbb2fb6800d9cd733daa91f483eb2937e95f0f Reviewed-on: https://go-review.googlesource.com/31579 Run-TryBot: Austin Clements <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Minux Ma <[email protected]> Reviewed-by: Adam Langley <[email protected]>
1 parent 3ded668 commit 722a7b7

File tree

4 files changed

+4
-64
lines changed

4 files changed

+4
-64
lines changed

curve25519/freeze_amd64.s

+1-24
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,9 @@
88
// +build amd64,!gccgo,!appengine
99

1010
// func freeze(inout *[5]uint64)
11-
TEXT ·freeze(SB),7,$96-8
11+
TEXT ·freeze(SB),7,$0-8
1212
MOVQ inout+0(FP), DI
1313

14-
MOVQ SP,R11
15-
MOVQ $31,CX
16-
NOTQ CX
17-
ANDQ CX,SP
18-
ADDQ $32,SP
19-
20-
MOVQ R11,0(SP)
21-
MOVQ R12,8(SP)
22-
MOVQ R13,16(SP)
23-
MOVQ R14,24(SP)
24-
MOVQ R15,32(SP)
25-
MOVQ BX,40(SP)
26-
MOVQ BP,48(SP)
2714
MOVQ 0(DI),SI
2815
MOVQ 8(DI),DX
2916
MOVQ 16(DI),CX
@@ -81,14 +68,4 @@ REDUCELOOP:
8168
MOVQ CX,16(DI)
8269
MOVQ R8,24(DI)
8370
MOVQ R9,32(DI)
84-
MOVQ 0(SP),R11
85-
MOVQ 8(SP),R12
86-
MOVQ 16(SP),R13
87-
MOVQ 24(SP),R14
88-
MOVQ 32(SP),R15
89-
MOVQ 40(SP),BX
90-
MOVQ 48(SP),BP
91-
MOVQ R11,SP
92-
MOVQ DI,AX
93-
MOVQ SI,DX
9471
RET

curve25519/ladderstep_amd64.s

+1-8
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,9 @@
88
// +build amd64,!gccgo,!appengine
99

1010
// func ladderstep(inout *[5][5]uint64)
11-
TEXT ·ladderstep(SB),0,$384-8
11+
TEXT ·ladderstep(SB),0,$352-8
1212
MOVQ inout+0(FP),DI
1313

14-
MOVQ SP,R11
15-
MOVQ $31,CX
16-
NOTQ CX
17-
ANDQ CX,SP
18-
ADDQ $32,SP
19-
2014
MOVQ R11,0(SP)
2115
MOVQ R12,8(SP)
2216
MOVQ R13,16(SP)
@@ -1392,7 +1386,6 @@ TEXT ·ladderstep(SB),0,$384-8
13921386
MOVQ 32(SP),R15
13931387
MOVQ 40(SP),BX
13941388
MOVQ 48(SP),BP
1395-
MOVQ R11,SP
13961389
MOVQ DI,AX
13971390
MOVQ SI,DX
13981391
RET

curve25519/mul_amd64.s

+1-8
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,11 @@
88
// +build amd64,!gccgo,!appengine
99

1010
// func mul(dest, a, b *[5]uint64)
11-
TEXT ·mul(SB),0,$128-24
11+
TEXT ·mul(SB),0,$80-24
1212
MOVQ dest+0(FP), DI
1313
MOVQ a+8(FP), SI
1414
MOVQ b+16(FP), DX
1515

16-
MOVQ SP,R11
17-
MOVQ $31,CX
18-
NOTQ CX
19-
ANDQ CX,SP
20-
ADDQ $32,SP
21-
2216
MOVQ R11,0(SP)
2317
MOVQ R12,8(SP)
2418
MOVQ R13,16(SP)
@@ -185,7 +179,6 @@ TEXT ·mul(SB),0,$128-24
185179
MOVQ 32(SP),R15
186180
MOVQ 40(SP),BX
187181
MOVQ 48(SP),BP
188-
MOVQ R11,SP
189182
MOVQ DI,AX
190183
MOVQ SI,DX
191184
RET

curve25519/square_amd64.s

+1-24
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,10 @@
88
// +build amd64,!gccgo,!appengine
99

1010
// func square(out, in *[5]uint64)
11-
TEXT ·square(SB),7,$96-16
11+
TEXT ·square(SB),7,$0-16
1212
MOVQ out+0(FP), DI
1313
MOVQ in+8(FP), SI
1414

15-
MOVQ SP,R11
16-
MOVQ $31,CX
17-
NOTQ CX
18-
ANDQ CX,SP
19-
ADDQ $32, SP
20-
21-
MOVQ R11,0(SP)
22-
MOVQ R12,8(SP)
23-
MOVQ R13,16(SP)
24-
MOVQ R14,24(SP)
25-
MOVQ R15,32(SP)
26-
MOVQ BX,40(SP)
27-
MOVQ BP,48(SP)
2815
MOVQ 0(SI),AX
2916
MULQ 0(SI)
3017
MOVQ AX,CX
@@ -140,14 +127,4 @@ TEXT ·square(SB),7,$96-16
140127
MOVQ R9,16(DI)
141128
MOVQ AX,24(DI)
142129
MOVQ R10,32(DI)
143-
MOVQ 0(SP),R11
144-
MOVQ 8(SP),R12
145-
MOVQ 16(SP),R13
146-
MOVQ 24(SP),R14
147-
MOVQ 32(SP),R15
148-
MOVQ 40(SP),BX
149-
MOVQ 48(SP),BP
150-
MOVQ R11,SP
151-
MOVQ DI,AX
152-
MOVQ SI,DX
153130
RET

0 commit comments

Comments
 (0)