Skip to content

Commit 8169a60

Browse files
committed
fix(cpu_features): refactor architecture detection to explicit x86 whitelist
Currently, `cpu_features.cc` assumes any non-ARM architecture is x86/x64, which leads to a fatal missing `<cpuid.h>` error on architectures like RISC-V. This commit refactors the preprocessor macros to explicitly whitelist x86 architectures (`__x86_64__`, `__i386__`, `_M_X64`, `_M_IX86`). All other architectures (RISC-V, ARM, etc.) will now safely fall back to the default zero-initialization, allowing cross-compilation to succeed. Signed-off-by: ihb2032 <hebome@foxmail.com>
1 parent 6737810 commit 8169a60

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/ailego/internal/cpu_features.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717

1818
#if defined(_MSC_VER)
1919
#include <intrin.h>
20-
#elif !defined(__ARM_ARCH)
20+
#endif
21+
22+
#if (defined(__x86_64__) || defined(__i386__)) && !defined(_MSC_VER)
2123
#include <cpuid.h>
2224
#endif
2325

@@ -34,7 +36,7 @@ namespace internal {
3436

3537
CpuFeatures::CpuFlags CpuFeatures::flags_;
3638

37-
#if defined(_MSC_VER)
39+
#if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86))
3840
CpuFeatures::CpuFlags::CpuFlags(void)
3941
: L1_ECX(0), L1_EDX(0), L7_EBX(0), L7_ECX(0), L7_EDX(0) {
4042
int l1[4] = {0, 0, 0, 0};
@@ -48,7 +50,7 @@ CpuFeatures::CpuFlags::CpuFlags(void)
4850
L7_ECX = l7[2];
4951
L7_EDX = l7[3];
5052
}
51-
#elif !defined(__ARM_ARCH)
53+
#elif defined(__x86_64__) || defined(__i386__)
5254
CpuFeatures::CpuFlags::CpuFlags(void)
5355
: L1_ECX(0), L1_EDX(0), L7_EBX(0), L7_ECX(0), L7_EDX(0) {
5456
uint32_t eax, ebx, ecx, edx;

0 commit comments

Comments
 (0)