Skip to content

Commit

Permalink
Squashed 'src/snappy/' changes from 537f4ad6..2b63814b
Browse files Browse the repository at this point in the history
2b63814b Tag open source release 1.1.9.
9c1be179 'size' remains unused if none of ZLIB, LZO and LZ4 are available.
78650d12 Add project goals to CONTRIBUTING.md.
5e7c14bd Add stubs for abseil flags.
80a2a10c Remove unused run_microbenchmarks flag.
453942b3 Add absl::GetFlag and absl::SetFlag to uses of flags.
ea368c2f Add AppVeyor status badge.
d1d1f486 Remove unused include in snappy_benchmark.cc.
4ebd8b2f Split benchmarks and test tools into separate targets.
0793e2ae Merge pull request silx-kit#117 from cmumford:disable-osx-fuzzer
ac55f842 Test stub improvements.
6e9ae724 Disable fuzzing on OSX.
402d8881 Fixup for adding the third_party/{benchmark, googletest} submodules. (silx-kit#115)
6badb0a2 Merge pull request silx-kit#114 from cmumford:werror-only-clang
bc53daa7 Fixed endif clause.
e9a6a084 Matching clang.
955a5dd1 Building with `-Werror` only with clang.
42d1dd7e Fix CHECK_EQ to call ok() instead of CheckSuccess().
eaaa0ed0 Fixup for adding the third_party/{benchmark, googletest} submodules. (silx-kit#111)
e1e91ee4 Rework file:: stubs.
6aa79cb4 Wrap snappy_unittest in an anonymous namespace and remove static from functions.
bae9f9be Fixup for adding the third_party/{benchmark, googletest} submodules. (silx-kit#110)
5f913be0 Fix unused local variable warnings.
549685a5 Remove custom testing and benchmarking code.
11f9a77a Add Travis-CI build status badge to README.md.
49540965 Update Travis CI config.
8995ffab Replace #pragma nounroll with equivalent used elsewhere.
d1daa830 Remove inline qualifier from static variables.
3b571656 1) Improve the lookup table data to require less instructions to extract the necessary data. We now store len - offset in a signed int16, this happens to remove masking offset in the calculations and the calculations that need to be done precisely give the flags that we need for testing correctness. 2) Replace offset extraction with a lookup mask. This is less uops and is needed because we need to special case type 3 to always return 0 as to properly trigger the fallback. 3) Unroll the loop twice, this removes some loop-condition checks AND it improves the generated assembly. The loop variables tend to end up in a different register requiring mov's having two consecutive copies allows the elision of the mov's.
a9730ed5 Optimize zippy decompression by making IncrementalCopy faster.
56c2c247 Internal change
a94be58e Optimize zippy decompression by making IncrementalCopy faster.
01a566f8 Fix opensource version
616b8229 Add LZ4 as a benchmark option. Snappy is starting to look really good compared to LZ4. LZ4 is considered the fastest solution by many on internet. We now see that Snappy is actually becoming very competitive with compression a little faster and decompression slower but certainly not terribly slower.
e4a6e97b Extend validate benchmarks over all types and also add a medley for validation.
719bed0a Bug fix. Error on 0 offset copies.
289c8a3c Make zippy decompression branchless
3bfa265a Revert zippy optimization that causes heap buffer overflows.
4d2dc9dc Optimize zippy unzipping by upto >10% by making IncrementalCopy faster.
11e5165b Add a benchmark that decreased the branch prediction memorization by increasing the amount of independent branches executed per benchmark iteration.
6835abd9 Change hash function for Compress.
368b01c8 Merge pull request silx-kit#107 from jsteemann:bug-fix/fix-compile-warning
1ce58af2 Fix the use of op + len when op is nullptr and len is non-zero. See https://reviews.llvm.org/D67122 for some discussion of why this can matter. I don't think this should have any noticeable effect on performance.
0b990db2 Run clang-format
cb2b3c7e fix compile warnings due to missing override specifiers
7ffaf77c Replace ARCH_K8 with __x86_64__.
4dd277fe Replace the division with a constant table in IncrementalCopy
f16eda34 Correct uninitialized variable.
837f38b3 Revise stubs for ARCH_{K8,PPC,ARM}.
e1353b9f Remove ARCH_* guards around Bits::FindLSBSetNonZero64().
c98344f6 Fix Clang/GCC compilation warnings.
113cd97a Tighten types on a few for loops.
abde3abb Fix Travis CI build.
e6506681 Fix accidental double std:: qualifiers.
63620c06 Add some std:: qualifiers to types and functions.
5417da69 Switch from C headers to C++ headers.
251d935d Remove #include <string> from snappy-stubs-public.h.
4f195aee Remove mismatched #endif.
041c6080 Remove platform-dependent code for unaligned loads/stores.
27ff130f Remove platform-dependent code for little-endian loads and stores.
a4cdb5d1 Introduce SNAPPY_ATTRIBUTE_ALWAYS_INLINE.
231b8be0 Migrate to standard integral types.
14bef662 Modernize memcpy() and memmove() usage.
d674348a Improve zippy with 5-10%.
4dfcad9f assertion failure on darwin_x86_64, have to investigage
e1917874 assertion failure on darwin_x86_64, have to investigage
0faf5637 This cl does two things 1) It shaves of a few cycles from the data dependency chain. By using "shrd" instead of a load. 2) The important loop is finding small copies (4-12) which are either "copy 1", or "copy 2" depending if the offset fits <2048. It turns out that this is a branch that is mispredicted often. Due to the long dependency chain the CPU is running with IPC~1 anyway so we can freely add instructions to instead emit copies branchfree. This reduces the branch misspredicts from 15% to 11% (for BM_ZFlat/6 txt1) and from 5.6% to 4% (for BM_ZFlat/10 or pb).
0c7ed08a The result on protobuf benchmark is around 19%. Results vary by their propensity for compression. As the frequency of finding matches influences the amount of branch misspredicts and the amount of hashing.
3c77e014 1) Make the output pointer a local variable such it doesn't need a load add store on it's loop carried dependency chain. 2) Reduce the input pointer loop carried dependency chain from 7 cycles to 4 cycles by using pre-loading. This is a very subtle point. 3) Just brutally copy 64 bytes which removes a difficult to predict branch from the inner most loop. There is enough bandwidth to do so in the intrinsic cycles of the loop. 4) Implement limit pointers that include the slop region. This removes unnecessary instructions from the hot path. 5) It seems the removal of the difficult to predict branch has removed the code sensitivity to alignment, so remove the asm nop's.
9eabb7ba Cut a load from the critical dependency chain of the input pointer by speculating the uncommon case of COPY_4 is not happening.
cddd9c08 Improve comments in IncrementalCopy, add an assert.

