<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Nov 4, 2014 at 6:05 AM, Juha-Pekka Heikkila <span dir="ltr"><<a href="mailto:juhapekka.heikkila@gmail.com" target="_blank">juhapekka.heikkila@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Signed-off-by: Juha-Pekka Heikkila <<a href="mailto:juhapekka.heikkila@gmail.com" target="_blank">juhapekka.heikkila@gmail.com</a>><br>
---<br>
 src/mesa/Makefile.am              |   8 +++<br>
 src/mesa/main/x86/sse2_clamping.c | 103 ++++++++++++++++++++++++++++++++++++++<br>
 src/mesa/main/x86/sse2_clamping.h |  49 ++++++++++++++++++<br>
 3 files changed, 160 insertions(+)<br>
 create mode 100644 src/mesa/main/x86/sse2_clamping.c<br>
 create mode 100644 src/mesa/main/x86/sse2_clamping.h<br>
<br>
diff --git a/src/mesa/Makefile.am b/src/mesa/Makefile.am<br>
index e71bccb..5d3c6f5 100644<br>
--- a/src/mesa/Makefile.am<br>
+++ b/src/mesa/Makefile.am<br>
@@ -111,6 +111,10 @@ if SSE41_SUPPORTED<br>
 ARCH_LIBS += <a href="http://libmesa_sse41.la" target="_blank">libmesa_sse41.la</a><br>
 endif<br>
<br>
+if SSE2_SUPPORTED<br>
+ARCH_LIBS += <a href="http://libmesa_sse2.la" target="_blank">libmesa_sse2.la</a><br>
+endif<br>
+<br>
 MESA_ASM_FILES_FOR_ARCH =<br>
<br>
 if HAVE_X86_ASM<br>
@@ -154,6 +158,10 @@ libmesa_sse41_la_SOURCES = \<br>
        main/streaming-load-memcpy.c<br>
 libmesa_sse41_la_CFLAGS = $(AM_CFLAGS) -msse4.1<br>
<br>
+libmesa_sse2_la_SOURCES = \<br>
+       main/x86/sse2_clamping.c<br>
+libmesa_sse2_la_CFLAGS = $(AM_CFLAGS) -msse2<br>
+<br>
 pkgconfigdir = $(libdir)/pkgconfig<br>
 pkgconfig_DATA = gl.pc<br>
