Skip to content

Commit 14e8a39

Browse files
committed
[PPC64LE] poly_tomont: trim dead callee-saved spills (frame 320->224)
The prologue saved and restored v20-v30, but the body only clobbers v23, v24, and v27-v30. v20, v21, v22, v25, and v26 were spilled and reloaded but never used: five dead stxvx/lxvx pairs and 80 bytes of frame. This saves only the registers the body touches and trims the frame from 320 to 224 bytes. The Montgomery multiply is unchanged. The mlkem/ copy was regenerated with scripts/simpasm. Closes #1722. Signed-off-by: Scott Boudreaux <scottbphone12@gmail.com>
1 parent 4482a37 commit 14e8a39

2 files changed

Lines changed: 32 additions & 76 deletions

File tree

dev/ppc64le/src/poly_tomont_ppc_asm.S

Lines changed: 18 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
.text
5353

5454
/*
55-
* Barrett multiplication by R = 2^16 mod q,
55+
* Barrett multiplication by R = 2^16 mod q,
5656
* mapping each coefficient to the Montgomery domain.
5757
* For each lane (a in vdata1..4):
5858
* t = vmhraddshs(a, V_FACTOR_TW, 0) = round(a*factor_tw / 2^15)
@@ -103,40 +103,26 @@
103103
.global MLK_ASM_NAMESPACE(poly_tomont_ppc_asm)
104104
.balign 16
105105
MLK_ASM_FN_SYMBOL(poly_tomont_ppc_asm)
106-
stdu 1, -320(1)
106+
stdu 1, -224(1)
107107
mflr 0
108108

109109
/*
110-
* TODO: this saves/restores v20-v30, but the body only touches
111-
* v23 (vdata3), v24 (vtmp3) and v27-v30 (vresult1..4) in the
112-
* callee-saved range. v20, v21, v22, v25, v26 are spilled and
113-
* reloaded but never used -- 5 dead stxvx/lxvx pairs plus 80
114-
* bytes of frame. Trim the save set (and frame size) to the
115-
* registers actually clobbered. Separate change from the doc
116-
* pass, since it alters emitted code.
110+
* Save/restore only the callee-saved VRs the body clobbers:
111+
* v23, v24, v27-v30. v20-v22, v25, v26 were spilled but never
112+
* used. Frame trimmed from 320 to 224 bytes.
117113
*/
118114
li 6, 128
119115
li 7, 144
120116
li 8, 160
121117
li 9, 176
122118
li 10, 192
123119
li 11, 208
124-
li 12, 224
125-
stxvx 32+20, 6, 1
126-
stxvx 32+21, 7, 1
127-
stxvx 32+22, 8, 1
128-
stxvx 32+23, 9, 1
129-
stxvx 32+24, 10, 1
130-
stxvx 32+25, 11, 1
131-
stxvx 32+26, 12, 1
132-
li 6, 240
133-
li 7, 256
134-
li 8, 272
135-
li 9, 288
136-
stxvx 32+27, 6, 1
137-
stxvx 32+28, 7, 1
138-
stxvx 32+29, 8, 1
139-
stxvx 32+30, 9, 1
120+
stxvx 32+23, 6, 1
121+
stxvx 32+24, 7, 1
122+
stxvx 32+27, 8, 1
123+
stxvx 32+28, 9, 1
124+
stxvx 32+29, 10, 1
125+
stxvx 32+30, 11, 1
140126

141127
li 6, MLK_PPC_NQ_OFFSET
142128
li 7, MLK_PPC_TOMONT_OFFSET
@@ -178,24 +164,14 @@ MLK_ASM_FN_SYMBOL(poly_tomont_ppc_asm)
178164
li 9, 176
179165
li 10, 192
180166
li 11, 208
181-
li 12, 224
182-
lxvx 32+20, 6, 1
183-
lxvx 32+21, 7, 1
184-
lxvx 32+22, 8, 1
185-
lxvx 32+23, 9, 1
186-
lxvx 32+24, 10, 1
187-
lxvx 32+25, 11, 1
188-
lxvx 32+26, 12, 1
189-
li 6, 240
190-
li 7, 256
191-
li 8, 272
192-
li 9, 288
193-
lxvx 32+27, 6, 1
194-
lxvx 32+28, 7, 1
195-
lxvx 32+29, 8, 1
196-
lxvx 32+30, 9, 1
167+
lxvx 32+23, 6, 1
168+
lxvx 32+24, 7, 1
169+
lxvx 32+27, 8, 1
170+
lxvx 32+28, 9, 1
171+
lxvx 32+29, 10, 1
172+
lxvx 32+30, 11, 1
197173
mtlr 0
198-
addi 1, 1, 320
174+
addi 1, 1, 224
199175
blr
200176

201177
/* To facilitate single-compilation-unit (SCU) builds, undefine all macros.

mlkem/src/native/ppc64le/src/poly_tomont_ppc_asm.S

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,20 @@
2727
.global MLK_ASM_NAMESPACE(poly_tomont_ppc_asm)
2828
MLK_ASM_FN_SYMBOL(poly_tomont_ppc_asm)
2929

30-
stdu 1, -320(1)
30+
stdu 1, -224(1)
3131
mflr 0
3232
li 6, 128
3333
li 7, 144
3434
li 8, 160
3535
li 9, 176
3636
li 10, 192
3737
li 11, 208
38-
li 12, 224
39-
stxvd2x 52, 6, 1
40-
stxvd2x 53, 7, 1
41-
stxvd2x 54, 8, 1
42-
stxvd2x 55, 9, 1
43-
stxvd2x 56, 10, 1
44-
stxvd2x 57, 11, 1
45-
stxvd2x 58, 12, 1
46-
li 6, 240
47-
li 7, 256
48-
li 8, 272
49-
li 9, 288
50-
stxvd2x 59, 6, 1
51-
stxvd2x 60, 7, 1
52-
stxvd2x 61, 8, 1
53-
stxvd2x 62, 9, 1
38+
stxvd2x 55, 6, 1
39+
stxvd2x 56, 7, 1
40+
stxvd2x 59, 8, 1
41+
stxvd2x 60, 9, 1
42+
stxvd2x 61, 10, 1
43+
stxvd2x 62, 11, 1
5444
li 6, 0
5545
li 7, 80
5646
li 8, 96
@@ -264,24 +254,14 @@ MLK_ASM_FN_SYMBOL(poly_tomont_ppc_asm)
264254
li 9, 176
265255
li 10, 192
266256
li 11, 208
267-
li 12, 224
268-
lxvd2x 52, 6, 1
269-
lxvd2x 53, 7, 1
270-
lxvd2x 54, 8, 1
271-
lxvd2x 55, 9, 1
272-
lxvd2x 56, 10, 1
273-
lxvd2x 57, 11, 1
274-
lxvd2x 58, 12, 1
275-
li 6, 240
276-
li 7, 256
277-
li 8, 272
278-
li 9, 288
279-
lxvd2x 59, 6, 1
280-
lxvd2x 60, 7, 1
281-
lxvd2x 61, 8, 1
282-
lxvd2x 62, 9, 1
257+
lxvd2x 55, 6, 1
258+
lxvd2x 56, 7, 1
259+
lxvd2x 59, 8, 1
260+
lxvd2x 60, 9, 1
261+
lxvd2x 61, 10, 1
262+
lxvd2x 62, 11, 1
283263
mtlr 0
284-
addi 1, 1, 320
264+
addi 1, 1, 224
285265
blr
286266

287267
MLK_ASM_FN_SIZE(poly_tomont_ppc_asm)

0 commit comments

Comments
 (0)