git-subtree-dir: src/snappy
git-subtree-split: 2b63814b15a2aaae54b7943f0cd935892fae628f
  • Loading branch information
t20100 committed Oct 21, 2022
1 parent 026eaa9 commit 694d216
Show file tree
Hide file tree
Showing 27 changed files with 2,679 additions and 1,944 deletions.
1 change: 1 addition & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ build_script:

test_script:
- build\%CONFIGURATION%\snappy_unittest
- build\%CONFIGURATION%\snappy_benchmark
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "third_party/benchmark"]
path = third_party/benchmark
url = https://github.com/google/benchmark.git
[submodule "third_party/googletest"]
path = third_party/googletest
url = https://github.com/google/googletest.git
28 changes: 17 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

language: cpp
dist: bionic
osx_image: xcode10.3
osx_image: xcode12.2

compiler:
- gcc
Expand All @@ -19,32 +19,36 @@ env:
- BUILD_TYPE=RelWithDebInfo CPU_LEVEL=AVX
- BUILD_TYPE=RelWithDebInfo CPU_LEVEL=AVX2

matrix:
jobs:
exclude:
# Travis OSX servers seem to run on pre-Haswell CPUs. Attempting to use AVX2
# results in crashes.
- env: BUILD_TYPE=Debug CPU_LEVEL=AVX2
os: osx
- env: BUILD_TYPE=RelWithDebInfo CPU_LEVEL=AVX2
os: osx
allow_failures:
# Homebrew's GCC is currently broken on XCode 11.
- compiler: gcc
os: osx

