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


##########
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:
   On GCC (and on ARM ACLE implementations that gate these declarations), 
`arm_acle.h`/`arm_neon.h` expose `__crc32c*` and `vmull_p64` only when the 
corresponding `__ARM_FEATURE_*` macro is enabled at header inclusion time. This 
file includes both headers while compiling with the baseline `-march=armv8-a`, 
before either function-level `target(...)` attribute is in effect, so the 
intrinsic declarations can be absent and the claimed baseline GCC build fails. 
Please use target-specific wrappers/builtins or otherwise arrange the 
feature-enabled intrinsic declarations without requiring a global 
`+crc/+crypto` flag.



##########
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:
   If this sysctl key is unavailable or the query fails, returning `true` still 
dispatches to `__crc32*` instructions. That makes a failed capability probe an 
unsafe positive result and can raise SIGILL on an AArch64 Apple target without 
FEAT_CRC32; treat probe failure as unsupported (or use a separately verified 
platform guarantee) rather than enabling the path.
   
   This issue also appears on line 869 of the same file.



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