cpu: do not define capabilities on platforms that do not have them
authorRémi Denis-Courmont <remi@remlab.net>
Wed, 1 Aug 2012 15:03:19 +0000 (18:03 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Wed, 1 Aug 2012 15:37:19 +0000 (18:37 +0300)
Also update avcodec encoder and switcher x86 checks.

include/vlc_cpu.h
modules/codec/avcodec/avcodec.c
modules/codec/avcodec/encoder.c
modules/codec/libmpeg2.c
modules/codec/x264.c
modules/stream_out/switcher.c
modules/video_filter/postproc.c
modules/video_filter/swscale.c

index 03b0a36..befe49e 100644 (file)
 
 /**
  * \file
- * This file provides CPU-specific optimization flags.
+ * This file provides CPU features detection.
  */
 
 #ifndef VLC_CPU_H
 # define VLC_CPU_H 1
 
+VLC_API unsigned vlc_CPU(void);
+
 # if defined (__i386__) || defined (__x86_64__)
+#  define HAVE_FPU 1
 #  define CPU_CAPABILITY_MMX     (1<<3)
 #  define CPU_CAPABILITY_3DNOW   (1<<4)
 #  define CPU_CAPABILITY_MMXEXT  (1<<5)
 #  define VLC_SSE VLC_SSE_is_not_implemented_on_this_compiler
 # endif
 
-# else
-#  define CPU_CAPABILITY_MMX     (0)
-#  define CPU_CAPABILITY_3DNOW   (0)
-#  define CPU_CAPABILITY_MMXEXT  (0)
-#  define CPU_CAPABILITY_SSE     (0)
-#  define CPU_CAPABILITY_SSE2    (0)
-#  define CPU_CAPABILITY_SSE3    (0)
-#  define CPU_CAPABILITY_SSSE3   (0)
-#  define CPU_CAPABILITY_SSE4_1  (0)
-#  define CPU_CAPABILITY_SSE4_2  (0)
-#  define CPU_CAPABILITY_SSE4A   (0)
-# endif
-
-# if defined (__ppc__) || defined (__ppc64__) || defined (__powerpc__)
-#  define CPU_CAPABILITY_ALTIVEC (1<<16)
-# else
-#  define CPU_CAPABILITY_ALTIVEC (0)
-# endif
-
-# if defined (__arm__)
-#  define CPU_CAPABILITY_NEON    (1<<24)
-# else
-#  define CPU_CAPABILITY_NEON    (0)
-# endif
-
-VLC_API unsigned vlc_CPU( void );
-
-/** Are floating point operations fast?
- * If this bit is not set, you should try to use fixed-point instead.
- */
-# if defined (__i386__) || defined (__x86_64__)
-#  define HAVE_FPU 1
-
-# elif defined (__powerpc__) || defined (__ppc__) || defined (__ppc64__)
+# elif defined (__ppc__) || defined (__ppc64__) || defined (__powerpc__)
 #  define HAVE_FPU 1
+#  define CPU_CAPABILITY_ALTIVEC (1<<16)
 
 # elif defined (__arm__)
 #  if defined (__VFP_FP__) && !defined (__SOFTFP__)
@@ -96,14 +67,19 @@ VLC_API unsigned vlc_CPU( void );
 #  else
 #   define HAVE_FPU 0
 #  endif
+#  define CPU_CAPABILITY_NEON    (1<<24)
 
 # elif defined (__sparc__)
 #  define HAVE_FPU 1
 
 # else
+/**
+ * Are single precision floating point operations "fast"?
+ * If this preprocessor constant is zero, floating point should be avoided
+ * (especially relevant for audio codecs).
+ */
 #  define HAVE_FPU 0
 
 # endif
 
 #endif /* !VLC_CPU_H */
-
index a9d2dad..507f03c 100644 (file)
@@ -329,43 +329,35 @@ static int OpenDecoder( vlc_object_t *p_this )
     p_context->opaque = (void *)p_this;
 
     /* Set CPU capabilities */
-    unsigned i_cpu = vlc_CPU();
     p_context->dsp_mask = 0;
+#if defined (__i386__) || defined (__x86_64__)
+    unsigned i_cpu = vlc_CPU();
     if( !(i_cpu & CPU_CAPABILITY_MMX) )
-    {
         p_context->dsp_mask |= AV_CPU_FLAG_MMX;
-    }
     if( !(i_cpu & CPU_CAPABILITY_MMXEXT) )
-    {
         p_context->dsp_mask |= AV_CPU_FLAG_MMX2;
-    }
     if( !(i_cpu & CPU_CAPABILITY_3DNOW) )
-    {
         p_context->dsp_mask |= AV_CPU_FLAG_3DNOW;
-    }
     if( !(i_cpu & CPU_CAPABILITY_SSE) )
-    {
         p_context->dsp_mask |= AV_CPU_FLAG_SSE;
-    }
     if( !(i_cpu & CPU_CAPABILITY_SSE2) )
-    {
         p_context->dsp_mask |= AV_CPU_FLAG_SSE2;
-    }
-#ifdef AV_CPU_FLAG_SSE3
+# ifdef AV_CPU_FLAG_SSE3
     if( !(i_cpu & CPU_CAPABILITY_SSE3) )
         p_context->dsp_mask |= AV_CPU_FLAG_SSE3;
-#endif
-#ifdef AV_CPU_FLAG_SSSE3
+# endif
+# ifdef AV_CPU_FLAG_SSSE3
     if( !(i_cpu & CPU_CAPABILITY_SSSE3) )
         p_context->dsp_mask |= AV_CPU_FLAG_SSSE3;
-#endif
-#ifdef AV_CPU_FLAG_SSE4
+# endif
+# ifdef AV_CPU_FLAG_SSE4
     if( !(i_cpu & CPU_CAPABILITY_SSE4_1) )
         p_context->dsp_mask |= AV_CPU_FLAG_SSE4;
-#endif
-#ifdef AV_CPU_FLAG_SSE42
+# endif
+# ifdef AV_CPU_FLAG_SSE42
     if( !(i_cpu & CPU_CAPABILITY_SSE4_2) )
         p_context->dsp_mask |= AV_CPU_FLAG_SSE42;
+# endif
 #endif
 
     p_dec->b_need_packetized = true;
index d2d20bf..a9cadb3 100644 (file)
@@ -323,25 +323,36 @@ int OpenEncoder( vlc_object_t *p_this )
     p_context->opaque = (void *)p_this;
 
     /* Set CPU capabilities */
-    unsigned i_cpu = vlc_CPU();
     p_context->dsp_mask = 0;
+#if defined (__i386__) || defined (__x86_64__)
+    unsigned i_cpu = vlc_CPU();
     if( !(i_cpu & CPU_CAPABILITY_MMX) )
-    {
         p_context->dsp_mask |= AV_CPU_FLAG_MMX;
-    }
     if( !(i_cpu & CPU_CAPABILITY_MMXEXT) )
-    {
         p_context->dsp_mask |= AV_CPU_FLAG_MMX2;
-    }
     if( !(i_cpu & CPU_CAPABILITY_3DNOW) )
-    {
         p_context->dsp_mask |= AV_CPU_FLAG_3DNOW;
-    }
     if( !(i_cpu & CPU_CAPABILITY_SSE) )
-    {
         p_context->dsp_mask |= AV_CPU_FLAG_SSE;
+    if( !(i_cpu & CPU_CAPABILITY_SSE2) )
         p_context->dsp_mask |= AV_CPU_FLAG_SSE2;
-    }
+# ifdef AV_CPU_FLAG_SSE3
+    if( !(i_cpu & CPU_CAPABILITY_SSE3) )
+        p_context->dsp_mask |= AV_CPU_FLAG_SSE3;
+# endif
+# ifdef AV_CPU_FLAG_SSSE3
+    if( !(i_cpu & CPU_CAPABILITY_SSSE3) )
+        p_context->dsp_mask |= AV_CPU_FLAG_SSSE3;
+# endif
+# ifdef AV_CPU_FLAG_SSE4
+    if( !(i_cpu & CPU_CAPABILITY_SSE4_1) )
+        p_context->dsp_mask |= AV_CPU_FLAG_SSE4;
+# endif
+# ifdef AV_CPU_FLAG_SSE42
+    if( !(i_cpu & CPU_CAPABILITY_SSE4_2) )
+        p_context->dsp_mask |= AV_CPU_FLAG_SSE42;
+# endif
+#endif
 
     p_sys->i_key_int = var_GetInteger( p_enc, ENC_CFG_PREFIX "keyint" );
     p_sys->i_b_frames = var_GetInteger( p_enc, ENC_CFG_PREFIX "bframes" );
index 62d359c..8365c15 100644 (file)
@@ -192,35 +192,27 @@ static int OpenDecoder( vlc_object_t *p_this )
     p_sys->i_gop_user_data = 0;
 
 #if defined( __i386__ ) || defined( __x86_64__ )
-    if( vlc_CPU() & CPU_CAPABILITY_MMX )
-    {
+    unsigned cpu = vlc_CPU();
+    if( cpu & CPU_CAPABILITY_MMX )
         i_accel |= MPEG2_ACCEL_X86_MMX;
-    }
-
-    if( vlc_CPU() & CPU_CAPABILITY_3DNOW )
-    {
+    if( cpu & CPU_CAPABILITY_3DNOW )
         i_accel |= MPEG2_ACCEL_X86_3DNOW;
-    }
-
-    if( vlc_CPU() & CPU_CAPABILITY_MMXEXT )
-    {
+    if( cpu & CPU_CAPABILITY_MMXEXT )
         i_accel |= MPEG2_ACCEL_X86_MMXEXT;
-    }
-
 #elif defined( __powerpc__ ) || defined( __ppc__ ) || defined( __ppc64__ )
     if( vlc_CPU() & CPU_CAPABILITY_ALTIVEC )
-    {
         i_accel |= MPEG2_ACCEL_PPC_ALTIVEC;
-    }
 
-#elif defined(__arm__) && defined(MPEG2_ACCEL_ARM)
+#elif defined(__arm__)
+# ifdef MPEG2_ACCEL_ARM
     i_accel |= MPEG2_ACCEL_ARM;
-
+# endif
 # ifdef MPEG2_ACCEL_ARM_NEON
     if( vlc_CPU() & CPU_CAPABILITY_NEON )
        i_accel |= MPEG2_ACCEL_ARM_NEON;
 # endif
 
+    /* TODO: sparc */
 #else
     /* If we do not know this CPU, trust libmpeg2's feature detection */
     i_accel = MPEG2_ACCEL_DETECT;
index 1b56c94..6b6623f 100644 (file)
@@ -1259,24 +1259,17 @@ static int  Open ( vlc_object_t *p_this )
         x264_param_apply_profile( &p_sys->param, psz_val );
     free( psz_val );
 
-
+#if defined (__i386__) || defined (__x86_64__)
     unsigned i_cpu = vlc_CPU();
     if( !(i_cpu & CPU_CAPABILITY_MMX) )
-    {
         p_sys->param.cpu &= ~X264_CPU_MMX;
-    }
     if( !(i_cpu & CPU_CAPABILITY_MMXEXT) )
-    {
         p_sys->param.cpu &= ~X264_CPU_MMXEXT;
-    }
     if( !(i_cpu & CPU_CAPABILITY_SSE) )
-    {
         p_sys->param.cpu &= ~X264_CPU_SSE;
-    }
     if( !(i_cpu & CPU_CAPABILITY_SSE2) )
-    {
         p_sys->param.cpu &= ~X264_CPU_SSE2;
-    }
+#endif
 
     /* BUILD 29 adds support for multi-threaded encoding while BUILD 49 (r543)
        also adds support for threads = 0 for automatically selecting an optimal
index a0d699e..53ff95b 100644 (file)
@@ -378,28 +378,36 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
 #endif
 
         /* Set CPU capabilities */
-        unsigned i_cpu = vlc_CPU();
         id->ff_enc_c->dsp_mask = 0;
+#if defined (__i386__) || defined (__x86_64__)
+        unsigned i_cpu = vlc_CPU();
         if( !(i_cpu & CPU_CAPABILITY_MMX) )
-        {
             id->ff_enc_c->dsp_mask |= AV_CPU_FLAG_MMX;
-        }
         if( !(i_cpu & CPU_CAPABILITY_MMXEXT) )
-        {
             id->ff_enc_c->dsp_mask |= AV_CPU_FLAG_MMX2;
-        }
         if( !(i_cpu & CPU_CAPABILITY_3DNOW) )
-        {
             id->ff_enc_c->dsp_mask |= AV_CPU_FLAG_3DNOW;
-        }
         if( !(i_cpu & CPU_CAPABILITY_SSE) )
-        {
             id->ff_enc_c->dsp_mask |= AV_CPU_FLAG_SSE;
-        }
         if( !(i_cpu & CPU_CAPABILITY_SSE2) )
-        {
             id->ff_enc_c->dsp_mask |= AV_CPU_FLAG_SSE2;
-        }
+# ifdef AV_CPU_FLAG_SSE3
+        if( !(i_cpu & CPU_CAPABILITY_SSE3) )
+            id->ff_enc_c->dsp_mask |= AV_CPU_FLAG_SSE3;
+# endif
+# ifdef AV_CPU_FLAG_SSSE3
+        if( !(i_cpu & CPU_CAPABILITY_SSSE3) )
+            id->ff_enc_c->dsp_mask |= AV_CPU_FLAG_SSSE3;
+# endif
+# ifdef AV_CPU_FLAG_SSE4
+        if( !(i_cpu & CPU_CAPABILITY_SSE4_1) )
+            id->ff_enc_c->dsp_mask |= AV_CPU_FLAG_SSE4;
+# endif
+# ifdef AV_CPU_FLAG_SSE42
+        if( !(i_cpu & CPU_CAPABILITY_SSE4_2) )
+            id->ff_enc_c->dsp_mask |= AV_CPU_FLAG_SSE42;
+# endif
+#endif
 
         id->ff_enc_c->sample_rate = p_fmt->audio.i_rate;
         id->ff_enc_c->time_base.num = 1;
@@ -791,28 +799,36 @@ static mtime_t VideoCommand( sout_stream_t *p_stream, sout_stream_id_t *id )
 #endif
 
         /* Set CPU capabilities */
-        unsigned i_cpu = vlc_CPU();
         id->ff_enc_c->dsp_mask = 0;
+#if defined (__i386__) || defined (__x86_64__)
+        unsigned i_cpu = vlc_CPU();
         if( !(i_cpu & CPU_CAPABILITY_MMX) )
-        {
             id->ff_enc_c->dsp_mask |= AV_CPU_FLAG_MMX;
-        }
         if( !(i_cpu & CPU_CAPABILITY_MMXEXT) )
-        {
             id->ff_enc_c->dsp_mask |= AV_CPU_FLAG_MMX2;
-        }
         if( !(i_cpu & CPU_CAPABILITY_3DNOW) )
-        {
             id->ff_enc_c->dsp_mask |= AV_CPU_FLAG_3DNOW;
-        }
         if( !(i_cpu & CPU_CAPABILITY_SSE) )
-        {
             id->ff_enc_c->dsp_mask |= AV_CPU_FLAG_SSE;
-        }
         if( !(i_cpu & CPU_CAPABILITY_SSE2) )
-        {
             id->ff_enc_c->dsp_mask |= AV_CPU_FLAG_SSE2;
-        }
+# ifdef AV_CPU_FLAG_SSE3
+        if( !(i_cpu & CPU_CAPABILITY_SSE3) )
+            id->ff_enc_c->dsp_mask |= AV_CPU_FLAG_SSE3;
+# endif
+# ifdef AV_CPU_FLAG_SSSE3
+        if( !(i_cpu & CPU_CAPABILITY_SSSE3) )
+            id->ff_enc_c->dsp_mask |= AV_CPU_FLAG_SSSE3;
+# endif
+# ifdef AV_CPU_FLAG_SSE4
+        if( !(i_cpu & CPU_CAPABILITY_SSE4_1) )
+            id->ff_enc_c->dsp_mask |= AV_CPU_FLAG_SSE4;
+# endif
+# ifdef AV_CPU_FLAG_SSE42
+        if( !(i_cpu & CPU_CAPABILITY_SSE4_2) )
+            id->ff_enc_c->dsp_mask |= AV_CPU_FLAG_SSE42;
+# endif
+#endif
 
         id->ff_enc_c->width = p_sys->p_pictures[p_sys->i_cmd-1].format.i_width;
         id->ff_enc_c->height = p_sys->p_pictures[p_sys->i_cmd-1].format.i_height;
index bb4a1d7..e58a025 100644 (file)
@@ -122,7 +122,6 @@ static int OpenPostproc( vlc_object_t *p_this )
     filter_t *p_filter = (filter_t *)p_this;
     filter_sys_t *p_sys;
     vlc_value_t val, val_orig, text;
-    unsigned i_cpu = vlc_CPU();
     int i_flags = 0;
 
     if( p_filter->fmt_in.video.i_chroma != p_filter->fmt_out.video.i_chroma ||
@@ -134,14 +133,18 @@ static int OpenPostproc( vlc_object_t *p_this )
     }
 
     /* Set CPU capabilities */
+#if defined(__i386__) || defined(__x86_64__)
+    unsigned i_cpu = vlc_CPU();
     if( i_cpu & CPU_CAPABILITY_MMX )
         i_flags |= PP_CPU_CAPS_MMX;
     if( i_cpu & CPU_CAPABILITY_MMXEXT )
         i_flags |= PP_CPU_CAPS_MMX2;
     if( i_cpu & CPU_CAPABILITY_3DNOW )
         i_flags |= PP_CPU_CAPS_3DNOW;
-    if( i_cpu & CPU_CAPABILITY_ALTIVEC )
+#elif defined(__ppc__) || defined(__ppc64__) || defined(__powerpc__)
+    if( vlc_CPU() & CPU_CAPABILITY_ALTIVEC )
         i_flags |= PP_CPU_CAPS_ALTIVEC;
+#endif
 
     switch( p_filter->fmt_in.video.i_chroma )
     {
index 28d3b02..04fbe7e 100644 (file)
@@ -229,9 +229,10 @@ static void CloseScaler( vlc_object_t *p_this )
  *****************************************************************************/
 static int GetSwsCpuMask(void)
 {
-    const unsigned int i_cpu = vlc_CPU();
     int i_sws_cpu = 0;
 
+#if defined(__i386__) || defined(__x86_64__)
+    const unsigned int i_cpu = vlc_CPU();
     if( i_cpu & CPU_CAPABILITY_MMX )
         i_sws_cpu |= SWS_CPU_CAPS_MMX;
 #if (LIBSWSCALE_VERSION_INT >= ((0<<16)+(5<<8)+0))
@@ -240,9 +241,10 @@ static int GetSwsCpuMask(void)
 #endif
     if( i_cpu & CPU_CAPABILITY_3DNOW )
         i_sws_cpu |= SWS_CPU_CAPS_3DNOW;
-
-    if( i_cpu & CPU_CAPABILITY_ALTIVEC )
+#elif defined(__ppc__) || defined(__ppc64__) || defined(__powerpc__)
+    if( vlc_CPU() & CPU_CAPABILITY_ALTIVEC )
         i_sws_cpu |= SWS_CPU_CAPS_ALTIVEC;
+#endif
 
     return i_sws_cpu;
 }