[FFmpeg-devel] [PATCH v4 4/4] libavcodec: Enable runtime detection for MIPS MMI & MSA

Jiaxun Yang jiaxun.yang at flygoat.com
Mon Jun 8 06:32:26 EEST 2020


Apply optimized functions according to cpuflags.
MSA is always put after MMI as it's usually faster than MMI.

Signed-off-by: Jiaxun Yang <jiaxun.yang at flygoat.com>
---
 libavcodec/mips/blockdsp_init_mips.c        | 22 +++++++++++++-----
 libavcodec/mips/cabac.h                     |  2 +-
 libavcodec/mips/h263dsp_init_mips.c         | 12 +++++++---
 libavcodec/mips/h264chroma_init_mips.c      | 22 +++++++++++++-----
 libavcodec/mips/h264dsp_init_mips.c         | 25 ++++++++++++++++-----
 libavcodec/mips/h264pred_init_mips.c        | 25 ++++++++++++++++-----
 libavcodec/mips/h264qpel_init_mips.c        | 22 +++++++++++++-----
 libavcodec/mips/hevcdsp_init_mips.c         | 24 +++++++++++++++-----
 libavcodec/mips/hevcpred_init_mips.c        | 12 +++++++---
 libavcodec/mips/hpeldsp_init_mips.c         | 22 +++++++++++++-----
 libavcodec/mips/idctdsp_init_mips.c         | 24 +++++++++++++++-----
 libavcodec/mips/me_cmp_init_mips.c          | 12 +++++++---
 libavcodec/mips/mpegvideo_init_mips.c       | 22 +++++++++++++-----
 libavcodec/mips/mpegvideoencdsp_init_mips.c | 13 ++++++++---
 libavcodec/mips/pixblockdsp_init_mips.c     | 25 ++++++++++++++++-----
 libavcodec/mips/qpeldsp_init_mips.c         | 12 +++++++---
 libavcodec/mips/vc1dsp_init_mips.c          | 22 +++++++++++++-----
 libavcodec/mips/videodsp_init.c             | 12 +++++++---
 libavcodec/mips/vp3dsp_init_mips.c          | 22 +++++++++++++-----
 libavcodec/mips/vp8dsp_init_mips.c          | 22 +++++++++++++-----
 libavcodec/mips/vp9dsp_init_mips.c          | 22 +++++++++++++-----
 libavcodec/mips/wmv2dsp_init_mips.c         | 12 +++++++---
 libavcodec/mips/xvididct_init_mips.c        | 13 ++++++++---
 23 files changed, 312 insertions(+), 109 deletions(-)

diff --git a/libavcodec/mips/blockdsp_init_mips.c b/libavcodec/mips/blockdsp_init_mips.c
index 55ac1c3e99..47170c17ef 100644
--- a/libavcodec/mips/blockdsp_init_mips.c
+++ b/libavcodec/mips/blockdsp_init_mips.c
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/mips/cpu.h"
 #include "blockdsp_mips.h"
 
 #if HAVE_MSA
@@ -30,6 +31,10 @@ static av_cold void blockdsp_init_msa(BlockDSPContext *c)
     c->fill_block_tab[0] = ff_fill_block16_msa;
     c->fill_block_tab[1] = ff_fill_block8_msa;
 }
+#else
+static av_cold void blockdsp_init_msa(BlockDSPContext *c)
+{
+}
 #endif  // #if HAVE_MSA
 
 #if HAVE_MMI
@@ -41,14 +46,19 @@ static av_cold void blockdsp_init_mmi(BlockDSPContext *c)
     c->fill_block_tab[0] = ff_fill_block16_mmi;
     c->fill_block_tab[1] = ff_fill_block8_mmi;
 }
+#else
+static av_cold void blockdsp_init_mmi(BlockDSPContext *c)
+{
+}
 #endif /* HAVE_MMI */
 
 void ff_blockdsp_init_mips(BlockDSPContext *c)
 {
-#if HAVE_MMI
-    blockdsp_init_mmi(c);
-#endif /* HAVE_MMI */
-#if HAVE_MSA
-    blockdsp_init_msa(c);
-#endif  // #if HAVE_MSA
+    int cpu_flags = av_get_cpu_flags();
+
+    if (have_mmi(cpu_flags))
+        blockdsp_init_mmi(c);
+
+    if (have_msa(cpu_flags))
+        blockdsp_init_msa(c);
 }
diff --git a/libavcodec/mips/cabac.h b/libavcodec/mips/cabac.h
index 03b5010edc..c595915eda 100644
--- a/libavcodec/mips/cabac.h
+++ b/libavcodec/mips/cabac.h
@@ -25,7 +25,7 @@
 #define AVCODEC_MIPS_CABAC_H
 
 #include "libavcodec/cabac.h"
-#include "libavutil/mips/mmiutils.h"
+#include "libavutil/mips/asmdefs.h"
 #include "config.h"
 
 #define get_cabac_inline get_cabac_inline_mips
diff --git a/libavcodec/mips/h263dsp_init_mips.c b/libavcodec/mips/h263dsp_init_mips.c
index 09bd93707d..b88b76368b 100644
--- a/libavcodec/mips/h263dsp_init_mips.c
+++ b/libavcodec/mips/h263dsp_init_mips.c
@@ -18,6 +18,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/mips/cpu.h"
 #include "h263dsp_mips.h"
 
 #if HAVE_MSA
