]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Make unaligned access being disabled configurable via build scripts.
authorNathan Moinvaziri <nathan@nathanm.com>
Tue, 15 Mar 2022 01:30:51 +0000 (18:30 -0700)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Thu, 17 Mar 2022 10:03:26 +0000 (11:03 +0100)
.github/workflows/cmake.yml
CMakeLists.txt
README.md
configure
zbuild.h

index 5fdc38a185da4038e78a05db79119361cf119490..a4d05f35e5a6d06d644cbcfaf9e8ae449ffc63e2 100644 (file)
@@ -51,10 +51,11 @@ jobs:
             codecov: ubuntu_gcc_osb
             cflags: -O1 -g3
 
-          - name: Ubuntu GCC -O3
+          - name: Ubuntu GCC -O3 No Unaligned
             os: ubuntu-latest
             compiler: gcc
             cxx-compiler: g++
+            cmake-args: -DWITH_UNALIGNED=OFF
             codecov: ubuntu_gcc_o3
             cflags: -O3
 
index c41428c74f42f642ab319cda527530b779343968..e18a39451fac4bd4e0d99dc6164514c4bf629935 100644 (file)
@@ -87,6 +87,7 @@ option(WITH_MAINTAINER_WARNINGS "Build with project maintainer warnings" OFF)
 option(WITH_CODE_COVERAGE "Enable code coverage reporting" OFF)
 option(WITH_INFLATE_STRICT "Build with strict inflate distance checking" OFF)
 option(WITH_INFLATE_ALLOW_INVALID_DIST "Build with zero fill for inflate invalid distances" OFF)
+option(WITH_UNALIGNED "Support unaligned reads on platforms that support it" ON)
 
 set(ZLIB_SYMBOL_PREFIX "" CACHE STRING "Give this prefix to all publicly exported symbols.
 Useful when embedding into a larger library.
@@ -137,6 +138,7 @@ mark_as_advanced(FORCE
     WITH_POWER8
     WITH_INFLATE_STRICT
     WITH_INFLATE_ALLOW_INVALID_DIST
+    WITH_UNALIGNED
     INSTALL_UTILS
     )
 
@@ -247,6 +249,12 @@ else()
     endif()
 endif()
 
+# Set architecture alignment requirements
+if(NOT WITH_UNALIGNED)
+    add_definitions(-DNO_UNALIGNED)
+    message(STATUS "Unaligned reads manually disabled")
+endif()
+
 # Apply warning compiler flags
 if(WITH_MAINTAINER_WARNINGS)
     add_compile_options(${WARNFLAGS} ${WARNFLAGS_MAINTAINER} ${WARNFLAGS_DISABLE})
index 59899ad5c2554ab86425db66f9a4c8c125395ea9..b0842bc442c3f83715d860ca1778d9201038d030 100644 (file)
--- a/README.md
+++ b/README.md
@@ -211,6 +211,7 @@ Advanced Build Options
 | WITH_CRC32_VX                   | --without-crc32-vx    | Build with vectorized CRC32 on IBM Z                                | ON                     |
 | WITH_DFLTCC_DEFLATE             | --with-dfltcc-deflate | Build with DFLTCC intrinsics for compression on IBM Z               | OFF                    |
 | WITH_DFLTCC_INFLATE             | --with-dfltcc-inflate | Build with DFLTCC intrinsics for decompression on IBM Z             | OFF                    |
+| WITH_UNALIGNED                  | --without-unaligned   | Allow optimizations that use unaligned reads if safe on current arch| ON                     |
 | WITH_INFLATE_STRICT             |                       | Build with strict inflate distance checking                         | OFF                    |
 | WITH_INFLATE_ALLOW_INVALID_DIST |                       | Build with zero fill for inflate invalid distances                  | OFF                    |
 | INSTALL_UTILS                   |                       | Copy minigzip and minideflate during install                        | OFF                    |
index 17bd9fd8b3841f9116477a0ef2d35be893f8c44e..35404ce5b139fda2d78379638bc086feb471026b 100755 (executable)
--- a/configure
+++ b/configure
@@ -86,6 +86,7 @@ mandir=${mandir-'${prefix}/share/man'}
 shared_ext='.so'
 shared=1
 gzfileops=1
+unalignedok=1
 compat=0
 cover=0
 build32=0
@@ -162,7 +163,8 @@ case "$1" in
       echo '    [--warn]                    Enables extra compiler warnings' | tee -a configure.log
       echo '    [--debug]                   Enables extra debug prints during operation' | tee -a configure.log
       echo '    [--zlib-compat]             Compiles for zlib-compatible API instead of zlib-ng API' | tee -a configure.log
-      echo '    [--without-gzfileops]       Compiles with the gzfile parts of the API enabled' | tee -a configure.log
+      echo '    [--without-unaligned]       Compiles without fast unaligned access' | tee -a configure.log
+      echo '    [--without-gzfileops]       Compiles without the gzfile parts of the API enabled' | tee -a configure.log
       echo '    [--without-optimizations]   Compiles without support for optional instruction sets' | tee -a configure.log
       echo '    [--without-new-strategies]  Compiles without using new additional deflate strategies' | tee -a configure.log
       echo '    [--without-acle]            Compiles without ARM C Language Extensions' | tee -a configure.log
@@ -194,6 +196,7 @@ case "$1" in
     -s* | --shared | --enable-shared) shared=1; shift ;;
     -t | --static) shared=0; shift ;;
     --zlib-compat) compat=1; shift ;;
