This updates the #if checks for all compilers, but I'm only set up to test with gcc & Sun cc - I've tried not to break the existing Microsoft Visual C & Intel compiler support, but haven't tested that.
-Alan Coopersmith- alan.coopersm...@sun.com Sun Microsystems, Inc. - X Window System Engineering >From 8ff09cc2de04abafcf43f5f988c21aa232bf29ae Mon Sep 17 00:00:00 2001 From: Alan Coopersmith <alan.coopersm...@sun.com> Date: Wed, 1 Apr 2009 15:38:22 -0700 Subject: [PATCH] Fix MMX & SSE intrinsics to work with Sun compilers & Solaris Signed-off-by: Alan Coopersmith <alan.coopersm...@sun.com> --- configure.ac | 30 ++++++++++- pixman/Makefile.am | 2 + pixman/pixman-mmx.c | 113 +++++++++++++++++++++--------------------- pixman/pixman-private.h | 2 +- pixman/solaris-hwcap.mapfile | 36 +++++++++++++ 5 files changed, 122 insertions(+), 61 deletions(-) create mode 100644 pixman/solaris-hwcap.mapfile diff --git a/configure.ac b/configure.ac index 030d063..a683623 100644 --- a/configure.ac +++ b/configure.ac @@ -63,11 +63,16 @@ AM_INIT_AUTOMAKE([dist-bzip2]) AM_CONFIG_HEADER(config.h) +AC_CANONICAL_HOST + AC_PROG_CC AC_PROG_LIBTOOL AC_CHECK_FUNCS([getisax]) AC_C_BIGENDIAN AC_C_INLINE +AC_TYPE_UINT64_T +AC_CHECK_DECL([__SUNPRO_C], [SUNCC="yes"], [SUNCC="no"]) + # # We ignore pixman_major in the version here because the major version should # always be encoded in the actual library name. Ie., the soname is: @@ -141,7 +146,11 @@ AC_MSG_RESULT($have_sunstudio8) dnl =========================================================================== dnl Check for MMX -MMX_CFLAGS="-mmmx -Winline" +if test "x$SUNCC" = "xyes"; then + MMX_CFLAGS="" +else + MMX_CFLAGS="-mmmx -Winline" +fi have_mmx_intrinsics=no AC_MSG_CHECKING(whether to use MMX intrinsics) @@ -183,7 +192,11 @@ AM_CONDITIONAL(USE_MMX, test $have_mmx_intrinsics = yes) dnl =========================================================================== dnl Check for SSE2 -SSE2_CFLAGS="-mmmx -msse2 -Winline" +if test "x$SUNCC" = "xyes"; then + SSE2_CFLAGS="" +else + SSE2_CFLAGS="-mmmx -msse2 -Winline" +fi have_sse2_intrinsics=no AC_MSG_CHECKING(whether to use SSE2 intrinsics) @@ -226,10 +239,21 @@ fi AM_CONDITIONAL(USE_SSE2, test $have_sse2_intrinsics = yes) -dnl ======================================================== +dnl =========================================================================== +dnl Other special flags needed when building code using MMX or SSE instructions +case $host_os in + solaris*) + MMX_LDFLAGS='-Wl,-M,$(srcdir)/solaris-hwcap.mapfile' + SSE2_LDFLAGS="$MMX_LDFLAGS" + ;; +esac + AC_SUBST(MMX_CFLAGS) +AC_SUBST(MMX_LDFLAGS) AC_SUBST(SSE2_CFLAGS) +AC_SUBST(SSE2_LDFLAGS) +dnl =========================================================================== dnl Check for VMX/Altivec if test -n "`$CC -v 2>&1 | grep version | grep Apple`"; then VMX_CFLAGS="-faltivec" diff --git a/pixman/Makefile.am b/pixman/Makefile.am index c4612ea..b8589be 100644 --- a/pixman/Makefile.am +++ b/pixman/Makefile.am @@ -54,6 +54,7 @@ libpixman_mmx_la_SOURCES = \ pixman-mmx.h libpixman_mmx_la_CFLAGS = $(DEP_CFLAGS) $(MMX_CFLAGS) libpixman_mmx_la_LIBADD = $(DEP_LIBS) +libpixman_1_la_LDFLAGS += $(MMX_LDFLAGS) libpixman_1_la_LIBADD += libpixman-mmx.la endif @@ -77,6 +78,7 @@ libpixman_sse2_la_SOURCES = \ pixman-sse2.h libpixman_sse2_la_CFLAGS = $(DEP_CFLAGS) $(SSE2_CFLAGS) libpixman_sse2_la_LIBADD = $(DEP_LIBS) +libpixman_1_la_LDFLAGS += $(SSE2_LDFLAGS) libpixman_1_la_LIBADD += libpixman-sse2.la endif diff --git a/pixman/pixman-mmx.c b/pixman/pixman-mmx.c index caeeafc..71c4aed 100644 --- a/pixman/pixman-mmx.c +++ b/pixman/pixman-mmx.c @@ -35,6 +35,12 @@ #ifdef USE_MMX +#if HAVE_STDINT_H +# include <stdint.h> +#elif HAVE_INTTYPES_H +# include <inttypes.h> +#endif + #include <mmintrin.h> #include "pixman-mmx.h" @@ -71,15 +77,27 @@ * possible. */ -/* --------------- MMX primitivess ------------------------------------ */ +/* --------------- MMX primitives ------------------------------------- */ + +#if defined UINT64_MAX || defined uint64_t /* from autoconf AC_TYPE_UINT64_T */ +typedef uint64_t ullong; +#elif defined _MSC_VER +typedef unsigned __int64 ullong; +#else +# error "No 64-bit unsigned integer type defined" +#endif #ifdef __GNUC__ -typedef unsigned long long ullong; typedef ullong mmxdatafield; -#endif -#ifdef _MSC_VER -typedef unsigned __int64 ullong; +#else typedef __m64 mmxdatafield; +/* If __m64 is defined as a struct or union, define M64_MEMBER to be the + name of the member used to access the data */ +# ifdef _MSC_VER +# define M64_MEMBER m64_u64 +# elif defined(__SUNPRO_C) +# define M64_MEMBER l_ +# endif #endif typedef struct @@ -101,42 +119,31 @@ typedef struct mmxdatafield mmx_000000000000ffff; } MMXData; +#if defined(_MSC_VER) +# define MMXDATA_INIT(field, val) { val##UI64 } +#elif defined(M64_MEMBER) /* __m64 is a struct, not an integral type */ +# define MMXDATA_INIT(field, val) field = { val##ULL } +#else /* __m64 is an integral type */ +# define MMXDATA_INIT(field, val) field = val##ULL +#endif + static const MMXData c = { -#ifdef __GNUC__ - .mmx_4x00ff = 0x00ff00ff00ff00ffULL, - .mmx_4x0080 = 0x0080008000800080ULL, - .mmx_565_rgb = 0x000001f0003f001fULL, - .mmx_565_unpack_multiplier = 0x0000008404100840ULL, - .mmx_565_r = 0x000000f800000000ULL, - .mmx_565_g = 0x0000000000fc0000ULL, - .mmx_565_b = 0x00000000000000f8ULL, - .mmx_mask_0 = 0xffffffffffff0000ULL, - .mmx_mask_1 = 0xffffffff0000ffffULL, - .mmx_mask_2 = 0xffff0000ffffffffULL, - .mmx_mask_3 = 0x0000ffffffffffffULL, - .mmx_full_alpha = 0x00ff000000000000ULL, - .mmx_ffff0000ffff0000 = 0xffff0000ffff0000ULL, - .mmx_0000ffff00000000 = 0x0000ffff00000000ULL, - .mmx_000000000000ffff = 0x000000000000ffffULL, -#endif -#ifdef _MSC_VER - { 0x00ff00ff00ff00ffUI64 }, - { 0x0080008000800080UI64 }, - { 0x000001f0003f001fUI64 }, - { 0x0000008404100840UI64 }, - { 0x000000f800000000UI64 }, - { 0x0000000000fc0000UI64 }, - { 0x00000000000000f8UI64 }, - { 0xffffffffffff0000UI64 }, - { 0xffffffff0000ffffUI64 }, - { 0xffff0000ffffffffUI64 }, - { 0x0000ffffffffffffUI64 }, - { 0x00ff000000000000UI64 }, - { 0xffff0000ffff0000UI64 }, - { 0x0000ffff00000000UI64 }, - { 0x000000000000ffffUI64 }, -#endif + MMXDATA_INIT(.mmx_4x00ff, 0x00ff00ff00ff00ff), + MMXDATA_INIT(.mmx_4x0080, 0x0080008000800080), + MMXDATA_INIT(.mmx_565_rgb, 0x000001f0003f001f), + MMXDATA_INIT(.mmx_565_unpack_multiplier, 0x0000008404100840), + MMXDATA_INIT(.mmx_565_r, 0x000000f800000000), + MMXDATA_INIT(.mmx_565_g, 0x0000000000fc0000), + MMXDATA_INIT(.mmx_565_b, 0x00000000000000f8), + MMXDATA_INIT(.mmx_mask_0, 0xffffffffffff0000), + MMXDATA_INIT(.mmx_mask_1, 0xffffffff0000ffff), + MMXDATA_INIT(.mmx_mask_2, 0xffff0000ffffffff), + MMXDATA_INIT(.mmx_mask_3, 0x0000ffffffffffff), + MMXDATA_INIT(.mmx_full_alpha, 0x00ff000000000000), + MMXDATA_INIT(.mmx_ffff0000ffff0000, 0xffff0000ffff0000), + MMXDATA_INIT(.mmx_0000ffff00000000, 0x0000ffff00000000), + MMXDATA_INIT(.mmx_000000000000ffff, 0x000000000000ffff), }; #ifdef __GNUC__ @@ -145,9 +152,7 @@ static const MMXData c = # else # define MC(x) ((__m64)c.mmx_##x) # endif -#endif - -#ifdef _MSC_VER +#else # define MC(x) c.mmx_##x #endif @@ -156,15 +161,13 @@ M64 (ullong x) { #ifdef __ICC return _mm_cvtsi64_m64 (x); -#elif defined (__GNUC__) - return (__m64)x; -#endif - -#ifdef _MSC_VER +#elif defined M64_MEMBER /* __m64 is a struct, not an integral type */ __m64 res; - res.m64_u64 = x; + res.M64_MEMBER = x; return res; +#else /* __m64 is an integral type */ + return (__m64)x; #endif } @@ -173,15 +176,11 @@ ULLONG (__m64 x) { #ifdef __ICC return _mm_cvtm64_si64 (x); -#elif defined (__GNUC__) - return (ullong)x; -#endif - -#ifdef _MSC_VER - ullong res; - - res = x.m64_u64; +#elif defined M64_MEMBER /* __m64 is a struct, not an integral type */ + ullong res = x.M64_MEMBER; return res; +#else /* __m64 is an integral type */ + return (ullong)x; #endif } @@ -2864,7 +2863,7 @@ pixman_blt_mmx (uint32_t *src_bits, while (w >= 64) { -#ifdef __GNUC__ +#if defined (__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) __asm__ ( "movq (%1), %%mm0\n" "movq 8(%1), %%mm1\n" diff --git a/pixman/pixman-private.h b/pixman/pixman-private.h index 1380fa3..debd723 100644 --- a/pixman/pixman-private.h +++ b/pixman/pixman-private.h @@ -70,7 +70,7 @@ /* 'inline' is available only in C++ in MSVC */ # define inline __inline # define force_inline __forceinline -#elif defined __GNUC__ +#elif defined __GNUC__ || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) # define inline __inline__ # define force_inline __inline__ __attribute__ ((__always_inline__)) #else diff --git a/pixman/solaris-hwcap.mapfile b/pixman/solaris-hwcap.mapfile new file mode 100644 index 0000000..7f439a9 --- /dev/null +++ b/pixman/solaris-hwcap.mapfile @@ -0,0 +1,36 @@ +############################################################################### +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, and/or sell copies of the Software, and to permit persons +# to whom the Software is furnished to do so, provided that the above +# copyright notice(s) and this permission notice appear in all copies of +# the Software and that both the above copyright notice(s) and this +# permission notice appear in supporting documentation. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +# OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR 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. +# +# Except as contained in this notice, the name of a copyright holder +# shall not be used in advertising or otherwise to promote the sale, use +# or other dealings in this Software without prior written authorization +# of the copyright holder. +# +############################################################################### +# +# Override the linker's detection of CMOV/MMX/SSE instructions so this +# library isn't flagged as only usable on CPU's with those ISA's, since it +# checks at runtime for availability before calling them + +hwcap_1 = V0x0 FPU OVERRIDE; -- 1.5.6.5 _______________________________________________ xorg-devel mailing list xorg-devel@lists.x.org http://lists.x.org/mailman/listinfo/xorg-devel