@@ -26,11 +27,16 @@ static av_cold void h263dsp_init_msa(H263DSPContext *c)
     c->h263_h_loop_filter = ff_h263_h_loop_filter_msa;
     c->h263_v_loop_filter = ff_h263_v_loop_filter_msa;
 }
+#else
+static av_cold void h263dsp_init_msa(H263DSPContext *c)
+{
+}
 #endif  // #if HAVE_MSA
 
 av_cold void ff_h263dsp_init_mips(H263DSPContext *c)
 {
-#if HAVE_MSA
-    h263dsp_init_msa(c);
-#endif  // #if HAVE_MSA
+    int cpu_flags = av_get_cpu_flags();
+
+    if (have_msa(cpu_flags))
+        h263dsp_init_msa(c);
 }
diff --git a/libavcodec/mips/h264chroma_init_mips.c b/libavcodec/mips/h264chroma_init_mips.c
index ae817e47ae..84d335da59 100644
--- a/libavcodec/mips/h264chroma_init_mips.c
+++ b/libavcodec/mips/h264chroma_init_mips.c
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/mips/cpu.h"
 #include "h264chroma_mips.h"
 
 #if HAVE_MSA
@@ -36,6 +37,10 @@ static av_cold void h264chroma_init_msa(H264ChromaContext *c, int bit_depth)
         c->avg_h264_chroma_pixels_tab[2] = ff_avg_h264_chroma_mc2_msa;
     }
 }
+#else
+static av_cold void h264chroma_init_msa(H264ChromaContext *c, int bit_depth)
+{
+}
 #endif  // #if HAVE_MSA
 
 #if HAVE_MMI
@@ -50,14 +55,19 @@ static av_cold void h264chroma_init_mmi(H264ChromaContext *c, int bit_depth)
         c->avg_h264_chroma_pixels_tab[1] = ff_avg_h264_chroma_mc4_mmi;
     }
 }
+#else
+static av_cold void h264chroma_init_mmi(H264ChromaContext *c, int bit_depth)
+{
+}
 #endif /* HAVE_MMI */
 
 av_cold void ff_h264chroma_init_mips(H264ChromaContext *c, int bit_depth)
 {
-#if HAVE_MMI
-    h264chroma_init_mmi(c, bit_depth);
-#endif /* HAVE_MMI */
-#if HAVE_MSA
-    h264chroma_init_msa(c, bit_depth);
-#endif  // #if HAVE_MSA
+    int cpu_flags = av_get_cpu_flags();
+
+    if (have_mmi(cpu_flags))
+        h264chroma_init_mmi(c, bit_depth);
+
+    if (have_msa(cpu_flags))
+        h264chroma_init_msa(c, bit_depth);
 }
diff --git a/libavcodec/mips/h264dsp_init_mips.c b/libavcodec/mips/h264dsp_init_mips.c
index dc08a25800..7b89cfc393 100644
--- a/libavcodec/mips/h264dsp_init_mips.c
+++ b/libavcodec/mips/h264dsp_init_mips.c
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/mips/cpu.h"
 #include "h264dsp_mips.h"
 
 #if HAVE_MSA
@@ -79,6 +80,12 @@ static av_cold void h264dsp_init_msa(H264DSPContext *c,
         c->h264_luma_dc_dequant_idct = ff_h264_deq_idct_luma_dc_msa;
     }  // if (8 == bit_depth)
 }
+#else
+static av_cold void h264dsp_init_msa(H264DSPContext *c,
+                                     const int bit_depth,
+                                     const int chroma_format_idc)
+{
+}
 #endif  // #if HAVE_MSA
 
 #if HAVE_MMI
@@ -133,15 +140,21 @@ static av_cold void h264dsp_init_mmi(H264DSPContext * c, const int bit_depth,
         c->h264_h_loop_filter_luma_intra = ff_deblock_h_luma_intra_8_mmi;
     }
 }
+#else
+static av_cold void h264dsp_init_mmi(H264DSPContext * c, const int bit_depth,
+        const int chroma_format_idc)
+{
+}
 #endif /* HAVE_MMI */
 
 av_cold void ff_h264dsp_init_mips(H264DSPContext *c, const int bit_depth,
                                   const int chroma_format_idc)
 {
-#if HAVE_MMI
-    h264dsp_init_mmi(c, bit_depth, chroma_format_idc);
-#endif /* HAVE_MMI */
-#if HAVE_MSA
-    h264dsp_init_msa(c, bit_depth, chroma_format_idc);
-#endif  // #if HAVE_MSA
+    int cpu_flags = av_get_cpu_flags();
+
+    if (have_mmi(cpu_flags))
+        h264dsp_init_mmi(c, bit_depth, chroma_format_idc);
+
+    if (have_msa(cpu_flags))
+        h264dsp_init_msa(c, bit_depth, chroma_format_idc);
 }
diff --git a/libavcodec/mips/h264pred_init_mips.c b/libavcodec/mips/h264pred_init_mips.c
index e537ad8bd4..633d157b50 100644
--- a/libavcodec/mips/h264pred_init_mips.c
+++ b/libavcodec/mips/h264pred_init_mips.c
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/mips/cpu.h"
 #include "config.h"
 #include "h264dsp_mips.h"
 #include "h264pred_mips.h"
