From 75a137c1e97a44e3351782aa780d0a33f24d97ed Mon Sep 17 00:00:00 2001 From: Ari Koivula Date: Tue, 14 Oct 2014 12:01:56 +0300 Subject: [PATCH] Add --cpuid parameter to disable runtime optimizations. --- src/config.c | 4 +++ src/config.h | 1 + src/encmain.c | 14 ++++----- src/strategyselector.c | 64 ++++++++++++++++++++++-------------------- src/strategyselector.h | 4 ++- 5 files changed, 48 insertions(+), 39 deletions(-) diff --git a/src/config.c b/src/config.c index a7d52a84..f82a23a5 100644 --- a/src/config.c +++ b/src/config.c @@ -95,6 +95,7 @@ int config_init(config *cfg) cfg->slice_addresses_in_ts[0] = 0; cfg->threads = 0; + cfg->cpuid = 1; return 1; } @@ -438,6 +439,8 @@ static int config_parse(config *cfg, const char *name, const char *value) error = !parse_slice_specification(value, &cfg->slice_count, &cfg->slice_addresses_in_ts); else if OPT("threads") cfg->threads = atoi(value); + else if OPT("cpuid") + cfg->cpuid = atoi(value); else return 0; #undef OPT @@ -492,6 +495,7 @@ int config_read(config *cfg,int argc, char *argv[]) { "owf", required_argument, NULL, 0 }, { "slice-addresses", required_argument, NULL, 0 }, { "threads", required_argument, NULL, 0 }, + { "cpuid", required_argument, NULL, 0 }, {0, 0, 0, 0} }; diff --git a/src/config.h b/src/config.h index 5dcbec48..9146b9b1 100644 --- a/src/config.h +++ b/src/config.h @@ -79,6 +79,7 @@ typedef struct int32_t* slice_addresses_in_ts; int32_t threads; + int32_t cpuid; } config; /* Function definitions */ diff --git a/src/encmain.c b/src/encmain.c index ad6a351e..64559158 100644 --- a/src/encmain.c +++ b/src/encmain.c @@ -79,13 +79,6 @@ int main(int argc, char *argv[]) CHECKPOINTS_INIT(); - //Initialize strategies - if (!strategyselector_init()) { - fprintf(stderr, "Failed to initialize strategies.\n"); - return EXIT_FAILURE; - } - - // Handle configuration cfg = config_alloc(); @@ -125,6 +118,7 @@ int main(int argc, char *argv[]) " --aud : Use access unit delimiters\n" " --cqmfile : Custom Quantization Matrices from a file\n" " --debug : Output encoders reconstruction.\n" + " --cpuid : Disable runtime cpu optimizations with value 0.\n" "\n" " Video Usability Information:\n" " --sar : Specify Sample Aspect Ratio\n" @@ -202,6 +196,12 @@ int main(int argc, char *argv[]) goto exit_failure; } + //Initialize strategies + if (!strategyselector_init(cfg->cpuid)) { + fprintf(stderr, "Failed to initialize strategies.\n"); + goto exit_failure; + } + // Check if the input file name is a dash, this means stdin if (!strcmp(cfg->input, "-")) { input = stdin; diff --git a/src/strategyselector.c b/src/strategyselector.c index 901d6771..80172ac9 100644 --- a/src/strategyselector.c +++ b/src/strategyselector.c @@ -32,13 +32,13 @@ hardware_flags g_hardware_flags; -static void set_hardware_flags(); +static void set_hardware_flags(int32_t cpuid); static void* strategyselector_choose_for(const strategy_list * const strategies, const char * const strategy_type); //Strategies to include (add new file here) //Returns 1 if successful -int strategyselector_init() { +int strategyselector_init(int32_t cpuid) { const strategy_to_select *cur_strategy_to_select = strategies_to_select; strategy_list strategies; @@ -46,7 +46,7 @@ int strategyselector_init() { strategies.count = 0; strategies.strategies = NULL; - set_hardware_flags(); + set_hardware_flags(cpuid); //Add new register function here if (!strategy_register_picture(&strategies)) { @@ -232,15 +232,15 @@ out_close: } #endif //COMPILE_POWERPC -static void set_hardware_flags() { +static void set_hardware_flags(int32_t cpuid) { memset(&g_hardware_flags, 0, sizeof(g_hardware_flags)); g_hardware_flags.arm = COMPILE_ARM; g_hardware_flags.intel = COMPILE_INTEL; g_hardware_flags.powerpc = COMPILE_POWERPC; - + #if COMPILE_INTEL - { + if (cpuid) { unsigned int eax = 0, ebx = 0, ecx = 0, edx =0; /* CPU feature bits */ enum { BIT_SSE3 = 0, BIT_SSSE3 = 9, BIT_SSE41 = 19, BIT_SSE42 = 20, @@ -290,58 +290,60 @@ static void set_hardware_flags() { get_cpuid(7, &eax, &ebx, &ecx, &edx); if (ebx & (1 << 5)) g_hardware_flags.intel_flags.avx2 = 1; } + } - - fprintf(stderr, "Compiled: INTEL, flags:"); + fprintf(stderr, "Compiled: INTEL, flags:"); #if COMPILE_INTEL_MMX - fprintf(stderr, " MMX"); + fprintf(stderr, " MMX"); #endif #if COMPILE_INTEL_SSE - fprintf(stderr, " SSE"); + fprintf(stderr, " SSE"); #endif #if COMPILE_INTEL_SSE2 - fprintf(stderr, " SSE2"); + fprintf(stderr, " SSE2"); #endif #if COMPILE_INTEL_SSE3 - fprintf(stderr, " SSE3"); + fprintf(stderr, " SSE3"); #endif #if COMPILE_INTEL_SSSE3 - fprintf(stderr, " SSSE3"); + fprintf(stderr, " SSSE3"); #endif #if COMPILE_INTEL_SSE41 - fprintf(stderr, " SSE41"); + fprintf(stderr, " SSE41"); #endif #if COMPILE_INTEL_SSE42 - fprintf(stderr, " SSE42"); + fprintf(stderr, " SSE42"); #endif #if COMPILE_INTEL_AVX - fprintf(stderr, " AVX"); + fprintf(stderr, " AVX"); #endif #if COMPILE_INTEL_AVX2 - fprintf(stderr, " AVX2"); + fprintf(stderr, " AVX2"); #endif - fprintf(stderr, "\nRun on : INTEL, flags:"); - if (g_hardware_flags.intel_flags.mmx) fprintf(stderr, " MMX"); - if (g_hardware_flags.intel_flags.sse) fprintf(stderr, " SSE"); - if (g_hardware_flags.intel_flags.sse2) fprintf(stderr, " SSE2"); - if (g_hardware_flags.intel_flags.sse3) fprintf(stderr, " SSE3"); - if (g_hardware_flags.intel_flags.ssse3) fprintf(stderr, " SSSE3"); - if (g_hardware_flags.intel_flags.sse41) fprintf(stderr, " SSE41"); - if (g_hardware_flags.intel_flags.sse42) fprintf(stderr, " SSE42"); - if (g_hardware_flags.intel_flags.avx) fprintf(stderr, " AVX"); - if (g_hardware_flags.intel_flags.avx2) fprintf(stderr, " AVX2"); - fprintf(stderr, "\n"); - } + fprintf(stderr, "\nDetected: INTEL, flags:"); + if (g_hardware_flags.intel_flags.mmx) fprintf(stderr, " MMX"); + if (g_hardware_flags.intel_flags.sse) fprintf(stderr, " SSE"); + if (g_hardware_flags.intel_flags.sse2) fprintf(stderr, " SSE2"); + if (g_hardware_flags.intel_flags.sse3) fprintf(stderr, " SSE3"); + if (g_hardware_flags.intel_flags.ssse3) fprintf(stderr, " SSSE3"); + if (g_hardware_flags.intel_flags.sse41) fprintf(stderr, " SSE41"); + if (g_hardware_flags.intel_flags.sse42) fprintf(stderr, " SSE42"); + if (g_hardware_flags.intel_flags.avx) fprintf(stderr, " AVX"); + if (g_hardware_flags.intel_flags.avx2) fprintf(stderr, " AVX2"); + fprintf(stderr, "\n"); + #endif //COMPILE_INTEL #if COMPILE_POWERPC - g_hardware_flags.powerpc_flags.altivec = altivec_available(); + if (cpuid) { + g_hardware_flags.powerpc_flags.altivec = altivec_available(); + } fprintf(stderr, "Compiled: PowerPC, flags:"); #if COMPILE_POWERPC_ALTIVEC fprintf(stderr, " AltiVec"); #endif - fprintf(stderr, "\nRun on : PowerPC, flags:"); + fprintf(stderr, "\nDetected: PowerPC, flags:"); if (g_hardware_flags.powerpc_flags.altivec) fprintf(stderr, " AltiVec"); fprintf(stderr, "\n"); #endif diff --git a/src/strategyselector.h b/src/strategyselector.h index fa4f4ffd..1a0463ac 100644 --- a/src/strategyselector.h +++ b/src/strategyselector.h @@ -19,6 +19,8 @@ * along with Kvazaar. If not, see . ****************************************************************************/ +#include "global.h" + #if defined(_DEBUG) && !defined(DEBUG_STRATEGYSELECTOR) # define DEBUG_STRATEGYSELECTOR #endif @@ -136,7 +138,7 @@ typedef struct { extern hardware_flags g_hardware_flags; -int strategyselector_init(); +int strategyselector_init(int32_t cpuid); void strategyselector_free(); int strategyselector_register(void *opaque, const char *type, const char *strategy_name, int priority, void *fptr);