[x264-devel] commit: --asm to allow testing of different versions of asm without recompile ( Loren Merritt )

git version control git at videolan.org
Tue Apr 22 09:26:45 CEST 2008


x264 | branch: master | Loren Merritt <pengvado at akuvian.org> | Sun Apr 20 18:25:53 2008 -0600| [d940f6e66f418e24daa16f93f649ba9a38b173ce]

--asm to allow testing of different versions of asm without recompile

> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=d940f6e66f418e24daa16f93f649ba9a38b173ce
---

 common/common.c   |   21 ++++++++++++++++++++-
 common/cpu.c      |   19 +++++++++++++++++++
 common/cpu.h      |    5 +++++
 common/osdep.h    |    1 +
 encoder/encoder.c |   22 +++++++++-------------
 x264.c            |    2 ++
 6 files changed, 56 insertions(+), 14 deletions(-)

diff --git a/common/common.c b/common/common.c
index 2d00384..ff8ce77 100644
--- a/common/common.c
+++ b/common/common.c
@@ -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") )
diff --git a/common/cpu.c b/common/cpu.c
index a486793..0f71335 100644
--- a/common/cpu.c
+++ b/common/cpu.c
@@ -35,6 +35,25 @@
 
 #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 );
diff --git a/common/cpu.h b/common/cpu.h
index 84a4562..3be940b 100644
--- a/common/cpu.h
+++ b/common/cpu.h
@@ -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
diff --git a/common/osdep.h b/common/osdep.h
index a4b38d4..9817072 100644
--- a/common/osdep.h
+++ b/common/osdep.h
@@ -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
diff --git a/encoder/encoder.c b/encoder/encoder.c
index 7637dc2..2b81e64 100644
--- a/encoder/encoder.c
+++ b/encoder/encoder.c
@@ -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 51bd0cd..70adb71 100644
--- 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 },



More information about the x264-devel mailing list