From 925d8749e030c9dec49a5e27080000a4f950d625 Mon Sep 17 00:00:00 2001 From: Jeroen van Rijn Date: Thu, 7 Nov 2024 12:56:49 +0100 Subject: Suggest `-microarch:native` if `popcnt` instruction is missing. Fixes #4453. --- src/build_cpuid.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/build_cpuid.cpp (limited to 'src/build_cpuid.cpp') diff --git a/src/build_cpuid.cpp b/src/build_cpuid.cpp new file mode 100644 index 000000000..a4e44e7f1 --- /dev/null +++ b/src/build_cpuid.cpp @@ -0,0 +1,35 @@ +#if !defined(GB_COMPILER_MSVC) + #if defined(GB_CPU_X86) + #include + #endif +#endif + +gb_internal void odin_cpuid(int leaf, int result[]) { + #if defined(GB_CPU_ARM) || defined(GB_CPU_RISCV) + return; + + #elif defined(GB_CPU_X86) + + #if defined(GB_COMPILER_MSVC) + __cpuid(result, leaf); + #else + __get_cpuid(leaf, (unsigned int*)&result[0], (unsigned int*)&result[1], (unsigned int*)&result[2], (unsigned int*)&result[3]); + #endif + + #endif +} + +gb_internal bool should_use_march_native() { + #if !defined(GB_CPU_X86) + return false; + + #else + + int cpu[4]; + odin_cpuid(0x1, &cpu[0]); // Get feature information in ECX + EDX + + bool have_popcnt = cpu[2] && (1 << 23); // bit 23 in ECX = popcnt + return !have_popcnt; + + #endif +} \ No newline at end of file -- cgit v1.2.3 From 3bfe675a68ad8448195d3b4729ee293b547d8761 Mon Sep 17 00:00:00 2001 From: Jeroen van Rijn Date: Thu, 7 Nov 2024 15:02:19 +0100 Subject: && --- src/build_cpuid.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/build_cpuid.cpp') diff --git a/src/build_cpuid.cpp b/src/build_cpuid.cpp index a4e44e7f1..b7ba5dcdf 100644 --- a/src/build_cpuid.cpp +++ b/src/build_cpuid.cpp @@ -28,7 +28,7 @@ gb_internal bool should_use_march_native() { int cpu[4]; odin_cpuid(0x1, &cpu[0]); // Get feature information in ECX + EDX - bool have_popcnt = cpu[2] && (1 << 23); // bit 23 in ECX = popcnt + bool have_popcnt = cpu[2] & (1 << 23); // bit 23 in ECX = popcnt return !have_popcnt; #endif -- cgit v1.2.3