From f7a6674a93a296b7e3ebf085011566e70149be41 Mon Sep 17 00:00:00 2001 From: Sun Yimin Date: Thu, 14 Sep 2023 15:59:05 +0800 Subject: [PATCH] sm3: arm64, fix #159 --- sm3/sm3block_arm64.s | 67 +++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/sm3/sm3block_arm64.s b/sm3/sm3block_arm64.s index eb4601f..53d42b3 100644 --- a/sm3/sm3block_arm64.s +++ b/sm3/sm3block_arm64.s @@ -33,6 +33,7 @@ #define NUM_BYTES R12 #define INP R13 #define CTX R14 // Beginning of digest in memory (a, b, c, ... , h) +#define rspSave R15 #define a1 R20 #define b1 R21 @@ -404,6 +405,8 @@ TEXT ·blockARM64(SB), 0, $512-32 LDPW (3*8)(CTX), (g, h) loop: + MOVD RSP, rspSave + MOVW a, a1 MOVW b, b1 MOVW c, c1 @@ -421,108 +424,108 @@ loop: schedule_compress: // for w0 - w47 // Do 4 rounds and scheduling - VST1 [XWORD0.B16], (RSP) + VST1.P [XWORD0.B16], 16(rspSave) VEOR XWORD0.B16, XWORD1.B16, XFER.B16 - VST1 [XFER.B16], 16(RSP) + VST1.P [XFER.B16], 16(rspSave) ROUND_AND_SCHED_N_0_0(0*16, 0x79cc4519, a, b, c, d, e, f, g, h, XWORD0, XWORD1, XWORD2, XWORD3) ROUND_AND_SCHED_N_0_1(0*16, 0xf3988a32, h, a, b, c, d, e, f, g, XWORD0, XWORD1, XWORD2, XWORD3) ROUND_AND_SCHED_N_0_2(0*16, 0xe7311465, g, h, a, b, c, d, e, f, XWORD0, XWORD1, XWORD2, XWORD3) ROUND_AND_SCHED_N_0_3(0*16, 0xce6228cb, f, g, h, a, b, c, d, e, XWORD0, XWORD1, XWORD2, XWORD3) // Do 4 rounds and scheduling - VST1 [XWORD1.B16], 32(RSP) + VST1.P [XWORD1.B16], 16(rspSave) VEOR XWORD1.B16, XWORD2.B16, XFER.B16 - VST1 [XFER.B16], 48(RSP) + VST1.P [XFER.B16], 16(rspSave) ROUND_AND_SCHED_N_0_0(2*16, 0x9cc45197, e, f, g, h, a, b, c, d, XWORD1, XWORD2, XWORD3, XWORD0) ROUND_AND_SCHED_N_0_1(2*16, 0x3988a32f, d, e, f, g, h, a, b, c, XWORD1, XWORD2, XWORD3, XWORD0) ROUND_AND_SCHED_N_0_2(2*16, 0x7311465e, c, d, e, f, g, h, a, b, XWORD1, XWORD2, XWORD3, XWORD0) ROUND_AND_SCHED_N_0_3(2*16, 0xe6228cbc, b, c, d, e, f, g, h, a, XWORD1, XWORD2, XWORD3, XWORD0) // Do 4 rounds and scheduling - VST1 [XWORD2.B16], 64(RSP) + VST1.P [XWORD2.B16], 16(rspSave) VEOR XWORD2.B16, XWORD3.B16, XFER.B16 - VST1 [XFER.B16], 80(RSP) + VST1.P [XFER.B16], 16(rspSave) ROUND_AND_SCHED_N_0_0(4*16, 0xcc451979, a, b, c, d, e, f, g, h, XWORD2, XWORD3, XWORD0, XWORD1) ROUND_AND_SCHED_N_0_1(4*16, 0x988a32f3, h, a, b, c, d, e, f, g, XWORD2, XWORD3, XWORD0, XWORD1) ROUND_AND_SCHED_N_0_2(4*16, 0x311465e7, g, h, a, b, c, d, e, f, XWORD2, XWORD3, XWORD0, XWORD1) ROUND_AND_SCHED_N_0_3(4*16, 0x6228cbce, f, g, h, a, b, c, d, e, XWORD2, XWORD3, XWORD0, XWORD1) // Do 4 rounds and scheduling - VST1 [XWORD3.B16], 96(RSP) + VST1.P [XWORD3.B16], 16(rspSave) VEOR XWORD3.B16, XWORD0.B16, XFER.B16 - VST1 [XFER.B16], 112(RSP) + VST1.P [XFER.B16], 16(rspSave) ROUND_AND_SCHED_N_0_0(6*16, 0xc451979c, e, f, g, h, a, b, c, d, XWORD3, XWORD0, XWORD1, XWORD2) ROUND_AND_SCHED_N_0_1(6*16, 0x88a32f39, d, e, f, g, h, a, b, c, XWORD3, XWORD0, XWORD1, XWORD2) ROUND_AND_SCHED_N_0_2(6*16, 0x11465e73, c, d, e, f, g, h, a, b, XWORD3, XWORD0, XWORD1, XWORD2) ROUND_AND_SCHED_N_0_3(6*16, 0x228cbce6, b, c, d, e, f, g, h, a, XWORD3, XWORD0, XWORD1, XWORD2) // Do 4 rounds and scheduling - VST1 [XWORD0.B16], 128(RSP) + VST1.P [XWORD0.B16], 16(rspSave) VEOR XWORD0.B16, XWORD1.B16, XFER.B16 - VST1 [XFER.B16], 144(RSP) + VST1.P [XFER.B16], 16(rspSave) ROUND_AND_SCHED_N_1_0(8*16, 0x9d8a7a87, a, b, c, d, e, f, g, h, XWORD0, XWORD1, XWORD2, XWORD3) ROUND_AND_SCHED_N_1_1(8*16, 0x3b14f50f, h, a, b, c, d, e, f, g, XWORD0, XWORD1, XWORD2, XWORD3) ROUND_AND_SCHED_N_1_2(8*16, 0x7629ea1e, g, h, a, b, c, d, e, f, XWORD0, XWORD1, XWORD2, XWORD3) ROUND_AND_SCHED_N_1_3(8*16, 0xec53d43c, f, g, h, a, b, c, d, e, XWORD0, XWORD1, XWORD2, XWORD3) // Do 4 rounds and scheduling - VST1 [XWORD1.B16], 160(RSP) + VST1.P [XWORD1.B16], 16(rspSave) VEOR XWORD1.B16, XWORD2.B16, XFER.B16 - VST1 [XFER.B16], 176(RSP) + VST1.P [XFER.B16], 16(rspSave) ROUND_AND_SCHED_N_1_0(10*16, 0xd8a7a879, e, f, g, h, a, b, c, d, XWORD1, XWORD2, XWORD3, XWORD0) ROUND_AND_SCHED_N_1_1(10*16, 0xb14f50f3, d, e, f, g, h, a, b, c, XWORD1, XWORD2, XWORD3, XWORD0) ROUND_AND_SCHED_N_1_2(10*16, 0x629ea1e7, c, d, e, f, g, h, a, b, XWORD1, XWORD2, XWORD3, XWORD0) ROUND_AND_SCHED_N_1_3(10*16, 0xc53d43ce, b, c, d, e, f, g, h, a, XWORD1, XWORD2, XWORD3, XWORD0) // Do 4 rounds and scheduling - VST1 [XWORD2.B16], 192(RSP) + VST1.P [XWORD2.B16], 16(rspSave) VEOR XWORD2.B16, XWORD3.B16, XFER.B16 - VST1 [XFER.B16], 208(RSP) + VST1.P [XFER.B16], 16(rspSave) ROUND_AND_SCHED_N_1_0(12*16, 0x8a7a879d, a, b, c, d, e, f, g, h, XWORD2, XWORD3, XWORD0, XWORD1) ROUND_AND_SCHED_N_1_1(12*16, 0x14f50f3b, h, a, b, c, d, e, f, g, XWORD2, XWORD3, XWORD0, XWORD1) ROUND_AND_SCHED_N_1_2(12*16, 0x29ea1e76, g, h, a, b, c, d, e, f, XWORD2, XWORD3, XWORD0, XWORD1) ROUND_AND_SCHED_N_1_3(12*16, 0x53d43cec, f, g, h, a, b, c, d, e, XWORD2, XWORD3, XWORD0, XWORD1) // Do 4 rounds and scheduling - VST1 [XWORD3.B16], 224(RSP) + VST1.P [XWORD3.B16], 16(rspSave) VEOR XWORD3.B16, XWORD0.B16, XFER.B16 - VST1 [XFER.B16], 240(RSP) + VST1.P [XFER.B16], 16(rspSave) ROUND_AND_SCHED_N_1_0(14*16, 0xa7a879d8, e, f, g, h, a, b, c, d, XWORD3, XWORD0, XWORD1, XWORD2) ROUND_AND_SCHED_N_1_1(14*16, 0x4f50f3b1, d, e, f, g, h, a, b, c, XWORD3, XWORD0, XWORD1, XWORD2) ROUND_AND_SCHED_N_1_2(14*16, 0x9ea1e762, c, d, e, f, g, h, a, b, XWORD3, XWORD0, XWORD1, XWORD2) ROUND_AND_SCHED_N_1_3(14*16, 0x3d43cec5, b, c, d, e, f, g, h, a, XWORD3, XWORD0, XWORD1, XWORD2) // Do 4 rounds and scheduling - VST1 [XWORD0.B16], 256(RSP) + VST1.P [XWORD0.B16], 16(rspSave) VEOR XWORD0.B16, XWORD1.B16, XFER.B16 - VST1 [XFER.B16], 272(RSP) + VST1.P [XFER.B16], 16(rspSave) ROUND_AND_SCHED_N_1_0(16*16, 0x7a879d8a, a, b, c, d, e, f, g, h, XWORD0, XWORD1, XWORD2, XWORD3) ROUND_AND_SCHED_N_1_1(16*16, 0xf50f3b14, h, a, b, c, d, e, f, g, XWORD0, XWORD1, XWORD2, XWORD3) ROUND_AND_SCHED_N_1_2(16*16, 0xea1e7629, g, h, a, b, c, d, e, f, XWORD0, XWORD1, XWORD2, XWORD3) ROUND_AND_SCHED_N_1_3(16*16, 0xd43cec53, f, g, h, a, b, c, d, e, XWORD0, XWORD1, XWORD2, XWORD3) // Do 4 rounds and scheduling - VST1 [XWORD1.B16], 288(RSP) + VST1.P [XWORD1.B16], 16(rspSave) VEOR XWORD1.B16, XWORD2.B16, XFER.B16 - VST1 [XFER.B16], 304(RSP) + VST1.P [XFER.B16], 16(rspSave) ROUND_AND_SCHED_N_1_0(18*16, 0xa879d8a7, e, f, g, h, a, b, c, d, XWORD1, XWORD2, XWORD3, XWORD0) ROUND_AND_SCHED_N_1_1(18*16, 0x50f3b14f, d, e, f, g, h, a, b, c, XWORD1, XWORD2, XWORD3, XWORD0) ROUND_AND_SCHED_N_1_2(18*16, 0xa1e7629e, c, d, e, f, g, h, a, b, XWORD1, XWORD2, XWORD3, XWORD0) ROUND_AND_SCHED_N_1_3(18*16, 0x43cec53d, b, c, d, e, f, g, h, a, XWORD1, XWORD2, XWORD3, XWORD0) // Do 4 rounds and scheduling - VST1 [XWORD2.B16], 320(RSP) + VST1.P [XWORD2.B16], 16(rspSave) VEOR XWORD2.B16, XWORD3.B16, XFER.B16 - VST1 [XFER.B16], 336(RSP) + VST1.P [XFER.B16], 16(rspSave) ROUND_AND_SCHED_N_1_0(20*16, 0x879d8a7a, a, b, c, d, e, f, g, h, XWORD2, XWORD3, XWORD0, XWORD1) ROUND_AND_SCHED_N_1_1(20*16, 0xf3b14f5, h, a, b, c, d, e, f, g, XWORD2, XWORD3, XWORD0, XWORD1) ROUND_AND_SCHED_N_1_2(20*16, 0x1e7629ea, g, h, a, b, c, d, e, f, XWORD2, XWORD3, XWORD0, XWORD1) ROUND_AND_SCHED_N_1_3(20*16, 0x3cec53d4, f, g, h, a, b, c, d, e, XWORD2, XWORD3, XWORD0, XWORD1) // Do 4 rounds and scheduling - VST1 [XWORD2.B16], 352(RSP) + VST1.P [XWORD2.B16], 16(rspSave) VEOR XWORD2.B16, XWORD3.B16, XFER.B16 - VST1 [XFER.B16], 368(RSP) + VST1.P [XFER.B16], 16(rspSave) ROUND_AND_SCHED_N_1_0(22*16, 0x79d8a7a8, e, f, g, h, a, b, c, d, XWORD3, XWORD0, XWORD1, XWORD2) ROUND_AND_SCHED_N_1_1(22*16, 0xf3b14f50, d, e, f, g, h, a, b, c, XWORD3, XWORD0, XWORD1, XWORD2) ROUND_AND_SCHED_N_1_2(22*16, 0xe7629ea1, c, d, e, f, g, h, a, b, XWORD3, XWORD0, XWORD1, XWORD2) @@ -530,9 +533,9 @@ schedule_compress: // for w0 - w47 // w48 - w63 processed with only 4 rounds scheduling (last 16 rounds) // Do 4 rounds and scheduling - VST1 [XWORD0.B16], 384(RSP) + VST1.P [XWORD0.B16], 16(rspSave) VEOR XWORD0.B16, XWORD1.B16, XFER.B16 - VST1 [XFER.B16], 400(RSP) + VST1.P [XFER.B16], 16(rspSave) ROUND_AND_SCHED_N_1_0(24*16, 0x9d8a7a87, a, b, c, d, e, f, g, h, XWORD0, XWORD1, XWORD2, XWORD3) ROUND_AND_SCHED_N_1_1(24*16, 0x3b14f50f, h, a, b, c, d, e, f, g, XWORD0, XWORD1, XWORD2, XWORD3) ROUND_AND_SCHED_N_1_2(24*16, 0x7629ea1e, g, h, a, b, c, d, e, f, XWORD0, XWORD1, XWORD2, XWORD3) @@ -540,27 +543,27 @@ schedule_compress: // for w0 - w47 // w52 - w63 processed with no scheduling (last 12 rounds) // Do 4 rounds - VST1 [XWORD1.B16], 416(RSP) + VST1.P [XWORD1.B16], 16(rspSave) VEOR XWORD1.B16, XWORD2.B16, XFER.B16 - VST1 [XFER.B16], 432(RSP) + VST1.P [XFER.B16], 16(rspSave) DO_ROUND_N_1(26*16, 0, 0xd8a7a879, e, f, g, h, a, b, c, d) DO_ROUND_N_1(26*16, 1, 0xb14f50f3, d, e, f, g, h, a, b, c) DO_ROUND_N_1(26*16, 2, 0x629ea1e7, c, d, e, f, g, h, a, b) DO_ROUND_N_1(26*16, 3, 0xc53d43ce, b, c, d, e, f, g, h, a) // Do 4 rounds - VST1 [XWORD2.B16], 448(RSP) + VST1.P [XWORD2.B16], 16(rspSave) VEOR XWORD2.B16, XWORD3.B16, XFER.B16 - VST1 [XFER.B16], 464(RSP) + VST1.P [XFER.B16], 16(rspSave) DO_ROUND_N_1(28*16, 0, 0x8a7a879d, a, b, c, d, e, f, g, h) DO_ROUND_N_1(28*16, 1, 0x14f50f3b, h, a, b, c, d, e, f, g) DO_ROUND_N_1(28*16, 2, 0x29ea1e76, g, h, a, b, c, d, e, f) DO_ROUND_N_1(28*16, 3, 0x53d43cec, f, g, h, a, b, c, d, e) // Do 4 rounds - VST1 [XWORD3.B16], 480(RSP) + VST1.P [XWORD3.B16], 16(rspSave) VEOR XWORD3.B16, XWORD0.B16, XFER.B16 - VST1 [XFER.B16], 496(RSP) + VST1 [XFER.B16], (rspSave) DO_ROUND_N_1(30*16, 0, 0xa7a879d8, e, f, g, h, a, b, c, d) DO_ROUND_N_1(30*16, 1, 0x4f50f3b1, d, e, f, g, h, a, b, c) DO_ROUND_N_1(30*16, 2, 0x9ea1e762, c, d, e, f, g, h, a, b)