Skip to content

Commit 2a7a6c0

Browse files
Crypteaucajunmkannwischer
authored andcommitted
ppc64le: Trim dead callee-saved spills in poly_tomont
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 cfd1912 commit 2a7a6c0

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
@@ -73,7 +73,7 @@
7373
.text
7474

7575
/*
76-
* Barrett multiplication by R = 2^16 mod q,
76+
* Barrett multiplication by R = 2^16 mod q,
7777
* mapping each coefficient to the Montgomery domain.
7878
* For each lane (a in vdata1..4):
7979
* t = vmhraddshs(a, V_FACTOR_TW, 0) = round(a*factor_tw / 2^15)
@@ -124,40 +124,26 @@
124124
.global MLK_ASM_NAMESPACE(poly_tomont_ppc_asm)
125125
.balign 16
126126
MLK_ASM_FN_SYMBOL(poly_tomont_ppc_asm)
127-
stdu 1, -320(1)
127+
stdu 1, -224(1)
128128
mflr 0
129129

130130
/*
131-
* TODO: this saves/restores v20-v30, but the body only touches
132-
* v23 (vdata3), v24 (vtmp3) and v27-v30 (vresult1..4) in the
133-
* callee-saved range. v20, v21, v22, v25, v26 are spilled and
134-
* reloaded but never used -- 5 dead stxvx/lxvx pairs plus 80
135-
* bytes of frame. Trim the save set (and frame size) to the
136-
* registers actually clobbered. Separate change from the doc
137-
* pass, since it alters emitted code.
131+
* Save/restore only the callee-saved VRs the body clobbers:
132+
* v23, v24, v27-v30. v20-v22, v25, v26 were spilled but never
133+
* used. Frame trimmed from 320 to 224 bytes.
138134
*/
139135
li 6, 128
140136
li 7, 144
141137
li 8, 160
142138
li 9, 176
143139
li 10, 192
144140
li 11, 208
145-
li 12, 224
146-
stxvx 32+20, 6, 1
147-
stxvx 32+21, 7, 1
148-
stxvx 32+22, 8, 1
149-
stxvx 32+23, 9, 1
150-
stxvx 32+24, 10, 1
151-
stxvx 32+25, 11, 1
152-
stxvx 32+26, 12, 1
153-
li 6, 240
154-
li 7, 256
155-
li 8, 272
156-
li 9, 288
157-
stxvx 32+27, 6, 1
158-
stxvx 32+28, 7, 1
159-
stxvx 32+29, 8, 1
160-
stxvx 32+30, 9, 1
141+
stxvx 32+23, 6, 1
142+
stxvx 32+24, 7, 1
143+
stxvx 32+27, 8, 1
144+
stxvx 32+28, 9, 1
145+
stxvx 32+29, 10, 1
146+
stxvx 32+30, 11, 1
161147

162148
li 6, MLK_PPC_NQ_OFFSET
163149
li 7, MLK_PPC_TOMONT_OFFSET
@@ -199,24 +185,14 @@ MLK_ASM_FN_SYMBOL(poly_tomont_ppc_asm)
199185
li 9, 176
200186
li 10, 192
201187
li 11, 208
202-
li 12, 224
203-
lxvx 32+20, 6, 1
204-
lxvx 32+21, 7, 1
205-
lxvx 32+22, 8, 1
206-
lxvx 32+23, 9, 1
207-
lxvx 32+24, 10, 1
208-
lxvx 32+25, 11, 1
209-
lxvx 32+26, 12, 1
210-
li 6, 240
211-
li 7, 256
212-
li 8, 272
213-
li 9, 288
214-
lxvx 32+27, 6, 1
215-
lxvx 32+28, 7, 1
216-
lxvx 32+29, 8, 1
217-
lxvx 32+30, 9, 1
188+
lxvx 32+23, 6, 1
189+
lxvx 32+24, 7, 1
190+
lxvx 32+27, 8, 1
191+
lxvx 32+28, 9, 1
192+
lxvx 32+29, 10, 1
193+
lxvx 32+30, 11, 1
218194
mtlr 0
219-
addi 1, 1, 320
195+
addi 1, 1, 224
220196
blr
221197

222198
/* 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
@@ -48,30 +48,20 @@
4848
.global MLK_ASM_NAMESPACE(poly_tomont_ppc_asm)
4949
MLK_ASM_FN_SYMBOL(poly_tomont_ppc_asm)
5050

51-
stdu 1, -320(1)
51+
stdu 1, -224(1)
5252
mflr 0
5353
li 6, 128
5454
li 7, 144
5555
li 8, 160
5656
li 9, 176
5757
li 10, 192
5858
li 11, 208
59-
li 12, 224
60-
stxvd2x 52, 6, 1
61-
stxvd2x 53, 7, 1
62-
stxvd2x 54, 8, 1
63-
stxvd2x 55, 9, 1
64-
stxvd2x 56, 10, 1
65-
stxvd2x 57, 11, 1
66-
stxvd2x 58, 12, 1
67-
li 6, 240
68-
li 7, 256
69-
li 8, 272
70-
li 9, 288
71-
stxvd2x 59, 6, 1
72-
stxvd2x 60, 7, 1
73-
stxvd2x 61, 8, 1
74-
stxvd2x 62, 9, 1
59+
stxvd2x 55, 6, 1
60+
stxvd2x 56, 7, 1
61+
stxvd2x 59, 8, 1
62+
stxvd2x 60, 9, 1
63+
stxvd2x 61, 10, 1
64+
stxvd2x 62, 11, 1
7565
li 6, 0
7666
li 7, 80
7767
li 8, 96
@@ -285,24 +275,14 @@ MLK_ASM_FN_SYMBOL(poly_tomont_ppc_asm)
285275
li 9, 176
286276
li 10, 192
287277
li 11, 208
288-
li 12, 224
289-
lxvd2x 52, 6, 1
290-
lxvd2x 53, 7, 1
291-
lxvd2x 54, 8, 1
292-
lxvd2x 55, 9, 1
293-
lxvd2x 56, 10, 1
294-
lxvd2x 57, 11, 1
295-
lxvd2x 58, 12, 1
296-
li 6, 240
297-
li 7, 256
298-
li 8, 272
299-
li 9, 288
300-
lxvd2x 59, 6, 1
301-
lxvd2x 60, 7, 1
302-
lxvd2x 61, 8, 1
303-
lxvd2x 62, 9, 1
278+
lxvd2x 55, 6, 1
279+
lxvd2x 56, 7, 1
280+
lxvd2x 59, 8, 1
281+
lxvd2x 60, 9, 1
282+
lxvd2x 61, 10, 1
283+
lxvd2x 62, 11, 1
304284
mtlr 0
305-
addi 1, 1, 320
285+
addi 1, 1, 224
306286
blr
307287

308288
MLK_ASM_FN_SIZE(poly_tomont_ppc_asm)

0 commit comments

Comments
 (0)