zstdlib 0.4.0-x64-mingw32 → 0.5.0-x64-mingw32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +6 -1
  3. data/README.md +1 -1
  4. data/ext/zstdlib/extconf.rb +2 -2
  5. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/common/bitstream.h +3 -2
  6. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/common/compiler.h +14 -2
  7. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/common/cpu.h +0 -0
  8. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/common/debug.c +0 -0
  9. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/common/debug.h +0 -0
  10. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/common/entropy_common.c +0 -0
  11. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/common/error_private.c +0 -0
  12. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/common/error_private.h +0 -0
  13. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/common/fse.h +1 -1
  14. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/common/fse_decompress.c +2 -0
  15. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/common/huf.h +0 -0
  16. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/common/mem.h +73 -0
  17. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/common/pool.c +7 -3
  18. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/common/pool.h +0 -0
  19. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/common/threading.c +46 -1
  20. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/common/threading.h +32 -1
  21. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/common/xxhash.c +0 -0
  22. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/common/xxhash.h +0 -0
  23. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/common/zstd_common.c +0 -0
  24. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/common/zstd_errors.h +0 -0
  25. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/common/zstd_internal.h +32 -55
  26. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/compress/fse_compress.c +0 -0
  27. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/compress/hist.c +0 -0
  28. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/compress/hist.h +0 -0
  29. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/compress/huf_compress.c +0 -0
  30. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/compress/zstd_compress.c +633 -436
  31. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/compress/zstd_compress_internal.h +54 -12
  32. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/compress/zstd_compress_literals.c +10 -5
  33. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/compress/zstd_compress_literals.h +1 -1
  34. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/compress/zstd_compress_sequences.c +3 -3
  35. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/compress/zstd_compress_sequences.h +1 -1
  36. data/ext/zstdlib/zstd-1.4.4/lib/compress/zstd_cwksp.h +535 -0
  37. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/compress/zstd_double_fast.c +9 -9
  38. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/compress/zstd_double_fast.h +0 -0
  39. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/compress/zstd_fast.c +30 -39
  40. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/compress/zstd_fast.h +0 -0
  41. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/compress/zstd_lazy.c +5 -5
  42. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/compress/zstd_lazy.h +0 -0
  43. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/compress/zstd_ldm.c +4 -4
  44. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/compress/zstd_ldm.h +0 -0
  45. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/compress/zstd_opt.c +1 -1
  46. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/compress/zstd_opt.h +0 -0
  47. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/compress/zstdmt_compress.c +32 -26
  48. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/compress/zstdmt_compress.h +0 -0
  49. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/decompress/huf_decompress.c +2 -0
  50. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/decompress/zstd_ddict.c +0 -0
  51. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/decompress/zstd_ddict.h +0 -0
  52. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/decompress/zstd_decompress.c +14 -16
  53. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/decompress/zstd_decompress_block.c +144 -146
  54. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/decompress/zstd_decompress_block.h +0 -0
  55. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/decompress/zstd_decompress_internal.h +0 -0
  56. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/lib/zstd.h +161 -59
  57. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/zlibWrapper/gzclose.c +1 -1
  58. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/zlibWrapper/gzcompatibility.h +0 -0
  59. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/zlibWrapper/gzguts.h +0 -0
  60. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/zlibWrapper/gzlib.c +9 -9
  61. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/zlibWrapper/gzread.c +16 -8
  62. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/zlibWrapper/gzwrite.c +8 -8
  63. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/zlibWrapper/zstd_zlibwrapper.c +15 -11
  64. data/ext/zstdlib/{zstd-1.4.3 → zstd-1.4.4}/zlibWrapper/zstd_zlibwrapper.h +0 -0
  65. data/lib/2.2/zstdlib.so +0 -0
  66. data/lib/2.3/zstdlib.so +0 -0
  67. data/lib/2.4/zstdlib.so +0 -0
  68. data/lib/2.5/zstdlib.so +0 -0
  69. data/lib/2.6/zstdlib.so +0 -0
  70. metadata +62 -61
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7961596fedcd960dbafb1f54c2979cb65506619273a6e9a93d2e96165d2f40fb
4
- data.tar.gz: 5ebf420761484d6c0dfd87be293e1cce9613e57212abbd17e1806a9a4bfe49a6
3
+ metadata.gz: 96ca25a2f2935534780679e291e8fcd7dbef97a47c0631dcf51414c6e6413336
4
+ data.tar.gz: 937a6f5c4ec14c146dd3284f25db08b43915e7d776f4bde070eee5d19a8aede8
5
5
  SHA512:
