extzstd 0.3 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/HISTORY.ja.md +8 -0
  3. data/README.md +1 -1
  4. data/contrib/zstd/CHANGELOG +94 -0
  5. data/contrib/zstd/CONTRIBUTING.md +351 -1
  6. data/contrib/zstd/Makefile +32 -10
  7. data/contrib/zstd/README.md +33 -10
  8. data/contrib/zstd/TESTING.md +2 -2
  9. data/contrib/zstd/appveyor.yml +42 -4
  10. data/contrib/zstd/lib/Makefile +128 -60
  11. data/contrib/zstd/lib/README.md +47 -16
  12. data/contrib/zstd/lib/common/bitstream.h +38 -39
  13. data/contrib/zstd/lib/common/compiler.h +40 -5
  14. data/contrib/zstd/lib/common/cpu.h +1 -1
  15. data/contrib/zstd/lib/common/debug.c +11 -31
  16. data/contrib/zstd/lib/common/debug.h +11 -31
  17. data/contrib/zstd/lib/common/entropy_common.c +13 -33
  18. data/contrib/zstd/lib/common/error_private.c +2 -1
  19. data/contrib/zstd/lib/common/error_private.h +6 -2
  20. data/contrib/zstd/lib/common/fse.h +12 -32
  21. data/contrib/zstd/lib/common/fse_decompress.c +12 -35
  22. data/contrib/zstd/lib/common/huf.h +15 -33
  23. data/contrib/zstd/lib/common/mem.h +75 -2
  24. data/contrib/zstd/lib/common/pool.c +8 -4
  25. data/contrib/zstd/lib/common/pool.h +2 -2
  26. data/contrib/zstd/lib/common/threading.c +50 -4
  27. data/contrib/zstd/lib/common/threading.h +36 -4
  28. data/contrib/zstd/lib/common/xxhash.c +23 -35
  29. data/contrib/zstd/lib/common/xxhash.h +11 -31
  30. data/contrib/zstd/lib/common/zstd_common.c +1 -1
  31. data/contrib/zstd/lib/common/zstd_errors.h +2 -1
  32. data/contrib/zstd/lib/common/zstd_internal.h +154 -26
  33. data/contrib/zstd/lib/compress/fse_compress.c +17 -40
  34. data/contrib/zstd/lib/compress/hist.c +15 -35
  35. data/contrib/zstd/lib/compress/hist.h +12 -32
  36. data/contrib/zstd/lib/compress/huf_compress.c +92 -92
  37. data/contrib/zstd/lib/compress/zstd_compress.c +1191 -1330
  38. data/contrib/zstd/lib/compress/zstd_compress_internal.h +317 -55
  39. data/contrib/zstd/lib/compress/zstd_compress_literals.c +158 -0
  40. data/contrib/zstd/lib/compress/zstd_compress_literals.h +29 -0
  41. data/contrib/zstd/lib/compress/zstd_compress_sequences.c +419 -0
  42. data/contrib/zstd/lib/compress/zstd_compress_sequences.h +54 -0
  43. data/contrib/zstd/lib/compress/zstd_compress_superblock.c +845 -0
  44. data/contrib/zstd/lib/compress/zstd_compress_superblock.h +32 -0
  45. data/contrib/zstd/lib/compress/zstd_cwksp.h +525 -0
  46. data/contrib/zstd/lib/compress/zstd_double_fast.c +65 -43
  47. data/contrib/zstd/lib/compress/zstd_double_fast.h +2 -2
  48. data/contrib/zstd/lib/compress/zstd_fast.c +92 -66
  49. data/contrib/zstd/lib/compress/zstd_fast.h +2 -2
  50. data/contrib/zstd/lib/compress/zstd_lazy.c +74 -42
  51. data/contrib/zstd/lib/compress/zstd_lazy.h +1 -1
  52. data/contrib/zstd/lib/compress/zstd_ldm.c +32 -10
  53. data/contrib/zstd/lib/compress/zstd_ldm.h +7 -2
  54. data/contrib/zstd/lib/compress/zstd_opt.c +81 -114
  55. data/contrib/zstd/lib/compress/zstd_opt.h +1 -1
  56. data/contrib/zstd/lib/compress/zstdmt_compress.c +95 -51
  57. data/contrib/zstd/lib/compress/zstdmt_compress.h +3 -2
  58. data/contrib/zstd/lib/decompress/huf_decompress.c +76 -60
  59. data/contrib/zstd/lib/decompress/zstd_ddict.c +12 -8
  60. data/contrib/zstd/lib/decompress/zstd_ddict.h +2 -2
  61. data/contrib/zstd/lib/decompress/zstd_decompress.c +292 -172
  62. data/contrib/zstd/lib/decompress/zstd_decompress_block.c +459 -338
  63. data/contrib/zstd/lib/decompress/zstd_decompress_block.h +3 -3
  64. data/contrib/zstd/lib/decompress/zstd_decompress_internal.h +18 -4
  65. data/contrib/zstd/lib/deprecated/zbuff.h +9 -8
  66. data/contrib/zstd/lib/deprecated/zbuff_common.c +2 -2
  67. data/contrib/zstd/lib/deprecated/zbuff_compress.c +1 -1
  68. data/contrib/zstd/lib/deprecated/zbuff_decompress.c +1 -1
  69. data/contrib/zstd/lib/dictBuilder/cover.c +164 -54
  70. data/contrib/zstd/lib/dictBuilder/cover.h +52 -7
  71. data/contrib/zstd/lib/dictBuilder/fastcover.c +60 -43
  72. data/contrib/zstd/lib/dictBuilder/zdict.c +43 -19
  73. data/contrib/zstd/lib/dictBuilder/zdict.h +56 -28
  74. data/contrib/zstd/lib/legacy/zstd_legacy.h +8 -4
  75. data/contrib/zstd/lib/legacy/zstd_v01.c +110 -110
  76. data/contrib/zstd/lib/legacy/zstd_v01.h +1 -1
  77. data/contrib/zstd/lib/legacy/zstd_v02.c +23 -13
  78. data/contrib/zstd/lib/legacy/zstd_v02.h +1 -1
  79. data/contrib/zstd/lib/legacy/zstd_v03.c +23 -13
  80. data/contrib/zstd/lib/legacy/zstd_v03.h +1 -1
  81. data/contrib/zstd/lib/legacy/zstd_v04.c +30 -17
  82. data/contrib/zstd/lib/legacy/zstd_v04.h +1 -1
  83. data/contrib/zstd/lib/legacy/zstd_v05.c +113 -102
  84. data/contrib/zstd/lib/legacy/zstd_v05.h +2 -2
  85. data/contrib/zstd/lib/legacy/zstd_v06.c +20 -18
  86. data/contrib/zstd/lib/legacy/zstd_v06.h +1 -1
  87. data/contrib/zstd/lib/legacy/zstd_v07.c +25 -19
  88. data/contrib/zstd/lib/legacy/zstd_v07.h +1 -1
  89. data/contrib/zstd/lib/libzstd.pc.in +3 -2
  90. data/contrib/zstd/lib/zstd.h +265 -88
  91. data/ext/extzstd.h +1 -1
  92. data/ext/libzstd_conf.h +8 -0
  93. data/ext/zstd_common.c +1 -3
  94. data/ext/zstd_compress.c +3 -3
  95. data/ext/zstd_decompress.c +1 -5
  96. data/ext/zstd_dictbuilder.c +2 -3
  97. data/ext/zstd_dictbuilder_fastcover.c +1 -3
  98. data/ext/zstd_legacy_v01.c +2 -0
  99. data/ext/zstd_legacy_v02.c +2 -0
  100. data/ext/zstd_legacy_v03.c +2 -0
  101. data/ext/zstd_legacy_v04.c +2 -0
  102. data/ext/zstd_legacy_v05.c +2 -0
  103. data/ext/zstd_legacy_v06.c +2 -0
  104. data/ext/zstd_legacy_v07.c +2 -0
  105. data/lib/extzstd.rb +18 -10
  106. data/lib/extzstd/version.rb +1 -1
  107. metadata +15 -6
