Add --cpuid parameter to disable runtime optimizations.

This commit is contained in:
Ari Koivula 2014-10-14 12:01:56 +03:00
parent b32867be2a
commit 75a137c1e9
5 changed files with 48 additions and 39 deletions

View file

@ -95,6 +95,7 @@ int config_init(config *cfg)
cfg->slice_addresses_in_ts[0] = 0; cfg->slice_addresses_in_ts[0] = 0;
cfg->threads = 0; cfg->threads = 0;
cfg->cpuid = 1;
return 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); error = !parse_slice_specification(value, &cfg->slice_count, &cfg->slice_addresses_in_ts);
else if OPT("threads") else if OPT("threads")
cfg->threads = atoi(value); cfg->threads = atoi(value);
else if OPT("cpuid")
cfg->cpuid = atoi(value);
else else
return 0; return 0;
#undef OPT #undef OPT
@ -492,6 +495,7 @@ int config_read(config *cfg,int argc, char *argv[])
{ "owf", required_argument, NULL, 0 }, { "owf", required_argument, NULL, 0 },
{ "slice-addresses", required_argument, NULL, 0 }, { "slice-addresses", required_argument, NULL, 0 },
{ "threads", required_argument, NULL, 0 }, { "threads", required_argument, NULL, 0 },
{ "cpuid", required_argument, NULL, 0 },
{0, 0, 0, 0} {0, 0, 0, 0}
}; };

View file

@ -79,6 +79,7 @@ typedef struct
int32_t* slice_addresses_in_ts; int32_t* slice_addresses_in_ts;
int32_t threads; int32_t threads;
int32_t cpuid;
} config; } config;
/* Function definitions */ /* Function definitions */

View file

