jimmystewpot commented on code in PR #3754:
URL: https://github.com/apache/brpc/pull/3754#discussion_r4608910755


##########
src/butil/crc32c.cc:
##########
@@ -17,6 +17,17 @@
 #ifdef __SSE4_2__
 #include <nmmintrin.h>
 #endif
+#if defined(__aarch64__)
+#include <arm_acle.h>
+#include <arm_neon.h>

Review Comment:
   Fixed in 07487347. Wrapped `<arm_acle.h>` and `<arm_neon.h>` inclusions with 
`#pragma clang attribute push(__attribute__((target("crc,aes"))), apply_to = 
function)` on Clang and `#pragma GCC push_options` / `#pragma GCC 
target("+crc+crypto")` on GCC, and routed CRC32C/PMULL operations through 
target-attributed inline wrappers (`ArmCrc32cb/h/w/d` using 
`__builtin_arm_crc32c*` / `__builtin_aarch64_crc32c*` and `ArmVmullP64`) so 
baseline `-march=armv8-a` builds work across both GCC and older Clang releases.



##########
src/butil/crc32c.cc:
##########
@@ -812,6 +823,235 @@ static bool isSSE42() {
 }
 #endif
 
+#if defined(__aarch64__)
+#if defined(__clang__)
+#define BUTIL_CRC32_TARGET_CRC __attribute__((target("crc")))
+#define BUTIL_CRC32_TARGET_CRC_PMULL __attribute__((target("crc,aes")))
+#elif defined(__GNUC__)
+#define BUTIL_CRC32_TARGET_CRC __attribute__((target("+crc")))
+#define BUTIL_CRC32_TARGET_CRC_PMULL __attribute__((target("+crc+crypto")))
+#else
+#define BUTIL_CRC32_TARGET_CRC
+#define BUTIL_CRC32_TARGET_CRC_PMULL
+#endif
+
+static bool isArmCrc32() {
+  static const bool supported = []() {
+#if defined(__linux__)
+#ifndef HWCAP_CRC32
+#define HWCAP_CRC32 (1 << 7)
+#endif
+    return (getauxval(AT_HWCAP) & HWCAP_CRC32) != 0;
+#elif defined(__APPLE__)
+    int val = 0;
+    size_t len = sizeof(val);
+    if (sysctlbyname("hw.optional.armv8_crc32", &val, &len, nullptr, 0) == 0) {
+      return val != 0;
+    }
+    return true;

Review Comment:
   Fixed in 07487347. Changed the macOS `sysctlbyname` fallbacks in 
`isArmCrc32()` and `isArmPmull()` to return `false` on probe failure.



-- 
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]

Reply via email to