[Pixman] [PATCH 3/3] Add MSA support.

Yin Shiyou yinshiyou-hf at loongson.cn
Tue Feb 11 08:28:04 UTC 2020


MSA is mips SIMD Architecture.
Loongson processor support MSA from 3A4000 and 2K1000.
---
 configure.ac             | 53 ++++++++++++++++++++++++++++++++++++++++++++++++
 pixman/Makefile.am       |  9 ++++++++
 pixman/pixman-mips-msa.c | 44 ++++++++++++++++++++++++++++++++++++++++
 pixman/pixman-mips.c     |  9 +++++++-
 pixman/pixman-private.h  |  5 +++++
 5 files changed, 119 insertions(+), 1 deletion(-)
 create mode 100644 pixman/pixman-mips-msa.c

diff --git a/configure.ac b/configure.ac
index fd7df47..dffc83b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -323,6 +323,57 @@ fi
 AM_CONDITIONAL(USE_LOONGSON_MMI, test $have_loongson_mmi = yes)
 
 dnl ===========================================================================
+dnl Check for MIPS SIMD Architecture(MSA)
+
+if test "x$MSA_CFLAGS" = "x" ; then
+    MSA_CFLAGS="-mmsa"
+fi
+
+have_mips_msa=no
+AC_MSG_CHECKING(whether to use MSA intrinsics)
+
+xserver_save_CFLAGS=$CFLAGS
+CFLAGS=" $MSA_CFLAGS $CFLAGS -I$srcdir"
+AC_LINK_IFELSE([AC_LANG_SOURCE([[
+#if !(defined(__mips__) &&  __mips_isa_rev >= 2)
+#error "MIPS SIMD Architecture are only available on MIPS"
+#endif
+#if defined(__GNUC__) && (__GNUC__ < 7 )
+#error "Need GCC >= 7 for MSA compilation"
+#endif
+#include <msa.h>
+int
+main ()
+{
+    v16i8 a = {0}, b = {0};
+    a = __msa_addvi_b(b,1);
+    return 0;
+}]])], have_mips_msa=yes)
+CFLAGS=$xserver_save_CFLAGS
+
+AC_ARG_ENABLE(mips-msa,
+   [AC_HELP_STRING([--disable-mips-msa],
+                   [disable Mips MSA fast paths])],
+   [enable_mips_msa=$enableval], [enable_mips_msa=auto])
+
+if test $enable_mips_msa = no ; then
+   have_mips_msa=disabled
+fi
+
+if test $have_mips_msa = yes ; then
+   AC_DEFINE(USE_MIPS_MSA, 1, [use MIPS SIMD Architecture])
+else
+   MSA_CFLAGS=
+fi
+
+AC_MSG_RESULT($have_mips_msa)
+if test $enable_mips_msa = yes && test $have_mips_msa = no ; then
+   AC_MSG_ERROR([Mips MSA not detected])
+fi
+
+AM_CONDITIONAL(USE_MIPS_MSA, test $have_mips_msa = yes)
+
+dnl ===========================================================================
 dnl Check for MMX
 
 if test "x$MMX_CFLAGS" = "x" ; then
@@ -532,6 +583,8 @@ case $host_os in
 esac
 
 AC_SUBST(LS_CFLAGS)
+AC_SUBST(MSA_CFLAGS)
+AC_SUBST(MSA_LDFLAGS)
 AC_SUBST(IWMMXT_CFLAGS)
 AC_SUBST(MMX_CFLAGS)
 AC_SUBST(MMX_LDFLAGS)
diff --git a/pixman/Makefile.am b/pixman/Makefile.am
index 3de2615..8af1de5 100644
--- a/pixman/Makefile.am
+++ b/pixman/Makefile.am
@@ -129,6 +129,15 @@ libpixman_1_la_LIBADD += libpixman-mips-dspr2.la
 ASM_CFLAGS_mips_dspr2=
 endif
 
+# mips msa code
+if USE_MIPS_MSA
+noinst_LTLIBRARIES += libpixman-mips-msa.la
+libpixman_mips_msa_la_SOURCES = pixman-mips-msa.c
+libpixman_mips_msa_la_CFLAGS = $(MSA_CFLAGS)
+libpixman_1_la_LDFLAGS += $(MSA_LDFLAGS)
+libpixman_1_la_LIBADD += libpixman-mips-msa.la
+endif
+
 # loongson code
 if USE_LOONGSON_MMI
 noinst_LTLIBRARIES += libpixman-loongson-mmi.la
diff --git a/pixman/pixman-mips-msa.c b/pixman/pixman-mips-msa.c
new file mode 100644
index 0000000..10b731a
--- /dev/null
+++ b/pixman/pixman-mips-msa.c
@@ -0,0 +1,44 @@
+/*
+ * Copyright © 2019 Loongson Technology Co. Ltd.
+ * Contributed by Yin Shiyou(yinshiyou-hf at loongson.cn)
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Red Hat not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  Red Hat makes no representations about the
+ * suitability of this software for any purpose.  It is provided "as is"
+ * without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ *
+ */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <msa.h>
+#include "pixman-private.h"
+
+static const pixman_fast_path_t msa_fast_paths[] =
+{
+    { PIXMAN_OP_NONE },
+};
+
+pixman_implementation_t *
+_pixman_implementation_create_msa (pixman_implementation_t *fallback)
+{
+    pixman_implementation_t *imp =
+        _pixman_implementation_create (fallback, msa_fast_paths);
+
+    return imp;
+}
diff --git a/pixman/pixman-mips.c b/pixman/pixman-mips.c
index 3048813..f3c3142 100644
--- a/pixman/pixman-mips.c
+++ b/pixman/pixman-mips.c
@@ -25,7 +25,7 @@
 
 #include "pixman-private.h"
 
-#if defined(USE_MIPS_DSPR2) || defined(USE_LOONGSON_MMI)
+#if defined(USE_MIPS_DSPR2) || defined(USE_LOONGSON_MMI) || defined(USE_MIPS_MSA)
 
 #include <string.h>
 #include <stdlib.h>
@@ -74,6 +74,13 @@ _pixman_mips_get_implementations (pixman_implementation_t *imp)
 	imp = _pixman_implementation_create_mmx (imp);
 #endif
 
+#ifdef USE_MIPS_MSA
+    if (!_pixman_disabled ("mips-msa") && have_feature ("msa"))
+    {
+        imp = _pixman_implementation_create_msa (imp);
+    }
+#endif
+
 #ifdef USE_MIPS_DSPR2
     if (!_pixman_disabled ("mips-dspr2"))
     {
diff --git a/pixman/pixman-private.h b/pixman/pixman-private.h
index d836cc5..f82ae61 100644
--- a/pixman/pixman-private.h
+++ b/pixman/pixman-private.h
@@ -620,6 +620,11 @@ pixman_implementation_t *
 _pixman_implementation_create_mmx (pixman_implementation_t *fallback);
 #endif
 
+#if USE_MIPS_MSA
+pixman_implementation_t *
+_pixman_implementation_create_msa (pixman_implementation_t *fallback);
+#endif
+
 #ifdef USE_SSE2
 pixman_implementation_t *
 _pixman_implementation_create_sse2 (pixman_implementation_t *fallback);
-- 
2.1.0



More information about the Pixman mailing list