@@ -91,6 +92,12 @@ static av_cold void h264_pred_init_msa(H264PredContext *h, int codec_id,
         h->pred16x16[DC_128_PRED8x8] = ff_h264_intra_pred_dc_128_16x16_msa;
     }
 }
+#else
+static av_cold void h264_pred_init_msa(H264PredContext *h, int codec_id,
+                                       const int bit_depth,
+                                       const int chroma_format_idc)
+{
+}
 #endif  // #if HAVE_MSA
 
 #if HAVE_MMI
@@ -137,16 +144,22 @@ static av_cold void h264_pred_init_mmi(H264PredContext *h, int codec_id,
         }
     }
 }
+#else
+static av_cold void h264_pred_init_mmi(H264PredContext *h, int codec_id,
+        const int bit_depth, const int chroma_format_idc)
+{
+}
 #endif /* HAVE_MMI */
 
 av_cold void ff_h264_pred_init_mips(H264PredContext *h, int codec_id,
                                     int bit_depth,
                                     const int chroma_format_idc)
 {
-#if HAVE_MMI
-    h264_pred_init_mmi(h, codec_id, bit_depth, chroma_format_idc);
-#endif /* HAVE_MMI */
-#if HAVE_MSA
-    h264_pred_init_msa(h, codec_id, bit_depth, chroma_format_idc);
-#endif  // #if HAVE_MSA
+    int cpu_flags = av_get_cpu_flags();
+
+    if (have_mmi(cpu_flags))
+        h264_pred_init_mmi(h, codec_id, bit_depth, chroma_format_idc);
+
+    if (have_msa(cpu_flags))
+        h264_pred_init_msa(h, codec_id, bit_depth, chroma_format_idc);
 }
diff --git a/libavcodec/mips/h264qpel_init_mips.c b/libavcodec/mips/h264qpel_init_mips.c
index 33bae3093a..c1d584b14b 100644
--- a/libavcodec/mips/h264qpel_init_mips.c
+++ b/libavcodec/mips/h264qpel_init_mips.c
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/mips/cpu.h"
 #include "h264dsp_mips.h"
 
 #if HAVE_MSA
@@ -127,6 +128,10 @@ static av_cold void h264qpel_init_msa(H264QpelContext *c, int bit_depth)
         c->avg_h264_qpel_pixels_tab[2][15] = ff_avg_h264_qpel4_mc33_msa;
     }
 }
+#else
+static av_cold void h264qpel_init_msa(H264QpelContext *c, int bit_depth)
+{
+}
 #endif  // #if HAVE_MSA
 
 #if HAVE_MMI
@@ -236,14 +241,19 @@ static av_cold void h264qpel_init_mmi(H264QpelContext *c, int bit_depth)
         c->avg_h264_qpel_pixels_tab[2][15] = ff_avg_h264_qpel4_mc33_mmi;
     }
 }
+#else
+static av_cold void h264qpel_init_mmi(H264QpelContext *c, int bit_depth)
+{
+}
 #endif /* HAVE_MMI */
 
 av_cold void ff_h264qpel_init_mips(H264QpelContext *c, int bit_depth)
 {
-#if HAVE_MMI
-    h264qpel_init_mmi(c, bit_depth);
-#endif /* HAVE_MMI */
-#if HAVE_MSA
-    h264qpel_init_msa(c, bit_depth);
-#endif  // #if HAVE_MSA
+    int cpu_flags = av_get_cpu_flags();
+
+    if (have_mmi(cpu_flags))
+        h264qpel_init_mmi(c, bit_depth);
+
+    if (have_msa(cpu_flags))
+        h264qpel_init_msa(c, bit_depth);
 }
diff --git a/libavcodec/mips/hevcdsp_init_mips.c b/libavcodec/mips/hevcdsp_init_mips.c
index 88337f462e..246d71b74e 100644
--- a/libavcodec/mips/hevcdsp_init_mips.c
+++ b/libavcodec/mips/hevcdsp_init_mips.c
@@ -18,6 +18,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/mips/cpu.h"
 #include "libavcodec/mips/hevcdsp_mips.h"
 
 #if HAVE_MMI
@@ -90,6 +91,11 @@ static av_cold void hevc_dsp_init_mmi(HEVCDSPContext *c,
         c->put_hevc_qpel_uni[9][1][1] = ff_hevc_put_hevc_qpel_uni_hv64_8_mmi;
     }
 }
+#else
+static av_cold void hevc_dsp_init_mmi(HEVCDSPContext *c,
+                                      const int bit_depth)
+{
+}
 #endif // #if HAVE_MMI
 
 #if HAVE_MSA
@@ -516,14 +522,20 @@ static av_cold void hevc_dsp_init_msa(HEVCDSPContext *c,
         c->transform_4x4_luma = ff_hevc_idct_luma_4x4_msa;
     }
 }
