source-engine/tier1/processor_detect_linux.cpp

86 lines
2.1 KiB
C++
Raw Permalink Normal View History

2020-04-22 16:56:21 +00:00
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: linux dependant ASM code for CPU capability detection
//
// $Workfile: $
// $NoKeywords: $
//=============================================================================//
2022-02-23 12:00:04 +00:00
#include "platform.h"
2022-05-01 17:08:32 +00:00
#if defined __SANITIZE_ADDRESS__
2021-04-25 20:36:09 +00:00
bool CheckMMXTechnology(void) { return false; }
bool CheckSSETechnology(void) { return false; }
bool CheckSSE2Technology(void) { return false; }
bool Check3DNowTechnology(void) { return false; }
2022-06-19 12:07:41 +00:00
#elif defined (__arm__) || defined (__aarch64__)
2022-05-15 18:09:59 +00:00
bool CheckMMXTechnology(void) { return false; }
bool CheckSSETechnology(void) { return false; }
bool CheckSSE2Technology(void) { return false; }
2022-05-01 17:08:32 +00:00
bool Check3DNowTechnology(void) { return false; }
2021-04-25 20:36:09 +00:00
#else
2022-02-23 12:00:04 +00:00
static void cpuid(uint32 function, uint32& out_eax, uint32& out_ebx, uint32& out_ecx, uint32& out_edx)
{
#if defined(PLATFORM_64BITS)
asm("mov %%rbx, %%rsi\n\t"
"cpuid\n\t"
"xchg %%rsi, %%rbx"
: "=a" (out_eax),
"=S" (out_ebx),
"=c" (out_ecx),
"=d" (out_edx)
: "a" (function)
);
#else
asm("mov %%ebx, %%esi\n\t"
"cpuid\n\t"
"xchg %%esi, %%ebx"
: "=a" (out_eax),
"=S" (out_ebx),
"=c" (out_ecx),
"=d" (out_edx)
: "a" (function)
);
#endif
}
2020-04-22 16:56:21 +00:00
bool CheckMMXTechnology(void)
{
2022-02-23 12:00:04 +00:00
uint32 eax,ebx,edx,unused;
2020-04-22 16:56:21 +00:00
cpuid(1,eax,ebx,unused,edx);
return edx & 0x800000;
}
bool CheckSSETechnology(void)
{
2022-02-23 12:00:04 +00:00
uint32 eax,ebx,edx,unused;
2020-04-22 16:56:21 +00:00
cpuid(1,eax,ebx,unused,edx);
return edx & 0x2000000L;
}
bool CheckSSE2Technology(void)
{
2022-02-23 12:00:04 +00:00
uint32 eax,ebx,edx,unused;
2020-04-22 16:56:21 +00:00
cpuid(1,eax,ebx,unused,edx);
return edx & 0x04000000;
}
bool Check3DNowTechnology(void)
{
2022-02-23 12:00:04 +00:00
uint32 eax, unused;
2020-04-22 16:56:21 +00:00
cpuid(0x80000000,eax,unused,unused,unused);
if ( eax > 0x80000000L )
{
cpuid(0x80000001,unused,unused,unused,eax);
return ( eax & 1<<31 );
}
return false;
}
2021-04-25 20:36:09 +00:00
#endif