Skip to content

Commit 8cf1cb0

Browse files
authored
Merge pull request #597 from Dreaming-Codes/fix/arm64-crc32-compile
fix: ARM64 build fails due to x86-only CRC32 intrinsics
2 parents 43a82f2 + 5d1e9ed commit 8cf1cb0

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/vmaware.hpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1935,12 +1935,19 @@ struct VM {
19351935

19361936
// 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,
19371937
// will always make it slower or equal to a simple unrolled u8 loop, and not every cpu model fits in u32/u64
1938-
#if (CLANG || GCC)
1938+
#if (x86 && (CLANG || GCC))
19391939
__attribute__((__target__("crc32")))
19401940
#endif
19411941
static u32 crc32_hw(u32 crc, char data) {
1942-
1942+
#if (x86)
19431943
return _mm_crc32_u8(crc, static_cast<u8>(data));
1944+
#else
1945+
// Fallback for non-x86: use software CRC32-C
1946+
crc ^= static_cast<u8>(data);
1947+
for (int i = 0; i < 8; ++i)
1948+
crc = (crc >> 1) ^ ((crc & 1) ? 0x82F63B78u : 0);
1949+
return crc;
1950+
#endif
19441951
}
19451952

19461953
using hashfc = u32(*)(u32, char);
@@ -9244,7 +9251,7 @@ struct VM {
92449251
* @implements VM::BOOT_LOGO
92459252
*/
92469253
[[nodiscard]] static bool boot_logo()
9247-
#if (CLANG || GCC)
9254+
#if (x86 && (CLANG || GCC))
92489255
__attribute__((__target__("crc32")))
92499256
#endif
92509257
{

0 commit comments

Comments
 (0)