+#else
+static av_cold void hevc_dsp_init_msa(HEVCDSPContext *c,
+                                      const int bit_depth)
+{
+}
 #endif  // #if HAVE_MSA
 
 void ff_hevc_dsp_init_mips(HEVCDSPContext *c, const int bit_depth)
 {
-#if HAVE_MMI
-    hevc_dsp_init_mmi(c, bit_depth);
-#endif  // #if HAVE_MMI
-#if HAVE_MSA
-    hevc_dsp_init_msa(c, bit_depth);
-#endif  // #if HAVE_MSA
+    int cpu_flags = av_get_cpu_flags();
+
+    if (have_mmi(cpu_flags))
+        hevc_dsp_init_mmi(c, bit_depth);
+
+    if (have_msa(cpu_flags))
+        hevc_dsp_init_msa(c, bit_depth);
 }
diff --git a/libavcodec/mips/hevcpred_init_mips.c b/libavcodec/mips/hevcpred_init_mips.c
index e987698d66..f829561ddf 100644
--- a/libavcodec/mips/hevcpred_init_mips.c
+++ b/libavcodec/mips/hevcpred_init_mips.c
@@ -18,6 +18,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/mips/cpu.h"
 #include "config.h"
 #include "libavutil/attributes.h"
 #include "libavcodec/mips/hevcpred_mips.h"
@@ -39,11 +40,16 @@ static av_cold void hevc_pred_init_msa(HEVCPredContext *c, const int bit_depth)
         c->pred_angular[3] = ff_pred_intra_pred_angular_3_msa;
     }
 }
+#else
+static av_cold void hevc_pred_init_msa(HEVCPredContext *c, const int bit_depth)
+{
+}
 #endif  // #if HAVE_MSA
 
 void ff_hevc_pred_init_mips(HEVCPredContext *c, const int bit_depth)
 {
-#if HAVE_MSA
-    hevc_pred_init_msa(c, bit_depth);
-#endif  // #if HAVE_MSA
+    int cpu_flags = av_get_cpu_flags();
+
+    if (have_msa(cpu_flags))
+        hevc_pred_init_msa(c, bit_depth);
 }
diff --git a/libavcodec/mips/hpeldsp_init_mips.c b/libavcodec/mips/hpeldsp_init_mips.c
index d6f7a9793d..9e12bde547 100644
--- a/libavcodec/mips/hpeldsp_init_mips.c
+++ b/libavcodec/mips/hpeldsp_init_mips.c
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/mips/cpu.h"
 #include "../hpeldsp.h"
 #include "libavcodec/mips/hpeldsp_mips.h"
 
@@ -64,6 +65,10 @@ static void ff_hpeldsp_init_msa(HpelDSPContext *c, int flags)
     c->avg_pixels_tab[2][2] = ff_avg_pixels4_y2_msa;
     c->avg_pixels_tab[2][3] = ff_avg_pixels4_xy2_msa;
 }
+#else
+static void ff_hpeldsp_init_msa(HpelDSPContext *c, int flags)
+{
+}
 #endif  // #if HAVE_MSA
 
 #if HAVE_MMI
@@ -109,14 +114,19 @@ static void ff_hpeldsp_init_mmi(HpelDSPContext *c, int flags)
     c->avg_pixels_tab[2][2] = ff_avg_pixels4_y2_8_mmi;
     c->avg_pixels_tab[2][3] = ff_avg_pixels4_xy2_8_mmi;
 }
+#else
+static void ff_hpeldsp_init_mmi(HpelDSPContext *c, int flags)
+{
+}
 #endif  // #if HAVE_MMI
 
 void ff_hpeldsp_init_mips(HpelDSPContext *c, int flags)
 {
-#if HAVE_MMI
-    ff_hpeldsp_init_mmi(c, flags);
-#endif  // #if HAVE_MMI
-#if HAVE_MSA
-    ff_hpeldsp_init_msa(c, flags);
-#endif  // #if HAVE_MSA
+    int cpu_flags = av_get_cpu_flags();
+
+    if (have_mmi(cpu_flags))
+        ff_hpeldsp_init_mmi(c, flags);
+
+    if (have_msa(cpu_flags))
+        ff_hpeldsp_init_msa(c, flags);
 }
diff --git a/libavcodec/mips/idctdsp_init_mips.c b/libavcodec/mips/idctdsp_init_mips.c
index 85b76ca478..a1a5ad5449 100644
--- a/libavcodec/mips/idctdsp_init_mips.c
+++ b/libavcodec/mips/idctdsp_init_mips.c
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/mips/cpu.h"
 #include "idctdsp_mips.h"
 #include "xvididct_mips.h"
 
@@ -40,6 +41,11 @@ static av_cold void idctdsp_init_msa(IDCTDSPContext *c, AVCodecContext *avctx,
     c->put_signed_pixels_clamped = ff_put_signed_pixels_clamped_msa;
     c->add_pixels_clamped = ff_add_pixels_clamped_msa;
 }
+#else
+static av_cold void idctdsp_init_msa(IDCTDSPContext *c, AVCodecContext *avctx,
+                                     unsigned high_bit_depth)
+{
+}
 #endif  // #if HAVE_MSA
 
 #if HAVE_MMI
@@ -60,15 +66,21 @@ static av_cold void idctdsp_init_mmi(IDCTDSPContext *c, AVCodecContext *avctx,
     c->add_pixels_clamped = ff_add_pixels_clamped_mmi;
     c->put_signed_pixels_clamped = ff_put_signed_pixels_clamped_mmi;
 }
