MIPS DSP instruction set extensions --- configure.ac | 40 +++++++++++++++++++++++++++++++ pixman/Makefile.am | 13 ++++++++++ pixman/pixman-cpu.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++ pixman/pixman-mips-dsp.c | 51 ++++++++++++++++++++++++++++++++++++++++ pixman/pixman-mips-dsp.h | 38 ++++++++++++++++++++++++++++++ pixman/pixman-private.h | 5 ++++ 6 files changed, 205 insertions(+), 0 deletions(-) create mode 100644 pixman/pixman-mips-dsp.c create mode 100644 pixman/pixman-mips-dsp.h
diff --git a/configure.ac b/configure.ac index 2eded70..d9b71f9 100644 --- a/configure.ac +++ b/configure.ac @@ -591,6 +591,46 @@ 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..e26d57e 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-dsp.la +libpixman_mips_dsp_la_SOURCES = \ + pixman-mips-dsp.c \ + pixman-mips-dsp.h +libpixman_mips_dsp_la_CFLAGS = $(DEP_CFLAGS) +libpixman_mips_dsp_la_LIBADD = $(DEP_LIBS) +libpixman_1_la_LIBADD += libpixman-mips-dsp.la + +ASM_CFLAGS_mips_dsp= +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 4172e52..c7d36eb 100644 --- a/pixman/pixman-cpu.c +++ b/pixman/pixman-cpu.c @@ -382,6 +382,59 @@ 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_dsp() { + 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_dsp() 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 @@ -651,6 +704,11 @@ _pixman_choose_implementation (void) imp = _pixman_implementation_create_arm_neon (imp); #endif +#ifdef USE_MIPS_DSPR2 + if (pixman_have_mips_dsp ()) + imp = _pixman_implementation_create_mips_dsp (imp); +#endif + #ifdef USE_VMX if (pixman_have_vmx ()) imp = _pixman_implementation_create_vmx (imp); diff --git a/pixman/pixman-mips-dsp.c b/pixman/pixman-mips-dsp.c new file mode 100644 index 0000000..d68ee62 --- /dev/null +++ b/pixman/pixman-mips-dsp.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 (nlu...@mips.com) + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <string.h> +#include "pixman-private.h" +#include "pixman-mips-dsp.h" + +static const pixman_fast_path_t mips_dsp_fast_paths[] = +{ + { PIXMAN_OP_NONE }, +}; + +pixman_implementation_t * +_pixman_implementation_create_mips_dsp (pixman_implementation_t *fallback) +{ + pixman_implementation_t *imp = _pixman_implementation_create (fallback, mips_dsp_fast_paths); + + return imp; +} diff --git a/pixman/pixman-mips-dsp.h b/pixman/pixman-mips-dsp.h new file mode 100644 index 0000000..04e60c4 --- /dev/null +++ b/pixman/pixman-mips-dsp.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 (nlu...@mips.com) + */ + +#ifndef PIXMAN_MIPS_DSP_H__ +#define PIXMAN_MIPS_DSP_H__ + +#include "pixman-private.h" +#include "pixman-inlines.h" + +#endif //PIXMAN_MIPS_DSP_H__ diff --git a/pixman/pixman-private.h b/pixman/pixman-private.h index 1443bfb..227ecff 100644 --- a/pixman/pixman-private.h +++ b/pixman/pixman-private.h @@ -582,6 +582,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_dsp (pixman_implementation_t *fallback); +#endif + #ifdef USE_VMX pixman_implementation_t * _pixman_implementation_create_vmx (pixman_implementation_t *fallback); -- 1.7.1 _______________________________________________ Pixman mailing list Pixman@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/pixman