From 3dad842181512e3bee18ec1aab2765179fb4ceef Mon Sep 17 00:00:00 2001 From: Eddy Jansson Date: Fri, 15 Nov 2024 17:56:24 +0100 Subject: [PATCH] CPU detection for GCC/clang. --- tiny_bvh_speedtest.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tiny_bvh_speedtest.cpp b/tiny_bvh_speedtest.cpp index eb2afd2..91bd081 100644 --- a/tiny_bvh_speedtest.cpp +++ b/tiny_bvh_speedtest.cpp @@ -9,6 +9,9 @@ #ifdef _WIN32 #include // for __cpuidex #endif +#ifdef __GNUC__ +#include +#endif #ifdef __EMSCRIPTEN__ #include // for __EMSCRIPTEN_major__, __EMSCRIPTEN_minor__ #endif @@ -115,9 +118,15 @@ int main() #endif // determine what CPU is running the tests. -#ifdef _WIN32 +#if defined (_WIN32) || defined(__GNUC__) char model[256]{}; - for (unsigned i = 0; i < 3; ++i) __cpuidex( (int*)(model + i * 16), i + 0x80000002, 0 ); + for (unsigned i = 0; i < 3; ++i) { +#ifdef _WIN32 + __cpuidex( (int*)(model + i * 16), i + 0x80000002, 0 ); +#elif defined __GNUC__ + __get_cpuid(i + 0x80000002, (unsigned int*)(model+ i * 16 + 0), (unsigned int*)(model + i * 16 + 4), (unsigned int*)(model + i * 16 + 8), (unsigned int*)(model + i * 16 + 12)); +#endif + } printf( "running on %s\n", model ); #endif printf( "----------------------------------------------------------------\n" );