1 diff --git a/configure.ac b/configure.ac 2 --- a/configure.ac 2016-04-27 22:33:47.805069558 -0500 3 +++ b/configure.ac 2016-04-27 22:33:47.829012469 -0500 4 @@ -1,10 +1,13 @@ 5 # configure.ac 6 7 +# Copyright (c) 2016 Google, Inc. 8 +# Written by Mike Klein and Matt Sarett 9 +# Derived from the ARM supporting code in libpng/configure.ac, which was 10 # Copyright (c) 2004-2015 Glenn Randers-Pehrson 11 # Last changed in libpng 1.6.22 [(PENDING RELEASE)] 12 13 # This code is released under the libpng license. 14 # For conditions of distribution and use, see the disclaimer 15 # and license in png.h 16 17 dnl Process this file with autoconf to produce a configure script. 18 @@ -335,16 +338,50 @@ AC_ARG_ENABLE([arm-neon], 19 20 AM_CONDITIONAL([PNG_ARM_NEON], 21 [test "$enable_arm_neon" != 'no' && 22 case "$host_cpu" in 23 arm*|aarch64*) :;; 24 *) test "$enable_arm_neon" != '';; 25 esac]) 26 27 +# INTEL 28 +# ===== 29 +# 30 +# INTEL SSE (SIMD) support. 31 + 32 +AC_ARG_ENABLE([intel-sse], 33 + AS_HELP_STRING([[[--enable-intel-sse]]], 34 + [Enable Intel SSE optimizations: =no/off, yes/on:] 35 + [no/off: disable the optimizations;] 36 + [yes/on: enable the optimizations.] 37 + [If not specified: determined by the compiler.]), 38 + [case "$enableval" in 39 + no|off) 40 + # disable the default enabling: 41 + AC_DEFINE([PNG_INTEL_SSE_OPT], [0], 42 + [Disable Intel SSE optimizations]) 43 + # Prevent inclusion of the assembler files below: 44 + enable_intel_sse=no;; 45 + yes|on) 46 + AC_DEFINE([PNG_INTEL_SSE_OPT], [1], 47 + [Enable Intel SSE optimizations]);; 48 + *) 49 + AC_MSG_ERROR([--enable-intel-sse=${enable_intel_sse}: invalid value]) 50 + esac]) 51 + 52 +# Add Intel specific files to all builds where the host_cpu is Intel ('x86*') 53 +# or where Intel optimizations were explicitly requested (this allows a 54 +# fallback if a future host CPU does not match 'x86*') 55 +AM_CONDITIONAL([PNG_INTEL_SSE], 56 + [test "$enable_intel_sse" != 'no' && 57 + case "$host_cpu" in 58 + i?86|x86_64) :;; 59 + *) test "$enable_intel_sse" != '';; 60 + esac]) 61 AC_MSG_NOTICE([[Extra options for compiler: $PNG_COPTS]]) 62 63 # Config files, substituting as above 64 AC_CONFIG_FILES([Makefile libpng.pc:libpng.pc.in]) 65 AC_CONFIG_FILES([libpng-config:libpng-config.in], 66 [chmod +x libpng-config]) 67 68 AC_OUTPUT 69 diff --git a/Makefile.am b/Makefile.am 70 --- a/Makefile.am 2016-04-27 22:33:47.809928404 -0500 71 +++ b/Makefile.am 2016-04-27 22:33:47.832941146 -0500 72 @@ -1,10 +1,13 @@ 73 # Makefile.am, the source file for Makefile.in (and hence Makefile), is 74 # 75 +# Copyright (c) 2016 Google, Inc. 76 +# Written by Mike Klein and Matt Sarett 77 +# Derived from the ARM supporting code in libpng/configure.ac, which was 78 # Copyright (c) 2004-2016 Glenn Randers-Pehrson 79 # Last changed in libpng 1.6.22 [(PENDING RELEASE)] 80 # 81 # This code is released under the libpng license. 82 # For conditions of distribution and use, see the disclaimer 83 # and license in png.h 84 85 PNGLIB_BASENAME= libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@ 86 @@ -86,16 +89,20 @@ libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SO 87 pngset.c pngtrans.c pngwio.c pngwrite.c pngwtran.c pngwutil.c\ 88 png.h pngconf.h pngdebug.h pnginfo.h pngpriv.h pngstruct.h pngusr.dfa 89 90 if PNG_ARM_NEON 91 libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES += arm/arm_init.c\ 92 arm/filter_neon.S arm/filter_neon_intrinsics.c 93 endif 94 95 +if PNG_INTEL_SSE 96 +libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES += contrib/intel/intel_init.c\ 97 + contrib/intel/filter_sse2_intrinsics.c 98 +endif 99 nodist_libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES = pnglibconf.h 100 101 libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_LDFLAGS = -no-undefined -export-dynamic \ 102 -version-number @PNGLIB_MAJOR@@PNGLIB_MINOR@:@PNGLIB_RELEASE@:0 103 104 if HAVE_LD_VERSION_SCRIPT 105 # Versioned symbols and restricted exports 106 if HAVE_SOLARIS_LD 107 diff --git a/pngpriv.h b/pngpriv.h 108 --- a/pngpriv.h 2016-04-27 22:33:47.800157005 -0500 109 +++ b/pngpriv.h 2016-04-27 22:33:47.838191194 -0500 110 @@ -177,16 +177,52 @@ 111 # endif /* !PNG_ARM_NEON_IMPLEMENTATION */ 112 113 # ifndef PNG_ARM_NEON_IMPLEMENTATION 114 /* Use the intrinsics code by default. */ 115 # define PNG_ARM_NEON_IMPLEMENTATION 1 116 # endif 117 #endif /* PNG_ARM_NEON_OPT > 0 */ 118 119 +#ifndef PNG_INTEL_SSE_OPT 120 +# ifdef PNG_INTEL_SSE 121 + /* Only check for SSE if the build configuration has been modified to 122 + * enable SSE optimizations. This means that these optimizations will 123 + * be off by default. See contrib/intel for more details. 124 + */ 125 +# if defined(__SSE4_1__) || defined(__AVX__) || defined(__SSSE3__) || \ 126 + defined(__SSE2__) || defined(_M_X64) || defined(_M_AMD64) || \ 127 + (defined(_M_IX86_FP) && _M_IX86_FP >= 2) 128 +# define PNG_INTEL_SSE_OPT 1 129 +# endif 130 +# endif 131 +#endif 132 + 133 +#if PNG_INTEL_SSE_OPT > 0 134 +# ifndef PNG_INTEL_SSE_IMPLEMENTATION 135 +# if defined(__SSE4_1__) || defined(__AVX__) 136 + /* We are not actually using AVX, but checking for AVX is the best 137 + way we can detect SSE4.1 and SSSE3 on MSVC. 138 + */ 139 +# define PNG_INTEL_SSE_IMPLEMENTATION 3 140 +# elif defined(__SSSE3__) 141 +# define PNG_INTEL_SSE_IMPLEMENTATION 2 142 +# elif defined(__SSE2__) || defined(_M_X64) || defined(_M_AMD64) || \ 143 + (defined(_M_IX86_FP) && _M_IX86_FP >= 2) 144 +# define PNG_INTEL_SSE_IMPLEMENTATION 1 145 +# else 146 +# define PNG_INTEL_SSE_IMPLEMENTATION 0 147 +# endif 148 +# endif 149 + 150 +# if PNG_INTEL_SSE_IMPLEMENTATION > 0 151 +# define PNG_FILTER_OPTIMIZATIONS png_init_filter_functions_sse2 152 +# endif 153 +#endif 154 + 155 /* Is this a build of a DLL where compilation of the object modules requires 156 * different preprocessor settings to those required for a simple library? If 157 * so PNG_BUILD_DLL must be set. 158 * 159 * If libpng is used inside a DLL but that DLL does not export the libpng APIs 160 * PNG_BUILD_DLL must not be set. To avoid the code below kicking in build a 161 * static library of libpng then link the DLL against that. 162 */ 163 @@ -1184,16 +1220,29 @@ PNG_INTERNAL_FUNCTION(void,png_read_filt 164 row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); 165 PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg4_neon,(png_row_infop 166 row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); 167 PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth3_neon,(png_row_infop 168 row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); 169 PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth4_neon,(png_row_infop 170 row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); 171 172 +PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub3_sse2,(png_row_infop 173 + row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); 174 +PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub4_sse2,(png_row_infop 175 + row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); 176 +PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg3_sse2,(png_row_infop 177 + row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); 178 +PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg4_sse2,(png_row_infop 179 + row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); 180 +PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth3_sse2,(png_row_infop 181 + row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); 182 +PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth4_sse2,(png_row_infop 183 + row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY); 184 + 185 /* Choose the best filter to use and filter the row data */ 186 PNG_INTERNAL_FUNCTION(void,png_write_find_filter,(png_structrp png_ptr, 187 png_row_infop row_info),PNG_EMPTY); 188 189 #ifdef PNG_SEQUENTIAL_READ_SUPPORTED 190 PNG_INTERNAL_FUNCTION(void,png_read_IDAT_data,(png_structrp png_ptr, 191 png_bytep output, png_alloc_size_t avail_out),PNG_EMPTY); 192 /* Read 'avail_out' bytes of data from the IDAT stream. If the output buffer 193