Use gcc builtin functions for cpuid

This commit is contained in:
Isaac Connor 2020-08-19 16:57:20 -04:00
parent 8f70ae192d
commit 2773737e54
1 changed files with 11 additions and 43 deletions

View File

@ -229,63 +229,31 @@ void hwcaps_detect() {
neonversion = 0; neonversion = 0;
sse_version = 0; sse_version = 0;
#if (defined(__i386__) || defined(__x86_64__)) #if (defined(__i386__) || defined(__x86_64__))
/* x86 or x86-64 processor */ __builtin_cpu_init();
uint32_t r_edx, r_ecx, r_ebx;
#ifdef __x86_64__
__asm__ __volatile__(
"push %%rbx\n\t"
"mov $0x0,%%ecx\n\t"
"mov $0x7,%%eax\n\t"
"cpuid\n\t"
"push %%rbx\n\t"
"mov $0x1,%%eax\n\t"
"cpuid\n\t"
"pop %%rax\n\t"
"pop %%rbx\n\t"
: "=d" (r_edx), "=c" (r_ecx), "=a" (r_ebx)
:
:
);
#else
__asm__ __volatile__(
"push %%ebx\n\t"
"mov $0x0,%%ecx\n\t"
"mov $0x7,%%eax\n\t"
"cpuid\n\t"
"push %%ebx\n\t"
"mov $0x1,%%eax\n\t"
"cpuid\n\t"
"pop %%eax\n\t"
"pop %%ebx\n\t"
: "=d" (r_edx), "=c" (r_ecx), "=a" (r_ebx)
:
:
);
#endif
if ( r_ebx & 0x00000020 ) { if ( __builtin_cpu_supports("avx2") ) {
sse_version = 52; /* AVX2 */ sse_version = 52; /* AVX2 */
Debug(1, "Detected a x86\\x86-64 processor with AVX2"); Debug(1, "Detected a x86\\x86-64 processor with AVX2");
} else if ( r_ecx & 0x10000000 ) { } else if ( __builtin_cpu_supports("avx") ) {
sse_version = 51; /* AVX */ sse_version = 51; /* AVX */
Debug(1, "Detected a x86\\x86-64 processor with AVX"); Debug(1, "Detected a x86\\x86-64 processor with AVX");
} else if ( r_ecx & 0x00100000 ) { } else if ( __builtin_cpu_supports("sse4.2") ) {
sse_version = 42; /* SSE4.2 */ sse_version = 42; /* SSE4.2 */
Debug(1, "Detected a x86\\x86-64 processor with SSE4.2"); Debug(1, "Detected a x86\\x86-64 processor with SSE4.2");
} else if ( r_ecx & 0x00080000 ) { } else if ( __builtin_cpu_supports("sse4.1") ) {
sse_version = 41; /* SSE4.1 */ sse_version = 41; /* SSE4.1 */
Debug(1, "Detected a x86\\x86-64 processor with SSE4.1"); Debug(1, "Detected a x86\\x86-64 processor with SSE4.1");
} else if ( r_ecx & 0x00000200 ) { } else if ( __builtin_cpu_supports("ssse3") ) {
sse_version = 35; /* SSSE3 */ sse_version = 35; /* SSSE3 */
Debug(1,"Detected a x86\\x86-64 processor with SSSE3"); Debug(1,"Detected a x86\\x86-64 processor with SSSE3");
} else if ( r_ecx & 0x00000001 ) { } else if ( __builtin_cpu_supports("sse3") ) {
sse_version = 30; /* SSE3 */ sse_version = 30; /* SSE3 */
Debug(1, "Detected a x86\\x86-64 processor with SSE3"); Debug(1, "Detected a x86\\x86-64 processor with SSE3");
} else if ( r_edx & 0x04000000 ) { } else if ( __builtin_cpu_supports("sse2") ) {
sse_version = 20; /* SSE2 */ sse_version = 20; /* SSE2 */
Debug(1, "Detected a x86\\x86-64 processor with SSE2"); Debug(1, "Detected a x86\\x86-64 processor with SSE2");
} else if ( r_edx & 0x02000000 ) { } else if ( __builtin_cpu_supports("sse") ) {
sse_version = 10; /* SSE */ sse_version = 10; /* SSE */
Debug(1, "Detected a x86\\x86-64 processor with SSE"); Debug(1, "Detected a x86\\x86-64 processor with SSE");
} else { } else {