@@ -2,17 +2,20 @@
2
2
  * Copyright (c) 2016 Tino Reichardt
3
3
  * All rights reserved.
4
4
  *
5
+ * You can contact the author at:
6
+ * - zstdmt source repository: https://github.com/mcmilk/zstdmt
7
+ *
5
8
  * This source code is licensed under both the BSD-style license (found in the
6
9
  * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7
10
  * in the COPYING file in the root directory of this source tree).
8
- *
9
- * You can contact the author at:
10
- * - zstdmt source repository: https://github.com/mcmilk/zstdmt
11
+ * You may select, at your option, one of the above-listed licenses.
11
12
  */
12
13
 
13
14
  #ifndef THREADING_H_938743
14
15
  #define THREADING_H_938743
15
16
 
17
+ #include "debug.h"
18
+
16
19
  #if defined (__cplusplus)
17
20
  extern "C" {
18
21
  #endif
@@ -75,10 +78,12 @@ int ZSTD_pthread_join(ZSTD_pthread_t thread, void** value_ptr);
75
78
  */
76
79
 
77
80
 
78
- #elif defined(ZSTD_MULTITHREAD) /* posix assumed ; need a better detection method */
81
+ #elif defined(ZSTD_MULTITHREAD) /* posix assumed ; need a better detection method */
79
82
  /* === POSIX Systems === */
80
83
  # include <pthread.h>
81
84
 
85
+ #if DEBUGLEVEL < 1
86
+
82
87
  #define ZSTD_pthread_mutex_t pthread_mutex_t
83
88
  #define ZSTD_pthread_mutex_init(a, b) pthread_mutex_init((a), (b))
84
89
  #define ZSTD_pthread_mutex_destroy(a) pthread_mutex_destroy((a))
@@ -96,6 +101,33 @@ int ZSTD_pthread_join(ZSTD_pthread_t thread, void** value_ptr);
96
101
  #define ZSTD_pthread_create(a, b, c, d) pthread_create((a), (b), (c), (d))
97
102
  #define ZSTD_pthread_join(a, b) pthread_join((a),(b))
98
103
 
104
+ #else /* DEBUGLEVEL >= 1 */
105
+
106
+ /* Debug implementation of threading.
107
+ * In this implementation we use pointers for mutexes and condition variables.
108
+ * This way, if we forget to init/destroy them the program will crash or ASAN
109
+ * will report leaks.
110
+ */
111
+
112
+ #define ZSTD_pthread_mutex_t pthread_mutex_t*
113
+ int ZSTD_pthread_mutex_init(ZSTD_pthread_mutex_t* mutex, pthread_mutexattr_t const* attr);
114
+ int ZSTD_pthread_mutex_destroy(ZSTD_pthread_mutex_t* mutex);
115
+ #define ZSTD_pthread_mutex_lock(a) pthread_mutex_lock(*(a))
116
+ #define ZSTD_pthread_mutex_unlock(a) pthread_mutex_unlock(*(a))
117
+
118
+ #define ZSTD_pthread_cond_t pthread_cond_t*
119
+ int ZSTD_pthread_cond_init(ZSTD_pthread_cond_t* cond, pthread_condattr_t const* attr);
120
+ int ZSTD_pthread_cond_destroy(ZSTD_pthread_cond_t* cond);
121
+ #define ZSTD_pthread_cond_wait(a, b) pthread_cond_wait(*(a), *(b))
122
+ #define ZSTD_pthread_cond_signal(a) pthread_cond_signal(*(a))
123
+ #define ZSTD_pthread_cond_broadcast(a) pthread_cond_broadcast(*(a))
124
+
125
+ #define ZSTD_pthread_t pthread_t
126
+ #define ZSTD_pthread_create(a, b, c, d) pthread_create((a), (b), (c), (d))
127
+ #define ZSTD_pthread_join(a, b) pthread_join((a),(b))
128
+
129
+ #endif
130
+
99
131
  #else /* ZSTD_MULTITHREAD not defined */
100
132
  /* No multithreading support */
101
133
 
@@ -1,35 +1,15 @@
1
1
  /*
2
- * xxHash - Fast Hash algorithm
3
- * Copyright (C) 2012-2016, Yann Collet
4
- *
5
- * BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
6
- *
7
- * Redistribution and use in source and binary forms, with or without
8
- * modification, are permitted provided that the following conditions are
9
- * met:
10
- *
11
- * * Redistributions of source code must retain the above copyright
12
- * notice, this list of conditions and the following disclaimer.
13
- * * Redistributions in binary form must reproduce the above
14
- * copyright notice, this list of conditions and the following disclaimer
15
- * in the documentation and/or other materials provided with the
16
- * distribution.
17
- *
18
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
- *
30
- * You can contact the author at :
31
- * - xxHash homepage: http://www.xxhash.com
32
- * - xxHash source repository : https://github.com/Cyan4973/xxHash
2
+ * xxHash - Fast Hash algorithm
3
+ * Copyright (c) 2012-2020, Yann Collet, Facebook, Inc.
4
+ *
5
+ * You can contact the author at :
6
+ * - xxHash homepage: http://www.xxhash.com
7
+ * - xxHash source repository : https://github.com/Cyan4973/xxHash
8
+ *
9
+ * This source code is licensed under both the BSD-style license (found in the
10
+ * LICENSE file in the root directory of this source tree) and the GPLv2 (found
11
+ * in the COPYING file in the root directory of this source tree).
12
+ * You may select, at your option, one of the above-listed licenses.
33
13
  */
34
14
 
35
15
 
@@ -53,7 +33,8 @@
53
33
  # if defined(__GNUC__) && ( defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) )
54
34
  # define XXH_FORCE_MEMORY_ACCESS 2
55
35
  # elif (defined(__INTEL_COMPILER) && !defined(WIN32)) || \
56
- (defined(__GNUC__) && ( defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) ))
36
+ (defined(__GNUC__) && ( defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) )) || \
37
+ defined(__ICCARM__)
57
38
  # define XXH_FORCE_MEMORY_ACCESS 1
