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 699fdbd
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
#if defined(__GNUC__) && defined(__x86_64__)
#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.
#if (defined(__x86_64__) || defined(_M_X64)) && (defined (_WIN32) || defined(__GNUC__))
char model[64]{};
for (unsigned i = 0; i < 3; ++i) {
#ifdef _WIN32
char model[256]{};
for (unsigned i = 0; i < 3; ++i) __cpuidex( (int*)(model + i * 16), i + 0x80000002, 0 );
__cpuidex( (int*)(model + i * 16), i + 0x80000002, 0 );
#elif defined(__GNUC__)
__get_cpuid(i + 0x80000002, (unsigned int*)(model) + i * 4 + 0, (unsigned int*)(model) + i * 4 + 1, (unsigned int*)(model) + i * 4 + 2, (unsigned int*)(model) + i * 4 + 3);
#endif
}
printf( "running on %s\n", model );
#endif
printf( "----------------------------------------------------------------\n" );
Expand Down

0 comments on commit 699fdbd

Please sign in to comment.