1diff --git a/configure.ac b/configure.ac 2--- a/configure.ac 2016-08-29 11:46:27.000000000 -0400 3+++ b/configure.ac 2016-08-29 16:57:03.866355018 -0400 4@@ -386,16 +386,51 @@ AC_ARG_ENABLE([mips-msa], 5 # future host CPU does not match 'mips*') 6 7 AM_CONDITIONAL([PNG_MIPS_MSA], 8 [test "$enable_mips_msa" != 'no' && 9 case "$host_cpu" in 10 mipsel*|mips64el*) :;; 11 esac]) 12 13+# INTEL 14+# ===== 15+# 16+# INTEL SSE (SIMD) support. 17+ 18+AC_ARG_ENABLE([intel-sse], 19+ AS_HELP_STRING([[[--enable-intel-sse]]], 20+ [Enable Intel SSE optimizations: =no/off, yes/on:] 21+ [no/off: disable the optimizations;] 22+ [yes/on: enable the optimizations.] 23+ [If not specified: determined by the compiler.]), 24+ [case "$enableval" in 25+ no|off) 26+ # disable the default enabling: 27+ AC_DEFINE([PNG_INTEL_SSE_OPT], [0], 28+ [Disable Intel SSE optimizations]) 29+ # Prevent inclusion of the assembler files below: 30+ enable_intel_sse=no;; 31+ yes|on) 32+ AC_DEFINE([PNG_INTEL_SSE_OPT], [1], 33+ [Enable Intel SSE optimizations]);; 34+ *) 35+ AC_MSG_ERROR([--enable-intel-sse=${enable_intel_sse}: invalid value]) 36+ esac]) 37+ 38+# Add Intel specific files to all builds where the host_cpu is Intel ('x86*') 39+# or where Intel optimizations were explicitly requested (this allows a 40+# fallback if a future host CPU does not match 'x86*') 41+AM_CONDITIONAL([PNG_INTEL_SSE], 42+ [test "$enable_intel_sse" != 'no' && 43+ case "$host_cpu" in 44+ i?86|x86_64) :;; 45+ *) test "$enable_intel_sse" != '';; 46+ esac]) 47+ 48 AC_MSG_NOTICE([[Extra options for compiler: $PNG_COPTS]]) 49 50 # Config files, substituting as above 51 AC_CONFIG_FILES([Makefile libpng.pc:libpng.pc.in]) 52 AC_CONFIG_FILES([libpng-config:libpng-config.in], 53 [chmod +x libpng-config]) 54 55 AC_OUTPUT 56diff --git a/Makefile.am b/Makefile.am 57--- a/Makefile.am 2016-08-29 11:46:27.000000000 -0400 58+++ b/Makefile.am 2016-08-29 16:57:45.955528215 -0400 59@@ -97,16 +97,21 @@ libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SO 60 arm/filter_neon.S arm/filter_neon_intrinsics.c 61 endif 62 63 if PNG_MIPS_MSA 64 libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES += mips/mips_init.c\ 65 mips/filter_msa_intrinsics.c 66 endif 67 68+if PNG_INTEL_SSE 69+libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES += contrib/intel/intel_init.c\ 70+ contrib/intel/filter_sse2_intrinsics.c 71+endif 72+ 73 nodist_libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES = pnglibconf.h 74 75 libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_LDFLAGS = -no-undefined -export-dynamic \ 76 -version-number @PNGLIB_MAJOR@@PNGLIB_MINOR@:@PNGLIB_RELEASE@:0 77 78 if HAVE_LD_VERSION_SCRIPT 79 # Versioned symbols and restricted exports 80 if HAVE_SOLARIS_LD 81diff --git a/pngpriv.h b/pngpriv.h 82--- debug16/pngpriv.h 2016-08-30 10:46:36.000000000 -0400 83+++ libpng16/pngpriv.h 2016-08-30 11:57:25.672280202 -0400 84@@ -185,16 +185,52 @@ 85 #ifndef PNG_MIPS_MSA_OPT 86 # if defined(__mips_msa) && (__mips_isa_rev >= 5) && defined(PNG_ALIGNED_MEMORY_SUPPORTED) 87 # define PNG_MIPS_MSA_OPT 2 88 # else 89 # define PNG_MIPS_MSA_OPT 0 90 # endif 91 #endif 92 93+#ifndef PNG_INTEL_SSE_OPT 94+# ifdef PNG_INTEL_SSE 95+ /* Only check for SSE if the build configuration has been modified to 96+ * enable SSE optimizations. This means that these optimizations will 97+ * be off by default. See contrib/intel for more details. 98+ */ 99+# if defined(__SSE4_1__) || defined(__AVX__) || defined(__SSSE3__) || \ 100+ defined(__SSE2__) || defined(_M_X64) || defined(_M_AMD64) || \ 101+ (defined(_M_IX86_FP) && _M_IX86_FP >= 2) 102+# define PNG_INTEL_SSE_OPT 1 103+# endif 104+# endif 105+#endif 106+ 107+#if PNG_INTEL_SSE_OPT > 0 108+# ifndef PNG_INTEL_SSE_IMPLEMENTATION 109+# if defined(__SSE4_1__) || defined(__AVX__) 110+ /* We are not actually using AVX, but checking for AVX is the best 111+ way we can detect SSE4.1 and SSSE3 on MSVC. 112+ */ 113+# define PNG_INTEL_SSE_IMPLEMENTATION 3 114+# elif defined(__SSSE3__) 115+# define PNG_INTEL_SSE_IMPLEMENTATION 2 116+# elif defined(__SSE2__) || defined(_M_X64) || defined(_M_AMD64) || \ 117+ (defined(_M_IX86_FP) && _M_IX86_FP >= 2) 118+# define PNG_INTEL_SSE_IMPLEMENTATION 1 119+# else 120+# define PNG_INTEL_SSE_IMPLEMENTATION 0 121+# endif 122+# endif 123+ 124+# if PNG_INTEL_SSE_IMPLEMENTATION > 0 125+# define PNG_FILTER_OPTIMIZATIONS png_init_filter_functions_sse2 126+# endif 127+#endif 128+ 129 #if PNG_MIPS_MSA_OPT > 0 130 # define PNG_FILTER_OPTIMIZATIONS png_init_filter_functions_msa 131 # ifndef PNG_MIPS_MSA_IMPLEMENTATION 132 # if defined(__mips_msa) 133 # if defined(__clang__) 134 # elif defined(__GNUC__) 135 # if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 7) 136 # define PNG_MIPS_MSA_IMPLEMENTATION 2 137@@ -1232,16 +1268,31 @@ PNG_INTERNAL_FUNCTION(void,png_read_filt 138 PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg4_msa,(png_row_infop 139 row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); 140 PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth3_msa,(png_row_infop 141 row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); 142 PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth4_msa,(png_row_infop 143 row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); 144 #endif 145 146+#if PNG_INTEL_SSE_IMPLEMENTATION > 0 147+PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub3_sse2,(png_row_infop 148+ row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); 149+PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub4_sse2,(png_row_infop 150+ row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); 151+PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg3_sse2,(png_row_infop 152+ row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); 153+PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg4_sse2,(png_row_infop 154+ row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); 155+PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth3_sse2,(png_row_infop 156+ row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); 157+PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth4_sse2,(png_row_infop 158+ row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); 159+#endif 160+ 161 /* Choose the best filter to use and filter the row data */ 162 PNG_INTERNAL_FUNCTION(void,png_write_find_filter,(png_structrp png_ptr, 163 png_row_infop row_info),PNG_EMPTY); 164 165 #ifdef PNG_SEQUENTIAL_READ_SUPPORTED 166 PNG_INTERNAL_FUNCTION(void,png_read_IDAT_data,(png_structrp png_ptr, 167 png_bytep output, png_alloc_size_t avail_out),PNG_EMPTY); 168 /* Read 'avail_out' bytes of data from the IDAT stream. If the output buffer 169@@ -1967,16 +2018,21 @@ PNG_INTERNAL_FUNCTION(void, PNG_FILTER_O 170 PNG_INTERNAL_FUNCTION(void, png_init_filter_functions_neon, 171 (png_structp png_ptr, unsigned int bpp), PNG_EMPTY); 172 #endif 173 174 #if PNG_MIPS_MSA_OPT > 0 175 PNG_INTERNAL_FUNCTION(void, png_init_filter_functions_msa, 176 (png_structp png_ptr, unsigned int bpp), PNG_EMPTY); 177 #endif 178+ 179+# if PNG_INTEL_SSE_IMPLEMENTATION > 0 180+PNG_INTERNAL_FUNCTION(void, png_init_filter_functions_sse2, 181+ (png_structp png_ptr, unsigned int bpp), PNG_EMPTY); 182+# endif 183 #endif 184 185 PNG_INTERNAL_FUNCTION(png_uint_32, png_check_keyword, (png_structrp png_ptr, 186 png_const_charp key, png_bytep new_key), PNG_EMPTY); 187 188 /* Maintainer: Put new private prototypes here ^ */ 189 190 #include "pngdebug.h" 191