[Pixman] [RFC PATCH] mmx: Use shuffle instruction when available

Matt Turner mattst88 at gmail.com
Sun Feb 12 16:42:06 PST 2012


Although not part of the original MMX instruction set, both SSE and
AMD's Extended 3DNow! both provide the pshufw instruction.

ARM iwMMXt also has an equivalent instruction, as do the Loongson
Multimedia Instructions.

We can simplify the expand_alpha, expand_alpha_rev, and invert_colors
functions down to this single instruction.

The SSE intrinsics provide _mm_shuffle_pi16, but there aren't 3DNow!
intrinsics (to my knowledge). This will require a bit of work to
configure.ac, which I haven't done yet. I'm interested in hearing
some opinions on using Extended MMX instructions.
---
 pixman/pixman-mmx.c |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/pixman/pixman-mmx.c b/pixman/pixman-mmx.c
index 937ce8f..52e6ab1 100644
--- a/pixman/pixman-mmx.c
+++ b/pixman/pixman-mmx.c
@@ -36,6 +36,10 @@
 #if defined USE_X86_MMX || defined USE_ARM_IWMMXT
 
 #include <mmintrin.h>
+#define HAVE_MMX_SHUFFLE 1
+#ifdef HAVE_MMX_SHUFFLE
+#include <xmmintrin.h>
+#endif
 #include "pixman-private.h"
 #include "pixman-combine32.h"
 
@@ -233,6 +237,9 @@ pix_add (__m64 a, __m64 b)
 static force_inline __m64
 expand_alpha (__m64 pixel)
 {
+#ifdef HAVE_MMX_SHUFFLE
+    return _mm_shuffle_pi16(pixel, 0xFF);
+#else
     __m64 t1, t2;
 
     t1 = shift (pixel, -48);
@@ -242,11 +249,15 @@ expand_alpha (__m64 pixel)
     t1 = _mm_or_si64 (t1, t2);
 
     return t1;
+#endif
 }
 
 static force_inline __m64
 expand_alpha_rev (__m64 pixel)
 {
+#ifdef HAVE_MMX_SHUFFLE
+    return _mm_shuffle_pi16(pixel, 0x00);
+#else
     __m64 t1, t2;
 
     /* move alpha to low 16 bits and zero the rest */
@@ -259,11 +270,15 @@ expand_alpha_rev (__m64 pixel)
     t1 = _mm_or_si64 (t1, t2);
 
     return t1;
+#endif
 }
 
 static force_inline __m64
 invert_colors (__m64 pixel)
 {
+#ifdef HAVE_MMX_SHUFFLE
+    return _mm_shuffle_pi16(pixel, 0xC6);
+#else
     __m64 x, y, z;
 
     x = y = z = pixel;
@@ -279,6 +294,7 @@ invert_colors (__m64 pixel)
     x = _mm_or_si64 (x, z);
 
     return x;
+#endif
 }
 
 static force_inline __m64
-- 
1.7.3.4



More information about the Pixman mailing list