6
- metadata.gz: 0bf6c0688c63e2521ae8d083744b7a91c19bdee700b38a4aa01b4463b99e120dd54fd034ae2cbe6226516c4cd32e29dc79aab811fe6b9f3f540f5296c995f77d
7
- data.tar.gz: 4b09a7b3a8bc574e067cf087ed20e62bae82328638c69e52c92b819fc8f210bd92c7a90a85befd70f250c187e45b49849677525239b562af818c67e0cbfffe85
6
+ metadata.gz: 495c5a0225f8ad8c3a21a497fb9460021803318792a401a6d38f8c8138c2cda8dcdfb7306992a24be9bad9ea9587f9125a76a0f993bbc56118337b5e84500a5a
7
+ data.tar.gz: ae7b3c2ff162eb9419e8360bf40968d1d519d0d062cdc6bc2a6a4852274e035e240abae6e37a44934185b1251e7d2ec68073a8d081db6cd1f786e90ba16db715
data/CHANGES.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 0.5.0
2
+
3
+ Zstd version update to `1.4.4`
4
+
5
+
1
6
  # 0.4.0
2
7
 
3
8
  Zstd version update to `1.4.3`
@@ -43,4 +48,4 @@ Zstd version: `1.3.8`
43
48
 
44
49
  Zlib version: `1.2.11`
45
50
 
46
- Supported MRI Ruby versions: `2.2-2.6`
51
+ Supported MRI Ruby versions: `2.2-2.6`
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # [Zstdlib](https://bitbucket.org/fougas/zstdlib) - a Zstandard data compression library binding for Ruby
1
+ # [Zstdlib](https://github.com/okhlybov/zstdlib) - a Zstandard data compression library binding for Ruby
2
2
 
3
3
  _zstdlib_ is native Ruby extension for [Zstandard](https://facebook.github.io/zstd/) data compression library.
4
4
 
@@ -6,7 +6,7 @@ require 'fileutils'
6
6
  include RbConfig
7
7
  include FileUtils
8
8
 
9
- ZSTD_VERSION = '1.4.3'
9
+ ZSTD_VERSION = '1.4.4'
10
10
  ZLIB_VERSION = '1.2.11'
11
11
  RB_VERSION = CONFIG['MAJOR']+'.'+CONFIG['MINOR']
12
12
  ZMOD_VERSION = RB_VERSION >= '2.3' ? '2.6' : RB_VERSION # Review requirements with every new zlib module release!
@@ -46,4 +46,4 @@ libzlibwrapper.a :
46
46
  \texport SRCDIR=#{zlibwrapper} && mkdir -p zlibwrapper && $(MAKE) -C zlibwrapper -f #{File.expand_path root}/zlibwrapper.mk
47
47
 
48
48
  ~
49
- end
49
+ end
@@ -164,7 +164,7 @@ MEM_STATIC unsigned BIT_highbit32 (U32 val)
164
164
  _BitScanReverse ( &r, val );
165
165
  return (unsigned) r;
166
166
  # elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */
167
- return 31 - __builtin_clz (val);
167
+ return __builtin_clz (val) ^ 31;
168
168
  # elif defined(__ICCARM__) /* IAR Intrinsic */
169
169
  return 31 - __CLZ(val);
170
170
  # else /* Software version */
@@ -244,9 +244,9 @@ MEM_STATIC void BIT_flushBitsFast(BIT_CStream_t* bitC)
244
244
  {
245
245
  size_t const nbBytes = bitC->bitPos >> 3;
246
246
  assert(bitC->bitPos < sizeof(bitC->bitContainer) * 8);
247
+ assert(bitC->ptr <= bitC->endPtr);
247
248
  MEM_writeLEST(bitC->ptr, bitC->bitContainer);
248
249
  bitC->ptr += nbBytes;
249
- assert(bitC->ptr <= bitC->endPtr);
250
250
  bitC->bitPos &= 7;
251
251
  bitC->bitContainer >>= nbBytes*8;
252
252
  }
@@ -260,6 +260,7 @@ MEM_STATIC void BIT_flushBits(BIT_CStream_t* bitC)
260
260
  {
261
261
  size_t const nbBytes = bitC->bitPos >> 3;
262
262
  assert(bitC->bitPos < sizeof(bitC->bitContainer) * 8);
263
+ assert(bitC->ptr <= bitC->endPtr);
263
264
  MEM_writeLEST(bitC->ptr, bitC->bitContainer);
264
265
  bitC->ptr += nbBytes;
265
266
  if (bitC->ptr > bitC->endPtr) bitC->ptr = bitC->endPtr;
@@ -61,6 +61,13 @@
61
61
  # define HINT_INLINE static INLINE_KEYWORD FORCE_INLINE_ATTR
62
62
  #endif
63
63
 
64
+ /* UNUSED_ATTR tells the compiler it is okay if the function is unused. */
65
+ #if defined(__GNUC__)
66
+ # define UNUSED_ATTR __attribute__((unused))
67
+ #else
68
+ # define UNUSED_ATTR
69
+ #endif
70
+
64
71
  /* force no inlining */
65
72
  #ifdef _MSC_VER
66
73
  # define FORCE_NOINLINE static __declspec(noinline)
@@ -127,9 +134,14 @@
127
134
  } \
128
135
  }
