[FFmpeg-devel] [PATCH] Add AVX2 capable CPU detection

Kieran Kunhya kierank at ob-encoder.com
Sun Oct 20 16:42:46 CEST 2013


---
 configure                |    3 +++
 libavutil/cpu.c          |    2 ++
 libavutil/cpu.h          |    2 ++
 libavutil/x86/cpu.c      |    9 +++++++++
 libavutil/x86/cpu.h      |    3 +++
 libswscale/x86/input.asm |    6 ++++++
 6 files changed, 25 insertions(+)

diff --git a/configure b/configure
index 7e52abf..1c00309 100755
--- a/configure
+++ b/configure
@@ -269,6 +269,7 @@ Optimization options (experts only):
   --disable-sse42          disable SSE4.2 optimizations
   --disable-avx            disable AVX optimizations
   --disable-fma4           disable FMA4 optimizations
+  --disable-avx2           disable AVX2 optimizations
   --disable-armv5te        disable armv5te optimizations
   --disable-armv6          disable armv6 optimizations
   --disable-armv6t2        disable armv6t2 optimizations
@@ -1178,6 +1179,7 @@ ARCH_EXT_LIST_X86='
     amd3dnow
     amd3dnowext
     avx
+    avx2
     fma4
     i686
     mmx
@@ -1498,6 +1500,7 @@ sse4_deps="ssse3"
 sse42_deps="sse4"
 avx_deps="sse42"
 fma4_deps="avx"
+avx2_deps="avx"
 
 mmx_external_deps="yasm"
 mmx_inline_deps="inline_asm"
diff --git a/libavutil/cpu.c b/libavutil/cpu.c
index 8edebbc..8890ecd 100644
--- a/libavutil/cpu.c
+++ b/libavutil/cpu.c
@@ -81,6 +81,7 @@ int av_parse_cpu_flags(const char *s)
 #define CPUFLAG_AVX      (AV_CPU_FLAG_AVX      | CPUFLAG_SSE42)
 #define CPUFLAG_XOP      (AV_CPU_FLAG_XOP      | CPUFLAG_AVX)
 #define CPUFLAG_FMA4     (AV_CPU_FLAG_FMA4     | CPUFLAG_AVX)
+#define CPUFLAG_AVX2     (AV_CPU_FLAG_AVX2     | CPUFLAG_AVX)
     static const AVOption cpuflags_opts[] = {
         { "flags"   , NULL, 0, AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT64_MIN, INT64_MAX, .unit = "flags" },
 #if   ARCH_PPC
@@ -100,6 +101,7 @@ int av_parse_cpu_flags(const char *s)
         { "avx"     , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_AVX          },    .unit = "flags" },
         { "xop"     , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_XOP          },    .unit = "flags" },
         { "fma4"    , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_FMA4         },    .unit = "flags" },
+        { "avx2"    , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_AVX2         },    .unit = "flags" },
         { "3dnow"   , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_3DNOW        },    .unit = "flags" },
         { "3dnowext", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_3DNOWEXT     },    .unit = "flags" },
         { "cmov",     NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_CMOV     },    .unit = "flags" },
diff --git a/libavutil/cpu.h b/libavutil/cpu.h
index 3103131..1c336e8 100644
--- a/libavutil/cpu.h
+++ b/libavutil/cpu.h
@@ -48,6 +48,8 @@
 #define AV_CPU_FLAG_XOP          0x0400 ///< Bulldozer XOP functions
 #define AV_CPU_FLAG_FMA4         0x0800 ///< Bulldozer FMA4 functions
 #define AV_CPU_FLAG_CMOV         0x1000 ///< i686 cmov
+#define AV_CPU_FLAG_AVX2         0x8000 ///< AVX2 functions: requires OS support even if YMM registers aren't used
+
 
 #define AV_CPU_FLAG_ALTIVEC      0x0001 ///< standard
 
