[PATCH 2/2] Implement av_get_cpu_mm_flags().

Stefano Sabatini stefano.sabatini-lala
Sun Aug 29 23:29:38 CEST 2010


---
 libavcodec/Makefile                                |    1 -
 libavcodec/arm/dsputil_init_arm.c                  |    5 --
 libavcodec/dct-test.c                              |    3 +-
 libavcodec/h263dec.c                               |    3 +-
 libavcodec/libxvidff.c                             |    6 +-
 libavcodec/ppc/dsputil_ppc.c                       |   14 +----
 libavcodec/ppc/h264_altivec.c                      |    5 +-
 libavcodec/ppc/mpegvideo_altivec.c                 |    3 +-
 libavcodec/ppc/vp8dsp_altivec.c                    |    3 +-
 libavcodec/x86/cavsdsp_mmx.c                       |    3 +-
 libavcodec/x86/dnxhd_mmx.c                         |    2 +-
 libavcodec/x86/dsputil_mmx.c                       |    4 +-
 libavcodec/x86/dsputilenc_mmx.c                    |    3 +-
 libavcodec/x86/fft.c                               |    5 +-
 libavcodec/x86/h264dsp_mmx.c                       |    3 +-
 libavcodec/x86/motion_est_mmx.c                    |    2 +-
 libavcodec/x86/mpegaudiodec_mmx.c                  |    3 +-
 libavcodec/x86/mpegvideo_mmx.c                     |    1 +
 libavcodec/x86/snowdsp_mmx.c                       |    2 +-
 libavcodec/x86/vc1dsp_mmx.c                        |    3 +-
 libavcodec/x86/vp56dsp_init.c                      |    3 +-
 libavcodec/x86/vp8dsp-init.c                       |    3 +-
 libavutil/Makefile                                 |    3 +-
 libavutil/arm/cpu.h                                |   29 ++++++++++
 libavutil/cpu.c                                    |   60 ++++++++++++++++++++
 libavutil/cpu.h                                    |    6 ++
 libavutil/internal.h                               |    4 +
 .../ppc/check_altivec.c => libavutil/ppc/cpu.h     |   22 +++++--
 libavcodec/x86/cpuid.c => libavutil/x86/cpu.h      |   34 ++---------
 29 files changed, 160 insertions(+), 78 deletions(-)
 create mode 100644 libavutil/arm/cpu.h
 create mode 100644 libavutil/cpu.c
 rename libavcodec/ppc/check_altivec.c => libavutil/ppc/cpu.h (89%)
 rename libavcodec/x86/cpuid.c => libavutil/x86/cpu.h (82%)

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 3d0cb8c..0c9c632 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -633,7 +633,6 @@ SKIPHEADERS                            += mpegaudio3.h
 EXAMPLES = api
 
 TESTPROGS = cabac dct eval fft h264 iirfilter rangecoder snow
-TESTPROGS-$(ARCH_X86) += x86/cpuid
 TESTPROGS-$(HAVE_MMX) += motion
 TESTOBJS = dctref.o
 
diff --git a/libavcodec/arm/dsputil_init_arm.c b/libavcodec/arm/dsputil_init_arm.c
index d1c482b..5c13290 100644
--- a/libavcodec/arm/dsputil_init_arm.c
+++ b/libavcodec/arm/dsputil_init_arm.c
@@ -73,11 +73,6 @@ static void simple_idct_arm_add(uint8_t *dest, int line_size, DCTELEM *block)
     ff_add_pixels_clamped(block, dest, line_size);
 }
 
