[Pixman] [PATCH 1/3] autoconf: add MMX EXT support check

Matt Turner mattst88 at gmail.com
Sun Feb 19 11:59:26 PST 2012


The current runtime test checked that MMX extensions were available
before executing code in pixman-mmx.c, even though no MMX extensions
were used.

The new --{enable,disable}-mmxext flag enables the use of MMX extensions
in pixman-mmx.c. This allows us to use a few more efficient instructions
added with 3DNow and SSE1 by default, and also allows the builder to
disable these instructions and use pixman-mmx.c on a system without MMX
extensions, something that wasn't possible before.

The SSE intrinsics header xmmintrin.h includes the MMX extensions we
want to use, while the mm3dnow.h header does not. Instead of compiling
with -msse (which would cause SSE instructions to be generated), we use
a hack and just #define __SSE__ before including xmmintrin.h.

Signed-off-by: Matt Turner <mattst88 at gmail.com>
---
 configure.ac        |   40 ++++++++++++++++++++++++++++++++++++++++
 pixman/pixman-cpu.c |    4 ++++
 2 files changed, 44 insertions(+), 0 deletions(-)

diff --git a/configure.ac b/configure.ac
index 4f8a0c5..d6db78b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -324,6 +324,46 @@ fi
 AM_CONDITIONAL(USE_X86_MMX, test $have_mmx_intrinsics = yes)
 
 dnl ===========================================================================
+dnl Check for MMX Extensions
+
+have_mmxext_intrinsics=no
+AC_MSG_CHECKING(whether to use MMX EXT intrinsics)
+AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
+#if defined(__GNUC__) && (__GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 4))
+#error "Need GCC >= 3.4 for MMX EXT intrinsics"
+#endif
+#include <mmintrin.h>
+extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
+_mm_mulhi_pu16 (__m64 __A, __m64 __B)
+{
+  return (__m64) __builtin_ia32_pmulhuw ((__v4hi)__A, (__v4hi)__B);
+}
+int main () {
+    __m64 v = _mm_cvtsi32_si64 (1);
+    return _mm_cvtsi64_si32(_mm_mulhi_pu16 (v, v));
+}]])], have_mmxext_intrinsics=yes)
+
+AC_ARG_ENABLE(mmxext,
+   [AC_HELP_STRING([--disable-mmxext],
+                   [disable x86 MMX EXT instructions in the MMX fast paths])],
+   [enable_mmxext=$enableval], [enable_mmxext=auto])
+
+if test $enable_mmx = no -o $enable_mmxext = no ; then
+   have_mmxext_intrinsics=disabled
+fi
+
+if test $have_mmxext_intrinsics = yes ; then
+   AC_DEFINE(USE_X86_MMX_EXT, 1, [use x86 MMX EXT compiler intrinsics])
+fi
+
+AC_MSG_RESULT($have_mmxext_intrinsics)
+if test $enable_mmxext = yes && test $have_mmxext_intrinsics = no ; then
+   AC_MSG_ERROR([x86 MMX EXT intrinsics not detected])
+fi
+
+AM_CONDITIONAL(USE_X86_MMX_EXT, test $have_mmxext_intrinsics = yes)
+
+dnl ===========================================================================
 dnl Check for SSE2
 
 if test "x$SSE2_CFLAGS" = "x" ; then
diff --git a/pixman/pixman-cpu.c b/pixman/pixman-cpu.c
index 92942b2..901d1a2 100644
--- a/pixman/pixman-cpu.c
+++ b/pixman/pixman-cpu.c
@@ -627,7 +627,11 @@ pixman_have_mmx (void)
     if (!initialized)
     {
 	unsigned int features = detect_cpu_features ();
+#ifdef USE_X86_MMX_EXT
 	mmx_present = (features & (MMX | MMX_EXTENSIONS)) == (MMX | MMX_EXTENSIONS);
+#else
+	mmx_present = (features & MMX) == MMX;
+#endif
 	initialized = TRUE;
     }
 
-- 
1.7.3.4



More information about the Pixman mailing list