Skip to content

Commit 6946d87

Browse files
committed
Keccak/AArch64: Remove redundant stack usage and mov operation
The AArch64+SHA3 based Keccak-F1600-x1 implementation allocates stack space for GPR storage which is never used. This commit removes the allocation. The code also includes an unnecessary `mov x1, x1` stemming from two different register aliases for the same thing. This commit removes one alias and the respective `mov` instruction. Signed-off-by: Hanno Becker <beckphan@amazon.co.uk>
1 parent dfa048b commit 6946d87

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

dev/fips202/aarch64/src/keccak_f1600_x1_v84a_asm_clean.S

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949

5050
input_addr .req x0
5151
input_rc .req x1
52-
const_addr .req x1
5352
count .req x2
5453
cur_const .req x3
5554

@@ -210,7 +209,7 @@
210209
str Asud, [input_addr, #0xC0]
211210
.endm
212211

213-
#define STACK_SIZE (16*4 + 16*6) /* VREGS (16*4) + GPRS (TODO: Remove) */
212+
#define STACK_SIZE (16*4) /* VREGS (16*4) */
214213

215214
#define STACK_BASE_GPRS (16*4)
216215
.macro alloc_stack
@@ -219,7 +218,7 @@
219218

220219
.macro free_stack
221220
add sp, sp, #(STACK_SIZE)
222-
.endm
221+
.endm
223222

224223
.macro save_vregs
225224
stp d8, d9, [sp, #(16*0)]
@@ -300,7 +299,7 @@
300299
xar_m0 Ame_, Aga, E0, 28
301300
xar_m0 Abe_, Age, E1, 20
302301

303-
ld1r {v31.2d}, [const_addr], #8
302+
ld1r {v31.2d}, [input_rc], #8
304303

305304
bcax_m0 Aga, Aga_, Agi_, Age_
306305
bcax_m0 Age, Age_, Ago_, Agi_
@@ -341,7 +340,6 @@
341340
MLK_ASM_FN_SYMBOL(keccak_f1600_x1_v84a_asm_clean)
342341
alloc_stack
343342
save_vregs
344-
mov const_addr, input_rc
345343
load_input
346344

347345
mov count, #(KECCAK_F1600_ROUNDS)
@@ -358,7 +356,6 @@ keccak_f1600_x1_v84a_loop:
358356
/****************** REGISTER DEALLOCATIONS *******************/
359357
.unreq input_addr
360358
.unreq input_rc
361-
.unreq const_addr
362359
.unreq count
363360
.unreq cur_const
364361
.unreq Aba

mlkem/fips202/native/aarch64/src/keccak_f1600_x1_v84a_asm_clean.S

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,11 @@
5555
.global MLK_ASM_NAMESPACE(keccak_f1600_x1_v84a_asm_clean)
5656
MLK_ASM_FN_SYMBOL(keccak_f1600_x1_v84a_asm_clean)
5757

58-
sub sp, sp, #0xa0
58+
sub sp, sp, #0x40
5959
stp d8, d9, [sp]
6060
stp d10, d11, [sp, #0x10]
6161
stp d12, d13, [sp, #0x20]
6262
stp d14, d15, [sp, #0x30]
63-
mov x1, x1
6463
ldp d0, d1, [x0]
6564
ldp d2, d3, [x0, #0x10]
6665
ldp d4, d5, [x0, #0x20]
@@ -163,7 +162,7 @@ keccak_f1600_x1_v84a_loop:
163162
ldp d10, d11, [sp, #0x10]
164163
ldp d12, d13, [sp, #0x20]
165164
ldp d14, d15, [sp, #0x30]
166-
add sp, sp, #0xa0
165+
add sp, sp, #0x40
167166
ret
168167

169168
#endif /* __ARM_FEATURE_SHA3 */

0 commit comments

Comments
 (0)