129
136
 
130
- /* vectorization */
137
+ /* vectorization
138
+ * older GCC (pre gcc-4.3 picked as the cutoff) uses a different syntax */
131
139
  #if !defined(__clang__) && defined(__GNUC__)
132
- # define DONT_VECTORIZE __attribute__((optimize("no-tree-vectorize")))
140
+ # if (__GNUC__ == 4 && __GNUC_MINOR__ > 3) || (__GNUC__ >= 5)
141
+ # define DONT_VECTORIZE __attribute__((optimize("no-tree-vectorize")))
142
+ # else
143
+ # define DONT_VECTORIZE _Pragma("GCC optimize(\"no-tree-vectorize\")")
144
+ # endif
133
145
  #else
134
146
  # define DONT_VECTORIZE
135
147
  #endif
@@ -308,7 +308,7 @@ If there is an error, the function will return an error code, which can be teste
308
308
  *******************************************/
309
309
  /* FSE buffer bounds */
310
310
  #define FSE_NCOUNTBOUND 512
311
- #define FSE_BLOCKBOUND(size) (size + (size>>7))
311
+ #define FSE_BLOCKBOUND(size) (size + (size>>7) + 4 /* fse states */ + sizeof(size_t) /* bitContainer */)
312
312
  #define FSE_COMPRESSBOUND(size) (FSE_NCOUNTBOUND + FSE_BLOCKBOUND(size)) /* Macro version, useful for static allocation */
313
313
 
314
314
  /* It is possible to statically allocate FSE CTable/DTable as a table of FSE_CTable/FSE_DTable using below macros */
@@ -52,7 +52,9 @@
52
52
  #define FSE_STATIC_ASSERT(c) DEBUG_STATIC_ASSERT(c) /* use only *after* variable declarations */
53
53
 
54
54
  /* check and forward error code */
55
+ #ifndef CHECK_F
55
56
  #define CHECK_F(f) { size_t const e = f; if (FSE_isError(e)) return e; }
57
+ #endif
56
58
 
57
59
 
