diff --git a/configure b/configure
index 7fac4e9f1db4d246215e3b931ff52ba02e94f036..8b8f85d393a56e98e029d33a08837a608278fbf9 100755
--- a/configure
+++ b/configure
@@ -2598,7 +2598,7 @@ probe_cc(){
         _flags='-nologo'
         _cflags='-D_USE_MATH_DEFINES -Dinline=__inline -FIstdlib.h -Dstrtoll=_strtoi64'
         if [ $pfx = hostcc ]; then
-            _cflags="$cflags -Dsnprintf=_snprintf"
+            append _cflags -Dsnprintf=_snprintf
         fi
         disable aligned_stack
     fi
diff --git a/libavcodec/x86/ac3dsp_init.c b/libavcodec/x86/ac3dsp_init.c
index cf1d7db8a4ef9243c63006c6836d3a31c754f9fe..516a6adb194902e4323dc4d253822a7801325d81 100644
--- a/libavcodec/x86/ac3dsp_init.c
+++ b/libavcodec/x86/ac3dsp_init.c
@@ -20,6 +20,7 @@
  */
 
 #include "libavutil/x86/asm.h"
+#include "libavutil/x86/cpu.h"
 #include "dsputil_mmx.h"
 #include "libavcodec/ac3dsp.h"
 
@@ -50,29 +51,28 @@ extern void ff_ac3_extract_exponents_ssse3(uint8_t *exp, int32_t *coef, int nb_c
 
 av_cold void ff_ac3dsp_init_x86(AC3DSPContext *c, int bit_exact)
 {
-#if HAVE_YASM
     int mm_flags = av_get_cpu_flags();
 
-    if (mm_flags & AV_CPU_FLAG_MMX) {
+    if (EXTERNAL_MMX(mm_flags)) {
         c->ac3_exponent_min = ff_ac3_exponent_min_mmx;
         c->ac3_max_msb_abs_int16 = ff_ac3_max_msb_abs_int16_mmx;
         c->ac3_lshift_int16 = ff_ac3_lshift_int16_mmx;
         c->ac3_rshift_int32 = ff_ac3_rshift_int32_mmx;
     }
-    if (mm_flags & AV_CPU_FLAG_3DNOW && HAVE_AMD3DNOW) {
+    if (EXTERNAL_AMD3DNOW(mm_flags)) {
         c->extract_exponents = ff_ac3_extract_exponents_3dnow;
         if (!bit_exact) {
             c->float_to_fixed24 = ff_float_to_fixed24_3dnow;
         }
     }
-    if (mm_flags & AV_CPU_FLAG_MMXEXT && HAVE_MMXEXT) {
+    if (EXTERNAL_MMXEXT(mm_flags)) {
         c->ac3_exponent_min = ff_ac3_exponent_min_mmxext;
         c->ac3_max_msb_abs_int16 = ff_ac3_max_msb_abs_int16_mmx2;
     }
-    if (mm_flags & AV_CPU_FLAG_SSE && HAVE_SSE) {
+    if (EXTERNAL_SSE(mm_flags)) {
         c->float_to_fixed24 = ff_float_to_fixed24_sse;
     }
-    if (mm_flags & AV_CPU_FLAG_SSE2 && HAVE_SSE) {
+    if (EXTERNAL_SSE2(mm_flags)) {
         c->ac3_exponent_min = ff_ac3_exponent_min_sse2;
         c->ac3_max_msb_abs_int16 = ff_ac3_max_msb_abs_int16_sse2;
         c->float_to_fixed24 = ff_float_to_fixed24_sse2;
@@ -83,11 +83,10 @@ av_cold void ff_ac3dsp_init_x86(AC3DSPContext *c, int bit_exact)
             c->ac3_rshift_int32 = ff_ac3_rshift_int32_sse2;
         }
     }
-    if (mm_flags & AV_CPU_FLAG_SSSE3 && HAVE_SSSE3) {
+    if (EXTERNAL_SSSE3(mm_flags)) {
         c->ac3_max_msb_abs_int16 = ff_ac3_max_msb_abs_int16_ssse3;
         if (!(mm_flags & AV_CPU_FLAG_ATOM)) {
             c->extract_exponents = ff_ac3_extract_exponents_ssse3;
         }
     }
-#endif
 }
diff --git a/libavcodec/x86/dsputilenc_mmx.c b/libavcodec/x86/dsputilenc_mmx.c
index 325d55062b663886dbbe4ad238cdcb0b45d34f62..1110f9c3772ee89bc8ca6727e912e11bbddf4e47 100644
--- a/libavcodec/x86/dsputilenc_mmx.c
+++ b/libavcodec/x86/dsputilenc_mmx.c
@@ -24,6 +24,7 @@
 
 #include "libavutil/cpu.h"
 #include "libavutil/x86/asm.h"
+#include "libavutil/x86/cpu.h"
 #include "libavcodec/dsputil.h"
 #include "libavcodec/mpegvideo.h"
 #include "libavcodec/mathops.h"
@@ -1181,17 +1182,16 @@ void ff_dsputilenc_init_mmx(DSPContext* c, AVCodecContext *avctx)
     }
 #endif /* HAVE_INLINE_ASM */
 
-#if HAVE_YASM
-    if (mm_flags & AV_CPU_FLAG_MMX) {
+    if (EXTERNAL_MMX(mm_flags)) {
         c->hadamard8_diff[0] = ff_hadamard8_diff16_mmx;
         c->hadamard8_diff[1] = ff_hadamard8_diff_mmx;
 
-        if (mm_flags & AV_CPU_FLAG_MMXEXT) {
+        if (EXTERNAL_MMXEXT(mm_flags)) {
             c->hadamard8_diff[0] = ff_hadamard8_diff16_mmx2;
             c->hadamard8_diff[1] = ff_hadamard8_diff_mmx2;
         }
 
-        if (mm_flags & AV_CPU_FLAG_SSE2){
+        if (EXTERNAL_SSE2(mm_flags)) {
             c->sse[0] = ff_sse16_sse2;
 
 #if HAVE_ALIGNED_STACK
@@ -1200,14 +1200,11 @@ void ff_dsputilenc_init_mmx(DSPContext* c, AVCodecContext *avctx)
 #endif
         }
 
-#if HAVE_SSSE3 && HAVE_ALIGNED_STACK
-        if (mm_flags & AV_CPU_FLAG_SSSE3) {
+        if (EXTERNAL_SSSE3(mm_flags) && HAVE_ALIGNED_STACK) {
             c->hadamard8_diff[0] = ff_hadamard8_diff16_ssse3;
             c->hadamard8_diff[1] = ff_hadamard8_diff_ssse3;
         }
-#endif
     }
-#endif /* HAVE_YASM */
 
     ff_dsputil_init_pix_mmx(c, avctx);
 }
diff --git a/libavcodec/x86/fft_init.c b/libavcodec/x86/fft_init.c
index f14c588e20f50162f9efd90d0b4c37b3d54b86b6..d7a31d4efa8f30e42e04734f27018593a0bbb830 100644
--- a/libavcodec/x86/fft_init.c
+++ b/libavcodec/x86/fft_init.c
@@ -17,29 +17,29 @@
  */
 
 #include "libavutil/cpu.h"
+#include "libavutil/x86/cpu.h"
 #include "libavcodec/dsputil.h"
 #include "libavcodec/dct.h"
 #include "fft.h"
 
 av_cold void ff_fft_init_mmx(FFTContext *s)
 {
-#if HAVE_YASM
     int has_vectors = av_get_cpu_flags();
 #if ARCH_X86_32
-    if (has_vectors & AV_CPU_FLAG_3DNOW && HAVE_AMD3DNOW) {
+    if (EXTERNAL_AMD3DNOW(has_vectors)) {
         /* 3DNow! for K6-2/3 */
         s->imdct_calc = ff_imdct_calc_3dnow;
         s->imdct_half = ff_imdct_half_3dnow;
         s->fft_calc   = ff_fft_calc_3dnow;
     }
-    if (has_vectors & AV_CPU_FLAG_3DNOWEXT && HAVE_AMD3DNOWEXT) {
+    if (EXTERNAL_AMD3DNOWEXT(has_vectors)) {
         /* 3DNowEx for K7 */
         s->imdct_calc = ff_imdct_calc_3dnowext;
         s->imdct_half = ff_imdct_half_3dnowext;
         s->fft_calc   = ff_fft_calc_3dnowext;
     }
 #endif
-    if (has_vectors & AV_CPU_FLAG_SSE && HAVE_SSE) {
+    if (EXTERNAL_SSE(has_vectors)) {
         /* SSE for P3/P4/K8 */
         s->imdct_calc  = ff_imdct_calc_sse;
         s->imdct_half  = ff_imdct_half_sse;
@@ -47,26 +47,23 @@ av_cold void ff_fft_init_mmx(FFTContext *s)
         s->fft_calc    = ff_fft_calc_sse;
         s->fft_permutation = FF_FFT_PERM_SWAP_LSBS;
     }
-    if (has_vectors & AV_CPU_FLAG_AVX && HAVE_AVX_EXTERNAL && s->nbits >= 5) {
+    if (EXTERNAL_AVX(has_vectors) && s->nbits >= 5) {
         /* AVX for SB */
         s->imdct_half      = ff_imdct_half_avx;
         s->fft_calc        = ff_fft_calc_avx;
         s->fft_permutation = FF_FFT_PERM_AVX;
     }
-#endif
 }
 
 #if CONFIG_DCT
 av_cold void ff_dct_init_mmx(DCTContext *s)
 {
-#if HAVE_YASM
     int has_vectors = av_get_cpu_flags();
-    if (has_vectors & AV_CPU_FLAG_SSE && HAVE_SSE)
+    if (EXTERNAL_SSE(has_vectors))
         s->dct32 = ff_dct32_float_sse;
-    if (has_vectors & AV_CPU_FLAG_SSE2 && HAVE_SSE)
+    if (EXTERNAL_SSE2(has_vectors))
         s->dct32 = ff_dct32_float_sse2;
-    if (has_vectors & AV_CPU_FLAG_AVX && HAVE_AVX_EXTERNAL)
+    if (EXTERNAL_AVX(has_vectors))
         s->dct32 = ff_dct32_float_avx;
-#endif
 }
 #endif
diff --git a/libavcodec/x86/fmtconvert_init.c b/libavcodec/x86/fmtconvert_init.c
index 2aa23ba78023b50020d20b54e96c2467dbe6e25b..528b7b1221fdb294c81e40a7c4bd58f99702beac 100644
--- a/libavcodec/x86/fmtconvert_init.c
+++ b/libavcodec/x86/fmtconvert_init.c
@@ -24,6 +24,7 @@
 
 #include "libavutil/cpu.h"
 #include "libavutil/x86/asm.h"
+#include "libavutil/x86/cpu.h"
 #include "libavcodec/fmtconvert.h"
 #include "libavcodec/dsputil.h"
 
@@ -117,27 +118,27 @@ void ff_fmt_convert_init_x86(FmtConvertContext *c, AVCodecContext *avctx)
 #if HAVE_YASM
     int mm_flags = av_get_cpu_flags();
 
-    if (mm_flags & AV_CPU_FLAG_MMX) {
+    if (EXTERNAL_MMX(mm_flags)) {
         c->float_interleave = float_interleave_mmx;
 
-        if (HAVE_AMD3DNOW && mm_flags & AV_CPU_FLAG_3DNOW) {
+        if (EXTERNAL_AMD3DNOW(mm_flags)) {
             if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
                 c->float_to_int16 = ff_float_to_int16_3dnow;
                 c->float_to_int16_interleave = float_to_int16_interleave_3dnow;
             }
         }
-        if (HAVE_AMD3DNOWEXT && mm_flags & AV_CPU_FLAG_3DNOWEXT) {
+        if (EXTERNAL_AMD3DNOWEXT(mm_flags)) {
             if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
                 c->float_to_int16_interleave = float_to_int16_interleave_3dnowext;
             }
         }
-        if (HAVE_SSE && mm_flags & AV_CPU_FLAG_SSE) {
+        if (EXTERNAL_SSE(mm_flags)) {
             c->int32_to_float_fmul_scalar = ff_int32_to_float_fmul_scalar_sse;
             c->float_to_int16 = ff_float_to_int16_sse;
             c->float_to_int16_interleave = float_to_int16_interleave_sse;
             c->float_interleave = float_interleave_sse;
         }
-        if (HAVE_SSE && mm_flags & AV_CPU_FLAG_SSE2) {
+        if (EXTERNAL_SSE2(mm_flags)) {
             c->int32_to_float_fmul_scalar = ff_int32_to_float_fmul_scalar_sse2;
             c->float_to_int16 = ff_float_to_int16_sse2;
             c->float_to_int16_interleave = float_to_int16_interleave_sse2;
diff --git a/libavcodec/x86/h264_intrapred_init.c b/libavcodec/x86/h264_intrapred_init.c
index d40a08a6bba9916b0e57d3aed7d48a5d0f300718..6d8b414dd3d830b32d2d609a63eac62cd05c7e2a 100644
--- a/libavcodec/x86/h264_intrapred_init.c
+++ b/libavcodec/x86/h264_intrapred_init.c
@@ -19,6 +19,7 @@
  */
 
 #include "libavutil/cpu.h"
+#include "libavutil/x86/cpu.h"
 #include "libavcodec/h264pred.h"
 
 #define PRED4x4(TYPE, DEPTH, OPT) \
@@ -169,11 +170,10 @@ void ff_pred4x4_vertical_vp8_mmxext(uint8_t *src, const uint8_t *topright, int s
 
 void ff_h264_pred_init_x86(H264PredContext *h, int codec_id, const int bit_depth, const int chroma_format_idc)
 {
-#if HAVE_YASM
     int mm_flags = av_get_cpu_flags();
 
     if (bit_depth == 8) {
-        if (mm_flags & AV_CPU_FLAG_MMX) {
+        if (EXTERNAL_MMX(mm_flags)) {
             h->pred16x16[VERT_PRED8x8         ] = ff_pred16x16_vertical_mmx;
             h->pred16x16[HOR_PRED8x8          ] = ff_pred16x16_horizontal_mmx;
             if (chroma_format_idc == 1) {
@@ -198,7 +198,7 @@ void ff_h264_pred_init_x86(H264PredContext *h, int codec_id, const int bit_depth
             }
         }
 
-        if (mm_flags & AV_CPU_FLAG_MMXEXT) {
+        if (EXTERNAL_MMXEXT(mm_flags)) {
             h->pred16x16[HOR_PRED8x8            ] = ff_pred16x16_horizontal_mmx2;
             h->pred16x16[DC_PRED8x8             ] = ff_pred16x16_dc_mmx2;
             if (chroma_format_idc == 1)
@@ -250,11 +250,11 @@ void ff_h264_pred_init_x86(H264PredContext *h, int codec_id, const int bit_depth
             }
         }
 
-        if (mm_flags & AV_CPU_FLAG_SSE) {
+        if (EXTERNAL_SSE(mm_flags)) {
             h->pred16x16[VERT_PRED8x8] = ff_pred16x16_vertical_sse;
         }
 
-        if (mm_flags & AV_CPU_FLAG_SSE2) {
+        if (EXTERNAL_SSE2(mm_flags)) {
             h->pred16x16[DC_PRED8x8           ] = ff_pred16x16_dc_sse2;
             h->pred8x8l [DIAG_DOWN_LEFT_PRED  ] = ff_pred8x8l_down_left_sse2;
             h->pred8x8l [DIAG_DOWN_RIGHT_PRED ] = ff_pred8x8l_down_right_sse2;
@@ -277,7 +277,7 @@ void ff_h264_pred_init_x86(H264PredContext *h, int codec_id, const int bit_depth
             }
         }
 
-        if (mm_flags & AV_CPU_FLAG_SSSE3) {
+        if (EXTERNAL_SSSE3(mm_flags)) {
             h->pred16x16[HOR_PRED8x8          ] = ff_pred16x16_horizontal_ssse3;
             h->pred16x16[DC_PRED8x8           ] = ff_pred16x16_dc_ssse3;
             if (chroma_format_idc == 1)
@@ -308,7 +308,7 @@ void ff_h264_pred_init_x86(H264PredContext *h, int codec_id, const int bit_depth
             }
         }
     } else if (bit_depth == 10) {
-        if (mm_flags & AV_CPU_FLAG_MMXEXT) {
+        if (EXTERNAL_MMXEXT(mm_flags)) {
             h->pred4x4[DC_PRED             ] = ff_pred4x4_dc_10_mmxext;
             h->pred4x4[HOR_UP_PRED         ] = ff_pred4x4_horizontal_up_10_mmxext;
 
@@ -324,7 +324,7 @@ void ff_h264_pred_init_x86(H264PredContext *h, int codec_id, const int bit_depth
             h->pred16x16[VERT_PRED8x8      ] = ff_pred16x16_vertical_10_mmxext;
             h->pred16x16[HOR_PRED8x8       ] = ff_pred16x16_horizontal_10_mmxext;
         }
-        if (mm_flags & AV_CPU_FLAG_SSE2) {
+        if (EXTERNAL_SSE2(mm_flags)) {
             h->pred4x4[DIAG_DOWN_LEFT_PRED ] = ff_pred4x4_down_left_10_sse2;
             h->pred4x4[DIAG_DOWN_RIGHT_PRED] = ff_pred4x4_down_right_10_sse2;
             h->pred4x4[VERT_LEFT_PRED      ] = ff_pred4x4_vertical_left_10_sse2;
@@ -356,7 +356,7 @@ void ff_h264_pred_init_x86(H264PredContext *h, int codec_id, const int bit_depth
             h->pred16x16[VERT_PRED8x8      ] = ff_pred16x16_vertical_10_sse2;
             h->pred16x16[HOR_PRED8x8       ] = ff_pred16x16_horizontal_10_sse2;
         }
-        if (mm_flags & AV_CPU_FLAG_SSSE3) {
+        if (EXTERNAL_SSSE3(mm_flags)) {
             h->pred4x4[DIAG_DOWN_RIGHT_PRED] = ff_pred4x4_down_right_10_ssse3;
             h->pred4x4[VERT_RIGHT_PRED     ] = ff_pred4x4_vertical_right_10_ssse3;
             h->pred4x4[HOR_DOWN_PRED       ] = ff_pred4x4_horizontal_down_10_ssse3;
@@ -367,7 +367,7 @@ void ff_h264_pred_init_x86(H264PredContext *h, int codec_id, const int bit_depth
             h->pred8x8l[VERT_RIGHT_PRED     ] = ff_pred8x8l_vertical_right_10_ssse3;
             h->pred8x8l[HOR_UP_PRED         ] = ff_pred8x8l_horizontal_up_10_ssse3;
         }
-        if (HAVE_AVX_EXTERNAL && mm_flags & AV_CPU_FLAG_AVX) {
+        if (EXTERNAL_AVX(mm_flags)) {
             h->pred4x4[DIAG_DOWN_LEFT_PRED ] = ff_pred4x4_down_left_10_avx;
             h->pred4x4[DIAG_DOWN_RIGHT_PRED] = ff_pred4x4_down_right_10_avx;
             h->pred4x4[VERT_LEFT_PRED      ] = ff_pred4x4_vertical_left_10_avx;
@@ -384,5 +384,4 @@ void ff_h264_pred_init_x86(H264PredContext *h, int codec_id, const int bit_depth
             h->pred8x8l[HOR_UP_PRED         ] = ff_pred8x8l_horizontal_up_10_avx;
         }
     }
-#endif /* HAVE_YASM */
 }
diff --git a/libavcodec/x86/h264dsp_init.c b/libavcodec/x86/h264dsp_init.c
index 6c83d8ce5893fd0795fd3f857946153dd069e203..7ada4950cc46186a56695593d4984bed1db5b2fa 100644
--- a/libavcodec/x86/h264dsp_init.c
+++ b/libavcodec/x86/h264dsp_init.c
@@ -20,6 +20,7 @@
 
 #include "libavutil/cpu.h"
 #include "libavutil/x86/asm.h"
+#include "libavutil/x86/cpu.h"
 #include "libavcodec/h264dsp.h"
 #include "dsputil_mmx.h"
 
@@ -209,14 +210,13 @@ H264_BIWEIGHT_10_SSE(4,  10)
 void ff_h264dsp_init_x86(H264DSPContext *c, const int bit_depth,
                          const int chroma_format_idc)
 {
-#if HAVE_YASM
     int mm_flags = av_get_cpu_flags();
 
-    if (chroma_format_idc == 1 && mm_flags & AV_CPU_FLAG_MMXEXT)
+    if (chroma_format_idc == 1 && EXTERNAL_MMXEXT(mm_flags))
         c->h264_loop_filter_strength = ff_h264_loop_filter_strength_mmx2;
 
     if (bit_depth == 8) {
-        if (mm_flags & AV_CPU_FLAG_MMX) {
+        if (EXTERNAL_MMX(mm_flags)) {
             c->h264_idct_dc_add   =
             c->h264_idct_add      = ff_h264_idct_add_8_mmx;
             c->h264_idct8_dc_add  =
@@ -230,7 +230,7 @@ void ff_h264dsp_init_x86(H264DSPContext *c, const int bit_depth,
             if (mm_flags & AV_CPU_FLAG_CMOV)
                 c->h264_luma_dc_dequant_idct = ff_h264_luma_dc_dequant_idct_mmx;
 
-            if (mm_flags & AV_CPU_FLAG_MMXEXT) {
+            if (EXTERNAL_MMXEXT(mm_flags)) {
                 c->h264_idct_dc_add  = ff_h264_idct_dc_add_8_mmx2;
                 c->h264_idct8_dc_add = ff_h264_idct8_dc_add_8_mmx2;
                 c->h264_idct_add16   = ff_h264_idct_add16_8_mmx2;
@@ -259,7 +259,7 @@ void ff_h264dsp_init_x86(H264DSPContext *c, const int bit_depth,
                 c->biweight_h264_pixels_tab[1] = ff_h264_biweight_8_mmx2;
                 c->biweight_h264_pixels_tab[2] = ff_h264_biweight_4_mmx2;
 
-                if (mm_flags & AV_CPU_FLAG_SSE2) {
+                if (EXTERNAL_SSE2(mm_flags)) {
                     c->h264_idct8_add  = ff_h264_idct8_add_8_sse2;
 
                     c->h264_idct_add16 = ff_h264_idct_add16_8_sse2;
@@ -282,23 +282,21 @@ void ff_h264dsp_init_x86(H264DSPContext *c, const int bit_depth,
                     c->h264_h_loop_filter_luma_intra = ff_deblock_h_luma_intra_8_sse2;
 #endif /* HAVE_ALIGNED_STACK */
                 }
-                if (mm_flags & AV_CPU_FLAG_SSSE3) {
+                if (EXTERNAL_SSSE3(mm_flags)) {
                     c->biweight_h264_pixels_tab[0] = ff_h264_biweight_16_ssse3;
                     c->biweight_h264_pixels_tab[1] = ff_h264_biweight_8_ssse3;
                 }
-                if (HAVE_AVX_EXTERNAL && mm_flags & AV_CPU_FLAG_AVX) {
-#if HAVE_ALIGNED_STACK
+                if (EXTERNAL_AVX(mm_flags) && HAVE_ALIGNED_STACK) {
                     c->h264_v_loop_filter_luma       = ff_deblock_v_luma_8_avx;
                     c->h264_h_loop_filter_luma       = ff_deblock_h_luma_8_avx;
                     c->h264_v_loop_filter_luma_intra = ff_deblock_v_luma_intra_8_avx;
                     c->h264_h_loop_filter_luma_intra = ff_deblock_h_luma_intra_8_avx;
-#endif /* HAVE_ALIGNED_STACK */
                 }
             }
         }
     } else if (bit_depth == 10) {
-        if (mm_flags & AV_CPU_FLAG_MMX) {
-            if (mm_flags & AV_CPU_FLAG_MMXEXT) {
+        if (EXTERNAL_MMX(mm_flags)) {
+            if (EXTERNAL_MMXEXT(mm_flags)) {
 #if ARCH_X86_32
                 c->h264_v_loop_filter_chroma       = ff_deblock_v_chroma_10_mmx2;
                 c->h264_v_loop_filter_chroma_intra = ff_deblock_v_chroma_intra_10_mmx2;
@@ -308,7 +306,7 @@ void ff_h264dsp_init_x86(H264DSPContext *c, const int bit_depth,
                 c->h264_h_loop_filter_luma_intra   = ff_deblock_h_luma_intra_10_mmx2;
 #endif /* ARCH_X86_32 */
                 c->h264_idct_dc_add = ff_h264_idct_dc_add_10_mmx2;
-                if (mm_flags & AV_CPU_FLAG_SSE2) {
+                if (EXTERNAL_SSE2(mm_flags)) {
                     c->h264_idct_add     = ff_h264_idct_add_10_sse2;
                     c->h264_idct8_dc_add = ff_h264_idct8_dc_add_10_sse2;
 
@@ -338,7 +336,7 @@ void ff_h264dsp_init_x86(H264DSPContext *c, const int bit_depth,
                     c->h264_h_loop_filter_luma_intra = ff_deblock_h_luma_intra_10_sse2;
 #endif /* HAVE_ALIGNED_STACK */
                 }
-                if (mm_flags & AV_CPU_FLAG_SSE4) {
+                if (EXTERNAL_SSE4(mm_flags)) {
                     c->weight_h264_pixels_tab[0] = ff_h264_weight_16_10_sse4;
                     c->weight_h264_pixels_tab[1] = ff_h264_weight_8_10_sse4;
                     c->weight_h264_pixels_tab[2] = ff_h264_weight_4_10_sse4;
@@ -347,8 +345,7 @@ void ff_h264dsp_init_x86(H264DSPContext *c, const int bit_depth,
                     c->biweight_h264_pixels_tab[1] = ff_h264_biweight_8_10_sse4;
                     c->biweight_h264_pixels_tab[2] = ff_h264_biweight_4_10_sse4;
                 }
-#if HAVE_AVX_EXTERNAL
-                if (mm_flags & AV_CPU_FLAG_AVX) {
+                if (EXTERNAL_AVX(mm_flags)) {
                     c->h264_idct_dc_add  =
                     c->h264_idct_add     = ff_h264_idct_add_10_avx;
                     c->h264_idct8_dc_add = ff_h264_idct8_dc_add_10_avx;
@@ -371,9 +368,7 @@ void ff_h264dsp_init_x86(H264DSPContext *c, const int bit_depth,
                     c->h264_h_loop_filter_luma_intra   = ff_deblock_h_luma_intra_10_avx;
 #endif /* HAVE_ALIGNED_STACK */
                 }
-#endif /* HAVE_AVX_EXTERNAL */
             }
         }
     }
-#endif /* HAVE_YASM */
 }
diff --git a/libavcodec/x86/mlpdsp.c b/libavcodec/x86/mlpdsp.c
index 0cd0e4c2fb3fdaa350b4339cbb17cd82035ed609..f7c0f21f64b2d001c1cd40702971e2fbf29eabd7 100644
--- a/libavcodec/x86/mlpdsp.c
+++ b/libavcodec/x86/mlpdsp.c
@@ -23,7 +23,7 @@
 #include "libavcodec/dsputil.h"
 #include "libavcodec/mlp.h"
 
-#if HAVE_7REGS
+#if HAVE_7REGS && HAVE_INLINE_ASM
 
 extern char ff_mlp_firorder_8;
 extern char ff_mlp_firorder_7;
@@ -171,11 +171,11 @@ static void mlp_filter_channel_x86(int32_t *state, const int32_t *coeff,
     );
 }
 
-#endif /* HAVE_7REGS */
+#endif /* HAVE_7REGS && HAVE_INLINE_ASM */
 
 void ff_mlp_init_x86(DSPContext* c, AVCodecContext *avctx)
 {
-#if HAVE_7REGS
+#if HAVE_7REGS && HAVE_INLINE_ASM
     c->mlp_filter_channel = mlp_filter_channel_x86;
 #endif
 }
diff --git a/libavcodec/x86/mpegaudiodec.c b/libavcodec/x86/mpegaudiodec.c
index 8a6d59ad6ad9068610aa3eb281449a8b85cf39ed..edf630b31dba35e72a8afad9b3467cc9135688ae 100644
--- a/libavcodec/x86/mpegaudiodec.c
+++ b/libavcodec/x86/mpegaudiodec.c
@@ -21,6 +21,7 @@
 
 #include "libavutil/cpu.h"
 #include "libavutil/x86/asm.h"
+#include "libavutil/x86/cpu.h"
 #include "libavcodec/dsputil.h"
 #include "libavcodec/mpegaudiodsp.h"
 
@@ -251,21 +252,16 @@ void ff_mpadsp_init_mmx(MPADSPContext *s)
 #endif /* HAVE_SSE2_INLINE */
 
 #if HAVE_YASM
-    if (0) {
-#if HAVE_AVX_EXTERNAL
-    } else if (mm_flags & AV_CPU_FLAG_AVX && HAVE_AVX) {
+    if (EXTERNAL_AVX(mm_flags)) {
         s->imdct36_blocks_float = imdct36_blocks_avx;
-#endif
-#if HAVE_SSE
-    } else if (mm_flags & AV_CPU_FLAG_SSSE3) {
+    } else if (EXTERNAL_SSSE3(mm_flags)) {
         s->imdct36_blocks_float = imdct36_blocks_ssse3;
-    } else if (mm_flags & AV_CPU_FLAG_SSE3) {
+    } else if (EXTERNAL_SSE3(mm_flags)) {
         s->imdct36_blocks_float = imdct36_blocks_sse3;
-    } else if (mm_flags & AV_CPU_FLAG_SSE2) {
+    } else if (EXTERNAL_SSE2(mm_flags)) {
         s->imdct36_blocks_float = imdct36_blocks_sse2;
-    } else if (mm_flags & AV_CPU_FLAG_SSE) {
+    } else if (EXTERNAL_SSE(mm_flags)) {
         s->imdct36_blocks_float = imdct36_blocks_sse;
-#endif /* HAVE_SSE */
     }
 #endif /* HAVE_YASM */
 }
diff --git a/libavcodec/x86/mpegvideoenc.c b/libavcodec/x86/mpegvideoenc.c
index 850467f663292d1cee514642ec2dfec3f4f407c2..20d26ec8b6a0bf94710d99cfb4d06d9b32c830eb 100644
--- a/libavcodec/x86/mpegvideoenc.c
+++ b/libavcodec/x86/mpegvideoenc.c
@@ -21,6 +21,7 @@
 
 #include "libavutil/cpu.h"
 #include "libavutil/x86/asm.h"
+#include "libavutil/x86/cpu.h"
 #include "libavcodec/avcodec.h"
 #include "libavcodec/dsputil.h"
 #include "libavcodec/mpegvideo.h"
@@ -86,19 +87,19 @@ void ff_MPV_encode_init_x86(MpegEncContext *s)
 
     if (dct_algo == FF_DCT_AUTO || dct_algo == FF_DCT_MMX) {
 #if HAVE_MMX_INLINE
-        if (mm_flags & AV_CPU_FLAG_MMX && HAVE_MMX)
+        if (INLINE_MMX(mm_flags))
             s->dct_quantize = dct_quantize_MMX;
 #endif
 #if HAVE_MMXEXT_INLINE
-        if (mm_flags & AV_CPU_FLAG_MMXEXT && HAVE_MMXEXT)
+        if (INLINE_MMXEXT(mm_flags))
             s->dct_quantize = dct_quantize_MMX2;
 #endif
 #if HAVE_SSE2_INLINE
-        if (mm_flags & AV_CPU_FLAG_SSE2 && HAVE_SSE2)
+        if (INLINE_SSE2(mm_flags))
             s->dct_quantize = dct_quantize_SSE2;
 #endif
 #if HAVE_SSSE3_INLINE
-        if (mm_flags & AV_CPU_FLAG_SSSE3)
+        if (INLINE_SSSE3(mm_flags))
             s->dct_quantize = dct_quantize_SSSE3;
 #endif
     }
diff --git a/libavcodec/x86/pngdsp_init.c b/libavcodec/x86/pngdsp_init.c
index 7a1273062004823d9958fda968c75d03d494943a..05fd05121068e1508d472bce0cbe816894e2adbb 100644
--- a/libavcodec/x86/pngdsp_init.c
+++ b/libavcodec/x86/pngdsp_init.c
@@ -20,7 +20,7 @@
  */
 
 #include "libavutil/common.h"
-#include "libavutil/cpu.h"
+#include "libavutil/x86/cpu.h"
 #include "libavcodec/pngdsp.h"
 
 void ff_add_png_paeth_prediction_mmx2 (uint8_t *dst, uint8_t *src,
@@ -34,18 +34,16 @@ void ff_add_bytes_l2_sse2(uint8_t *dst, uint8_t *src1,
 
 void ff_pngdsp_init_x86(PNGDSPContext *dsp)
 {
-#if HAVE_YASM
     int flags = av_get_cpu_flags();
 
 #if ARCH_X86_32
-    if (flags & AV_CPU_FLAG_MMX)
+    if (EXTERNAL_MMX(flags))
         dsp->add_bytes_l2         = ff_add_bytes_l2_mmx;
 #endif
-    if (flags & AV_CPU_FLAG_MMXEXT)
+    if (EXTERNAL_MMXEXT(flags))
         dsp->add_paeth_prediction = ff_add_png_paeth_prediction_mmx2;
-    if (flags & AV_CPU_FLAG_SSE2)
+    if (EXTERNAL_SSE2(flags))
         dsp->add_bytes_l2         = ff_add_bytes_l2_sse2;
-    if (flags & AV_CPU_FLAG_SSSE3)
+    if (EXTERNAL_SSSE3(flags))
         dsp->add_paeth_prediction = ff_add_png_paeth_prediction_ssse3;
-#endif
 }
diff --git a/libavcodec/x86/proresdsp_init.c b/libavcodec/x86/proresdsp_init.c
index 5892af2518037c241c04c24ae4b1c784eae9faff..21ce0986d220d1f739ad4fb25ff5d22603d9de3f 100644
--- a/libavcodec/x86/proresdsp_init.c
+++ b/libavcodec/x86/proresdsp_init.c
@@ -20,6 +20,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/x86/cpu.h"
 #include "libavcodec/proresdsp.h"
 
 void ff_prores_idct_put_10_sse2(uint16_t *dst, int linesize,
@@ -31,25 +32,25 @@ void ff_prores_idct_put_10_avx (uint16_t *dst, int linesize,
 
 void ff_proresdsp_x86_init(ProresDSPContext *dsp, AVCodecContext *avctx)
 {
-#if ARCH_X86_64 && HAVE_YASM
+#if ARCH_X86_64
     int flags = av_get_cpu_flags();
 
     if(avctx->flags & CODEC_FLAG_BITEXACT)
         return;
 
-    if (flags & AV_CPU_FLAG_SSE2) {
+    if (EXTERNAL_SSE2(flags)) {
         dsp->idct_permutation_type = FF_TRANSPOSE_IDCT_PERM;
         dsp->idct_put = ff_prores_idct_put_10_sse2;
     }
 
-    if (flags & AV_CPU_FLAG_SSE4) {
+    if (EXTERNAL_SSE4(flags)) {
         dsp->idct_permutation_type = FF_TRANSPOSE_IDCT_PERM;
         dsp->idct_put = ff_prores_idct_put_10_sse4;
     }
 
-    if (HAVE_AVX_EXTERNAL && flags & AV_CPU_FLAG_AVX) {
+    if (EXTERNAL_AVX(flags)) {
         dsp->idct_permutation_type = FF_TRANSPOSE_IDCT_PERM;
         dsp->idct_put = ff_prores_idct_put_10_avx;
     }
-#endif /* ARCH_X86_64 && HAVE_YASM */
+#endif /* ARCH_X86_64 */
 }
diff --git a/libavcodec/x86/rv34dsp_init.c b/libavcodec/x86/rv34dsp_init.c
index de323e9c3c67e62a17b76a5ec1108ec78dc5a271..305745aa95fae262988d004c52fda7c9931f8c03 100644
--- a/libavcodec/x86/rv34dsp_init.c
+++ b/libavcodec/x86/rv34dsp_init.c
@@ -21,6 +21,7 @@
 
 #include "libavutil/cpu.h"
 #include "libavutil/x86/asm.h"
+#include "libavutil/x86/cpu.h"
 #include "libavcodec/dsputil.h"
 #include "libavcodec/rv34dsp.h"
 
@@ -32,16 +33,14 @@ void ff_rv34_idct_add_mmx2(uint8_t *dst, ptrdiff_t stride, DCTELEM *block);
 
 av_cold void ff_rv34dsp_init_x86(RV34DSPContext* c, DSPContext *dsp)
 {
-#if HAVE_YASM
     int mm_flags = av_get_cpu_flags();
 
-    if (mm_flags & AV_CPU_FLAG_MMX)
+    if (EXTERNAL_MMX(mm_flags))
         c->rv34_idct_dc_add = ff_rv34_idct_dc_add_mmx;
-    if (mm_flags & AV_CPU_FLAG_MMXEXT) {
+    if (EXTERNAL_MMXEXT(mm_flags)) {
         c->rv34_inv_transform_dc = ff_rv34_idct_dc_noround_mmx2;
         c->rv34_idct_add         = ff_rv34_idct_add_mmx2;
     }
-    if (mm_flags & AV_CPU_FLAG_SSE4)
+    if (EXTERNAL_SSE4(mm_flags))
         c->rv34_idct_dc_add = ff_rv34_idct_dc_add_sse4;
-#endif /* HAVE_YASM */
 }
diff --git a/libavcodec/x86/rv40dsp_init.c b/libavcodec/x86/rv40dsp_init.c
index 50aaa24b43d30f7e2e99586ec4e52cf9ae0d9a24..966e3f22f5cc7480c03de7b32250c9ebe1ce4846 100644
--- a/libavcodec/x86/rv40dsp_init.c
+++ b/libavcodec/x86/rv40dsp_init.c
@@ -28,6 +28,7 @@
 
 #include "libavcodec/rv34dsp.h"
 #include "libavutil/mem.h"
+#include "libavutil/x86/cpu.h"
 #include "dsputil_mmx.h"
 
 #if HAVE_YASM
@@ -191,7 +192,7 @@ void ff_rv40dsp_init_x86(RV34DSPContext *c, DSPContext *dsp)
 #if HAVE_YASM
     int mm_flags = av_get_cpu_flags();
 
-    if (mm_flags & AV_CPU_FLAG_MMX) {
+    if (EXTERNAL_MMX(mm_flags)) {
         c->put_chroma_pixels_tab[0] = ff_put_rv40_chroma_mc8_mmx;
         c->put_chroma_pixels_tab[1] = ff_put_rv40_chroma_mc4_mmx;
 #if HAVE_INLINE_ASM
@@ -204,7 +205,7 @@ void ff_rv40dsp_init_x86(RV34DSPContext *c, DSPContext *dsp)
         QPEL_MC_SET(put_, _mmx)
 #endif
     }
-    if (mm_flags & AV_CPU_FLAG_MMXEXT) {
+    if (EXTERNAL_MMXEXT(mm_flags)) {
         c->avg_chroma_pixels_tab[0] = ff_avg_rv40_chroma_mc8_mmx2;
         c->avg_chroma_pixels_tab[1] = ff_avg_rv40_chroma_mc4_mmx2;
         c->rv40_weight_pixels_tab[0][0] = ff_rv40_weight_func_rnd_16_mmx2;
@@ -214,14 +215,14 @@ void ff_rv40dsp_init_x86(RV34DSPContext *c, DSPContext *dsp)
 #if ARCH_X86_32
         QPEL_MC_SET(avg_, _mmx2)
 #endif
-    } else if (mm_flags & AV_CPU_FLAG_3DNOW) {
+    } else if (EXTERNAL_AMD3DNOW(mm_flags)) {
         c->avg_chroma_pixels_tab[0] = ff_avg_rv40_chroma_mc8_3dnow;
         c->avg_chroma_pixels_tab[1] = ff_avg_rv40_chroma_mc4_3dnow;
 #if ARCH_X86_32
         QPEL_MC_SET(avg_, _3dnow)
 #endif
     }
-    if (mm_flags & AV_CPU_FLAG_SSE2) {
+    if (EXTERNAL_SSE2(mm_flags)) {
         c->rv40_weight_pixels_tab[0][0] = ff_rv40_weight_func_rnd_16_sse2;
         c->rv40_weight_pixels_tab[0][1] = ff_rv40_weight_func_rnd_8_sse2;
         c->rv40_weight_pixels_tab[1][0] = ff_rv40_weight_func_nornd_16_sse2;
@@ -229,7 +230,7 @@ void ff_rv40dsp_init_x86(RV34DSPContext *c, DSPContext *dsp)
         QPEL_MC_SET(put_, _sse2)
         QPEL_MC_SET(avg_, _sse2)
     }
-    if (mm_flags & AV_CPU_FLAG_SSSE3) {
+    if (EXTERNAL_SSSE3(mm_flags)) {
         c->rv40_weight_pixels_tab[0][0] = ff_rv40_weight_func_rnd_16_ssse3;
         c->rv40_weight_pixels_tab[0][1] = ff_rv40_weight_func_rnd_8_ssse3;
         c->rv40_weight_pixels_tab[1][0] = ff_rv40_weight_func_nornd_16_ssse3;
diff --git a/libavcodec/x86/sbrdsp_init.c b/libavcodec/x86/sbrdsp_init.c
index 0ffe5b9e1187b267744810aabdbac7393b378974..d272896704e4e1e047a854dc4f506088fb5a4a3c 100644
--- a/libavcodec/x86/sbrdsp_init.c
+++ b/libavcodec/x86/sbrdsp_init.c
@@ -21,6 +21,7 @@
 
 #include "config.h"
 #include "libavutil/cpu.h"
+#include "libavutil/x86/cpu.h"
 #include "libavcodec/sbrdsp.h"
 
 float ff_sbr_sum_square_sse(float (*x)[2], int n);
@@ -29,12 +30,10 @@ void ff_sbr_hf_g_filt_sse(float (*Y)[2], const float (*X_high)[40][2],
 
 void ff_sbrdsp_init_x86(SBRDSPContext *s)
 {
-    if (HAVE_YASM) {
-        int mm_flags = av_get_cpu_flags();
+    int mm_flags = av_get_cpu_flags();
 
-        if (mm_flags & AV_CPU_FLAG_SSE) {
-            s->sum_square = ff_sbr_sum_square_sse;
-            s->hf_g_filt = ff_sbr_hf_g_filt_sse;
-        }
+    if (EXTERNAL_SSE(mm_flags)) {
+        s->sum_square = ff_sbr_sum_square_sse;
+        s->hf_g_filt  = ff_sbr_hf_g_filt_sse;
     }
 }
diff --git a/libavcodec/x86/vp3dsp_init.c b/libavcodec/x86/vp3dsp_init.c
index 8905452dcf62b8864dcf56bafc9811b1d316df75..c4d462bc62900f97240c3170fa0e8378edc5dfa1 100644
--- a/libavcodec/x86/vp3dsp_init.c
+++ b/libavcodec/x86/vp3dsp_init.c
@@ -20,6 +20,7 @@
 
 #include "libavutil/attributes.h"
 #include "libavutil/cpu.h"
+#include "libavutil/x86/cpu.h"
 #include "libavcodec/avcodec.h"
 #include "libavcodec/vp3dsp.h"
 #include "config.h"
@@ -38,18 +39,17 @@ void ff_vp3_h_loop_filter_mmx2(uint8_t *src, int stride, int *bounding_values);
 
 av_cold void ff_vp3dsp_init_x86(VP3DSPContext *c, int flags)
 {
-#if HAVE_YASM
     int cpuflags = av_get_cpu_flags();
 
 #if ARCH_X86_32
-    if (HAVE_MMX && cpuflags & AV_CPU_FLAG_MMX) {
+    if (EXTERNAL_MMX(cpuflags)) {
         c->idct_put  = ff_vp3_idct_put_mmx;
         c->idct_add  = ff_vp3_idct_add_mmx;
         c->idct_perm = FF_PARTTRANS_IDCT_PERM;
     }
 #endif
 
-    if (HAVE_MMXEXT && cpuflags & AV_CPU_FLAG_MMXEXT) {
+    if (EXTERNAL_MMXEXT(cpuflags)) {
         c->idct_dc_add = ff_vp3_idct_dc_add_mmx2;
 
         if (!(flags & CODEC_FLAG_BITEXACT)) {
@@ -58,10 +58,9 @@ av_cold void ff_vp3dsp_init_x86(VP3DSPContext *c, int flags)
         }
     }
 
-    if (cpuflags & AV_CPU_FLAG_SSE2) {
+    if (EXTERNAL_SSE2(cpuflags)) {
         c->idct_put  = ff_vp3_idct_put_sse2;
         c->idct_add  = ff_vp3_idct_add_sse2;
         c->idct_perm = FF_TRANSPOSE_IDCT_PERM;
     }
-#endif
 }
diff --git a/libavcodec/x86/vp56dsp_init.c b/libavcodec/x86/vp56dsp_init.c
index bef1af6546e80ea808ea22871b63fd69c2258061..b699f793caf8a134c826df11ea3edf644d5018fb 100644
--- a/libavcodec/x86/vp56dsp_init.c
+++ b/libavcodec/x86/vp56dsp_init.c
@@ -22,6 +22,7 @@
 
 #include "libavutil/cpu.h"
 #include "libavutil/x86/asm.h"
+#include "libavutil/x86/cpu.h"
 #include "libavcodec/dsputil.h"
 #include "libavcodec/vp56dsp.h"
 
@@ -32,19 +33,17 @@ void ff_vp6_filter_diag4_sse2(uint8_t *dst, uint8_t *src, int stride,
 
 av_cold void ff_vp56dsp_init_x86(VP56DSPContext* c, enum AVCodecID codec)
 {
-#if HAVE_YASM
     int mm_flags = av_get_cpu_flags();
 
     if (CONFIG_VP6_DECODER && codec == AV_CODEC_ID_VP6) {
 #if ARCH_X86_32
-        if (mm_flags & AV_CPU_FLAG_MMX) {
+        if (EXTERNAL_MMX(mm_flags)) {
             c->vp6_filter_diag4 = ff_vp6_filter_diag4_mmx;
         }
 #endif
 
-        if (mm_flags & AV_CPU_FLAG_SSE2) {
+        if (EXTERNAL_SSE2(mm_flags)) {
             c->vp6_filter_diag4 = ff_vp6_filter_diag4_sse2;
         }
     }
-#endif
 }
diff --git a/libavresample/x86/audio_convert_init.c b/libavresample/x86/audio_convert_init.c
index a3589c69576e1da6e9afb6e81a36641cf32148d1..879108dff174ca4fe2655574de5fc589df5f0f4b 100644
--- a/libavresample/x86/audio_convert_init.c
+++ b/libavresample/x86/audio_convert_init.c
@@ -20,6 +20,7 @@
 
 #include "config.h"
 #include "libavutil/cpu.h"
+#include "libavutil/x86/cpu.h"
 #include "libavresample/audio_convert.h"
 
 /* flat conversions */
@@ -144,16 +145,15 @@ extern void ff_conv_flt_to_fltp_6ch_avx (float *const *dst, float *src, int len,
 
 av_cold void ff_audio_convert_init_x86(AudioConvert *ac)
 {
-#if HAVE_YASM
     int mm_flags = av_get_cpu_flags();
 
-    if (mm_flags & AV_CPU_FLAG_MMX && HAVE_MMX) {
+    if (EXTERNAL_MMX(mm_flags)) {
         ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32,
                                   0, 1, 8, "MMX", ff_conv_s32_to_s16_mmx);
         ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLTP,
                                   6, 1, 4, "MMX", ff_conv_fltp_to_flt_6ch_mmx);
     }
-    if (mm_flags & AV_CPU_FLAG_SSE && HAVE_SSE) {
+    if (EXTERNAL_SSE(mm_flags)) {
         ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP,
                                   6, 1, 2, "SSE", ff_conv_fltp_to_s16_6ch_sse);
         ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLTP,
@@ -161,7 +161,7 @@ av_cold void ff_audio_convert_init_x86(AudioConvert *ac)
         ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_FLT,
                                   2, 16, 4, "SSE", ff_conv_flt_to_fltp_2ch_sse);
     }
-    if (mm_flags & AV_CPU_FLAG_SSE2 && HAVE_SSE) {
+    if (EXTERNAL_SSE2(mm_flags)) {
         if (!(mm_flags & AV_CPU_FLAG_SSE2SLOW)) {
             ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32,
                                       0, 16, 16, "SSE2", ff_conv_s32_to_s16_sse2);
@@ -206,7 +206,7 @@ av_cold void ff_audio_convert_init_x86(AudioConvert *ac)
         ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_FLT,
                                   6, 16, 4, "SSE2", ff_conv_flt_to_fltp_6ch_sse2);
     }
-    if (mm_flags & AV_CPU_FLAG_SSSE3 && HAVE_SSE) {
+    if (EXTERNAL_SSSE3(mm_flags)) {
         ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16P,
                                   6, 16, 4, "SSSE3", ff_conv_s16p_to_flt_6ch_ssse3);
         ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP,
@@ -220,13 +220,13 @@ av_cold void ff_audio_convert_init_x86(AudioConvert *ac)
         ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_FLT,
                                   6, 16, 4, "SSSE3", ff_conv_flt_to_s16p_6ch_ssse3);
     }
-    if (mm_flags & AV_CPU_FLAG_SSE4 && HAVE_SSE) {
+    if (EXTERNAL_SSE4(mm_flags)) {
         ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16,
                                   0, 16, 8, "SSE4", ff_conv_s16_to_flt_sse4);
         ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLTP,
                                   6, 16, 4, "SSE4", ff_conv_fltp_to_flt_6ch_sse4);
     }
-    if (mm_flags & AV_CPU_FLAG_AVX && HAVE_AVX) {
+    if (EXTERNAL_AVX(mm_flags)) {
         ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32,
                                   0, 32, 16, "AVX", ff_conv_s32_to_flt_avx);
         ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT,
@@ -260,5 +260,4 @@ av_cold void ff_audio_convert_init_x86(AudioConvert *ac)
         ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_FLT,
                                   6, 16, 4, "AVX", ff_conv_flt_to_fltp_6ch_avx);
     }
-#endif
 }
diff --git a/libavresample/x86/audio_mix_init.c b/libavresample/x86/audio_mix_init.c
index 1b472afc2fee557e82a575182baac9e1149137ab..72b2397ad6b59a8b7517dd009f31c29f305894be 100644
--- a/libavresample/x86/audio_mix_init.c
+++ b/libavresample/x86/audio_mix_init.c
@@ -20,6 +20,7 @@
 
 #include "config.h"
 #include "libavutil/cpu.h"
+#include "libavutil/x86/cpu.h"
 #include "libavresample/audio_mix.h"
 
 extern void ff_mix_2_to_1_fltp_flt_sse(float **src, float **matrix, int len,
@@ -105,7 +106,7 @@ DEFINE_MIX_3_8_TO_1_2(7)
 DEFINE_MIX_3_8_TO_1_2(8)
 
 #define SET_MIX_3_8_TO_1_2(chan)                                            \
-    if (mm_flags & AV_CPU_FLAG_SSE && HAVE_SSE) {                           \
+    if (EXTERNAL_SSE(mm_flags)) {                                           \
         ff_audio_mix_set_func(am, AV_SAMPLE_FMT_FLTP, AV_MIX_COEFF_TYPE_FLT,\
                               chan, 1, 16, 4, "SSE",                        \
                               ff_mix_ ## chan ## _to_1_fltp_flt_sse);       \
@@ -113,7 +114,7 @@ DEFINE_MIX_3_8_TO_1_2(8)
                               chan, 2, 16, 4, "SSE",                        \
                               ff_mix_## chan ##_to_2_fltp_flt_sse);         \
     }                                                                       \
-    if (mm_flags & AV_CPU_FLAG_SSE2 && HAVE_SSE) {                          \
+    if (EXTERNAL_SSE2(mm_flags)) {                                          \
         ff_audio_mix_set_func(am, AV_SAMPLE_FMT_S16P, AV_MIX_COEFF_TYPE_FLT,\
                               chan, 1, 16, 8, "SSE2",                       \
                               ff_mix_ ## chan ## _to_1_s16p_flt_sse2);      \
@@ -121,7 +122,7 @@ DEFINE_MIX_3_8_TO_1_2(8)
                               chan, 2, 16, 8, "SSE2",                       \
                               ff_mix_ ## chan ## _to_2_s16p_flt_sse2);      \
     }                                                                       \
-    if (mm_flags & AV_CPU_FLAG_SSE4 && HAVE_SSE) {                          \
+    if (EXTERNAL_SSE4(mm_flags)) {                                          \
         ff_audio_mix_set_func(am, AV_SAMPLE_FMT_S16P, AV_MIX_COEFF_TYPE_FLT,\
                               chan, 1, 16, 8, "SSE4",                       \
                               ff_mix_ ## chan ## _to_1_s16p_flt_sse4);      \
@@ -129,7 +130,7 @@ DEFINE_MIX_3_8_TO_1_2(8)
                               chan, 2, 16, 8, "SSE4",                       \
                               ff_mix_ ## chan ## _to_2_s16p_flt_sse4);      \
     }                                                                       \
-    if (mm_flags & AV_CPU_FLAG_AVX && HAVE_AVX) {                           \
+    if (EXTERNAL_AVX(mm_flags)) {                                           \
         int ptr_align = 32;                                                 \
         int smp_align = 8;                                                  \
         if (ARCH_X86_32 || chan >= 6) {                                     \
@@ -149,7 +150,7 @@ DEFINE_MIX_3_8_TO_1_2(8)
                               chan, 2, 16, 8, "AVX",                        \
                               ff_mix_ ## chan ## _to_2_s16p_flt_avx);       \
     }                                                                       \
-    if (mm_flags & AV_CPU_FLAG_FMA4 && HAVE_FMA4) {                         \
+    if (EXTERNAL_FMA4(mm_flags)) {                                          \
         int ptr_align = 32;                                                 \
         int smp_align = 8;                                                  \
         if (ARCH_X86_32 || chan >= 6) {                                     \
@@ -175,13 +176,13 @@ av_cold void ff_audio_mix_init_x86(AudioMix *am)
 #if HAVE_YASM
     int mm_flags = av_get_cpu_flags();
 
-    if (mm_flags & AV_CPU_FLAG_SSE && HAVE_SSE) {
+    if (EXTERNAL_SSE(mm_flags)) {
         ff_audio_mix_set_func(am, AV_SAMPLE_FMT_FLTP, AV_MIX_COEFF_TYPE_FLT,
                               2, 1, 16, 8, "SSE", ff_mix_2_to_1_fltp_flt_sse);
         ff_audio_mix_set_func(am, AV_SAMPLE_FMT_FLTP, AV_MIX_COEFF_TYPE_FLT,
                               1, 2, 16, 4, "SSE", ff_mix_1_to_2_fltp_flt_sse);
     }
-    if (mm_flags & AV_CPU_FLAG_SSE2 && HAVE_SSE) {
+    if (EXTERNAL_SSE2(mm_flags)) {
         ff_audio_mix_set_func(am, AV_SAMPLE_FMT_S16P, AV_MIX_COEFF_TYPE_FLT,
                               2, 1, 16, 8, "SSE2", ff_mix_2_to_1_s16p_flt_sse2);
         ff_audio_mix_set_func(am, AV_SAMPLE_FMT_S16P, AV_MIX_COEFF_TYPE_Q8,
@@ -189,13 +190,13 @@ av_cold void ff_audio_mix_init_x86(AudioMix *am)
         ff_audio_mix_set_func(am, AV_SAMPLE_FMT_S16P, AV_MIX_COEFF_TYPE_FLT,
                               1, 2, 16, 8, "SSE2", ff_mix_1_to_2_s16p_flt_sse2);
     }
-    if (mm_flags & AV_CPU_FLAG_SSE4 && HAVE_SSE) {
+    if (EXTERNAL_SSE4(mm_flags)) {
         ff_audio_mix_set_func(am, AV_SAMPLE_FMT_S16P, AV_MIX_COEFF_TYPE_FLT,
                               2, 1, 16, 8, "SSE4", ff_mix_2_to_1_s16p_flt_sse4);
         ff_audio_mix_set_func(am, AV_SAMPLE_FMT_S16P, AV_MIX_COEFF_TYPE_FLT,
                               1, 2, 16, 8, "SSE4", ff_mix_1_to_2_s16p_flt_sse4);
     }
-    if (mm_flags & AV_CPU_FLAG_AVX && HAVE_AVX) {
+    if (EXTERNAL_AVX(mm_flags)) {
         ff_audio_mix_set_func(am, AV_SAMPLE_FMT_FLTP, AV_MIX_COEFF_TYPE_FLT,
                               2, 1, 32, 16, "AVX", ff_mix_2_to_1_fltp_flt_avx);
         ff_audio_mix_set_func(am, AV_SAMPLE_FMT_FLTP, AV_MIX_COEFF_TYPE_FLT,
diff --git a/libavutil/x86/float_dsp_init.c b/libavutil/x86/float_dsp_init.c
index 7c73f5f8401961cb02d9a27886b51e3755755127..1382373185f3e84ac25a1b9fbcaa64a8f925b3bc 100644
--- a/libavutil/x86/float_dsp_init.c
+++ b/libavutil/x86/float_dsp_init.c
@@ -20,6 +20,7 @@
 
 #include "libavutil/cpu.h"
 #include "libavutil/float_dsp.h"
+#include "cpu.h"
 
 extern void ff_vector_fmul_sse(float *dst, const float *src0, const float *src1,
                                int len);
@@ -33,16 +34,14 @@ extern void ff_vector_fmac_scalar_avx(float *dst, const float *src, float mul,
 
 void ff_float_dsp_init_x86(AVFloatDSPContext *fdsp)
 {
-#if HAVE_YASM
     int mm_flags = av_get_cpu_flags();
 
-    if (mm_flags & AV_CPU_FLAG_SSE && HAVE_SSE) {
+    if (EXTERNAL_SSE(mm_flags)) {
         fdsp->vector_fmul = ff_vector_fmul_sse;
         fdsp->vector_fmac_scalar = ff_vector_fmac_scalar_sse;
     }
-    if (mm_flags & AV_CPU_FLAG_AVX && HAVE_AVX_EXTERNAL) {
+    if (EXTERNAL_AVX(mm_flags)) {
         fdsp->vector_fmul = ff_vector_fmul_avx;
         fdsp->vector_fmac_scalar = ff_vector_fmac_scalar_avx;
     }
-#endif
 }
diff --git a/libswscale/utils.c b/libswscale/utils.c
index f2a007f936c9351acb164ff09939b6e64b249c31..4b14c737af627fe8a77b3cebd61eefa4142ad6ea 100644
--- a/libswscale/utils.c
+++ b/libswscale/utils.c
@@ -47,6 +47,7 @@
 #include "libavutil/opt.h"
 #include "libavutil/pixdesc.h"
 #include "libavutil/x86/asm.h"
+#include "libavutil/x86/cpu.h"
 #include "rgb2rgb.h"
 #include "swscale.h"
 #include "swscale_internal.h"
@@ -497,7 +498,7 @@ static int initFilter(int16_t **outFilter, int32_t **filterPos,
             filterAlign = 1;
     }
 
-    if (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) {
+    if (INLINE_MMX(cpu_flags)) {
         // special case for unscaled vertical filtering
         if (minFilterSize == 1 && filterAlign == 2)
             filterAlign = 1;
@@ -1024,8 +1025,7 @@ av_cold int sws_init_context(SwsContext *c, SwsFilter *srcFilter,
         c->srcBpc = 16;
     if (c->dstBpc == 16)
         dst_stride <<= 1;
-    if (HAVE_MMXEXT && HAVE_INLINE_ASM && cpu_flags & AV_CPU_FLAG_MMXEXT &&
-        c->srcBpc == 8 && c->dstBpc <= 14) {
+    if (INLINE_MMXEXT(cpu_flags) && c->srcBpc == 8 && c->dstBpc <= 14) {
         c->canMMX2BeUsed = (dstW >= srcW && (dstW & 31) == 0 &&
                             (srcW & 15) == 0) ? 1 : 0;
         if (!c->canMMX2BeUsed && dstW >= srcW && (srcW & 15) == 0
@@ -1055,7 +1055,7 @@ av_cold int sws_init_context(SwsContext *c, SwsFilter *srcFilter,
             c->chrXInc += 20;
         }
         // we don't use the x86 asm scaler if MMX is available
-        else if (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX && c->dstBpc <= 14) {
+        else if (INLINE_MMX(cpu_flags) && c->dstBpc <= 14) {
             c->lumXInc = ((int64_t)(srcW       - 2) << 16) / (dstW       - 2) - 20;
             c->chrXInc = ((int64_t)(c->chrSrcW - 2) << 16) / (c->chrDstW - 2) - 20;
         }
@@ -1273,11 +1273,11 @@ av_cold int sws_init_context(SwsContext *c, SwsFilter *srcFilter,
 #endif
                av_get_pix_fmt_name(dstFormat));
 
-        if (HAVE_MMXEXT && cpu_flags & AV_CPU_FLAG_MMXEXT)
+        if (INLINE_MMXEXT(cpu_flags))
             av_log(c, AV_LOG_INFO, "using MMX2\n");
-        else if (HAVE_AMD3DNOW && cpu_flags & AV_CPU_FLAG_3DNOW)
+        else if (INLINE_AMD3DNOW(cpu_flags))
             av_log(c, AV_LOG_INFO, "using 3DNOW\n");
-        else if (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX)
+        else if (INLINE_MMX(cpu_flags))
             av_log(c, AV_LOG_INFO, "using MMX\n");
         else if (HAVE_ALTIVEC && cpu_flags & AV_CPU_FLAG_ALTIVEC)
             av_log(c, AV_LOG_INFO, "using AltiVec\n");
diff --git a/libswscale/x86/rgb2rgb.c b/libswscale/x86/rgb2rgb.c
index 24b284eec7ca5d817e66d953c3459e6c9537ffd3..83734a218bf14c8b86a293276720e2db415cedd7 100644
--- a/libswscale/x86/rgb2rgb.c
+++ b/libswscale/x86/rgb2rgb.c
@@ -28,6 +28,7 @@
 #include "config.h"
 #include "libavutil/attributes.h"
 #include "libavutil/x86/asm.h"
+#include "libavutil/x86/cpu.h"
 #include "libavutil/cpu.h"
 #include "libavutil/bswap.h"
 #include "libswscale/rgb2rgb.h"
@@ -136,13 +137,13 @@ av_cold void rgb2rgb_init_x86(void)
 #if HAVE_INLINE_ASM
     int cpu_flags = av_get_cpu_flags();
 
-    if (cpu_flags & AV_CPU_FLAG_MMX)
+    if (INLINE_MMX(cpu_flags))
         rgb2rgb_init_MMX();
-    if (HAVE_AMD3DNOW && cpu_flags & AV_CPU_FLAG_3DNOW)
+    if (INLINE_AMD3DNOW(cpu_flags))
         rgb2rgb_init_3DNOW();
-    if (HAVE_MMXEXT   && cpu_flags & AV_CPU_FLAG_MMXEXT)
+    if (INLINE_MMXEXT(cpu_flags))
         rgb2rgb_init_MMX2();
-    if (HAVE_SSE      && cpu_flags & AV_CPU_FLAG_SSE2)
+    if (INLINE_SSE2(cpu_flags))
         rgb2rgb_init_SSE2();
 #endif /* HAVE_INLINE_ASM */
 }
diff --git a/libswscale/x86/swscale.c b/libswscale/x86/swscale.c
index e633e922a72b1d1a4e047b74ca1ce0ec059cccf7..2ff37f55f04b50dc4a7f2eb926b6bd772228b5eb 100644
--- a/libswscale/x86/swscale.c
+++ b/libswscale/x86/swscale.c
@@ -26,6 +26,7 @@
 #include "libavutil/avassert.h"
 #include "libavutil/intreadwrite.h"
 #include "libavutil/x86/asm.h"
+#include "libavutil/x86/cpu.h"
 #include "libavutil/cpu.h"
 #include "libavutil/pixdesc.h"
 
@@ -385,7 +386,6 @@ av_cold void ff_sws_init_swScale_mmx(SwsContext *c)
 #endif
 #endif /* HAVE_INLINE_ASM */
 
-#if HAVE_YASM
 #define ASSIGN_SCALE_FUNC2(hscalefn, filtersize, opt1, opt2) do { \
     if (c->srcBpc == 8) { \
         hscalefn = c->dstBpc <= 14 ? ff_hscale8to15_ ## filtersize ## _ ## opt2 : \
@@ -436,7 +436,7 @@ switch(c->dstBpc){ \
                 c->chrToYV12 = ff_ ## x ## ToUV_ ## opt; \
             break
 #if ARCH_X86_32
-    if (cpu_flags & AV_CPU_FLAG_MMX) {
+    if (EXTERNAL_MMX(cpu_flags)) {
         ASSIGN_MMX_SCALE_FUNC(c->hyScale, c->hLumFilterSize, mmx, mmx);
         ASSIGN_MMX_SCALE_FUNC(c->hcScale, c->hChrFilterSize, mmx, mmx);
         ASSIGN_VSCALE_FUNC(c->yuv2plane1, mmx, mmx2, cpu_flags & AV_CPU_FLAG_MMXEXT);
@@ -471,7 +471,7 @@ switch(c->dstBpc){ \
             break;
         }
     }
-    if (cpu_flags & AV_CPU_FLAG_MMXEXT) {
+    if (EXTERNAL_MMXEXT(cpu_flags)) {
         ASSIGN_VSCALEX_FUNC(c->yuv2planeX, mmx2, , 1);
     }
 #endif /* ARCH_X86_32 */
@@ -483,7 +483,7 @@ switch(c->dstBpc){ \
              else                ASSIGN_SCALE_FUNC2(hscalefn, X8, opt1, opt2); \
              break; \
     }
-    if (cpu_flags & AV_CPU_FLAG_SSE2) {
+    if (EXTERNAL_SSE2(cpu_flags)) {
         ASSIGN_SSE_SCALE_FUNC(c->hyScale, c->hLumFilterSize, sse2, sse2);
         ASSIGN_SSE_SCALE_FUNC(c->hcScale, c->hChrFilterSize, sse2, sse2);
         ASSIGN_VSCALEX_FUNC(c->yuv2planeX, sse2, ,
@@ -520,7 +520,7 @@ switch(c->dstBpc){ \
             break;
         }
     }
-    if (cpu_flags & AV_CPU_FLAG_SSSE3) {
+    if (EXTERNAL_SSSE3(cpu_flags)) {
         ASSIGN_SSE_SCALE_FUNC(c->hyScale, c->hLumFilterSize, ssse3, ssse3);
         ASSIGN_SSE_SCALE_FUNC(c->hcScale, c->hChrFilterSize, ssse3, ssse3);
         switch (c->srcFormat) {
@@ -530,7 +530,7 @@ switch(c->dstBpc){ \
             break;
         }
     }
-    if (cpu_flags & AV_CPU_FLAG_SSE4) {
+    if (EXTERNAL_SSE4(cpu_flags)) {
         /* Xto15 don't need special sse4 functions */
         ASSIGN_SSE_SCALE_FUNC(c->hyScale, c->hLumFilterSize, sse4, ssse3);
         ASSIGN_SSE_SCALE_FUNC(c->hcScale, c->hChrFilterSize, sse4, ssse3);
@@ -541,7 +541,7 @@ switch(c->dstBpc){ \
             c->yuv2plane1 = ff_yuv2plane1_16_sse4;
     }
 
-    if (HAVE_AVX_EXTERNAL && cpu_flags & AV_CPU_FLAG_AVX) {
+    if (EXTERNAL_AVX(cpu_flags)) {
         ASSIGN_VSCALEX_FUNC(c->yuv2planeX, avx, ,
                             HAVE_ALIGNED_STACK || ARCH_X86_64);
         ASSIGN_VSCALE_FUNC(c->yuv2plane1, avx, avx, 1);
@@ -569,5 +569,4 @@ switch(c->dstBpc){ \
             break;
         }
     }
-#endif
 }