diff --git a/libavutil/x86/cpu.c b/libavutil/x86/cpu.c
index 3e946b8..07a8425 100644
--- a/libavutil/x86/cpu.c
+++ b/libavutil/x86/cpu.c
@@ -134,6 +134,15 @@ int ff_get_cpu_flags_x86(void)
             if ((eax & 0x6) == 0x6)
                 rval |= AV_CPU_FLAG_AVX;
         }
+#if HAVE_AVX2
+    if( max_std_level >= 7 )
+    {
+        cpuid( 7, eax, ebx, ecx, edx );
+        if( ebx&0x00000020 )
+            rval |= AV_CPU_FLAG_AVX2;
+        /* TODO: BMI1/2 */
+    }
+#endif /* HAVE_AVX2 */
 #endif /* HAVE_AVX */
 #endif /* HAVE_SSE */
     }
diff --git a/libavutil/x86/cpu.h b/libavutil/x86/cpu.h
index e5153bb..5303c5a 100644
--- a/libavutil/x86/cpu.h
+++ b/libavutil/x86/cpu.h
@@ -38,6 +38,7 @@
 #define X86_SSE42(flags)            CPUEXT(flags, SSE42)
 #define X86_AVX(flags)              CPUEXT(flags, AVX)
 #define X86_FMA4(flags)             CPUEXT(flags, FMA4)
+#define X86_AVX2(flags)             CPUEXT(flags, AVX2)
 
 #define EXTERNAL_AMD3DNOW(flags)    CPUEXT_SUFFIX(flags, _EXTERNAL, AMD3DNOW)
 #define EXTERNAL_AMD3DNOWEXT(flags) CPUEXT_SUFFIX(flags, _EXTERNAL, AMD3DNOWEXT)
@@ -51,6 +52,7 @@
 #define EXTERNAL_SSE42(flags)       CPUEXT_SUFFIX(flags, _EXTERNAL, SSE42)
 #define EXTERNAL_AVX(flags)         CPUEXT_SUFFIX(flags, _EXTERNAL, AVX)
 #define EXTERNAL_FMA4(flags)        CPUEXT_SUFFIX(flags, _EXTERNAL, FMA4)
+#define EXTERNAL_AVX2(flags)        CPUEXT_SUFFIX(flags, _EXTERNAL, AVX2)
 
 #define INLINE_AMD3DNOW(flags)      CPUEXT_SUFFIX(flags, _INLINE, AMD3DNOW)
 #define INLINE_AMD3DNOWEXT(flags)   CPUEXT_SUFFIX(flags, _INLINE, AMD3DNOWEXT)
@@ -64,6 +66,7 @@
 #define INLINE_SSE42(flags)         CPUEXT_SUFFIX(flags, _INLINE, SSE42)
 #define INLINE_AVX(flags)           CPUEXT_SUFFIX(flags, _INLINE, AVX)
 #define INLINE_FMA4(flags)          CPUEXT_SUFFIX(flags, _INLINE, FMA4)
+#define INLINE_AVX2(flags)          CPUEXT_SUFFIX(flags, _INLINE, AVX2)
 
 void ff_cpu_cpuid(int index, int *eax, int *ebx, int *ecx, int *edx);
 void ff_cpu_xgetbv(int op, int *eax, int *edx);
diff --git a/libswscale/x86/input.asm b/libswscale/x86/input.asm
index 6f5677e..5ed0dba 100644
--- a/libswscale/x86/input.asm
+++ b/libswscale/x86/input.asm
@@ -666,3 +666,9 @@ YUYV_TO_UV_FN 3, yuyv
 YUYV_TO_UV_FN 3, uyvy, 1
 NVXX_TO_UV_FN 5, nv12
 NVXX_TO_UV_FN 5, nv21
+
+;<fmt>toyuv422(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src,
+;              int width, int height,
+;              int lumStride, int chromStride, int srcStride)
+
+
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list