(Performance) Use one single unsigned variable instead of

multiple bools - also introduce bitmasks
This commit is contained in:
twinaphex 2012-11-05 09:06:00 +01:00
parent 9f3af988f1
commit af648b6598
3 changed files with 37 additions and 16 deletions

View File

@ -146,18 +146,35 @@ void rarch_get_cpu_features(struct rarch_cpu_features *cpu)
return;
x86_cpuid(1, flags);
cpu->sse = flags[3] & (1 << 25);
cpu->sse2 = flags[3] & (1 << 26);
if(flags[3] & (1 << 25))
cpu->simd |= RARCH_SIMD_SSE;
if(flags[3] & (1 << 26))
cpu->simd |= RARCH_SIMD_SSE2;
int avx_flags = (1 << 27) | (1 << 28);
cpu->avx = (flags[2] & avx_flags) == avx_flags; // Is this enough?
RARCH_LOG("[CPUID]: SSE: %d\n", cpu->sse);
RARCH_LOG("[CPUID]: SSE2: %d\n", cpu->sse2);
RARCH_LOG("[CPUID]: AVX: %d\n", cpu->avx);
if((flags[2] & avx_flags) == avx_flags)
cpu->simd |= RARCH_SIMD_AVX;
RARCH_LOG("[CPUID]: SSE: %d\n", (cpu->simd & RARCH_SIMD_SSE) == RARCH_SIMD_SSE);
RARCH_LOG("[CPUID]: SSE2: %d\n", (cpu->simd & RARCH_SIMD_SSE2) == RARCH_SIMD_SSE2);
RARCH_LOG("[CPUID]: AVX: %d\n", (cpu->simd & RARCH_SIMD_AVX) == RARCH_SIMD_AVX);
#elif defined(ANDROID) && defined(ANDROID_ARM)
uint64_t cpu_flags = android_getCpuFeatures();
cpu->neon = (cpu_flags & ANDROID_CPU_ARM_FEATURE_NEON);
RARCH_LOG("[CPUID]: NEON: %d\n", cpu->neon);
if(cpu_flags & ANDROID_CPU_ARM_FEATURE_NEON)
cpu->simd |= RARCH_SIMD_NEON;
RARCH_LOG("[CPUID]: NEON: %d\n", (cpu->simd & RARCH_SIMD_NEON) == RARCH_SIMD_NEON);
#elif defined(__CELLOS_LV2__)
cpu->simd |= RARCH_SIMD_VMX;
RARCH_LOG("[CPUID]: VMX: %d\n", (cpu->simd & RARCH_SIMD_VMX) == RARCH_SIMD_VMX);
#elif defined(XBOX360)
cpu->simd |= RARCH_SIMD_VMX128;
RARCH_LOG("[CPUID]: VMX128: %d\n", (cpu->simd & RARCH_SIMD_VMX128) == RARCH_SIMD_VMX128);
#endif
}

View File

@ -42,13 +42,17 @@ void rarch_perf_log(void);
struct rarch_cpu_features
{
bool sse;
bool sse2;
bool vmx;
bool avx;
bool neon;
uint32_t simd;
};
// Id values for SIMD CPU features
#define RARCH_SIMD_SSE (1 << 0)
#define RARCH_SIMD_SSE2 (1 << 1)
#define RARCH_SIMD_VMX (1 << 2)
#define RARCH_SIMD_VMX128 (1 << 3)
#define RARCH_SIMD_AVX (1 << 4)
#define RARCH_SIMD_NEON (1 << 5)
void rarch_get_cpu_features(struct rarch_cpu_features *cpu);
#ifdef PERF_TEST

View File

@ -2594,15 +2594,15 @@ static void validate_cpu_features(void)
} while(0)
#ifdef __SSE__
if (!cpu.sse)
if ((cpu.simd & RARCH_SIMD_SSE) != RARCH_SIMD_SSE)
FAIL_CPU("SSE");
#endif
#ifdef __SSE2__
if (!cpu.sse2)
if ((cpu.simd & RARCH_SIMD_SSE2) != RARCH_SIMD_SSE2)
FAIL_CPU("SSE2");
#endif
#ifdef __AVX__
if (!cpu.avx)
if ((cpu.simd & RARCH_SIMD_AVX) != RARCH_SIMD_AVX)
FAIL_CPU("AVX");
#endif
}