Use CPUID to detect MMX/SSE support

Make it so that it works with all compilers and OSes.
Tested in VS, gcc and clang (built for Android x86)
This commit is contained in:
David Guillen Fandos 2019-03-25 00:05:48 +01:00
parent cb278e367b
commit 69ab16ad9c
1 changed files with 17 additions and 51 deletions

View File

@ -31,59 +31,26 @@ bool sse_3=true;
bool ssse_3=true; bool ssse_3=true;
bool mmx=true; bool mmx=true;
void DetectCpuFeatures() void DetectCpuFeatures() {
{
static bool detected=false; static bool detected=false;
if (detected) return; if (detected) return;
detected=true; detected=true;
#if HOST_OS==OS_WINDOWS #if BUILD_COMPILER == COMPILER_VC
__try #include <intrin.h>
{ int info[4];
__asm addps xmm0,xmm0 __cpuid(info, 1);
} mmx = info[3] & (1 << 23);
__except(1) sse_1 = info[3] & (1 << 25);
{ sse_2 = info[3] & (1 << 26);
sse_1=false; sse_3 = info[2] & (1 << 0);
} ssse_3 = info[2] & (1 << 9);
#else
__try mmx = __builtin_cpu_supports("mmx");
{ sse_1 = __builtin_cpu_supports("sse");
__asm addpd xmm0,xmm0 sse_2 = __builtin_cpu_supports("sse2");
} sse_3 = __builtin_cpu_supports("sse3");
__except(1) ssse_3 = __builtin_cpu_supports("ssse3");
{
sse_2=false;
}
__try
{
__asm addsubpd xmm0,xmm0
}
__except(1)
{
sse_3=false;
}
__try
{
__asm phaddw xmm0,xmm0
}
__except(1)
{
ssse_3=false;
}
__try
{
__asm paddd mm0,mm1
__asm emms;
}
__except(1)
{
mmx=false;
}
#endif #endif
} }
@ -296,7 +263,6 @@ void ngen_Compile(RuntimeBlockInfo* block,bool force_checks, bool reset, bool st
((DynaRBI*)block)->reloc_info=0; ((DynaRBI*)block)->reloc_info=0;
//Setup emitter //Setup emitter
x86e = new x86_block(); x86e = new x86_block();
x86e->Init(0,0); x86e->Init(0,0);