Skip to content

Commit

Permalink
CPU detection for GCC/clang.
Browse files Browse the repository at this point in the history
  • Loading branch information
eloj committed Nov 15, 2024
1 parent c4f1b0d commit 3dad842
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions tiny_bvh_speedtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#ifdef _WIN32
#include <intrin.h> // for __cpuidex
#endif
#ifdef __GNUC__
#include <cpuid.h>
#endif
#ifdef __EMSCRIPTEN__
#include <emscripten/version.h> // for __EMSCRIPTEN_major__, __EMSCRIPTEN_minor__
#endif
Expand Down Expand Up @@ -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" );
Expand Down

0 comments on commit 3dad842

Please sign in to comment.