]> git.sesse.net Git - ffmpeg/blobdiff - libavutil/cpu.c
Merge remote-tracking branch 'cehoyos/master'
[ffmpeg] / libavutil / cpu.c
index 2d402117d045e23d4e8bbda6cbaa7012a388af87..1cd0522dc6f11f7910d75fff6afa7ede9244d21c 100644 (file)
@@ -225,6 +225,10 @@ int av_parse_cpu_caps(unsigned *flags, const char *s)
         { "vfp",      NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_VFP      },    .unit = "flags" },
         { "vfpv3",    NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_VFPV3    },    .unit = "flags" },
         { "neon",     NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_NEON     },    .unit = "flags" },
+#elif ARCH_AARCH64
+        { "armv8",    NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_ARMV8    },    .unit = "flags" },
+        { "neon",     NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_NEON     },    .unit = "flags" },
+        { "vfp",      NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_VFP      },    .unit = "flags" },
 #endif
         { NULL },
     };
@@ -278,6 +282,11 @@ int av_cpu_count(void)
 #ifdef TEST
 
 #include <stdio.h>
+#include "avstring.h"
+
+#if !HAVE_GETOPT
+#include "compat/getopt.c"
+#endif
 
 static const struct {
     int flag;
@@ -301,9 +310,9 @@ static const struct {
     { AV_CPU_FLAG_MMXEXT,    "mmxext"     },
     { AV_CPU_FLAG_SSE,       "sse"        },
     { AV_CPU_FLAG_SSE2,      "sse2"       },
-    { AV_CPU_FLAG_SSE2SLOW,  "sse2(slow)" },
+    { AV_CPU_FLAG_SSE2SLOW,  "sse2slow"   },
     { AV_CPU_FLAG_SSE3,      "sse3"       },
-    { AV_CPU_FLAG_SSE3SLOW,  "sse3(slow)" },
+    { AV_CPU_FLAG_SSE3SLOW,  "sse3slow"   },
     { AV_CPU_FLAG_SSSE3,     "ssse3"      },
     { AV_CPU_FLAG_ATOM,      "atom"       },
     { AV_CPU_FLAG_SSE4,      "sse4.1"     },
@@ -322,17 +331,71 @@ static const struct {
     { 0 }
 };
 
-int main(void)
+static void print_cpu_flags(int cpu_flags, const char *type)
 {
-    int cpu_flags = av_get_cpu_flags();
     int i;
 
-    printf("cpu_flags = 0x%08X\n", cpu_flags);
-    printf("cpu_flags =");
+    printf("cpu_flags(%s) = 0x%08X\n", type, cpu_flags);
+    printf("cpu_flags_str(%s) =", type);
     for (i = 0; cpu_flag_tab[i].flag; i++)
         if (cpu_flags & cpu_flag_tab[i].flag)
             printf(" %s", cpu_flag_tab[i].name);
     printf("\n");
+}
+
+
+int main(int argc, char **argv)
+{
+    int cpu_flags_raw = av_get_cpu_flags();
+    int cpu_flags_eff;
+    int cpu_count = av_cpu_count();
+    char threads[5] = "auto";
+    int i;
+
+    for(i = 0; cpu_flag_tab[i].flag; i++) {
+        unsigned tmp = 0;
+        if (av_parse_cpu_caps(&tmp, cpu_flag_tab[i].name) < 0) {
+            fprintf(stderr, "Table missing %s\n", cpu_flag_tab[i].name);
+            return 4;
+        }
+    }
+
+    if (cpu_flags_raw < 0)
+        return 1;
+
+    for (;;) {
+        int c = getopt(argc, argv, "c:t:");
+        if (c == -1)
+            break;
+        switch (c) {
+        case 'c':
+        {
+            unsigned flags = av_get_cpu_flags();
+            if (av_parse_cpu_caps(&flags, optarg) < 0)
+                return 2;
+
+            av_force_cpu_flags(flags);
+            break;
+        }
+        case 't':
+        {
+            int len = av_strlcpy(threads, optarg, sizeof(threads));
+            if (len >= sizeof(threads)) {
+                fprintf(stderr, "Invalid thread count '%s'\n", optarg);
+                return 2;
+            }
+        }
+        }
+    }
+
+    cpu_flags_eff = av_get_cpu_flags();
+
+    if (cpu_flags_eff < 0)
+        return 3;
+
+    print_cpu_flags(cpu_flags_raw, "raw");
+    print_cpu_flags(cpu_flags_eff, "effective");
+    printf("threads = %s (cpu_count = %d)\n", threads, cpu_count);
 
     return 0;
 }