]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Move UNALIGNED_OK detection to compile time instead of configure time.
authorNathan Moinvaziri <nathan@nathanm.com>
Tue, 18 Jan 2022 02:47:23 +0000 (18:47 -0800)
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
arch/x86/compare256_avx2.c
compare256.c
configure
win32/Makefile.a64
win32/Makefile.arm
win32/Makefile.msc
zbuild.h

index b37c84d35164b1c1a64ce5a6871a2889e6a6459c..5fdc38a185da4038e78a05db79119361cf119490 100644 (file)
@@ -41,21 +41,20 @@ jobs:
             cmake-args: -DZLIB_COMPAT=ON -DZLIB_SYMBOL_PREFIX=zTest_
             codecov: ubuntu_gcc_compat_sprefix
 
-          - name: Ubuntu GCC OSB -O1 No Unaligned64 UBSAN
+          - name: Ubuntu GCC OSB -O1 UBSAN
             os: ubuntu-latest
             compiler: gcc
             cxx-compiler: g++
-            cmake-args: -DWITH_UNALIGNED=ON -DUNALIGNED64_OK=OFF -DWITH_SANITIZER=Undefined
+            cmake-args: -DWITH_SANITIZER=Undefined
             build-dir: ../build
             build-src-dir: ../zlib-ng
             codecov: ubuntu_gcc_osb
             cflags: -O1 -g3
 
-          - name: Ubuntu GCC -O3 No Unaligned
+          - name: Ubuntu GCC -O3
             os: ubuntu-latest
             compiler: gcc
             cxx-compiler: g++
-            cmake-args: -DWITH_UNALIGNED=OFF
             codecov: ubuntu_gcc_o3
             cflags: -O3
 
index 60ccbe25bd09bf7d2a000bc64b173b29bce21355..c41428c74f42f642ab319cda527530b779343968 100644 (file)
@@ -87,7 +87,6 @@ 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.
@@ -138,7 +137,6 @@ mark_as_advanced(FORCE
     WITH_POWER8
     WITH_INFLATE_STRICT
     WITH_INFLATE_ALLOW_INVALID_DIST
-    WITH_UNALIGNED
     INSTALL_UTILS
     )
 
@@ -249,46 +247,6 @@ else()
     endif()
 endif()
 
-# Set architecture alignment requirements
-if(WITH_UNALIGNED)
-    if((BASEARCH_ARM_FOUND AND NOT "${ARCH}" MATCHES "armv[2-7]") OR (BASEARCH_PPC_FOUND AND "${ARCH}" MATCHES "powerpc64le") OR BASEARCH_X86_FOUND)
-        if(NOT DEFINED UNALIGNED_OK)
-            set(UNALIGNED_OK TRUE)
-        endif()
-    endif()
-    if(UNALIGNED_OK)
-        add_definitions(-DUNALIGNED_OK)
-        message(STATUS "Architecture supports unaligned reads")
-    endif()
-    if(BASEARCH_ARM_FOUND)
-        if(NOT DEFINED UNALIGNED64_OK)
-            if("${ARCH}" MATCHES "armv[2-7]")
-                set(UNALIGNED64_OK FALSE)
-            elseif("${ARCH}" MATCHES "(arm(v[8-9])?|aarch64)")
-                set(UNALIGNED64_OK TRUE)
-            endif()
-        endif()
-    endif()
-    if(BASEARCH_PPC_FOUND)
-        if(NOT DEFINED UNALIGNED64_OK)
-            if("${ARCH}" MATCHES "powerpc64le")
-                set(UNALIGNED64_OK TRUE)
-            endif()
-        endif()
-    endif()
-    if(BASEARCH_X86_FOUND)
-        if(NOT DEFINED UNALIGNED64_OK)
-            set(UNALIGNED64_OK TRUE)
-        endif()
-    endif()
-    if(UNALIGNED64_OK)
-        add_definitions(-DUNALIGNED64_OK)
-        message(STATUS "Architecture supports unaligned reads of > 4 bytes")
-    endif()
-else()
-    message(STATUS "Unaligned reads manually disabled")
-endif()
-
 # Apply warning compiler flags
 if(WITH_MAINTAINER_WARNINGS)
     add_compile_options(${WARNFLAGS} ${WARNFLAGS_MAINTAINER} ${WARNFLAGS_DISABLE})
