[go] crypto/sha1: use const table for key loading on loong64

7 views
Skip to first unread message

Julian Zhu (Gerrit)

unread,
Dec 24, 2025, 8:17:51 AM (19 hours ago) Dec 24
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Julian Zhu has uploaded the change for review

Commit message

crypto/sha1: use const table for key loading on loong64

Load constant keys from a static memory table rather than loading immediates into registers on loong64.

Benchmark for Loongson-3A5000:
goos: linux
goarch: loong64
pkg: crypto/sha1
cpu: Loongson-3A5000-HV @ 2500.00MHz
│ old │ new │
│ sec/op │ sec/op vs base │
Hash8Bytes/New-4 235.9n ± 0% 229.1n ± 0% -2.88% (p=0.000 n=8)
Hash8Bytes/Sum-4 1.892µ ± 0% 1.882µ ± 0% -0.50% (p=0.000 n=8)
Hash320Bytes/New-4 1022.0n ± 0% 963.8n ± 0% -5.70% (p=0.000 n=8)
Hash320Bytes/Sum-4 1037.0n ± 0% 981.1n ± 0% -5.39% (p=0.000 n=8)
Hash1K/New-4 2.760µ ± 0% 2.594µ ± 0% -6.01% (p=0.000 n=8)
Hash1K/Sum-4 2.775µ ± 0% 2.610µ ± 0% -5.95% (p=0.000 n=8)
Hash8K/New-4 20.46µ ± 0% 19.20µ ± 0% -6.17% (p=0.000 n=8)
Hash8K/Sum-4 20.49µ ± 0% 19.22µ ± 0% -6.17% (p=0.000 n=8)
geomean 2.498µ 2.377µ -4.87%

│ old │ new │
│ B/s │ B/s vs base │
Hash8Bytes/New-4 32.34Mi ± 0% 33.30Mi ± 0% +2.98% (p=0.000 n=8)
Hash8Bytes/Sum-4 4.034Mi ± 0% 4.053Mi ± 0% +0.47% (p=0.000 n=8)
Hash320Bytes/New-4 298.7Mi ± 0% 316.7Mi ± 0% +6.02% (p=0.000 n=8)
Hash320Bytes/Sum-4 294.3Mi ± 0% 311.0Mi ± 0% +5.69% (p=0.000 n=8)
Hash1K/New-4 353.8Mi ± 0% 376.5Mi ± 0% +6.41% (p=0.000 n=8)
Hash1K/Sum-4 351.9Mi ± 0% 374.1Mi ± 0% +6.31% (p=0.000 n=8)
Hash8K/New-4 381.8Mi ± 0% 406.9Mi ± 0% +6.57% (p=0.000 n=8)
Hash8K/Sum-4 381.4Mi ± 0% 406.4Mi ± 0% +6.58% (p=0.000 n=8)
geomean 146.1Mi 153.6Mi +5.11%
Change-Id: I7305caefa1434ab2bb4ce94a1c789d4ee5b7ccf3

Change diff

diff --git a/src/crypto/sha1/sha1block_loong64.s b/src/crypto/sha1/sha1block_loong64.s
index b76b193..78d42f5 100644
--- a/src/crypto/sha1/sha1block_loong64.s
+++ b/src/crypto/sha1/sha1block_loong64.s
@@ -63,38 +63,38 @@

#define FUNC4 FUNC2

-#define MIX(a, b, c, d, e, const) \
+#define MIX(a, b, c, d, e, key) \
ROTR $2, b; \ // b << 30
ADD REGTMP1, e; \ // e = e + f
ROTR $27, a, REGTMP2; \ // a << 5
ADD REGTMP3, e; \ // e = e + w[i]
- ADDV $const, e; \ // e = e + k
+ ADDV key, e; \ // e = e + k
ADD REGTMP2, e // e = e + a<<5

#define ROUND1(a, b, c, d, e, index) \
LOAD1(index); \
FUNC1(a, b, c, d, e); \
- MIX(a, b, c, d, e, 0x5A827999)
+ MIX(a, b, c, d, e, R25)