<br>
diff --git a/src/mesa/main/x86/sse2_clamping.c b/src/mesa/main/x86/sse2_clamping.c<br>
new file mode 100644<br>
index 0000000..7df1c85<br>
--- /dev/null<br>
+++ b/src/mesa/main/x86/sse2_clamping.c<br>
@@ -0,0 +1,103 @@<br>
+/*<br>
+ * Copyright © 2014 Intel Corporation<br>
+ *<br>
+ * Permission is hereby granted, free of charge, to any person obtaining a<br>
+ * copy of this software and associated documentation files (the "Software"),<br>
+ * to deal in the Software without restriction, including without limitation<br>
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
+ * and/or sell copies of the Software, and to permit persons to whom the<br>
+ * Software is furnished to do so, subject to the following conditions:<br>
+ *<br>
+ * The above copyright notice and this permission notice (including the next<br>
+ * paragraph) shall be included in all copies or substantial portions of the<br>
+ * Software.<br>
+ *<br>
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL<br>
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS<br>
+ * IN THE SOFTWARE.<br>
+ *<br>
+ * Authors:<br>
+ *    Juha-Pekka Heikkila <<a href="mailto:juhapekka.heikkila@gmail.com" target="_blank">juhapekka.heikkila@gmail.com</a>><br>
+ *<br>
+ */<br>
+<br>
+#ifdef __SSE2__<br>
+#include "main/macros.h"<br>
+#include "main/x86/sse2_clamping.h"<br>
+#include <emmintrin.h><br>
+<br>
+/**<br>
+ * Clamp four float values to [min,max]<br>
+ */<br>
+static inline void<br>
+_mesa_clamp_float_rgba(GLfloat src[4], GLfloat result[4], const float min,<br>
+                       const float max)<br>
+{<br>
+   __m128  operand, minval, maxval;<br>
+<br>
+   operand = _mm_loadu_ps(src);<br>
+   minval = _mm_set1_ps(min);<br>
+   maxval = _mm_set1_ps(max);<br>
+   operand = _mm_max_ps(operand, minval);<br>
+   operand = _mm_min_ps(operand, maxval);<br>
+   _mm_storeu_ps(result, operand);<br>
+}<br>
+<br>
+<br>
+/* Clamp n amount float rgba pixels to [min,max] using SSE2<br></blockquote><div><br></div><div>Conceptually, _mesa_streaming_clamp_float_rgba() is clamping a contiguous array of floats to some min/max value. The fact that they are pixels is somewhat incidental when looking at it from a stream perspective. It looks like the code is more or less just operating on n*4 floats. Given that, a more efficient implementation would check alignment and then use aligned loads and streaming stores. It doesn't really matter if you straddle pixel boundaries as long as each float is operated on. I'm not sure how much effort you want to put into this though. :)</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
+ */<br>
+void<br>
+_mesa_streaming_clamp_float_rgba(const GLuint n, GLfloat rgba_src[][4],<br>
+                                 GLfloat rgba_dst[][4], const GLfloat min,<br>
+                                 const GLfloat max)<br>
+{<br>
+   int i;<br>
+<br>
+   for (i = 0; i < n; i++) {<br>
+      _mesa_clamp_float_rgba(rgba_src[i], rgba_dst[i], min, max);<br>
+   }<br>
+}<br>
+<br>
+<br>
+/* Clamp n amount float rgba pixels to [min,max] using SSE2 and apply<br>
+ * scaling and mapping to components.<br>
+ *<br>
+ * this replace handling of [RGBA] channels:<br>
+ * rgba_temp[RCOMP] = CLAMP(rgba[i][RCOMP], 0.0F, 1.0F);<br>
+ * rgba[i][RCOMP] = rMap[F_TO_I(rgba_temp[RCOMP] * scale[RCOMP])];<br>
+ */<br>
+void<br>
+_mesa_clamp_float_rgba_scale_and_map(const GLuint n, GLfloat rgba_src[][4],<br>
+                                     GLfloat rgba_dst[][4], const GLfloat min,<br>
+                                     const GLfloat max,<br>
+                                     const GLfloat scale[4],<br>
+                                     const GLfloat* rMap, const GLfloat* gMap,<br>
+                                     const GLfloat* bMap, const GLfloat* aMap)<br>
+{<br>
+   int i;<br>
+   GLfloat __attribute__((aligned(16))) temp[4];<br>
+   __m128  *operand = (__m128*) &temp, multiplier, mmove;<br>
+   __m128i truncated_integers;<br>
+<br>
+   const unsigned int* map_p = (const unsigned int*) &truncated_integers;<br>
+<br>
+   multiplier = _mm_loadu_ps(scale);<br>
+<br>
+   for(i = 0; i < n; i++) {<br>
+      _mesa_clamp_float_rgba(rgba_src[i], temp, min, max);<br>
+<br>
+      *operand = _mm_mul_ps(multiplier, *operand);<br>
+      truncated_integers = _mm_cvttps_epi32(*operand);<br>
+      mmove = _mm_set_ps(aMap[map_p[ACOMP]], bMap[map_p[BCOMP]],<br>
+                         gMap[map_p[GCOMP]], rMap[map_p[RCOMP]] );<br>
+<br>
+      _mm_storeu_ps(rgba_dst[i], mmove);<br>
+   }<br>
+}<br>
+<br>
+<br>
+#endif /* __SSE2__ */<br>
diff --git a/src/mesa/main/x86/sse2_clamping.h b/src/mesa/main/x86/sse2_clamping.h<br>
new file mode 100644<br>
index 0000000..688fab7<br>
--- /dev/null<br>
+++ b/src/mesa/main/x86/sse2_clamping.h<br>
@@ -0,0 +1,49 @@<br>
+/*<br>
+ * Copyright © 2014 Intel Corporation<br>
+ *<br>
+ * Permission is hereby granted, free of charge, to any person obtaining a<br>
+ * copy of this software and associated documentation files (the "Software"),<br>
+ * to deal in the Software without restriction, including without limitation<br>
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
+ * and/or sell copies of the Software, and to permit persons to whom the<br>
+ * Software is furnished to do so, subject to the following conditions:<br>
+ *<br>
+ * The above copyright notice and this permission notice (including the next<br>
+ * paragraph) shall be included in all copies or substantial portions of the<br>
+ * Software.<br>
+ *<br>
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL<br>
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS<br>
+ * IN THE SOFTWARE.<br>
+ *<br>
+ * Authors:<br>
+ *    Juha-Pekka Heikkila <<a href="mailto:juhapekka.heikkila@gmail.com" target="_blank">juhapekka.heikkila@gmail.com</a>><br>
+ *<br>
+ */<br>
+<br>
+#ifdef __SSE2__<br>
+<br>
+/* Clamp n amount float rgba pixels to [min,max] using SSE2<br>
+ */<br>
+void<br>
+_mesa_streaming_clamp_float_rgba(const GLuint n, GLfloat rgba_src[][4],<br>
+                                 GLfloat rgba_dst[][4], const GLfloat min,<br>
+                                 const GLfloat max);<br>
+<br>
+<br>
+/* Clamp n amount float rgba pixels to [min,max] using SSE2 and apply<br>
+ * scaling and mapping to components.<br>
+ */<br>
+void<br>
+_mesa_clamp_float_rgba_scale_and_map(const GLuint n, GLfloat rgba_src[][4],<br>
+                                     GLfloat rgba_dst[][4], const GLfloat min,<br>
+                                     const GLfloat max,<br>
+                                     const GLfloat scale[4],<br>
+                                     const GLfloat* rMap, const GLfloat* gMap,<br>
+                                     const GLfloat* bMap, const GLfloat* aMap);<br>
+<br>
+#endif /* __SSE2__ */<br>
<span><font color="#888888">--<br>
1.8.5.1<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank">mesa-dev@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>