diff --git a/Makefile.orbis b/Makefile.orbis index dd72f33c10..fe08503b04 100644 --- a/Makefile.orbis +++ b/Makefile.orbis @@ -17,7 +17,7 @@ PC_DEVELOPMENT_UDP_PORT = 18194 AUTH_INFO = 000000000000000000000000001C004000FF000000000080000000000000000000000000000000000000008000400040000000000000008000000000000000080040FFFF000000F000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 OBJ += memory/ps4/user_mem.o \ -# memory/ps4/user_new.o \ + deps/xxHash/xxhash.c \ # input/drivers/ps4_input.o \ # input/drivers_joypad/ps4_joypad.o \ # audio/drivers/psp_audio.o \ diff --git a/deps/xxHash/.gitattributes b/deps/xxHash/.gitattributes new file mode 100644 index 0000000000..fbcf75b555 --- /dev/null +++ b/deps/xxHash/.gitattributes @@ -0,0 +1,10 @@ +# Set the default behavior +* text eol=lf + +# Explicitly declare source files +*.c text eol=lf +*.h text eol=lf + +# Denote files that should not be modified. +*.odt binary + diff --git a/deps/xxHash/.gitignore b/deps/xxHash/.gitignore new file mode 100644 index 0000000000..d0ce9aac3b --- /dev/null +++ b/deps/xxHash/.gitignore @@ -0,0 +1,47 @@ +# objects +*.o +*.obj +*.s + +# libraries +libxxhash.* +!libxxhash.pc.in + +# Executables +*.exe +xxh32sum +xxh64sum +xxh128sum +xxhsum +xxhsum32 +xxhsum_privateXXH +xxhsum_inlinedXXH +dispatch +tests/generate_unicode_test + +# compilation chain +.clang_complete + +# Mac OS-X artefacts +*.dSYM +.DS_Store + +# Wasm / emcc / emscripten artefacts +*.html +*.wasm +*.js + +# CMake build directories +build*/ + +# project managers artifacts +.projectile + +# analyzer artifacts +infer-out + +# test artifacts +.test* +tmp* +tests/*.unicode +tests/unicode_test* diff --git a/deps/xxHash/.travis.yml b/deps/xxHash/.travis.yml new file mode 100644 index 0000000000..9f9e42cac4 --- /dev/null +++ b/deps/xxHash/.travis.yml @@ -0,0 +1,142 @@ +language: c + +# Dump CPU info before start +before_install: + - cat /proc/cpuinfo || echo /proc/cpuinfo is not present + +matrix: + fast_finish: true + include: + + - name: General linux x64 tests + arch: amd64 + addons: + apt: + packages: + - g++-multilib + - gcc-multilib + - cppcheck + script: + - make -B test-all + - make clean + - CFLAGS="-Werror" MOREFLAGS="-Wno-sign-conversion" make dispatch # removing sign conversion warnings due to a bug in gcc-5's definition of some AVX512 intrinsics + - make clean + - CFLAGS="-O1 -mavx512f -Werror" make + - make clean + - CFLAGS="-Wall -Wextra -Werror" make DISPATCH=1 + - make clean + - CFLAGS="-std=c90 -pedantic -Wno-long-long -Werror" make xxhsum # check C90 + long long compliance + - make c90test # strict c90, with no long long support; resulting in no XXH64_* symbol + - make noxxh3test # check library can be compiled with XXH_NO_XXH3, resulting in no XXH3_* symbol + + + - name: Check results consistency on x64 + arch: amd64 + script: + - CPPFLAGS=-DXXH_VECTOR=XXH_SCALAR make check # Scalar code path + - make clean + - CPPFLAGS=-DXXH_VECTOR=XXH_SSE2 make check # SSE2 code path + - make clean + - CPPFLAGS="-mavx2 -DXXH_VECTOR=XXH_AVX2" make check # AVX2 code path + - make clean + - CPPFLAGS="-mavx512f -DXXH_VECTOR=XXH_AVX512" make check # AVX512 code path + - make clean + - CPPFLAGS=-DXXH_REROLL=1 make check # reroll code path (#240) + - make -C tests/bench + + - name: macOS General Test + os: osx + compiler: clang + script: + - CFLAGS="-Werror" make # test library build + - make clean + - make test MOREFLAGS='-Werror' | tee # test scenario where `stdout` is not the console + + - name: ARM compilation and consistency checks (Qemu) + dist: xenial + arch: amd64 + addons: + apt: + packages: + - qemu-system-arm + - qemu-user-static + - gcc-arm-linux-gnueabi + - libc6-dev-armel-cross + script: + # arm (32-bit) + - CC=arm-linux-gnueabi-gcc CPPFLAGS=-DXXH_VECTOR=XXH_SCALAR LDFLAGS=-static RUN_ENV=qemu-arm-static make check # Scalar code path + - make clean + # NEON (32-bit) + - CC=arm-linux-gnueabi-gcc CPPFLAGS=-DXXH_VECTOR=XXH_NEON CFLAGS="-O3 -march=armv7-a -fPIC -mfloat-abi=softfp -mfpu=neon-vfpv4" LDFLAGS=-static RUN_ENV=qemu-arm-static make check # NEON code path + + - name: aarch64 compilation and consistency checks + dist: xenial + arch: arm64 + script: + # aarch64 + - CPPFLAGS=-DXXH_VECTOR=XXH_SCALAR make check # Scalar code path + # NEON (64-bit) + - make clean + - CPPFLAGS=-DXXH_VECTOR=XXH_NEON make check # NEON code path + # clang + - make clean + - CC=clang CPPFLAGS=-DXXH_VECTOR=XXH_SCALAR make check # Scalar code path + # clang + NEON + - make clean + - CC=clang CPPFLAGS=-DXXH_VECTOR=XXH_NEON make check # NEON code path + + # We need Bionic here because the QEMU versions shipped in the older repos + # do not support POWER8 emulation, and compiling QEMU from source is a pain. + - name: PowerPC + PPC64 compilation and consistency checks (Qemu on Bionic) + dist: bionic + arch: amd64 + addons: + apt: + packages: + - qemu-system-ppc + - qemu-user-static + - gcc-powerpc-linux-gnu + - gcc-powerpc64-linux-gnu + - libc6-dev-powerpc-cross + - libc6-dev-ppc64-cross + script: + - CC=powerpc-linux-gnu-gcc RUN_ENV=qemu-ppc-static LDFLAGS=-static make check # Scalar code path + - make clean + - CC=powerpc64-linux-gnu-gcc RUN_ENV=qemu-ppc64-static CPPFLAGS=-DXXH_VECTOR=XXH_SCALAR CFLAGS="-O3" LDFLAGS="-static -m64" make check # Scalar code path + # VSX code + - make clean + - CC=powerpc64-linux-gnu-gcc RUN_ENV="qemu-ppc64-static -cpu power8" CPPFLAGS=-DXXH_VECTOR=XXH_VSX CFLAGS="-O3 -maltivec -mvsx -mcpu=power8 -mpower8-vector" LDFLAGS="-static -m64" make check # VSX code path + # altivec.h redefinition issue #426 + - make clean + - CC=powerpc64-linux-gnu-gcc CPPFLAGS=-DXXH_VECTOR=XXH_VSX CFLAGS="-maltivec -mvsx -mcpu=power8 -mpower8-vector" make -C tests test_ppc_redefine + + - name: PPC64LE compilation and consistency checks + dist: xenial + arch: ppc64le + script: + # Scalar (universal) code path + - CPPFLAGS=-DXXH_VECTOR=XXH_SCALAR LDFLAGS=-static make check + # VSX code path (64-bit) + - make clean + - CPPFLAGS=-DXXH_VECTOR=XXH_VSX CFLAGS="-O3 -maltivec -mvsx -mpower8-vector -mcpu=power8" LDFLAGS="-static" make check + # altivec.h redefinition issue #426 + - make clean + - CPPFLAGS=-DXXH_VECTOR=XXH_VSX CFLAGS="-maltivec -mvsx -mcpu=power8 -mpower8-vector" make -C tests test_ppc_redefine + + - name: IBM s390x compilation and consistency checks + dist: bionic + arch: s390x + script: + # Scalar (universal) code path + - CPPFLAGS=-DXXH_VECTOR=XXH_SCALAR LDFLAGS=-static make check + # s390x code path (64-bit) + - make clean + - CPPFLAGS=-DXXH_VECTOR=XXH_VSX CFLAGS="-O3 -march=arch11 -mzvector" LDFLAGS="-static" make check + + - name: cmake build test + script: + - cd cmake_unofficial + - mkdir build + - cd build + - cmake .. + - CFLAGS=-Werror make diff --git a/deps/xxHash/CHANGELOG b/deps/xxHash/CHANGELOG new file mode 100644 index 0000000000..23870756bb --- /dev/null +++ b/deps/xxHash/CHANGELOG @@ -0,0 +1,52 @@ +v0.8.0 +- api : stabilize XXH3 +- cli : xxhsum can parse BSD-style --check lines, by @WayneD +- cli : `xxhsum -` accepts console input, requested by @jaki +- cli : xxhsum accepts -- separator, by @jaki +- cli : fix : print correct default algo for symlinked helpers, by @martinetd +- install: improved pkgconfig script, allowing custom install locations, requested by @ellert + +v0.7.4 +- perf: automatic vector detection and selection at runtime (`xxh_x86dispatch.h`), initiated by @easyaspi314 +- perf: added AVX512 support, by @gzm55 +- api : new: secret generator `XXH_generateSecret()`, suggested by @koraa +- api : fix: XXH3_state_t is movable, identified by @koraa +- api : fix: state is correctly aligned in AVX mode (unlike `malloc()`), by @easyaspi314 +- api : fix: streaming generated wrong values in some combination of random ingestion lengths, reported by @WayneD +- cli : fix unicode print on Windows, by @easyaspi314 +- cli : can `-c` check file generated by sfv +- build: `make DISPATCH=1` generates `xxhsum` and `libxxhash` with runtime vector detection (x86/x64 only) +- install: cygwin installation support +- doc : Cryptol specification of XXH32 and XXH64, by @weaversa + +v0.7.3 +- perf: improved speed for large inputs (~+20%) +- perf: improved latency for small inputs (~10%) +- perf: s390x Vectorial code, by @easyaspi314 +- cli: improved support for Unicode filenames on Windows, thanks to @easyaspi314 and @t-mat +- api: `xxhash.h` can now be included in any order, with and without `XXH_STATIC_LINKING_ONLY` and `XXH_INLINE_ALL` +- build: xxHash's implementation transferred into `xxhash.h`. No more need to have `xxhash.c` in the `/include` directory for `XXH_INLINE_ALL` to work +- install: created pkg-config file, by @bket +- install: VCpkg installation instructions, by @LilyWangL +- doc: Highly improved code documentation, by @easyaspi314 +- misc: New test tool in `/tests/collisions`: brute force collision tester for 64-bit hashes + +v0.7.2 +- Fixed collision ratio of `XXH128` for some specific input lengths, reported by @svpv +- Improved `VSX` and `NEON` variants, by @easyaspi314 +- Improved performance of scalar code path (`XXH_VECTOR=0`), by @easyaspi314 +- `xxhsum`: can generate 128-bit hashes with the `-H2` option (note: for experimental purposes only! `XXH128` is not yet frozen) +- `xxhsum`: option `-q` removes status notifications + +v0.7.1 +- Secret first: the algorithm computation can be altered by providing a "secret", which is any blob of bytes, of size >= `XXH3_SECRET_SIZE_MIN`. +- `seed` is still available, and acts as a secret generator +- updated `ARM NEON` variant by @easyaspi314 +- Streaming implementation is available +- Improve compatibility and performance with Visual Studio, with help from @aras-p +- Better integration when using `XXH_INLINE_ALL`: do not pollute host namespace, use its own macros, such as `XXH_ASSERT()`, `XXH_ALIGN`, etc. +- 128-bit variant provides helper functions for comparison of hashes. +- Better `clang` generation of `rotl` instruction, thanks to @easyaspi314 +- `XXH_REROLL` build macro to reduce binary size, by @easyaspi314 +- Improved `cmake` script, by @Mezozoysky +- Full benchmark program provided in `/tests/bench` diff --git a/deps/xxHash/Doxyfile b/deps/xxHash/Doxyfile new file mode 100644 index 0000000000..634e1e1a38 --- /dev/null +++ b/deps/xxHash/Doxyfile @@ -0,0 +1,58 @@ +# Doxygen config for xxHash +DOXYFILE_ENCODING = UTF-8 + +PROJECT_NAME = "xxHash" +PROJECT_NUMBER = "0.8.0" +PROJECT_BRIEF = "Extremely fast non-cryptographic hash function" +OUTPUT_DIRECTORY = doxygen +OUTPUT_LANGUAGE = English + +# We already separate the internal docs. +INTERNAL_DOCS = YES +# Consistency +SORT_MEMBER_DOCS = NO +BRIEF_MEMBER_DESC = YES +REPEAT_BRIEF = YES + +# Warnings +QUIET = YES +# Until we document everything +WARN_IF_UNDOCUMENTED = NO + +# TODO: Add the other files. It is just xxhash.h for now. +FILE_PATTERNS = xxhash.h xxh_x86dispatch.c +# Note: xxHash's source files are technically ASCII only. +INPUT_ENCODING = UTF-8 +TAB_SIZE = 4 +MARKDOWN_SUPPORT = YES + +# xxHash is a C library +OPTIMIZE_OUTPUT_FOR_C = YES +# So we can document the internals +EXTRACT_STATIC = YES +# Document the macros +MACRO_EXPANSION = YES +EXPAND_ONLY_PREDEF = YES +# Predefine some macros to clean up the output. +PREDEFINED = "XXH_DOXYGEN=" \ + "XXH_PUBLIC_API=" \ + "XXH_FORCE_INLINE=static inline" \ + "XXH_NO_INLINE=static" \ + "XXH_RESTRICT=restrict" \ + "XSUM_API=" \ + "XXH_STATIC_LINKING_ONLY" \ + "XXH_IMPLEMENTATION" \ + "XXH_ALIGN(N)=alignas(N)" \ + "XXH_ALIGN_MEMBER(align,type)=alignas(align) type" + +# We want HTML docs +GENERATE_HTML = YES +HTML_OUTPUT = html +HTML_FILE_EXTENSION = .html +# Tweak the colors a bit +HTML_COLORSTYLE_HUE = 220 +HTML_COLORSTYLE_GAMMA = 100 +HTML_COLORSTYLE_SAT = 100 + +# We don't want LaTeX. +GENERATE_LATEX = NO diff --git a/deps/xxHash/LICENSE b/deps/xxHash/LICENSE new file mode 100644 index 0000000000..fa20595dc6 --- /dev/null +++ b/deps/xxHash/LICENSE @@ -0,0 +1,48 @@ +xxHash Library +Copyright (c) 2012-2020 Yann Collet +All rights reserved. + +BSD 2-Clause License (https://www.opensource.org/licenses/bsd-license.php) + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, this + list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +---------------------------------------------------- + +xxhsum command line interface +Copyright (c) 2013-2020 Yann Collet +All rights reserved. + +GPL v2 License + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. diff --git a/deps/xxHash/Makefile b/deps/xxHash/Makefile new file mode 100644 index 0000000000..da6e08187c --- /dev/null +++ b/deps/xxHash/Makefile @@ -0,0 +1,533 @@ +# ################################################################ +# xxHash Makefile +# Copyright (C) 2012-2020 Yann Collet +# +# GPL v2 License +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# You can contact the author at: +# - xxHash homepage: https://www.xxhash.com +# - xxHash source repository: https://github.com/Cyan4973/xxHash +# ################################################################ +# xxhsum: provides 32/64 bits hash of one or multiple files, or stdin +# ################################################################ +Q = $(if $(filter 1,$(V) $(VERBOSE)),,@) + +# Version numbers +SED ?= sed +SED_ERE_OPT ?= -E +LIBVER_MAJOR_SCRIPT:=`$(SED) -n '/define XXH_VERSION_MAJOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < xxhash.h` +LIBVER_MINOR_SCRIPT:=`$(SED) -n '/define XXH_VERSION_MINOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < xxhash.h` +LIBVER_PATCH_SCRIPT:=`$(SED) -n '/define XXH_VERSION_RELEASE/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < xxhash.h` +LIBVER_MAJOR := $(shell echo $(LIBVER_MAJOR_SCRIPT)) +LIBVER_MINOR := $(shell echo $(LIBVER_MINOR_SCRIPT)) +LIBVER_PATCH := $(shell echo $(LIBVER_PATCH_SCRIPT)) +LIBVER := $(LIBVER_MAJOR).$(LIBVER_MINOR).$(LIBVER_PATCH) + +CFLAGS ?= -O3 +DEBUGFLAGS+=-Wall -Wextra -Wconversion -Wcast-qual -Wcast-align -Wshadow \ + -Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement \ + -Wstrict-prototypes -Wundef -Wpointer-arith -Wformat-security \ + -Wvla -Wformat=2 -Winit-self -Wfloat-equal -Wwrite-strings \ + -Wredundant-decls -Wstrict-overflow=2 +CFLAGS += $(DEBUGFLAGS) $(MOREFLAGS) +FLAGS = $(CFLAGS) $(CPPFLAGS) +XXHSUM_VERSION = $(LIBVER) +UNAME := $(shell uname) + +# Define *.exe as extension for Windows systems +ifneq (,$(filter Windows%,$(OS))) +EXT =.exe +else +EXT = +endif + +# OS X linker doesn't support -soname, and use different extension +# see: https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/DynamicLibraryDesignGuidelines.html +ifeq ($(UNAME), Darwin) + SHARED_EXT = dylib + SHARED_EXT_MAJOR = $(LIBVER_MAJOR).$(SHARED_EXT) + SHARED_EXT_VER = $(LIBVER).$(SHARED_EXT) + SONAME_FLAGS = -install_name $(LIBDIR)/libxxhash.$(SHARED_EXT_MAJOR) -compatibility_version $(LIBVER_MAJOR) -current_version $(LIBVER) +else + SONAME_FLAGS = -Wl,-soname=libxxhash.$(SHARED_EXT).$(LIBVER_MAJOR) + SHARED_EXT = so + SHARED_EXT_MAJOR = $(SHARED_EXT).$(LIBVER_MAJOR) + SHARED_EXT_VER = $(SHARED_EXT).$(LIBVER) +endif + +LIBXXH = libxxhash.$(SHARED_EXT_VER) + +XXHSUM_SRC_DIR = cli +XXHSUM_SPLIT_SRCS = $(XXHSUM_SRC_DIR)/xxhsum.c \ + $(XXHSUM_SRC_DIR)/xsum_os_specific.c \ + $(XXHSUM_SRC_DIR)/xsum_output.c \ + $(XXHSUM_SRC_DIR)/xsum_sanity_check.c +XXHSUM_SPLIT_OBJS = $(XXHSUM_SPLIT_SRCS:.c=.o) +XXHSUM_HEADERS = $(XXHSUM_SRC_DIR)/xsum_config.h \ + $(XXHSUM_SRC_DIR)/xsum_arch.h \ + $(XXHSUM_SRC_DIR)/xsum_os_specific.h \ + $(XXHSUM_SRC_DIR)/xsum_output.h \ + $(XXHSUM_SRC_DIR)/xsum_sanity_check.h + +## generate CLI and libraries in release mode (default for `make`) +.PHONY: default +default: DEBUGFLAGS= +default: lib xxhsum_and_links + +.PHONY: all +all: lib xxhsum xxhsum_inlinedXXH + +## xxhsum is the command line interface (CLI) +ifeq ($(DISPATCH),1) +xxhsum: CPPFLAGS += -DXXHSUM_DISPATCH=1 +xxhsum: xxh_x86dispatch.o +endif +xxhsum: xxhash.o $(XXHSUM_SPLIT_OBJS) + $(CC) $(FLAGS) $^ $(LDFLAGS) -o $@$(EXT) + +xxhsum32: CFLAGS += -m32 ## generate CLI in 32-bits mode +xxhsum32: xxhash.c $(XXHSUM_SPLIT_SRCS) ## do not generate object (avoid mixing different ABI) + $(CC) $(FLAGS) $^ $(LDFLAGS) -o $@$(EXT) + +## dispatch only works for x86/x64 systems +dispatch: CPPFLAGS += -DXXHSUM_DISPATCH=1 +dispatch: xxhash.o xxh_x86dispatch.o $(XXHSUM_SPLIT_SRCS) + $(CC) $(FLAGS) $^ $(LDFLAGS) -o $@$(EXT) + +xxhash.o: xxhash.c xxhash.h +xxhsum.o: $(XXHSUM_SRC_DIR)/xxhsum.c $(XXHSUM_HEADERS) \ + xxhash.h xxh_x86dispatch.h +xxh_x86dispatch.o: xxh_x86dispatch.c xxh_x86dispatch.h xxhash.h + +.PHONY: xxhsum_and_links +xxhsum_and_links: xxhsum xxh32sum xxh64sum xxh128sum + +xxh32sum xxh64sum xxh128sum: xxhsum + ln -sf $<$(EXT) $@$(EXT) + +xxhsum_inlinedXXH: CPPFLAGS += -DXXH_INLINE_ALL +xxhsum_inlinedXXH: $(XXHSUM_SPLIT_SRCS) + $(CC) $(FLAGS) $< -o $@$(EXT) + + +# library + +libxxhash.a: ARFLAGS = rcs +libxxhash.a: xxhash.o + $(AR) $(ARFLAGS) $@ $^ + +$(LIBXXH): LDFLAGS += -shared +ifeq (,$(filter Windows%,$(OS))) +$(LIBXXH): CFLAGS += -fPIC +endif +ifeq ($(DISPATCH),1) +$(LIBXXH): xxh_x86dispatch.c +endif +$(LIBXXH): xxhash.c + $(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@ + ln -sf $@ libxxhash.$(SHARED_EXT_MAJOR) + ln -sf $@ libxxhash.$(SHARED_EXT) + +.PHONY: libxxhash +libxxhash: ## generate dynamic xxhash library +libxxhash: $(LIBXXH) + +.PHONY: lib +lib: ## generate static and dynamic xxhash libraries +lib: libxxhash.a libxxhash + +# helper targets + +AWK = awk +GREP = grep +SORT = sort +NM = nm + +.PHONY: list +list: ## list all Makefile targets + $(Q)$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | $(AWK) -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | $(SORT) | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | xargs + +.PHONY: help +help: ## list documented targets + $(Q)$(GREP) -E '^[0-9a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \ + $(SORT) | \ + $(AWK) 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' + +.PHONY: clean +clean: ## remove all build artifacts + $(Q)$(RM) -r *.dSYM # Mac OS-X specific + $(Q)$(RM) core *.o *.obj *.$(SHARED_EXT) *.$(SHARED_EXT).* *.a libxxhash.pc + $(Q)$(RM) xxhsum$(EXT) xxhsum32$(EXT) xxhsum_inlinedXXH$(EXT) dispatch$(EXT) + $(Q)$(RM) xxh32sum$(EXT) xxh64sum$(EXT) xxh128sum$(EXT) + $(Q)$(RM) $(XXHSUM_SRC_DIR)/*.o $(XXHSUM_SRC_DIR)/*.obj + $(MAKE) -C tests clean + $(MAKE) -C tests/bench clean + $(MAKE) -C tests/collisions clean + @echo cleaning completed + + +# ================================================= +# tests +# ================================================= + +# make check can be run with cross-compiled binaries on emulated environments (qemu user mode) +# by setting $(RUN_ENV) to the target emulation environment +.PHONY: check +check: xxhsum ## basic tests for xxhsum CLI, set RUN_ENV for emulated environments + # stdin + $(RUN_ENV) ./xxhsum$(EXT) < xxhash.c + # multiple files + $(RUN_ENV) ./xxhsum$(EXT) xxhash.* + # internal bench + $(RUN_ENV) ./xxhsum$(EXT) -bi0 + # long bench command + $(RUN_ENV) ./xxhsum$(EXT) --benchmark-all -i0 + # bench multiple variants + $(RUN_ENV) ./xxhsum$(EXT) -b1,2,3 -i0 + # file bench + $(RUN_ENV) ./xxhsum$(EXT) -bi0 xxhash.c + # 32-bit + $(RUN_ENV) ./xxhsum$(EXT) -H0 xxhash.c + # 128-bit + $(RUN_ENV) ./xxhsum$(EXT) -H2 xxhash.c + # request incorrect variant + $(RUN_ENV) ./xxhsum$(EXT) -H9 xxhash.c ; test $$? -eq 1 + @printf "\n ....... checks completed successfully ....... \n" + +.PHONY: test-unicode +test-unicode: + $(MAKE) -C tests test_unicode + +.PHONY: test-mem +VALGRIND = valgrind --leak-check=yes --error-exitcode=1 +test-mem: RUN_ENV = $(VALGRIND) +test-mem: xxhsum check + +.PHONY: test32 +test32: xxhsum32 + @echo ---- test 32-bit ---- + ./xxhsum32 -bi0 xxhash.c + +TEST_FILES = xxhsum$(EXT) xxhash.c xxhash.h +.PHONY: test-xxhsum-c +test-xxhsum-c: xxhsum + # xxhsum to/from pipe + ./xxhsum $(TEST_FILES) | ./xxhsum -c - + ./xxhsum -H0 $(TEST_FILES) | ./xxhsum -c - + # xxhsum -c is unable to verify checksum of file from STDIN (#470) + ./xxhsum < README.md > .test.README.md.xxh + ./xxhsum -c .test.README.md.xxh < README.md + # xxhsum -q does not display "Loading" message into stderr (#251) + ! ./xxhsum -q $(TEST_FILES) 2>&1 | grep Loading + # xxhsum does not display "Loading" message into stderr either + ! ./xxhsum $(TEST_FILES) 2>&1 | grep Loading + # Check that xxhsum do display filename that it failed to open. + LC_ALL=C ./xxhsum nonexistent 2>&1 | grep "Error: Could not open 'nonexistent'" + # xxhsum to/from file, shell redirection + ./xxhsum $(TEST_FILES) > .test.xxh64 + ./xxhsum --tag $(TEST_FILES) > .test.xxh64_tag + ./xxhsum --little-endian $(TEST_FILES) > .test.le_xxh64 + ./xxhsum --tag --little-endian $(TEST_FILES) > .test.le_xxh64_tag + ./xxhsum -H0 $(TEST_FILES) > .test.xxh32 + ./xxhsum -H0 --tag $(TEST_FILES) > .test.xxh32_tag + ./xxhsum -H0 --little-endian $(TEST_FILES) > .test.le_xxh32 + ./xxhsum -H0 --tag --little-endian $(TEST_FILES) > .test.le_xxh32_tag + ./xxhsum -H2 $(TEST_FILES) > .test.xxh128 + ./xxhsum -H2 --tag $(TEST_FILES) > .test.xxh128_tag + ./xxhsum -H2 --little-endian $(TEST_FILES) > .test.le_xxh128 + ./xxhsum -H2 --tag --little-endian $(TEST_FILES) > .test.le_xxh128_tag + ./xxhsum -c .test.xxh* + ./xxhsum -c --little-endian .test.le_xxh* + ./xxhsum -c .test.*_tag + # read list of files from stdin + ./xxhsum -c < .test.xxh64 + ./xxhsum -c < .test.xxh32 + cat .test.xxh* | ./xxhsum -c - + # check variant with '*' marker as second separator + $(SED) 's/ / \*/' .test.xxh32 | ./xxhsum -c + # bsd-style output + ./xxhsum --tag xxhsum* | $(GREP) XXH64 + ./xxhsum --tag -H0 xxhsum* | $(GREP) XXH32 + ./xxhsum --tag -H1 xxhsum* | $(GREP) XXH64 + ./xxhsum --tag -H2 xxhsum* | $(GREP) XXH128 + ./xxhsum --tag -H32 xxhsum* | $(GREP) XXH32 + ./xxhsum --tag -H64 xxhsum* | $(GREP) XXH64 + ./xxhsum --tag -H128 xxhsum* | $(GREP) XXH128 + ./xxhsum --tag -H0 --little-endian xxhsum* | $(GREP) XXH32_LE + ./xxhsum --tag -H1 --little-endian xxhsum* | $(GREP) XXH64_LE + ./xxhsum --tag -H2 --little-endian xxhsum* | $(GREP) XXH128_LE + ./xxhsum --tag -H32 --little-endian xxhsum* | $(GREP) XXH32_LE + ./xxhsum --tag -H64 --little-endian xxhsum* | $(GREP) XXH64_LE + ./xxhsum --tag -H128 --little-endian xxhsum* | $(GREP) XXH128_LE + # check bsd-style + ./xxhsum --tag xxhsum* | ./xxhsum -c + ./xxhsum --tag -H32 --little-endian xxhsum* | ./xxhsum -c + # xxhsum -c warns improperly format lines. + echo '12345678 ' >>.test.xxh32 + ./xxhsum -c .test.xxh32 | $(GREP) improperly + echo '123456789 file' >>.test.xxh64 + ./xxhsum -c .test.xxh64 | $(GREP) improperly + # Expects "FAILED" + echo "0000000000000000 LICENSE" | ./xxhsum -c -; test $$? -eq 1 + echo "00000000 LICENSE" | ./xxhsum -c -; test $$? -eq 1 + # Expects "FAILED open or read" + echo "0000000000000000 test-expects-file-not-found" | ./xxhsum -c -; test $$? -eq 1 + echo "00000000 test-expects-file-not-found" | ./xxhsum -c -; test $$? -eq 1 + @$(RM) .test.* + +.PHONY: armtest +armtest: clean + @echo ---- test ARM compilation ---- + CC=arm-linux-gnueabi-gcc MOREFLAGS="-Werror -static" $(MAKE) xxhsum + +.PHONY: clangtest +clangtest: clean + @echo ---- test clang compilation ---- + CC=clang MOREFLAGS="-Werror -Wconversion -Wno-sign-conversion" $(MAKE) all + +.PHONY: cxxtest +cxxtest: clean + @echo ---- test C++ compilation ---- + CC="$(CXX) -Wno-deprecated" $(MAKE) all CFLAGS="-O3 -Wall -Wextra -Wundef -Wshadow -Wcast-align -Werror -fPIC" + +.PHONY: c90test +ifeq ($(NO_C90_TEST),true) +c90test: + @echo no c90 compatibility test +else +c90test: CPPFLAGS += -DXXH_NO_LONG_LONG +c90test: CFLAGS += -std=c90 -Werror -pedantic +c90test: xxhash.c + @echo ---- test strict C90 compilation [xxh32 only] ---- + $(RM) xxhash.o + $(CC) $(FLAGS) $^ -c + $(NM) xxhash.o | $(GREP) XXH64 ; test $$? -eq 1 + $(RM) xxhash.o +endif + +noxxh3test: CPPFLAGS += -DXXH_NO_XXH3 +noxxh3test: CFLAGS += -Werror -pedantic -Wno-long-long # XXH64 requires long long support +noxxh3test: xxhash.c + @echo ---- test compilation without XXH3 ---- + $(RM) xxhash.o + $(CC) $(FLAGS) $^ -c + $(NM) xxhash.o | $(GREP) XXH3_ ; test $$? -eq 1 + $(RM) xxhash.o + +.PHONY: usan +usan: CC=clang +usan: CXX=clang++ +usan: ## check CLI runtime for undefined behavior, using clang's sanitizer + @echo ---- check undefined behavior - sanitize ---- + $(MAKE) clean + $(MAKE) test CC=$(CC) CXX=$(CXX) MOREFLAGS="-g -fsanitize=undefined -fno-sanitize-recover=all" + +.PHONY: staticAnalyze +SCANBUILD ?= scan-build +staticAnalyze: clean ## check C source files using $(SCANBUILD) static analyzer + @echo ---- static analyzer - $(SCANBUILD) ---- + CFLAGS="-g -Werror" $(SCANBUILD) --status-bugs -v $(MAKE) all + +CPPCHECK ?= cppcheck +.PHONY: cppcheck +cppcheck: ## check C source files using $(CPPCHECK) static analyzer + @echo ---- static analyzer - $(CPPCHECK) ---- + $(CPPCHECK) . --force --enable=warning,portability,performance,style --error-exitcode=1 > /dev/null + +.PHONY: namespaceTest +namespaceTest: ## ensure XXH_NAMESPACE redefines all public symbols + $(CC) -c xxhash.c + $(CC) -DXXH_NAMESPACE=TEST_ -c xxhash.c -o xxhash2.o + $(CC) xxhash.o xxhash2.o $(XXHSUM_SPLIT_SRCS) -o xxhsum2 # will fail if one namespace missing (symbol collision) + $(RM) *.o xxhsum2 # clean + +MAN = $(XXHSUM_SRC_DIR)/xxhsum.1 +MD2ROFF ?= ronn +MD2ROFF_FLAGS ?= --roff --warnings --manual="User Commands" --organization="xxhsum $(XXHSUM_VERSION)" +$(MAN): $(XXHSUM_SRC_DIR)/xxhsum.1.md xxhash.h + cat $< | $(MD2ROFF) $(MD2ROFF_FLAGS) | $(SED) -n '/^\.\\\".*/!p' > $@ + +.PHONY: man +man: $(MAN) ## generate man page from markdown source + +.PHONY: clean-man +clean-man: + $(RM) xxhsum.1 + +.PHONY: preview-man +preview-man: man + man ./xxhsum.1 + +.PHONY: test +test: DEBUGFLAGS += -DXXH_DEBUGLEVEL=1 +test: all namespaceTest check test-xxhsum-c c90test test-tools + +.PHONY: test-inline +test-inline: + $(MAKE) -C tests test_multiInclude + +.PHONY: test-all +test-all: CFLAGS += -Werror +test-all: test test32 test-unicode clangtest cxxtest usan test-inline listL120 trailingWhitespace + +.PHONY: test-tools +test-tools: + CFLAGS=-Werror $(MAKE) -C tests/bench + CFLAGS=-Werror $(MAKE) -C tests/collisions + +.PHONY: listL120 +listL120: # extract lines >= 120 characters in *.{c,h}, by Takayuki Matsuoka (note: $$, for Makefile compatibility) + find . -type f -name '*.c' -o -name '*.h' | while read -r filename; do awk 'length > 120 {print FILENAME "(" FNR "): " $$0}' $$filename; done + +.PHONY: trailingWhitespace +trailingWhitespace: + ! $(GREP) -E "`printf '[ \\t]$$'`" cli/*.{c,h,1} *.c *.h LICENSE Makefile cmake_unofficial/CMakeLists.txt + +.PHONY: lint-unicode +lint-unicode: + ./tests/unicode_lint.sh + +# ========================================================= +# make install is validated only for the following targets +# ========================================================= +ifneq (,$(filter Linux Darwin GNU/kFreeBSD GNU Haiku OpenBSD FreeBSD NetBSD DragonFly SunOS CYGWIN% , $(UNAME))) + +DESTDIR ?= +# directory variables: GNU conventions prefer lowercase +# see https://www.gnu.org/prep/standards/html_node/Makefile-Conventions.html +# support both lower and uppercase (BSD), use uppercase in script +prefix ?= /usr/local +PREFIX ?= $(prefix) +exec_prefix ?= $(PREFIX) +EXEC_PREFIX ?= $(exec_prefix) +libdir ?= $(EXEC_PREFIX)/lib +LIBDIR ?= $(libdir) +includedir ?= $(PREFIX)/include +INCLUDEDIR ?= $(includedir) +bindir ?= $(EXEC_PREFIX)/bin +BINDIR ?= $(bindir) +datarootdir ?= $(PREFIX)/share +mandir ?= $(datarootdir)/man +man1dir ?= $(mandir)/man1 + +ifneq (,$(filter $(UNAME),FreeBSD NetBSD DragonFly)) +PKGCONFIGDIR ?= $(PREFIX)/libdata/pkgconfig +else +PKGCONFIGDIR ?= $(LIBDIR)/pkgconfig +endif + +ifneq (,$(filter $(UNAME),OpenBSD FreeBSD NetBSD DragonFly SunOS)) +MANDIR ?= $(PREFIX)/man/man1 +else +MANDIR ?= $(man1dir) +endif + +ifneq (,$(filter $(UNAME),SunOS)) +INSTALL ?= ginstall +else +INSTALL ?= install +endif + +INSTALL_PROGRAM ?= $(INSTALL) +INSTALL_DATA ?= $(INSTALL) -m 644 + + +# Escape special symbols by putting each character into its separate class +EXEC_PREFIX_REGEX ?= $(shell echo "$(EXEC_PREFIX)" | $(SED) $(SED_ERE_OPT) -e "s/([^^])/[\1]/g" -e "s/\\^/\\\\^/g") +PREFIX_REGEX ?= $(shell echo "$(PREFIX)" | $(SED) $(SED_ERE_OPT) -e "s/([^^])/[\1]/g" -e "s/\\^/\\\\^/g") + +PCLIBDIR ?= $(shell echo "$(LIBDIR)" | $(SED) -n $(SED_ERE_OPT) -e "s@^$(EXEC_PREFIX_REGEX)(/|$$)@@p") +PCINCDIR ?= $(shell echo "$(INCLUDEDIR)" | $(SED) -n $(SED_ERE_OPT) -e "s@^$(PREFIX_REGEX)(/|$$)@@p") +PCEXECDIR?= $(if $(filter $(PREFIX),$(EXEC_PREFIX)),$$\{prefix\},$(EXEC_PREFIX)) + +ifeq (,$(PCLIBDIR)) +# Additional prefix check is required, since the empty string is technically a +# valid PCLIBDIR +ifeq (,$(shell echo "$(LIBDIR)" | $(SED) -n $(SED_ERE_OPT) -e "\\@^$(EXEC_PREFIX_REGEX)(/|$$)@ p")) +$(error configured libdir ($(LIBDIR)) is outside of exec_prefix ($(EXEC_PREFIX)), can't generate pkg-config file) +endif +endif + +ifeq (,$(PCINCDIR)) +# Additional prefix check is required, since the empty string is technically a +# valid PCINCDIR +ifeq (,$(shell echo "$(INCLUDEDIR)" | $(SED) -n $(SED_ERE_OPT) -e "\\@^$(PREFIX_REGEX)(/|$$)@ p")) +$(error configured includedir ($(INCLUDEDIR)) is outside of prefix ($(PREFIX)), can't generate pkg-config file) +endif +endif + +libxxhash.pc: libxxhash.pc.in + @echo creating pkgconfig + $(Q)$(SED) $(SED_ERE_OPT) -e 's|@PREFIX@|$(PREFIX)|' \ + -e 's|@EXECPREFIX@|$(PCEXECDIR)|' \ + -e 's|@LIBDIR@|$(PCLIBDIR)|' \ + -e 's|@INCLUDEDIR@|$(PCINCDIR)|' \ + -e 's|@VERSION@|$(LIBVER)|' \ + $< > $@ + + +.PHONY: install +install: lib libxxhash.pc xxhsum ## install libraries, CLI, links and man page + @echo Installing libxxhash + $(Q)$(INSTALL) -d -m 755 $(DESTDIR)$(LIBDIR) + $(Q)$(INSTALL_DATA) libxxhash.a $(DESTDIR)$(LIBDIR) + $(Q)$(INSTALL_PROGRAM) $(LIBXXH) $(DESTDIR)$(LIBDIR) + $(Q)ln -sf $(LIBXXH) $(DESTDIR)$(LIBDIR)/libxxhash.$(SHARED_EXT_MAJOR) + $(Q)ln -sf $(LIBXXH) $(DESTDIR)$(LIBDIR)/libxxhash.$(SHARED_EXT) + $(Q)$(INSTALL) -d -m 755 $(DESTDIR)$(INCLUDEDIR) # includes + $(Q)$(INSTALL_DATA) xxhash.h $(DESTDIR)$(INCLUDEDIR) + $(Q)$(INSTALL_DATA) xxh3.h $(DESTDIR)$(INCLUDEDIR) # for compatibility, will be removed in v0.9.0 +ifeq ($(DISPATCH),1) + $(Q)$(INSTALL_DATA) xxh_x86dispatch.h $(DESTDIR)$(INCLUDEDIR) +endif + @echo Installing pkgconfig + $(Q)$(INSTALL) -d -m 755 $(DESTDIR)$(PKGCONFIGDIR)/ + $(Q)$(INSTALL_DATA) libxxhash.pc $(DESTDIR)$(PKGCONFIGDIR)/ + @echo Installing xxhsum + $(Q)$(INSTALL) -d -m 755 $(DESTDIR)$(BINDIR)/ $(DESTDIR)$(MANDIR)/ + $(Q)$(INSTALL_PROGRAM) xxhsum $(DESTDIR)$(BINDIR)/xxhsum + $(Q)ln -sf xxhsum $(DESTDIR)$(BINDIR)/xxh32sum + $(Q)ln -sf xxhsum $(DESTDIR)$(BINDIR)/xxh64sum + $(Q)ln -sf xxhsum $(DESTDIR)$(BINDIR)/xxh128sum + @echo Installing man pages + $(Q)$(INSTALL_DATA) $(MAN) $(DESTDIR)$(MANDIR)/xxhsum.1 + $(Q)ln -sf $(MAN) $(DESTDIR)$(MANDIR)/xxh32sum.1 + $(Q)ln -sf $(MAN) $(DESTDIR)$(MANDIR)/xxh64sum.1 + $(Q)ln -sf $(MAN) $(DESTDIR)$(MANDIR)/xxh128sum.1 + @echo xxhash installation completed + +.PHONY: uninstall +uninstall: ## uninstall libraries, CLI, links and man page + $(Q)$(RM) $(DESTDIR)$(LIBDIR)/libxxhash.a + $(Q)$(RM) $(DESTDIR)$(LIBDIR)/libxxhash.$(SHARED_EXT) + $(Q)$(RM) $(DESTDIR)$(LIBDIR)/libxxhash.$(SHARED_EXT_MAJOR) + $(Q)$(RM) $(DESTDIR)$(LIBDIR)/$(LIBXXH) + $(Q)$(RM) $(DESTDIR)$(INCLUDEDIR)/xxhash.h + $(Q)$(RM) $(DESTDIR)$(INCLUDEDIR)/xxh3.h + $(Q)$(RM) $(DESTDIR)$(INCLUDEDIR)/xxh_x86dispatch.h + $(Q)$(RM) $(DESTDIR)$(PKGCONFIGDIR)/libxxhash.pc + $(Q)$(RM) $(DESTDIR)$(BINDIR)/xxh32sum + $(Q)$(RM) $(DESTDIR)$(BINDIR)/xxh64sum + $(Q)$(RM) $(DESTDIR)$(BINDIR)/xxh128sum + $(Q)$(RM) $(DESTDIR)$(BINDIR)/xxhsum + $(Q)$(RM) $(DESTDIR)$(MANDIR)/xxh32sum.1 + $(Q)$(RM) $(DESTDIR)$(MANDIR)/xxh64sum.1 + $(Q)$(RM) $(DESTDIR)$(MANDIR)/xxh128sum.1 + $(Q)$(RM) $(DESTDIR)$(MANDIR)/xxhsum.1 + @echo xxhsum successfully uninstalled + +endif diff --git a/deps/xxHash/README.md b/deps/xxHash/README.md new file mode 100644 index 0000000000..18704f5300 --- /dev/null +++ b/deps/xxHash/README.md @@ -0,0 +1,237 @@ + +xxHash - Extremely fast hash algorithm +====================================== + +xxHash is an Extremely fast Hash algorithm, running at RAM speed limits. +It successfully completes the [SMHasher](https://code.google.com/p/smhasher/wiki/SMHasher) test suite +which evaluates collision, dispersion and randomness qualities of hash functions. +Code is highly portable, and hashes are identical across all platforms (little / big endian). + +|Branch |Status | +|------------|---------| +|dev | [![Build Status](https://github.com/Cyan4973/xxHash/actions/workflows/ci.yml/badge.svg?branch=dev)](https://github.com/Cyan4973/xxHash/actions?query=branch%3Adev+) | + + +Benchmarks +------------------------- + +The reference system uses an Intel i7-9700K cpu, and runs Ubuntu x64 20.04. +The [open source benchmark program] is compiled with `clang` v10.0 using `-O3` flag. + +| Hash Name | Width | Bandwidth (GB/s) | Small Data Velocity | Quality | Comment | +| --------- | ----- | ---------------- | ----- | --- | --- | +| __XXH3__ (SSE2) | 64 | 31.5 GB/s | 133.1 | 10 +| __XXH128__ (SSE2) | 128 | 29.6 GB/s | 118.1 | 10 +| _RAM sequential read_ | N/A | 28.0 GB/s | N/A | N/A | _for reference_ +| City64 | 64 | 22.0 GB/s | 76.6 | 10 +| T1ha2 | 64 | 22.0 GB/s | 99.0 | 9 | Slightly worse [collisions] +| City128 | 128 | 21.7 GB/s | 57.7 | 10 +| __XXH64__ | 64 | 19.4 GB/s | 71.0 | 10 +| SpookyHash | 64 | 19.3 GB/s | 53.2 | 10 +| Mum | 64 | 18.0 GB/s | 67.0 | 9 | Slightly worse [collisions] +| __XXH32__ | 32 | 9.7 GB/s | 71.9 | 10 +| City32 | 32 | 9.1 GB/s | 66.0 | 10 +| Murmur3 | 32 | 3.9 GB/s | 56.1 | 10 +| SipHash | 64 | 3.0 GB/s | 43.2 | 10 +| FNV64 | 64 | 1.2 GB/s | 62.7 | 5 | Poor avalanche properties +| Blake2 | 256 | 1.1 GB/s | 5.1 | 10 | Cryptographic +| SHA1 | 160 | 0.8 GB/s | 5.6 | 10 | Cryptographic but broken +| MD5 | 128 | 0.6 GB/s | 7.8 | 10 | Cryptographic but broken + +[open source benchmark program]: https://github.com/Cyan4973/xxHash/tree/release/tests/bench +[collisions]: https://github.com/Cyan4973/xxHash/wiki/Collision-ratio-comparison#collision-study + +note 1: Small data velocity is a _rough_ evaluation of algorithm's efficiency on small data. For more detailed analysis, please refer to next paragraph. + +note 2: some algorithms feature _faster than RAM_ speed. In which case, they can only reach their full speed when input data is already in CPU cache (L3 or better). Otherwise, they max out on RAM speed limit. + +### Small data + +Performance on large data is only one part of the picture. +Hashing is also very useful in constructions like hash tables and bloom filters. +In these use cases, it's frequent to hash a lot of small data (starting at a few bytes). +Algorithm's performance can be very different for such scenarios, since parts of the algorithm, +such as initialization or finalization, become fixed cost. +The impact of branch mis-prediction also becomes much more present. + +XXH3 has been designed for excellent performance on both long and small inputs, +which can be observed in the following graph: + +![XXH3, latency, random size](https://user-images.githubusercontent.com/750081/61976089-aedeab00-af9f-11e9-9239-e5375d6c080f.png) + +For a more detailed analysis, visit the wiki : +https://github.com/Cyan4973/xxHash/wiki/Performance-comparison#benchmarks-concentrating-on-small-data- + +Quality +------------------------- + +Speed is not the only property that matters. +Produced hash values must respect excellent dispersion and randomness properties, +so that any sub-section of it can be used to maximally spread out a table or index, +as well as reduce the amount of collisions to the minimal theoretical level, following the [birthday paradox]. + +`xxHash` has been tested with Austin Appleby's excellent SMHasher test suite, +and passes all tests, ensuring reasonable quality levels. +It also passes extended tests from [newer forks of SMHasher], featuring additional scenarios and conditions. + +Finally, xxHash provides its own [massive collision tester](https://github.com/Cyan4973/xxHash/tree/dev/tests/collisions), +able to generate and compare billions of hashes to test the limits of 64-bit hash algorithms. +On this front too, xxHash features good results, in line with the [birthday paradox]. +A more detailed analysis is documented [in the wiki](https://github.com/Cyan4973/xxHash/wiki/Collision-ratio-comparison). + +[birthday paradox]: https://en.wikipedia.org/wiki/Birthday_problem +[newer forks of SMHasher]: https://github.com/rurban/smhasher + + +### Build modifiers + +The following macros can be set at compilation time to modify libxxhash's behavior. They are generally disabled by default. + +- `XXH_INLINE_ALL`: Make all functions `inline`, with implementations being directly included within `xxhash.h`. + Inlining functions is beneficial for speed on small keys. + It's _extremely effective_ when key length is expressed as _a compile time constant_, + with performance improvements observed in the +200% range . + See [this article](https://fastcompression.blogspot.com/2018/03/xxhash-for-small-keys-impressive-power.html) for details. +- `XXH_PRIVATE_API`: same outcome as `XXH_INLINE_ALL`. Still available for legacy support. + The name underlines that `XXH_*` symbols will not be exported. +- `XXH_NAMESPACE`: Prefixes all symbols with the value of `XXH_NAMESPACE`. + This macro can only use compilable character set. + Useful to evade symbol naming collisions, + in case of multiple inclusions of xxHash's source code. + Client applications still use the regular function names, + as symbols are automatically translated through `xxhash.h`. +- `XXH_FORCE_MEMORY_ACCESS`: The default method `0` uses a portable `memcpy()` notation. + Method `1` uses a gcc-specific `packed` attribute, which can provide better performance for some targets. + Method `2` forces unaligned reads, which is not standards compliant, but might sometimes be the only way to extract better read performance. + Method `3` uses a byteshift operation, which is best for old compilers which don't inline `memcpy()` or big-endian systems without a byteswap instruction +- `XXH_FORCE_ALIGN_CHECK`: Use a faster direct read path when input is aligned. + This option can result in dramatic performance improvement when input to hash is aligned on 32 or 64-bit boundaries, + when running on architectures unable to load memory from unaligned addresses, or suffering a performance penalty from it. + It is (slightly) detrimental on platform with good unaligned memory access performance (same instruction for both aligned and unaligned accesses). + This option is automatically disabled on `x86`, `x64` and `aarch64`, and enabled on all other platforms. +- `XXH_VECTOR` : manually select a vector instruction set (default: auto-selected at compilation time). Available instruction sets are `XXH_SCALAR`, `XXH_SSE2`, `XXH_AVX2`, `XXH_AVX512`, `XXH_NEON` and `XXH_VSX`. Compiler may require additional flags to ensure proper support (for example, `gcc` on linux will require `-mavx2` for AVX2, and `-mavx512f` for AVX512). +- `XXH_NO_PREFETCH` : disable prefetching. XXH3 only. +- `XXH_PREFETCH_DIST` : select prefecting distance. XXH3 only. +- `XXH_NO_INLINE_HINTS`: By default, xxHash uses `__attribute__((always_inline))` and `__forceinline` to improve performance at the cost of code size. + Defining this macro to 1 will mark all internal functions as `static`, allowing the compiler to decide whether to inline a function or not. + This is very useful when optimizing for smallest binary size, + and is automatically defined when compiling with `-O0`, `-Os`, `-Oz`, or `-fno-inline` on GCC and Clang. + This may also increase performance depending on compiler and architecture. +- `XXH_REROLL`: Reduces the size of the generated code by not unrolling some loops. + Impact on performance may vary, depending on platform and algorithm. +- `XXH_ACCEPT_NULL_INPUT_POINTER`: if set to `1`, when input is a `NULL` pointer, + xxHash'd result is the same as a zero-length input + (instead of a dereference segfault). + Adds one branch at the beginning of each hash. +- `XXH_STATIC_LINKING_ONLY`: gives access to the state declaration for static allocation. + Incompatible with dynamic linking, due to risks of ABI changes. +- `XXH_NO_XXH3` : removes symbols related to `XXH3` (both 64 & 128 bits) from generated binary. + Useful to reduce binary size, notably for applications which do not use `XXH3`. +- `XXH_NO_LONG_LONG`: removes compilation of algorithms relying on 64-bit types (XXH3 and XXH64). Only XXH32 will be compiled. + Useful for targets (architectures and compilers) without 64-bit support. +- `XXH_IMPORT`: MSVC specific: should only be defined for dynamic linking, as it prevents linkage errors. +- `XXH_CPU_LITTLE_ENDIAN`: By default, endianess is determined by a runtime test resolved at compile time. + If, for some reason, the compiler cannot simplify the runtime test, it can cost performance. + It's possible to skip auto-detection and simply state that the architecture is little-endian by setting this macro to 1. + Setting it to 0 states big-endian. + +For the Command Line Interface `xxhsum`, the following environment variables can also be set : +- `DISPATCH=1` : use `xxh_x86dispatch.c`, to automatically select between `scalar`, `sse2`, `avx2` or `avx512` instruction set at runtime, depending on local host. This option is only valid for `x86`/`x64` systems. + + +### Building xxHash - Using vcpkg + +You can download and install xxHash using the [vcpkg](https://github.com/Microsoft/vcpkg) dependency manager: + + git clone https://github.com/Microsoft/vcpkg.git + cd vcpkg + ./bootstrap-vcpkg.sh + ./vcpkg integrate install + ./vcpkg install xxhash + +The xxHash port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg repository. + + +### Example + +The simplest example calls xxhash 64-bit variant as a one-shot function +generating a hash value from a single buffer, and invoked from a C/C++ program: + +```C +#include "xxhash.h" + + (...) + XXH64_hash_t hash = XXH64(buffer, size, seed); +} +``` + +Streaming variant is more involved, but makes it possible to provide data incrementally: + +```C +#include "stdlib.h" /* abort() */ +#include "xxhash.h" + + +XXH64_hash_t calcul_hash_streaming(FileHandler fh) +{ + /* create a hash state */ + XXH64_state_t* const state = XXH64_createState(); + if (state==NULL) abort(); + + size_t const bufferSize = SOME_SIZE; + void* const buffer = malloc(bufferSize); + if (buffer==NULL) abort(); + + /* Initialize state with selected seed */ + XXH64_hash_t const seed = 0; /* or any other value */ + if (XXH64_reset(state, seed) == XXH_ERROR) abort(); + + /* Feed the state with input data, any size, any number of times */ + (...) + while ( /* some data left */ ) { + size_t const length = get_more_data(buffer, bufferSize, fh); + if (XXH64_update(state, buffer, length) == XXH_ERROR) abort(); + (...) + } + (...) + + /* Produce the final hash value */ + XXH64_hash_t const hash = XXH64_digest(state); + + /* State could be re-used; but in this example, it is simply freed */ + free(buffer); + XXH64_freeState(state); + + return hash; +} +``` + + +### License + +The library files `xxhash.c` and `xxhash.h` are BSD licensed. +The utility `xxhsum` is GPL licensed. + + +### Other programming languages + +Beyond the C reference version, +xxHash is also available from many different programming languages, +thanks to great contributors. +They are [listed here](http://www.xxhash.com/#other-languages). + + +### Packaging status + +Many distributions bundle a package manager +which allows easy xxhash installation as both a `libxxhash` library +and `xxhsum` command line interface. + +[![Packaging status](https://repology.org/badge/vertical-allrepos/xxhash.svg)](https://repology.org/project/xxhash/versions) + + +### Special Thanks + +- Takayuki Matsuoka, aka @t-mat, for creating `xxhsum -c` and great support during early xxh releases +- Mathias Westerdahl, aka @JCash, for introducing the first version of `XXH64` +- Devin Hussey, aka @easyaspi314, for incredible low-level optimizations on `XXH3` and `XXH128` diff --git a/deps/xxHash/appveyor.yml b/deps/xxHash/appveyor.yml new file mode 100644 index 0000000000..7aef900fc2 --- /dev/null +++ b/deps/xxHash/appveyor.yml @@ -0,0 +1,115 @@ +#---------------------------------# +# general configuration # +#---------------------------------# +version: 1.0.{build} +max_jobs: 2 + +#---------------------------------# +# environment configuration # +#---------------------------------# +clone_depth: 2 +environment: + matrix: + - COMPILER: "visual" + ARCH: "x64" + TEST_XXHSUM: "true" + - COMPILER: "visual" + ARCH: "Win32" + TEST_XXHSUM: "true" + - COMPILER: "visual" + ARCH: "Win32" + APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013 + TEST_XXHSUM: "true" + - COMPILER: "visual" + ARCH: "ARM" +# Below tests are now disabled due to redundancy. +# Their equivalent already runs correctly on Github Actions. +# - COMPILER: "visual" +# ARCH: "x64" +# APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 +# TEST_XXHSUM: "true" +# - COMPILER: "visual" +# ARCH: "ARM64" +# APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 +# # note: ARM64 is not available with Visual Studio 14 2015, which is default for Appveyor + +# The following tests were also flacky on Appveyor, for various reasons. +# - COMPILER: "gcc" +# PLATFORM: "mingw64" +# - COMPILER: "gcc" +# PLATFORM: "mingw32" +# - COMPILER: "gcc" +# PLATFORM: "clang" + +install: + - ECHO Installing %COMPILER% %PLATFORM% %ARCH% + - MKDIR bin + - if [%COMPILER%]==[gcc] SET PATH_ORIGINAL=%PATH% + - if [%COMPILER%]==[gcc] ( + SET "PATH_MINGW32=c:\MinGW\bin;c:\MinGW\usr\bin" && + SET "PATH_MINGW64=c:\msys64\mingw64\bin;c:\msys64\usr\bin" && + COPY C:\MinGW\bin\mingw32-make.exe C:\MinGW\bin\make.exe && + COPY C:\MinGW\bin\gcc.exe C:\MinGW\bin\cc.exe + ) + +#---------------------------------# +# build configuration # +#---------------------------------# +build_script: + - if [%PLATFORM%]==[mingw32] SET PATH=%PATH_MINGW32%;%PATH_ORIGINAL% + - if [%PLATFORM%]==[mingw64] SET PATH=%PATH_MINGW64%;%PATH_ORIGINAL% + - if [%PLATFORM%]==[clang] SET PATH=%PATH_MINGW64%;%PATH_ORIGINAL% + - ECHO *** + - ECHO Building %COMPILER% %PLATFORM% %ARCH% + - ECHO *** + + - if [%COMPILER%]==[gcc] ( + if [%PLATFORM%]==[clang] ( + clang -v + ) ELSE ( + gcc -v + ) + ) + - if [%COMPILER%]==[gcc] ( + echo ----- && + make -v && + echo ----- && + if not [%PLATFORM%]==[clang] ( + if [%PLATFORM%]==[mingw32] ( SET CPPFLAGS=-DPOOL_MT=0 ) && + make -B clean test MOREFLAGS=-Werror + ) ELSE ( + SET CXXFLAGS=--std=c++14 && + make -B clean test CC=clang CXX=clang++ MOREFLAGS="--target=x86_64-w64-mingw32 -Werror -Wno-pass-failed" NO_C90_TEST=true + ) && + make -C tests/bench + ) + # note 1: strict c90 tests with clang fail, due to (erroneous) presence on `inline` keyword in some included system file + # note 2: multi-threading code doesn't work with mingw32, disabled through POOL_MT=0 + # note 3: clang requires C++14 to compile sort because its own code contains c++14-only code + + - if [%COMPILER%]==[visual] ( + cd cmake_unofficial && + cmake . -DCMAKE_BUILD_TYPE=Release -A %ARCH% -DXXHASH_C_FLAGS="/WX" && + cmake --build . --config Release + ) + +#---------------------------------# +# tests configuration # +#---------------------------------# +test_script: + # note: can only run x86 and x64 binaries on Appveyor + # note: if %COMPILER%==gcc, xxhsum was already tested within `make test` + - if [%TEST_XXHSUM%]==[true] ( + ECHO *** && + ECHO Testing %COMPILER% %PLATFORM% %ARCH% && + ECHO *** && + cd Release && + xxhsum.exe -bi1 && + ECHO ------- xxhsum tested ------- + ) + + +#---------------------------------# +# artifacts configuration # +#---------------------------------# +# none yet diff --git a/deps/xxHash/cli/xsum_arch.h b/deps/xxHash/cli/xsum_arch.h new file mode 100644 index 0000000000..cc39297972 --- /dev/null +++ b/deps/xxHash/cli/xsum_arch.h @@ -0,0 +1,153 @@ +/* + * xxhsum - Command line interface for xxhash algorithms + * Copyright (C) 2013-2020 Yann Collet + * + * GPL v2 License + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * You can contact the author at: + * - xxHash homepage: https://www.xxhash.com + * - xxHash source repository: https://github.com/Cyan4973/xxHash + */ + +/* + * Checks for predefined macros by the compiler to try and get both the arch + * and the compiler version. + */ +#ifndef XSUM_ARCH_H +#define XSUM_ARCH_H + +#include "xsum_config.h" + +#define XSUM_LIB_VERSION XXH_VERSION_MAJOR.XXH_VERSION_MINOR.XXH_VERSION_RELEASE +#define XSUM_QUOTE(str) #str +#define XSUM_EXPAND_AND_QUOTE(str) XSUM_QUOTE(str) +#define XSUM_PROGRAM_VERSION XSUM_EXPAND_AND_QUOTE(XSUM_LIB_VERSION) + + +/* Show compiler versions in WELCOME_MESSAGE. XSUM_CC_VERSION_FMT will return the printf specifiers, + * and VERSION will contain the comma separated list of arguments to the XSUM_CC_VERSION_FMT string. */ +#if defined(__clang_version__) +/* Clang does its own thing. */ +# ifdef __apple_build_version__ +# define XSUM_CC_VERSION_FMT "Apple Clang %s" +# else +# define XSUM_CC_VERSION_FMT "Clang %s" +# endif +# define XSUM_CC_VERSION __clang_version__ +#elif defined(__VERSION__) +/* GCC and ICC */ +# define XSUM_CC_VERSION_FMT "%s" +# ifdef __INTEL_COMPILER /* icc adds its prefix */ +# define XSUM_CC_VERSION __VERSION__ +# else /* assume GCC */ +# define XSUM_CC_VERSION "GCC " __VERSION__ +# endif +#elif defined(_MSC_FULL_VER) && defined(_MSC_BUILD) +/* + * MSVC + * "For example, if the version number of the Visual C++ compiler is + * 15.00.20706.01, the _MSC_FULL_VER macro evaluates to 150020706." + * + * https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=vs-2017 + */ +# define XSUM_CC_VERSION_FMT "MSVC %02i.%02i.%05i.%02i" +# define XSUM_CC_VERSION _MSC_FULL_VER / 10000000 % 100, _MSC_FULL_VER / 100000 % 100, _MSC_FULL_VER % 100000, _MSC_BUILD +#elif defined(_MSC_VER) /* old MSVC */ +# define XSUM_CC_VERSION_FMT "MSVC %02i.%02i" +# define XSUM_CC_VERSION _MSC_VER / 100, _MSC_VER % 100 +#elif defined(__TINYC__) +/* tcc stores its version in the __TINYC__ macro. */ +# define XSUM_CC_VERSION_FMT "tcc %i.%i.%i" +# define XSUM_CC_VERSION __TINYC__ / 10000 % 100, __TINYC__ / 100 % 100, __TINYC__ % 100 +#else +# define XSUM_CC_VERSION_FMT "%s" +# define XSUM_CC_VERSION "unknown compiler" +#endif + +/* makes the next part easier */ +#if defined(__x86_64__) || defined(_M_AMD64) || defined(_M_X64) +# define XSUM_ARCH_X64 1 +# define XSUM_ARCH_X86 "x86_64" +#elif defined(__i386__) || defined(_M_IX86) || defined(_M_IX86_FP) +# define XSUM_ARCH_X86 "i386" +#endif + +/* Try to detect the architecture. */ +#if defined(XSUM_ARCH_X86) +# if defined(XXHSUM_DISPATCH) +# define XSUM_ARCH XSUM_ARCH_X86 " autoVec" +# elif defined(__AVX512F__) +# define XSUM_ARCH XSUM_ARCH_X86 " + AVX512" +# elif defined(__AVX2__) +# define XSUM_ARCH XSUM_ARCH_X86 " + AVX2" +# elif defined(__AVX__) +# define XSUM_ARCH XSUM_ARCH_X86 " + AVX" +# elif defined(_M_X64) || defined(_M_AMD64) || defined(__x86_64__) \ + || defined(__SSE2__) || (defined(_M_IX86_FP) && _M_IX86_FP == 2) +# define XSUM_ARCH XSUM_ARCH_X86 " + SSE2" +# else +# define XSUM_ARCH XSUM_ARCH_X86 +# endif +#elif defined(__aarch64__) || defined(__arm64__) || defined(_M_ARM64) +# define XSUM_ARCH "aarch64 + NEON" +#elif defined(__arm__) || defined(__thumb__) || defined(__thumb2__) || defined(_M_ARM) +/* ARM has a lot of different features that can change xxHash significantly. */ +# if defined(__thumb2__) || (defined(__thumb__) && (__thumb__ == 2 || __ARM_ARCH >= 7)) +# define XSUM_ARCH_THUMB " Thumb-2" +# elif defined(__thumb__) +# define XSUM_ARCH_THUMB " Thumb-1" +# else +# define XSUM_ARCH_THUMB "" +# endif +/* ARMv7 has unaligned by default */ +# if defined(__ARM_FEATURE_UNALIGNED) || __ARM_ARCH >= 7 || defined(_M_ARMV7VE) +# define XSUM_ARCH_UNALIGNED " + unaligned" +# else +# define XSUM_ARCH_UNALIGNED "" +# endif +# if defined(__ARM_NEON) || defined(__ARM_NEON__) +# define XSUM_ARCH_NEON " + NEON" +# else +# define XSUM_ARCH_NEON "" +# endif +# define XSUM_ARCH "ARMv" XSUM_EXPAND_AND_QUOTE(__ARM_ARCH) XSUM_ARCH_THUMB XSUM_ARCH_NEON XSUM_ARCH_UNALIGNED +#elif defined(__powerpc64__) || defined(__ppc64__) || defined(__PPC64__) +# if defined(__GNUC__) && defined(__POWER9_VECTOR__) +# define XSUM_ARCH "ppc64 + POWER9 vector" +# elif defined(__GNUC__) && defined(__POWER8_VECTOR__) +# define XSUM_ARCH "ppc64 + POWER8 vector" +# else +# define XSUM_ARCH "ppc64" +# endif +#elif defined(__powerpc__) || defined(__ppc__) || defined(__PPC__) +# define XSUM_ARCH "ppc" +#elif defined(__AVR) +# define XSUM_ARCH "AVR" +#elif defined(__mips64) +# define XSUM_ARCH "mips64" +#elif defined(__mips) +# define XSUM_ARCH "mips" +#elif defined(__s390x__) +# define XSUM_ARCH "s390x" +#elif defined(__s390__) +# define XSUM_ARCH "s390" +#else +# define XSUM_ARCH "unknown" +#endif + + +#endif /* XSUM_ARCH_H */ diff --git a/deps/xxHash/cli/xsum_config.h b/deps/xxHash/cli/xsum_config.h new file mode 100644 index 0000000000..9222144d0e --- /dev/null +++ b/deps/xxHash/cli/xsum_config.h @@ -0,0 +1,205 @@ +/* + * xxhsum - Command line interface for xxhash algorithms + * Copyright (C) 2013-2020 Yann Collet + * + * GPL v2 License + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * You can contact the author at: + * - xxHash homepage: https://www.xxhash.com + * - xxHash source repository: https://github.com/Cyan4973/xxHash + */ + +/* + * This contains various configuration parameters and feature detection for + * xxhsum. + * + * Similar to config.h in Autotools, this should be the first header included. + */ + +#ifndef XSUM_CONFIG_H +#define XSUM_CONFIG_H + + +/* ************************************ + * Compiler Options + **************************************/ +/* + * Disable Visual C's warnings when using the "insecure" CRT functions instead + * of the "secure" _s functions. + * + * These functions are not portable, and aren't necessary if you are using the + * original functions properly. + */ +#if defined(_MSC_VER) || defined(_WIN32) +# ifndef _CRT_SECURE_NO_WARNINGS +# define _CRT_SECURE_NO_WARNINGS +# endif +#endif + +/* Under Linux at least, pull in the *64 commands */ +#ifndef _LARGEFILE64_SOURCE +# define _LARGEFILE64_SOURCE +#endif +#ifndef _FILE_OFFSET_BITS +# define _FILE_OFFSET_BITS 64 +#endif + +/* + * So we can use __attribute__((__format__)) + */ +#ifdef __GNUC__ +# define XSUM_ATTRIBUTE(x) __attribute__(x) +#else +# define XSUM_ATTRIBUTE(x) +#endif + +#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)) /* UNIX-like OS */ \ + || defined(__midipix__) || defined(__VMS)) +# if (defined(__APPLE__) && defined(__MACH__)) || defined(__SVR4) || defined(_AIX) || defined(__hpux) /* POSIX.1-2001 (SUSv3) conformant */ \ + || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) /* BSD distros */ +# define XSUM_PLATFORM_POSIX_VERSION 200112L +# else +# if defined(__linux__) || defined(__linux) +# ifndef _POSIX_C_SOURCE +# define _POSIX_C_SOURCE 200112L /* use feature test macro */ +# endif +# endif +# include /* declares _POSIX_VERSION */ +# if defined(_POSIX_VERSION) /* POSIX compliant */ +# define XSUM_PLATFORM_POSIX_VERSION _POSIX_VERSION +# else +# define XSUM_PLATFORM_POSIX_VERSION 0 +# endif +# endif +#endif +#if !defined(XSUM_PLATFORM_POSIX_VERSION) +# define XSUM_PLATFORM_POSIX_VERSION -1 +#endif + +#if !defined(S_ISREG) +# define S_ISREG(x) (((x) & S_IFMT) == S_IFREG) +#endif + + +/* ************************************ + * Windows helpers + **************************************/ + +/* + * Whether to use the Windows UTF-16 APIs instead of the portable libc 8-bit + * ("ANSI") APIs. + * + * Windows is not UTF-8 clean by default, and the only way to access every file + * on the OS is to use UTF-16. + * + * Do note that xxhsum uses UTF-8 internally and only uses UTF-16 for command + * line arguments, console I/O, and opening files. + * + * Additionally, this guarantees all piped output is UTF-8. + */ +#if defined(XSUM_WIN32_USE_WCHAR) && !defined(_WIN32) +/* We use Windows APIs, only use this on Windows. */ +# undef XSUM_WIN32_USE_WCHAR +#endif + +#ifndef XSUM_WIN32_USE_WCHAR +# if defined(_WIN32) +# include +# if WCHAR_MAX == 0xFFFFU /* UTF-16 wchar_t */ +# define XSUM_WIN32_USE_WCHAR 1 +# else +# define XSUM_WIN32_USE_WCHAR 0 +# endif +# else +# define XSUM_WIN32_USE_WCHAR 0 +# endif +#endif + +#if !XSUM_WIN32_USE_WCHAR +/* + * It doesn't make sense to have one without the other. + * Due to XSUM_WIN32_USE_WCHAR being undef'd, this also handles + * non-WIN32 platforms. + */ +# undef XSUM_WIN32_USE_WMAIN +# define XSUM_WIN32_USE_WMAIN 0 +#else +/* + * Whether to use wmain() or main(). + * + * wmain() is preferred because we don't have to mess with internal hidden + * APIs. + * + * It always works on MSVC, but in MinGW, it only works on MinGW-w64 with the + * -municode flag. + * + * Therefore we have to use main() -- there is no better option. + */ +# ifndef XSUM_WIN32_USE_WMAIN +# if defined(_UNICODE) || defined(UNICODE) /* MinGW -municode */ \ + || defined(_MSC_VER) /* MSVC */ +# define XSUM_WIN32_USE_WMAIN 1 +# else +# define XSUM_WIN32_USE_WMAIN 0 +# endif +# endif +/* + * It is always good practice to define these to prevent accidental use of the + * ANSI APIs, even if the program primarily uses UTF-8. + */ +# ifndef _UNICODE +# define _UNICODE +# endif +# ifndef UNICODE +# define UNICODE +# endif +#endif /* XSUM_WIN32_USE_WCHAR */ + +#ifndef XSUM_API +# ifdef XXH_INLINE_ALL +# define XSUM_API static +# else +# define XSUM_API +# endif +#endif + +#ifndef XSUM_NO_TESTS +# define XSUM_NO_TESTS 0 +#endif + +/* *************************** + * Basic types + * ***************************/ + +#if defined(__cplusplus) /* C++ */ \ + || (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) /* C99 */ +# include + typedef uint8_t XSUM_U8; + typedef uint32_t XSUM_U32; + typedef uint64_t XSUM_U64; +# else +# include + typedef unsigned char XSUM_U8; +# if UINT_MAX == 0xFFFFFFFFUL + typedef unsigned int XSUM_U32; +# else + typedef unsigned long XSUM_U32; +# endif + typedef unsigned long long XSUM_U64; +#endif /* not C++/C99 */ + +#endif /* XSUM_CONFIG_H */ diff --git a/deps/xxHash/cli/xsum_os_specific.c b/deps/xxHash/cli/xsum_os_specific.c new file mode 100644 index 0000000000..8f48ce0762 --- /dev/null +++ b/deps/xxHash/cli/xsum_os_specific.c @@ -0,0 +1,487 @@ +/* + * xxhsum - Command line interface for xxhash algorithms + * Copyright (C) 2013-2020 Yann Collet + * + * GPL v2 License + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * You can contact the author at: + * - xxHash homepage: https://www.xxhash.com + * - xxHash source repository: https://github.com/Cyan4973/xxHash + */ + +#include "xsum_config.h" +#include "xsum_os_specific.h" +#include +#include +#include +#include /* struct stat / __wstat64 */ +#include /* stat() / _stat64() */ + +/* + * This file contains all of the ugly boilerplate to make xxhsum work across + * platforms. + */ +#if defined(_MSC_VER) || XSUM_WIN32_USE_WCHAR + typedef struct __stat64 XSUM_stat_t; +# if defined(_MSC_VER) + typedef int mode_t; +# endif +#else + typedef struct stat XSUM_stat_t; +#endif + +#if (defined(__linux__) && (XSUM_PLATFORM_POSIX_VERSION >= 1)) \ + || (XSUM_PLATFORM_POSIX_VERSION >= 200112L) \ + || defined(__DJGPP__) \ + || defined(__MSYS__) +# include /* isatty */ +# define XSUM_IS_CONSOLE(stdStream) isatty(fileno(stdStream)) +#elif defined(MSDOS) || defined(OS2) +# include /* _isatty */ +# define XSUM_IS_CONSOLE(stdStream) _isatty(_fileno(stdStream)) +#elif defined(WIN32) || defined(_WIN32) +# include /* _isatty */ +# include /* DeviceIoControl, HANDLE, FSCTL_SET_SPARSE */ +# include /* FILE */ +static __inline int XSUM_IS_CONSOLE(FILE* stdStream) +{ + DWORD dummy; + return _isatty(_fileno(stdStream)) && GetConsoleMode((HANDLE)_get_osfhandle(_fileno(stdStream)), &dummy); +} +#else +# define XSUM_IS_CONSOLE(stdStream) 0 +#endif + +#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(_WIN32) +# include /* _O_BINARY */ +# include /* _setmode, _fileno, _get_osfhandle */ +# if !defined(__DJGPP__) +# include /* DeviceIoControl, HANDLE, FSCTL_SET_SPARSE */ +# include /* FSCTL_SET_SPARSE */ +# define XSUM_SET_BINARY_MODE(file) { int const unused=_setmode(_fileno(file), _O_BINARY); (void)unused; } +# else +# define XSUM_SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY) +# endif +#else +# define XSUM_SET_BINARY_MODE(file) ((void)file) +#endif + +XSUM_API int XSUM_isConsole(FILE* stream) +{ + return XSUM_IS_CONSOLE(stream); +} + +XSUM_API void XSUM_setBinaryMode(FILE* stream) +{ + XSUM_SET_BINARY_MODE(stream); +} + +#if !XSUM_WIN32_USE_WCHAR + +XSUM_API FILE* XSUM_fopen(const char* filename, const char* mode) +{ + return fopen(filename, mode); +} +XSUM_ATTRIBUTE((__format__(__printf__, 2, 0))) +XSUM_API int XSUM_vfprintf(FILE* stream, const char* format, va_list ap) +{ + return vfprintf(stream, format, ap); +} + +static int XSUM_stat(const char* infilename, XSUM_stat_t* statbuf) +{ +#if defined(_MSC_VER) + return _stat64(infilename, statbuf); +#else + return stat(infilename, statbuf); +#endif +} + +#ifndef XSUM_NO_MAIN +int main(int argc, char* argv[]) +{ + return XSUM_main(argc, argv); +} +#endif + +/* Unicode helpers for Windows to make UTF-8 act as it should. */ +#else +# include +# include + +/***************************************************************************** + * Unicode conversion tools + *****************************************************************************/ + +/* + * Converts a UTF-8 string to UTF-16. Acts like strdup. The string must be freed afterwards. + * This version allows keeping the output length. + */ +static wchar_t* XSUM_widenString(const char* str, int* lenOut) +{ + int const len = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0); + if (lenOut != NULL) *lenOut = len; + if (len == 0) return NULL; + { wchar_t* buf = (wchar_t*)malloc((size_t)len * sizeof(wchar_t)); + if (buf != NULL) { + if (MultiByteToWideChar(CP_UTF8, 0, str, -1, buf, len) == 0) { + free(buf); + return NULL; + } } + return buf; + } +} + +/* + * Converts a UTF-16 string to UTF-8. Acts like strdup. The string must be freed afterwards. + * This version allows keeping the output length. + */ +static char* XSUM_narrowString(const wchar_t *str, int *lenOut) +{ + int len = WideCharToMultiByte(CP_UTF8, 0, str, -1, NULL, 0, NULL, NULL); + if (lenOut != NULL) *lenOut = len; + if (len == 0) return NULL; + { char* const buf = (char*)malloc((size_t)len * sizeof(char)); + if (buf != NULL) { + if (WideCharToMultiByte(CP_UTF8, 0, str, -1, buf, len, NULL, NULL) == 0) { + free(buf); + return NULL; + } } + return buf; + } +} + + + +/***************************************************************************** + * File helpers + *****************************************************************************/ +/* + * fopen wrapper that supports UTF-8 + * + * fopen will only accept ANSI filenames, which means that we can't open Unicode filenames. + * + * In order to open a Unicode filename, we need to convert filenames to UTF-16 and use _wfopen. + */ +XSUM_API FILE* XSUM_fopen(const char* filename, const char* mode) +{ + FILE* f = NULL; + wchar_t* const wide_filename = XSUM_widenString(filename, NULL); + if (wide_filename != NULL) { + wchar_t* const wide_mode = XSUM_widenString(mode, NULL); + if (wide_mode != NULL) { + f = _wfopen(wide_filename, wide_mode); + free(wide_mode); + } + free(wide_filename); + } + return f; +} + +/* + * stat() wrapper which supports UTF-8 filenames. + */ +static int XSUM_stat(const char* infilename, XSUM_stat_t* statbuf) +{ + int r = -1; + wchar_t* const wide_filename = XSUM_widenString(infilename, NULL); + if (wide_filename != NULL) { + r = _wstat64(wide_filename, statbuf); + free(wide_filename); + } + return r; +} + +/* + * In case it isn't available, this is what MSVC 2019 defines in stdarg.h. + */ +#if defined(_MSC_VER) && !defined(__clang__) && !defined(va_copy) +# define XSUM_va_copy(destination, source) ((destination) = (source)) +#else +# define XSUM_va_copy(destination, source) va_copy(destination, source) +#endif + +/* + * vasprintf for Windows. + */ +XSUM_ATTRIBUTE((__format__(__printf__, 2, 0))) +static int XSUM_vasprintf(char** strp, const char* format, va_list ap) +{ + int ret; + int size; + va_list copy; + /* + * To be safe, make a va_copy. + * + * Note that Microsoft doesn't use va_copy in its sample code: + * https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/vsprintf-vsprintf-l-vswprintf-vswprintf-l-vswprintf-l?view=vs-2019 + */ + XSUM_va_copy(copy, ap); + /* Calculate how many characters we need */ + size = _vscprintf(format, ap); + va_end(copy); + + if (size < 0) { + *strp = NULL; + return size; + } else { + *strp = (char*) malloc((size_t)size + 1); + if (*strp == NULL) { + return -1; + } + /* vsprintf into the new buffer */ + ret = vsprintf(*strp, format, ap); + if (ret < 0) { + free(*strp); + *strp = NULL; + } + return ret; + } +} + +/* + * fprintf wrapper that supports UTF-8. + * + * fprintf doesn't properly handle Unicode on Windows. + * + * Additionally, it is codepage sensitive on console and may crash the program. + * + * Instead, we use vsnprintf, and either print with fwrite or convert to UTF-16 + * for console output and use the codepage-independent WriteConsoleW. + * + * Credit to t-mat: https://github.com/t-mat/xxHash/commit/5691423 + */ +XSUM_ATTRIBUTE((__format__(__printf__, 2, 0))) +XSUM_API int XSUM_vfprintf(FILE *stream, const char *format, va_list ap) +{ + int result; + char* u8_str = NULL; + + /* + * Generate the UTF-8 output string with vasprintf. + */ + result = XSUM_vasprintf(&u8_str, format, ap); + + if (result >= 0) { + const size_t nchar = (size_t)result + 1; + + /* + * Check if we are outputting to a console. Don't use XSUM_isConsole + * directly -- we don't need to call _get_osfhandle twice. + */ + int fileNb = _fileno(stream); + intptr_t handle_raw = _get_osfhandle(fileNb); + HANDLE handle = (HANDLE)handle_raw; + DWORD dwTemp; + + if (handle_raw < 0) { + result = -1; + } else if (_isatty(fileNb) && GetConsoleMode(handle, &dwTemp)) { + /* + * Convert to UTF-16 and output with WriteConsoleW. + * + * This is codepage independent and works on Windows XP's default + * msvcrt.dll. + */ + int len; + wchar_t* const u16_buf = XSUM_widenString(u8_str, &len); + if (u16_buf == NULL) { + result = -1; + } else { + if (WriteConsoleW(handle, u16_buf, (DWORD)len - 1, &dwTemp, NULL)) { + result = (int)dwTemp; + } else { + result = -1; + } + free(u16_buf); + } + } else { + /* fwrite the UTF-8 string if we are printing to a file */ + result = (int)fwrite(u8_str, 1, nchar - 1, stream); + if (result == 0) { + result = -1; + } + } + free(u8_str); + } + return result; +} + +#ifndef XSUM_NO_MAIN +/***************************************************************************** + * Command Line argument parsing + *****************************************************************************/ + +/* Converts a UTF-16 argv to UTF-8. */ +static char** XSUM_convertArgv(int argc, wchar_t* utf16_argv[]) +{ + char** const utf8_argv = (char**)malloc((size_t)(argc + 1) * sizeof(char*)); + if (utf8_argv != NULL) { + int i; + for (i = 0; i < argc; i++) { + utf8_argv[i] = XSUM_narrowString(utf16_argv[i], NULL); + if (utf8_argv[i] == NULL) { + /* Out of memory, whoops. */ + while (i-- > 0) { + free(utf8_argv[i]); + } + free(utf8_argv); + return NULL; + } + } + utf8_argv[argc] = NULL; + } + return utf8_argv; +} +/* Frees arguments returned by XSUM_convertArgv */ +static void XSUM_freeArgv(int argc, char** argv) +{ + int i; + if (argv == NULL) { + return; + } + for (i = 0; i < argc; i++) { + free(argv[i]); + } + free(argv); +} + +static int XSUM_wmain(int argc, wchar_t* utf16_argv[]) +{ + /* Convert the UTF-16 arguments to UTF-8. */ + char** utf8_argv = XSUM_convertArgv(argc, utf16_argv); + + if (utf8_argv == NULL) { + /* An unfortunate but incredibly unlikely error. */ + fprintf(stderr, "xxhsum: error converting command line arguments!\n"); + abort(); + } else { + int ret; + + /* + * MinGW's terminal uses full block buffering for stderr. + * + * This is nonstandard behavior and causes text to not display until + * the buffer fills. + * + * `setvbuf()` can easily correct this to make text display instantly. + */ + setvbuf(stderr, NULL, _IONBF, 0); + + /* Call our real main function */ + ret = XSUM_main(argc, utf8_argv); + + /* Cleanup */ + XSUM_freeArgv(argc, utf8_argv); + return ret; + } +} + +#if XSUM_WIN32_USE_WMAIN + +/* + * The preferred method of obtaining the real UTF-16 arguments. Always works + * on MSVC, sometimes works on MinGW-w64 depending on the compiler flags. + */ +#ifdef __cplusplus +extern "C" +#endif +int __cdecl wmain(int argc, wchar_t* utf16_argv[]) +{ + return XSUM_wmain(argc, utf16_argv); +} +#else /* !XSUM_WIN32_USE_WMAIN */ + +/* + * Wrap `XSUM_wmain()` using `main()` and `__wgetmainargs()` on MinGW without + * Unicode support. + * + * `__wgetmainargs()` is used in the CRT startup to retrieve the arguments for + * `wmain()`, so we use it on MinGW to emulate `wmain()`. + * + * It is an internal function and not declared in any public headers, so we + * have to declare it manually. + * + * An alternative that doesn't mess with internal APIs is `GetCommandLineW()` + * with `CommandLineToArgvW()`, but the former doesn't expand wildcards and the + * latter requires linking to Shell32.dll and its numerous dependencies. + * + * This method keeps our dependencies to kernel32.dll and the CRT. + * + * https://docs.microsoft.com/en-us/cpp/c-runtime-library/getmainargs-wgetmainargs?view=vs-2019 + */ +typedef struct { + int newmode; +} _startupinfo; + +#ifdef __cplusplus +extern "C" +#endif +int __cdecl __wgetmainargs( + int* Argc, + wchar_t*** Argv, + wchar_t*** Env, + int DoWildCard, + _startupinfo* StartInfo +); + +int main(int ansi_argc, char* ansi_argv[]) +{ + int utf16_argc; + wchar_t** utf16_argv; + wchar_t** utf16_envp; /* Unused but required */ + _startupinfo startinfo = {0}; /* 0 == don't change new mode */ + + /* Get wmain's UTF-16 arguments. Make sure we expand wildcards. */ + if (__wgetmainargs(&utf16_argc, &utf16_argv, &utf16_envp, 1, &startinfo) < 0) + /* In the very unlikely case of an error, use the ANSI arguments. */ + return XSUM_main(ansi_argc, ansi_argv); + + /* Call XSUM_wmain with our UTF-16 arguments */ + return XSUM_wmain(utf16_argc, utf16_argv); +} + +#endif /* !XSUM_WIN32_USE_WMAIN */ +#endif /* !XSUM_NO_MAIN */ +#endif /* XSUM_WIN32_USE_WCHAR */ + + +/* + * Determines whether the file at filename is a directory. + */ +XSUM_API int XSUM_isDirectory(const char* filename) +{ + XSUM_stat_t statbuf; + int r = XSUM_stat(filename, &statbuf); +#ifdef _MSC_VER + if (!r && (statbuf.st_mode & _S_IFDIR)) return 1; +#else + if (!r && S_ISDIR(statbuf.st_mode)) return 1; +#endif + return 0; +} + +/* + * Returns the filesize of the file at filename. + */ +XSUM_API XSUM_U64 XSUM_getFileSize(const char* filename) +{ + XSUM_stat_t statbuf; + int r = XSUM_stat(filename, &statbuf); + if (r || !S_ISREG(statbuf.st_mode)) return 0; /* No good... */ + return (XSUM_U64)statbuf.st_size; +} diff --git a/deps/xxHash/cli/xsum_os_specific.h b/deps/xxHash/cli/xsum_os_specific.h new file mode 100644 index 0000000000..b3562b260d --- /dev/null +++ b/deps/xxHash/cli/xsum_os_specific.h @@ -0,0 +1,89 @@ +/* + * xxhsum - Command line interface for xxhash algorithms + * Copyright (C) 2013-2020 Yann Collet + * + * GPL v2 License + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * You can contact the author at: + * - xxHash homepage: https://www.xxhash.com + * - xxHash source repository: https://github.com/Cyan4973/xxHash + */ + +#ifndef XSUM_OS_SPECIFIC_H +#define XSUM_OS_SPECIFIC_H + +#include "xsum_config.h" +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Declared here to be implemented in user code. + * + * Functions like main(), but is passed UTF-8 arguments even on Windows. + */ +XSUM_API int XSUM_main(int argc, char* argv[]); + +/* + * Returns whether stream is a console. + * + * Functionally equivalent to isatty(fileno(stream)). + */ +XSUM_API int XSUM_isConsole(FILE* stream); + +/* + * Sets stream to pure binary mode (a.k.a. no CRLF conversions). + */ +XSUM_API void XSUM_setBinaryMode(FILE* stream); + +/* + * Returns whether the file at filename is a directory. + */ +XSUM_API int XSUM_isDirectory(const char* filename); + +/* + * Returns the file size of the file at filename. + */ +XSUM_API XSUM_U64 XSUM_getFileSize(const char* filename); + +/* + * UTF-8 stdio wrappers primarily for Windows + */ + +/* + * fopen() wrapper. Accepts UTF-8 filenames on Windows. + * + * Specifically, on Windows, the arguments will be converted to UTF-16 + * and passed to _wfopen(). + */ +XSUM_API FILE* XSUM_fopen(const char* filename, const char* mode); + +/* + * vfprintf() wrapper which prints UTF-8 strings to Windows consoles + * if applicable. + */ +XSUM_ATTRIBUTE((__format__(__printf__, 2, 0))) +XSUM_API int XSUM_vfprintf(FILE* stream, const char* format, va_list ap); + +#ifdef __cplusplus +} +#endif + +#endif /* XSUM_OS_SPECIFIC_H */ diff --git a/deps/xxHash/cli/xsum_output.c b/deps/xxHash/cli/xsum_output.c new file mode 100644 index 0000000000..a4d741154d --- /dev/null +++ b/deps/xxHash/cli/xsum_output.c @@ -0,0 +1,67 @@ +/* + * xxhsum - Command line interface for xxhash algorithms + * Copyright (C) 2013-2020 Yann Collet + * + * GPL v2 License + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * You can contact the author at: + * - xxHash homepage: https://www.xxhash.com + * - xxHash source repository: https://github.com/Cyan4973/xxHash + */ + +#include "xsum_output.h" +#include "xsum_os_specific.h" +#include + +int XSUM_logLevel = 2; + +XSUM_ATTRIBUTE((__format__(__printf__, 1, 2))) +XSUM_API int XSUM_log(const char* format, ...) +{ + int ret; + va_list ap; + va_start(ap, format); + ret = XSUM_vfprintf(stderr, format, ap); + va_end(ap); + return ret; +} + + +XSUM_ATTRIBUTE((__format__(__printf__, 1, 2))) +XSUM_API int XSUM_output(const char* format, ...) +{ + int ret; + va_list ap; + va_start(ap, format); + ret = XSUM_vfprintf(stdout, format, ap); + va_end(ap); + return ret; +} + +XSUM_ATTRIBUTE((__format__(__printf__, 2, 3))) +XSUM_API int XSUM_logVerbose(int minLevel, const char* format, ...) +{ + if (XSUM_logLevel >= minLevel) { + int ret; + va_list ap; + va_start(ap, format); + ret = XSUM_vfprintf(stderr, format, ap); + va_end(ap); + return ret; + } + return 0; +} diff --git a/deps/xxHash/cli/xsum_output.h b/deps/xxHash/cli/xsum_output.h new file mode 100644 index 0000000000..8a02c1b777 --- /dev/null +++ b/deps/xxHash/cli/xsum_output.h @@ -0,0 +1,62 @@ +/* + * xxhsum - Command line interface for xxhash algorithms + * Copyright (C) 2013-2020 Yann Collet + * + * GPL v2 License + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * You can contact the author at: + * - xxHash homepage: https://www.xxhash.com + * - xxHash source repository: https://github.com/Cyan4973/xxHash + */ + +#ifndef XSUM_OUTPUT_H +#define XSUM_OUTPUT_H + +#include "xsum_config.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * How verbose the output is. + */ +extern int XSUM_logLevel; + +/* + * Same as fprintf(stderr, format, ...) + */ +XSUM_ATTRIBUTE((__format__(__printf__, 1, 2))) +XSUM_API int XSUM_log(const char *format, ...); + +/* + * Like XSUM_log, but only outputs if XSUM_logLevel >= minLevel. + */ +XSUM_ATTRIBUTE((__format__(__printf__, 2, 3))) +XSUM_API int XSUM_logVerbose(int minLevel, const char *format, ...); + +/* + * Same as printf(format, ...) + */ +XSUM_ATTRIBUTE((__format__(__printf__, 1, 2))) +XSUM_API int XSUM_output(const char *format, ...); + +#ifdef __cplusplus +} +#endif + +#endif /* XSUM_OUTPUT_H */ diff --git a/deps/xxHash/cli/xsum_sanity_check.c b/deps/xxHash/cli/xsum_sanity_check.c new file mode 100644 index 0000000000..347d1db58e --- /dev/null +++ b/deps/xxHash/cli/xsum_sanity_check.c @@ -0,0 +1,602 @@ +/* + * xxhsum - Command line interface for xxhash algorithms + * Copyright (C) 2013-2020 Yann Collet + * + * GPL v2 License + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * You can contact the author at: + * - xxHash homepage: https://www.xxhash.com + * - xxHash source repository: https://github.com/Cyan4973/xxHash + */ + +#include "xsum_config.h" +#include "xsum_sanity_check.h" +#include "xsum_output.h" +#include +#include +#include +#ifndef XXH_STATIC_LINKING_ONLY +# define XXH_STATIC_LINKING_ONLY +#endif +#include "../xxhash.h" + +/* use #define to make them constant, required for initialization */ +#define PRIME32 2654435761U +#define PRIME64 11400714785074694797ULL + +/* + * Fills a test buffer with pseudorandom data. + * + * This is used in the sanity check - its values must not be changed. + */ +XSUM_API void XSUM_fillTestBuffer(XSUM_U8* buffer, size_t len) +{ + XSUM_U64 byteGen = PRIME32; + size_t i; + + assert(buffer != NULL); + + for (i=0; i>56); + byteGen *= PRIME64; + } +} + + + +/* ************************************************ + * Self-test: + * ensure results consistency accross platforms + *********************************************** */ +#if XSUM_NO_TESTS +XSUM_API void XSUM_sanityCheck(void) +{ + XSUM_log("This version of xxhsum is not verified.\n"); +} +#else + +/* + * Test data vectors + */ +typedef struct { + XSUM_U32 len; + XSUM_U32 seed; + XSUM_U32 Nresult; +} XSUM_testdata32_t; + +typedef struct { + XSUM_U32 len; + XSUM_U64 seed; + XSUM_U64 Nresult; +} XSUM_testdata64_t; + +typedef struct { + XSUM_U32 len; + XSUM_U64 seed; + XXH128_hash_t Nresult; +} XSUM_testdata128_t; + +#define SECRET_SAMPLE_NBBYTES 4 +typedef struct { + XSUM_U32 len; + XSUM_U8 byte[SECRET_SAMPLE_NBBYTES]; +} XSUM_testdata_sample_t; + +/* XXH32 */ +static const XSUM_testdata32_t XSUM_XXH32_testdata[] = { + { 0, 0, 0x02CC5D05U }, + { 0, PRIME32, 0x36B78AE7U }, + { 1, 0, 0xCF65B03EU }, + { 1, PRIME32, 0xB4545AA4U }, + { 14, 0, 0x1208E7E2U }, + { 14, PRIME32, 0x6AF1D1FEU }, + { 222, 0, 0x5BD11DBDU }, + { 222, PRIME32, 0x58803C5FU } +}; + +/* XXH64 */ +static const XSUM_testdata64_t XSUM_XXH64_testdata[] = { + { 0, 0, 0xEF46DB3751D8E999ULL }, + { 0, PRIME32, 0xAC75FDA2929B17EFULL }, + { 1, 0, 0xE934A84ADB052768ULL }, + { 1, PRIME32, 0x5014607643A9B4C3ULL }, + { 4, 0, 0x9136A0DCA57457EEULL }, + { 14, 0, 0x8282DCC4994E35C8ULL }, + { 14, PRIME32, 0xC3BD6BF63DEB6DF0ULL }, + { 222, 0, 0xB641AE8CB691C174ULL }, + { 222, PRIME32, 0x20CB8AB7AE10C14AULL } +}; +/* + * XXH3: + * Due to being a more complex hash function with specializations for certain + * lengths, a more extensive test is used for XXH3. + */ + +/* XXH3_64bits, seeded */ +static const XSUM_testdata64_t XSUM_XXH3_testdata[] = { + { 0, 0, 0x2D06800538D394C2ULL }, /* empty string */ + { 0, PRIME64, 0xA8A6B918B2F0364AULL }, /* empty string */ + { 1, 0, 0xC44BDFF4074EECDBULL }, /* 1 - 3 */ + { 1, PRIME64, 0x032BE332DD766EF8ULL }, /* 1 - 3 */ + { 6, 0, 0x27B56A84CD2D7325ULL }, /* 4 - 8 */ + { 6, PRIME64, 0x84589C116AB59AB9ULL }, /* 4 - 8 */ + { 12, 0, 0xA713DAF0DFBB77E7ULL }, /* 9 - 16 */ + { 12, PRIME64, 0xE7303E1B2336DE0EULL }, /* 9 - 16 */ + { 24, 0, 0xA3FE70BF9D3510EBULL }, /* 17 - 32 */ + { 24, PRIME64, 0x850E80FC35BDD690ULL }, /* 17 - 32 */ + { 48, 0, 0x397DA259ECBA1F11ULL }, /* 33 - 64 */ + { 48, PRIME64, 0xADC2CBAA44ACC616ULL }, /* 33 - 64 */ + { 80, 0, 0xBCDEFBBB2C47C90AULL }, /* 65 - 96 */ + { 80, PRIME64, 0xC6DD0CB699532E73ULL }, /* 65 - 96 */ + { 195, 0, 0xCD94217EE362EC3AULL }, /* 129-240 */ + { 195, PRIME64, 0xBA68003D370CB3D9ULL }, /* 129-240 */ + + { 403, 0, 0xCDEB804D65C6DEA4ULL }, /* one block, last stripe is overlapping */ + { 403, PRIME64, 0x6259F6ECFD6443FDULL }, /* one block, last stripe is overlapping */ + { 512, 0, 0x617E49599013CB6BULL }, /* one block, finishing at stripe boundary */ + { 512, PRIME64, 0x3CE457DE14C27708ULL }, /* one block, finishing at stripe boundary */ + { 2048, 0, 0xDD59E2C3A5F038E0ULL }, /* 2 blocks, finishing at block boundary */ + { 2048, PRIME64, 0x66F81670669ABABCULL }, /* 2 blocks, finishing at block boundary */ + { 2240, 0, 0x6E73A90539CF2948ULL }, /* 3 blocks, finishing at stripe boundary */ + { 2240, PRIME64, 0x757BA8487D1B5247ULL }, /* 3 blocks, finishing at stripe boundary */ + { 2367, 0, 0xCB37AEB9E5D361EDULL }, /* 3 blocks, last stripe is overlapping */ + { 2367, PRIME64, 0xD2DB3415B942B42AULL } /* 3 blocks, last stripe is overlapping */ +}; +/* XXH3_64bits, custom secret */ +static const XSUM_testdata64_t XSUM_XXH3_withSecret_testdata[] = { + { 0, 0, 0x3559D64878C5C66CULL }, /* empty string */ + { 1, 0, 0x8A52451418B2DA4DULL }, /* 1 - 3 */ + { 6, 0, 0x82C90AB0519369ADULL }, /* 4 - 8 */ + { 12, 0, 0x14631E773B78EC57ULL }, /* 9 - 16 */ + { 24, 0, 0xCDD5542E4A9D9FE8ULL }, /* 17 - 32 */ + { 48, 0, 0x33ABD54D094B2534ULL }, /* 33 - 64 */ + { 80, 0, 0xE687BA1684965297ULL }, /* 65 - 96 */ + { 195, 0, 0xA057273F5EECFB20ULL }, /* 129-240 */ + + { 403, 0, 0x14546019124D43B8ULL }, /* one block, last stripe is overlapping */ + { 512, 0, 0x7564693DD526E28DULL }, /* one block, finishing at stripe boundary */ + { 2048, 0, 0xD32E975821D6519FULL }, /* >= 2 blodcks, at least one scrambling */ + { 2367, 0, 0x293FA8E5173BB5E7ULL }, /* >= 2 blocks, at least one scrambling, last stripe unaligned */ + + { 64*10*3, 0, 0x751D2EC54BC6038BULL } /* exactly 3 full blocks, not a multiple of 256 */ +}; +/* XXH3_128bits, seeded */ +static const XSUM_testdata128_t XSUM_XXH128_testdata[] = { + { 0, 0, { 0x6001C324468D497FULL, 0x99AA06D3014798D8ULL } }, /* empty string */ + { 0, PRIME32, { 0x5444F7869C671AB0ULL, 0x92220AE55E14AB50ULL } }, /* empty string */ + { 1, 0, { 0xC44BDFF4074EECDBULL, 0xA6CD5E9392000F6AULL } }, /* 1 - 3 */ + { 1, PRIME32, { 0xB53D5557E7F76F8DULL, 0x89B99554BA22467CULL } }, /* 1 - 3 */ + { 6, 0, { 0x3E7039BDDA43CFC6ULL, 0x082AFE0B8162D12AULL } }, /* 4 - 8 */ + { 6, PRIME32, { 0x269D8F70BE98856EULL, 0x5A865B5389ABD2B1ULL } }, /* 4 - 8 */ + { 12, 0, { 0x061A192713F69AD9ULL, 0x6E3EFD8FC7802B18ULL } }, /* 9 - 16 */ + { 12, PRIME32, { 0x9BE9F9A67F3C7DFBULL, 0xD7E09D518A3405D3ULL } }, /* 9 - 16 */ + { 24, 0, { 0x1E7044D28B1B901DULL, 0x0CE966E4678D3761ULL } }, /* 17 - 32 */ + { 24, PRIME32, { 0xD7304C54EBAD40A9ULL, 0x3162026714A6A243ULL } }, /* 17 - 32 */ + { 48, 0, { 0xF942219AED80F67BULL, 0xA002AC4E5478227EULL } }, /* 33 - 64 */ + { 48, PRIME32, { 0x7BA3C3E453A1934EULL, 0x163ADDE36C072295ULL } }, /* 33 - 64 */ + { 81, 0, { 0x5E8BAFB9F95FB803ULL, 0x4952F58181AB0042ULL } }, /* 65 - 96 */ + { 81, PRIME32, { 0x703FBB3D7A5F755CULL, 0x2724EC7ADC750FB6ULL } }, /* 65 - 96 */ + { 222, 0, { 0xF1AEBD597CEC6B3AULL, 0x337E09641B948717ULL } }, /* 129-240 */ + { 222, PRIME32, { 0xAE995BB8AF917A8DULL, 0x91820016621E97F1ULL } }, /* 129-240 */ + + { 403, 0, { 0xCDEB804D65C6DEA4ULL, 0x1B6DE21E332DD73DULL } }, /* one block, last stripe is overlapping */ + { 403, PRIME64, { 0x6259F6ECFD6443FDULL, 0xBED311971E0BE8F2ULL } }, /* one block, last stripe is overlapping */ + { 512, 0, { 0x617E49599013CB6BULL, 0x18D2D110DCC9BCA1ULL } }, /* one block, finishing at stripe boundary */ + { 512, PRIME64, { 0x3CE457DE14C27708ULL, 0x925D06B8EC5B8040ULL } }, /* one block, finishing at stripe boundary */ + { 2048, 0, { 0xDD59E2C3A5F038E0ULL, 0xF736557FD47073A5ULL } }, /* 2 blocks, finishing at block boundary */ + { 2048, PRIME32, { 0x230D43F30206260BULL, 0x7FB03F7E7186C3EAULL } }, /* 2 blocks, finishing at block boundary */ + { 2240, 0, { 0x6E73A90539CF2948ULL, 0xCCB134FBFA7CE49DULL } }, /* 3 blocks, finishing at stripe boundary */ + { 2240, PRIME32, { 0xED385111126FBA6FULL, 0x50A1FE17B338995FULL } }, /* 3 blocks, finishing at stripe boundary */ + { 2367, 0, { 0xCB37AEB9E5D361EDULL, 0xE89C0F6FF369B427ULL } }, /* 3 blocks, last stripe is overlapping */ + { 2367, PRIME32, { 0x6F5360AE69C2F406ULL, 0xD23AAE4B76C31ECBULL } } /* 3 blocks, last stripe is overlapping */ +}; + +/* XXH128, custom secret */ +static const XSUM_testdata128_t XSUM_XXH128_withSecret_testdata[] = { + { 0, 0, { 0x005923CCEECBE8AEULL, 0x5F70F4EA232F1D38ULL } }, /* empty string */ + { 1, 0, { 0x8A52451418B2DA4DULL, 0x3A66AF5A9819198EULL } }, /* 1 - 3 */ + { 6, 0, { 0x0B61C8ACA7D4778FULL, 0x376BD91B6432F36DULL } }, /* 4 - 8 */ + { 12, 0, { 0xAF82F6EBA263D7D8ULL, 0x90A3C2D839F57D0FULL } } /* 9 - 16 */ +}; + +static const XSUM_testdata_sample_t XSUM_XXH3_generateSecret_testdata[] = { + { 0, { 0xB8, 0x26, 0x83, 0x7E } }, + { 1, { 0xA6, 0x16, 0x06, 0x7B } }, + { XXH3_SECRET_SIZE_MIN - 1, { 0xDA, 0x2A, 0x12, 0x11 } }, + { XXH3_SECRET_DEFAULT_SIZE + 500, { 0x7E, 0x48, 0x0C, 0xA7 } } +}; + +static void XSUM_checkResult32(XXH32_hash_t r1, XXH32_hash_t r2) +{ + static int nbTests = 1; + if (r1!=r2) { + XSUM_log("\rError: 32-bit hash test %i: Internal sanity check failed!\n", nbTests); + XSUM_log("\rGot 0x%08X, expected 0x%08X.\n", (unsigned)r1, (unsigned)r2); + XSUM_log("\rNote: If you modified the hash functions, make sure to either update the values\n" + "or temporarily recompile with XSUM_NO_TESTS=1.\n"); + exit(1); + } + nbTests++; +} + +static void XSUM_checkResult64(XXH64_hash_t r1, XXH64_hash_t r2) +{ + static int nbTests = 1; + if (r1!=r2) { + XSUM_log("\rError: 64-bit hash test %i: Internal sanity check failed!\n", nbTests); + XSUM_log("\rGot 0x%08X%08XULL, expected 0x%08X%08XULL.\n", + (unsigned)(r1>>32), (unsigned)r1, (unsigned)(r2>>32), (unsigned)r2); + XSUM_log("\rNote: If you modified the hash functions, make sure to either update the values\n" + "or temporarily recompile with XSUM_NO_TESTS=1.\n"); + exit(1); + } + nbTests++; +} + +static void XSUM_checkResult128(XXH128_hash_t r1, XXH128_hash_t r2) +{ + static int nbTests = 1; + if ((r1.low64 != r2.low64) || (r1.high64 != r2.high64)) { + XSUM_log("\rError: 128-bit hash test %i: Internal sanity check failed.\n", nbTests); + XSUM_log("\rGot { 0x%08X%08XULL, 0x%08X%08XULL }, expected { 0x%08X%08XULL, 0x%08X%08XULL } \n", + (unsigned)(r1.low64>>32), (unsigned)r1.low64, (unsigned)(r1.high64>>32), (unsigned)r1.high64, + (unsigned)(r2.low64>>32), (unsigned)r2.low64, (unsigned)(r2.high64>>32), (unsigned)r2.high64 ); + XSUM_log("\rNote: If you modified the hash functions, make sure to either update the values\n" + "or temporarily recompile with XSUM_NO_TESTS=1.\n"); + exit(1); + } + nbTests++; +} + + +static void XSUM_testXXH32(const void* data, const XSUM_testdata32_t* testData) +{ + XXH32_state_t *state = XXH32_createState(); + size_t pos; + + size_t len = testData->len; + XSUM_U32 seed = testData->seed; + XSUM_U32 Nresult = testData->Nresult; + + if (len == 0) { + data = NULL; + } else { + assert(data != NULL); + } + + assert(state != NULL); + + XSUM_checkResult32(XXH32(data, len, seed), Nresult); + + (void)XXH32_reset(state, seed); + (void)XXH32_update(state, data, len); + XSUM_checkResult32(XXH32_digest(state), Nresult); + + (void)XXH32_reset(state, seed); + for (pos=0; poslen; + XSUM_U64 seed = testData->seed; + XSUM_U64 Nresult = testData->Nresult; + + if (len == 0) { + data = NULL; + } else { + assert(data != NULL); + } + + assert(state != NULL); + + XSUM_checkResult64(XXH64(data, len, seed), Nresult); + + (void)XXH64_reset(state, seed); + (void)XXH64_update(state, data, len); + XSUM_checkResult64(XXH64_digest(state), Nresult); + + (void)XXH64_reset(state, seed); + for (pos=0; pos> 40); +} + +/* + * Technically, XXH3_64bits_update is identical to XXH3_128bits_update as of + * v0.8.0, but we treat them as separate. + */ +typedef XXH_errorcode (*XSUM_XXH3_update_t)(XXH3_state_t* state, const void* input, size_t length); + +/* + * Runs the passed XXH3_update variant on random lengths. This is to test the + * more complex logic of the update function, catching bugs like this one: + * https://github.com/Cyan4973/xxHash/issues/378 + */ +static void XSUM_XXH3_randomUpdate(XXH3_state_t* state, const void* data, + size_t len, XSUM_XXH3_update_t update_fn) +{ + size_t p = 0; + while (p < len) { + size_t const modulo = len > 2 ? len : 2; + size_t l = (size_t)(XSUM_rand()) % modulo; + if (p + l > len) l = len - p; + (void)update_fn(state, (const char*)data+p, l); + p += l; + } +} + +static void XSUM_testXXH3(const void* data, const XSUM_testdata64_t* testData) +{ + size_t len = testData->len; + XSUM_U64 seed = testData->seed; + XSUM_U64 Nresult = testData->Nresult; + if (len == 0) { + data = NULL; + } else { + assert(data != NULL); + } + { XSUM_U64 const Dresult = XXH3_64bits_withSeed(data, len, seed); + XSUM_checkResult64(Dresult, Nresult); + } + + /* check that the no-seed variant produces same result as seed==0 */ + if (seed == 0) { + XSUM_U64 const Dresult = XXH3_64bits(data, len); + XSUM_checkResult64(Dresult, Nresult); + } + + /* streaming API test */ + { XXH3_state_t* const state = XXH3_createState(); + assert(state != NULL); + /* single ingestion */ + (void)XXH3_64bits_reset_withSeed(state, seed); + (void)XXH3_64bits_update(state, data, len); + XSUM_checkResult64(XXH3_64bits_digest(state), Nresult); + + /* random ingestion */ + (void)XXH3_64bits_reset_withSeed(state, seed); + XSUM_XXH3_randomUpdate(state, data, len, &XXH3_64bits_update); + XSUM_checkResult64(XXH3_64bits_digest(state), Nresult); + + /* byte by byte ingestion */ + { size_t pos; + (void)XXH3_64bits_reset_withSeed(state, seed); + for (pos=0; poslen; + XSUM_U64 Nresult = testData->Nresult; + + if (len == 0) { + data = NULL; + } else { + assert(data != NULL); + } + { XSUM_U64 const Dresult = XXH3_64bits_withSecret(data, len, secret, secretSize); + XSUM_checkResult64(Dresult, Nresult); + } + + /* streaming API test */ + { XXH3_state_t *state = XXH3_createState(); + assert(state != NULL); + (void)XXH3_64bits_reset_withSecret(state, secret, secretSize); + (void)XXH3_64bits_update(state, data, len); + XSUM_checkResult64(XXH3_64bits_digest(state), Nresult); + + /* random ingestion */ + (void)XXH3_64bits_reset_withSecret(state, secret, secretSize); + XSUM_XXH3_randomUpdate(state, data, len, &XXH3_64bits_update); + XSUM_checkResult64(XXH3_64bits_digest(state), Nresult); + + /* byte by byte ingestion */ + { size_t pos; + (void)XXH3_64bits_reset_withSecret(state, secret, secretSize); + for (pos=0; poslen; + XSUM_U64 seed = testData->seed; + XXH128_hash_t const Nresult = testData->Nresult; + if (len == 0) { + data = NULL; + } else { + assert(data != NULL); + } + + { XXH128_hash_t const Dresult = XXH3_128bits_withSeed(data, len, seed); + XSUM_checkResult128(Dresult, Nresult); + } + + /* check that XXH128() is identical to XXH3_128bits_withSeed() */ + { XXH128_hash_t const Dresult2 = XXH128(data, len, seed); + XSUM_checkResult128(Dresult2, Nresult); + } + + /* check that the no-seed variant produces same result as seed==0 */ + if (seed == 0) { + XXH128_hash_t const Dresult = XXH3_128bits(data, len); + XSUM_checkResult128(Dresult, Nresult); + } + + /* streaming API test */ + { XXH3_state_t *state = XXH3_createState(); + assert(state != NULL); + + /* single ingestion */ + (void)XXH3_128bits_reset_withSeed(state, seed); + (void)XXH3_128bits_update(state, data, len); + XSUM_checkResult128(XXH3_128bits_digest(state), Nresult); + + /* random ingestion */ + (void)XXH3_128bits_reset_withSeed(state, seed); + XSUM_XXH3_randomUpdate(state, data, len, &XXH3_128bits_update); + XSUM_checkResult128(XXH3_128bits_digest(state), Nresult); + + /* byte by byte ingestion */ + { size_t pos; + (void)XXH3_128bits_reset_withSeed(state, seed); + for (pos=0; poslen; + XXH128_hash_t Nresult = testData->Nresult; + if (len == 0) { + data = NULL; + } else if (len>0) { + assert(data != NULL); + } + { XXH128_hash_t const Dresult = XXH3_128bits_withSecret(data, len, secret, secretSize); + XSUM_checkResult128(Dresult, Nresult); + } + + /* streaming API test */ + { XXH3_state_t* const state = XXH3_createState(); + assert(state != NULL); + (void)XXH3_128bits_reset_withSecret(state, secret, secretSize); + (void)XXH3_128bits_update(state, data, len); + XSUM_checkResult128(XXH3_128bits_digest(state), Nresult); + + /* random ingestion */ + (void)XXH3_128bits_reset_withSecret(state, secret, secretSize); + XSUM_XXH3_randomUpdate(state, data, len, &XXH3_128bits_update); + XSUM_checkResult128(XXH3_128bits_digest(state), Nresult); + + /* byte by byte ingestion */ + { size_t pos; + (void)XXH3_128bits_reset_withSecret(state, secret, secretSize); + for (pos=0; poslen); + for (i=0; ibyte, sizeof(testData->byte))) { + XSUM_log("\rError: Secret generation test %i: Internal sanity check failed. \n", nbTests); + XSUM_log("\rGot { 0x%02X, 0x%02X, 0x%02X, 0x%02X }, expected { 0x%02X, 0x%02X, 0x%02X, 0x%02X } \n", + samples[0], samples[1], samples[2], samples[3], + testData->byte[0], testData->byte[1], testData->byte[2], testData->byte[3] ); + exit(1); + } + nbTests++; +} + +/*! + * XSUM_sanityCheck(): + * Runs a sanity check before the benchmark. + * + * Exits on an incorrect output. + */ +XSUM_API void XSUM_sanityCheck(void) +{ + size_t i; +#define SANITY_BUFFER_SIZE 2367 + XSUM_U8 sanityBuffer[SANITY_BUFFER_SIZE]; + const void* const secret = sanityBuffer + 7; + const size_t secretSize = XXH3_SECRET_SIZE_MIN + 11; + assert(sizeof(sanityBuffer) >= 7 + secretSize); + + XSUM_fillTestBuffer(sanityBuffer, sizeof(sanityBuffer)); + + /* XXH32 */ + for (i = 0; i < (sizeof(XSUM_XXH32_testdata)/sizeof(XSUM_XXH32_testdata[0])); i++) { + XSUM_testXXH32(sanityBuffer, &XSUM_XXH32_testdata[i]); + } + /* XXH64 */ + for (i = 0; i < (sizeof(XSUM_XXH64_testdata)/sizeof(XSUM_XXH64_testdata[0])); i++) { + XSUM_testXXH64(sanityBuffer, &XSUM_XXH64_testdata[i]); + } + /* XXH3_64bits, seeded */ + for (i = 0; i < (sizeof(XSUM_XXH3_testdata)/sizeof(XSUM_XXH3_testdata[0])); i++) { + XSUM_testXXH3(sanityBuffer, &XSUM_XXH3_testdata[i]); + } + /* XXH3_64bits, custom secret */ + for (i = 0; i < (sizeof(XSUM_XXH3_withSecret_testdata)/sizeof(XSUM_XXH3_withSecret_testdata[0])); i++) { + XSUM_testXXH3_withSecret(sanityBuffer, secret, secretSize, &XSUM_XXH3_withSecret_testdata[i]); + } + /* XXH128 */ + for (i = 0; i < (sizeof(XSUM_XXH128_testdata)/sizeof(XSUM_XXH128_testdata[0])); i++) { + XSUM_testXXH128(sanityBuffer, &XSUM_XXH128_testdata[i]); + } + /* XXH128 with custom Secret */ + for (i = 0; i < (sizeof(XSUM_XXH128_withSecret_testdata)/sizeof(XSUM_XXH128_withSecret_testdata[0])); i++) { + XSUM_testXXH128_withSecret(sanityBuffer, secret, secretSize, &XSUM_XXH128_withSecret_testdata[i]); + } + /* secret generator */ + for (i = 0; i < (sizeof(XSUM_XXH3_generateSecret_testdata)/sizeof(XSUM_XXH3_generateSecret_testdata[0])); i++) { + XSUM_testSecretGenerator(sanityBuffer, &XSUM_XXH3_generateSecret_testdata[i]); + } + + XSUM_logVerbose(3, "\r%70s\r", ""); /* Clean display line */ + XSUM_logVerbose(3, "Sanity check -- all tests ok\n"); +} + +#endif /* !XSUM_NO_TESTS */ diff --git a/deps/xxHash/cli/xsum_sanity_check.h b/deps/xxHash/cli/xsum_sanity_check.h new file mode 100644 index 0000000000..4e3bc0f69d --- /dev/null +++ b/deps/xxHash/cli/xsum_sanity_check.h @@ -0,0 +1,60 @@ +/* + * xxhsum - Command line interface for xxhash algorithms + * Copyright (C) 2013-2020 Yann Collet + * + * GPL v2 License + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * You can contact the author at: + * - xxHash homepage: https://www.xxhash.com + * - xxHash source repository: https://github.com/Cyan4973/xxHash + */ + +#ifndef XSUM_SANITY_CHECK_H +#define XSUM_SANITY_CHECK_H + +#include "xsum_config.h" /* XSUM_API, XSUM_U8 */ + +#include /* size_t */ + + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Runs a series of self-tests. + * + * Exits if any of these tests fail, printing a message to stderr. + * + * If XSUM_NO_TESTS is defined to non-zero, + * this will instead print a warning if this is called (e.g. via xxhsum -b). + */ +XSUM_API void XSUM_sanityCheck(void); + +/* + * Fills a test buffer with pseudorandom data. + * + * This is used in the sanity check and the benchmarks. + * Its values must not be changed. + */ +XSUM_API void XSUM_fillTestBuffer(XSUM_U8* buffer, size_t len); + +#ifdef __cplusplus +} +#endif + +#endif /* XSUM_SANITY_CHECK_H */ diff --git a/deps/xxHash/cli/xxhsum.1 b/deps/xxHash/cli/xxhsum.1 new file mode 100644 index 0000000000..dd17108f10 --- /dev/null +++ b/deps/xxHash/cli/xxhsum.1 @@ -0,0 +1,165 @@ +. +.TH "XXHSUM" "1" "July 2020" "xxhsum 0.7.4" "User Commands" +. +.SH "NAME" +\fBxxhsum\fR \- print or check xxHash non\-cryptographic checksums +. +.SH "SYNOPSIS" +\fBxxhsum [