Checks for CPU capability at run-time (on x86 and PPC)
authorRémi Denis-Courmont <remi@remlab.net>
Mon, 9 May 2011 16:17:49 +0000 (19:17 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Mon, 9 May 2011 16:41:00 +0000 (19:41 +0300)
modules/3dnow/memcpy.c
modules/altivec/memcpy.c
modules/mmx/memcpy.c
modules/mmxext/memcpy.c
modules/video_chroma/i420_rgb.c
modules/video_chroma/i420_yuy2.c
modules/video_chroma/i422_yuy2.c

index 37f33e9..34b1f87 100644 (file)
@@ -34,6 +34,9 @@
 
 static int Activate( vlc_object_t *p_this )
 {
+    if( !(vlc_CPU() & CPU_CAPABILITY_3DNOW) )
+        return VLC_EGENERIC;
+
     VLC_UNUSED(p_this);
     vlc_fastmem_register( fast_memcpy, NULL );
 
index 2d91ea2..cd329c1 100644 (file)
@@ -49,6 +49,9 @@ static void * fast_memcpy ( void * to, const void * from, size_t len );
  *****************************************************************************/
 static int Activate ( vlc_object_t *p_this )
 {
+    if( !(vlc_CPU() & CPU_CAPABILITY_ALTIVEC) )
+        return VLC_EGENERIC;
+
     VLC_UNUSED(p_this);
     vlc_fastmem_register( fast_memcpy, NULL );
     return VLC_SUCCESS;
index 53ae7ae..8aa55ac 100644 (file)
@@ -34,6 +34,9 @@
 
 static int Activate( vlc_object_t *p_this )
 {
+    if( !(vlc_CPU() & CPU_CAPABILITY_MMX) )
+        return VLC_EGENERIC;
+
     VLC_UNUSED(p_this);
     vlc_fastmem_register( fast_memcpy, NULL );
 
index 9e59bf5..344bff7 100644 (file)
@@ -34,6 +34,9 @@
 
 static int Activate( vlc_object_t *p_this )
 {
+    if( !(vlc_CPU() & CPU_CAPABILITY_MMXEXT) )
+        return VLC_EGENERIC;
+
     VLC_UNUSED(p_this);
     vlc_fastmem_register( fast_memcpy, NULL );
 
index cfaeb73..e74ec66 100644 (file)
@@ -35,6 +35,7 @@
 #include <vlc_common.h>
 #include <vlc_plugin.h>
 #include <vlc_filter.h>
+#include <vlc_cpu.h>
 
 #include "i420_rgb.h"
 #if defined (MODULE_NAME_IS_i420_rgb)
@@ -83,14 +84,17 @@ vlc_module_begin ()
     set_description( N_("I420,IYUV,YV12 to "
                        "RGB2,RV15,RV16,RV24,RV32 conversions") )
     set_capability( "video filter2", 80 )
+# define CPU_CAPABILITY 0
 #elif defined (MODULE_NAME_IS_i420_rgb_mmx)
     set_description( N_( "MMX I420,IYUV,YV12 to "
                         "RV15,RV16,RV24,RV32 conversions") )
     set_capability( "video filter2", 100 )
+# define CPU_CAPABILITY CPU_CAPABILITY_MMX
 #elif defined (MODULE_NAME_IS_i420_rgb_sse2)
     set_description( N_( "SSE2 I420,IYUV,YV12 to "
                         "RV15,RV16,RV24,RV32 conversions") )
     set_capability( "video filter2", 120 )
+# define CPU_CAPABILITY CPU_CAPABILITY_SSE2
 #endif
     set_callbacks( Activate, Deactivate )
 vlc_module_end ()
@@ -107,6 +111,10 @@ static int Activate( vlc_object_t *p_this )
     size_t i_tables_size;
 #endif
 
+#if CPU_CAPABILITY
+    if( !(vlc_CPU() & CPU_CAPABILITY) )
+        return VLC_EGENERIC;
+#endif
     if( p_filter->fmt_out.video.i_width & 1
      || p_filter->fmt_out.video.i_height & 1 )
     {
index 09a904f..1d36b06 100644 (file)
@@ -33,6 +33,7 @@
 #include <vlc_common.h>
 #include <vlc_plugin.h>
 #include <vlc_filter.h>
+#include <vlc_cpu.h>
 
 #if defined (MODULE_NAME_IS_i420_yuy2_altivec) && defined(HAVE_ALTIVEC_H)
 #   include <altivec.h>
@@ -87,16 +88,20 @@ vlc_module_begin ()
 #if defined (MODULE_NAME_IS_i420_yuy2)
     set_description( N_("Conversions from " SRC_FOURCC " to " DEST_FOURCC) )
     set_capability( "video filter2", 80 )
+# define CPU_CAPABILITY 0
 #elif defined (MODULE_NAME_IS_i420_yuy2_mmx)
     set_description( N_("MMX conversions from " SRC_FOURCC " to " DEST_FOURCC) )
     set_capability( "video filter2", 160 )
+# define CPU_CAPABILITY CPU_CAPABILITY_MMX
 #elif defined (MODULE_NAME_IS_i420_yuy2_sse2)
     set_description( N_("SSE2 conversions from " SRC_FOURCC " to " DEST_FOURCC) )
     set_capability( "video filter2", 250 )
+# define CPU_CAPABILITY CPU_CAPABILITY_SSE2
 #elif defined (MODULE_NAME_IS_i420_yuy2_altivec)
     set_description(
             _("AltiVec conversions from " SRC_FOURCC " to " DEST_FOURCC) );
     set_capability( "video filter2", 250 )
+# define CPU_CAPABILITY CPU_CAPABILITY_ALTIVEC
 #endif
     set_callbacks( Activate, NULL )
 vlc_module_end ()
@@ -110,6 +115,10 @@ static int Activate( vlc_object_t *p_this )
 {
     filter_t *p_filter = (filter_t *)p_this;
 
+#if CPU_CAPABILITY
+    if( !(vlc_CPU() & CPU_CAPABILITY) )
+        return VLC_EGENERIC;
+#endif
     if( p_filter->fmt_in.video.i_width & 1
      || p_filter->fmt_in.video.i_height & 1 )
     {
index fc426ff..142057f 100644 (file)
@@ -33,6 +33,7 @@
 #include <vlc_common.h>
 #include <vlc_plugin.h>
 #include <vlc_filter.h>
+#include <vlc_cpu.h>
 
 #include "i422_yuy2.h"
 
@@ -70,12 +71,15 @@ vlc_module_begin ()
 #if defined (MODULE_NAME_IS_i422_yuy2)
     set_description( N_("Conversions from " SRC_FOURCC " to " DEST_FOURCC) )
     set_capability( "video filter2", 80 )
+# define CPU_CAPABILITY 0
 #elif defined (MODULE_NAME_IS_i422_yuy2_mmx)
     set_description( N_("MMX conversions from " SRC_FOURCC " to " DEST_FOURCC) )
     set_capability( "video filter2", 100 )
+# define CPU_CAPABILITY CPU_CAPABILITY_MMX
 #elif defined (MODULE_NAME_IS_i422_yuy2_sse2)
     set_description( N_("SSE2 conversions from " SRC_FOURCC " to " DEST_FOURCC) )
     set_capability( "video filter2", 120 )
+# define CPU_CAPABILITY CPU_CAPABILITY_SSE2
 #endif
     set_callbacks( Activate, NULL )
 vlc_module_end ()
@@ -89,6 +93,10 @@ static int Activate( vlc_object_t *p_this )
 {
     filter_t *p_filter = (filter_t *)p_this;
 
+#if CPU_CAPABILITY
+    if( !(vlc_CPU() & CPU_CAPABILITY) )
+        return VLC_EGENERIC;
+#endif
     if( p_filter->fmt_in.video.i_width & 1
      || p_filter->fmt_in.video.i_height & 1 )
     {