From a3fa174e7184c480b2656c9e013f16c3c32268bf Mon Sep 17 00:00:00 2001 From: Sun Yimin Date: Wed, 4 Sep 2024 07:58:07 +0800 Subject: [PATCH] sm3: s390x copyResultsBy4 --- sm3/sm3blocks_s390x.go | 3 +++ sm3/sm3blocks_s390x.s | 13 +++++++++++++ sm3/sm3blocks_s390x_test.go | 23 +++++++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/sm3/sm3blocks_s390x.go b/sm3/sm3blocks_s390x.go index 01db70b..1a61e36 100644 --- a/sm3/sm3blocks_s390x.go +++ b/sm3/sm3blocks_s390x.go @@ -8,3 +8,6 @@ package sm3 //go:noescape func transposeMatrix(dig **[8]uint32) + +//go:noescape +func copyResultsBy4(dig *uint32, p *byte) diff --git a/sm3/sm3blocks_s390x.s b/sm3/sm3blocks_s390x.s index 73604be..e560774 100644 --- a/sm3/sm3blocks_s390x.s +++ b/sm3/sm3blocks_s390x.s @@ -56,3 +56,16 @@ TEXT ·transposeMatrix(SB),NOSPLIT,$0 VSTM V6, V7, (R2) RET + +// func copyResultsBy4(dig *uint32, dst *byte) +TEXT ·copyResultsBy4(SB),NOSPLIT,$0 +#define digPtr R1 +#define dstPtr R2 + MOVD dig+0(FP), digPtr + MOVD dst+8(FP), dstPtr + + // load state + VLM (digPtr), V0, V7 + VSTM V0, V7, (dstPtr) + + RET diff --git a/sm3/sm3blocks_s390x_test.go b/sm3/sm3blocks_s390x_test.go index 94021ef..a6f2a52 100644 --- a/sm3/sm3blocks_s390x_test.go +++ b/sm3/sm3blocks_s390x_test.go @@ -29,3 +29,26 @@ func TestTransposeMatrix(t *testing.T) { fmt.Println() } } + +func TestCopyResultsBy4(t *testing.T) { + var m [4][8]uint32 + var k uint32 = 0 + for i := 0; i < 4; i++ { + for j := 0; j < 8; j++ { + m[i][j] = k << 24 + k++ + fmt.Printf("%04x ", m[i][j]) + } + fmt.Println() + } + var p [32]byte + copyResultsBy4(&m[0][0], &p[0]) + fmt.Println() + fmt.Println() + for i := 0; i < 32; i++ { + fmt.Printf("%04x ", p[i]) + if i%8 == 7 { + fmt.Println() + } + } +}