58
39
  # endif
59
40
  #endif
@@ -114,13 +95,13 @@ static void* XXH_memcpy(void* dest, const void* src, size_t size) { return memcp
114
95
  /* *************************************
115
96
  * Compiler Specific Options
116
97
  ***************************************/
117
- #if defined (__GNUC__) || defined(__cplusplus) || defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */
98
+ #if (defined(__GNUC__) && !defined(__STRICT_ANSI__)) || defined(__cplusplus) || defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */
118
99
  # define INLINE_KEYWORD inline
119
100
  #else
120
101
  # define INLINE_KEYWORD
121
102
  #endif
122
103
 
123
- #if defined(__GNUC__)
104
+ #if defined(__GNUC__) || defined(__ICCARM__)
124
105
  # define FORCE_INLINE_ATTR __attribute__((always_inline))
125
106
  #elif defined(_MSC_VER)
126
107
  # define FORCE_INLINE_ATTR __forceinline
@@ -206,7 +187,12 @@ static U64 XXH_read64(const void* memPtr)
206
187
  # define XXH_rotl32(x,r) _rotl(x,r)
207
188
  # define XXH_rotl64(x,r) _rotl64(x,r)
208
189
  #else
190
+ #if defined(__ICCARM__)
191
+ # include <intrinsics.h>
192
+ # define XXH_rotl32(x,r) __ROR(x,(32 - r))
193
+ #else
209
194
  # define XXH_rotl32(x,r) ((x << r) | (x >> (32 - r)))
195
+ #endif
210
196
  # define XXH_rotl64(x,r) ((x << r) | (x >> (64 - r)))
211
197
  #endif
212
198
 
@@ -723,7 +709,9 @@ FORCE_INLINE_TEMPLATE XXH_errorcode XXH64_update_endian (XXH64_state_t* state, c
723
709
  state->total_len += len;
724
710
 
725
711
  if (state->memsize + len < 32) { /* fill in tmp buffer */
726
- XXH_memcpy(((BYTE*)state->mem64) + state->memsize, input, len);
712
+ if (input != NULL) {
713
+ XXH_memcpy(((BYTE*)state->mem64) + state->memsize, input, len);
714
+ }
727
715
  state->memsize += (U32)len;
728
716
  return XXH_OK;
729
717
  }
@@ -1,35 +1,15 @@
1
1
  /*
2
- xxHash - Extremely Fast Hash algorithm
3
- Header File
4
- Copyright (C) 2012-2016, Yann Collet.
5
-
6
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
7
-
8
- Redistribution and use in source and binary forms, with or without
9
- modification, are permitted provided that the following conditions are
10
- met:
11
-
12
- * Redistributions of source code must retain the above copyright
13
- notice, this list of conditions and the following disclaimer.
14
- * Redistributions in binary form must reproduce the above
15
- copyright notice, this list of conditions and the following disclaimer
16
- in the documentation and/or other materials provided with the
17
- distribution.
18
-
19
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
-
31
- You can contact the author at :
32
- - xxHash source repository : https://github.com/Cyan4973/xxHash
2
+ * xxHash - Extremely Fast Hash algorithm
3
+ * Header File
4
+ * Copyright (c) 2012-2020, Yann Collet, Facebook, Inc.
5
+ *
6
+ * You can contact the author at :
7
+ * - xxHash source repository : https://github.com/Cyan4973/xxHash
8
+ *
9
+ * This source code is licensed under both the BSD-style license (found in the
10
+ * LICENSE file in the root directory of this source tree) and the GPLv2 (found
11
+ * in the COPYING file in the root directory of this source tree).
12
+ * You may select, at your option, one of the above-listed licenses.
33
13
  */
34
14
 
35
15
  /* Notice extracted from xxHash homepage :
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
2
+ * Copyright (c) 2016-2020, 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
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
2
+ * Copyright (c) 2016-2020, 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
@@ -76,6 +76,7 @@ typedef enum {
76
76
  /* following error codes are __NOT STABLE__, they can be removed or changed in future versions */
77
77
  ZSTD_error_frameIndex_tooLarge = 100,
78
78
  ZSTD_error_seekableIO = 102,
79
+ ZSTD_error_dstBuffer_wrong = 104,
79
80
  ZSTD_error_maxCode = 120 /* never EVER use this value directly, it can change in future versions! Use ZSTD_isError() instead */
80
81
  } ZSTD_ErrorCode;
81
82
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
2
+ * Copyright (c) 2016-2020, 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,12 +19,15 @@
19
19
  /*-*************************************
20
20
  * Dependencies
21
21
  ***************************************/
22
+ #ifdef __aarch64__
23
+ #include <arm_neon.h>
24
+ #endif
22
25
  #include "compiler.h"
23
26
  #include "mem.h"
24
27
  #include "debug.h" /* assert, DEBUGLOG, RAWLOG, g_debuglevel */
25
28
  #include "error_private.h"
26
29
  #define ZSTD_STATIC_LINKING_ONLY
27
- #include "zstd.h"
30
+ #include "../zstd.h"
28
31
  #define FSE_STATIC_LINKING_ONLY
29
32
  #include "fse.h"
30
33
  #define HUF_STATIC_LINKING_ONLY
@@ -34,7 +37,6 @@
34
37
  #endif
35
38
  #include "xxhash.h" /* XXH_reset, update, digest */
36
39
 
37
-
38
40
  #if defined (__cplusplus)
39
41
  extern "C" {
40
42
  #endif
@@ -54,16 +56,43 @@ extern "C" {
54
56
  #define MIN(a,b) ((a)<(b) ? (a) : (b))
55
57
  #define MAX(a,b) ((a)>(b) ? (a) : (b))
56
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
+
57
84
  /**
58
85
  * Return the specified error if the condition evaluates to true.
59
86
  *
60
- * In debug modes, prints additional information. In order to do that
61
- * (particularly, printing the conditional that failed), this can't just wrap
62
- * RETURN_ERROR().
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().
63
90
  */
64
91
  #define RETURN_ERROR_IF(cond, err, ...) \
65
92
  if (cond) { \
66
- RAWLOG(3, "%s:%d: ERROR!: check %s failed, returning %s", __FILE__, __LINE__, ZSTD_QUOTE(cond), ZSTD_QUOTE(ERROR(err))); \
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__); \
67
96
  RAWLOG(3, ": " __VA_ARGS__); \
68
97
  RAWLOG(3, "\n"); \
69
98
  return ERROR(err); \
@@ -76,7 +105,9 @@ extern "C" {
76
105
  */
77
106
  #define RETURN_ERROR(err, ...) \
78
107
  do { \
79
- RAWLOG(3, "%s:%d: ERROR!: unconditional check failed, returning %s", __FILE__, __LINE__, ZSTD_QUOTE(ERROR(err))); \
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__); \
80
111
  RAWLOG(3, ": " __VA_ARGS__); \
81
112
  RAWLOG(3, "\n"); \
82
113
  return ERROR(err); \
@@ -91,7 +122,9 @@ extern "C" {
91
122
  do { \
92
123
  size_t const err_code = (err); \
93
124
  if (ERR_isError(err_code)) { \
94
- RAWLOG(3, "%s:%d: ERROR!: forwarding error in %s: %s", __FILE__, __LINE__, ZSTD_QUOTE(err), ERR_getErrorName(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__); \
95
128
  RAWLOG(3, ": " __VA_ARGS__); \
96
129
  RAWLOG(3, "\n"); \
97
130
  return err_code; \
@@ -129,6 +162,8 @@ static const size_t ZSTD_did_fieldSize[4] = { 0, 1, 2, 4 };
129
162
  static const size_t ZSTD_blockHeaderSize = ZSTD_BLOCKHEADERSIZE;
130
163
  typedef enum { bt_raw, bt_rle, bt_compressed, bt_reserved } blockType_e;
131
164
 
165
+ #define ZSTD_FRAMECHECKSUMSIZE 4
166
+
132
167
  #define MIN_SEQUENCES_SIZE 1 /* nbSeq==0 */
133
168
  #define MIN_CBLOCK_SIZE (1 /*litCSize*/ + 1 /* RLE or RAW */ + MIN_SEQUENCES_SIZE /* nbSeq==0 */) /* for a non-null block */
134
169
 
@@ -192,32 +227,99 @@ static const U32 OF_defaultNormLog = OF_DEFAULTNORMLOG;
192
227
  /*-*******************************************
193
228
  * Shared functions to include for inlining
194
229
  *********************************************/
195
- static void ZSTD_copy8(void* dst, const void* src) { memcpy(dst, src, 8); }
230
+ static void ZSTD_copy8(void* dst, const void* src) {
231
+ #ifdef __aarch64__
232
+ vst1_u8((uint8_t*)dst, vld1_u8((const uint8_t*)src));
233
+ #else
234
+ memcpy(dst, src, 8);
235
+ #endif
236
+ }
237
+
196
238
  #define COPY8(d,s) { ZSTD_copy8(d,s); d+=8; s+=8; }
239
+ static void ZSTD_copy16(void* dst, const void* src) {
240
+ #ifdef __aarch64__
241
+ vst1q_u8((uint8_t*)dst, vld1q_u8((const uint8_t*)src));
242
+ #else
243
+ memcpy(dst, src, 16);
244
+ #endif
245
+ }
246
+ #define COPY16(d,s) { ZSTD_copy16(d,s); d+=16; s+=16; }
247
+
248
+ #define WILDCOPY_OVERLENGTH 32
249
+ #define WILDCOPY_VECLEN 16
250
+
251
+ typedef enum {
252
+ ZSTD_no_overlap,
253
+ ZSTD_overlap_src_before_dst
254
+ /* ZSTD_overlap_dst_before_src, */
255
+ } ZSTD_overlap_e;
197
256
 
198
257
  /*! ZSTD_wildcopy() :
199
- * custom version of memcpy(), can overwrite up to WILDCOPY_OVERLENGTH bytes (if length==0) */
200
- #define WILDCOPY_OVERLENGTH 8
201
- MEM_STATIC void ZSTD_wildcopy(void* dst, const void* src, ptrdiff_t length)
258
+ * Custom version of memcpy(), can over read/write up to WILDCOPY_OVERLENGTH bytes (if length==0)
259
+ * @param ovtype controls the overlap detection
260
+ * - ZSTD_no_overlap: The source and destination are guaranteed to be at least WILDCOPY_VECLEN bytes apart.
261
+ * - ZSTD_overlap_src_before_dst: The src and dst may overlap, but they MUST be at least 8 bytes apart.
262
+ * The src buffer must be before the dst buffer.
263
+ */
264
+ MEM_STATIC FORCE_INLINE_ATTR
265
+ void ZSTD_wildcopy(void* dst, const void* src, ptrdiff_t length, ZSTD_overlap_e const ovtype)
202
266
  {
267
+ ptrdiff_t diff = (BYTE*)dst - (const BYTE*)src;
203
268
  const BYTE* ip = (const BYTE*)src;
204
269
  BYTE* op = (BYTE*)dst;
205
270
  BYTE* const oend = op + length;
206
- do
207
- COPY8(op, ip)
208
- while (op < oend);
271
+
272
+ assert(diff >= 8 || (ovtype == ZSTD_no_overlap && diff <= -WILDCOPY_VECLEN));
273
+
274
+ if (ovtype == ZSTD_overlap_src_before_dst && diff < WILDCOPY_VECLEN) {
275
+ /* Handle short offset copies. */
276
+ do {
277
+ COPY8(op, ip)
278
+ } while (op < oend);
279
+ } else {
280
+ assert(diff >= WILDCOPY_VECLEN || diff <= -WILDCOPY_VECLEN);
281
+ /* Separate out the first COPY16() call because the copy length is
282
+ * almost certain to be short, so the branches have different
283
+ * probabilities. Since it is almost certain to be short, only do
284
+ * one COPY16() in the first call. Then, do two calls per loop since
285
+ * at that point it is more likely to have a high trip count.
286
+ */
287
+ #ifndef __aarch64__
288
+ do {
289
+ COPY16(op, ip);
290
+ }
291
+ while (op < oend);
292
+ #else
293
+ COPY16(op, ip);
294
+ if (op >= oend) return;
295
+ do {
296
+ COPY16(op, ip);
297
+ COPY16(op, ip);
298
+ }
299
+ while (op < oend);
300
+ #endif
301
+ }
209
302
  }
210
303
 
211
- MEM_STATIC void ZSTD_wildcopy_e(void* dst, const void* src, void* dstEnd) /* should be faster for decoding, but strangely, not verified on all platform */
304
+ MEM_STATIC size_t ZSTD_limitCopy(void* dst, size_t dstCapacity, const void* src, size_t srcSize)
212
305
  {
213
- const BYTE* ip = (const BYTE*)src;
214
- BYTE* op = (BYTE*)dst;
215
- BYTE* const oend = (BYTE*)dstEnd;
216
- do
217
- COPY8(op, ip)
218
- while (op < oend);
306
+ size_t const length = MIN(dstCapacity, srcSize);
307
+ if (length > 0) {
308
+ memcpy(dst, src, length);
309
+ }
310
+ return length;
219
311
  }
220
312
 
313
+ /* define "workspace is too large" as this number of times larger than needed */
314
+ #define ZSTD_WORKSPACETOOLARGE_FACTOR 3
315
+
316
+ /* when workspace is continuously too large
317
+ * during at least this number of times,
318
+ * context's memory usage is considered wasteful,
319
+ * because it's sized to handle a worst case scenario which rarely happens.
320
+ * In which case, resize it down to free some memory */
321
+ #define ZSTD_WORKSPACETOOLARGE_MAXDURATION 128
322
+
221
323
 
222
324
  /*-*******************************************
223
325
  * Private declarations
@@ -242,6 +344,31 @@ typedef struct {
242
344
  U32 longLengthPos;
243
345
  } seqStore_t;
244
346
 
347
+ typedef struct {
348
+ U32 litLength;
349
+ U32 matchLength;
350
+ } ZSTD_sequenceLength;
351
+
352
+ /**
353
+ * Returns the ZSTD_sequenceLength for the given sequences. It handles the decoding of long sequences
354
+ * indicated by longLengthPos and longLengthID, and adds MINMATCH back to matchLength.
355
+ */
356
+ MEM_STATIC ZSTD_sequenceLength ZSTD_getSequenceLength(seqStore_t const* seqStore, seqDef const* seq)
357
+ {
358
+ ZSTD_sequenceLength seqLen;
359
+ seqLen.litLength = seq->litLength;
360
+ seqLen.matchLength = seq->matchLength + MINMATCH;
361
+ if (seqStore->longLengthPos == (U32)(seq - seqStore->sequencesStart)) {
362
+ if (seqStore->longLengthID == 1) {
363
+ seqLen.litLength += 0xFFFF;
364
+ }
365
+ if (seqStore->longLengthID == 2) {
366
+ seqLen.matchLength += 0xFFFF;
367
+ }
368
+ }
369
+ return seqLen;
370
+ }
371
+
245
372
  /**
246
373
  * Contains the compressed frame size and an upper-bound for the decompressed frame size.
247
374
  * Note: before using `compressedSize`, check for errors using ZSTD_isError().
@@ -268,10 +395,11 @@ MEM_STATIC U32 ZSTD_highbit32(U32 val) /* compress, dictBuilder, decodeCorpus
268
395
  {
269
396
  # if defined(_MSC_VER) /* Visual */
270
397
  unsigned long r=0;
271
- _BitScanReverse(&r, val);
272
- return (unsigned)r;
398
+ return _BitScanReverse(&r, val) ? (unsigned)r : 0;
273
399
  # elif defined(__GNUC__) && (__GNUC__ >= 3) /* GCC Intrinsic */
274
- return 31 - __builtin_clz(val);
400
+ return __builtin_clz (val) ^ 31;
401
+ # elif defined(__ICCARM__) /* IAR Intrinsic */
402
+ return 31 - __CLZ(val);
275
403
  # else /* Software version */
276
404
  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 };
277
405
  U32 v = val;