]> granicus.if.org Git - libx264/commitdiff
--asm to allow testing of different versions of asm without recompile
authorLoren Merritt <pengvado@akuvian.org>
Mon, 21 Apr 2008 00:25:53 +0000 (18:25 -0600)
committerLoren Merritt <pengvado@akuvian.org>
Mon, 21 Apr 2008 00:25:53 +0000 (18:25 -0600)
common/common.c
common/cpu.c
common/cpu.h
common/osdep.h
encoder/encoder.c
x264.c

index 2d00384f810a081ba2aa261445c60efeccaf77db..ff8ce7796f5daa22352eb1d78e381901ccf3baae 100644 (file)
@@ -22,6 +22,7 @@
  *****************************************************************************/
 
 #include <stdarg.h>
+#include <ctype.h>
 
 #ifdef HAVE_MALLOC_H
 #include <malloc.h>
@@ -239,7 +240,25 @@ int x264_param_parse( x264_param_t *p, const char *name, const char *value )
 #define OPT2(STR0, STR1) else if( !strcmp( name, STR0 ) || !strcmp( name, STR1 ) )
     if(0);
     OPT("asm")
-        p->cpu = atobool(value) ? x264_cpu_detect() : 0;
+    {
+        p->cpu = isdigit(value[0]) ? atoi(value) :
+                 !strcmp(value, "auto") || atobool(value) ? x264_cpu_detect() : 0;
+        if( b_error )
+        {
+            char *buf = strdup(value);
+            char *tok, *saveptr, *init;
+            b_error = 0;
+            p->cpu = 0;
+            for( init=buf; (tok=strtok_r(init, ",", &saveptr)); init=NULL )
+            {
+                for( i=0; x264_cpu_names[i].flags && strcasecmp(tok, x264_cpu_names[i].name); i++ );
+                p->cpu |= x264_cpu_names[i].flags;
+                if( !x264_cpu_names[i].flags )
+                    b_error = 1;
+            }
+            free( buf );
+        }
+    }
     OPT("threads")
     {
         if( !strcmp(value, "auto") )
index a486793e8be1cacb023baeb55b9c94356d0c8ce6..0f713358526c07d4af51b754b9dc5503821b3267 100644 (file)
 
 #include "common.h"
 
+const struct {
+    const char name[8];
+    int flags;
+} x264_cpu_names[] = {
+    {"MMX",     X264_CPU_MMX},
+    {"MMX2",    X264_CPU_MMX|X264_CPU_MMXEXT},
+    {"MMXEXT",  X264_CPU_MMX|X264_CPU_MMXEXT},
+    {"SSE",     X264_CPU_MMX|X264_CPU_MMXEXT|X264_CPU_SSE},
+    {"SSE1",    X264_CPU_MMX|X264_CPU_MMXEXT|X264_CPU_SSE},
+    {"SSE2",    X264_CPU_MMX|X264_CPU_MMXEXT|X264_CPU_SSE|X264_CPU_SSE2},
+    {"SSE3",    X264_CPU_MMX|X264_CPU_MMXEXT|X264_CPU_SSE|X264_CPU_SSE2|X264_CPU_SSE3},
+    {"SSSE3",   X264_CPU_MMX|X264_CPU_MMXEXT|X264_CPU_SSE|X264_CPU_SSE2|X264_CPU_SSE3|X264_CPU_SSSE3},
+    {"3DNow",   X264_CPU_3DNOW},
+    {"Altivec", X264_CPU_ALTIVEC},
+    {"Cache32", X264_CPU_CACHELINE_SPLIT|X264_CPU_CACHELINE_32},
+    {"Cache64", X264_CPU_CACHELINE_SPLIT|X264_CPU_CACHELINE_64},
+    {"", 0},
+};
+
 #ifdef HAVE_MMX
 extern int  x264_cpu_cpuid_test( void );
 extern uint32_t  x264_cpu_cpuid( uint32_t op, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx );
index 84a45627c17a1a249a9406d72e13edc8b8a67fae..3be940b5136784fcd786d2f76e2698e1e7f2d979 100644 (file)
@@ -44,4 +44,9 @@ void x264_stack_align( void (*func)(x264_t*), x264_t *arg );
 #define x264_stack_align(func,arg) func(arg)
 #endif
 
+extern const struct {
+    const char name[8];
+    int flags;
+} x264_cpu_names[];
+
 #endif
index a4b38d44414cbac40860496f2d0ee9a1fb696278..98170728a83d3b33e54e244c8c9e3f3898534f6b 100644 (file)
@@ -35,6 +35,7 @@
 #include <io.h>    // _setmode()
 #include <fcntl.h> // _O_BINARY
 #define inline __inline
+#define strcasecmp stricmp
 #define strncasecmp strnicmp
 #define snprintf _snprintf
 #define fseek _fseeki64
index 7637dc2bd280b0e78a04c6ec686182db966aebd5..2b81e6432b1f01fa55c94abb2a6f3e705c1a7821 100644 (file)
@@ -570,6 +570,7 @@ static void mbcmp_init( x264_t *h )
 x264_t *x264_encoder_open   ( x264_param_t *param )
 {
     x264_t *h = x264_malloc( sizeof( x264_t ) );
+    char buf[1000], *p;
     int i;
 
     memset( h, 0, sizeof( x264_t ) );
@@ -684,19 +685,14 @@ x264_t *x264_encoder_open   ( x264_param_t *param )
 
     mbcmp_init( h );
 
-    x264_log( h, X264_LOG_INFO, "using cpu capabilities: %s%s%s%s%s%s%s%s%s%s\n",
-             param->cpu&X264_CPU_MMX ? "MMX " : "",
-             param->cpu&X264_CPU_MMXEXT ? "MMXEXT " : "",
-             param->cpu&X264_CPU_SSE ? "SSE " : "",
-             param->cpu&X264_CPU_SSE2 ? "SSE2 " : "",
-             param->cpu&X264_CPU_SSE3 ? "SSE3 " : "",
-             param->cpu&X264_CPU_SSSE3 ? "SSSE3 " : "",
-             param->cpu&X264_CPU_3DNOW ? "3DNow! " : "",
-             param->cpu&X264_CPU_ALTIVEC ? "Altivec " : "",
-             param->cpu&X264_CPU_CACHELINE_SPLIT ?
-                 param->cpu&X264_CPU_CACHELINE_32 ? "Cache32 " :
-                 param->cpu&X264_CPU_CACHELINE_64 ? "Cache64 " : "Cache? " : "",
-             param->cpu ? "" : "none!" );
+    p = buf + sprintf( buf, "using cpu capabilities:" );
+    for( i=0; x264_cpu_names[i].flags; i++ )
+        if( (param->cpu & x264_cpu_names[i].flags) == x264_cpu_names[i].flags
+            && (!i || x264_cpu_names[i].flags != x264_cpu_names[i-1].flags) )
+            p += sprintf( p, " %s", x264_cpu_names[i].name );
+    if( !param->cpu )
+        p += sprintf( p, " none!" );
+    x264_log( h, X264_LOG_INFO, "%s\n", buf );
 
     h->out.i_nal = 0;
     h->out.i_bitstream = X264_MAX( 1000000, h->param.i_width * h->param.i_height * 4
diff --git a/x264.c b/x264.c
index 51bd0cd97500d7232589bdadbbcbc944cdc1103d..70adb7180394ceb1a2295820f45e094744d83d50 100644 (file)
--- a/x264.c
+++ b/x264.c
@@ -316,6 +316,7 @@ static void Help( x264_param_t *defaults, int b_longhelp )
     H0( "      --threads <integer>     Parallel encoding\n" );
     H0( "      --thread-input          Run Avisynth in its own thread\n" );
     H1( "      --non-deterministic     Slightly improve quality of SMP, at the cost of repeatability\n" );
+    H1( "      --asm <integer>         Override CPU detection\n" );
     H1( "      --no-asm                Disable all CPU optimizations\n" );
     H1( "      --visualize             Show MB types overlayed on the encoded video\n" );
     H1( "      --sps-id <integer>      Set SPS and PPS id numbers [%d]\n", defaults->i_sps_id );
@@ -392,6 +393,7 @@ static int  Parse( int argc, char **argv,
             { "qpstep",  required_argument, NULL, 0 },
             { "crf",     required_argument, NULL, 0 },
             { "ref",     required_argument, NULL, 'r' },
+            { "asm",     required_argument, NULL, 0 },
             { "no-asm",  no_argument,       NULL, 0 },
             { "sar",     required_argument, NULL, 0 },
             { "fps",     required_argument, NULL, 0 },