mirror of
https://github.com/emmansun/gmsm.git
synced 2026-11-23 12:51:59 +08:00
mldsa: fix asm FP-width vet warnings in the avx2 field kernels
asmdecl flagged three references in field_amd64.s: * nttMatRowVecMulAVX2 read the 8-byte int argument with MOVL, i.e. only its low 32 bits. Load it with MOVQ instead; the body still does 32-bit arithmetic on it. * polyInfinityNormAVX2 and polyInfinityNormSignedAVX2 stored their uint32 result with VMOVD, which asmdecl sizes as 8 bytes from the opcode suffix. The store itself was correct; split it into VMOVD+MOVL so the width matches and vet stays quiet. Also guard a non-positive len in nttMatRowVecMulAVX2: the accumulate counter used to underflow to 0xFFFFFFFF. A test pins both the guard and the unchanged normal path.
This commit is contained in:
1 parent
7990363c43
commit
f96c69dc77
2 files changed
+38
-3
No files matched your search
+9
-3
@@ -556,7 +556,10 @@ TEXT ·nttMatRowVecMulAVX2(SB), NOSPLIT, $0-32
|
||||
MOVQ dst+0(FP), DI
|
||||
MOVQ vec+8(FP), SI
|
||||
MOVQ matRow+16(FP), DX
|
||||
MOVL len+24(FP), CX
|
||||
MOVQ len+24(FP), CX
|
||||
|
||||
TESTL CX, CX
|
||||
JLE mvmDone // len <= 0: nothing to accumulate
|
||||
|
||||
VPBROADCASTD qNegInvConst, QNegInv
|
||||
VPBROADCASTD qConst, Q
|
||||
@@ -636,6 +639,7 @@ mvmWrite:
|
||||
DECL R8
|
||||
JNZ mvmChunkLoop
|
||||
|
||||
mvmDone:
|
||||
VZEROUPPER
|
||||
RET
|
||||
|
||||
@@ -720,7 +724,8 @@ polyInfinityNormLoop:
|
||||
VPMAXSD X0, X7, X7
|
||||
VPSHUFD $0xB1, X7, X0
|
||||
VPMAXSD X0, X7, X7
|
||||
VMOVD X7, ret+8(FP)
|
||||
VMOVD X7, AX // 32-bit lane; store width must match the uint32 result
|
||||
MOVL AX, ret+8(FP)
|
||||
|
||||
VZEROUPPER
|
||||
RET
|
||||
@@ -746,7 +751,8 @@ polyInfinityNormSignedLoop:
|
||||
VPMAXSD X0, X7, X7
|
||||
VPSHUFD $0xB1, X7, X0
|
||||
VPMAXSD X0, X7, X7
|
||||
VMOVD X7, ret+8(FP)
|
||||
VMOVD X7, AX // 32-bit lane; store width must match the uint32 result
|
||||
MOVL AX, ret+8(FP)
|
||||
|
||||
VZEROUPPER
|
||||
RET
|
||||
|
||||
@@ -200,6 +200,35 @@ func TestPolyInfinityNormSignedAVX2(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNttMatRowVecMulAVX2NonPositiveLen(t *testing.T) {
|
||||
if !useAVX2 {
|
||||
t.Skip("AVX2 is not available")
|
||||
}
|
||||
|
||||
vec := nttElement(randomRingElement())
|
||||
matRow := nttElement(randomRingElement())
|
||||
|
||||
// A non-positive length must leave dst untouched instead of underflowing
|
||||
// the accumulate counter into a near-infinite loop.
|
||||
for _, length := range []int{0, -1} {
|
||||
dst := nttElement(randomRingElement())
|
||||
want := dst
|
||||
nttMatRowVecMulAVX2(&dst, &vec, &matRow, length)
|
||||
if dst != want {
|
||||
t.Fatalf("nttMatRowVecMulAVX2(len=%d) modified dst", length)
|
||||
}
|
||||
}
|
||||
|
||||
// The guard must not disturb the normal path.
|
||||
got := nttElement(randomRingElement())
|
||||
want := nttElement(randomRingElement())
|
||||
nttMatRowVecMulAVX2(&got, &vec, &matRow, 1)
|
||||
nttMatRowVecMulGeneric(&want, &vec, &matRow, 1)
|
||||
if got != want {
|
||||
t.Fatal("nttMatRowVecMulAVX2(len=1) mismatch with generic")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecomposeSubToR0Gamma32AVX2(t *testing.T) {
|
||||
if !useAVX2 {
|
||||
t.Skip("AVX2 is not available")
|
||||
|
||||
Reference in new issue
Block a user