58
60
  /* **************************************************************
@@ -47,6 +47,79 @@ extern "C" {
47
47
  #define MEM_STATIC_ASSERT(c) { enum { MEM_static_assert = 1/(int)(!!(c)) }; }
48
48
  MEM_STATIC void MEM_check(void) { MEM_STATIC_ASSERT((sizeof(size_t)==4) || (sizeof(size_t)==8)); }
49
49
 
50
+ /* detects whether we are being compiled under msan */
51
+ #if defined (__has_feature)
52
+ # if __has_feature(memory_sanitizer)
53
+ # define MEMORY_SANITIZER 1
54
+ # endif
55
+ #endif
56
+
57
+ #if defined (MEMORY_SANITIZER)
58
+ /* Not all platforms that support msan provide sanitizers/msan_interface.h.
59
+ * We therefore declare the functions we need ourselves, rather than trying to
60
+ * include the header file... */
61
+
62
+ #include <stdint.h> /* intptr_t */
63
+
64
+ /* Make memory region fully initialized (without changing its contents). */
65
+ void __msan_unpoison(const volatile void *a, size_t size);
66
+
67
+ /* Make memory region fully uninitialized (without changing its contents).
68
+ This is a legacy interface that does not update origin information. Use
69
+ __msan_allocated_memory() instead. */
70
+ void __msan_poison(const volatile void *a, size_t size);
71
+
72
+ /* Returns the offset of the first (at least partially) poisoned byte in the
73
+ memory range, or -1 if the whole range is good. */
74
+ intptr_t __msan_test_shadow(const volatile void *x, size_t size);
75
+ #endif
76
+
77
+ /* detects whether we are being compiled under asan */
78
+ #if defined (__has_feature)
79
+ # if __has_feature(address_sanitizer)
80
+ # define ADDRESS_SANITIZER 1
81
+ # endif
82
+ #elif defined(__SANITIZE_ADDRESS__)
83
+ # define ADDRESS_SANITIZER 1
84
+ #endif
85
+
86
+ #if defined (ADDRESS_SANITIZER)
87
+ /* Not all platforms that support asan provide sanitizers/asan_interface.h.
88
+ * We therefore declare the functions we need ourselves, rather than trying to
89
+ * include the header file... */
90
+
91
+ /**
92
+ * Marks a memory region (<c>[addr, addr+size)</c>) as unaddressable.
93
+ *
94
+ * This memory must be previously allocated by your program. Instrumented
95
+ * code is forbidden from accessing addresses in this region until it is
96
+ * unpoisoned. This function is not guaranteed to poison the entire region -
97
+ * it could poison only a subregion of <c>[addr, addr+size)</c> due to ASan
98
+ * alignment restrictions.
99
+ *
100
+ * \note This function is not thread-safe because no two threads can poison or
101
+ * unpoison memory in the same memory region simultaneously.
102
+ *
103
+ * \param addr Start of memory region.
104
+ * \param size Size of memory region. */
105
+ void __asan_poison_memory_region(void const volatile *addr, size_t size);
106
+
107
+ /**
108
+ * Marks a memory region (<c>[addr, addr+size)</c>) as addressable.
109
+ *
110
+ * This memory must be previously allocated by your program. Accessing
111
+ * addresses in this region is allowed until this region is poisoned again.
112
+ * This function could unpoison a super-region of <c>[addr, addr+size)</c> due
113
+ * to ASan alignment restrictions.
114
+ *
115
+ * \note This function is not thread-safe because no two threads can
116
+ * poison or unpoison memory in the same memory region simultaneously.
117
+ *
118
+ * \param addr Start of memory region.
119
+ * \param size Size of memory region. */
120
+ void __asan_unpoison_memory_region(void const volatile *addr, size_t size);
121
+ #endif
122
+
50
123
 
51
124
  /*-**************************************************************
52
125
  * Basic Types
@@ -127,9 +127,13 @@ POOL_ctx* POOL_create_advanced(size_t numThreads, size_t queueSize,
127
127
  ctx->queueTail = 0;
128
128
  ctx->numThreadsBusy = 0;
129
129
  ctx->queueEmpty = 1;
130
- (void)ZSTD_pthread_mutex_init(&ctx->queueMutex, NULL);
131
- (void)ZSTD_pthread_cond_init(&ctx->queuePushCond, NULL);
132
- (void)ZSTD_pthread_cond_init(&ctx->queuePopCond, NULL);
130
+ {
131
+ int error = 0;
132
+ error |= ZSTD_pthread_mutex_init(&ctx->queueMutex, NULL);
133
+ error |= ZSTD_pthread_cond_init(&ctx->queuePushCond, NULL);
134
+ error |= ZSTD_pthread_cond_init(&ctx->queuePopCond, NULL);
135
+ if (error) { POOL_free(ctx); return NULL; }
136
+ }
133
137
  ctx->shutdown = 0;
134
138
  /* Allocate space for the thread handles */
