[x264-devel] Patch Intel's CPU dispatcher

Steven Walters git at videolan.org
Thu Mar 24 06:38:35 CET 2011


x264 | branch: master | Steven Walters <kemuri9 at gmail.com> | Wed Mar  2 20:39:25 2011 -0500| [9b7b3c7e238e3cac383dd7d2863b7c3c0f718422] | committer: Jason Garrett-Glaser

Patch Intel's CPU dispatcher
Reduces Intel Compiler's bias against non-Intel CPUs.

Big thanks to Agner for the original information on how to do this.

> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=9b7b3c7e238e3cac383dd7d2863b7c3c0f718422
---

 common/osdep.c |   32 ++++++++++++++++++++++++++++++++
 1 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/common/osdep.c b/common/osdep.c
index fc03591..e44d26c 100644
--- a/common/osdep.c
+++ b/common/osdep.c
@@ -89,3 +89,35 @@ int x264_threading_init( void )
     return 0;
 }
 #endif
+
+#ifdef __INTEL_COMPILER
+/* Agner's patch to Intel's CPU dispatcher from pages 131-132 of
+ * http://agner.org/optimize/optimizing_cpp.pdf (2011-01-30)
+ * adapted to x264's cpu schema. */
+
+// Global variable indicating cpu
+int __intel_cpu_indicator = 0;
+// CPU dispatcher function
+void __intel_cpu_indicator_init( void )
+{
+    unsigned int cpu = x264_cpu_detect();
+    if( cpu&X264_CPU_AVX )
+        __intel_cpu_indicator = 0x20000;
+    else if( cpu&X264_CPU_SSE42 )
+        __intel_cpu_indicator = 0x8000;
+    else if( cpu&X264_CPU_SSE4 )
+        __intel_cpu_indicator = 0x2000;
+    else if( cpu&X264_CPU_SSSE3 )
+        __intel_cpu_indicator = 0x1000;
+    else if( cpu&X264_CPU_SSE3 )
+        __intel_cpu_indicator = 0x800;
+    else if( cpu&X264_CPU_SSE2 && !(cpu&X264_CPU_SSE2_IS_SLOW) )
+        __intel_cpu_indicator = 0x200;
+    else if( cpu&X264_CPU_SSE )
+        __intel_cpu_indicator = 0x80;
+    else if( cpu&X264_CPU_MMXEXT )
+        __intel_cpu_indicator = 8;
+    else
+        __intel_cpu_indicator = 1;
+}
+#endif



More information about the x264-devel mailing list