zstdlib 0.7.0-x86-mingw32 → 0.10.0-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +20 -0
- data/README.md +7 -1
- data/Rakefile +38 -8
- data/ext/{zstdlib → zstdlib_c}/extconf.rb +11 -6
- data/ext/{zstdlib → zstdlib_c}/ruby/zlib-2.2/zstdlib.c +2 -2
- data/ext/{zstdlib → zstdlib_c}/ruby/zlib-2.3/zstdlib.c +2 -2
- data/ext/{zstdlib → zstdlib_c}/ruby/zlib-2.4/zstdlib.c +2 -2
- data/ext/{zstdlib → zstdlib_c}/ruby/zlib-2.5/zstdlib.c +2 -2
- data/ext/{zstdlib → zstdlib_c}/ruby/zlib-2.6/zstdlib.c +2 -2
- data/ext/{zstdlib → zstdlib_c}/ruby/zlib-2.7/zstdlib.c +2 -2
- data/ext/zstdlib_c/ruby/zlib-3.0/zstdlib.c +4994 -0
- data/ext/zstdlib_c/ruby/zlib-3.1/zstdlib.c +5076 -0
- data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/adler32.c +0 -0
- data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/compress.c +0 -0
- data/ext/zstdlib_c/zlib-1.2.12/crc32.c +1116 -0
- data/ext/zstdlib_c/zlib-1.2.12/crc32.h +9446 -0
- data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/deflate.c +78 -30
- data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/deflate.h +12 -15
- data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/gzclose.c +0 -0
- data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/gzguts.h +3 -2
- data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/gzlib.c +5 -3
- data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/gzread.c +5 -7
- data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/gzwrite.c +25 -13
- data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/infback.c +2 -1
- data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/inffast.c +14 -14
- data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/inffast.h +0 -0
- data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/inffixed.h +0 -0
- data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/inflate.c +39 -8
- data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/inflate.h +3 -2
- data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/inftrees.c +3 -3
- data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/inftrees.h +0 -0
- data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/trees.c +27 -48
- data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/trees.h +0 -0
- data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/uncompr.c +0 -0
- data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/zconf.h +0 -0
- data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/zlib.h +123 -100
- data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/zutil.c +2 -2
- data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/zutil.h +12 -9
- data/ext/{zstdlib → zstdlib_c}/zlib.mk +0 -0
- data/ext/{zstdlib → zstdlib_c}/zlibwrapper/zlibwrapper.c +1 -5
- data/ext/{zstdlib → zstdlib_c}/zlibwrapper.mk +0 -0
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/common/bitstream.h +46 -22
- data/ext/zstdlib_c/zstd-1.5.2/lib/common/compiler.h +335 -0
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/common/cpu.h +1 -3
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/common/debug.c +1 -1
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/common/debug.h +12 -19
- data/ext/zstdlib_c/zstd-1.5.2/lib/common/entropy_common.c +368 -0
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/common/error_private.c +2 -1
- data/ext/zstdlib_c/zstd-1.5.2/lib/common/error_private.h +159 -0
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/common/fse.h +41 -12
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/common/fse_decompress.c +139 -22
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/common/huf.h +47 -23
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/common/mem.h +87 -98
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/common/pool.c +34 -23
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/common/pool.h +4 -4
- data/ext/zstdlib_c/zstd-1.5.2/lib/common/portability_macros.h +137 -0
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/common/threading.c +6 -5
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/common/threading.h +0 -0
- data/ext/zstdlib_c/zstd-1.5.2/lib/common/xxhash.c +24 -0
- data/ext/zstdlib_c/zstd-1.5.2/lib/common/xxhash.h +5686 -0
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/common/zstd_common.c +10 -10
- data/ext/zstdlib_c/zstd-1.5.2/lib/common/zstd_deps.h +111 -0
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/common/zstd_internal.h +191 -145
- data/ext/zstdlib_c/zstd-1.5.2/lib/common/zstd_trace.h +163 -0
- data/ext/zstdlib_c/zstd-1.5.2/lib/compress/clevels.h +134 -0
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/fse_compress.c +89 -46
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/hist.c +27 -29
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/hist.h +2 -2
- data/ext/zstdlib_c/zstd-1.5.2/lib/compress/huf_compress.c +1370 -0
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_compress.c +2917 -868
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_compress_internal.h +458 -125
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_compress_literals.c +12 -11
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_compress_literals.h +4 -2
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_compress_sequences.c +41 -18
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_compress_sequences.h +1 -1
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_compress_superblock.c +26 -298
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_compress_superblock.h +1 -1
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_cwksp.h +234 -83
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_double_fast.c +313 -138
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_double_fast.h +1 -1
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_fast.c +329 -150
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_fast.h +1 -1
- data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_lazy.c +2104 -0
- data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_lazy.h +125 -0
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_ldm.c +321 -216
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_ldm.h +9 -2
- data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_ldm_geartab.h +106 -0
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_opt.c +412 -166
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_opt.h +1 -1
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstdmt_compress.c +169 -453
- data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstdmt_compress.h +113 -0
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/decompress/huf_decompress.c +1044 -403
- data/ext/zstdlib_c/zstd-1.5.2/lib/decompress/huf_decompress_amd64.S +585 -0
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/decompress/zstd_ddict.c +9 -9
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/decompress/zstd_ddict.h +2 -2
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/decompress/zstd_decompress.c +450 -105
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/decompress/zstd_decompress_block.c +913 -273
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/decompress/zstd_decompress_block.h +14 -5
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/decompress/zstd_decompress_internal.h +59 -12
- data/ext/zstdlib_c/zstd-1.5.2/lib/zdict.h +452 -0
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/zstd.h +699 -214
- data/ext/{zstdlib/zstd-1.4.5/lib/common → zstdlib_c/zstd-1.5.2/lib}/zstd_errors.h +2 -1
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/zlibWrapper/gzclose.c +0 -0
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/zlibWrapper/gzcompatibility.h +1 -1
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/zlibWrapper/gzguts.h +0 -0
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/zlibWrapper/gzlib.c +0 -0
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/zlibWrapper/gzread.c +0 -0
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/zlibWrapper/gzwrite.c +0 -0
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/zlibWrapper/zstd_zlibwrapper.c +133 -44
- data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/zlibWrapper/zstd_zlibwrapper.h +1 -1
- data/ext/zstdlib_c/zstd.mk +15 -0
- data/lib/2.4/zstdlib_c.so +0 -0
- data/lib/2.5/zstdlib_c.so +0 -0
- data/lib/2.6/zstdlib_c.so +0 -0
- data/lib/2.7/zstdlib_c.so +0 -0
- data/lib/3.0/zstdlib_c.so +0 -0
- data/lib/3.1/zstdlib_c.so +0 -0
- data/lib/zstdlib.rb +2 -2
- metadata +125 -116
- data/ext/zstdlib/zlib-1.2.11/crc32.c +0 -442
- data/ext/zstdlib/zlib-1.2.11/crc32.h +0 -441
- data/ext/zstdlib/zstd-1.4.5/lib/common/compiler.h +0 -175
- data/ext/zstdlib/zstd-1.4.5/lib/common/entropy_common.c +0 -216
- data/ext/zstdlib/zstd-1.4.5/lib/common/error_private.h +0 -80
- data/ext/zstdlib/zstd-1.4.5/lib/common/xxhash.c +0 -864
- data/ext/zstdlib/zstd-1.4.5/lib/common/xxhash.h +0 -285
- data/ext/zstdlib/zstd-1.4.5/lib/compress/huf_compress.c +0 -798
- data/ext/zstdlib/zstd-1.4.5/lib/compress/zstd_lazy.c +0 -1138
- data/ext/zstdlib/zstd-1.4.5/lib/compress/zstd_lazy.h +0 -67
- data/ext/zstdlib/zstd-1.4.5/lib/compress/zstdmt_compress.h +0 -192
- data/ext/zstdlib/zstd.mk +0 -14
- data/lib/2.2/zstdlib.so +0 -0
- data/lib/2.3/zstdlib.so +0 -0
- data/lib/2.4/zstdlib.so +0 -0
- data/lib/2.5/zstdlib.so +0 -0
- data/lib/2.6/zstdlib.so +0 -0
- data/lib/2.7/zstdlib.so +0 -0
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Yann Collet, Facebook, Inc.
|
3
3
|
* All rights reserved.
|
4
4
|
*
|
5
5
|
* This source code is licensed under both the BSD-style license (found in the
|
@@ -13,8 +13,8 @@
|
|
13
13
|
/*-*************************************
|
14
14
|
* Dependencies
|
15
15
|
***************************************/
|
16
|
-
#
|
17
|
-
#include
|
16
|
+
#define ZSTD_DEPS_NEED_MALLOC
|
17
|
+
#include "zstd_deps.h" /* ZSTD_malloc, ZSTD_calloc, ZSTD_free, ZSTD_memset */
|
18
18
|
#include "error_private.h"
|
19
19
|
#include "zstd_internal.h"
|
20
20
|
|
@@ -53,31 +53,31 @@ const char* ZSTD_getErrorString(ZSTD_ErrorCode code) { return ERR_getErrorString
|
|
53
53
|
/*=**************************************************************
|
54
54
|
* Custom allocator
|
55
55
|
****************************************************************/
|
56
|
-
void*
|
56
|
+
void* ZSTD_customMalloc(size_t size, ZSTD_customMem customMem)
|
57
57
|
{
|
58
58
|
if (customMem.customAlloc)
|
59
59
|
return customMem.customAlloc(customMem.opaque, size);
|
60
|
-
return
|
60
|
+
return ZSTD_malloc(size);
|
61
61
|
}
|
62
62
|
|
63
|
-
void*
|
63
|
+
void* ZSTD_customCalloc(size_t size, ZSTD_customMem customMem)
|
64
64
|
{
|
65
65
|
if (customMem.customAlloc) {
|
66
66
|
/* calloc implemented as malloc+memset;
|
67
67
|
* not as efficient as calloc, but next best guess for custom malloc */
|
68
68
|
void* const ptr = customMem.customAlloc(customMem.opaque, size);
|
69
|
-
|
69
|
+
ZSTD_memset(ptr, 0, size);
|
70
70
|
return ptr;
|
71
71
|
}
|
72
|
-
return
|
72
|
+
return ZSTD_calloc(1, size);
|
73
73
|
}
|
74
74
|
|
75
|
-
void
|
75
|
+
void ZSTD_customFree(void* ptr, ZSTD_customMem customMem)
|
76
76
|
{
|
77
77
|
if (ptr!=NULL) {
|
78
78
|
if (customMem.customFree)
|
79
79
|
customMem.customFree(customMem.opaque, ptr);
|
80
80
|
else
|
81
|
-
|
81
|
+
ZSTD_free(ptr);
|
82
82
|
}
|
83
83
|
}
|
@@ -0,0 +1,111 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) Facebook, Inc.
|
3
|
+
* All rights reserved.
|
4
|
+
*
|
5
|
+
* This source code is licensed under both the BSD-style license (found in the
|
6
|
+
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
7
|
+
* in the COPYING file in the root directory of this source tree).
|
8
|
+
* You may select, at your option, one of the above-listed licenses.
|
9
|
+
*/
|
10
|
+
|
11
|
+
/* This file provides common libc dependencies that zstd requires.
|
12
|
+
* The purpose is to allow replacing this file with a custom implementation
|
13
|
+
* to compile zstd without libc support.
|
14
|
+
*/
|
15
|
+
|
16
|
+
/* Need:
|
17
|
+
* NULL
|
18
|
+
* INT_MAX
|
19
|
+
* UINT_MAX
|
20
|
+
* ZSTD_memcpy()
|
21
|
+
* ZSTD_memset()
|
22
|
+
* ZSTD_memmove()
|
23
|
+
*/
|
24
|
+
#ifndef ZSTD_DEPS_COMMON
|
25
|
+
#define ZSTD_DEPS_COMMON
|
26
|
+
|
27
|
+
#include <limits.h>
|
28
|
+
#include <stddef.h>
|
29
|
+
#include <string.h>
|
30
|
+
|
31
|
+
#if defined(__GNUC__) && __GNUC__ >= 4
|
32
|
+
# define ZSTD_memcpy(d,s,l) __builtin_memcpy((d),(s),(l))
|
33
|
+
# define ZSTD_memmove(d,s,l) __builtin_memmove((d),(s),(l))
|
34
|
+
# define ZSTD_memset(p,v,l) __builtin_memset((p),(v),(l))
|
35
|
+
#else
|
36
|
+
# define ZSTD_memcpy(d,s,l) memcpy((d),(s),(l))
|
37
|
+
# define ZSTD_memmove(d,s,l) memmove((d),(s),(l))
|
38
|
+
# define ZSTD_memset(p,v,l) memset((p),(v),(l))
|
39
|
+
#endif
|
40
|
+
|
41
|
+
#endif /* ZSTD_DEPS_COMMON */
|
42
|
+
|
43
|
+
/* Need:
|
44
|
+
* ZSTD_malloc()
|
45
|
+
* ZSTD_free()
|
46
|
+
* ZSTD_calloc()
|
47
|
+
*/
|
48
|
+
#ifdef ZSTD_DEPS_NEED_MALLOC
|
49
|
+
#ifndef ZSTD_DEPS_MALLOC
|
50
|
+
#define ZSTD_DEPS_MALLOC
|
51
|
+
|
52
|
+
#include <stdlib.h>
|
53
|
+
|
54
|
+
#define ZSTD_malloc(s) malloc(s)
|
55
|
+
#define ZSTD_calloc(n,s) calloc((n), (s))
|
56
|
+
#define ZSTD_free(p) free((p))
|
57
|
+
|
58
|
+
#endif /* ZSTD_DEPS_MALLOC */
|
59
|
+
#endif /* ZSTD_DEPS_NEED_MALLOC */
|
60
|
+
|
61
|
+
/*
|
62
|
+
* Provides 64-bit math support.
|
63
|
+
* Need:
|
64
|
+
* U64 ZSTD_div64(U64 dividend, U32 divisor)
|
65
|
+
*/
|
66
|
+
#ifdef ZSTD_DEPS_NEED_MATH64
|
67
|
+
#ifndef ZSTD_DEPS_MATH64
|
68
|
+
#define ZSTD_DEPS_MATH64
|
69
|
+
|
70
|
+
#define ZSTD_div64(dividend, divisor) ((dividend) / (divisor))
|
71
|
+
|
72
|
+
#endif /* ZSTD_DEPS_MATH64 */
|
73
|
+
#endif /* ZSTD_DEPS_NEED_MATH64 */
|
74
|
+
|
75
|
+
/* Need:
|
76
|
+
* assert()
|
77
|
+
*/
|
78
|
+
#ifdef ZSTD_DEPS_NEED_ASSERT
|
79
|
+
#ifndef ZSTD_DEPS_ASSERT
|
80
|
+
#define ZSTD_DEPS_ASSERT
|
81
|
+
|
82
|
+
#include <assert.h>
|
83
|
+
|
84
|
+
#endif /* ZSTD_DEPS_ASSERT */
|
85
|
+
#endif /* ZSTD_DEPS_NEED_ASSERT */
|
86
|
+
|
87
|
+
/* Need:
|
88
|
+
* ZSTD_DEBUG_PRINT()
|
89
|
+
*/
|
90
|
+
#ifdef ZSTD_DEPS_NEED_IO
|
91
|
+
#ifndef ZSTD_DEPS_IO
|
92
|
+
#define ZSTD_DEPS_IO
|
93
|
+
|
94
|
+
#include <stdio.h>
|
95
|
+
#define ZSTD_DEBUG_PRINT(...) fprintf(stderr, __VA_ARGS__)
|
96
|
+
|
97
|
+
#endif /* ZSTD_DEPS_IO */
|
98
|
+
#endif /* ZSTD_DEPS_NEED_IO */
|
99
|
+
|
100
|
+
/* Only requested when <stdint.h> is known to be present.
|
101
|
+
* Need:
|
102
|
+
* intptr_t
|
103
|
+
*/
|
104
|
+
#ifdef ZSTD_DEPS_NEED_STDINT
|
105
|
+
#ifndef ZSTD_DEPS_STDINT
|
106
|
+
#define ZSTD_DEPS_STDINT
|
107
|
+
|
108
|
+
#include <stdint.h>
|
109
|
+
|
110
|
+
#endif /* ZSTD_DEPS_STDINT */
|
111
|
+
#endif /* ZSTD_DEPS_NEED_STDINT */
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Yann Collet, Facebook, Inc.
|
3
3
|
* All rights reserved.
|
4
4
|
*
|
5
5
|
* This source code is licensed under both the BSD-style license (found in the
|
@@ -19,10 +19,8 @@
|
|
19
19
|
/*-*************************************
|
20
20
|
* Dependencies
|
21
21
|
***************************************/
|
22
|
-
#ifdef __aarch64__
|
23
|
-
#include <arm_neon.h>
|
24
|
-
#endif
|
25
22
|
#include "compiler.h"
|
23
|
+
#include "cpu.h"
|
26
24
|
#include "mem.h"
|
27
25
|
#include "debug.h" /* assert, DEBUGLOG, RAWLOG, g_debuglevel */
|
28
26
|
#include "error_private.h"
|
@@ -36,6 +34,11 @@
|
|
36
34
|
# define XXH_STATIC_LINKING_ONLY /* XXH64_state_t */
|
37
35
|
#endif
|
38
36
|
#include "xxhash.h" /* XXH_reset, update, digest */
|
37
|
+
#ifndef ZSTD_NO_TRACE
|
38
|
+
# include "zstd_trace.h"
|
39
|
+
#else
|
40
|
+
# define ZSTD_TRACE 0
|
41
|
+
#endif
|
39
42
|
|
40
43
|
#if defined (__cplusplus)
|
41
44
|
extern "C" {
|
@@ -55,81 +58,7 @@ extern "C" {
|
|
55
58
|
#undef MAX
|
56
59
|
#define MIN(a,b) ((a)<(b) ? (a) : (b))
|
57
60
|
#define MAX(a,b) ((a)>(b) ? (a) : (b))
|
58
|
-
|
59
|
-
/**
|
60
|
-
* Ignore: this is an internal helper.
|
61
|
-
*
|
62
|
-
* This is a helper function to help force C99-correctness during compilation.
|
63
|
-
* Under strict compilation modes, variadic macro arguments can't be empty.
|
64
|
-
* However, variadic function arguments can be. Using a function therefore lets
|
65
|
-
* us statically check that at least one (string) argument was passed,
|
66
|
-
* independent of the compilation flags.
|
67
|
-
*/
|
68
|
-
static INLINE_KEYWORD UNUSED_ATTR
|
69
|
-
void _force_has_format_string(const char *format, ...) {
|
70
|
-
(void)format;
|
71
|
-
}
|
72
|
-
|
73
|
-
/**
|
74
|
-
* Ignore: this is an internal helper.
|
75
|
-
*
|
76
|
-
* We want to force this function invocation to be syntactically correct, but
|
77
|
-
* we don't want to force runtime evaluation of its arguments.
|
78
|
-
*/
|
79
|
-
#define _FORCE_HAS_FORMAT_STRING(...) \
|
80
|
-
if (0) { \
|
81
|
-
_force_has_format_string(__VA_ARGS__); \
|
82
|
-
}
|
83
|
-
|
84
|
-
/**
|
85
|
-
* Return the specified error if the condition evaluates to true.
|
86
|
-
*
|
87
|
-
* In debug modes, prints additional information.
|
88
|
-
* In order to do that (particularly, printing the conditional that failed),
|
89
|
-
* this can't just wrap RETURN_ERROR().
|
90
|
-
*/
|
91
|
-
#define RETURN_ERROR_IF(cond, err, ...) \
|
92
|
-
if (cond) { \
|
93
|
-
RAWLOG(3, "%s:%d: ERROR!: check %s failed, returning %s", \
|
94
|
-
__FILE__, __LINE__, ZSTD_QUOTE(cond), ZSTD_QUOTE(ERROR(err))); \
|
95
|
-
_FORCE_HAS_FORMAT_STRING(__VA_ARGS__); \
|
96
|
-
RAWLOG(3, ": " __VA_ARGS__); \
|
97
|
-
RAWLOG(3, "\n"); \
|
98
|
-
return ERROR(err); \
|
99
|
-
}
|
100
|
-
|
101
|
-
/**
|
102
|
-
* Unconditionally return the specified error.
|
103
|
-
*
|
104
|
-
* In debug modes, prints additional information.
|
105
|
-
*/
|
106
|
-
#define RETURN_ERROR(err, ...) \
|
107
|
-
do { \
|
108
|
-
RAWLOG(3, "%s:%d: ERROR!: unconditional check failed, returning %s", \
|
109
|
-
__FILE__, __LINE__, ZSTD_QUOTE(ERROR(err))); \
|
110
|
-
_FORCE_HAS_FORMAT_STRING(__VA_ARGS__); \
|
111
|
-
RAWLOG(3, ": " __VA_ARGS__); \
|
112
|
-
RAWLOG(3, "\n"); \
|
113
|
-
return ERROR(err); \
|
114
|
-
} while(0);
|
115
|
-
|
116
|
-
/**
|
117
|
-
* If the provided expression evaluates to an error code, returns that error code.
|
118
|
-
*
|
119
|
-
* In debug modes, prints additional information.
|
120
|
-
*/
|
121
|
-
#define FORWARD_IF_ERROR(err, ...) \
|
122
|
-
do { \
|
123
|
-
size_t const err_code = (err); \
|
124
|
-
if (ERR_isError(err_code)) { \
|
125
|
-
RAWLOG(3, "%s:%d: ERROR!: forwarding error in %s: %s", \
|
126
|
-
__FILE__, __LINE__, ZSTD_QUOTE(err), ERR_getErrorName(err_code)); \
|
127
|
-
_FORCE_HAS_FORMAT_STRING(__VA_ARGS__); \
|
128
|
-
RAWLOG(3, ": " __VA_ARGS__); \
|
129
|
-
RAWLOG(3, "\n"); \
|
130
|
-
return err_code; \
|
131
|
-
} \
|
132
|
-
} while(0);
|
61
|
+
#define BOUNDED(min,val,max) (MAX(min,MIN(val,max)))
|
133
62
|
|
134
63
|
|
135
64
|
/*-*************************************
|
@@ -138,8 +67,7 @@ void _force_has_format_string(const char *format, ...) {
|
|
138
67
|
#define ZSTD_OPT_NUM (1<<12)
|
139
68
|
|
140
69
|
#define ZSTD_REP_NUM 3 /* number of repcodes */
|
141
|
-
|
142
|
-
static const U32 repStartValue[ZSTD_REP_NUM] = { 1, 4, 8 };
|
70
|
+
static UNUSED_ATTR const U32 repStartValue[ZSTD_REP_NUM] = { 1, 4, 8 };
|
143
71
|
|
144
72
|
#define KB *(1 <<10)
|
145
73
|
#define MB *(1 <<20)
|
@@ -153,13 +81,13 @@ static const U32 repStartValue[ZSTD_REP_NUM] = { 1, 4, 8 };
|
|
153
81
|
#define BIT0 1
|
154
82
|
|
155
83
|
#define ZSTD_WINDOWLOG_ABSOLUTEMIN 10
|
156
|
-
static const size_t ZSTD_fcs_fieldSize[4] = { 0, 2, 4, 8 };
|
157
|
-
static const size_t ZSTD_did_fieldSize[4] = { 0, 1, 2, 4 };
|
84
|
+
static UNUSED_ATTR const size_t ZSTD_fcs_fieldSize[4] = { 0, 2, 4, 8 };
|
85
|
+
static UNUSED_ATTR const size_t ZSTD_did_fieldSize[4] = { 0, 1, 2, 4 };
|
158
86
|
|
159
87
|
#define ZSTD_FRAMEIDSIZE 4 /* magic number size */
|
160
88
|
|
161
89
|
#define ZSTD_BLOCKHEADERSIZE 3 /* C standard doesn't allow `static const` variable to be init using another `static const` variable */
|
162
|
-
static const size_t ZSTD_blockHeaderSize = ZSTD_BLOCKHEADERSIZE;
|
90
|
+
static UNUSED_ATTR const size_t ZSTD_blockHeaderSize = ZSTD_BLOCKHEADERSIZE;
|
163
91
|
typedef enum { bt_raw, bt_rle, bt_compressed, bt_reserved } blockType_e;
|
164
92
|
|
165
93
|
#define ZSTD_FRAMECHECKSUMSIZE 4
|
@@ -186,61 +114,86 @@ typedef enum { set_basic, set_rle, set_compressed, set_repeat } symbolEncodingTy
|
|
186
114
|
#define OffFSELog 8
|
187
115
|
#define MaxFSELog MAX(MAX(MLFSELog, LLFSELog), OffFSELog)
|
188
116
|
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
117
|
+
#define ZSTD_MAX_HUF_HEADER_SIZE 128 /* header + <= 127 byte tree description */
|
118
|
+
/* Each table cannot take more than #symbols * FSELog bits */
|
119
|
+
#define ZSTD_MAX_FSE_HEADERS_SIZE (((MaxML + 1) * MLFSELog + (MaxLL + 1) * LLFSELog + (MaxOff + 1) * OffFSELog + 7) / 8)
|
120
|
+
|
121
|
+
static UNUSED_ATTR const U8 LL_bits[MaxLL+1] = {
|
122
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
123
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
124
|
+
1, 1, 1, 1, 2, 2, 3, 3,
|
125
|
+
4, 6, 7, 8, 9,10,11,12,
|
126
|
+
13,14,15,16
|
127
|
+
};
|
128
|
+
static UNUSED_ATTR const S16 LL_defaultNorm[MaxLL+1] = {
|
129
|
+
4, 3, 2, 2, 2, 2, 2, 2,
|
130
|
+
2, 2, 2, 2, 2, 1, 1, 1,
|
131
|
+
2, 2, 2, 2, 2, 2, 2, 2,
|
132
|
+
2, 3, 2, 1, 1, 1, 1, 1,
|
133
|
+
-1,-1,-1,-1
|
134
|
+
};
|
199
135
|
#define LL_DEFAULTNORMLOG 6 /* for static allocation */
|
200
|
-
static const U32 LL_defaultNormLog = LL_DEFAULTNORMLOG;
|
201
|
-
|
202
|
-
static const
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
136
|
+
static UNUSED_ATTR const U32 LL_defaultNormLog = LL_DEFAULTNORMLOG;
|
137
|
+
|
138
|
+
static UNUSED_ATTR const U8 ML_bits[MaxML+1] = {
|
139
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
140
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
141
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
142
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
143
|
+
1, 1, 1, 1, 2, 2, 3, 3,
|
144
|
+
4, 4, 5, 7, 8, 9,10,11,
|
145
|
+
12,13,14,15,16
|
146
|
+
};
|
147
|
+
static UNUSED_ATTR const S16 ML_defaultNorm[MaxML+1] = {
|
148
|
+
1, 4, 3, 2, 2, 2, 2, 2,
|
149
|
+
2, 1, 1, 1, 1, 1, 1, 1,
|
150
|
+
1, 1, 1, 1, 1, 1, 1, 1,
|
151
|
+
1, 1, 1, 1, 1, 1, 1, 1,
|
152
|
+
1, 1, 1, 1, 1, 1, 1, 1,
|
153
|
+
1, 1, 1, 1, 1, 1,-1,-1,
|
154
|
+
-1,-1,-1,-1,-1
|
155
|
+
};
|
216
156
|
#define ML_DEFAULTNORMLOG 6 /* for static allocation */
|
217
|
-
static const U32 ML_defaultNormLog = ML_DEFAULTNORMLOG;
|
218
|
-
|
219
|
-
static const S16 OF_defaultNorm[DefaultMaxOff+1] = {
|
220
|
-
|
221
|
-
|
222
|
-
|
157
|
+
static UNUSED_ATTR const U32 ML_defaultNormLog = ML_DEFAULTNORMLOG;
|
158
|
+
|
159
|
+
static UNUSED_ATTR const S16 OF_defaultNorm[DefaultMaxOff+1] = {
|
160
|
+
1, 1, 1, 1, 1, 1, 2, 2,
|
161
|
+
2, 1, 1, 1, 1, 1, 1, 1,
|
162
|
+
1, 1, 1, 1, 1, 1, 1, 1,
|
163
|
+
-1,-1,-1,-1,-1
|
164
|
+
};
|
223
165
|
#define OF_DEFAULTNORMLOG 5 /* for static allocation */
|
224
|
-
static const U32 OF_defaultNormLog = OF_DEFAULTNORMLOG;
|
166
|
+
static UNUSED_ATTR const U32 OF_defaultNormLog = OF_DEFAULTNORMLOG;
|
225
167
|
|
226
168
|
|
227
169
|
/*-*******************************************
|
228
170
|
* Shared functions to include for inlining
|
229
171
|
*********************************************/
|
230
172
|
static void ZSTD_copy8(void* dst, const void* src) {
|
231
|
-
#
|
173
|
+
#if defined(ZSTD_ARCH_ARM_NEON)
|
232
174
|
vst1_u8((uint8_t*)dst, vld1_u8((const uint8_t*)src));
|
233
175
|
#else
|
234
|
-
|
176
|
+
ZSTD_memcpy(dst, src, 8);
|
235
177
|
#endif
|
236
178
|
}
|
237
|
-
|
238
179
|
#define COPY8(d,s) { ZSTD_copy8(d,s); d+=8; s+=8; }
|
180
|
+
|
181
|
+
/* Need to use memmove here since the literal buffer can now be located within
|
182
|
+
the dst buffer. In circumstances where the op "catches up" to where the
|
183
|
+
literal buffer is, there can be partial overlaps in this call on the final
|
184
|
+
copy if the literal is being shifted by less than 16 bytes. */
|
239
185
|
static void ZSTD_copy16(void* dst, const void* src) {
|
240
|
-
#
|
186
|
+
#if defined(ZSTD_ARCH_ARM_NEON)
|
241
187
|
vst1q_u8((uint8_t*)dst, vld1q_u8((const uint8_t*)src));
|
188
|
+
#elif defined(ZSTD_ARCH_X86_SSE2)
|
189
|
+
_mm_storeu_si128((__m128i*)dst, _mm_loadu_si128((const __m128i*)src));
|
190
|
+
#elif defined(__clang__)
|
191
|
+
ZSTD_memmove(dst, src, 16);
|
242
192
|
#else
|
243
|
-
|
193
|
+
/* ZSTD_memmove is not inlined properly by gcc */
|
194
|
+
BYTE copy16_buf[16];
|
195
|
+
ZSTD_memcpy(copy16_buf, src, 16);
|
196
|
+
ZSTD_memcpy(dst, copy16_buf, 16);
|
244
197
|
#endif
|
245
198
|
}
|
246
199
|
#define COPY16(d,s) { ZSTD_copy16(d,s); d+=16; s+=16; }
|
@@ -255,13 +208,13 @@ typedef enum {
|
|
255
208
|
} ZSTD_overlap_e;
|
256
209
|
|
257
210
|
/*! ZSTD_wildcopy() :
|
258
|
-
* Custom version of
|
211
|
+
* Custom version of ZSTD_memcpy(), can over read/write up to WILDCOPY_OVERLENGTH bytes (if length==0)
|
259
212
|
* @param ovtype controls the overlap detection
|
260
213
|
* - ZSTD_no_overlap: The source and destination are guaranteed to be at least WILDCOPY_VECLEN bytes apart.
|
261
214
|
* - ZSTD_overlap_src_before_dst: The src and dst may overlap, but they MUST be at least 8 bytes apart.
|
262
215
|
* The src buffer must be before the dst buffer.
|
263
216
|
*/
|
264
|
-
MEM_STATIC FORCE_INLINE_ATTR
|
217
|
+
MEM_STATIC FORCE_INLINE_ATTR
|
265
218
|
void ZSTD_wildcopy(void* dst, const void* src, ptrdiff_t length, ZSTD_overlap_e const ovtype)
|
266
219
|
{
|
267
220
|
ptrdiff_t diff = (BYTE*)dst - (const BYTE*)src;
|
@@ -269,8 +222,6 @@ void ZSTD_wildcopy(void* dst, const void* src, ptrdiff_t length, ZSTD_overlap_e
|
|
269
222
|
BYTE* op = (BYTE*)dst;
|
270
223
|
BYTE* const oend = op + length;
|
271
224
|
|
272
|
-
assert(diff >= 8 || (ovtype == ZSTD_no_overlap && diff <= -WILDCOPY_VECLEN));
|
273
|
-
|
274
225
|
if (ovtype == ZSTD_overlap_src_before_dst && diff < WILDCOPY_VECLEN) {
|
275
226
|
/* Handle short offset copies. */
|
276
227
|
do {
|
@@ -284,14 +235,16 @@ void ZSTD_wildcopy(void* dst, const void* src, ptrdiff_t length, ZSTD_overlap_e
|
|
284
235
|
* one COPY16() in the first call. Then, do two calls per loop since
|
285
236
|
* at that point it is more likely to have a high trip count.
|
286
237
|
*/
|
287
|
-
#
|
238
|
+
#ifdef __aarch64__
|
288
239
|
do {
|
289
240
|
COPY16(op, ip);
|
290
241
|
}
|
291
242
|
while (op < oend);
|
292
243
|
#else
|
293
|
-
|
294
|
-
if (
|
244
|
+
ZSTD_copy16(op, ip);
|
245
|
+
if (16 >= length) return;
|
246
|
+
op += 16;
|
247
|
+
ip += 16;
|
295
248
|
do {
|
296
249
|
COPY16(op, ip);
|
297
250
|
COPY16(op, ip);
|
@@ -305,7 +258,7 @@ MEM_STATIC size_t ZSTD_limitCopy(void* dst, size_t dstCapacity, const void* src,
|
|
305
258
|
{
|
306
259
|
size_t const length = MIN(dstCapacity, srcSize);
|
307
260
|
if (length > 0) {
|
308
|
-
|
261
|
+
ZSTD_memcpy(dst, src, length);
|
309
262
|
}
|
310
263
|
return length;
|
311
264
|
}
|
@@ -320,28 +273,46 @@ MEM_STATIC size_t ZSTD_limitCopy(void* dst, size_t dstCapacity, const void* src,
|
|
320
273
|
* In which case, resize it down to free some memory */
|
321
274
|
#define ZSTD_WORKSPACETOOLARGE_MAXDURATION 128
|
322
275
|
|
276
|
+
/* Controls whether the input/output buffer is buffered or stable. */
|
277
|
+
typedef enum {
|
278
|
+
ZSTD_bm_buffered = 0, /* Buffer the input/output */
|
279
|
+
ZSTD_bm_stable = 1 /* ZSTD_inBuffer/ZSTD_outBuffer is stable */
|
280
|
+
} ZSTD_bufferMode_e;
|
281
|
+
|
323
282
|
|
324
283
|
/*-*******************************************
|
325
284
|
* Private declarations
|
326
285
|
*********************************************/
|
327
286
|
typedef struct seqDef_s {
|
328
|
-
U32
|
287
|
+
U32 offBase; /* offBase == Offset + ZSTD_REP_NUM, or repcode 1,2,3 */
|
329
288
|
U16 litLength;
|
330
|
-
U16 matchLength
|
289
|
+
U16 mlBase; /* mlBase == matchLength - MINMATCH */
|
331
290
|
} seqDef;
|
332
291
|
|
292
|
+
/* Controls whether seqStore has a single "long" litLength or matchLength. See seqStore_t. */
|
293
|
+
typedef enum {
|
294
|
+
ZSTD_llt_none = 0, /* no longLengthType */
|
295
|
+
ZSTD_llt_literalLength = 1, /* represents a long literal */
|
296
|
+
ZSTD_llt_matchLength = 2 /* represents a long match */
|
297
|
+
} ZSTD_longLengthType_e;
|
298
|
+
|
333
299
|
typedef struct {
|
334
300
|
seqDef* sequencesStart;
|
335
|
-
seqDef* sequences;
|
301
|
+
seqDef* sequences; /* ptr to end of sequences */
|
336
302
|
BYTE* litStart;
|
337
|
-
BYTE* lit;
|
303
|
+
BYTE* lit; /* ptr to end of literals */
|
338
304
|
BYTE* llCode;
|
339
305
|
BYTE* mlCode;
|
340
306
|
BYTE* ofCode;
|
341
307
|
size_t maxNbSeq;
|
342
308
|
size_t maxNbLit;
|
343
|
-
|
344
|
-
|
309
|
+
|
310
|
+
/* longLengthPos and longLengthType to allow us to represent either a single litLength or matchLength
|
311
|
+
* in the seqStore that has a value larger than U16 (if it exists). To do so, we increment
|
312
|
+
* the existing value of the litLength or matchLength by 0x10000.
|
313
|
+
*/
|
314
|
+
ZSTD_longLengthType_e longLengthType;
|
315
|
+
U32 longLengthPos; /* Index of the sequence to apply long length modification to */
|
345
316
|
} seqStore_t;
|
346
317
|
|
347
318
|
typedef struct {
|
@@ -351,18 +322,18 @@ typedef struct {
|
|
351
322
|
|
352
323
|
/**
|
353
324
|
* Returns the ZSTD_sequenceLength for the given sequences. It handles the decoding of long sequences
|
354
|
-
* indicated by longLengthPos and
|
325
|
+
* indicated by longLengthPos and longLengthType, and adds MINMATCH back to matchLength.
|
355
326
|
*/
|
356
327
|
MEM_STATIC ZSTD_sequenceLength ZSTD_getSequenceLength(seqStore_t const* seqStore, seqDef const* seq)
|
357
328
|
{
|
358
329
|
ZSTD_sequenceLength seqLen;
|
359
330
|
seqLen.litLength = seq->litLength;
|
360
|
-
seqLen.matchLength = seq->
|
331
|
+
seqLen.matchLength = seq->mlBase + MINMATCH;
|
361
332
|
if (seqStore->longLengthPos == (U32)(seq - seqStore->sequencesStart)) {
|
362
|
-
if (seqStore->
|
333
|
+
if (seqStore->longLengthType == ZSTD_llt_literalLength) {
|
363
334
|
seqLen.litLength += 0xFFFF;
|
364
335
|
}
|
365
|
-
if (seqStore->
|
336
|
+
if (seqStore->longLengthType == ZSTD_llt_matchLength) {
|
366
337
|
seqLen.matchLength += 0xFFFF;
|
367
338
|
}
|
368
339
|
}
|
@@ -384,9 +355,9 @@ const seqStore_t* ZSTD_getSeqStore(const ZSTD_CCtx* ctx); /* compress & dictBu
|
|
384
355
|
void ZSTD_seqToCodes(const seqStore_t* seqStorePtr); /* compress, dictBuilder, decodeCorpus (shouldn't get its definition from here) */
|
385
356
|
|
386
357
|
/* custom memory allocation functions */
|
387
|
-
void*
|
388
|
-
void*
|
389
|
-
void
|
358
|
+
void* ZSTD_customMalloc(size_t size, ZSTD_customMem customMem);
|
359
|
+
void* ZSTD_customCalloc(size_t size, ZSTD_customMem customMem);
|
360
|
+
void ZSTD_customFree(void* ptr, ZSTD_customMem customMem);
|
390
361
|
|
391
362
|
|
392
363
|
MEM_STATIC U32 ZSTD_highbit32(U32 val) /* compress, dictBuilder, decodeCorpus */
|
@@ -394,8 +365,18 @@ MEM_STATIC U32 ZSTD_highbit32(U32 val) /* compress, dictBuilder, decodeCorpus
|
|
394
365
|
assert(val != 0);
|
395
366
|
{
|
396
367
|
# if defined(_MSC_VER) /* Visual */
|
397
|
-
|
398
|
-
|
368
|
+
# if STATIC_BMI2 == 1
|
369
|
+
return _lzcnt_u32(val)^31;
|
370
|
+
# else
|
371
|
+
if (val != 0) {
|
372
|
+
unsigned long r;
|
373
|
+
_BitScanReverse(&r, val);
|
374
|
+
return (unsigned)r;
|
375
|
+
} else {
|
376
|
+
/* Should not reach this code path */
|
377
|
+
__assume(0);
|
378
|
+
}
|
379
|
+
# endif
|
399
380
|
# elif defined(__GNUC__) && (__GNUC__ >= 3) /* GCC Intrinsic */
|
400
381
|
return __builtin_clz (val) ^ 31;
|
401
382
|
# elif defined(__ICCARM__) /* IAR Intrinsic */
|
@@ -413,6 +394,63 @@ MEM_STATIC U32 ZSTD_highbit32(U32 val) /* compress, dictBuilder, decodeCorpus
|
|
413
394
|
}
|
414
395
|
}
|
415
396
|
|
397
|
+
/**
|
398
|
+
* Counts the number of trailing zeros of a `size_t`.
|
399
|
+
* Most compilers should support CTZ as a builtin. A backup
|
400
|
+
* implementation is provided if the builtin isn't supported, but
|
401
|
+
* it may not be terribly efficient.
|
402
|
+
*/
|
403
|
+
MEM_STATIC unsigned ZSTD_countTrailingZeros(size_t val)
|
404
|
+
{
|
405
|
+
if (MEM_64bits()) {
|
406
|
+
# if defined(_MSC_VER) && defined(_WIN64)
|
407
|
+
# if STATIC_BMI2
|
408
|
+
return _tzcnt_u64(val);
|
409
|
+
# else
|
410
|
+
if (val != 0) {
|
411
|
+
unsigned long r;
|
412
|
+
_BitScanForward64(&r, (U64)val);
|
413
|
+
return (unsigned)r;
|
414
|
+
} else {
|
415
|
+
/* Should not reach this code path */
|
416
|
+
__assume(0);
|
417
|
+
}
|
418
|
+
# endif
|
419
|
+
# elif defined(__GNUC__) && (__GNUC__ >= 4)
|
420
|
+
return __builtin_ctzll((U64)val);
|
421
|
+
# else
|
422
|
+
static const int DeBruijnBytePos[64] = { 0, 1, 2, 7, 3, 13, 8, 19,
|
423
|
+
4, 25, 14, 28, 9, 34, 20, 56,
|
424
|
+
5, 17, 26, 54, 15, 41, 29, 43,
|
425
|
+
10, 31, 38, 35, 21, 45, 49, 57,
|
426
|
+
63, 6, 12, 18, 24, 27, 33, 55,
|
427
|
+
16, 53, 40, 42, 30, 37, 44, 48,
|
428
|
+
62, 11, 23, 32, 52, 39, 36, 47,
|
429
|
+
61, 22, 51, 46, 60, 50, 59, 58 };
|
430
|
+
return DeBruijnBytePos[((U64)((val & -(long long)val) * 0x0218A392CDABBD3FULL)) >> 58];
|
431
|
+
# endif
|
432
|
+
} else { /* 32 bits */
|
433
|
+
# if defined(_MSC_VER)
|
434
|
+
if (val != 0) {
|
435
|
+
unsigned long r;
|
436
|
+
_BitScanForward(&r, (U32)val);
|
437
|
+
return (unsigned)r;
|
438
|
+
} else {
|
439
|
+
/* Should not reach this code path */
|
440
|
+
__assume(0);
|
441
|
+
}
|
442
|
+
# elif defined(__GNUC__) && (__GNUC__ >= 3)
|
443
|
+
return __builtin_ctz((U32)val);
|
444
|
+
# else
|
445
|
+
static const int DeBruijnBytePos[32] = { 0, 1, 28, 2, 29, 14, 24, 3,
|
446
|
+
30, 22, 20, 15, 25, 17, 4, 8,
|
447
|
+
31, 27, 13, 23, 21, 19, 16, 7,
|
448
|
+
26, 12, 18, 6, 11, 5, 10, 9 };
|
449
|
+
return DeBruijnBytePos[((U32)((val & -(S32)val) * 0x077CB531U)) >> 27];
|
450
|
+
# endif
|
451
|
+
}
|
452
|
+
}
|
453
|
+
|
416
454
|
|
417
455
|
/* ZSTD_invalidateRepCodes() :
|
418
456
|
* ensures next compression will not use repcodes from previous block.
|
@@ -439,6 +477,14 @@ size_t ZSTD_getcBlockSize(const void* src, size_t srcSize,
|
|
439
477
|
size_t ZSTD_decodeSeqHeaders(ZSTD_DCtx* dctx, int* nbSeqPtr,
|
440
478
|
const void* src, size_t srcSize);
|
441
479
|
|
480
|
+
/**
|
481
|
+
* @returns true iff the CPU supports dynamic BMI2 dispatch.
|
482
|
+
*/
|
483
|
+
MEM_STATIC int ZSTD_cpuSupportsBmi2(void)
|
484
|
+
{
|
485
|
+
ZSTD_cpuid_t cpuid = ZSTD_cpuid();
|
486
|
+
return ZSTD_cpuid_bmi1(cpuid) && ZSTD_cpuid_bmi2(cpuid);
|
487
|
+
}
|
442
488
|
|
443
489
|
#if defined (__cplusplus)
|
444
490
|
}
|