From 8cfeed852c53bb9a03a6972828a83bdfcf352104 Mon Sep 17 00:00:00 2001 From: Eemeli Kallio Date: Tue, 10 May 2016 12:59:15 +0300 Subject: [PATCH] Added print about SIMD optimizations available and in use to strategyselector. --- src/strategyselector.c | 144 ++++++++++++++++++++++++++++++++++++++++- src/strategyselector.h | 5 +- 2 files changed, 144 insertions(+), 5 deletions(-) diff --git a/src/strategyselector.c b/src/strategyselector.c index 58d5b8c4..c0115d42 100644 --- a/src/strategyselector.c +++ b/src/strategyselector.c @@ -25,6 +25,8 @@ #include hardware_flags_t kvz_g_hardware_flags; +hardware_flags_t kvz_g_strategies_in_use; +hardware_flags_t kvz_g_strategies_available; static void set_hardware_flags(int32_t cpuid); static void* strategyselector_choose_for(const strategy_list_t * const strategies, const char * const strategy_type); @@ -87,10 +89,118 @@ int kvz_strategyselector_init(int32_t cpuid, uint8_t bitdepth) { } ++cur_strategy_to_select; } - + //We can free the structure now, as all strategies are statically set to pointers if (strategies.allocated) { - free(strategies.strategies); + //Also check what optimizations are available and what are in use + //SIMD optimizations available + bool strategies_available = false; + fprintf(stderr, "Available: "); + if (kvz_g_strategies_available.intel_flags.avx != 0){ + fprintf(stderr, "avx(%d) ", kvz_g_strategies_available.intel_flags.avx); + strategies_available = true; + } + if (kvz_g_strategies_available.intel_flags.avx2 != 0){ + fprintf(stderr, "avx2(%d) ", kvz_g_strategies_available.intel_flags.avx2); + strategies_available = true; + } + if (kvz_g_strategies_available.intel_flags.mmx != 0) { + fprintf(stderr, "mmx(%d) ", kvz_g_strategies_available.intel_flags.mmx); + strategies_available = true; + } + if (kvz_g_strategies_available.intel_flags.sse != 0) { + fprintf(stderr, "sse(%d) ", kvz_g_strategies_available.intel_flags.sse); + strategies_available = true; + } + if (kvz_g_strategies_available.intel_flags.sse2 != 0) { + fprintf(stderr, "sse2(%d) ", kvz_g_strategies_available.intel_flags.sse2); + strategies_available = true; + } + if (kvz_g_strategies_available.intel_flags.sse3 != 0) { + fprintf(stderr, "sse3(%d) ", kvz_g_strategies_available.intel_flags.sse3); + strategies_available = true; + } + if (kvz_g_strategies_available.intel_flags.sse41 != 0) { + fprintf(stderr, "sse41(%d) ", kvz_g_strategies_available.intel_flags.sse41); + strategies_available = true; + } + if (kvz_g_strategies_available.intel_flags.sse42 != 0) { + fprintf(stderr, "sse42(%d) ", kvz_g_strategies_available.intel_flags.sse42); + strategies_available = true; + } + if (kvz_g_strategies_available.intel_flags.ssse3 != 0) { + fprintf(stderr, "ssse3(%d) ", kvz_g_strategies_available.intel_flags.ssse3); + strategies_available = true; + } + if (kvz_g_strategies_available.arm_flags.neon != 0) { + fprintf(stderr, "neon(%d) ", kvz_g_strategies_available.arm_flags.neon); + strategies_available = true; + } + if (kvz_g_strategies_available.powerpc_flags.altivec != 0) { + fprintf(stderr, "altivec(%d) ", kvz_g_strategies_available.powerpc_flags.altivec); + strategies_available = true; + } + //If there is no strategies available + if (!strategies_available){ + fprintf(stderr, "no SIMD optimizations"); + } + fprintf(stderr, "\n"); + + //SIMD optimizations in use + bool strategies_in_use = false; + fprintf(stderr, "In use: "); + if (kvz_g_strategies_in_use.intel_flags.avx != 0){ + fprintf(stderr, "avx(%d) ", kvz_g_strategies_in_use.intel_flags.avx); + strategies_in_use = true; + } + if (kvz_g_strategies_in_use.intel_flags.avx2 != 0){ + fprintf(stderr, "avx2(%d) ", kvz_g_strategies_in_use.intel_flags.avx2); + strategies_in_use = true; + } + if (kvz_g_strategies_in_use.intel_flags.mmx != 0) { + fprintf(stderr, "mmx(%d) ", kvz_g_strategies_in_use.intel_flags.mmx); + strategies_in_use = true; + } + if (kvz_g_strategies_in_use.intel_flags.sse != 0) { + fprintf(stderr, "sse(%d) ", kvz_g_strategies_in_use.intel_flags.sse); + strategies_in_use = true; + } + if (kvz_g_strategies_in_use.intel_flags.sse2 != 0) { + fprintf(stderr, "sse2(%d) ", kvz_g_strategies_in_use.intel_flags.sse2); + strategies_in_use = true; + } + if (kvz_g_strategies_in_use.intel_flags.sse3 != 0) { + fprintf(stderr, "sse3(%d) ", kvz_g_strategies_in_use.intel_flags.sse3); + strategies_in_use = true; + } + if (kvz_g_strategies_in_use.intel_flags.sse41 != 0) { + fprintf(stderr, "sse41(%d) ", kvz_g_strategies_in_use.intel_flags.sse41); + strategies_in_use = true; + } + if (kvz_g_strategies_in_use.intel_flags.sse42 != 0) { + fprintf(stderr, "sse42(%d) ", kvz_g_strategies_in_use.intel_flags.sse42); + strategies_in_use = true; + } + if (kvz_g_strategies_in_use.intel_flags.ssse3 != 0) { + fprintf(stderr, "ssse3(%d) ", kvz_g_strategies_in_use.intel_flags.ssse3); + strategies_in_use = true; + } + if (kvz_g_strategies_in_use.arm_flags.neon != 0) { + fprintf(stderr, "neon(%d) ", kvz_g_strategies_in_use.arm_flags.neon); + strategies_in_use = true; + } + if (kvz_g_strategies_in_use.powerpc_flags.altivec != 0) { + fprintf(stderr, "altivec(%d) ", kvz_g_strategies_in_use.powerpc_flags.altivec); + strategies_in_use = true; + } + //If there is no strategies in use + if (!strategies_in_use){ + fprintf(stderr, "no SIMD optimizations"); + } + fprintf(stderr, "\n"); + + //Free memory + free(strategies.strategies); } return 1; @@ -117,6 +227,21 @@ int kvz_strategyselector_register(void * const opaque, const char * const type, new_strategy->priority = priority; new_strategy->fptr = fptr; } + + //Check what strategies are available when they are registered + if (strcmp(strategy_name, "avx") == 0) kvz_g_strategies_available.intel_flags.avx++; + if (strcmp(strategy_name, "x86_asm_avx") == 0) kvz_g_strategies_available.intel_flags.avx++; + if (strcmp(strategy_name, "avx2") == 0) kvz_g_strategies_available.intel_flags.avx2++; + if (strcmp(strategy_name, "mmx") == 0) kvz_g_strategies_available.intel_flags.mmx++; + if (strcmp(strategy_name, "sse") == 0) kvz_g_strategies_available.intel_flags.sse++; + if (strcmp(strategy_name, "sse2") == 0) kvz_g_strategies_available.intel_flags.sse2++; + if (strcmp(strategy_name, "sse3") == 0) kvz_g_strategies_available.intel_flags.sse3++; + if (strcmp(strategy_name, "sse41") == 0) kvz_g_strategies_available.intel_flags.sse41++; + if (strcmp(strategy_name, "sse42") == 0) kvz_g_strategies_available.intel_flags.sse42++; + if (strcmp(strategy_name, "ssse3") == 0) kvz_g_strategies_available.intel_flags.ssse3++; + if (strcmp(strategy_name, "altivec") == 0) kvz_g_strategies_available.powerpc_flags.altivec++; + if (strcmp(strategy_name, "neon") == 0) kvz_g_strategies_available.arm_flags.neon++; + #ifdef DEBUG_STRATEGYSELECTOR fprintf(stderr, "Registered strategy %s:%s with priority %d (%p)\n", type, strategy_name, priority, fptr); #endif //DEBUG_STRATEGYSELECTOR @@ -174,6 +299,20 @@ static void* strategyselector_choose_for(const strategy_list_t * const strategie if (max_priority_i == -1) { return NULL; } + + //Check what strategy we are going to use + if (strcmp(strategies->strategies[max_priority_i].strategy_name, "avx") == 0) kvz_g_strategies_in_use.intel_flags.avx++; + if (strcmp(strategies->strategies[max_priority_i].strategy_name, "x86_asm_avx") == 0) kvz_g_strategies_available.intel_flags.avx++; + if (strcmp(strategies->strategies[max_priority_i].strategy_name, "avx2") == 0) kvz_g_strategies_in_use.intel_flags.avx2++; + if (strcmp(strategies->strategies[max_priority_i].strategy_name, "mmx") == 0) kvz_g_strategies_in_use.intel_flags.mmx++; + if (strcmp(strategies->strategies[max_priority_i].strategy_name, "sse") == 0) kvz_g_strategies_in_use.intel_flags.sse++; + if (strcmp(strategies->strategies[max_priority_i].strategy_name, "sse2") == 0) kvz_g_strategies_in_use.intel_flags.sse2++; + if (strcmp(strategies->strategies[max_priority_i].strategy_name, "sse3") == 0) kvz_g_strategies_in_use.intel_flags.sse3++; + if (strcmp(strategies->strategies[max_priority_i].strategy_name, "sse41") == 0) kvz_g_strategies_in_use.intel_flags.sse41++; + if (strcmp(strategies->strategies[max_priority_i].strategy_name, "sse42") == 0) kvz_g_strategies_in_use.intel_flags.sse42++; + if (strcmp(strategies->strategies[max_priority_i].strategy_name, "ssse3") == 0) kvz_g_strategies_in_use.intel_flags.ssse3++; + if (strcmp(strategies->strategies[max_priority_i].strategy_name, "altivec") == 0) kvz_g_strategies_in_use.powerpc_flags.altivec++; + if (strcmp(strategies->strategies[max_priority_i].strategy_name, "neon") == 0) kvz_g_strategies_in_use.arm_flags.neon++; return strategies->strategies[max_priority_i].fptr; } @@ -369,7 +508,6 @@ static void set_hardware_flags(int32_t cpuid) { if (kvz_g_hardware_flags.intel_flags.avx) fprintf(stderr, " AVX"); if (kvz_g_hardware_flags.intel_flags.avx2) fprintf(stderr, " AVX2"); fprintf(stderr, "\n"); - #endif //COMPILE_INTEL #if COMPILE_POWERPC diff --git a/src/strategyselector.h b/src/strategyselector.h index 6be48f62..1eae4d5a 100644 --- a/src/strategyselector.h +++ b/src/strategyselector.h @@ -41,7 +41,7 @@ typedef struct { typedef struct { unsigned int count; - unsigned int allocated; + unsigned int allocated;//How much memory is allocated strategy_t* strategies; } strategy_list_t; @@ -75,7 +75,8 @@ typedef struct { } hardware_flags_t; extern hardware_flags_t kvz_g_hardware_flags; - +extern hardware_flags_t kvz_g_strategies_in_use; +extern hardware_flags_t kvz_g_strategies_available; int kvz_strategyselector_init(int32_t cpuid, uint8_t bitdepth); int kvz_strategyselector_register(void *opaque, const char *type, const char *strategy_name, int priority, void *fptr);