From 9a3357cf0be8fdd05ed50f5c9d9f144fd113472f Mon Sep 17 00:00:00 2001 From: Sun Yimin Date: Fri, 10 Oct 2025 10:37:59 +0800 Subject: [PATCH] internal/sm2ec: try LASX --- internal/sm2ec/p256_asm_loong64.s | 36 +++++++++++++++++++++- internal/sm2ec/sm2p256_asm_loong64.go | 3 ++ internal/sm2ec/sm2p256_asm_loong64_test.go | 2 +- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/internal/sm2ec/p256_asm_loong64.s b/internal/sm2ec/p256_asm_loong64.s index 3752fe8..7f10e5a 100644 --- a/internal/sm2ec/p256_asm_loong64.s +++ b/internal/sm2ec/p256_asm_loong64.s @@ -2,7 +2,7 @@ // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -//go:build !purego +//go:build go1.25 && !purego #include "textflag.h" @@ -87,6 +87,40 @@ TEXT ·p256MovCond(SB),NOSPLIT,$0 MOVV ·supportLSX+0(SB), t1 BEQ t1, ZERO, basic_path + MOVV ·supportLASX+0(SB), t1 + BEQ t1, ZERO, lsx_path + + XVMOVQ t0, X0.V4 + XVXORV X1, X1, X1 + XVSEQV X0, X1, X0 + + XVMOVQ (32*0)(x_ptr), X1 + XVMOVQ (32*1)(x_ptr), X2 + XVMOVQ (32*2)(x_ptr), X3 + + XVANDNV X1, X0, X1 + XVANDNV X2, X0, X2 + XVANDNV X3, X0, X3 + + XVMOVQ (32*0)(y_ptr), X4 + XVMOVQ (32*1)(y_ptr), X5 + XVMOVQ (32*2)(y_ptr), X6 + + XVANDV X4, X0, X4 + XVANDV X5, X0, X5 + XVANDV X6, X0, X6 + + XVORV X1, X4, X1 + XVORV X2, X5, X2 + XVORV X3, X6, X3 + + XVMOVQ X1, (32*0)(res_ptr) + XVMOVQ X2, (32*1)(res_ptr) + XVMOVQ X3, (32*2)(res_ptr) + + RET + +lsx_path: VMOVQ t0, V0.V2 VXORV V1, V1, V1 VSEQV V0, V1, V0 diff --git a/internal/sm2ec/sm2p256_asm_loong64.go b/internal/sm2ec/sm2p256_asm_loong64.go index 13c0767..2287c5a 100644 --- a/internal/sm2ec/sm2p256_asm_loong64.go +++ b/internal/sm2ec/sm2p256_asm_loong64.go @@ -1,3 +1,5 @@ +//go:build go1.25 + package sm2ec import ( @@ -15,6 +17,7 @@ type SM2P256Point1 struct { } var supportLSX = cpu.Loong64.HasLSX +var supportLASX = cpu.Loong64.HasLASX //go:noescape func p256BigToLittle(res *p256Element, in *[32]byte) diff --git a/internal/sm2ec/sm2p256_asm_loong64_test.go b/internal/sm2ec/sm2p256_asm_loong64_test.go index 32ab7cd..35ed2e0 100644 --- a/internal/sm2ec/sm2p256_asm_loong64_test.go +++ b/internal/sm2ec/sm2p256_asm_loong64_test.go @@ -1,4 +1,4 @@ -//go:build loong64 && !purego +//go:build loong64 && go1.25 && !purego package sm2ec