-int mm_support(void)
-{
-    return HAVE_IWMMXT * AV_CPU_MM_IWMMXT;
-}
-
 void dsputil_init_arm(DSPContext* c, AVCodecContext *avctx)
 {
     ff_put_pixels_clamped = c->put_pixels_clamped;
diff --git a/libavcodec/dct-test.c b/libavcodec/dct-test.c
index 7160a7b..8440a07 100644
--- a/libavcodec/dct-test.c
+++ b/libavcodec/dct-test.c
@@ -32,6 +32,7 @@
 #include <unistd.h>
 #include <math.h>
 
+#include "libavutil/cpu.h"
 #include "libavutil/common.h"
 #include "libavutil/lfg.h"
 
@@ -554,7 +555,7 @@ int main(int argc, char **argv)
     int test_idct = 0, test_248_dct = 0;
     int c,i;
     int test=1;
-    cpu_flags = mm_support();
+    cpu_flags = av_get_cpu_mm_flags();
 
     ff_ref_dct_init();
     idct_mmx_init();
diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
index 76882d1..cd3d598 100644
--- a/libavcodec/h263dec.c
+++ b/libavcodec/h263dec.c
@@ -25,6 +25,7 @@
  * H.263 decoder.
  */
 
+#include "libavutil/cpu.h"
 #include "internal.h"
 #include "avcodec.h"
 #include "dsputil.h"
@@ -553,7 +554,7 @@ retry:
 #endif
 
 #if HAVE_MMX
-    if(s->codec_id == CODEC_ID_MPEG4 && s->xvid_build>=0 && avctx->idct_algo == FF_IDCT_AUTO && (mm_support() & AV_CPU_MM_MMX)){
+    if(s->codec_id == CODEC_ID_MPEG4 && s->xvid_build>=0 && avctx->idct_algo == FF_IDCT_AUTO && (av_get_cpu_mm_flags() & AV_CPU_MM_MMX)){
         avctx->idct_algo= FF_IDCT_XVIDMMX;
         avctx->coded_width= 0; // force reinit
 //        dsputil_init(&s->dsp, avctx);
diff --git a/libavcodec/libxvidff.c b/libavcodec/libxvidff.c
index 37f6161..bda8ece 100644
--- a/libavcodec/libxvidff.c
+++ b/libavcodec/libxvidff.c
@@ -28,6 +28,7 @@
 /* needed for mkstemp() */
 #define _XOPEN_SOURCE 600
 
+#include "libavutil/internal.h"
 #include <xvid.h>
 #include <unistd.h>
 #include "avcodec.h"
@@ -44,9 +45,6 @@
 #define BUFFER_REMAINING(x)         (BUFFER_SIZE - strlen(x))
 #define BUFFER_CAT(x)               (&((x)[strlen(x)]))
 
-/* For PPC Use */
-int has_altivec(void);
-
 /**
  * Structure for the private Xvid context.
  * This stores all the private context for the codec.
@@ -215,7 +213,7 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx)  {
 #if ARCH_PPC
     /* Xvid's PPC support is borked, use libavcodec to detect */
 #if HAVE_ALTIVEC
-    if( has_altivec() ) {
+    if (ff_has_altivec()) {
         xvid_gbl_init.cpu_flags = XVID_CPU_FORCE | XVID_CPU_ALTIVEC;
     } else
 #endif
diff --git a/libavcodec/ppc/dsputil_ppc.c b/libavcodec/ppc/dsputil_ppc.c
index 09a5f32..682b3fd 100644
--- a/libavcodec/ppc/dsputil_ppc.c
+++ b/libavcodec/ppc/dsputil_ppc.c
@@ -20,20 +20,10 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/internal.h"
 #include "libavcodec/dsputil.h"
 #include "dsputil_altivec.h"
 
-int mm_support(void)
-{
-    int result = 0;
-#if HAVE_ALTIVEC
-    if (has_altivec()) {
-        result |= AV_CPU_MM_ALTIVEC;
-    }
-#endif /* result */
-    return result;
-}
-
 /* ***** WARNING ***** WARNING ***** WARNING ***** */
 /*
 clear_blocks_dcbz32_ppc will not work properly on PowerPC processors with a
@@ -179,7 +169,7 @@ void dsputil_init_ppc(DSPContext* c, AVCodecContext *avctx)
 #if HAVE_ALTIVEC
     if(CONFIG_H264_DECODER) dsputil_h264_init_ppc(c, avctx);
 
-    if (has_altivec()) {
+    if (ff_has_altivec()) {
         dsputil_init_altivec(c, avctx);
         if(CONFIG_VC1_DECODER)
             vc1dsp_init_altivec(c, avctx);
diff --git a/libavcodec/ppc/h264_altivec.c b/libavcodec/ppc/h264_altivec.c
index c9c2944..1cbee30 100644
--- a/libavcodec/ppc/h264_altivec.c
+++ b/libavcodec/ppc/h264_altivec.c
@@ -18,6 +18,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/internal.h"
 #include "libavcodec/dsputil.h"
 #include "libavcodec/h264data.h"
 #include "libavcodec/h264dsp.h"
@@ -969,7 +970,7 @@ H264_WEIGHT( 8, 4)
 
 void dsputil_h264_init_ppc(DSPContext* c, AVCodecContext *avctx) {
 
-    if (has_altivec()) {
+    if (ff_has_altivec()) {
         c->put_h264_chroma_pixels_tab[0] = put_h264_chroma_mc8_altivec;
         c->avg_h264_chroma_pixels_tab[0] = avg_h264_chroma_mc8_altivec;
         c->put_no_rnd_vc1_chroma_pixels_tab[0] = put_no_rnd_vc1_chroma_mc8_altivec;
@@ -1001,7 +1002,7 @@ void dsputil_h264_init_ppc(DSPContext* c, AVCodecContext *avctx) {
 
 void ff_h264dsp_init_ppc(H264DSPContext *c)
 {
-    if (has_altivec()) {
+    if (ff_has_altivec()) {
         c->h264_idct_add = ff_h264_idct_add_altivec;
         c->h264_idct_add8 = ff_h264_idct_add8_altivec;
         c->h264_idct_add16 = ff_h264_idct_add16_altivec;
diff --git a/libavcodec/ppc/mpegvideo_altivec.c b/libavcodec/ppc/mpegvideo_altivec.c
index 19d897f..818da39 100644
--- a/libavcodec/ppc/mpegvideo_altivec.c
+++ b/libavcodec/ppc/mpegvideo_altivec.c
@@ -23,6 +23,7 @@
 
 #include <stdlib.h>
 #include <stdio.h>
+#include "libavutil/internal.h"
 #include "libavcodec/dsputil.h"
 #include "libavcodec/mpegvideo.h"
 
@@ -570,7 +571,7 @@ static void dct_unquantize_h263_altivec(MpegEncContext *s,
 
 void MPV_common_init_altivec(MpegEncContext *s)
 {
-    if (!has_altivec()) return;
+    if (!ff_has_altivec()) return;
 
     if (s->avctx->lowres==0) {
         if ((s->avctx->idct_algo == FF_IDCT_AUTO) ||
diff --git a/libavcodec/ppc/vp8dsp_altivec.c b/libavcodec/ppc/vp8dsp_altivec.c
index f7b3cda..da77ee6 100644
--- a/libavcodec/ppc/vp8dsp_altivec.c
+++ b/libavcodec/ppc/vp8dsp_altivec.c
@@ -20,6 +20,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/internal.h"
 #include "libavcodec/vp8dsp.h"
 #include "dsputil_altivec.h"
 #include "types_altivec.h"
@@ -265,7 +266,7 @@ static void put_vp8_pixels16_altivec(uint8_t *dst, int stride, uint8_t *src, int
 
 av_cold void ff_vp8dsp_init_altivec(VP8DSPContext *c)
 {
-    if (!has_altivec())
+    if (!ff_has_altivec())
         return;
 
     c->put_vp8_epel_pixels_tab[0][0][0] = put_vp8_pixels16_altivec;
diff --git a/libavcodec/x86/cavsdsp_mmx.c b/libavcodec/x86/cavsdsp_mmx.c
index 6022469..df7b94f 100644
--- a/libavcodec/x86/cavsdsp_mmx.c
+++ b/libavcodec/x86/cavsdsp_mmx.c
@@ -23,6 +23,7 @@
  */
 
 #include "libavutil/common.h"
+#include "libavutil/cpu.h"
 #include "libavutil/x86_cpu.h"
 #include "libavcodec/dsputil.h"
 #include "libavcodec/cavsdsp.h"
@@ -472,7 +473,7 @@ static void ff_cavsdsp_init_3dnow(CAVSDSPContext* c, AVCodecContext *avctx) {
 
 void ff_cavsdsp_init_mmx(CAVSDSPContext *c, AVCodecContext *avctx)
 {
-    int mm_flags = mm_support();
+    int mm_flags = av_get_cpu_mm_flags();
 
     if (mm_flags & AV_CPU_MM_MMX2)  ff_cavsdsp_init_mmx2 (c, avctx);
     if (mm_flags & AV_CPU_MM_3DNOW) ff_cavsdsp_init_3dnow(c, avctx);
diff --git a/libavcodec/x86/dnxhd_mmx.c b/libavcodec/x86/dnxhd_mmx.c
index b9d720d..68f4ee0 100644
--- a/libavcodec/x86/dnxhd_mmx.c
+++ b/libavcodec/x86/dnxhd_mmx.c
@@ -52,7 +52,7 @@ static void get_pixels_8x4_sym_sse2(DCTELEM *block, const uint8_t *pixels, int l
 
 void ff_dnxhd_init_mmx(DNXHDEncContext *ctx)
 {
-    if (mm_support() & AV_CPU_MM_SSE2) {
+    if (av_get_cpu_mm_flags() & AV_CPU_MM_SSE2) {
         ctx->get_pixels_8x4_sym = get_pixels_8x4_sym_sse2;
     }
 }
diff --git a/libavcodec/x86/dsputil_mmx.c b/libavcodec/x86/dsputil_mmx.c
index e251af7..a9e5ac6 100644
--- a/libavcodec/x86/dsputil_mmx.c
+++ b/libavcodec/x86/dsputil_mmx.c
@@ -2501,7 +2501,7 @@ float ff_scalarproduct_float_sse(const float *v1, const float *v2, int order);
 
 void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx)
 {
-    int mm_flags = mm_support();
+    int mm_flags = av_get_cpu_mm_flags();
 
     if (avctx->dsp_mask) {
         if (avctx->dsp_mask & AV_CPU_MM_FORCE)
@@ -2930,7 +2930,7 @@ void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx)
 #if CONFIG_H264DSP
 void ff_h264dsp_init_x86(H264DSPContext *c)
 {
-    int mm_flags = mm_support();
+    int mm_flags = av_get_cpu_mm_flags();
 
     if (mm_flags & AV_CPU_MM_MMX) {
         c->h264_idct_dc_add=
diff --git a/libavcodec/x86/dsputilenc_mmx.c b/libavcodec/x86/dsputilenc_mmx.c
index 66f463a..41f2f68 100644
--- a/libavcodec/x86/dsputilenc_mmx.c
+++ b/libavcodec/x86/dsputilenc_mmx.c
@@ -22,6 +22,7 @@
  * MMX optimization by Nick Kurshev <nickols_k at mail.ru>
  */
 
+#include "libavutil/cpu.h"
 #include "libavutil/x86_cpu.h"
 #include "libavcodec/dsputil.h"
 #include "libavcodec/mpegvideo.h"
@@ -1350,7 +1351,7 @@ static int ssd_int8_vs_int16_mmx(const int8_t *pix1, const int16_t *pix2, int si
 
 void dsputilenc_init_mmx(DSPContext* c, AVCodecContext *avctx)
 {
-    int mm_flags = mm_support();
+    int mm_flags = av_get_cpu_mm_flags();
 
     if (mm_flags & AV_CPU_MM_MMX) {
         const int dct_algo = avctx->dct_algo;
diff --git a/libavcodec/x86/fft.c b/libavcodec/x86/fft.c
index f915cbf..06e8243 100644
--- a/libavcodec/x86/fft.c
+++ b/libavcodec/x86/fft.c
@@ -16,13 +16,14 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/cpu.h"
 #include "libavcodec/dsputil.h"
 #include "fft.h"
 
 av_cold void ff_fft_init_mmx(FFTContext *s)
 {
 #if HAVE_YASM
-    int has_vectors = mm_support();
+    int has_vectors = av_get_cpu_mm_flags();
     if (has_vectors & AV_CPU_MM_SSE && HAVE_SSE) {
         /* SSE for P3/P4/K8 */
         s->imdct_calc  = ff_imdct_calc_sse;
@@ -46,7 +47,7 @@ av_cold void ff_fft_init_mmx(FFTContext *s)
 #if CONFIG_DCT
 av_cold void ff_dct_init_mmx(DCTContext *s)
 {
-    int has_vectors = mm_support();
+    int has_vectors = av_get_cpu_mm_flags();
     if (has_vectors & AV_CPU_MM_SSE && HAVE_SSE)
         s->dct32 = ff_dct32_float_sse;
 }
diff --git a/libavcodec/x86/h264dsp_mmx.c b/libavcodec/x86/h264dsp_mmx.c
index 911f1d1..7534386 100644
--- a/libavcodec/x86/h264dsp_mmx.c
+++ b/libavcodec/x86/h264dsp_mmx.c
@@ -18,6 +18,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/cpu.h"
 #include "dsputil_mmx.h"
 #include "libavcodec/h264pred.h"
 
@@ -2368,7 +2369,7 @@ void ff_pred4x4_vertical_vp8_mmxext(uint8_t *src, const uint8_t *topright, int s
 #if CONFIG_H264PRED
 void ff_h264_pred_init_x86(H264PredContext *h, int codec_id)
 {
-    int mm_flags = mm_support();
+    int mm_flags = av_get_cpu_mm_flags();
 
 #if HAVE_YASM
     if (mm_flags & AV_CPU_MM_MMX) {
diff --git a/libavcodec/x86/motion_est_mmx.c b/libavcodec/x86/motion_est_mmx.c
index a70e4e5..f1c3b41 100644
--- a/libavcodec/x86/motion_est_mmx.c
+++ b/libavcodec/x86/motion_est_mmx.c
@@ -427,7 +427,7 @@ PIX_SAD(mmx2)
 
 void dsputil_init_pix_mmx(DSPContext* c, AVCodecContext *avctx)
 {
-    int mm_flags = mm_support();
+    int mm_flags = av_get_cpu_mm_flags();
 
     if (mm_flags & AV_CPU_MM_MMX) {
         c->pix_abs[0][0] = sad16_mmx;
diff --git a/libavcodec/x86/mpegaudiodec_mmx.c b/libavcodec/x86/mpegaudiodec_mmx.c
index 0d57bc4..36d5470 100644
--- a/libavcodec/x86/mpegaudiodec_mmx.c
+++ b/libavcodec/x86/mpegaudiodec_mmx.c
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/cpu.h"
 #include "libavutil/x86_cpu.h"
 
 #define CONFIG_FLOAT 1
@@ -149,7 +150,7 @@ static void apply_window_mp3(float *in, float *win, int *unused, float *out,
 
 void ff_mpegaudiodec_init_mmx(MPADecodeContext *s)
 {
-    int mm_flags = mm_support();
+    int mm_flags = av_get_cpu_mm_flags();
 
     if (mm_flags & AV_CPU_MM_SSE2) {
         s->apply_window_mp3 = apply_window_mp3;
diff --git a/libavcodec/x86/mpegvideo_mmx.c b/libavcodec/x86/mpegvideo_mmx.c
index fece818..7e1bef4 100644
--- a/libavcodec/x86/mpegvideo_mmx.c
+++ b/libavcodec/x86/mpegvideo_mmx.c
@@ -22,6 +22,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/cpu.h"
 #include "libavutil/x86_cpu.h"
 #include "libavcodec/avcodec.h"
 #include "libavcodec/dsputil.h"
diff --git a/libavcodec/x86/snowdsp_mmx.c b/libavcodec/x86/snowdsp_mmx.c
index 13b7b7d..7726ac8 100644
--- a/libavcodec/x86/snowdsp_mmx.c
+++ b/libavcodec/x86/snowdsp_mmx.c
@@ -875,7 +875,7 @@ static void ff_snow_inner_add_yblock_mmx(const uint8_t *obmc, const int obmc_str
 
 void ff_dwt_init_x86(DWTContext *c)
 {
-    int mm_flags = mm_support();
+    int mm_flags = av_get_cpu_mm_flags();
 
     if (mm_flags & AV_CPU_MM_MMX) {
         if(mm_flags & AV_CPU_MM_SSE2 & 0){
diff --git a/libavcodec/x86/vc1dsp_mmx.c b/libavcodec/x86/vc1dsp_mmx.c
index 930f2ed..b22f62a 100644
--- a/libavcodec/x86/vc1dsp_mmx.c
+++ b/libavcodec/x86/vc1dsp_mmx.c
@@ -24,6 +24,7 @@
  * OTHER DEALINGS IN THE SOFTWARE.
  */
 
+#include "libavutil/cpu.h"
 #include "libavutil/x86_cpu.h"
 #include "libavcodec/dsputil.h"
 #include "dsputil_mmx.h"
@@ -714,7 +715,7 @@ static void vc1_h_loop_filter16_sse4(uint8_t *src, int stride, int pq)
 #endif
 
 void ff_vc1dsp_init_mmx(DSPContext* dsp, AVCodecContext *avctx) {
-    int mm_flags = mm_support();
+    int mm_flags = av_get_cpu_mm_flags();
 
     dsp->put_vc1_mspel_pixels_tab[ 0] = ff_put_vc1_mspel_mc00_mmx;
     dsp->put_vc1_mspel_pixels_tab[ 4] = put_vc1_mspel_mc01_mmx;
diff --git a/libavcodec/x86/vp56dsp_init.c b/libavcodec/x86/vp56dsp_init.c
index a9dc1d9..059c8e5 100644
--- a/libavcodec/x86/vp56dsp_init.c
+++ b/libavcodec/x86/vp56dsp_init.c
@@ -20,6 +20,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/cpu.h"
 #include "libavutil/x86_cpu.h"
 #include "libavcodec/dsputil.h"
 #include "libavcodec/vp56dsp.h"
@@ -32,7 +33,7 @@ void ff_vp6_filter_diag4_sse2(uint8_t *dst, uint8_t *src, int stride,
 av_cold void ff_vp56dsp_init_x86(VP56DSPContext* c, enum CodecID codec)
 {
 #if HAVE_YASM
-    int mm_flags = mm_support();
+    int mm_flags = av_get_cpu_mm_flags();
 
     if (CONFIG_VP6_DECODER && codec == CODEC_ID_VP6) {
         if (mm_flags & AV_CPU_MM_MMX) {
diff --git a/libavcodec/x86/vp8dsp-init.c b/libavcodec/x86/vp8dsp-init.c
index baee2a9..d835f61 100644
--- a/libavcodec/x86/vp8dsp-init.c
+++ b/libavcodec/x86/vp8dsp-init.c
@@ -20,6 +20,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/cpu.h"
 #include "libavutil/x86_cpu.h"
 #include "libavcodec/vp8dsp.h"
 
@@ -282,7 +283,7 @@ DECLARE_LOOP_FILTER(sse4)
 
 av_cold void ff_vp8dsp_init_x86(VP8DSPContext* c)
 {
-    int mm_flags = mm_support();
+    int mm_flags = av_get_cpu_mm_flags();
 
 #if HAVE_YASM
     if (mm_flags & AV_CPU_MM_MMX) {
diff --git a/libavutil/Makefile b/libavutil/Makefile
index c74eb70..545e1c2 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -34,6 +34,7 @@ OBJS = adler32.o                                                        \
        aes.o                                                            \
        avstring.o                                                       \
        base64.o                                                         \
+       cpu.o                                                            \
        crc.o                                                            \
        des.o                                                            \
        error.o                                                          \
@@ -56,7 +57,7 @@ OBJS = adler32.o                                                        \
        tree.o                                                           \
        utils.o                                                          \
 
-TESTPROGS = adler32 aes base64 crc des lls md5 pca sha softfloat tree
+TESTPROGS = adler32 aes base64 cpu crc des lls md5 pca sha softfloat tree
 TESTPROGS-$(HAVE_LZO1X_999_COMPRESS) += lzo
 
 DIRS = arm bfin sh4 x86
diff --git a/libavutil/arm/cpu.h b/libavutil/arm/cpu.h
new file mode 100644
index 0000000..f67ac32
--- /dev/null
+++ b/libavutil/arm/cpu.h
@@ -0,0 +1,29 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_ARM_CPU_H
+#define AVUTIL_ARM_CPU_H
+
+#include "config.h"
+
+int av_get_cpu_flags(void)
+{
+    return HAVE_IWMMXT * AV_CPU_MM_IWMMXT;
+}
+
+#endif /* AVUTIL_ARM_CPU_H */
diff --git a/libavutil/cpu.c b/libavutil/cpu.c
new file mode 100644
index 0000000..92d85a6
--- /dev/null
+++ b/libavutil/cpu.c
@@ -0,0 +1,60 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "cpu.h"
+#include "config.h"
+
+#if   ARCH_ARM
+#   include "arm/cpu.h"
+#elif ARCH_PPC
+#   include "arm/ppc.h"
+#elif ARCH_X86
+#   include "x86/cpu.h"
+#else
+int av_get_cpu_mm_flags(void)
+{
+    return 0;
+}
+#endif
+
+#ifdef TEST
+
+#undef printf
+
+int main(void)
+{
+    int mm_flags = av_get_cpu_mm_flags();
+
+    printf("mm_flags = 0x%08X\n", mm_flags);
+    printf("mm_flags = %s%s%s%s%s%s%s%s%s%s%s%s\n",
+           mm_flags & AV_CPU_MM_MMX      ? "MMX "        : "",
+           mm_flags & AV_CPU_MM_MMX2     ? "MMX2 "       : "",
+           mm_flags & AV_CPU_MM_SSE      ? "SSE "        : "",
+           mm_flags & AV_CPU_MM_SSE2     ? "SSE2 "       : "",
+           mm_flags & AV_CPU_MM_SSE2SLOW ? "SSE2(slow) " : "",
+           mm_flags & AV_CPU_MM_SSE3     ? "SSE3 "       : "",
+           mm_flags & AV_CPU_MM_SSE3SLOW ? "SSE3(slow) " : "",
+           mm_flags & AV_CPU_MM_SSSE3    ? "SSSE3 "      : "",
+           mm_flags & AV_CPU_MM_SSE4     ? "SSE4.1 "     : "",
+           mm_flags & AV_CPU_MM_SSE42    ? "SSE4.2 "     : "",
+           mm_flags & AV_CPU_MM_3DNOW    ? "3DNow "      : "",
+           mm_flags & AV_CPU_MM_3DNOWEXT ? "3DNowExt "   : "");
+
+    return 0;
+}
+#endif
diff --git a/libavutil/cpu.h b/libavutil/cpu.h
index ec361e0..738ef86 100644
--- a/libavutil/cpu.h
+++ b/libavutil/cpu.h
@@ -41,4 +41,10 @@
 #define AV_CPU_MM_IWMMXT       0x0100 ///< XScale IWMMXT
 #define AV_CPU_MM_ALTIVEC      0x0001 ///< standard
 
+/**
+ * Return the flags which specify the MultiMedia extensions supported
+ * by the CPU.
+ */
+int av_get_cpu_mm_flags(void);
+
 #endif  /* AVUTIL_CPU_H */
diff --git a/libavutil/internal.h b/libavutil/internal.h
index 53d2b94..934e15e 100644
--- a/libavutil/internal.h
+++ b/libavutil/internal.h
@@ -231,4 +231,8 @@
     type ff_##name args
 #endif
 
+#if HAVE_ALTIVEC
+int ff_has_altivec(void);
+#endif
+
 #endif /* AVUTIL_INTERNAL_H */
diff --git a/libavcodec/ppc/check_altivec.c b/libavutil/ppc/cpu.h
similarity index 89%
rename from libavcodec/ppc/check_altivec.c
rename to libavutil/ppc/cpu.h
index 6b9332c..a1fe304 100644
--- a/libavcodec/ppc/check_altivec.c
+++ b/libavutil/ppc/cpu.h
@@ -16,11 +16,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-
-/**
- * @file
- * Check for AltiVec presence.
- */
+#ifndef AVUTIL_PPC_CPU_H
+#define AVUTIL_PPC_CPU_H
 
 #ifdef __APPLE__
 #undef _POSIX_C_SOURCE
@@ -42,8 +39,7 @@
  * This function MAY rely on signal() or fork() in order to make sure AltiVec
  * is present.
  */
-
-int has_altivec(void)
+int ff_has_altivec(void)
 {
 #ifdef __AMIGAOS4__
     ULONG result = 0;
@@ -85,3 +81,15 @@ int has_altivec(void)
 #endif /* __AMIGAOS4__ */
 }
 
+int av_get_cpu_flags(void)
+{
+    int result = 0;
+#if HAVE_ALTIVEC
+    if (ff_has_altivec()) {
+        result |= AV_CPU_MM_ALTIVEC;
+    }
+#endif
+    return result;
+}
+
+#endif /* AVUTIL_PPC_CPU_H */
diff --git a/libavcodec/x86/cpuid.c b/libavutil/x86/cpu.h
similarity index 82%
rename from libavcodec/x86/cpuid.c
rename to libavutil/x86/cpu.h
index a9a8d78..397885f 100644
--- a/libavcodec/x86/cpuid.c
+++ b/libavutil/x86/cpu.h
@@ -20,11 +20,12 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#ifndef AVUTIL_X86_CPU_H
+#define AVUTIL_X86_CPU_H
+
 #include <stdlib.h>
 #include "libavutil/x86_cpu.h"
-#include "libavcodec/dsputil.h"
-
-#undef printf
+#include "libavutil/cpu.h"
 
 /* ebx saving is necessary for PIC. gcc seems unable to see it alone */
 #define cpuid(index,eax,ebx,ecx,edx)\
@@ -37,7 +38,7 @@
          : "0" (index));
 
 /* Function to test if multimedia instructions are supported...  */
-int mm_support(void)
+int av_get_cpu_mm_flags(void)
 {
     int rval = 0;
     int eax, ebx, ecx, edx;
@@ -121,30 +122,7 @@ int mm_support(void)
         if (rval & AV_CPU_MM_SSE3) rval ^= AV_CPU_MM_SSE3SLOW|AV_CPU_MM_SSE3;
     }
 
-#if 0
-    av_log(NULL, AV_LOG_DEBUG, "%s%s%s%s%s%s%s%s%s%s%s%s\n",
-        (rval&AV_CPU_MM_MMX) ? "MMX ":"",
-        (rval&AV_CPU_MM_MMX2) ? "MMX2 ":"",
-        (rval&AV_CPU_MM_SSE) ? "SSE ":"",
-        (rval&AV_CPU_MM_SSE2) ? "SSE2 ":"",
-        (rval&AV_CPU_MM_SSE2SLOW) ? "SSE2(slow) ":"",
-        (rval&AV_CPU_MM_SSE3) ? "SSE3 ":"",
-        (rval&AV_CPU_MM_SSE3SLOW) ? "SSE3(slow) ":"",
-        (rval&AV_CPU_MM_SSSE3) ? "SSSE3 ":"",
-        (rval&AV_CPU_MM_SSE4) ? "SSE4.1 ":"",
-        (rval&AV_CPU_MM_SSE42) ? "SSE4.2 ":"",
-        (rval&AV_CPU_MM_3DNOW) ? "3DNow ":"",
-        (rval&AV_CPU_MM_3DNOWEXT) ? "3DNowExt ":"");
-#endif
     return rval;
 }
 
-#ifdef TEST
-int main ( void )
-{
-    int mm_flags;
-    mm_flags = mm_support();
-    printf("mm_support = 0x%08X\n",mm_flags);
-    return 0;
-}
-#endif
+#endif  /* AVUTIL_X86_CPU_H */
-- 
1.7.1


--cWoXeonUoKmBZSoM--



More information about the ffmpeg-devel mailing list