+#else
+static av_cold void idctdsp_init_mmi(IDCTDSPContext *c, AVCodecContext *avctx,
+        unsigned high_bit_depth)
+{
+}
 #endif /* HAVE_MMI */
 
 av_cold void ff_idctdsp_init_mips(IDCTDSPContext *c, AVCodecContext *avctx,
                           unsigned high_bit_depth)
 {
-#if HAVE_MMI
-    idctdsp_init_mmi(c, avctx, high_bit_depth);
-#endif /* HAVE_MMI */
-#if HAVE_MSA
-    idctdsp_init_msa(c, avctx, high_bit_depth);
-#endif  // #if HAVE_MSA
+    int cpu_flags = av_get_cpu_flags();
+
+    if (have_mmi(cpu_flags))
+        idctdsp_init_mmi(c, avctx, high_bit_depth);
+
+    if (have_msa(cpu_flags))
+        idctdsp_init_msa(c, avctx, high_bit_depth);
 }
diff --git a/libavcodec/mips/me_cmp_init_mips.c b/libavcodec/mips/me_cmp_init_mips.c
index 219a0dc00c..3b5c01ecd4 100644
--- a/libavcodec/mips/me_cmp_init_mips.c
+++ b/libavcodec/mips/me_cmp_init_mips.c
@@ -18,6 +18,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/mips/cpu.h"
 #include "me_cmp_mips.h"
 
 #if HAVE_MSA
@@ -46,11 +47,16 @@ static av_cold void me_cmp_msa(MECmpContext *c, AVCodecContext *avctx)
     c->sse[2] = ff_sse4_msa;
 #endif
 }
+#else
+static av_cold void me_cmp_msa(MECmpContext *c, AVCodecContext *avctx)
+{
+}
 #endif  // #if HAVE_MSA
 
 av_cold void ff_me_cmp_init_mips(MECmpContext *c, AVCodecContext *avctx)
 {
-#if HAVE_MSA
-    me_cmp_msa(c, avctx);
-#endif  // #if HAVE_MSA
+    int cpu_flags = av_get_cpu_flags();
+
+    if (have_msa(cpu_flags))
+        me_cmp_msa(c, avctx);
 }
diff --git a/libavcodec/mips/mpegvideo_init_mips.c b/libavcodec/mips/mpegvideo_init_mips.c
index be77308140..cc6d4b1785 100644
--- a/libavcodec/mips/mpegvideo_init_mips.c
+++ b/libavcodec/mips/mpegvideo_init_mips.c
@@ -18,6 +18,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/mips/cpu.h"
 #include "h263dsp_mips.h"
 #include "mpegvideo_mips.h"
 
@@ -29,6 +30,10 @@ static av_cold void dct_unquantize_init_msa(MpegEncContext *s)
     if (!s->q_scale_type)
         s->dct_unquantize_mpeg2_inter = ff_dct_unquantize_mpeg2_inter_msa;
 }
+#else
+static av_cold void dct_unquantize_init_msa(MpegEncContext *s)
+{
+}
 #endif  // #if HAVE_MSA
 
 #if HAVE_MMI
@@ -45,14 +50,19 @@ static av_cold void dct_unquantize_init_mmi(MpegEncContext *s)
 
     s->denoise_dct= ff_denoise_dct_mmi;
 }
+#else
+static av_cold void dct_unquantize_init_mmi(MpegEncContext *s)
+{
+}
 #endif /* HAVE_MMI */
 
 av_cold void ff_mpv_common_init_mips(MpegEncContext *s)
 {
-#if HAVE_MMI
-    dct_unquantize_init_mmi(s);
-#endif /* HAVE_MMI */
-#if HAVE_MSA
-    dct_unquantize_init_msa(s);
-#endif  // #if HAVE_MSA
+    int cpu_flags = av_get_cpu_flags();
+
+    if (have_mmi(cpu_flags))
+        dct_unquantize_init_mmi(s);
+
+    if (have_msa(cpu_flags))
+        dct_unquantize_init_msa(s);
 }
diff --git a/libavcodec/mips/mpegvideoencdsp_init_mips.c b/libavcodec/mips/mpegvideoencdsp_init_mips.c
index 9bfe94e4cd..543f429aa4 100644
--- a/libavcodec/mips/mpegvideoencdsp_init_mips.c
+++ b/libavcodec/mips/mpegvideoencdsp_init_mips.c
@@ -18,6 +18,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/mips/cpu.h"
 #include "libavcodec/bit_depth_template.c"
 #include "h263dsp_mips.h"
 
@@ -29,12 +30,18 @@ static av_cold void mpegvideoencdsp_init_msa(MpegvideoEncDSPContext *c,
     c->pix_sum = ff_pix_sum_msa;
 #endif
 }
+#else
+static av_cold void mpegvideoencdsp_init_msa(MpegvideoEncDSPContext *c,
+                                             AVCodecContext *avctx)
+{
+}
 #endif  // #if HAVE_MSA
 
 av_cold void ff_mpegvideoencdsp_init_mips(MpegvideoEncDSPContext *c,
                                           AVCodecContext *avctx)
 {
-#if HAVE_MSA
-    mpegvideoencdsp_init_msa(c, avctx);
-#endif  // #if HAVE_MSA
+    int cpu_flags = av_get_cpu_flags();
+
+    if (have_msa(cpu_flags))
+        mpegvideoencdsp_init_msa(c, avctx);
 }