#define ROUND1x(a, b, c, d, e, index) \
LOAD(index); \
FUNC1(a, b, c, d, e); \
- MIX(a, b, c, d, e, 0x5A827999)
+ MIX(a, b, c, d, e, R25)

#define ROUND2(a, b, c, d, e, index) \
LOAD(index); \
FUNC2(a, b, c, d, e); \
- MIX(a, b, c, d, e, 0x6ED9EBA1)
+ MIX(a, b, c, d, e, R26)

#define ROUND3(a, b, c, d, e, index) \
LOAD(index); \
FUNC3(a, b, c, d, e); \
- MIX(a, b, c, d, e, 0x8F1BBCDC)
+ MIX(a, b, c, d, e, R27)

#define ROUND4(a, b, c, d, e, index) \
LOAD(index); \
FUNC4(a, b, c, d, e); \
- MIX(a, b, c, d, e, 0xCA62C1D6)
+ MIX(a, b, c, d, e, R28)

// A stack frame size of 64 bytes is required here, because
// the frame size used for data expansion is 64 bytes.
@@ -108,13 +108,19 @@
BEQ R6, zero

// p_len >= 64
- ADDV R5, R6, R24
+ ADDV R5, R6, R24
MOVW (0*4)(R4), R7
MOVW (1*4)(R4), R8
MOVW (2*4)(R4), R9
MOVW (3*4)(R4), R10
MOVW (4*4)(R4), R11

+ MOVV $·_K(SB), R21
+ MOVW (0*4)(R21), R25
+ MOVW (1*4)(R21), R26
+ MOVW (2*4)(R21), R27
+ MOVW (3*4)(R21), R28
+
loop:
MOVW R7, R12
MOVW R8, R13
@@ -224,3 +230,9 @@
MOVW R11, (4*4)(R4)
zero:
RET
+
+GLOBL ·_K(SB),RODATA,$16
+DATA ·_K+0(SB)/4, $0x5A827999
+DATA ·_K+4(SB)/4, $0x6ED9EBA1
+DATA ·_K+8(SB)/4, $0x8F1BBCDC
+DATA ·_K+12(SB)/4, $0xCA62C1D6

Change information

Files:
  • M src/crypto/sha1/sha1block_loong64.s
Change size: S
Delta: 1 file changed, 20 insertions(+), 8 deletions(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I7305caefa1434ab2bb4ce94a1c789d4ee5b7ccf3
Gerrit-Change-Number: 732580
Gerrit-PatchSet: 1
Gerrit-Owner: Julian Zhu <jz53...@gmail.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Julian Zhu (Gerrit)

unread,
Dec 24, 2025, 8:56:08 AM (18 hours ago) Dec 24
to goph...@pubsubhelper.golang.org, Filippo Valsorda, Roland Shoemaker, Daniel McCarney, Gopher Robot, golang-co...@googlegroups.com
Attention needed from Daniel McCarney, Filippo Valsorda and Roland Shoemaker

Julian Zhu voted Commit-Queue+1

Commit-Queue+1
Open in Gerrit

Related details

Attention is currently required from:
  • Daniel McCarney
  • Filippo Valsorda
  • Roland Shoemaker
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I7305caefa1434ab2bb4ce94a1c789d4ee5b7ccf3
Gerrit-Change-Number: 732580
Gerrit-PatchSet: 1
Gerrit-Owner: Julian Zhu <jz53...@gmail.com>
Gerrit-Reviewer: Daniel McCarney <dan...@binaryparadox.net>
Gerrit-Reviewer: Filippo Valsorda <fil...@golang.org>
Gerrit-Reviewer: Julian Zhu <jz53...@gmail.com>
Gerrit-Reviewer: Roland Shoemaker <rol...@golang.org>
Gerrit-CC: Gopher Robot <go...@golang.org>
Gerrit-Attention: Roland Shoemaker <rol...@golang.org>
Gerrit-Attention: Filippo Valsorda <fil...@golang.org>
Gerrit-Attention: Daniel McCarney <dan...@binaryparadox.net>
Gerrit-Comment-Date: Wed, 24 Dec 2025 13:56:04 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
unsatisfied_requirement
satisfied_requirement
open
diffy
Reply all
Reply to author
Forward
0 new messages