jimmystewpot commented on code in PR #3754:
URL: https://github.com/apache/brpc/pull/3754#discussion_r4730175768
##########
test/crc32c_unittest.cc:
##########
@@ -71,6 +206,285 @@ 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(IsArm64Crc32CompiledForTest() && 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);
+ EXPECT_EQ(IsArm64PmullCompiledForTest() && sysctl_crc32 && sysctl_pmull,
+ IsArm64PmullSelectedForTest());
+#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(IsArm64Crc32CompiledForTest() && hw_crc32, IsFastCrc32Supported());
+ EXPECT_EQ(IsArm64PmullCompiledForTest() && hw_crc32 && hw_pmull,
+ IsArm64PmullSelectedForTest());
+#elif defined(__aarch64__)
+ EXPECT_FALSE(IsFastCrc32Supported());
+ EXPECT_FALSE(IsArm64PmullSelectedForTest());
+#endif
+}
+
+TEST_F(CRC, UnalignedAndAllTailLengths) {
+ if (IsBigEndianArm64()) {
+ GTEST_SKIP() << "Big-endian ARM64 preserves legacy software CRC32C path";
+ }
+ std::vector<char> storage(16 + 512 + 16);
+ for (size_t i = 0; i < storage.size(); ++i) {
+ storage[i] = static_cast<char>((i * 131 + 17) & 0xff);
+ }
+ for (size_t align = 0; align < 16; ++align) {
+ const char* base = storage.data() + align;
+ for (size_t len = 0; len <= 512; ++len) {
+ const uint32_t expected = ReferenceExtend(0, base, len);
+ ASSERT_EQ(expected, Value(base, len))
+ << "align=" << align << " len=" << len;
+ if (len >= 2) {
+ const size_t split = len / 3;
+ const uint32_t part1 = Extend(0, base, split);
+ const uint32_t chained = Extend(part1, base + split, len - split);
+ ASSERT_EQ(expected, chained)
+ << "align=" << align << " len=" << len << " split=" << split;
+ }
+ }
+ }
+}
+
+TEST_F(CRC, LargeBuffersAndSeeds) {
+ if (IsBigEndianArm64()) {
+ GTEST_SKIP() << "Big-endian ARM64 preserves legacy software CRC32C path";
+ }
+ const size_t sizes[] = {191, 192, 193, 383, 384, 385, 1007, 1008,
+ 1009, 1024, 3071, 3072, 3073, 4096, 16384, 65536};
+ const uint32_t seeds[] = {0U, 1U, 0x12345678U, 0xdeadbeefU, 0xffffffffU};
+ std::vector<char> storage(65536 + 32);
+ uint32_t prng = 0x9e3779b9U;
+ for (size_t i = 0; i < storage.size(); ++i) {
+ prng ^= prng << 13;
+ prng ^= prng >> 17;
+ prng ^= prng << 5;
+ storage[i] = static_cast<char>(prng & 0xff);
+ }
+
+ for (size_t s = 0; s < sizeof(sizes) / sizeof(sizes[0]); ++s) {
+ const size_t len = sizes[s];
+ for (size_t align = 0; align < 16; ++align) {
+ const char* buf = storage.data() + align;
+ for (size_t k = 0; k < sizeof(seeds) / sizeof(seeds[0]); ++k) {
+ const uint32_t seed = seeds[k];
+ const uint32_t expected = ReferenceExtend(seed, buf, len);
+ ASSERT_EQ(expected, Extend(seed, buf, len))
+ << "len=" << len << " align=" << align << " seed=" << seed;
+ }
+ }
+ }
+}
+
+TEST_F(CRC, TightBoundsAndAllArm64Paths) {
+ if (IsBigEndianArm64()) {
+ GTEST_SKIP() << "Big-endian ARM64 preserves legacy software CRC32C path";
+ }
+ const size_t lengths[] = {
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 15, 16, 17,
+ 31, 32, 33, 63, 64, 65, 191, 192, 193, 335, 336, 337, 383,
+ 384, 385, 1007, 1008, 1009, 1199, 1200, 1201, 2015, 2016, 2017};
+ const uint32_t seeds[] = {0U, 0x9e3779b9U, 0xffffffffU};
+ for (size_t li = 0; li < sizeof(lengths) / sizeof(lengths[0]); ++li) {
+ const size_t len = lengths[li];
+ for (size_t align = 0; align < 16; ++align) {
+ const size_t alloc_len = (align + len == 0) ? 1 : (align + len);
+ std::unique_ptr<char[]> raw(new char[alloc_len]);
+ for (size_t a = 0; a < align; ++a) {
+ raw[a] = static_cast<char>(0xa5);
+ }
+ for (size_t i = 0; i < len; ++i) {
+ raw[align + i] = static_cast<char>(((i * 131) + 17) & 0xff);
+ }
+ const char* base = raw.get() + align;
+ for (size_t si = 0; si < sizeof(seeds) / sizeof(seeds[0]); ++si) {
+ ASSERT_NO_FATAL_FAILURE(
+ VerifyAllExtendPaths("tight", seeds[si], base, len, align));
+ }
+ for (size_t a = 0; a < align; ++a) {
+ ASSERT_EQ(static_cast<char>(0xa5), raw[a])
+ << "len=" << len << " align=" << align << " a=" << a;
+ }
+ }
+ }
+}
+
+TEST_F(CRC, Arm64PmullStripeBoundaries) {
+#if !defined(__aarch64__)
+ GTEST_SKIP() << "ARM64-only PMULL backend test";
+#else
+ if (!IsArm64PmullSelectedForTest()) {
+ GTEST_SKIP() << "ARM64 PMULL backend not selected on this target";
+ }
+ ASSERT_TRUE(IsArm64PmullSelectedForTest());
+
+ // Includes 194..200 and 1010..1016 so misaligned offsets (1..7) land
+ // directly on post-alignment 192B and 1008B stripe boundaries.
+ const size_t lengths[] = {
+ 0, 1, 7, 8, 15, 31, 63, 64, 65, 191, 192, 193,
+ 194, 198, 199, 200, 335, 336, 337, 383, 384, 385, 1007, 1008,
+ 1009, 1010, 1014, 1015, 1016, 1199, 1200, 1201, 2015, 2016, 2017};
Review Comment:
Fixed in `6ba49ee8`.
Replaced the hand-listed boundary entries in
`CRC.Arm64PmullStripeBoundaries` with a loop generating the complete contiguous
`[B - 1, B + 8]` window around every PMULL block threshold `B` (`192, 384,
1008, 1200, 2016`), sizing `storage` dynamically to `max_len + 16`. This covers
`191..200` and `1007..1016` (including `195..197` and `1011..1013`) with zero
omitted lengths so every starting alignment `addr % 8` in `0..7` hits
`remaining == B - 1`, `B`, and `B + 1`.
--
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]