From 5d1e9ed64290d959ce22b290349644ccddef9fe4 Mon Sep 17 00:00:00 2001 From: DreamingCodes Date: Mon, 5 Jan 2026 18:09:28 -0800 Subject: [PATCH] fix: guard x86 CRC32 intrinsics for ARM64 compatibility The __attribute__((__target__("crc32"))) and _mm_crc32_u8 intrinsics are x86-specific but were only guarded by #if (CLANG || GCC), causing ARM64 builds to fail. Changes: - Add x86 guard to target("crc32") attribute - Add #if (x86) guard around _mm_crc32_u8 with software fallback --- src/vmaware.hpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/vmaware.hpp b/src/vmaware.hpp index 8a061db..cc0aaee 100644 --- a/src/vmaware.hpp +++ b/src/vmaware.hpp @@ -1935,12 +1935,19 @@ struct VM { // For strings shorter than 16-32 bytes, the overhead of setting up the _mm_crc32_u64 (or 32) loop, then checking length, handling the tail bytes, and finally handling alignment, // will always make it slower or equal to a simple unrolled u8 loop, and not every cpu model fits in u32/u64 - #if (CLANG || GCC) + #if (x86 && (CLANG || GCC)) __attribute__((__target__("crc32"))) #endif static u32 crc32_hw(u32 crc, char data) { - + #if (x86) return _mm_crc32_u8(crc, static_cast(data)); + #else + // Fallback for non-x86: use software CRC32-C + crc ^= static_cast(data); + for (int i = 0; i < 8; ++i) + crc = (crc >> 1) ^ ((crc & 1) ? 0x82F63B78u : 0); + return crc; + #endif } using hashfc = u32(*)(u32, char); @@ -9244,7 +9251,7 @@ struct VM { * @implements VM::BOOT_LOGO */ [[nodiscard]] static bool boot_logo() - #if (CLANG || GCC) + #if (x86 && (CLANG || GCC)) __attribute__((__target__("crc32"))) #endif {