135
139
  ctx->threads = (ZSTD_pthread_t*)ZSTD_malloc(numThreads * sizeof(ZSTD_pthread_t), customMem);
@@ -14,6 +14,8 @@
14
14
  * This file will hold wrapper for systems, which do not support pthreads
15
15
  */
16
16
 
17
+ #include "threading.h"
18
+
17
19
  /* create fake symbol to avoid empty translation unit warning */
18
20
  int g_ZSTD_threading_useless_symbol;
19
21
 
@@ -28,7 +30,6 @@ int g_ZSTD_threading_useless_symbol;
28
30
  /* === Dependencies === */
29
31
  #include <process.h>
30
32
  #include <errno.h>
31
- #include "threading.h"
32
33
 
33
34
 
34
35
  /* === Implementation === */
@@ -73,3 +74,47 @@ int ZSTD_pthread_join(ZSTD_pthread_t thread, void **value_ptr)
73
74
  }
74
75
 
75
76
  #endif /* ZSTD_MULTITHREAD */
77
+
78
+ #if defined(ZSTD_MULTITHREAD) && DEBUGLEVEL >= 1 && !defined(_WIN32)
79
+
80
+ #include <stdlib.h>
81
+
82
+ int ZSTD_pthread_mutex_init(ZSTD_pthread_mutex_t* mutex, pthread_mutexattr_t const* attr)
83
+ {
84
+ *mutex = (pthread_mutex_t*)malloc(sizeof(pthread_mutex_t));
85
+ if (!*mutex)
86
+ return 1;
87
+ return pthread_mutex_init(*mutex, attr);
88
+ }
89
+
90
+ int ZSTD_pthread_mutex_destroy(ZSTD_pthread_mutex_t* mutex)
91
+ {
92
+ if (!*mutex)
93
+ return 0;
94
+ {
95
+ int const ret = pthread_mutex_destroy(*mutex);
96
+ free(*mutex);
97
+ return ret;
98
+ }
99
+ }
100
+
101
+ int ZSTD_pthread_cond_init(ZSTD_pthread_cond_t* cond, pthread_condattr_t const* attr)
102
+ {
103
+ *cond = (pthread_cond_t*)malloc(sizeof(pthread_cond_t));
104
+ if (!*cond)
105
+ return 1;
106
+ return pthread_cond_init(*cond, attr);
107
+ }
108
+
109
+ int ZSTD_pthread_cond_destroy(ZSTD_pthread_cond_t* cond)
110
+ {
111
+ if (!*cond)
112
+ return 0;
113
+ {
114
+ int const ret = pthread_cond_destroy(*cond);
115
+ free(*cond);
116
+ return ret;
117
+ }
118
+ }
119
+
120
+ #endif
@@ -13,6 +13,8 @@
13
13
  #ifndef THREADING_H_938743
14
14
  #define THREADING_H_938743
15
15
 
16
+ #include "debug.h"
17
+
16
18
  #if defined (__cplusplus)