diff --git a/libavcodec/mips/pixblockdsp_init_mips.c b/libavcodec/mips/pixblockdsp_init_mips.c
index fd0238d79b..cf4f986ba7 100644
--- a/libavcodec/mips/pixblockdsp_init_mips.c
+++ b/libavcodec/mips/pixblockdsp_init_mips.c
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/mips/cpu.h"
 #include "pixblockdsp_mips.h"
 
 #if HAVE_MSA
@@ -43,6 +44,12 @@ static av_cold void pixblockdsp_init_msa(PixblockDSPContext *c,
         break;
     }
 }
+#else
+static av_cold void pixblockdsp_init_msa(PixblockDSPContext *c,
+                                         AVCodecContext *avctx,
+                                         unsigned high_bit_depth)
+{
+}
 #endif  // #if HAVE_MSA
 
 #if HAVE_MMI
@@ -55,15 +62,21 @@ static av_cold void pixblockdsp_init_mmi(PixblockDSPContext *c,
         c->get_pixels = ff_get_pixels_8_mmi;
     }
 }
+#else
+static av_cold void pixblockdsp_init_mmi(PixblockDSPContext *c,
+        AVCodecContext *avctx, unsigned high_bit_depth)
+{
+}
 #endif /* HAVE_MMI */
 
 void ff_pixblockdsp_init_mips(PixblockDSPContext *c, AVCodecContext *avctx,
                               unsigned high_bit_depth)
 {
-#if HAVE_MMI
-    pixblockdsp_init_mmi(c, avctx, high_bit_depth);
-#endif /* HAVE_MMI */
-#if HAVE_MSA
-    pixblockdsp_init_msa(c, avctx, high_bit_depth);
-#endif  // #if HAVE_MSA
+    int cpu_flags = av_get_cpu_flags();
+
+    if (have_mmi(cpu_flags))
+        pixblockdsp_init_mmi(c, avctx, high_bit_depth);
+
+    if (have_msa(cpu_flags))
+        pixblockdsp_init_msa(c, avctx, high_bit_depth);
 }
diff --git a/libavcodec/mips/qpeldsp_init_mips.c b/libavcodec/mips/qpeldsp_init_mips.c
index 140e8f89c9..2d136f5d6f 100644
--- a/libavcodec/mips/qpeldsp_init_mips.c
+++ b/libavcodec/mips/qpeldsp_init_mips.c
@@ -18,6 +18,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/mips/cpu.h"
 #include "qpeldsp_mips.h"
 
 #if HAVE_MSA
@@ -157,11 +158,16 @@ static av_cold void qpeldsp_init_msa(QpelDSPContext *c)
     c->avg_qpel_pixels_tab[1][14] = ff_hv_mc_qpel_avg_dst_aver_v_src1_8x8_msa;
     c->avg_qpel_pixels_tab[1][15] = ff_hv_mc_qpel_avg_dst_aver_hv_src11_8x8_msa;
 }
+#else
+static av_cold void qpeldsp_init_msa(QpelDSPContext *c)
+{
+}
 #endif  // #if HAVE_MSA
 
 void ff_qpeldsp_init_mips(QpelDSPContext *c)
 {
-#if HAVE_MSA
-    qpeldsp_init_msa(c);
-#endif  // #if HAVE_MSA
+    int cpu_flags = av_get_cpu_flags();
+
+    if (have_msa(cpu_flags))
+        qpeldsp_init_msa(c);
 }
diff --git a/libavcodec/mips/vc1dsp_init_mips.c b/libavcodec/mips/vc1dsp_init_mips.c
index c0007ff650..09840c6b83 100644
--- a/libavcodec/mips/vc1dsp_init_mips.c
+++ b/libavcodec/mips/vc1dsp_init_mips.c
@@ -18,6 +18,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/mips/cpu.h"
 #include "libavutil/attributes.h"
 #include "libavcodec/vc1dsp.h"
 #include "vc1dsp_mips.h"
@@ -98,6 +99,10 @@ static av_cold void vc1dsp_init_mmi(VC1DSPContext *dsp)
     dsp->put_no_rnd_vc1_chroma_pixels_tab[1] = ff_put_no_rnd_vc1_chroma_mc4_mmi;
     dsp->avg_no_rnd_vc1_chroma_pixels_tab[1] = ff_avg_no_rnd_vc1_chroma_mc4_mmi;
 }
+#else
+static av_cold void vc1dsp_init_mmi(VC1DSPContext *dsp)
+{
+}
 #endif /* HAVE_MMI */
 
 #if HAVE_MSA
@@ -117,14 +122,19 @@ static av_cold void vc1dsp_init_msa(VC1DSPContext *dsp)
     FN_ASSIGN(put_, 3, 2, _msa);
     FN_ASSIGN(put_, 3, 3, _msa);
 }
