zstdlib 0.3.0-x86-mingw32 → 0.8.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 +30 -1
- data/README.md +2 -2
- data/Rakefile +1 -1
- data/ext/zstdlib/extconf.rb +3 -3
- data/ext/zstdlib/ruby/zlib-2.7/zstdlib.c +4895 -0
- data/ext/zstdlib/ruby/zlib-3.0/zstdlib.c +4994 -0
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/bitstream.h +59 -51
- data/ext/zstdlib/zstd-1.5.0/lib/common/compiler.h +289 -0
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/cpu.h +1 -3
- data/ext/zstdlib/zstd-1.5.0/lib/common/debug.c +24 -0
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/debug.h +22 -49
- data/ext/zstdlib/zstd-1.5.0/lib/common/entropy_common.c +362 -0
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/error_private.c +3 -1
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/error_private.h +8 -4
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/fse.h +50 -42
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/fse_decompress.c +149 -55
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/huf.h +43 -39
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/mem.h +69 -25
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/pool.c +30 -20
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/pool.h +3 -3
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/threading.c +51 -4
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/threading.h +36 -4
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/xxhash.c +40 -92
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/xxhash.h +12 -32
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/common/zstd_common.c +10 -10
- data/ext/zstdlib/zstd-1.5.0/lib/common/zstd_deps.h +111 -0
- data/ext/zstdlib/zstd-1.5.0/lib/common/zstd_internal.h +490 -0
- data/ext/zstdlib/zstd-1.5.0/lib/common/zstd_trace.h +154 -0
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/fse_compress.c +47 -63
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/hist.c +41 -63
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/hist.h +13 -33
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/huf_compress.c +332 -193
- data/ext/zstdlib/zstd-1.5.0/lib/compress/zstd_compress.c +6393 -0
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/zstd_compress_internal.h +522 -86
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/zstd_compress_literals.c +25 -16
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/zstd_compress_literals.h +2 -2
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/zstd_compress_sequences.c +50 -24
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/zstd_compress_sequences.h +11 -4
- data/ext/zstdlib/zstd-1.5.0/lib/compress/zstd_compress_superblock.c +572 -0
- data/ext/zstdlib/zstd-1.5.0/lib/compress/zstd_compress_superblock.h +32 -0
- data/ext/zstdlib/zstd-1.5.0/lib/compress/zstd_cwksp.h +662 -0
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/zstd_double_fast.c +43 -41
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/zstd_double_fast.h +2 -2
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/zstd_fast.c +85 -80
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/zstd_fast.h +2 -2
- data/ext/zstdlib/zstd-1.5.0/lib/compress/zstd_lazy.c +2184 -0
- data/ext/zstdlib/zstd-1.5.0/lib/compress/zstd_lazy.h +125 -0
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/zstd_ldm.c +333 -208
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/zstd_ldm.h +15 -3
- data/ext/zstdlib/zstd-1.5.0/lib/compress/zstd_ldm_geartab.h +103 -0
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/zstd_opt.c +228 -129
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/zstd_opt.h +1 -1
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/compress/zstdmt_compress.c +151 -440
- data/ext/zstdlib/zstd-1.5.0/lib/compress/zstdmt_compress.h +110 -0
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/decompress/huf_decompress.c +395 -276
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/decompress/zstd_ddict.c +20 -16
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/decompress/zstd_ddict.h +3 -3
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/decompress/zstd_decompress.c +628 -231
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/decompress/zstd_decompress_block.c +606 -380
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/decompress/zstd_decompress_block.h +8 -5
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/decompress/zstd_decompress_internal.h +39 -9
- data/ext/zstdlib/zstd-1.5.0/lib/zdict.h +452 -0
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/lib/zstd.h +740 -153
- data/ext/zstdlib/{zstd-1.4.2/lib/common → zstd-1.5.0/lib}/zstd_errors.h +3 -1
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/zlibWrapper/gzclose.c +1 -1
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/zlibWrapper/gzcompatibility.h +1 -1
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/zlibWrapper/gzguts.h +0 -0
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/zlibWrapper/gzlib.c +9 -9
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/zlibWrapper/gzread.c +16 -8
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/zlibWrapper/gzwrite.c +8 -8
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/zlibWrapper/zstd_zlibwrapper.c +131 -45
- data/ext/zstdlib/{zstd-1.4.2 → zstd-1.5.0}/zlibWrapper/zstd_zlibwrapper.h +1 -1
- 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
- metadata +76 -67
- data/ext/zstdlib/zstd-1.4.2/lib/common/compiler.h +0 -147
- data/ext/zstdlib/zstd-1.4.2/lib/common/debug.c +0 -44
- data/ext/zstdlib/zstd-1.4.2/lib/common/entropy_common.c +0 -236
- data/ext/zstdlib/zstd-1.4.2/lib/common/zstd_internal.h +0 -371
- data/ext/zstdlib/zstd-1.4.2/lib/compress/zstd_compress.c +0 -3904
- data/ext/zstdlib/zstd-1.4.2/lib/compress/zstd_lazy.c +0 -1111
- data/ext/zstdlib/zstd-1.4.2/lib/compress/zstd_lazy.h +0 -67
- data/ext/zstdlib/zstd-1.4.2/lib/compress/zstdmt_compress.h +0 -192
@@ -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 */
|
@@ -0,0 +1,490 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) Yann Collet, 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
|
+
#ifndef ZSTD_CCOMMON_H_MODULE
|
12
|
+
#define ZSTD_CCOMMON_H_MODULE
|
13
|
+
|
14
|
+
/* this module contains definitions which must be identical
|
15
|
+
* across compression, decompression and dictBuilder.
|
16
|
+
* It also contains a few functions useful to at least 2 of them
|
17
|
+
* and which benefit from being inlined */
|
18
|
+
|
19
|
+
/*-*************************************
|
20
|
+
* Dependencies
|
21
|
+
***************************************/
|
22
|
+
#if !defined(ZSTD_NO_INTRINSICS) && defined(__ARM_NEON)
|
23
|
+
#include <arm_neon.h>
|
24
|
+
#endif
|
25
|
+
#include "compiler.h"
|
26
|
+
#include "mem.h"
|
27
|
+
#include "debug.h" /* assert, DEBUGLOG, RAWLOG, g_debuglevel */
|
28
|
+
#include "error_private.h"
|
29
|
+
#define ZSTD_STATIC_LINKING_ONLY
|
30
|
+
#include "../zstd.h"
|
31
|
+
#define FSE_STATIC_LINKING_ONLY
|
32
|
+
#include "fse.h"
|
33
|
+
#define HUF_STATIC_LINKING_ONLY
|
34
|
+
#include "huf.h"
|
35
|
+
#ifndef XXH_STATIC_LINKING_ONLY
|
36
|
+
# define XXH_STATIC_LINKING_ONLY /* XXH64_state_t */
|
37
|
+
#endif
|
38
|
+
#include "xxhash.h" /* XXH_reset, update, digest */
|
39
|
+
#ifndef ZSTD_NO_TRACE
|
40
|
+
# include "zstd_trace.h"
|
41
|
+
#else
|
42
|
+
# define ZSTD_TRACE 0
|
43
|
+
#endif
|
44
|
+
|
45
|
+
#if defined (__cplusplus)
|
46
|
+
extern "C" {
|
47
|
+
#endif
|
48
|
+
|
49
|
+
/* ---- static assert (debug) --- */
|
50
|
+
#define ZSTD_STATIC_ASSERT(c) DEBUG_STATIC_ASSERT(c)
|
51
|
+
#define ZSTD_isError ERR_isError /* for inlining */
|
52
|
+
#define FSE_isError ERR_isError
|
53
|
+
#define HUF_isError ERR_isError
|
54
|
+
|
55
|
+
|
56
|
+
/*-*************************************
|
57
|
+
* shared macros
|
58
|
+
***************************************/
|
59
|
+
#undef MIN
|
60
|
+
#undef MAX
|
61
|
+
#define MIN(a,b) ((a)<(b) ? (a) : (b))
|
62
|
+
#define MAX(a,b) ((a)>(b) ? (a) : (b))
|
63
|
+
|
64
|
+
/**
|
65
|
+
* Ignore: this is an internal helper.
|
66
|
+
*
|
67
|
+
* This is a helper function to help force C99-correctness during compilation.
|
68
|
+
* Under strict compilation modes, variadic macro arguments can't be empty.
|
69
|
+
* However, variadic function arguments can be. Using a function therefore lets
|
70
|
+
* us statically check that at least one (string) argument was passed,
|
71
|
+
* independent of the compilation flags.
|
72
|
+
*/
|
73
|
+
static INLINE_KEYWORD UNUSED_ATTR
|
74
|
+
void _force_has_format_string(const char *format, ...) {
|
75
|
+
(void)format;
|
76
|
+
}
|
77
|
+
|
78
|
+
/**
|
79
|
+
* Ignore: this is an internal helper.
|
80
|
+
*
|
81
|
+
* We want to force this function invocation to be syntactically correct, but
|
82
|
+
* we don't want to force runtime evaluation of its arguments.
|
83
|
+
*/
|
84
|
+
#define _FORCE_HAS_FORMAT_STRING(...) \
|
85
|
+
if (0) { \
|
86
|
+
_force_has_format_string(__VA_ARGS__); \
|
87
|
+
}
|
88
|
+
|
89
|
+
/**
|
90
|
+
* Return the specified error if the condition evaluates to true.
|
91
|
+
*
|
92
|
+
* In debug modes, prints additional information.
|
93
|
+
* In order to do that (particularly, printing the conditional that failed),
|
94
|
+
* this can't just wrap RETURN_ERROR().
|
95
|
+
*/
|
96
|
+
#define RETURN_ERROR_IF(cond, err, ...) \
|
97
|
+
if (cond) { \
|
98
|
+
RAWLOG(3, "%s:%d: ERROR!: check %s failed, returning %s", \
|
99
|
+
__FILE__, __LINE__, ZSTD_QUOTE(cond), ZSTD_QUOTE(ERROR(err))); \
|
100
|
+
_FORCE_HAS_FORMAT_STRING(__VA_ARGS__); \
|
101
|
+
RAWLOG(3, ": " __VA_ARGS__); \
|
102
|
+
RAWLOG(3, "\n"); \
|
103
|
+
return ERROR(err); \
|
104
|
+
}
|
105
|
+
|
106
|
+
/**
|
107
|
+
* Unconditionally return the specified error.
|
108
|
+
*
|
109
|
+
* In debug modes, prints additional information.
|
110
|
+
*/
|
111
|
+
#define RETURN_ERROR(err, ...) \
|
112
|
+
do { \
|
113
|
+
RAWLOG(3, "%s:%d: ERROR!: unconditional check failed, returning %s", \
|
114
|
+
__FILE__, __LINE__, ZSTD_QUOTE(ERROR(err))); \
|
115
|
+
_FORCE_HAS_FORMAT_STRING(__VA_ARGS__); \
|
116
|
+
RAWLOG(3, ": " __VA_ARGS__); \
|
117
|
+
RAWLOG(3, "\n"); \
|
118
|
+
return ERROR(err); \
|
119
|
+
} while(0);
|
120
|
+
|
121
|
+
/**
|
122
|
+
* If the provided expression evaluates to an error code, returns that error code.
|
123
|
+
*
|
124
|
+
* In debug modes, prints additional information.
|
125
|
+
*/
|
126
|
+
#define FORWARD_IF_ERROR(err, ...) \
|
127
|
+
do { \
|
128
|
+
size_t const err_code = (err); \
|
129
|
+
if (ERR_isError(err_code)) { \
|
130
|
+
RAWLOG(3, "%s:%d: ERROR!: forwarding error in %s: %s", \
|
131
|
+
__FILE__, __LINE__, ZSTD_QUOTE(err), ERR_getErrorName(err_code)); \
|
132
|
+
_FORCE_HAS_FORMAT_STRING(__VA_ARGS__); \
|
133
|
+
RAWLOG(3, ": " __VA_ARGS__); \
|
134
|
+
RAWLOG(3, "\n"); \
|
135
|
+
return err_code; \
|
136
|
+
} \
|
137
|
+
} while(0);
|
138
|
+
|
139
|
+
|
140
|
+
/*-*************************************
|
141
|
+
* Common constants
|
142
|
+
***************************************/
|
143
|
+
#define ZSTD_OPT_NUM (1<<12)
|
144
|
+
|
145
|
+
#define ZSTD_REP_NUM 3 /* number of repcodes */
|
146
|
+
#define ZSTD_REP_MOVE (ZSTD_REP_NUM-1)
|
147
|
+
static UNUSED_ATTR const U32 repStartValue[ZSTD_REP_NUM] = { 1, 4, 8 };
|
148
|
+
|
149
|
+
#define KB *(1 <<10)
|
150
|
+
#define MB *(1 <<20)
|
151
|
+
#define GB *(1U<<30)
|
152
|
+
|
153
|
+
#define BIT7 128
|
154
|
+
#define BIT6 64
|
155
|
+
#define BIT5 32
|
156
|
+
#define BIT4 16
|
157
|
+
#define BIT1 2
|
158
|
+
#define BIT0 1
|
159
|
+
|
160
|
+
#define ZSTD_WINDOWLOG_ABSOLUTEMIN 10
|
161
|
+
static UNUSED_ATTR const size_t ZSTD_fcs_fieldSize[4] = { 0, 2, 4, 8 };
|
162
|
+
static UNUSED_ATTR const size_t ZSTD_did_fieldSize[4] = { 0, 1, 2, 4 };
|
163
|
+
|
164
|
+
#define ZSTD_FRAMEIDSIZE 4 /* magic number size */
|
165
|
+
|
166
|
+
#define ZSTD_BLOCKHEADERSIZE 3 /* C standard doesn't allow `static const` variable to be init using another `static const` variable */
|
167
|
+
static UNUSED_ATTR const size_t ZSTD_blockHeaderSize = ZSTD_BLOCKHEADERSIZE;
|
168
|
+
typedef enum { bt_raw, bt_rle, bt_compressed, bt_reserved } blockType_e;
|
169
|
+
|
170
|
+
#define ZSTD_FRAMECHECKSUMSIZE 4
|
171
|
+
|
172
|
+
#define MIN_SEQUENCES_SIZE 1 /* nbSeq==0 */
|
173
|
+
#define MIN_CBLOCK_SIZE (1 /*litCSize*/ + 1 /* RLE or RAW */ + MIN_SEQUENCES_SIZE /* nbSeq==0 */) /* for a non-null block */
|
174
|
+
|
175
|
+
#define HufLog 12
|
176
|
+
typedef enum { set_basic, set_rle, set_compressed, set_repeat } symbolEncodingType_e;
|
177
|
+
|
178
|
+
#define LONGNBSEQ 0x7F00
|
179
|
+
|
180
|
+
#define MINMATCH 3
|
181
|
+
|
182
|
+
#define Litbits 8
|
183
|
+
#define MaxLit ((1<<Litbits) - 1)
|
184
|
+
#define MaxML 52
|
185
|
+
#define MaxLL 35
|
186
|
+
#define DefaultMaxOff 28
|
187
|
+
#define MaxOff 31
|
188
|
+
#define MaxSeq MAX(MaxLL, MaxML) /* Assumption : MaxOff < MaxLL,MaxML */
|
189
|
+
#define MLFSELog 9
|
190
|
+
#define LLFSELog 9
|
191
|
+
#define OffFSELog 8
|
192
|
+
#define MaxFSELog MAX(MAX(MLFSELog, LLFSELog), OffFSELog)
|
193
|
+
|
194
|
+
#define ZSTD_MAX_HUF_HEADER_SIZE 128 /* header + <= 127 byte tree description */
|
195
|
+
/* Each table cannot take more than #symbols * FSELog bits */
|
196
|
+
#define ZSTD_MAX_FSE_HEADERS_SIZE (((MaxML + 1) * MLFSELog + (MaxLL + 1) * LLFSELog + (MaxOff + 1) * OffFSELog + 7) / 8)
|
197
|
+
|
198
|
+
static UNUSED_ATTR const U32 LL_bits[MaxLL+1] = {
|
199
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
200
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
201
|
+
1, 1, 1, 1, 2, 2, 3, 3,
|
202
|
+
4, 6, 7, 8, 9,10,11,12,
|
203
|
+
13,14,15,16
|
204
|
+
};
|
205
|
+
static UNUSED_ATTR const S16 LL_defaultNorm[MaxLL+1] = {
|
206
|
+
4, 3, 2, 2, 2, 2, 2, 2,
|
207
|
+
2, 2, 2, 2, 2, 1, 1, 1,
|
208
|
+
2, 2, 2, 2, 2, 2, 2, 2,
|
209
|
+
2, 3, 2, 1, 1, 1, 1, 1,
|
210
|
+
-1,-1,-1,-1
|
211
|
+
};
|
212
|
+
#define LL_DEFAULTNORMLOG 6 /* for static allocation */
|
213
|
+
static UNUSED_ATTR const U32 LL_defaultNormLog = LL_DEFAULTNORMLOG;
|
214
|
+
|
215
|
+
static UNUSED_ATTR const U32 ML_bits[MaxML+1] = {
|
216
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
217
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
218
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
219
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
220
|
+
1, 1, 1, 1, 2, 2, 3, 3,
|
221
|
+
4, 4, 5, 7, 8, 9,10,11,
|
222
|
+
12,13,14,15,16
|
223
|
+
};
|
224
|
+
static UNUSED_ATTR const S16 ML_defaultNorm[MaxML+1] = {
|
225
|
+
1, 4, 3, 2, 2, 2, 2, 2,
|
226
|
+
2, 1, 1, 1, 1, 1, 1, 1,
|
227
|
+
1, 1, 1, 1, 1, 1, 1, 1,
|
228
|
+
1, 1, 1, 1, 1, 1, 1, 1,
|
229
|
+
1, 1, 1, 1, 1, 1, 1, 1,
|
230
|
+
1, 1, 1, 1, 1, 1,-1,-1,
|
231
|
+
-1,-1,-1,-1,-1
|
232
|
+
};
|
233
|
+
#define ML_DEFAULTNORMLOG 6 /* for static allocation */
|
234
|
+
static UNUSED_ATTR const U32 ML_defaultNormLog = ML_DEFAULTNORMLOG;
|
235
|
+
|
236
|
+
static UNUSED_ATTR const S16 OF_defaultNorm[DefaultMaxOff+1] = {
|
237
|
+
1, 1, 1, 1, 1, 1, 2, 2,
|
238
|
+
2, 1, 1, 1, 1, 1, 1, 1,
|
239
|
+
1, 1, 1, 1, 1, 1, 1, 1,
|
240
|
+
-1,-1,-1,-1,-1
|
241
|
+
};
|
242
|
+
#define OF_DEFAULTNORMLOG 5 /* for static allocation */
|
243
|
+
static UNUSED_ATTR const U32 OF_defaultNormLog = OF_DEFAULTNORMLOG;
|
244
|
+
|
245
|
+
|
246
|
+
/*-*******************************************
|
247
|
+
* Shared functions to include for inlining
|
248
|
+
*********************************************/
|
249
|
+
static void ZSTD_copy8(void* dst, const void* src) {
|
250
|
+
#if !defined(ZSTD_NO_INTRINSICS) && defined(__ARM_NEON)
|
251
|
+
vst1_u8((uint8_t*)dst, vld1_u8((const uint8_t*)src));
|
252
|
+
#else
|
253
|
+
ZSTD_memcpy(dst, src, 8);
|
254
|
+
#endif
|
255
|
+
}
|
256
|
+
|
257
|
+
#define COPY8(d,s) { ZSTD_copy8(d,s); d+=8; s+=8; }
|
258
|
+
static void ZSTD_copy16(void* dst, const void* src) {
|
259
|
+
#if !defined(ZSTD_NO_INTRINSICS) && defined(__ARM_NEON)
|
260
|
+
vst1q_u8((uint8_t*)dst, vld1q_u8((const uint8_t*)src));
|
261
|
+
#else
|
262
|
+
ZSTD_memcpy(dst, src, 16);
|
263
|
+
#endif
|
264
|
+
}
|
265
|
+
#define COPY16(d,s) { ZSTD_copy16(d,s); d+=16; s+=16; }
|
266
|
+
|
267
|
+
#define WILDCOPY_OVERLENGTH 32
|
268
|
+
#define WILDCOPY_VECLEN 16
|
269
|
+
|
270
|
+
typedef enum {
|
271
|
+
ZSTD_no_overlap,
|
272
|
+
ZSTD_overlap_src_before_dst
|
273
|
+
/* ZSTD_overlap_dst_before_src, */
|
274
|
+
} ZSTD_overlap_e;
|
275
|
+
|
276
|
+
/*! ZSTD_wildcopy() :
|
277
|
+
* Custom version of ZSTD_memcpy(), can over read/write up to WILDCOPY_OVERLENGTH bytes (if length==0)
|
278
|
+
* @param ovtype controls the overlap detection
|
279
|
+
* - ZSTD_no_overlap: The source and destination are guaranteed to be at least WILDCOPY_VECLEN bytes apart.
|
280
|
+
* - ZSTD_overlap_src_before_dst: The src and dst may overlap, but they MUST be at least 8 bytes apart.
|
281
|
+
* The src buffer must be before the dst buffer.
|
282
|
+
*/
|
283
|
+
MEM_STATIC FORCE_INLINE_ATTR
|
284
|
+
void ZSTD_wildcopy(void* dst, const void* src, ptrdiff_t length, ZSTD_overlap_e const ovtype)
|
285
|
+
{
|
286
|
+
ptrdiff_t diff = (BYTE*)dst - (const BYTE*)src;
|
287
|
+
const BYTE* ip = (const BYTE*)src;
|
288
|
+
BYTE* op = (BYTE*)dst;
|
289
|
+
BYTE* const oend = op + length;
|
290
|
+
|
291
|
+
assert(diff >= 8 || (ovtype == ZSTD_no_overlap && diff <= -WILDCOPY_VECLEN));
|
292
|
+
|
293
|
+
if (ovtype == ZSTD_overlap_src_before_dst && diff < WILDCOPY_VECLEN) {
|
294
|
+
/* Handle short offset copies. */
|
295
|
+
do {
|
296
|
+
COPY8(op, ip)
|
297
|
+
} while (op < oend);
|
298
|
+
} else {
|
299
|
+
assert(diff >= WILDCOPY_VECLEN || diff <= -WILDCOPY_VECLEN);
|
300
|
+
/* Separate out the first COPY16() call because the copy length is
|
301
|
+
* almost certain to be short, so the branches have different
|
302
|
+
* probabilities. Since it is almost certain to be short, only do
|
303
|
+
* one COPY16() in the first call. Then, do two calls per loop since
|
304
|
+
* at that point it is more likely to have a high trip count.
|
305
|
+
*/
|
306
|
+
#ifdef __aarch64__
|
307
|
+
do {
|
308
|
+
COPY16(op, ip);
|
309
|
+
}
|
310
|
+
while (op < oend);
|
311
|
+
#else
|
312
|
+
ZSTD_copy16(op, ip);
|
313
|
+
if (16 >= length) return;
|
314
|
+
op += 16;
|
315
|
+
ip += 16;
|
316
|
+
do {
|
317
|
+
COPY16(op, ip);
|
318
|
+
COPY16(op, ip);
|
319
|
+
}
|
320
|
+
while (op < oend);
|
321
|
+
#endif
|
322
|
+
}
|
323
|
+
}
|
324
|
+
|
325
|
+
MEM_STATIC size_t ZSTD_limitCopy(void* dst, size_t dstCapacity, const void* src, size_t srcSize)
|
326
|
+
{
|
327
|
+
size_t const length = MIN(dstCapacity, srcSize);
|
328
|
+
if (length > 0) {
|
329
|
+
ZSTD_memcpy(dst, src, length);
|
330
|
+
}
|
331
|
+
return length;
|
332
|
+
}
|
333
|
+
|
334
|
+
/* define "workspace is too large" as this number of times larger than needed */
|
335
|
+
#define ZSTD_WORKSPACETOOLARGE_FACTOR 3
|
336
|
+
|
337
|
+
/* when workspace is continuously too large
|
338
|
+
* during at least this number of times,
|
339
|
+
* context's memory usage is considered wasteful,
|
340
|
+
* because it's sized to handle a worst case scenario which rarely happens.
|
341
|
+
* In which case, resize it down to free some memory */
|
342
|
+
#define ZSTD_WORKSPACETOOLARGE_MAXDURATION 128
|
343
|
+
|
344
|
+
/* Controls whether the input/output buffer is buffered or stable. */
|
345
|
+
typedef enum {
|
346
|
+
ZSTD_bm_buffered = 0, /* Buffer the input/output */
|
347
|
+
ZSTD_bm_stable = 1 /* ZSTD_inBuffer/ZSTD_outBuffer is stable */
|
348
|
+
} ZSTD_bufferMode_e;
|
349
|
+
|
350
|
+
|
351
|
+
/*-*******************************************
|
352
|
+
* Private declarations
|
353
|
+
*********************************************/
|
354
|
+
typedef struct seqDef_s {
|
355
|
+
U32 offset; /* offset == rawOffset + ZSTD_REP_NUM, or equivalently, offCode + 1 */
|
356
|
+
U16 litLength;
|
357
|
+
U16 matchLength;
|
358
|
+
} seqDef;
|
359
|
+
|
360
|
+
/* Controls whether seqStore has a single "long" litLength or matchLength. See seqStore_t. */
|
361
|
+
typedef enum {
|
362
|
+
ZSTD_llt_none = 0, /* no longLengthType */
|
363
|
+
ZSTD_llt_literalLength = 1, /* represents a long literal */
|
364
|
+
ZSTD_llt_matchLength = 2 /* represents a long match */
|
365
|
+
} ZSTD_longLengthType_e;
|
366
|
+
|
367
|
+
typedef struct {
|
368
|
+
seqDef* sequencesStart;
|
369
|
+
seqDef* sequences; /* ptr to end of sequences */
|
370
|
+
BYTE* litStart;
|
371
|
+
BYTE* lit; /* ptr to end of literals */
|
372
|
+
BYTE* llCode;
|
373
|
+
BYTE* mlCode;
|
374
|
+
BYTE* ofCode;
|
375
|
+
size_t maxNbSeq;
|
376
|
+
size_t maxNbLit;
|
377
|
+
|
378
|
+
/* longLengthPos and longLengthType to allow us to represent either a single litLength or matchLength
|
379
|
+
* in the seqStore that has a value larger than U16 (if it exists). To do so, we increment
|
380
|
+
* the existing value of the litLength or matchLength by 0x10000.
|
381
|
+
*/
|
382
|
+
ZSTD_longLengthType_e longLengthType;
|
383
|
+
U32 longLengthPos; /* Index of the sequence to apply long length modification to */
|
384
|
+
} seqStore_t;
|
385
|
+
|
386
|
+
typedef struct {
|
387
|
+
U32 litLength;
|
388
|
+
U32 matchLength;
|
389
|
+
} ZSTD_sequenceLength;
|
390
|
+
|
391
|
+
/**
|
392
|
+
* Returns the ZSTD_sequenceLength for the given sequences. It handles the decoding of long sequences
|
393
|
+
* indicated by longLengthPos and longLengthType, and adds MINMATCH back to matchLength.
|
394
|
+
*/
|
395
|
+
MEM_STATIC ZSTD_sequenceLength ZSTD_getSequenceLength(seqStore_t const* seqStore, seqDef const* seq)
|
396
|
+
{
|
397
|
+
ZSTD_sequenceLength seqLen;
|
398
|
+
seqLen.litLength = seq->litLength;
|
399
|
+
seqLen.matchLength = seq->matchLength + MINMATCH;
|
400
|
+
if (seqStore->longLengthPos == (U32)(seq - seqStore->sequencesStart)) {
|
401
|
+
if (seqStore->longLengthType == ZSTD_llt_literalLength) {
|
402
|
+
seqLen.litLength += 0xFFFF;
|
403
|
+
}
|
404
|
+
if (seqStore->longLengthType == ZSTD_llt_matchLength) {
|
405
|
+
seqLen.matchLength += 0xFFFF;
|
406
|
+
}
|
407
|
+
}
|
408
|
+
return seqLen;
|
409
|
+
}
|
410
|
+
|
411
|
+
/**
|
412
|
+
* Contains the compressed frame size and an upper-bound for the decompressed frame size.
|
413
|
+
* Note: before using `compressedSize`, check for errors using ZSTD_isError().
|
414
|
+
* similarly, before using `decompressedBound`, check for errors using:
|
415
|
+
* `decompressedBound != ZSTD_CONTENTSIZE_ERROR`
|
416
|
+
*/
|
417
|
+
typedef struct {
|
418
|
+
size_t compressedSize;
|
419
|
+
unsigned long long decompressedBound;
|
420
|
+
} ZSTD_frameSizeInfo; /* decompress & legacy */
|
421
|
+
|
422
|
+
const seqStore_t* ZSTD_getSeqStore(const ZSTD_CCtx* ctx); /* compress & dictBuilder */
|
423
|
+
void ZSTD_seqToCodes(const seqStore_t* seqStorePtr); /* compress, dictBuilder, decodeCorpus (shouldn't get its definition from here) */
|
424
|
+
|
425
|
+
/* custom memory allocation functions */
|
426
|
+
void* ZSTD_customMalloc(size_t size, ZSTD_customMem customMem);
|
427
|
+
void* ZSTD_customCalloc(size_t size, ZSTD_customMem customMem);
|
428
|
+
void ZSTD_customFree(void* ptr, ZSTD_customMem customMem);
|
429
|
+
|
430
|
+
|
431
|
+
MEM_STATIC U32 ZSTD_highbit32(U32 val) /* compress, dictBuilder, decodeCorpus */
|
432
|
+
{
|
433
|
+
assert(val != 0);
|
434
|
+
{
|
435
|
+
# if defined(_MSC_VER) /* Visual */
|
436
|
+
# if STATIC_BMI2 == 1
|
437
|
+
return _lzcnt_u32(val)^31;
|
438
|
+
# else
|
439
|
+
unsigned long r=0;
|
440
|
+
return _BitScanReverse(&r, val) ? (unsigned)r : 0;
|
441
|
+
# endif
|
442
|
+
# elif defined(__GNUC__) && (__GNUC__ >= 3) /* GCC Intrinsic */
|
443
|
+
return __builtin_clz (val) ^ 31;
|
444
|
+
# elif defined(__ICCARM__) /* IAR Intrinsic */
|
445
|
+
return 31 - __CLZ(val);
|
446
|
+
# else /* Software version */
|
447
|
+
static const U32 DeBruijnClz[32] = { 0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30, 8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31 };
|
448
|
+
U32 v = val;
|
449
|
+
v |= v >> 1;
|
450
|
+
v |= v >> 2;
|
451
|
+
v |= v >> 4;
|
452
|
+
v |= v >> 8;
|
453
|
+
v |= v >> 16;
|
454
|
+
return DeBruijnClz[(v * 0x07C4ACDDU) >> 27];
|
455
|
+
# endif
|
456
|
+
}
|
457
|
+
}
|
458
|
+
|
459
|
+
|
460
|
+
/* ZSTD_invalidateRepCodes() :
|
461
|
+
* ensures next compression will not use repcodes from previous block.
|
462
|
+
* Note : only works with regular variant;
|
463
|
+
* do not use with extDict variant ! */
|
464
|
+
void ZSTD_invalidateRepCodes(ZSTD_CCtx* cctx); /* zstdmt, adaptive_compression (shouldn't get this definition from here) */
|
465
|
+
|
466
|
+
|
467
|
+
typedef struct {
|
468
|
+
blockType_e blockType;
|
469
|
+
U32 lastBlock;
|
470
|
+
U32 origSize;
|
471
|
+
} blockProperties_t; /* declared here for decompress and fullbench */
|
472
|
+
|
473
|
+
/*! ZSTD_getcBlockSize() :
|
474
|
+
* Provides the size of compressed block from block header `src` */
|
475
|
+
/* Used by: decompress, fullbench (does not get its definition from here) */
|
476
|
+
size_t ZSTD_getcBlockSize(const void* src, size_t srcSize,
|
477
|
+
blockProperties_t* bpPtr);
|
478
|
+
|
479
|
+
/*! ZSTD_decodeSeqHeaders() :
|
480
|
+
* decode sequence header from src */
|
481
|
+
/* Used by: decompress, fullbench (does not get its definition from here) */
|
482
|
+
size_t ZSTD_decodeSeqHeaders(ZSTD_DCtx* dctx, int* nbSeqPtr,
|
483
|
+
const void* src, size_t srcSize);
|
484
|
+
|
485
|
+
|
486
|
+
#if defined (__cplusplus)
|
487
|
+
}
|
488
|
+
#endif
|
489
|
+
|
490
|
+
#endif /* ZSTD_CCOMMON_H_MODULE */
|