From 9a308a3344e395e79858716a65296cfb47a81ca1 Mon Sep 17 00:00:00 2001 From: Matt Sarett Date: Wed, 17 Feb 2016 11:43:34 -0500 Subject: [PATCH] Add intel opts to Makefile and configure.ac --- Makefile.am | 5 +++++ configure.ac | 35 ++++++++++++++++++++++++++++++++++ intel/filter_sse2_intrinsics.c | 8 ++++---- intel/intel_init.c | 4 ++-- pngpriv.h | 30 ++++++++++++++++++++--------- 5 files changed, 67 insertions(+), 15 deletions(-) diff --git a/Makefile.am b/Makefile.am index 73097dbcc..646bb236a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -83,6 +83,11 @@ libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES += arm/arm_init.c\ arm/filter_neon.S arm/filter_neon_intrinsics.c endif +if PNG_INTEL_SSE +libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES += intel/intel_init.c\ + intel/filter_sse2_intrinsics.c +endif + nodist_libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES = pnglibconf.h libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_LDFLAGS = -no-undefined -export-dynamic \ diff --git a/configure.ac b/configure.ac index 10538fcc4..66f51261d 100644 --- a/configure.ac +++ b/configure.ac @@ -314,6 +314,41 @@ AM_CONDITIONAL([PNG_ARM_NEON], *) test "$enable_arm_neon" != '';; esac]) +# INTEL +# === +# +# INTEL SSE (SIMD) support. + +AC_ARG_ENABLE([intel-sse], + AS_HELP_STRING([[[--enable-intel-sse]]], + [Enable Intel SSE optimizations: =no/off, yes/on:] + [no/off: disable the optimizations;] + [yes/on: enable the optimizations.] + [If not specified: determined by the compiler.]), + [case "$enableval" in + no|off) + # disable the default enabling: + AC_DEFINE([PNG_INTEL_SSE_OPT], [0], + [Disable Intel SSE optimizations]) + # Prevent inclusion of the assembler files below: + enable_intel_sse=no;; + yes|on) + AC_DEFINE([PNG_INTEL_SSE_OPT], [1], + [Enable Intel SSE optimizations]);; + *) + AC_MSG_ERROR([--enable-intel-sse=${enable_intel_sse}: invalid value]) + esac]) + +# Add Intel specific files to all builds where the host_cpu is Intel ('x86*') +# or where Intel optimizations were explicitly requested (this allows a +# fallback if a future host CPU does not match 'x86*') +AM_CONDITIONAL([PNG_INTEL_SSE], + [test "$enable_intel_sse" != 'no' && + case "$host_cpu" in + x86*) :;; + *) test "$enable_intel_sse" != '';; + esac]) + AC_MSG_NOTICE([[Extra options for compiler: $PNG_COPTS]]) # Config files, substituting as above diff --git a/intel/filter_sse2_intrinsics.c b/intel/filter_sse2_intrinsics.c index 9e7484923..3bfdf5dd5 100644 --- a/intel/filter_sse2_intrinsics.c +++ b/intel/filter_sse2_intrinsics.c @@ -12,7 +12,7 @@ #ifdef PNG_READ_SUPPORTED -#if PNG_INTEL_SSE_OPT > 0 +#if PNG_INTEL_SSE_IMPLEMENTATION > 0 #include @@ -144,7 +144,7 @@ void png_read_filter_row_avg4_sse2(png_row_infop row_info, png_bytep row, // Returns |x| for 16-bit lanes. static __m128i abs_i16(__m128i x) { -#if PNG_INTEL_SSE_OPT >= 2 +#if PNG_INTEL_SSE_IMPLEMENTATION >= 2 return _mm_abs_epi16(x); #else // Read this all as, return x<0 ? -x : x. @@ -162,7 +162,7 @@ static __m128i abs_i16(__m128i x) { // Bytewise c ? t : e. static __m128i if_then_else(__m128i c, __m128i t, __m128i e) { -#if PNG_INTEL_SSE_OPT >= 3 +#if PNG_INTEL_SSE_IMPLEMENTATION >= 3 return _mm_blendv_epi8(e,t,c); #else return _mm_or_si128(_mm_and_si128(c, t), _mm_andnot_si128(c, e)); @@ -281,5 +281,5 @@ void png_read_filter_row_paeth4_sse2(png_row_infop row_info, png_bytep row, } } -#endif /* PNG_INTEL_SSE_OPT > 0 */ +#endif /* PNG_INTEL_SSE_IMPLEMENTATION > 0 */ #endif /* READ */ diff --git a/intel/intel_init.c b/intel/intel_init.c index 8616b53f1..394984e06 100644 --- a/intel/intel_init.c +++ b/intel/intel_init.c @@ -11,7 +11,7 @@ #include "../pngpriv.h" #ifdef PNG_READ_SUPPORTED -#if PNG_INTEL_SSE_OPT > 0 +#if PNG_INTEL_SSE_IMPLEMENTATION > 0 void png_init_filter_functions_sse2(png_structp pp, unsigned int bpp) @@ -41,5 +41,5 @@ png_init_filter_functions_sse2(png_structp pp, unsigned int bpp) // No need optimize PNG_FILTER_VALUE_UP. The compiler should autovectorize. } -#endif /* PNG_INTEL_SSE_OPT > 0 */ +#endif /* PNG_INTEL_SSE_IMPLEMENTATION > 0 */ #endif /* PNG_READ_SUPPORTED */ diff --git a/pngpriv.h b/pngpriv.h index f5c02de42..a402704f8 100644 --- a/pngpriv.h +++ b/pngpriv.h @@ -183,21 +183,33 @@ #endif /* PNG_ARM_NEON_OPT > 0 */ #ifndef PNG_INTEL_SSE_OPT -# if defined(__SSE4_1__) || defined(__AVX__) - /* We are not actually using AVX, but checking for AVX is the best - way we can detect SSE4.1 and SSSE3 on MSVC. - */ -# define PNG_INTEL_SSE_OPT 3 -# elif defined(__SSSE3__) -# define PNG_INTEL_SSE_OPT 2 -# elif defined(__SSE2__) || defined(_M_X64) || defined(_M_AMD64) || \ +# if defined(__SSE4_1__) || defined(__AVX__) || defined(__SSSE3__) || \ + defined(__SSE2__) || defined(_M_X64) || defined(_M_AMD64) || \ (defined(_M_IX86_FP) && _M_IX86_FP >= 2) # define PNG_INTEL_SSE_OPT 1 # endif #endif #if PNG_INTEL_SSE_OPT > 0 -# define PNG_FILTER_OPTIMIZATIONS png_init_filter_functions_sse2 +# ifndef PNG_INTEL_SSE_IMPLEMENTATION +# if defined(__SSE4_1__) || defined(__AVX__) + /* We are not actually using AVX, but checking for AVX is the best + way we can detect SSE4.1 and SSSE3 on MSVC. + */ +# define PNG_INTEL_SSE_IMPLEMENTATION 3 +# elif defined(__SSSE3__) +# define PNG_INTEL_SSE_IMPLEMENTATION 2 +# elif defined(__SSE2__) || defined(_M_X64) || defined(_M_AMD64) || \ + (defined(_M_IX86_FP) && _M_IX86_FP >= 2) +# define PNG_INTEL_SSE_IMPLEMENTATION 1 +# else +# define PNG_INTEL_SSE_IMPLEMENTATION 0 +# endif +# endif + +# if PNG_INTEL_SSE_IMPLEMENTATION > 0 +# define PNG_FILTER_OPTIMIZATIONS png_init_filter_functions_sse2 +# endif #endif /* Is this a build of a DLL where compilation of the object modules requires