+#else
+static av_cold void vc1dsp_init_msa(VC1DSPContext *dsp)
+{
+}
 #endif /* HAVE_MSA */
 
 av_cold void ff_vc1dsp_init_mips(VC1DSPContext *dsp)
 {
-#if HAVE_MMI
-    vc1dsp_init_mmi(dsp);
-#endif /* HAVE_MMI */
-#if HAVE_MSA
-    vc1dsp_init_msa(dsp);
-#endif /* HAVE_MSA */
+    int cpu_flags = av_get_cpu_flags();
+
+    if (have_mmi(cpu_flags))
+        vc1dsp_init_mmi(dsp);
+
+    if (have_msa(cpu_flags))
+        vc1dsp_init_msa(dsp);
 }
diff --git a/libavcodec/mips/videodsp_init.c b/libavcodec/mips/videodsp_init.c
index 817040420b..9d64d88a48 100644
--- a/libavcodec/mips/videodsp_init.c
+++ b/libavcodec/mips/videodsp_init.c
@@ -18,6 +18,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/mips/cpu.h"
 #include "config.h"
 #include "libavutil/attributes.h"
 #include "libavutil/mips/asmdefs.h"
@@ -41,11 +42,16 @@ static void prefetch_mips(uint8_t *mem, ptrdiff_t stride, int h)
         : [stride] "r" (stride)
     );
 }
+#else
+static void prefetch_mips(uint8_t *mem, ptrdiff_t stride, int h)
+{
+}
 #endif  // #if HAVE_MSA
 
 av_cold void ff_videodsp_init_mips(VideoDSPContext *ctx, int bpc)
 {
-#if HAVE_MSA
-    ctx->prefetch = prefetch_mips;
-#endif  // #if HAVE_MSA
+    int cpu_flags = av_get_cpu_flags();
+
+    if (have_msa(cpu_flags))
+        ctx->prefetch = prefetch_mips;
 }
diff --git a/libavcodec/mips/vp3dsp_init_mips.c b/libavcodec/mips/vp3dsp_init_mips.c
index e183db35b6..fcbd7e8332 100644
--- a/libavcodec/mips/vp3dsp_init_mips.c
+++ b/libavcodec/mips/vp3dsp_init_mips.c
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/mips/cpu.h"
 #include "config.h"
 #include "libavutil/attributes.h"
 #include "libavcodec/avcodec.h"
@@ -36,6 +37,10 @@ static av_cold void vp3dsp_init_msa(VP3DSPContext *c, int flags)
     c->v_loop_filter = ff_vp3_v_loop_filter_msa;
     c->h_loop_filter = ff_vp3_h_loop_filter_msa;
 }
+#else
+static av_cold void vp3dsp_init_msa(VP3DSPContext *c, int flags)
+{
+}
 #endif /* HAVE_MSA */
 
 #if HAVE_MMI
@@ -47,14 +52,19 @@ static av_cold void vp3dsp_init_mmi(VP3DSPContext *c, int flags)
     c->idct_put      = ff_vp3_idct_put_mmi;
     c->idct_dc_add   = ff_vp3_idct_dc_add_mmi;
 }
+#else
+static av_cold void vp3dsp_init_mmi(VP3DSPContext *c, int flags)
+{
+}
 #endif /* HAVE_MMI */
 
 av_cold void ff_vp3dsp_init_mips(VP3DSPContext *c, int flags)
 {
-#if HAVE_MMI
-    vp3dsp_init_mmi(c, flags);
-#endif /* HAVE_MMI */
-#if HAVE_MSA
-    vp3dsp_init_msa(c, flags);
-#endif /* HAVE_MSA */
+    int cpu_flags = av_get_cpu_flags();
+
+    if (have_mmi(cpu_flags))
+        vp3dsp_init_mmi(c, flags);
+
+    if (have_msa(cpu_flags))
+        vp3dsp_init_msa(c, flags);
 }
diff --git a/libavcodec/mips/vp8dsp_init_mips.c b/libavcodec/mips/vp8dsp_init_mips.c
index 7fd8fb0d32..73f172b64f 100644
--- a/libavcodec/mips/vp8dsp_init_mips.c
+++ b/libavcodec/mips/vp8dsp_init_mips.c
@@ -24,6 +24,7 @@
  * VP8 compatible video decoder
  */
 
+#include "libavutil/mips/cpu.h"
 #include "config.h"
 #include "libavutil/attributes.h"
 #include "libavcodec/vp8dsp.h"
@@ -104,6 +105,10 @@ static av_cold void vp8dsp_init_msa(VP8DSPContext *dsp)
     dsp->vp8_v_loop_filter_simple = ff_vp8_v_loop_filter_simple_msa;
     dsp->vp8_h_loop_filter_simple = ff_vp8_h_loop_filter_simple_msa;
 }
+#else
+static av_cold void vp8dsp_init_msa(VP8DSPContext *dsp)
+{
+}
 #endif  // #if HAVE_MSA
 
 #if HAVE_MMI
@@ -189,14 +194,19 @@ static av_cold void vp8dsp_init_mmi(VP8DSPContext *dsp)
     dsp->vp8_v_loop_filter_simple = ff_vp8_v_loop_filter_simple_mmi;
     dsp->vp8_h_loop_filter_simple = ff_vp8_h_loop_filter_simple_mmi;
 }
