From a245ef38b8854d8de333f3575158046cc115a6ac Mon Sep 17 00:00:00 2001 From: Hans Kristian Rosbach Date: Fri, 11 Sep 2020 21:48:46 +0200 Subject: [PATCH] Make it possible to disable UNALIGNED[64]_OK in cmake. Enable testing with -O3 and unaligned reads disabled. --- .github/workflows/cmake.yml | 14 +++++++--- CMakeLists.txt | 54 ++++++++++++++++++++----------------- README.md | 2 +- 3 files changed, 42 insertions(+), 28 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index f062ddaf..220db70c 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -9,7 +9,8 @@ jobs: matrix: name: [ Ubuntu GCC, - Ubuntu GCC OSB -O1, + Ubuntu GCC OSB -O1 No Unaligned, + Ubuntu GCC -O3 No Unaligned, Ubuntu GCC Link Zlib, Ubuntu GCC No AVX2, Ubuntu GCC No SSE2, @@ -55,15 +56,22 @@ jobs: cmake-args: -DWITH_SANITIZERS=ON codecov: ubuntu_gcc - - name: Ubuntu GCC OSB -O1 + - name: Ubuntu GCC OSB -O1 No Unaligned os: ubuntu-latest compiler: gcc - cmake-args: -DWITH_SANITIZERS=ON + cmake-args: -DWITH_SANITIZERS=ON -DWITH_UNALIGNED=OFF build-dir: ../build build-src-dir: ../zlib-ng codecov: ubuntu_gcc_osb cflags: -O1 -g3 + - name: Ubuntu GCC -O3 No Unaligned + os: ubuntu-latest + compiler: gcc + cmake-args: -DWITH_SANITIZERS=ON -DWITH_UNALIGNED=OFF + codecov: ubuntu_gcc_o3 + cflags: -O3 + - name: Ubuntu GCC Link Zlib os: ubuntu-latest compiler: gcc diff --git a/CMakeLists.txt b/CMakeLists.txt index db1c60ab..4ef0b563 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) if(BASEARCH_ARM_FOUND) option(WITH_ACLE "Build with ACLE" ON) @@ -116,6 +117,7 @@ mark_as_advanced(FORCE WITH_POWER8 WITH_INFLATE_STRICT WITH_INFLATE_ALLOW_INVALID_DIST + WITH_UNALIGNED INSTALL_UTILS ) @@ -266,37 +268,41 @@ if(NOT MSVC AND NOT CMAKE_C_FLAGS MATCHES "([\\/\\-]O)3") endif() # Set architecture alignment requirements -if(BASEARCH_ARM_FOUND OR (BASEARCH_PPC_FOUND AND "${ARCH}" MATCHES "powerpc64le") OR BASEARCH_X86_FOUND) - if(NOT DEFINED UNALIGNED_OK) - set(UNALIGNED_OK TRUE) +if(WITH_UNALIGNED) + if(BASEARCH_ARM_FOUND OR (BASEARCH_PPC_FOUND AND "${ARCH}" MATCHES "powerpc64le") OR BASEARCH_X86_FOUND) + if(NOT DEFINED UNALIGNED_OK) + set(UNALIGNED_OK TRUE) + endif() 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 "(arm(v[8-9])?|aarch64)") - set(UNALIGNED64_OK TRUE) + 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 "(arm(v[8-9])?|aarch64)") + set(UNALIGNED64_OK TRUE) + endif() endif() endif() -endif() -if(BASEARCH_PPC_FOUND) - if(NOT DEFINED UNALIGNED64_OK) - if("${ARCH}" MATCHES "powerpc64le") + 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() -endif() -if(BASEARCH_X86_FOUND) - if(NOT DEFINED UNALIGNED64_OK) - set(UNALIGNED64_OK TRUE) + if(UNALIGNED64_OK) + add_definitions(-DUNALIGNED64_OK) + message(STATUS "Architecture supports unaligned reads of > 4 bytes") endif() -endif() -if(UNALIGNED64_OK) - add_definitions(-DUNALIGNED64_OK) - message(STATUS "Architecture supports unaligned reads of > 4 bytes") +else() + message(STATUS "Unaligned reads manually disabled") endif() # Apply warning compiler flags diff --git a/README.md b/README.md index d1dfa23d..901af078 100644 --- a/README.md +++ b/README.md @@ -191,7 +191,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 | Assume SSE2 instructions are always available | ON (x86), OFF (x86_64) | | WITH_AVX2 | | Build with AVX2 intrinsics | ON | | WITH_SSE2 | | Build with SSE2 intrinsics | ON | @@ -202,6 +201,7 @@ Advanced Build Options | WITH_POWER8 | | Build with POWER8 optimisations | ON | | WITH_DFLTCC_DEFLATE | --with-dfltcc-deflate | Use DEFLATE COMPRESSION CALL instruction for compression on IBM Z | OFF | | WITH_DFLTCC_INFLATE | --with-dfltcc-inflate | Use DEFLATE COMPRESSION CALL instruction 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 | -- 2.47.2