From 3659b8756a2b81766e589e34d4fe9613b5917de0 Mon Sep 17 00:00:00 2001 From: Joel Sing Date: Tue, 19 Mar 2024 22:36:42 +1100 Subject: [PATCH] cmd/internal/obj/riscv: use native rotation instructions for rva22u64 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When rva22u64 is available, we can now use the native rotation instructions from the Zbb extension. Use these instead of synthesising rotation instructions. This provides a significant performance gain for SHA-512, the following benchmarked on a StarFive VisionFive 2: │ sha512.rva20u64 │ sha512.rva22u64 │ │ B/s │ B/s vs base │ Hash8Bytes/New-4 859.4Ki ± 0% 1337.9Ki ± 0% +55.68% (p=0.000 n=10) Hash8Bytes/Sum384-4 888.7Ki ± 1% 1308.6Ki ± 1% +47.25% (p=0.000 n=10) Hash8Bytes/Sum512-4 869.1Ki ± 0% 1269.5Ki ± 1% +46.07% (p=0.000 n=10) Hash1K/New-4 19.83Mi ± 0% 29.03Mi ± 0% +46.38% (p=0.000 n=10) Hash1K/Sum384-4 20.00Mi ± 0% 28.86Mi ± 0% +44.30% (p=0.000 n=10) Hash1K/Sum512-4 19.93Mi ± 0% 28.72Mi ± 0% +44.11% (p=0.000 n=10) Hash8K/New-4 23.85Mi ± 0% 34.12Mi ± 0% +43.09% (p=0.000 n=10) Hash8K/Sum384-4 23.88Mi ± 0% 34.09Mi ± 0% +42.77% (p=0.000 n=10) Hash8K/Sum512-4 23.87Mi ± 0% 34.07Mi ± 0% +42.71% (p=0.000 n=10) geomean 7.399Mi 10.78Mi +45.77% Change-Id: I9dca8e3f311eea101684c806cb998872dc697288 Reviewed-on: https://go-review.googlesource.com/c/go/+/572716 Run-TryBot: Joel Sing Reviewed-by: David Chase TryBot-Result: Gopher Robot Reviewed-by: M Zhuo LUCI-TryBot-Result: Go LUCI Reviewed-by: Matthew Dempsky Reviewed-by: Mark Ryan Auto-Submit: Emmanuel Odeke --- src/cmd/internal/obj/riscv/obj.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/cmd/internal/obj/riscv/obj.go b/src/cmd/internal/obj/riscv/obj.go index 5518b97c0a..9f24f746f6 100644 --- a/src/cmd/internal/obj/riscv/obj.go +++ b/src/cmd/internal/obj/riscv/obj.go @@ -2291,6 +2291,11 @@ func instructionsForMOV(p *obj.Prog) []*instruction { // instructionsForRotate returns the machine instructions for a bitwise rotation. func instructionsForRotate(p *obj.Prog, ins *instruction) []*instruction { + if buildcfg.GORISCV64 >= 22 { + // Rotation instructions are supported natively. + return []*instruction{ins} + } + switch ins.as { case AROL, AROLW, AROR, ARORW: // ROL -> OR (SLL x y) (SRL x (NEG y))