From: Klaus Post Date: Mon, 28 Jul 2025 15:26:52 +0000 (+0000) Subject: hash/crc32: fix incorrect checksums with avx512+race X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=e81eac19d30f373496cd1d08ce2f89c0469a21fd;p=gostls13.git 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: 5074012d2cbc8fdb78c1fb2ada72e3bd98c985c2 GitHub-Pull-Request: golang/go#74775 Reviewed-on: https://go-review.googlesource.com/c/go/+/690855 Reviewed-by: Keith Randall Reviewed-by: Keith Randall Auto-Submit: Keith Randall Reviewed-by: David Chase LUCI-TryBot-Result: Go LUCI --- diff --git a/src/hash/crc32/crc32_amd64.s b/src/hash/crc32/crc32_amd64.s index 4c482dc4a7..85d8b67a71 100644 --- a/src/hash/crc32/crc32_amd64.s +++ b/src/hash/crc32/crc32_amd64.s @@ -173,11 +173,11 @@ TEXT ·ieeeCLMUL(SB),NOSPLIT,$0 CMPQ CX, $1024 JL useSSE42 - // Use AVX512 - VPXORQ Z0, Z0, Z0 - VMOVQ AX, X0 + // Use AVX512. Zero upper and Z10 and load initial CRC into lower part of Z10. + VPXORQ Z10, Z10, Z10 + VMOVAPS X0, X10 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 SUBQ $64, CX // len-=64 diff --git a/src/hash/crc32/crc32_test.go b/src/hash/crc32/crc32_test.go index 40acd7da4f..eb5e73c394 100644 --- a/src/hash/crc32/crc32_test.go +++ b/src/hash/crc32/crc32_test.go @@ -11,6 +11,7 @@ import ( "internal/testhash" "io" "math/rand" + "strings" "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"}, {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