addons:
apt:
sources:
- sourceline: 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-9 main'
- sourceline: 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-10 main'
key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key'
- sourceline: 'ppa:ubuntu-toolchain-r/test'
packages:
- clang-9
- clang-10
- cmake
- gcc-9
- g++-9
- gcc-10
- g++-10
- ninja-build
homebrew:
packages:
- cmake
- gcc@9
- llvm@9
- gcc@10
- llvm@10
- ninja
update: true

Expand All @@ -55,20 +59,21 @@ install:
export PATH="$(brew --prefix llvm)/bin:$PATH";
fi
# Fuzzing is only supported on Clang. Perform fuzzing on Debug builds.
- if [ "$CXX" = "clang++" ] && [ "$BUILD_TYPE" = "Debug" ]; then
# LibFuzzer doesn't ship with CommandLineTools on osx.
- if [ "$CXX" = "clang++" ] && [ "$BUILD_TYPE" = "Debug" ] && [ "$TRAVIS_OS_NAME" != "osx" ]; then
export FUZZING=1;
else
export FUZZING=0;
fi
# /usr/bin/gcc points to an older compiler on both Linux and macOS.
- if [ "$CXX" = "g++" ]; then export CXX="g++-9" CC="gcc-9"; fi
- if [ "$CXX" = "g++" ]; then export CXX="g++-10" CC="gcc-10"; fi
# /usr/bin/clang points to an older compiler on both Linux and macOS.
#
# Homebrew's llvm package doesn't ship a versioned clang++ binary, so the values
# below don't work on macOS. Fortunately, the path change above makes the
# default values (clang and clang++) resolve to the correct compiler on macOS.
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then
if [ "$CXX" = "clang++" ]; then export CXX="clang++-9" CC="clang-9"; fi;
if [ "$CXX" = "clang++" ]; then export CXX="clang++-10" CC="clang-10"; fi;
fi
- echo ${CC}
- echo ${CXX}
Expand All @@ -85,6 +90,7 @@ before_script:

script:
- build/snappy_unittest
- build/snappy_benchmark
- if [ -f build/snappy_compress_fuzzer ]; then
build/snappy_compress_fuzzer -runs=1000 -close_fd_mask=3;
fi
Expand Down
155 changes: 128 additions & 27 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

cmake_minimum_required(VERSION 3.1)
project(Snappy VERSION 1.1.8 LANGUAGES C CXX)
project(Snappy VERSION 1.1.9 LANGUAGES C CXX)

# C++ standard can be overridden when this is used as a sub-project.
if(NOT CMAKE_CXX_STANDARD)
Expand All @@ -37,12 +37,59 @@ if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_EXTENSIONS OFF)
endif(NOT CMAKE_CXX_STANDARD)