@@ -1459,8 +1417,6 @@ add_feature_info(WITH_MAINTAINER_WARNINGS WITH_MAINTAINER_WARNINGS "Build with p
 add_feature_info(WITH_CODE_COVERAGE WITH_CODE_COVERAGE "Enable code coverage reporting")
 add_feature_info(WITH_INFLATE_STRICT WITH_INFLATE_STRICT "Build with strict inflate distance checking")
 add_feature_info(WITH_INFLATE_ALLOW_INVALID_DIST WITH_INFLATE_ALLOW_INVALID_DIST "Build with zero fill for inflate invalid distances")
-add_feature_info(WITH_UNALIGNED UNALIGNED_OK "Support unaligned reads on platforms that support it")
-add_feature_info(WITH_UNALIGNED64 UNALIGNED64_OK "Support unaligned 64-bit reads on platforms that support it")
 
 if(BASEARCH_ARM_FOUND)
     add_feature_info(WITH_ACLE WITH_ACLE "Build with ACLE")
index 0a801a7ec53bf4f2952dbc76694b2cd57b46f28c..59899ad5c2554ab86425db66f9a4c8c125395ea9 100644 (file)
--- a/README.md
+++ b/README.md
@@ -194,7 +194,6 @@ Advanced Build Options
 | CMake                           | configure             | Description                                                         | Default                |
 |:--------------------------------|:----------------------|:--------------------------------------------------------------------|------------------------|
 | ZLIB_DUAL_LINK                  |                       | Dual link tests with system zlib                                    | OFF                    |
-| UNALIGNED_OK                    |                       | Allow unaligned reads                                               | ON (x86, arm)          |
 | FORCE_SSE2                      | --force-sse2          | Skip runtime check for SSE2 instructions (Always on for x86_64)     | OFF (x86)              |
 | FORCE_TZCNT                     | --force-tzcnt         | Skip runtime check for TZCNT instructions                           | OFF                    |
 | WITH_AVX2                       |                       | Build with AVX2 intrinsics                                          | ON                     |
@@ -212,7 +211,6 @@ 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                  |                       | 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 07f57f2839af148b4be4b72ca1189b92b9c6ca81..e25fa93eb9b49d1058c21ea457a0741814b80a50 100644 (file)
@@ -14,7 +14,7 @@
 #  include <nmmintrin.h>
 #endif
 
-/* UNALIGNED_OK, AVX2 intrinsic comparison */
+/* AVX2 unaligned intrinsic comparison */
 static inline uint32_t compare256_unaligned_avx2_static(const uint8_t *src0, const uint8_t *src1) {
     uint32_t len = 0;
 
index 1b693f274f0ec09ae1f6cf818f861b769e45b1a9..609e6181ae2f1b7d09bf0e15886dccefa01f840b 100644 (file)
@@ -56,7 +56,7 @@ Z_INTERNAL uint32_t compare256_c(const uint8_t *src0, const uint8_t *src1) {
 #include "match_tpl.h"
 
 #ifdef UNALIGNED_OK
-/* UNALIGNED_OK, 16-bit integer comparison */
+/* 16-bit unaligned integer comparison */
 static inline uint32_t compare256_unaligned_16_static(const uint8_t *src0, const uint8_t *src1) {
     uint32_t len = 0;
 
@@ -94,7 +94,7 @@ Z_INTERNAL uint32_t compare256_unaligned_16(const uint8_t *src0, const uint8_t *
 #include "match_tpl.h"
 
 #ifdef HAVE_BUILTIN_CTZ
-/* UNALIGNED_OK, 32-bit integer comparison */
+/* 32-bit unaligned integer comparison */
 static inline uint32_t compare256_unaligned_32_static(const uint8_t *src0, const uint8_t *src1) {
     uint32_t len = 0;
 
index bd237236d632d54f6e7a779304474613fb30f16a..17bd9fd8b3841f9116477a0ef2d35be893f8c44e 100755 (executable)
--- a/configure
+++ b/configure
@@ -1481,9 +1481,6 @@ case "${ARCH}" in
     i386 | i486 | i586 | i686 |x86_64)
         ARCHDIR=arch/x86
 
-        CFLAGS="${CFLAGS} -DUNALIGNED_OK -DUNALIGNED64_OK"
-        SFLAGS="${SFLAGS} -DUNALIGNED_OK -DUNALIGNED64_OK"
-
         # Enable arch-specific optimizations
         if test $without_optimizations -eq 0; then
             CFLAGS="${CFLAGS} -DX86_FEATURES"
@@ -1704,9 +1701,6 @@ EOF
                 fi
             ;;
             armv6l | armv6hl)
-                CFLAGS="${CFLAGS} -DUNALIGNED_OK"
-                SFLAGS="${SFLAGS} -DUNALIGNED_OK"
-
                 if test $without_optimizations -eq 0; then
                     if test $buildacle -eq 1; then
                         echo ACLE support not available
@@ -1718,9 +1712,6 @@ EOF
                 fi
             ;;
             arm | armv7*)
-                CFLAGS="${CFLAGS} -DUNALIGNED_OK"
-                SFLAGS="${SFLAGS} -DUNALIGNED_OK"
-
                 if test $without_optimizations -eq 0; then
                     if test $buildacle -eq 1; then
                         echo ACLE support not available
@@ -1745,9 +1736,6 @@ EOF
                 fi
             ;;
             armv8-a | armv8-a+simd)
-                CFLAGS="${CFLAGS} -DUNALIGNED_OK -DUNALIGNED64_OK"
-                SFLAGS="${SFLAGS} -DUNALIGNED_OK -DUNALIGNED64_OK"
-
                 if test $without_optimizations -eq 0; then
                     if test $buildacle -eq 1; then
                         echo ACLE support not available
@@ -1772,9 +1760,6 @@ EOF
                 fi
             ;;
             armv8-a+crc | armv8-a+crc+simd | armv8.[1234]-a | armv8.[1234]-a+simd)
-                CFLAGS="${CFLAGS} -DUNALIGNED_OK -DUNALIGNED64_OK"
-                SFLAGS="${SFLAGS} -DUNALIGNED_OK -DUNALIGNED64_OK"
-
                 acleflag="-march=${ARCH}"
 
                 if test $without_optimizations -eq 0; then
@@ -1869,9 +1854,6 @@ EOF
 
         neonflag="-march=${ARCH}"
         acleflag="-march=${ARCH}"
-
-        CFLAGS="${CFLAGS} -DUNALIGNED_OK -DUNALIGNED64_OK"
-        SFLAGS="${SFLAGS} -DUNALIGNED_OK -DUNALIGNED64_OK"
     ;;
     powerpc*)
         case "${ARCH}" in
