hash/crc32: fix incorrect checksums with avx512+race

CRC value loaded from incorrect register, which happened
to line up with actual register on default compile.
Therefore failures would only show up with -race.

Add regression test with longer payloads.

Fix regression from CL 689435.

Fixes #74767.

Change-Id: Ib63ddade998a5630297b285f3d566361f36f28e5
GitHub-Last-Rev: 5074012d2c
GitHub-Pull-Request: golang/go#74775
Reviewed-on: https://go-review.googlesource.com/c/go/+/690855
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Klaus Post 2025-07-28 15:26:52 +00:00 committed by Gopher Robot
parent 6fbad4be75
commit e81eac19d3
2 changed files with 7 additions and 4 deletions

View file

@ -173,11 +173,11 @@ TEXT ·ieeeCLMUL(SB),NOSPLIT,$0
CMPQ CX, $1024 CMPQ CX, $1024
JL useSSE42 JL useSSE42
// Use AVX512 // Use AVX512. Zero upper and Z10 and load initial CRC into lower part of Z10.
VPXORQ Z0, Z0, Z0 VPXORQ Z10, Z10, Z10
VMOVQ AX, X0 VMOVAPS X0, X10
VMOVDQU64 (SI), Z1 VMOVDQU64 (SI), Z1
VPXORQ Z0, Z1, Z1 // Merge initial CRC value into Z1 VPXORQ Z10, Z1, Z1 // Merge initial CRC value into Z1
ADDQ $64, SI // buf+=64 ADDQ $64, SI // buf+=64
SUBQ $64, CX // len-=64 SUBQ $64, CX // len-=64

View file

@ -11,6 +11,7 @@ import (
"internal/testhash" "internal/testhash"
"io" "io"
"math/rand" "math/rand"
"strings"
"testing" "testing"
) )
@ -67,6 +68,8 @@ var golden = []test{
{0x8c79fd79, 0x297a88ed, "Even if I could be Shakespeare, I think I should still choose to be Faraday. - A. Huxley", "crc\x01ʇ\x91Ml+\xb8\xa7", "crc\x01wB\x84\x81\xbf\xd6S\xdd"}, {0x8c79fd79, 0x297a88ed, "Even if I could be Shakespeare, I think I should still choose to be Faraday. - A. Huxley", "crc\x01ʇ\x91Ml+\xb8\xa7", "crc\x01wB\x84\x81\xbf\xd6S\xdd"},
{0xa20b7167, 0x66ed1d8b, "The fugacity of a constituent in a mixture of gases at a given temperature is proportional to its mole fraction. Lewis-Randall Rule", "crc\x01ʇ\x91M<lR[", "crc\x01wB\x84\x81{\xaco\xb1"}, {0xa20b7167, 0x66ed1d8b, "The fugacity of a constituent in a mixture of gases at a given temperature is proportional to its mole fraction. Lewis-Randall Rule", "crc\x01ʇ\x91M<lR[", "crc\x01wB\x84\x81{\xaco\xb1"},
{0x8e0bb443, 0xdcded527, "How can you write a big system without C++? -Paul Glick", "crc\x01ʇ\x91M\x0e\x88\x89\xed", "crc\x01wB\x84\x813\xd7C\u007f"}, {0x8e0bb443, 0xdcded527, "How can you write a big system without C++? -Paul Glick", "crc\x01ʇ\x91M\x0e\x88\x89\xed", "crc\x01wB\x84\x813\xd7C\u007f"},
{0x1010dab0, 0x8a11661f, strings.Repeat("01234567", 1024), "crc\x01ʇ\x91M\x92\xe5\xba\xf3", "crc\x01wB\x84\x81\x1a\x02\x88Y"},
{0x772d04d7, 0x5a6f5c45, strings.Repeat("a", 1024+65), "crc\x01ʇ\x91M\xe7Љ\xd1", "crc\x01wB\x84\x81\x95B\xa9("},
} }
// testGoldenIEEE verifies that the given function returns // testGoldenIEEE verifies that the given function returns