diff --git a/lib/libzstd/CMakeLists.txt b/lib/libzstd/CMakeLists.txt index be42cb9da139..c2388c060804 100644 --- a/lib/libzstd/CMakeLists.txt +++ b/lib/libzstd/CMakeLists.txt @@ -4,7 +4,28 @@ use_clang() set(ZSTD_MODULE_DIR "../../module/zstd") add_library(libzstd + "${ZSTD_MODULE_DIR}/lib/common/entropy_common.c" + "${ZSTD_MODULE_DIR}/lib/common/error_private.c" + "${ZSTD_MODULE_DIR}/lib/common/fse_decompress.c" + "${ZSTD_MODULE_DIR}/lib/common/pool.c" + "${ZSTD_MODULE_DIR}/lib/common/zstd_common.c" + "${ZSTD_MODULE_DIR}/lib/common/xxhash.c" + "${ZSTD_MODULE_DIR}/lib/compress/fse_compress.c" + "${ZSTD_MODULE_DIR}/lib/compress/hist.c" + "${ZSTD_MODULE_DIR}/lib/compress/huf_compress.c" + "${ZSTD_MODULE_DIR}/lib/compress/zstd_compress_literals.c" + "${ZSTD_MODULE_DIR}/lib/compress/zstd_compress_sequences.c" + "${ZSTD_MODULE_DIR}/lib/compress/zstd_compress_superblock.c" + "${ZSTD_MODULE_DIR}/lib/compress/zstd_compress.c" + "${ZSTD_MODULE_DIR}/lib/compress/zstd_double_fast.c" + "${ZSTD_MODULE_DIR}/lib/compress/zstd_fast.c" + "${ZSTD_MODULE_DIR}/lib/compress/zstd_lazy.c" + "${ZSTD_MODULE_DIR}/lib/compress/zstd_ldm.c" + "${ZSTD_MODULE_DIR}/lib/compress/zstd_opt.c" + "${ZSTD_MODULE_DIR}/lib/decompress/huf_decompress.c" + "${ZSTD_MODULE_DIR}/lib/decompress/zstd_ddict.c" + "${ZSTD_MODULE_DIR}/lib/decompress/zstd_decompress.c" + "${ZSTD_MODULE_DIR}/lib/decompress/zstd_decompress_block.c" "${ZSTD_MODULE_DIR}/zfs_zstd.c" - "${ZSTD_MODULE_DIR}/lib/zstd.c" ) target_link_libraries(libzstd PUBLIC libnvpair libpthread) diff --git a/module/zstd/CMakeLists.txt b/module/zstd/CMakeLists.txt index 3a321beff581..9f4c4b03d577 100644 --- a/module/zstd/CMakeLists.txt +++ b/module/zstd/CMakeLists.txt @@ -2,7 +2,28 @@ use_clang() wdk_add_library(zstdkern - lib/zstd.c + lib/common/entropy_common.c + lib/common/error_private.c + lib/common/fse_decompress.c + lib/common/pool.c + lib/common/zstd_common.c + lib/common/xxhash.c + lib/compress/fse_compress.c + lib/compress/hist.c + lib/compress/huf_compress.c + lib/compress/zstd_compress_literals.c + lib/compress/zstd_compress_sequences.c + lib/compress/zstd_compress_superblock.c + lib/compress/zstd_compress.c + lib/compress/zstd_double_fast.c + lib/compress/zstd_fast.c + lib/compress/zstd_lazy.c + lib/compress/zstd_ldm.c + lib/compress/zstd_opt.c + lib/decompress/huf_decompress.c + lib/decompress/zstd_ddict.c + lib/decompress/zstd_decompress.c + lib/decompress/zstd_decompress_block.c zfs_zstd.c ) diff --git a/module/zstd/lib/common/bitstream.h b/module/zstd/lib/common/bitstream.h index 37b99c01eed3..624de3d6f976 100644 --- a/module/zstd/lib/common/bitstream.h +++ b/module/zstd/lib/common/bitstream.h @@ -140,7 +140,7 @@ MEM_STATIC unsigned BIT_highbit32 (U32 val) { assert(val != 0); { -# if defined(_MSC_VER) /* Visual */ +# if defined(_MSC_VER) && !defined(__clang__) /* Visual */ unsigned long r=0; return _BitScanReverse ( &r, val ) ? (unsigned)r : 0; # elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */ diff --git a/module/zstd/lib/common/compiler.h b/module/zstd/lib/common/compiler.h index 95e9483521d4..c816d70eb539 100644 --- a/module/zstd/lib/common/compiler.h +++ b/module/zstd/lib/common/compiler.h @@ -110,7 +110,7 @@ # define PREFETCH_L1(ptr) (void)(ptr) /* disabled */ # define PREFETCH_L2(ptr) (void)(ptr) /* disabled */ #else -# if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_I86)) /* _mm_prefetch() is not defined outside of x86/x64 */ +# if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_I86)) && !defined(__clang__) /* _mm_prefetch() is not defined outside of x86/x64 */ # include /* https://msdn.microsoft.com/fr-fr/library/84szxsww(v=vs.90).aspx */ # define PREFETCH_L1(ptr) _mm_prefetch((const char*)(ptr), _MM_HINT_T0) # define PREFETCH_L2(ptr) _mm_prefetch((const char*)(ptr), _MM_HINT_T1) @@ -163,7 +163,7 @@ #endif /* disable warnings */ -#ifdef _MSC_VER /* Visual Studio */ +#if defined(_MSC_VER) && !defined(__clang__) /* Visual Studio */ # include /* For Visual 2005 */ # pragma warning(disable : 4100) /* disable: C4100: unreferenced formal parameter */ # pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */ diff --git a/module/zstd/lib/common/cpu.h b/module/zstd/lib/common/cpu.h index 6e8a974f62d7..43123856a044 100644 --- a/module/zstd/lib/common/cpu.h +++ b/module/zstd/lib/common/cpu.h @@ -20,7 +20,7 @@ #include "mem.h" -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(__clang__) #include #endif @@ -36,7 +36,7 @@ MEM_STATIC ZSTD_cpuid_t ZSTD_cpuid(void) { U32 f1d = 0; U32 f7b = 0; U32 f7c = 0; -#if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86)) +#if defined(_MSC_VER) && !defined(__clang__) && (defined(_M_X64) || defined(_M_IX86)) int reg[4]; __cpuid((int*)reg, 0); { diff --git a/module/zstd/lib/common/mem.h b/module/zstd/lib/common/mem.h index 7fbb2e98215e..253d252cdf93 100644 --- a/module/zstd/lib/common/mem.h +++ b/module/zstd/lib/common/mem.h @@ -25,7 +25,7 @@ extern "C" { /*-**************************************** * Compiler specifics ******************************************/ -#if defined(_MSC_VER) /* Visual Studio */ +#if defined(_MSC_VER) && !defined(__clang__) /* Visual Studio */ # include /* _byteswap_ulong */ # include /* _byteswap_* */ #endif @@ -270,7 +270,7 @@ MEM_STATIC void MEM_write64(void* memPtr, U64 value) MEM_STATIC U32 MEM_swap32(U32 in) { -#if defined(_MSC_VER) /* Visual Studio */ +#if defined(_MSC_VER) && !defined(__clang__) /* Visual Studio */ return _byteswap_ulong(in); #elif (defined (__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 403)) \ || (defined(__clang__) && __has_builtin(__builtin_bswap32)) @@ -285,7 +285,7 @@ MEM_STATIC U32 MEM_swap32(U32 in) MEM_STATIC U64 MEM_swap64(U64 in) { -#if defined(_MSC_VER) /* Visual Studio */ +#if defined(_MSC_VER) && !defined(__clang__) /* Visual Studio */ return _byteswap_uint64(in); #elif (defined (__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 403)) \ || (defined(__clang__) && __has_builtin(__builtin_bswap64)) diff --git a/module/zstd/lib/common/xxhash.c b/module/zstd/lib/common/xxhash.c index 597de18fc895..27fcbf743c53 100644 --- a/module/zstd/lib/common/xxhash.c +++ b/module/zstd/lib/common/xxhash.c @@ -5,7 +5,7 @@ * You can contact the author at : * - xxHash homepage: http://www.xxhash.com * - xxHash source repository : https://github.com/Cyan4973/xxHash - * + * * This source code is licensed under both the BSD-style license (found in the * LICENSE file in the root directory of this source tree) and the GPLv2 (found * in the COPYING file in the root directory of this source tree). @@ -196,7 +196,7 @@ static U64 XXH_read64(const void* memPtr) # define XXH_rotl64(x,r) ((x << r) | (x >> (64 - r))) #endif -#if defined(_MSC_VER) /* Visual Studio */ +#if defined(_MSC_VER) && !defined(__clang__) /* Visual Studio */ # define XXH_swap32 _byteswap_ulong # define XXH_swap64 _byteswap_uint64 #elif GCC_VERSION >= 403 diff --git a/module/zstd/lib/common/zstd_internal.h b/module/zstd/lib/common/zstd_internal.h index 3bc7e55a0a97..bfbf24565cc5 100644 --- a/module/zstd/lib/common/zstd_internal.h +++ b/module/zstd/lib/common/zstd_internal.h @@ -261,7 +261,7 @@ typedef enum { * - ZSTD_overlap_src_before_dst: The src and dst may overlap, but they MUST be at least 8 bytes apart. * The src buffer must be before the dst buffer. */ -MEM_STATIC FORCE_INLINE_ATTR +MEM_STATIC FORCE_INLINE_ATTR void ZSTD_wildcopy(void* dst, const void* src, ptrdiff_t length, ZSTD_overlap_e const ovtype) { ptrdiff_t diff = (BYTE*)dst - (const BYTE*)src; @@ -393,7 +393,7 @@ MEM_STATIC U32 ZSTD_highbit32(U32 val) /* compress, dictBuilder, decodeCorpus { assert(val != 0); { -# if defined(_MSC_VER) /* Visual */ +# if defined(_MSC_VER) && !defined(__clang__) unsigned long r=0; return _BitScanReverse(&r, val) ? (unsigned)r : 0; # elif defined(__GNUC__) && (__GNUC__ >= 3) /* GCC Intrinsic */ diff --git a/module/zstd/lib/compress/zstd_compress_internal.h b/module/zstd/lib/compress/zstd_compress_internal.h index db73f6ce21f2..fb15cbc03747 100644 --- a/module/zstd/lib/compress/zstd_compress_internal.h +++ b/module/zstd/lib/compress/zstd_compress_internal.h @@ -497,7 +497,7 @@ static unsigned ZSTD_NbCommonBytes (size_t val) { if (MEM_isLittleEndian()) { if (MEM_64bits()) { -# if defined(_MSC_VER) && defined(_WIN64) +# if defined(_MSC_VER) && defined(_WIN64) && !defined(__clang__) unsigned long r = 0; return _BitScanForward64( &r, (U64)val ) ? (unsigned)(r >> 3) : 0; # elif defined(__GNUC__) && (__GNUC__ >= 4) @@ -514,7 +514,7 @@ static unsigned ZSTD_NbCommonBytes (size_t val) return DeBruijnBytePos[((U64)((val & -(long long)val) * 0x0218A392CDABBD3FULL)) >> 58]; # endif } else { /* 32 bits */ -# if defined(_MSC_VER) +# if defined(_MSC_VER) && !defined(__clang__) unsigned long r=0; return _BitScanForward( &r, (U32)val ) ? (unsigned)(r >> 3) : 0; # elif defined(__GNUC__) && (__GNUC__ >= 3) @@ -529,7 +529,7 @@ static unsigned ZSTD_NbCommonBytes (size_t val) } } else { /* Big Endian CPU */ if (MEM_64bits()) { -# if defined(_MSC_VER) && defined(_WIN64) +# if defined(_MSC_VER) && defined(_WIN64) && !defined(__clang__) unsigned long r = 0; return _BitScanReverse64( &r, val ) ? (unsigned)(r >> 3) : 0; # elif defined(__GNUC__) && (__GNUC__ >= 4) @@ -543,7 +543,7 @@ static unsigned ZSTD_NbCommonBytes (size_t val) return r; # endif } else { /* 32 bits */ -# if defined(_MSC_VER) +# if defined(_MSC_VER) && !defined(__clang__) unsigned long r = 0; return _BitScanReverse( &r, (unsigned long)val ) ? (unsigned)(r >> 3) : 0; # elif defined(__GNUC__) && (__GNUC__ >= 3)