chenBright commented on code in PR #3754:
URL: https://github.com/apache/brpc/pull/3754#discussion_r4704679737
##########
src/butil/crc32c.cc:
##########
@@ -829,6 +1226,16 @@ static inline Function Choose_Extend() {
return (Function)ExtendImpl<FastCRC32Functor>;
}
#endif
+#if defined(__aarch64__)
+ if (isArmCrc32()) {
+#if defined(BUTIL_ARM64_PMULL_ENABLED)
+ if (isArmPmull()) {
+ return (Function)Arm64ExtendCrc32Pmull;
+ }
+#endif
+ return (Function)Arm64ExtendCrc32;
Review Comment:
The new dispatch makes the checksum on big-endian ARM64 depend on whether
the CPU supports CRC32. For example, given the 16-byte-aligned bytes `01 00 00
00 00 00 00 00`, `ArmLoadLe64` returns `1` on the hardware path, while the
first `LE_LOAD32` returns `0x01000000` on the software path. The two sides may
fail to validate each other even when using the same binary and the same
shards.
##########
test/crc32c_unittest.cc:
##########
@@ -71,6 +160,287 @@ TEST_F(CRC, Mask) {
TEST_F(CRC, fast_is_on) {
std::cout << "IsFastCrc32Supported=" << IsFastCrc32Supported() << std::endl;
+#if defined(__aarch64__) && defined(__APPLE__)
+ int val = 0;
+ size_t len = sizeof(val);
+ const bool sysctl_crc32 =
+ (sysctlbyname("hw.optional.armv8_crc32", &val, &len, nullptr, 0) == 0 &&
+ val != 0);
+ EXPECT_EQ(sysctl_crc32, IsFastCrc32Supported());
+ val = 0;
+ len = sizeof(val);
+ const bool sysctl_pmull = (sysctlbyname("hw.optional.arm.FEAT_PMULL", &val,
+ &len, nullptr, 0) == 0 &&
+ val != 0);
+#if defined(__ARM_NEON)
+ EXPECT_EQ(sysctl_crc32 && sysctl_pmull, IsArm64PmullSelectedForTest());
+#else
+ (void)sysctl_pmull;
+ EXPECT_FALSE(IsArm64PmullSelectedForTest());
+#endif
+#elif defined(__aarch64__) && defined(__linux__)
+ const unsigned long hwcap = getauxval(AT_HWCAP);
+ const bool hw_crc32 = (hwcap & HWCAP_CRC32) != 0;
+ const bool hw_pmull = (hwcap & HWCAP_PMULL) != 0;
+ EXPECT_EQ(hw_crc32, IsFastCrc32Supported());
+#if defined(__ARM_NEON)
+ EXPECT_EQ(hw_crc32 && hw_pmull, IsArm64PmullSelectedForTest());
+#else
+ (void)hw_pmull;
+ EXPECT_FALSE(IsArm64PmullSelectedForTest());
Review Comment:
`__ARM_NEON` describes this test file. If `-march=armv8-a+nosimd` is used
only for the library's `crc32c.cc`, a machine that supports CRC32 and PMULL
will correctly select the scalar implementation, but this test will still
expect PMULL, causing `CRC.fast_is_on` to fail.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]