@@ -1883,8 +1865,6 @@ EOF
             ;;
             powerpc64le)
                 [ ! -z $CROSS_PREFIX ] && QEMU_ARCH=ppc64le
-                CFLAGS="${CFLAGS} -DUNALIGNED_OK -DUNALIGNED64_OK"
-                SFLAGS="${SFLAGS} -DUNALIGNED_OK -DUNALIGNED64_OK"
             ;;
         esac
 
index 4df6f3d080e540d7f9c969871cec851e0d4e8a4b..29e66ceed1583066a1f12da9830295d06d40b0cf 100644 (file)
@@ -30,8 +30,6 @@ WFLAGS  = \
        -D_CRT_NONSTDC_NO_DEPRECATE \
        -DARM_NEON_HASLD4 \
        -DARM_FEATURES \
-       -DUNALIGNED_OK \
-       -DUNALIGNED64_OK \
        #
 LDFLAGS = -nologo -debug -incremental:no -opt:ref -manifest
 ARFLAGS = -nologo
index 4cc902888d9b5049f7569c1ce1c3a4d29da70ec5..a43dc59b1ca8b49ea48ced3942290ffd7253a8c3 100644 (file)
@@ -30,7 +30,6 @@ WFLAGS  = \
        -D_CRT_NONSTDC_NO_DEPRECATE \
        -DARM_FEATURES \
        -DARM_NEON_HASLD4 \
-       -DUNALIGNED_OK \
        #
 LDFLAGS = -nologo -debug -incremental:no -opt:ref -manifest
 ARFLAGS = -nologo
index 3d8f1b2e3ed97bd42d336952147e6c9c0bd71f8c..9caa8211c8f3967f36ded238d85790f641bf1b69 100644 (file)
@@ -35,8 +35,6 @@ WFLAGS  = \
        -DX86_AVX2 \
        -DX86_AVX_CHUNKSET \
        -DX86_SSE2_CHUNKSET \
-       -DUNALIGNED_OK \
-       -DUNALIGNED64_OK \
        #
 LDFLAGS = -nologo -debug -incremental:no -opt:ref -manifest
 ARFLAGS = -nologo
index 08bc7ef6123d6bb53d467283ed75056532102fc8..20e3e20e347e4a43f6343bf66a22b64437ffb47f 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__)
+#    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
+
 /* Force compiler to emit unaligned memory accesses if unaligned access is supported
    on the architecture, otherwise don't assume unaligned access is supported. Older
    compilers don't optimize memcpy and memcmp calls to unaligned access instructions