@ -79,13 +79,6 @@ int main(int argc, char *argv[])
CHECKPOINTS_INIT(); CHECKPOINTS_INIT();
//Initialize strategies
if (!strategyselector_init()) {
fprintf(stderr, "Failed to initialize strategies.\n");
return EXIT_FAILURE;
}
// Handle configuration // Handle configuration
cfg = config_alloc(); cfg = config_alloc();
@ -125,6 +118,7 @@ int main(int argc, char *argv[])
" --aud : Use access unit delimiters\n" " --aud : Use access unit delimiters\n"
" --cqmfile <string> : Custom Quantization Matrices from a file\n" " --cqmfile <string> : Custom Quantization Matrices from a file\n"
" --debug <string> : Output encoders reconstruction.\n" " --debug <string> : Output encoders reconstruction.\n"
" --cpuid <integer> : Disable runtime cpu optimizations with value 0.\n"
"\n" "\n"
" Video Usability Information:\n" " Video Usability Information:\n"
" --sar <width:height> : Specify Sample Aspect Ratio\n" " --sar <width:height> : Specify Sample Aspect Ratio\n"
@ -202,6 +196,12 @@ int main(int argc, char *argv[])
goto exit_failure; 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 // Check if the input file name is a dash, this means stdin
if (!strcmp(cfg->input, "-")) { if (!strcmp(cfg->input, "-")) {
input = stdin; input = stdin;

View file

@ -32,13 +32,13 @@
hardware_flags g_hardware_flags; 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); static void* strategyselector_choose_for(const strategy_list * const strategies, const char * const strategy_type);
//Strategies to include (add new file here) //Strategies to include (add new file here)
//Returns 1 if successful //Returns 1 if successful
int strategyselector_init() { int strategyselector_init(int32_t cpuid) {
const strategy_to_select *cur_strategy_to_select = strategies_to_select; const strategy_to_select *cur_strategy_to_select = strategies_to_select;
strategy_list strategies; strategy_list strategies;
@ -46,7 +46,7 @@ int strategyselector_init() {
strategies.count = 0; strategies.count = 0;
strategies.strategies = NULL; strategies.strategies = NULL;
set_hardware_flags(); set_hardware_flags(cpuid);
//Add new register function here //Add new register function here
if (!strategy_register_picture(&strategies)) { if (!strategy_register_picture(&strategies)) {
@ -232,15 +232,15 @@ out_close:
} }
#endif //COMPILE_POWERPC #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)); memset(&g_hardware_flags, 0, sizeof(g_hardware_flags));
g_hardware_flags.arm = COMPILE_ARM; g_hardware_flags.arm = COMPILE_ARM;
g_hardware_flags.intel = COMPILE_INTEL; g_hardware_flags.intel = COMPILE_INTEL;
g_hardware_flags.powerpc = COMPILE_POWERPC; g_hardware_flags.powerpc = COMPILE_POWERPC;
#if COMPILE_INTEL #if COMPILE_INTEL
{ if (cpuid) {
unsigned int eax = 0, ebx = 0, ecx = 0, edx =0; unsigned int eax = 0, ebx = 0, ecx = 0, edx =0;
/* CPU feature bits */ /* CPU feature bits */
enum { BIT_SSE3 = 0, BIT_SSSE3 = 9, BIT_SSE41 = 19, BIT_SSE42 = 20, 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); get_cpuid(7, &eax, &ebx, &ecx, &edx);
if (ebx & (1 << 5)) g_hardware_flags.intel_flags.avx2 = 1; 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 #if COMPILE_INTEL_MMX
fprintf(stderr, " MMX"); fprintf(stderr, " MMX");
#endif #endif
#if COMPILE_INTEL_SSE #if COMPILE_INTEL_SSE
fprintf(stderr, " SSE"); fprintf(stderr, " SSE");
#endif #endif
#if COMPILE_INTEL_SSE2 #if COMPILE_INTEL_SSE2
fprintf(stderr, " SSE2"); fprintf(stderr, " SSE2");
#endif #endif
#if COMPILE_INTEL_SSE3 #if COMPILE_INTEL_SSE3
fprintf(stderr, " SSE3"); fprintf(stderr, " SSE3");
#endif #endif
#if COMPILE_INTEL_SSSE3 #if COMPILE_INTEL_SSSE3
fprintf(stderr, " SSSE3"); fprintf(stderr, " SSSE3");
#endif #endif
#if COMPILE_INTEL_SSE41 #if COMPILE_INTEL_SSE41
fprintf(stderr, " SSE41"); fprintf(stderr, " SSE41");
#endif #endif
#if COMPILE_INTEL_SSE42 #if COMPILE_INTEL_SSE42
fprintf(stderr, " SSE42"); fprintf(stderr, " SSE42");
#endif #endif
#if COMPILE_INTEL_AVX #if COMPILE_INTEL_AVX
fprintf(stderr, " AVX"); fprintf(stderr, " AVX");
#endif #endif
#if COMPILE_INTEL_AVX2 #if COMPILE_INTEL_AVX2
fprintf(stderr, " AVX2"); fprintf(stderr, " AVX2");
#endif #endif
fprintf(stderr, "\nRun on : INTEL, flags:"); fprintf(stderr, "\nDetected: INTEL, flags:");
if (g_hardware_flags.intel_flags.mmx) fprintf(stderr, " MMX"); 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.sse) fprintf(stderr, " SSE");
if (g_hardware_flags.intel_flags.sse2) fprintf(stderr, " SSE2"); 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.sse3) fprintf(stderr, " SSE3");
if (g_hardware_flags.intel_flags.ssse3) fprintf(stderr, " SSSE3"); 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.sse41) fprintf(stderr, " SSE41");
if (g_hardware_flags.intel_flags.sse42) fprintf(stderr, " SSE42"); 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.avx) fprintf(stderr, " AVX");
if (g_hardware_flags.intel_flags.avx2) fprintf(stderr, " AVX2"); if (g_hardware_flags.intel_flags.avx2) fprintf(stderr, " AVX2");
fprintf(stderr, "\n"); fprintf(stderr, "\n");
}
#endif //COMPILE_INTEL #endif //COMPILE_INTEL
#if COMPILE_POWERPC #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:"); fprintf(stderr, "Compiled: PowerPC, flags:");
#if COMPILE_POWERPC_ALTIVEC #if COMPILE_POWERPC_ALTIVEC
fprintf(stderr, " AltiVec"); fprintf(stderr, " AltiVec");
#endif #endif
fprintf(stderr, "\nRun on : PowerPC, flags:"); fprintf(stderr, "\nDetected: PowerPC, flags:");
if (g_hardware_flags.powerpc_flags.altivec) fprintf(stderr, " AltiVec"); if (g_hardware_flags.powerpc_flags.altivec) fprintf(stderr, " AltiVec");
fprintf(stderr, "\n"); fprintf(stderr, "\n");
#endif #endif

View file

@ -19,6 +19,8 @@
* along with Kvazaar. If not, see <http://www.gnu.org/licenses/>. * along with Kvazaar. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/ ****************************************************************************/
#include "global.h"
#if defined(_DEBUG) && !defined(DEBUG_STRATEGYSELECTOR) #if defined(_DEBUG) && !defined(DEBUG_STRATEGYSELECTOR)
# define DEBUG_STRATEGYSELECTOR # define DEBUG_STRATEGYSELECTOR
#endif #endif
@ -136,7 +138,7 @@ typedef struct {
extern hardware_flags g_hardware_flags; extern hardware_flags g_hardware_flags;
int strategyselector_init(); int strategyselector_init(int32_t cpuid);
void strategyselector_free(); void strategyselector_free();
int strategyselector_register(void *opaque, const char *type, const char *strategy_name, int priority, void *fptr); int strategyselector_register(void *opaque, const char *type, const char *strategy_name, int priority, void *fptr);