# https://github.com/izenecloud/cmake/blob/master/SetCompilerWarningAll.cmake
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
# Use the highest warning level for Visual Studio.
set(CMAKE_CXX_WARNING_LEVEL 4)
if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
else(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
endif(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")

# Disable C++ exceptions.
string(REGEX REPLACE "/EH[a-z]+" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHs-c-")
add_definitions(-D_HAS_EXCEPTIONS=0)

# Disable RTTI.
string(REGEX REPLACE "/GR" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-")
else(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
# Use -Wall for clang and gcc.
if(NOT CMAKE_CXX_FLAGS MATCHES "-Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
endif(NOT CMAKE_CXX_FLAGS MATCHES "-Wall")

# Use -Wextra for clang and gcc.
if(NOT CMAKE_CXX_FLAGS MATCHES "-Wextra")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra")
endif(NOT CMAKE_CXX_FLAGS MATCHES "-Wextra")

# Use -Werror for clang only.
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if(NOT CMAKE_CXX_FLAGS MATCHES "-Werror")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
endif(NOT CMAKE_CXX_FLAGS MATCHES "-Werror")
endif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")

# Disable C++ exceptions.
string(REGEX REPLACE "-fexceptions" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions")

# Disable RTTI.
string(REGEX REPLACE "-frtti" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
endif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")

# BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to make
# it prominent in the GUI.
option(BUILD_SHARED_LIBS "Build shared libraries(DLLs)." OFF)

option(SNAPPY_BUILD_TESTS "Build Snappy's own tests." ON)

option(SNAPPY_BUILD_BENCHMARKS "Build Snappy's benchmarks" ON)

option(SNAPPY_FUZZING_BUILD "Build Snappy for fuzzing." OFF)

option(SNAPPY_REQUIRE_AVX "Target processors with AVX support." OFF)
Expand All @@ -55,8 +102,6 @@ include(TestBigEndian)
test_big_endian(SNAPPY_IS_BIG_ENDIAN)

include(CheckIncludeFile)
check_include_file("byteswap.h" HAVE_BYTESWAP_H)
check_include_file("sys/endian.h" HAVE_SYS_ENDIAN_H)
check_include_file("sys/mman.h" HAVE_SYS_MMAN_H)
check_include_file("sys/resource.h" HAVE_SYS_RESOURCE_H)
check_include_file("sys/time.h" HAVE_SYS_TIME_H)
Expand All @@ -67,6 +112,7 @@ check_include_file("windows.h" HAVE_WINDOWS_H)
include(CheckLibraryExists)
check_library_exists(z zlibVersion "" HAVE_LIBZ)
check_library_exists(lzo2 lzo1x_1_15_compress "" HAVE_LIBLZO2)
check_library_exists(lz4 LZ4_compress_default "" HAVE_LIBLZ4)

include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("/arch:AVX" HAVE_VISUAL_STUDIO_ARCH_AVX)
Expand All @@ -92,6 +138,10 @@ elseif (SNAPPY_REQUIRE_AVX)
endif(HAVE_CLANG_MAVX)
endif(SNAPPY_REQUIRE_AVX2)

# Used by googletest.
check_cxx_compiler_flag(-Wno-missing-field-initializers
SNAPPY_HAVE_NO_MISSING_FIELD_INITIALIZERS)

include(CheckCXXSourceCompiles)
check_cxx_source_compiles("
int main() {
Expand All @@ -103,6 +153,13 @@ int main() {
return __builtin_ctzll(0);
}" HAVE_BUILTIN_CTZ)

check_cxx_source_compiles("
__attribute__((always_inline)) int zero() { return 0; }
int main() {
return zero();
}" HAVE_ATTRIBUTE_ALWAYS_INLINE)

check_cxx_source_compiles("
#include <tmmintrin.h>
Expand All @@ -125,16 +182,6 @@ include(CheckSymbolExists)
check_symbol_exists("mmap" "sys/mman.h" HAVE_FUNC_MMAP)
check_symbol_exists("sysconf" "unistd.h" HAVE_FUNC_SYSCONF)

find_package(GTest QUIET)
if(GTEST_FOUND)
set(HAVE_GTEST 1)
endif(GTEST_FOUND)

find_package(Gflags QUIET)
if(GFLAGS_FOUND)
set(HAVE_GFLAGS 1)
endif(GFLAGS_FOUND)

configure_file(
"cmake/config.h.in"
"${PROJECT_BINARY_DIR}/config.h"
Expand Down Expand Up @@ -202,38 +249,92 @@ if(BUILD_SHARED_LIBS)
set_target_properties(snappy PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
endif(BUILD_SHARED_LIBS)

if(SNAPPY_BUILD_TESTS)
enable_testing()

add_executable(snappy_unittest "")
target_sources(snappy_unittest
if(SNAPPY_BUILD_TESTS OR SNAPPY_BUILD_BENCHMARKS)
add_library(snappy_test_support "")
target_sources(snappy_test_support
PRIVATE
"snappy_unittest.cc"
"snappy-test.cc"
"snappy-test.h"
"snappy_test_data.cc"
"snappy_test_data.h"
"${PROJECT_BINARY_DIR}/config.h"
)
target_compile_definitions(snappy_unittest PRIVATE -DHAVE_CONFIG_H)
target_link_libraries(snappy_unittest snappy ${GFLAGS_LIBRARIES})

# Test files include snappy-test.h, HAVE_CONFIG_H must be defined.
target_compile_definitions(snappy_test_support PUBLIC -DHAVE_CONFIG_H)

target_link_libraries(snappy_test_support snappy)

if(HAVE_LIBZ)
target_link_libraries(snappy_unittest z)
target_link_libraries(snappy_test_support z)
endif(HAVE_LIBZ)
if(HAVE_LIBLZO2)
target_link_libraries(snappy_unittest lzo2)
target_link_libraries(snappy_test_support lzo2)
endif(HAVE_LIBLZO2)
if(HAVE_LIBLZ4)
target_link_libraries(snappy_test_support lz4)
endif(HAVE_LIBLZ4)

target_include_directories(snappy_unittest
BEFORE PRIVATE
target_include_directories(snappy_test_support
BEFORE PUBLIC
"${PROJECT_SOURCE_DIR}"
"${GTEST_INCLUDE_DIRS}"
"${GFLAGS_INCLUDE_DIRS}"
)
endif(SNAPPY_BUILD_TESTS OR SNAPPY_BUILD_BENCHMARKS)

if(SNAPPY_BUILD_TESTS)
enable_testing()

# Prevent overriding the parent project's compiler/linker settings on Windows.
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
set(install_gtest OFF)
set(install_gmock OFF)
set(build_gmock ON)

# This project is tested using GoogleTest.
add_subdirectory("third_party/googletest")

# GoogleTest triggers a missing field initializers warning.
if(SNAPPY_HAVE_NO_MISSING_FIELD_INITIALIZERS)
set_property(TARGET gtest
APPEND PROPERTY COMPILE_OPTIONS -Wno-missing-field-initializers)
set_property(TARGET gmock
APPEND PROPERTY COMPILE_OPTIONS -Wno-missing-field-initializers)
endif(SNAPPY_HAVE_NO_MISSING_FIELD_INITIALIZERS)

add_executable(snappy_unittest "")
target_sources(snappy_unittest
PRIVATE
"snappy_unittest.cc"
)
target_link_libraries(snappy_unittest snappy_test_support gmock_main gtest)

add_test(
NAME snappy_unittest
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
COMMAND "${PROJECT_BINARY_DIR}/snappy_unittest")

add_executable(snappy_test_tool "")
target_sources(snappy_test_tool
PRIVATE
"snappy_test_tool.cc"
)
target_link_libraries(snappy_test_tool snappy_test_support)
endif(SNAPPY_BUILD_TESTS)

if(SNAPPY_BUILD_BENCHMARKS)
add_executable(snappy_benchmark "")
target_sources(snappy_benchmark
PRIVATE
"snappy_benchmark.cc"
)
target_link_libraries(snappy_benchmark snappy_test_support benchmark_main)

# This project uses Google benchmark for benchmarking.
set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "" FORCE)
set(BENCHMARK_ENABLE_EXCEPTIONS OFF CACHE BOOL "" FORCE)
add_subdirectory("third_party/benchmark")
endif(SNAPPY_BUILD_BENCHMARKS)

if(SNAPPY_FUZZING_BUILD)
add_executable(snappy_compress_fuzzer "")
target_sources(snappy_compress_fuzzer
Expand Down
20 changes: 20 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,26 @@
We'd love to accept your patches and contributions to this project. There are
just a few small guidelines you need to follow.

## Project Goals

In addition to the aims listed at the top of the [README](README.md) Snappy
explicitly supports the following:

1. C++11
2. Clang (gcc and MSVC are best-effort).
3. Low level optimizations (e.g. assembly or equivalent intrinsics) for:
1. [x86](https://en.wikipedia.org/wiki/X86)
2. [x86-64](https://en.wikipedia.org/wiki/X86-64)
3. ARMv7 (32-bit)
4. ARMv8 (AArch64)
4. Supports only the Snappy compression scheme as described in
[format_description.txt](format_description.txt).
5. CMake for building

Changes adding features or dependencies outside of the core area of focus listed
above might not be accepted. If in doubt post a message to the
[Snappy discussion mailing list](https://groups.google.com/g/snappy-compression).

## Contributor License Agreement

Contributions to this project must be accompanied by a Contributor License
Expand Down
6 changes: 6 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Snappy v1.1.9, May 4th 2021:

* Performance improvements.

* Google Test and Google Benchmark are now bundled in third_party/.

Snappy v1.1.8, January 15th 2020:

* Small performance improvements.
Expand Down
Loading

0 comments on commit 694d216

Please sign in to comment.