Skip to content

Commit

Permalink
Potentially fix the getcpuid issue on linux and darwin
Browse files Browse the repository at this point in the history
  • Loading branch information
TheROPFather committed Oct 8, 2018
1 parent 3f63f72 commit 09d88d6
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/StageStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "MinaCalc.h"
#include "Song.h"
#include "GamePreferences.h"
#include <cpuid.h>

#ifdef _WIN32
#include <intrin.h>
Expand Down Expand Up @@ -228,21 +229,25 @@ getCpuHash()

#else // !DARWIN

static void
getCpuid(uint32_t* p, uint32_t ax)
{
__asm __volatile("movl %%ebx, %%esi\n\t"
"cpuid\n\t"
"xchgl %%ebx, %%esi"
: "=a"(p[0]), "=S"(p[1]), "=c"(p[2]), "=d"(p[3])
: "0"(ax));
}

uint16_t
getCpuHash()
{
uint32_t cpuinfo[4] = { 0, 0, 0, 0 };
getCpuid(cpuinfo, 0);

#ifdef __APPLE__
__cpuid(cpuinfo, 0);
#else
unsigned int eax = 0;
unsigned int ebx;
unsigned int ecx;
unsigned int edx;
__get_cpuid(0, &eax, &ebx, &ecx, &edx);

cpuinfo[0] = eax;
cpuinfo[1] = ebx;
cpuinfo[2] = ecx;
cpuinfo[3] = edx;
#endif
uint16_t hash = 0;
uint32_t* ptr = (&cpuinfo[0]);
for (uint32_t i = 0; i < 4; i++)
Expand Down

0 comments on commit 09d88d6

Please sign in to comment.