+    --without-unaligned) unalignedok=0; shift ;;
     --without-gzfileops) gzfileops=0; shift ;;
     --cover) cover=1; shift ;;
     -3* | --32) build32=1; shift ;;
@@ -910,6 +913,13 @@ else
   PIC_TESTOBJG="\$(OBJG)"
 fi
 
+# set architecture alignment requirements
+if test $unalignedok -eq 0; then
+  CFLAGS="${CFLAGS} -DNO_UANLIGNED"
+  SFLAGS="${SFLAGS} -DNO_UNALIGNED"
+  echo "Unaligned reads manually disabled." | tee -a configure.log
+fi
+
 # enable reduced memory configuration
 if test $reducedmem -eq 1; then
   echo "Configuring for reduced memory environment." | tee -a configure.log
index 20e3e20e347e4a43f6343bf66a22b64437ffb47f..0513bf0b16bac72ec67417bb0badefca524c7a12 100644 (file)
--- a/zbuild.h
+++ b/zbuild.h
 #  define Tracecv(c, x)
 #endif
 
-#if defined(__x86_64__) || defined(_M_X64) || defined(__amd64__) || defined(_M_AMD64)
-#  define UNALIGNED_OK
-#  define UNALIGNED64_OK
-#elif defined(__i386__) || defined(__i486__) || defined(__i586__) || \
-      defined(__i686__) || defined(_X86_) || defined(_M_IX86)
-#  define UNALIGNED_OK
-#elif defined(__aarch64__) || defined(_M_ARM64)
-#  if (defined(__GNUC__) && defined(__ARM_FEATURE_UNALIGNED)) || !defined(__GNUC__)
+#ifndef NO_UNALIGNED
+#  if defined(__x86_64__) || defined(_M_X64) || defined(__amd64__) || defined(_M_AMD64)
 #    define UNALIGNED_OK
 #    define UNALIGNED64_OK
-#  endif
-#elif defined(__arm__) || (_M_ARM >= 7)
-#  if (defined(__GNUC__) && defined(__ARM_FEATURE_UNALIGNED)) || !defined(__GNUC__)
-#    define UNALIGNED_OK
-#  endif
-#elif defined(__powerpc64__) || defined(__ppc64__)
-#  if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+#  elif defined(__i386__) || defined(__i486__) || defined(__i586__) || \
+        defined(__i686__) || defined(_X86_) || defined(_M_IX86)
 #    define UNALIGNED_OK
-#    define UNALIGNED64_OK
+#  elif defined(__aarch64__) || defined(_M_ARM64)
+#    if (defined(__GNUC__) && defined(__ARM_FEATURE_UNALIGNED)) || !defined(__GNUC__)
+#      define UNALIGNED_OK
+#      define UNALIGNED64_OK
+#    endif
+#  elif defined(__arm__) || (_M_ARM >= 7)
+#    if (defined(__GNUC__) && defined(__ARM_FEATURE_UNALIGNED)) || !defined(__GNUC__)
+#      define UNALIGNED_OK
+#    endif
+#  elif defined(__powerpc64__) || defined(__ppc64__)
+#    if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+#      define UNALIGNED_OK
+#      define UNALIGNED64_OK
+#    endif
 #  endif
 #endif