Skip to content

Commit

Permalink
Ported CPU detection to c++
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent-t committed Mar 13, 2017
1 parent afddd9c commit 7c37f74
Show file tree
Hide file tree
Showing 8 changed files with 222 additions and 466 deletions.
2 changes: 1 addition & 1 deletion src/xrCDB/ISpatial_q_ray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ void ISpatial_DB::q_ray(
Stats.Query.Begin();
q_result = &R;
q_result->clear_not_free();
if (CPU::ID.feature & _CPU_FEATURE_SSE)
if (CPU::ID.hasFeature(CpuFeature::FEATURE_SSE))
{
if (_o & O_ONLYFIRST)
{
Expand Down
2 changes: 1 addition & 1 deletion src/xrCDB/xrCDB_ray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ void COLLIDER::ray_query(const MODEL* m_def, const Fvector& r_start, const Fvect
const AABBNoLeafNode* N = T->GetNodes();
r_clear();

if (CPU::ID.feature & _CPU_FEATURE_SSE)
if (CPU::ID.hasFeature(CpuFeature::FEATURE_SSE))
{
// SSE
// Binary dispatcher
Expand Down
2 changes: 1 addition & 1 deletion src/xrCore/Threading/ttapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void SetThreadName(DWORD dwThreadID, LPCSTR szThreadName)
}
}

int ttapi_Init(const _processor_info& pi)
int ttapi_Init(const processor_info& pi)
{
if (ttapi_initialized)
return ttapi_worker_count;
Expand Down
2 changes: 1 addition & 1 deletion src/xrCore/Threading/ttapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ using TTAPIWorkerFunc = void (*)(void* lpWorkerParameters);

// Initializes subsystem
// Returns zero for error, and number of workers on success
int XRCORE_API ttapi_Init(const _processor_info& pi);
int XRCORE_API ttapi_Init(const processor_info& pi);

// Destroys subsystem
void XRCORE_API ttapi_Done();
Expand Down
49 changes: 26 additions & 23 deletions src/xrCore/_math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ XRCORE_API u64 qpc_freq = 0;
XRCORE_API u64 qpc_overhead = 0;
XRCORE_API u32 qpc_counter = 0;

XRCORE_API _processor_info ID;
XRCORE_API processor_info ID;

XRCORE_API u64 QPC()
{
Expand All @@ -164,7 +164,7 @@ u64 __fastcall GetCLK(void)
void Detect()
{
// General CPU identification
if (!_cpuid(&ID))
if (!query_processor_info(&ID))
{
// Core.Fatal ("Fatal error: can't detect CPU/FPU.");
abort();
Expand Down Expand Up @@ -234,43 +234,46 @@ bool g_initialize_cpu_called = false;
//------------------------------------------------------------------------------------
void _initialize_cpu(void)
{
Msg("* Detected CPU: %s [%s], F%d/M%d/S%d, %.2f mhz, %d-clk 'rdtsc'", CPU::ID.model_name, CPU::ID.v_name,
CPU::ID.family, CPU::ID.model, CPU::ID.stepping, float(CPU::clk_per_second / u64(1000000)),
u32(CPU::clk_overhead));
Msg("* Detected CPU: %s [%s], F%d/M%d/S%d, %.2f mhz, %d-clk 'rdtsc'",
CPU::ID.modelName, CPU::ID.vendor,
CPU::ID.family, CPU::ID.model, CPU::ID.stepping,
float(CPU::clk_per_second / u64(1000000)),
u32(CPU::clk_overhead)
);

// DUMP_PHASE;

if (strstr(Core.Params, "-x86"))
{
CPU::ID.feature &= ~_CPU_FEATURE_MMX;
CPU::ID.feature &= ~_CPU_FEATURE_3DNOW;
CPU::ID.feature &= ~_CPU_FEATURE_SSE;
CPU::ID.feature &= ~_CPU_FEATURE_SSE2;
CPU::ID.feature &= ~_CPU_FEATURE_SSE3;
CPU::ID.feature &= ~_CPU_FEATURE_SSSE3;
CPU::ID.feature &= ~_CPU_FEATURE_SSE4_1;
CPU::ID.feature &= ~_CPU_FEATURE_SSE4_2;
CPU::ID.hasFeature(CpuFeature::FEATURE_MMX);
CPU::ID.hasFeature(CpuFeature::FEATURE_3DNOW);
CPU::ID.hasFeature(CpuFeature::FEATURE_SSE);
CPU::ID.hasFeature(CpuFeature::FEATURE_SSE2);
CPU::ID.hasFeature(CpuFeature::FEATURE_SSE3);
CPU::ID.hasFeature(CpuFeature::FEATURE_SSSE3);
CPU::ID.hasFeature(CpuFeature::FEATURE_SSE41);
CPU::ID.hasFeature(CpuFeature::FEATURE_SSE41);
};

string256 features;
xr_strcpy(features, sizeof(features), "RDTSC");
if (CPU::ID.feature & _CPU_FEATURE_MMX)
if (CPU::ID.hasFeature(CpuFeature::FEATURE_MMX))
xr_strcat(features, ", MMX");
if (CPU::ID.feature & _CPU_FEATURE_3DNOW)
if (CPU::ID.hasFeature(CpuFeature::FEATURE_3DNOW))
xr_strcat(features, ", 3DNow!");
if (CPU::ID.feature & _CPU_FEATURE_SSE)
if (CPU::ID.hasFeature(CpuFeature::FEATURE_SSE))
xr_strcat(features, ", SSE");
if (CPU::ID.feature & _CPU_FEATURE_SSE2)
if (CPU::ID.hasFeature(CpuFeature::FEATURE_SSE2))
xr_strcat(features, ", SSE2");
if (CPU::ID.feature & _CPU_FEATURE_SSE3)
if (CPU::ID.hasFeature(CpuFeature::FEATURE_SSE3))
xr_strcat(features, ", SSE3");
if (CPU::ID.feature & _CPU_FEATURE_SSSE3)
if (CPU::ID.hasFeature(CpuFeature::FEATURE_SSSE3))
xr_strcat(features, ", SSSE3");
if (CPU::ID.feature & _CPU_FEATURE_SSE4_1)
if (CPU::ID.hasFeature(CpuFeature::FEATURE_SSE41))
xr_strcat(features, ", SSE4.1");
if (CPU::ID.feature & _CPU_FEATURE_SSE4_2)
if (CPU::ID.hasFeature(CpuFeature::FEATURE_SSE42))
xr_strcat(features, ", SSE4.2");
if (CPU::ID.feature & _CPU_FEATURE_HTT)
if (CPU::ID.hasFeature(CpuFeature::FEATURE_HT))
xr_strcat(features, ", HTT");

Msg("* CPU features: %s", features);
Expand Down Expand Up @@ -304,7 +307,7 @@ void _initialize_cpu_thread()
xrDebug::OnThreadSpawn();
if (!Core.PluginMode)
FPU::m24r();
if (CPU::ID.feature & _CPU_FEATURE_SSE)
if (CPU::ID.hasFeature(CpuFeature::FEATURE_SSE))
{
//_mm_setcsr ( _mm_getcsr() | (_MM_FLUSH_ZERO_ON+_MM_DENORMALS_ZERO_ON) );
_MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
Expand Down
2 changes: 1 addition & 1 deletion src/xrCore/_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ XRCORE_API extern u64 qpc_freq;
XRCORE_API extern u64 qpc_overhead;
XRCORE_API extern u32 qpc_counter;

XRCORE_API extern _processor_info ID;
XRCORE_API extern processor_info ID;
XRCORE_API extern u64 QPC();

#ifdef M_VISUAL
Expand Down
Loading

0 comments on commit 7c37f74

Please sign in to comment.