+#else
+static av_cold void vp8dsp_init_mmi(VP8DSPContext *dsp)
+{
+}
 #endif /* HAVE_MMI */
 
 av_cold void ff_vp8dsp_init_mips(VP8DSPContext *dsp)
 {
-#if HAVE_MMI
-    vp8dsp_init_mmi(dsp);
-#endif /* HAVE_MMI */
-#if HAVE_MSA
-    vp8dsp_init_msa(dsp);
-#endif  // #if HAVE_MSA
+    int cpu_flags = av_get_cpu_flags();
+
+    if (have_mmi(cpu_flags))
+        vp8dsp_init_mmi(dsp);
+
+    if (have_msa(cpu_flags))
+        vp8dsp_init_msa(dsp);
 }
diff --git a/libavcodec/mips/vp9dsp_init_mips.c b/libavcodec/mips/vp9dsp_init_mips.c
index 5990fa6952..ddbbd9f838 100644
--- a/libavcodec/mips/vp9dsp_init_mips.c
+++ b/libavcodec/mips/vp9dsp_init_mips.c
@@ -18,6 +18,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/mips/cpu.h"
 #include "config.h"
 #include "libavutil/common.h"
 #include "libavcodec/vp9dsp.h"
@@ -166,6 +167,10 @@ static av_cold void vp9dsp_init_msa(VP9DSPContext *dsp, int bpp)
     vp9dsp_mc_init_msa(dsp, bpp);
     vp9dsp_loopfilter_init_msa(dsp, bpp);
 }
+#else
+static av_cold void vp9dsp_init_msa(VP9DSPContext *dsp, int bpp)
+{
+}
 #endif  // #if HAVE_MSA
 
 #if HAVE_MMI
@@ -205,14 +210,19 @@ static av_cold void vp9dsp_init_mmi(VP9DSPContext *dsp, int bpp)
         vp9dsp_mc_init_mmi(dsp);
     }
 }
+#else
+static av_cold void vp9dsp_init_mmi(VP9DSPContext *dsp, int bpp)
+{
+}
 #endif  // #if HAVE_MMI
 
 av_cold void ff_vp9dsp_init_mips(VP9DSPContext *dsp, int bpp)
 {
-#if HAVE_MMI
-    vp9dsp_init_mmi(dsp, bpp);
-#endif  // #if HAVE_MMI
-#if HAVE_MSA
-    vp9dsp_init_msa(dsp, bpp);
-#endif  // #if HAVE_MSA
+    int cpu_flags = av_get_cpu_flags();
+
+    if (have_mmi(cpu_flags))
+        vp9dsp_init_mmi(dsp, bpp);
+
+    if (have_msa(cpu_flags))
+        vp9dsp_init_msa(dsp, bpp);
 }
diff --git a/libavcodec/mips/wmv2dsp_init_mips.c b/libavcodec/mips/wmv2dsp_init_mips.c
index 51dd2078d9..9dc3aeb29a 100644
--- a/libavcodec/mips/wmv2dsp_init_mips.c
+++ b/libavcodec/mips/wmv2dsp_init_mips.c
@@ -18,6 +18,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/mips/cpu.h"
 #include "config.h"
 #include "libavutil/attributes.h"
 #include "wmv2dsp_mips.h"
@@ -28,11 +29,16 @@ static av_cold void wmv2dsp_init_mmi(WMV2DSPContext *c)
     c->idct_add  = ff_wmv2_idct_add_mmi;
     c->idct_put  = ff_wmv2_idct_put_mmi;
 }
+#else
+static av_cold void wmv2dsp_init_mmi(WMV2DSPContext *c)
+{
+}
 #endif /* HAVE_MMI */
 
 av_cold void ff_wmv2dsp_init_mips(WMV2DSPContext *c)
 {
-#if HAVE_MMI
-    wmv2dsp_init_mmi(c);
-#endif /* HAVE_MMI */
+    int cpu_flags = av_get_cpu_flags();
+
+    if (have_mmi(cpu_flags))
+        wmv2dsp_init_mmi(c);
 }
diff --git a/libavcodec/mips/xvididct_init_mips.c b/libavcodec/mips/xvididct_init_mips.c
index c1d82cc30c..9193cbb401 100644
--- a/libavcodec/mips/xvididct_init_mips.c
+++ b/libavcodec/mips/xvididct_init_mips.c
@@ -18,6 +18,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/mips/cpu.h"
 #include "xvididct_mips.h"
 
 #if HAVE_MMI
@@ -34,12 +35,18 @@ static av_cold void xvid_idct_init_mmi(IDCTDSPContext *c, AVCodecContext *avctx,
         }
     }
 }
+#else
+static av_cold void xvid_idct_init_mmi(IDCTDSPContext *c, AVCodecContext *avctx,
+        unsigned high_bit_depth)
+{
+}
 #endif /* HAVE_MMI */
 
 av_cold void ff_xvid_idct_init_mips(IDCTDSPContext *c, AVCodecContext *avctx,
         unsigned high_bit_depth)
 {
-#if HAVE_MMI
-    xvid_idct_init_mmi(c, avctx, high_bit_depth);
-#endif /* HAVE_MMI */
+    int cpu_flags = av_get_cpu_flags();
+
+    if (have_mmi(cpu_flags))
+        xvid_idct_init_mmi(c, avctx, high_bit_depth);
 }
-- 
2.20.1


More information about the ffmpeg-devel mailing list