[Pixman] [PATCH 1/2] MIPS: DSPr2: Basic infrastructure for MIPS architecture
Nemanja Lukic
nlukic at mips.com
Fri Feb 10 07:02:23 PST 2012
From: Nemanja Lukic <nemanja.lukic at rt-rk.com>
MIPS DSP instruction set extensions
---
configure.ac | 42 ++++++++++++++++++++++++++++
pixman/Makefile.am | 13 ++++++++
pixman/pixman-cpu.c | 66 ++++++++++++++++++++++++++++++++++++++++++++
pixman/pixman-mips-dspr2.c | 51 ++++++++++++++++++++++++++++++++++
pixman/pixman-mips-dspr2.h | 38 +++++++++++++++++++++++++
pixman/pixman-private.h | 5 +++
6 files changed, 215 insertions(+), 0 deletions(-)
create mode 100644 pixman/pixman-mips-dspr2.c
create mode 100644 pixman/pixman-mips-dspr2.h
diff --git a/configure.ac b/configure.ac
index 2eded70..3d035b0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -591,6 +591,48 @@ fi
AM_CONDITIONAL(USE_ARM_IWMMXT, test $have_iwmmxt_intrinsics = yes)
+dnl ==========================================================================
+dnl Check if assembler is gas compatible and supports MIPS DSPr2 instructions
+have_mips_dspr2=no
+AC_MSG_CHECKING(whether to use MIPS DSPr2 assembler)
+xserver_save_CFLAGS=$CFLAGS
+AC_COMPILE_IFELSE([[
+#if defined(__mips__) && defined(__mips_dsp) && (__mips_dsp_rev < 2)
+#error MIPS DSPr2 is required (-mdspr2 flag must be added to CFLAGS)
+#endif
+int
+main ()
+{
+ int c = 0, a = 0, b = 0;
+ __asm__ __volatile__ (
+ "precr.qb.ph %[c], %[a], %[b] \n\t"
+ : [c] "=r" (c)
+ : [a] "r" (a), [b] "r" (b)
+ );
+ return c;
+}]], have_mips_dspr2=yes)
+CFLAGS=$xserver_save_CFLAGS
+
+AC_ARG_ENABLE(mips-dspr2,
+ [AC_HELP_STRING([--disable-mips-dspr2],
+ [disable MIPS DSPr2 fast paths])],
+ [enable_mips_dspr2=$enableval], [enable_mips_dspr2=auto])
+
+if test $enable_mips_dspr2 = no ; then
+ have_mips_dspr2=disabled
+fi
+
+if test $have_mips_dspr2 = yes ; then
+ AC_DEFINE(USE_MIPS_DSPR2, 1, [use MIPS DSPr2 assembly optimizations])
+fi
+
+AM_CONDITIONAL(USE_MIPS_DSPR2, test $have_mips_dspr2 = yes)
+
+AC_MSG_RESULT($have_mips_dspr2)
+if test $enable_mips_dspr2 = yes && test $have_mips_dspr2 = no ; then
+ AC_MSG_ERROR([MIPS DSPr2 instructions not detected])
+fi
+
dnl =========================================================================================
dnl Check for GNU-style inline assembly support
diff --git a/pixman/Makefile.am b/pixman/Makefile.am
index 286b7cf..a7fba33 100644
--- a/pixman/Makefile.am
+++ b/pixman/Makefile.am
@@ -102,5 +102,18 @@ libpixman_1_la_LIBADD += libpixman-iwmmxt.la
ASM_CFLAGS_IWMMXT=$(IWMMXT_CFLAGS)
endif
+# mips dspr2 code
+if USE_MIPS_DSPR2
+noinst_LTLIBRARIES += libpixman-mips-dspr2.la
+libpixman_mips_dspr2_la_SOURCES = \
+ pixman-mips-dspr2.c \
+ pixman-mips-dspr2.h
+libpixman_mips_dspr2_la_CFLAGS = $(DEP_CFLAGS)
+libpixman_mips_dspr2_la_LIBADD = $(DEP_LIBS)
+libpixman_1_la_LIBADD += libpixman-mips-dspr2.la
+
+ASM_CFLAGS_mips_dspr2=
+endif
+
.c.s : $(libpixmaninclude_HEADERS) $(BUILT_SOURCES)
$(CC) $(CFLAGS) $(ASM_CFLAGS_$(@:pixman-%.s=%)) $(ASM_CFLAGS_$(@:pixman-arm-%.s=arm_%)) -DHAVE_CONFIG_H -I$(srcdir) -I$(builddir) -I$(top_builddir) -S -o $@ $<
diff --git a/pixman/pixman-cpu.c b/pixman/pixman-cpu.c
index 92942b2..b94f48e 100644
--- a/pixman/pixman-cpu.c
+++ b/pixman/pixman-cpu.c
@@ -427,6 +427,67 @@ pixman_have_arm_iwmmxt (void)
#endif /* USE_ARM_SIMD || USE_ARM_NEON || USE_ARM_IWMMXT */
+#if defined(USE_MIPS_DSPR2)
+
+#if defined (__linux__) /* linux ELF */
+
+pixman_bool_t
+pixman_have_mips_dspr2 (void)
+{
+ const char *search_string = "dsp";
+ const char *file_name = "/proc/cpuinfo";
+ /* Simple detection of MIPS DSP ASE at runtime for Linux.
+ * It is based on /proc/cpuinfo, which reveals hardware
+ * configuration to user-space applications. According to
+ * MIPS (early 2010), no similar facility is universally
+ * available on the MIPS architectures, so it's up to
+ * individual OSes to provide such.
+ *
+ * This is written as a straight shot one pass parser and
+ * not using STL string and ifstream because, on Linux, it's
+ * reading from a (non-mmap-able) character special device.
+ */
+
+ FILE *f = NULL;
+ const char *what = search_string;
+
+ if (NULL == (f = fopen (file_name, "r")))
+ return FALSE;
+
+ int k;
+ while (EOF != (k = fgetc (f)))
+ {
+ if (k == *what)
+ {
+ ++what;
+ while ((*what != '\0') && (*what == fgetc (f)))
+ ++what;
+ if (*what == '\0')
+ {
+ fclose (f);
+ return TRUE;
+ }
+ else
+ {
+ what = search_string;
+ }
+ }
+ }
+
+ fclose (f);
+
+ /* Did not find string in the proc file. */
+ return FALSE;
+}
+
+#else /* linux ELF */
+
+#define pixman_have_mips_dspr2() FALSE
+
+#endif /* linux ELF */
+
+#endif /* USE_MIPS_DSPR2 */
+
#if defined(USE_X86_MMX) || defined(USE_SSE2)
/* The CPU detection code needs to be in a file not compiled with
* "-mmmx -msse", as gcc would generate CMOV instructions otherwise
@@ -696,6 +757,11 @@ _pixman_choose_implementation (void)
imp = _pixman_implementation_create_arm_neon (imp);
#endif
+#ifdef USE_MIPS_DSPR2
+ if (pixman_have_mips_dspr2 ())
+ imp = _pixman_implementation_create_mips_dspr2 (imp);
+#endif
+
#ifdef USE_VMX
if (pixman_have_vmx ())
imp = _pixman_implementation_create_vmx (imp);
diff --git a/pixman/pixman-mips-dspr2.c b/pixman/pixman-mips-dspr2.c
new file mode 100644
index 0000000..518dae1
--- /dev/null
+++ b/pixman/pixman-mips-dspr2.c
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2012
+ * MIPS Technologies, Inc., California.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the MIPS Technologies, Inc., nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE MIPS TECHNOLOGIES, INC. ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE MIPS TECHNOLOGIES, INC. BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * Author: Nemanja Lukic (nlukic at mips.com)
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "pixman-private.h"
+#include "pixman-mips-dspr2.h"
+
+static const pixman_fast_path_t mips_dspr2_fast_paths[] =
+{
+ { PIXMAN_OP_NONE },
+};
+
+pixman_implementation_t *
+_pixman_implementation_create_mips_dspr2 (pixman_implementation_t *fallback)
+{
+ pixman_implementation_t *imp =
+ _pixman_implementation_create (fallback, mips_dspr2_fast_paths);
+
+ return imp;
+}
diff --git a/pixman/pixman-mips-dspr2.h b/pixman/pixman-mips-dspr2.h
new file mode 100644
index 0000000..4c764a8
--- /dev/null
+++ b/pixman/pixman-mips-dspr2.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2012
+ * MIPS Technologies, Inc., California.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the MIPS Technologies, Inc., nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE MIPS TECHNOLOGIES, INC. ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE MIPS TECHNOLOGIES, INC. BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * Author: Nemanja Lukic (nlukic at mips.com)
+ */
+
+#ifndef PIXMAN_MIPS_DSPR2_H
+#define PIXMAN_MIPS_DSPR2_H
+
+#include "pixman-private.h"
+#include "pixman-inlines.h"
+
+#endif //PIXMAN_MIPS_DSPR2_H
diff --git a/pixman/pixman-private.h b/pixman/pixman-private.h
index 8560385..9d96a93 100644
--- a/pixman/pixman-private.h
+++ b/pixman/pixman-private.h
@@ -559,6 +559,11 @@ pixman_implementation_t *
_pixman_implementation_create_arm_neon (pixman_implementation_t *fallback);
#endif
+#ifdef USE_MIPS_DSPR2
+pixman_implementation_t *
+_pixman_implementation_create_mips_dspr2 (pixman_implementation_t *fallback);
+#endif
+
#ifdef USE_VMX
pixman_implementation_t *
_pixman_implementation_create_vmx (pixman_implementation_t *fallback);
--
1.7.3
More information about the Pixman
mailing list