17
19
  extern "C" {
18
20
  #endif
@@ -75,10 +77,12 @@ int ZSTD_pthread_join(ZSTD_pthread_t thread, void** value_ptr);
75
77
  */
76
78
 
77
79
 
78
- #elif defined(ZSTD_MULTITHREAD) /* posix assumed ; need a better detection method */
80
+ #elif defined(ZSTD_MULTITHREAD) /* posix assumed ; need a better detection method */
79
81
  /* === POSIX Systems === */
80
82
  # include <pthread.h>
81
83
 
84
+ #if DEBUGLEVEL < 1
85
+
82
86
  #define ZSTD_pthread_mutex_t pthread_mutex_t
83
87
  #define ZSTD_pthread_mutex_init(a, b) pthread_mutex_init((a), (b))
84
88
  #define ZSTD_pthread_mutex_destroy(a) pthread_mutex_destroy((a))
@@ -96,6 +100,33 @@ int ZSTD_pthread_join(ZSTD_pthread_t thread, void** value_ptr);
96
100
  #define ZSTD_pthread_create(a, b, c, d) pthread_create((a), (b), (c), (d))
97
101
  #define ZSTD_pthread_join(a, b) pthread_join((a),(b))
98
102
 
103
+ #else /* DEBUGLEVEL >= 1 */
104
+
105
+ /* Debug implementation of threading.
106
+ * In this implementation we use pointers for mutexes and condition variables.
107
+ * This way, if we forget to init/destroy them the program will crash or ASAN
108
+ * will report leaks.
109
+ */
110
+
111
+ #define ZSTD_pthread_mutex_t pthread_mutex_t*
112
+ int ZSTD_pthread_mutex_init(ZSTD_pthread_mutex_t* mutex, pthread_mutexattr_t const* attr);
113
+ int ZSTD_pthread_mutex_destroy(ZSTD_pthread_mutex_t* mutex);
114
+ #define ZSTD_pthread_mutex_lock(a) pthread_mutex_lock(*(a))
115
+ #define ZSTD_pthread_mutex_unlock(a) pthread_mutex_unlock(*(a))
116
+
117
+ #define ZSTD_pthread_cond_t pthread_cond_t*
118
+ int ZSTD_pthread_cond_init(ZSTD_pthread_cond_t* cond, pthread_condattr_t const* attr);
119
+ int ZSTD_pthread_cond_destroy(ZSTD_pthread_cond_t* cond);
120
+ #define ZSTD_pthread_cond_wait(a, b) pthread_cond_wait(*(a), *(b))
121
+ #define ZSTD_pthread_cond_signal(a) pthread_cond_signal(*(a))
122
+ #define ZSTD_pthread_cond_broadcast(a) pthread_cond_broadcast(*(a))
123
+
124
+ #define ZSTD_pthread_t pthread_t
125
+ #define ZSTD_pthread_create(a, b, c, d) pthread_create((a), (b), (c), (d))
126
+ #define ZSTD_pthread_join(a, b) pthread_join((a),(b))
127
+
128
+ #endif
129
+
99
130
  #else /* ZSTD_MULTITHREAD not defined */
100
131
  /* No multithreading support */
101
132
 
@@ -197,79 +197,56 @@ static void ZSTD_copy8(void* dst, const void* src) { memcpy(dst, src, 8); }
197
197
  static void ZSTD_copy16(void* dst, const void* src) { memcpy(dst, src, 16); }
198
198
  #define COPY16(d,s) { ZSTD_copy16(d,s); d+=16; s+=16; }
199
199
 
200
- #define WILDCOPY_OVERLENGTH 8
201
- #define VECLEN 16
200
+ #define WILDCOPY_OVERLENGTH 32
201
+ #define WILDCOPY_VECLEN 16
202
202
 
203
203
  typedef enum {
204
204
  ZSTD_no_overlap,
205
- ZSTD_overlap_src_before_dst,
205
+ ZSTD_overlap_src_before_dst
206
206
  /* ZSTD_overlap_dst_before_src, */
207
207
  } ZSTD_overlap_e;
208
208
 
209
209
  /*! ZSTD_wildcopy() :
210
- * custom version of memcpy(), can overwrite up to WILDCOPY_OVERLENGTH bytes (if length==0) */
210
+ * Custom version of memcpy(), can over read/write up to WILDCOPY_OVERLENGTH bytes (if length==0)
211
+ * @param ovtype controls the overlap detection
212
+ * - ZSTD_no_overlap: The source and destination are guaranteed to be at least WILDCOPY_VECLEN bytes apart.
213
+ * - ZSTD_overlap_src_before_dst: The src and dst may overlap, but they MUST be at least 8 bytes apart.
214
+ * The src buffer must be before the dst buffer.
215
+ */
211
216
  MEM_STATIC FORCE_INLINE_ATTR DONT_VECTORIZE
212
- void ZSTD_wildcopy(void* dst, const void* src, ptrdiff_t length, ZSTD_overlap_e ovtype)
217
+ void ZSTD_wildcopy(void* dst, const void* src, ptrdiff_t length, ZSTD_overlap_e const ovtype)
213
218
  {
214
219
  ptrdiff_t diff = (BYTE*)dst - (const BYTE*)src;
215
220
  const BYTE* ip = (const BYTE*)src;
216
221
  BYTE* op = (BYTE*)dst;
217
222
  BYTE* const oend = op + length;
218
223
 
219
- assert(diff >= 8 || (ovtype == ZSTD_no_overlap && diff < -8));
220
- if (length < VECLEN || (ovtype == ZSTD_overlap_src_before_dst && diff < VECLEN)) {
221
- do
222
- COPY8(op, ip)
223
- while (op < oend);
224
- }
225
- else {
226
- if ((length & 8) == 0)
227
- COPY8(op, ip);
228
- do {
224
+ assert(diff >= 8 || (ovtype == ZSTD_no_overlap && diff <= -WILDCOPY_VECLEN));
225
+
226
+ if (ovtype == ZSTD_overlap_src_before_dst && diff < WILDCOPY_VECLEN) {
227
+ /* Handle short offset copies. */
228
+ do {
229
+ COPY8(op, ip)
230
+ } while (op < oend);
231
+ } else {
232
+ assert(diff >= WILDCOPY_VECLEN || diff <= -WILDCOPY_VECLEN);
233
+ /* Separate out the first two COPY16() calls because the copy length is
234
+ * almost certain to be short, so the branches have different
235
+ * probabilities.
236
+ * On gcc-9 unrolling once is +1.6%, twice is +2%, thrice is +1.8%.
237
+ * On clang-8 unrolling once is +1.4%, twice is +3.3%, thrice is +3%.
238
+ */
229
239
  COPY16(op, ip);
230
- }
231
- while (op < oend);
232
- }
233
- }
234
-
235
- /*! ZSTD_wildcopy_16min() :
236
- * same semantics as ZSTD_wilcopy() except guaranteed to be able to copy 16 bytes at the start */
237
- MEM_STATIC FORCE_INLINE_ATTR DONT_VECTORIZE
238
- void ZSTD_wildcopy_16min(void* dst, const void* src, ptrdiff_t length, ZSTD_overlap_e ovtype)
239
- {
240
- ptrdiff_t diff = (BYTE*)dst - (const BYTE*)src;
241
- const BYTE* ip = (const BYTE*)src;
242
- BYTE* op = (BYTE*)dst;
243
- BYTE* const oend = op + length;
244
-
245
- assert(length >= 8);
246
- assert(diff >= 8 || (ovtype == ZSTD_no_overlap && diff < -8));
247
-
248
- if (ovtype == ZSTD_overlap_src_before_dst && diff < VECLEN) {
249
- do
250
- COPY8(op, ip)
251
- while (op < oend);
252
- }
253
- else {
254
- if ((length & 8) == 0)
255
- COPY8(op, ip);
256
- do {
257
240
  COPY16(op, ip);
258
- }
259
- while (op < oend);
241
+ if (op >= oend) return;
242
+ do {
243
+ COPY16(op, ip);
244
+ COPY16(op, ip);
245
+ }
246
+ while (op < oend);
260
247
  }
261
248
  }
262
249
 
263
- 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 */
264
- {
265
- const BYTE* ip = (const BYTE*)src;
266
- BYTE* op = (BYTE*)dst;
267
- BYTE* const oend = (BYTE*)dstEnd;
268
- do
269
- COPY8(op, ip)
270
- while (op < oend);
271
- }
272
-
273
250
 
274
251
  /*-*******************************************
275
252
  * Private declarations
@@ -323,7 +300,7 @@ MEM_STATIC U32 ZSTD_highbit32(U32 val) /* compress, dictBuilder, decodeCorpus
323
300
  _BitScanReverse(&r, val);
324
301
  return (unsigned)r;
325
302
  # elif defined(__GNUC__) && (__GNUC__ >= 3) /* GCC Intrinsic */
326
- return 31 - __builtin_clz(val);
303
+ return __builtin_clz (val) ^ 31;
327
304
  # elif defined(__ICCARM__) /* IAR Intrinsic */
328
305
  return 31 - __CLZ(val);
329
306
  # else /* Software version */