zstdlib 0.9.0-x86_64-darwin

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +6 -0
  3. data/CHANGES.md +78 -0
  4. data/Gemfile +3 -0
  5. data/README.md +107 -0
  6. data/Rakefile +59 -0
  7. data/ext/zstdlib_c/extconf.rb +54 -0
  8. data/ext/zstdlib_c/ruby/zlib-2.2/zstdlib.c +4675 -0
  9. data/ext/zstdlib_c/ruby/zlib-2.3/zstdlib.c +4702 -0
  10. data/ext/zstdlib_c/ruby/zlib-2.4/zstdlib.c +4859 -0
  11. data/ext/zstdlib_c/ruby/zlib-2.5/zstdlib.c +4864 -0
  12. data/ext/zstdlib_c/ruby/zlib-2.6/zstdlib.c +4906 -0
  13. data/ext/zstdlib_c/ruby/zlib-2.7/zstdlib.c +4895 -0
  14. data/ext/zstdlib_c/ruby/zlib-3.0/zstdlib.c +4994 -0
  15. data/ext/zstdlib_c/ruby/zlib-3.1/zstdlib.c +5076 -0
  16. data/ext/zstdlib_c/zlib-1.2.11/adler32.c +186 -0
  17. data/ext/zstdlib_c/zlib-1.2.11/compress.c +86 -0
  18. data/ext/zstdlib_c/zlib-1.2.11/crc32.c +442 -0
  19. data/ext/zstdlib_c/zlib-1.2.11/crc32.h +441 -0
  20. data/ext/zstdlib_c/zlib-1.2.11/deflate.c +2163 -0
  21. data/ext/zstdlib_c/zlib-1.2.11/deflate.h +349 -0
  22. data/ext/zstdlib_c/zlib-1.2.11/gzclose.c +25 -0
  23. data/ext/zstdlib_c/zlib-1.2.11/gzguts.h +218 -0
  24. data/ext/zstdlib_c/zlib-1.2.11/gzlib.c +637 -0
  25. data/ext/zstdlib_c/zlib-1.2.11/gzread.c +654 -0
  26. data/ext/zstdlib_c/zlib-1.2.11/gzwrite.c +665 -0
  27. data/ext/zstdlib_c/zlib-1.2.11/infback.c +640 -0
  28. data/ext/zstdlib_c/zlib-1.2.11/inffast.c +323 -0
  29. data/ext/zstdlib_c/zlib-1.2.11/inffast.h +11 -0
  30. data/ext/zstdlib_c/zlib-1.2.11/inffixed.h +94 -0
  31. data/ext/zstdlib_c/zlib-1.2.11/inflate.c +1561 -0
  32. data/ext/zstdlib_c/zlib-1.2.11/inflate.h +125 -0
  33. data/ext/zstdlib_c/zlib-1.2.11/inftrees.c +304 -0
  34. data/ext/zstdlib_c/zlib-1.2.11/inftrees.h +62 -0
  35. data/ext/zstdlib_c/zlib-1.2.11/trees.c +1203 -0
  36. data/ext/zstdlib_c/zlib-1.2.11/trees.h +128 -0
  37. data/ext/zstdlib_c/zlib-1.2.11/uncompr.c +93 -0
  38. data/ext/zstdlib_c/zlib-1.2.11/zconf.h +534 -0
  39. data/ext/zstdlib_c/zlib-1.2.11/zlib.h +1912 -0
  40. data/ext/zstdlib_c/zlib-1.2.11/zutil.c +325 -0
  41. data/ext/zstdlib_c/zlib-1.2.11/zutil.h +271 -0
  42. data/ext/zstdlib_c/zlib.mk +14 -0
  43. data/ext/zstdlib_c/zlibwrapper/zlibwrapper.c +10 -0
  44. data/ext/zstdlib_c/zlibwrapper.mk +14 -0
  45. data/ext/zstdlib_c/zstd-1.5.2/lib/common/bitstream.h +478 -0
  46. data/ext/zstdlib_c/zstd-1.5.2/lib/common/compiler.h +335 -0
  47. data/ext/zstdlib_c/zstd-1.5.2/lib/common/cpu.h +213 -0
  48. data/ext/zstdlib_c/zstd-1.5.2/lib/common/debug.c +24 -0
  49. data/ext/zstdlib_c/zstd-1.5.2/lib/common/debug.h +107 -0
  50. data/ext/zstdlib_c/zstd-1.5.2/lib/common/entropy_common.c +368 -0
  51. data/ext/zstdlib_c/zstd-1.5.2/lib/common/error_private.c +56 -0
  52. data/ext/zstdlib_c/zstd-1.5.2/lib/common/error_private.h +159 -0
  53. data/ext/zstdlib_c/zstd-1.5.2/lib/common/fse.h +717 -0
  54. data/ext/zstdlib_c/zstd-1.5.2/lib/common/fse_decompress.c +403 -0
  55. data/ext/zstdlib_c/zstd-1.5.2/lib/common/huf.h +364 -0
  56. data/ext/zstdlib_c/zstd-1.5.2/lib/common/mem.h +442 -0
  57. data/ext/zstdlib_c/zstd-1.5.2/lib/common/pool.c +355 -0
  58. data/ext/zstdlib_c/zstd-1.5.2/lib/common/pool.h +84 -0
  59. data/ext/zstdlib_c/zstd-1.5.2/lib/common/portability_macros.h +137 -0
  60. data/ext/zstdlib_c/zstd-1.5.2/lib/common/threading.c +122 -0
  61. data/ext/zstdlib_c/zstd-1.5.2/lib/common/threading.h +155 -0
  62. data/ext/zstdlib_c/zstd-1.5.2/lib/common/xxhash.c +24 -0
  63. data/ext/zstdlib_c/zstd-1.5.2/lib/common/xxhash.h +5686 -0
  64. data/ext/zstdlib_c/zstd-1.5.2/lib/common/zstd_common.c +83 -0
  65. data/ext/zstdlib_c/zstd-1.5.2/lib/common/zstd_deps.h +111 -0
  66. data/ext/zstdlib_c/zstd-1.5.2/lib/common/zstd_internal.h +493 -0
  67. data/ext/zstdlib_c/zstd-1.5.2/lib/common/zstd_trace.h +163 -0
  68. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/clevels.h +134 -0
  69. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/fse_compress.c +741 -0
  70. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/hist.c +181 -0
  71. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/hist.h +75 -0
  72. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/huf_compress.c +1370 -0
  73. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_compress.c +6327 -0
  74. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_compress_internal.h +1458 -0
  75. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_compress_literals.c +159 -0
  76. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_compress_literals.h +31 -0
  77. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_compress_sequences.c +442 -0
  78. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_compress_sequences.h +54 -0
  79. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_compress_superblock.c +573 -0
  80. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_compress_superblock.h +32 -0
  81. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_cwksp.h +676 -0
  82. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_double_fast.c +696 -0
  83. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_double_fast.h +38 -0
  84. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_fast.c +675 -0
  85. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_fast.h +37 -0
  86. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_lazy.c +2104 -0
  87. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_lazy.h +125 -0
  88. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_ldm.c +724 -0
  89. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_ldm.h +117 -0
  90. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_ldm_geartab.h +106 -0
  91. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_opt.c +1446 -0
  92. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_opt.h +56 -0
  93. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstdmt_compress.c +1859 -0
  94. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstdmt_compress.h +113 -0
  95. data/ext/zstdlib_c/zstd-1.5.2/lib/decompress/huf_decompress.c +1889 -0
  96. data/ext/zstdlib_c/zstd-1.5.2/lib/decompress/huf_decompress_amd64.S +585 -0
  97. data/ext/zstdlib_c/zstd-1.5.2/lib/decompress/zstd_ddict.c +244 -0
  98. data/ext/zstdlib_c/zstd-1.5.2/lib/decompress/zstd_ddict.h +44 -0
  99. data/ext/zstdlib_c/zstd-1.5.2/lib/decompress/zstd_decompress.c +2230 -0
  100. data/ext/zstdlib_c/zstd-1.5.2/lib/decompress/zstd_decompress_block.c +2072 -0
  101. data/ext/zstdlib_c/zstd-1.5.2/lib/decompress/zstd_decompress_block.h +68 -0
  102. data/ext/zstdlib_c/zstd-1.5.2/lib/decompress/zstd_decompress_internal.h +236 -0
  103. data/ext/zstdlib_c/zstd-1.5.2/lib/zdict.h +452 -0
  104. data/ext/zstdlib_c/zstd-1.5.2/lib/zstd.h +2575 -0
  105. data/ext/zstdlib_c/zstd-1.5.2/lib/zstd_errors.h +95 -0
  106. data/ext/zstdlib_c/zstd-1.5.2/zlibWrapper/gzclose.c +28 -0
  107. data/ext/zstdlib_c/zstd-1.5.2/zlibWrapper/gzcompatibility.h +68 -0
  108. data/ext/zstdlib_c/zstd-1.5.2/zlibWrapper/gzguts.h +229 -0
  109. data/ext/zstdlib_c/zstd-1.5.2/zlibWrapper/gzlib.c +640 -0
  110. data/ext/zstdlib_c/zstd-1.5.2/zlibWrapper/gzread.c +678 -0
  111. data/ext/zstdlib_c/zstd-1.5.2/zlibWrapper/gzwrite.c +671 -0
  112. data/ext/zstdlib_c/zstd-1.5.2/zlibWrapper/zstd_zlibwrapper.c +1198 -0
  113. data/ext/zstdlib_c/zstd-1.5.2/zlibWrapper/zstd_zlibwrapper.h +88 -0
  114. data/ext/zstdlib_c/zstd.mk +15 -0
  115. data/lib/2.4/zstdlib_c.bundle +0 -0
  116. data/lib/2.5/zstdlib_c.bundle +0 -0
  117. data/lib/2.6/zstdlib_c.bundle +0 -0
  118. data/lib/2.7/zstdlib_c.bundle +0 -0
  119. data/lib/3.0/zstdlib_c.bundle +0 -0
  120. data/lib/3.1/zstdlib_c.bundle +0 -0
  121. data/lib/zstdlib.rb +6 -0
  122. data/test/zstdlib_test.rb +21 -0
  123. metadata +237 -0
@@ -0,0 +1,335 @@
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_COMPILER_H
12
+ #define ZSTD_COMPILER_H
13
+
14
+ #include "portability_macros.h"
15
+
16
+ /*-*******************************************************
17
+ * Compiler specifics
18
+ *********************************************************/
19
+ /* force inlining */
20
+
21
+ #if !defined(ZSTD_NO_INLINE)
22
+ #if (defined(__GNUC__) && !defined(__STRICT_ANSI__)) || defined(__cplusplus) || defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */
23
+ # define INLINE_KEYWORD inline
24
+ #else
25
+ # define INLINE_KEYWORD
26
+ #endif
27
+
28
+ #if defined(__GNUC__) || defined(__ICCARM__)
29
+ # define FORCE_INLINE_ATTR __attribute__((always_inline))
30
+ #elif defined(_MSC_VER)
31
+ # define FORCE_INLINE_ATTR __forceinline
32
+ #else
33
+ # define FORCE_INLINE_ATTR
34
+ #endif
35
+
36
+ #else
37
+
38
+ #define INLINE_KEYWORD
39
+ #define FORCE_INLINE_ATTR
40
+
41
+ #endif
42
+
43
+ /**
44
+ On MSVC qsort requires that functions passed into it use the __cdecl calling conversion(CC).
45
+ This explicitly marks such functions as __cdecl so that the code will still compile
46
+ if a CC other than __cdecl has been made the default.
47
+ */
48
+ #if defined(_MSC_VER)
49
+ # define WIN_CDECL __cdecl
50
+ #else
51
+ # define WIN_CDECL
52
+ #endif
53
+
54
+ /**
55
+ * FORCE_INLINE_TEMPLATE is used to define C "templates", which take constant
56
+ * parameters. They must be inlined for the compiler to eliminate the constant
57
+ * branches.
58
+ */
59
+ #define FORCE_INLINE_TEMPLATE static INLINE_KEYWORD FORCE_INLINE_ATTR
60
+ /**
61
+ * HINT_INLINE is used to help the compiler generate better code. It is *not*
62
+ * used for "templates", so it can be tweaked based on the compilers
63
+ * performance.
64
+ *
65
+ * gcc-4.8 and gcc-4.9 have been shown to benefit from leaving off the
66
+ * always_inline attribute.
67
+ *
68
+ * clang up to 5.0.0 (trunk) benefit tremendously from the always_inline
69
+ * attribute.
70
+ */
71
+ #if !defined(__clang__) && defined(__GNUC__) && __GNUC__ >= 4 && __GNUC_MINOR__ >= 8 && __GNUC__ < 5
72
+ # define HINT_INLINE static INLINE_KEYWORD
73
+ #else
74
+ # define HINT_INLINE static INLINE_KEYWORD FORCE_INLINE_ATTR
75
+ #endif
76
+
77
+ /* UNUSED_ATTR tells the compiler it is okay if the function is unused. */
78
+ #if defined(__GNUC__)
79
+ # define UNUSED_ATTR __attribute__((unused))
80
+ #else
81
+ # define UNUSED_ATTR
82
+ #endif
83
+
84
+ /* force no inlining */
85
+ #ifdef _MSC_VER
86
+ # define FORCE_NOINLINE static __declspec(noinline)
87
+ #else
88
+ # if defined(__GNUC__) || defined(__ICCARM__)
89
+ # define FORCE_NOINLINE static __attribute__((__noinline__))
90
+ # else
91
+ # define FORCE_NOINLINE static
92
+ # endif
93
+ #endif
94
+
95
+
96
+ /* target attribute */
97
+ #if defined(__GNUC__) || defined(__ICCARM__)
98
+ # define TARGET_ATTRIBUTE(target) __attribute__((__target__(target)))
99
+ #else
100
+ # define TARGET_ATTRIBUTE(target)
101
+ #endif
102
+
103
+ /* Target attribute for BMI2 dynamic dispatch.
104
+ * Enable lzcnt, bmi, and bmi2.
105
+ * We test for bmi1 & bmi2. lzcnt is included in bmi1.
106
+ */
107
+ #define BMI2_TARGET_ATTRIBUTE TARGET_ATTRIBUTE("lzcnt,bmi,bmi2")
108
+
109
+ /* prefetch
110
+ * can be disabled, by declaring NO_PREFETCH build macro */
111
+ #if defined(NO_PREFETCH)
112
+ # define PREFETCH_L1(ptr) (void)(ptr) /* disabled */
113
+ # define PREFETCH_L2(ptr) (void)(ptr) /* disabled */
114
+ #else
115
+ # if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_I86)) /* _mm_prefetch() is not defined outside of x86/x64 */
116
+ # include <mmintrin.h> /* https://msdn.microsoft.com/fr-fr/library/84szxsww(v=vs.90).aspx */
117
+ # define PREFETCH_L1(ptr) _mm_prefetch((const char*)(ptr), _MM_HINT_T0)
118
+ # define PREFETCH_L2(ptr) _mm_prefetch((const char*)(ptr), _MM_HINT_T1)
119
+ # elif defined(__GNUC__) && ( (__GNUC__ >= 4) || ( (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1) ) )
120
+ # define PREFETCH_L1(ptr) __builtin_prefetch((ptr), 0 /* rw==read */, 3 /* locality */)
121
+ # define PREFETCH_L2(ptr) __builtin_prefetch((ptr), 0 /* rw==read */, 2 /* locality */)
122
+ # elif defined(__aarch64__)
123
+ # define PREFETCH_L1(ptr) __asm__ __volatile__("prfm pldl1keep, %0" ::"Q"(*(ptr)))
124
+ # define PREFETCH_L2(ptr) __asm__ __volatile__("prfm pldl2keep, %0" ::"Q"(*(ptr)))
125
+ # else
126
+ # define PREFETCH_L1(ptr) (void)(ptr) /* disabled */
127
+ # define PREFETCH_L2(ptr) (void)(ptr) /* disabled */
128
+ # endif
129
+ #endif /* NO_PREFETCH */
130
+
131
+ #define CACHELINE_SIZE 64
132
+
133
+ #define PREFETCH_AREA(p, s) { \
134
+ const char* const _ptr = (const char*)(p); \
135
+ size_t const _size = (size_t)(s); \
136
+ size_t _pos; \
137
+ for (_pos=0; _pos<_size; _pos+=CACHELINE_SIZE) { \
138
+ PREFETCH_L2(_ptr + _pos); \
139
+ } \
140
+ }
141
+
142
+ /* vectorization
143
+ * older GCC (pre gcc-4.3 picked as the cutoff) uses a different syntax,
144
+ * and some compilers, like Intel ICC and MCST LCC, do not support it at all. */
145
+ #if !defined(__INTEL_COMPILER) && !defined(__clang__) && defined(__GNUC__) && !defined(__LCC__)
146
+ # if (__GNUC__ == 4 && __GNUC_MINOR__ > 3) || (__GNUC__ >= 5)
147
+ # define DONT_VECTORIZE __attribute__((optimize("no-tree-vectorize")))
148
+ # else
149
+ # define DONT_VECTORIZE _Pragma("GCC optimize(\"no-tree-vectorize\")")
150
+ # endif
151
+ #else
152
+ # define DONT_VECTORIZE
153
+ #endif
154
+
155
+ /* Tell the compiler that a branch is likely or unlikely.
156
+ * Only use these macros if it causes the compiler to generate better code.
157
+ * If you can remove a LIKELY/UNLIKELY annotation without speed changes in gcc
158
+ * and clang, please do.
159
+ */
160
+ #if defined(__GNUC__)
161
+ #define LIKELY(x) (__builtin_expect((x), 1))
162
+ #define UNLIKELY(x) (__builtin_expect((x), 0))
163
+ #else
164
+ #define LIKELY(x) (x)
165
+ #define UNLIKELY(x) (x)
166
+ #endif
167
+
168
+ /* disable warnings */
169
+ #ifdef _MSC_VER /* Visual Studio */
170
+ # include <intrin.h> /* For Visual 2005 */
171
+ # pragma warning(disable : 4100) /* disable: C4100: unreferenced formal parameter */
172
+ # pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */
173
+ # pragma warning(disable : 4204) /* disable: C4204: non-constant aggregate initializer */
174
+ # pragma warning(disable : 4214) /* disable: C4214: non-int bitfields */
175
+ # pragma warning(disable : 4324) /* disable: C4324: padded structure */
176
+ #endif
177
+
178
+ /*Like DYNAMIC_BMI2 but for compile time determination of BMI2 support*/
179
+ #ifndef STATIC_BMI2
180
+ # if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_I86))
181
+ # ifdef __AVX2__ //MSVC does not have a BMI2 specific flag, but every CPU that supports AVX2 also supports BMI2
182
+ # define STATIC_BMI2 1
183
+ # endif
184
+ # endif
185
+ #endif
186
+
187
+ #ifndef STATIC_BMI2
188
+ #define STATIC_BMI2 0
189
+ #endif
190
+
191
+ /* compile time determination of SIMD support */
192
+ #if !defined(ZSTD_NO_INTRINSICS)
193
+ # if defined(__SSE2__) || defined(_M_AMD64) || (defined (_M_IX86) && defined(_M_IX86_FP) && (_M_IX86_FP >= 2))
194
+ # define ZSTD_ARCH_X86_SSE2
195
+ # endif
196
+ # if defined(__ARM_NEON) || defined(_M_ARM64)
197
+ # define ZSTD_ARCH_ARM_NEON
198
+ # endif
199
+ #
200
+ # if defined(ZSTD_ARCH_X86_SSE2)
201
+ # include <emmintrin.h>
202
+ # elif defined(ZSTD_ARCH_ARM_NEON)
203
+ # include <arm_neon.h>
204
+ # endif
205
+ #endif
206
+
207
+ /* C-language Attributes are added in C23. */
208
+ #if defined(__STDC_VERSION__) && (__STDC_VERSION__ > 201710L) && defined(__has_c_attribute)
209
+ # define ZSTD_HAS_C_ATTRIBUTE(x) __has_c_attribute(x)
210
+ #else
211
+ # define ZSTD_HAS_C_ATTRIBUTE(x) 0
212
+ #endif
213
+
214
+ /* Only use C++ attributes in C++. Some compilers report support for C++
215
+ * attributes when compiling with C.
216
+ */
217
+ #if defined(__cplusplus) && defined(__has_cpp_attribute)
218
+ # define ZSTD_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
219
+ #else
220
+ # define ZSTD_HAS_CPP_ATTRIBUTE(x) 0
221
+ #endif
222
+
223
+ /* Define ZSTD_FALLTHROUGH macro for annotating switch case with the 'fallthrough' attribute.
224
+ * - C23: https://en.cppreference.com/w/c/language/attributes/fallthrough
225
+ * - CPP17: https://en.cppreference.com/w/cpp/language/attributes/fallthrough
226
+ * - Else: __attribute__((__fallthrough__))
227
+ */
228
+ #ifndef ZSTD_FALLTHROUGH
229
+ # if ZSTD_HAS_C_ATTRIBUTE(fallthrough)
230
+ # define ZSTD_FALLTHROUGH [[fallthrough]]
231
+ # elif ZSTD_HAS_CPP_ATTRIBUTE(fallthrough)
232
+ # define ZSTD_FALLTHROUGH [[fallthrough]]
233
+ # elif __has_attribute(__fallthrough__)
234
+ /* Leading semicolon is to satisfy gcc-11 with -pedantic. Without the semicolon
235
+ * gcc complains about: a label can only be part of a statement and a declaration is not a statement.
236
+ */
237
+ # define ZSTD_FALLTHROUGH ; __attribute__((__fallthrough__))
238
+ # else
239
+ # define ZSTD_FALLTHROUGH
240
+ # endif
241
+ #endif
242
+
243
+ /*-**************************************************************
244
+ * Alignment check
245
+ *****************************************************************/
246
+
247
+ /* this test was initially positioned in mem.h,
248
+ * but this file is removed (or replaced) for linux kernel
249
+ * so it's now hosted in compiler.h,
250
+ * which remains valid for both user & kernel spaces.
251
+ */
252
+
253
+ #ifndef ZSTD_ALIGNOF
254
+ # if defined(__GNUC__) || defined(_MSC_VER)
255
+ /* covers gcc, clang & MSVC */
256
+ /* note : this section must come first, before C11,
257
+ * due to a limitation in the kernel source generator */
258
+ # define ZSTD_ALIGNOF(T) __alignof(T)
259
+
260
+ # elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
261
+ /* C11 support */
262
+ # include <stdalign.h>
263
+ # define ZSTD_ALIGNOF(T) alignof(T)
264
+
265
+ # else
266
+ /* No known support for alignof() - imperfect backup */
267
+ # define ZSTD_ALIGNOF(T) (sizeof(void*) < sizeof(T) ? sizeof(void*) : sizeof(T))
268
+
269
+ # endif
270
+ #endif /* ZSTD_ALIGNOF */
271
+
272
+ /*-**************************************************************
273
+ * Sanitizer
274
+ *****************************************************************/
275
+
276
+ #if ZSTD_MEMORY_SANITIZER
277
+ /* Not all platforms that support msan provide sanitizers/msan_interface.h.
278
+ * We therefore declare the functions we need ourselves, rather than trying to
279
+ * include the header file... */
280
+ #include <stddef.h> /* size_t */
281
+ #define ZSTD_DEPS_NEED_STDINT
282
+ #include "zstd_deps.h" /* intptr_t */
283
+
284
+ /* Make memory region fully initialized (without changing its contents). */
285
+ void __msan_unpoison(const volatile void *a, size_t size);
286
+
287
+ /* Make memory region fully uninitialized (without changing its contents).
288
+ This is a legacy interface that does not update origin information. Use
289
+ __msan_allocated_memory() instead. */
290
+ void __msan_poison(const volatile void *a, size_t size);
291
+
292
+ /* Returns the offset of the first (at least partially) poisoned byte in the
293
+ memory range, or -1 if the whole range is good. */
294
+ intptr_t __msan_test_shadow(const volatile void *x, size_t size);
295
+ #endif
296
+
297
+ #if ZSTD_ADDRESS_SANITIZER
298
+ /* Not all platforms that support asan provide sanitizers/asan_interface.h.
299
+ * We therefore declare the functions we need ourselves, rather than trying to
300
+ * include the header file... */
301
+ #include <stddef.h> /* size_t */
302
+
303
+ /**
304
+ * Marks a memory region (<c>[addr, addr+size)</c>) as unaddressable.
305
+ *
306
+ * This memory must be previously allocated by your program. Instrumented
307
+ * code is forbidden from accessing addresses in this region until it is
308
+ * unpoisoned. This function is not guaranteed to poison the entire region -
309
+ * it could poison only a subregion of <c>[addr, addr+size)</c> due to ASan
310
+ * alignment restrictions.
311
+ *
312
+ * \note This function is not thread-safe because no two threads can poison or
313
+ * unpoison memory in the same memory region simultaneously.
314
+ *
315
+ * \param addr Start of memory region.
316
+ * \param size Size of memory region. */
317
+ void __asan_poison_memory_region(void const volatile *addr, size_t size);
318
+
319
+ /**
320
+ * Marks a memory region (<c>[addr, addr+size)</c>) as addressable.
321
+ *
322
+ * This memory must be previously allocated by your program. Accessing
323
+ * addresses in this region is allowed until this region is poisoned again.
324
+ * This function could unpoison a super-region of <c>[addr, addr+size)</c> due
325
+ * to ASan alignment restrictions.
326
+ *
327
+ * \note This function is not thread-safe because no two threads can
328
+ * poison or unpoison memory in the same memory region simultaneously.
329
+ *
330
+ * \param addr Start of memory region.
331
+ * \param size Size of memory region. */
332
+ void __asan_unpoison_memory_region(void const volatile *addr, size_t size);
333
+ #endif
334
+
335
+ #endif /* ZSTD_COMPILER_H */
@@ -0,0 +1,213 @@
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
+ #ifndef ZSTD_COMMON_CPU_H
12
+ #define ZSTD_COMMON_CPU_H
13
+
14
+ /**
15
+ * Implementation taken from folly/CpuId.h
16
+ * https://github.com/facebook/folly/blob/master/folly/CpuId.h
17
+ */
18
+
19
+ #include "mem.h"
20
+
21
+ #ifdef _MSC_VER
22
+ #include <intrin.h>
23
+ #endif
24
+
25
+ typedef struct {
26
+ U32 f1c;
27
+ U32 f1d;
28
+ U32 f7b;
29
+ U32 f7c;
30
+ } ZSTD_cpuid_t;
31
+
32
+ MEM_STATIC ZSTD_cpuid_t ZSTD_cpuid(void) {
33
+ U32 f1c = 0;
34
+ U32 f1d = 0;
35
+ U32 f7b = 0;
36
+ U32 f7c = 0;
37
+ #if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86))
38
+ int reg[4];
39
+ __cpuid((int*)reg, 0);
40
+ {
41
+ int const n = reg[0];
42
+ if (n >= 1) {
43
+ __cpuid((int*)reg, 1);
44
+ f1c = (U32)reg[2];
45
+ f1d = (U32)reg[3];
46
+ }
47
+ if (n >= 7) {
48
+ __cpuidex((int*)reg, 7, 0);
49
+ f7b = (U32)reg[1];
50
+ f7c = (U32)reg[2];
51
+ }
52
+ }
53
+ #elif defined(__i386__) && defined(__PIC__) && !defined(__clang__) && defined(__GNUC__)
54
+ /* The following block like the normal cpuid branch below, but gcc
55
+ * reserves ebx for use of its pic register so we must specially
56
+ * handle the save and restore to avoid clobbering the register
57
+ */
58
+ U32 n;
59
+ __asm__(
60
+ "pushl %%ebx\n\t"
61
+ "cpuid\n\t"
62
+ "popl %%ebx\n\t"
63
+ : "=a"(n)
64
+ : "a"(0)
65
+ : "ecx", "edx");
66
+ if (n >= 1) {
67
+ U32 f1a;
68
+ __asm__(
69
+ "pushl %%ebx\n\t"
70
+ "cpuid\n\t"
71
+ "popl %%ebx\n\t"
72
+ : "=a"(f1a), "=c"(f1c), "=d"(f1d)
73
+ : "a"(1));
74
+ }
75
+ if (n >= 7) {
76
+ __asm__(
77
+ "pushl %%ebx\n\t"
78
+ "cpuid\n\t"
79
+ "movl %%ebx, %%eax\n\t"
80
+ "popl %%ebx"
81
+ : "=a"(f7b), "=c"(f7c)
82
+ : "a"(7), "c"(0)
83
+ : "edx");
84
+ }
85
+ #elif defined(__x86_64__) || defined(_M_X64) || defined(__i386__)
86
+ U32 n;
87
+ __asm__("cpuid" : "=a"(n) : "a"(0) : "ebx", "ecx", "edx");
88
+ if (n >= 1) {
89
+ U32 f1a;
90
+ __asm__("cpuid" : "=a"(f1a), "=c"(f1c), "=d"(f1d) : "a"(1) : "ebx");
91
+ }
92
+ if (n >= 7) {
93
+ U32 f7a;
94
+ __asm__("cpuid"
95
+ : "=a"(f7a), "=b"(f7b), "=c"(f7c)
96
+ : "a"(7), "c"(0)
97
+ : "edx");
98
+ }
99
+ #endif
100
+ {
101
+ ZSTD_cpuid_t cpuid;
102
+ cpuid.f1c = f1c;
103
+ cpuid.f1d = f1d;
104
+ cpuid.f7b = f7b;
105
+ cpuid.f7c = f7c;
106
+ return cpuid;
107
+ }
108
+ }
109
+
110
+ #define X(name, r, bit) \
111
+ MEM_STATIC int ZSTD_cpuid_##name(ZSTD_cpuid_t const cpuid) { \
112
+ return ((cpuid.r) & (1U << bit)) != 0; \
113
+ }
114
+
115
+ /* cpuid(1): Processor Info and Feature Bits. */
116
+ #define C(name, bit) X(name, f1c, bit)
117
+ C(sse3, 0)
118
+ C(pclmuldq, 1)
119
+ C(dtes64, 2)
120
+ C(monitor, 3)
121
+ C(dscpl, 4)
122
+ C(vmx, 5)
123
+ C(smx, 6)
124
+ C(eist, 7)
125
+ C(tm2, 8)
126
+ C(ssse3, 9)
127
+ C(cnxtid, 10)
128
+ C(fma, 12)
129
+ C(cx16, 13)
130
+ C(xtpr, 14)
131
+ C(pdcm, 15)
132
+ C(pcid, 17)
133
+ C(dca, 18)
134
+ C(sse41, 19)
135
+ C(sse42, 20)
136
+ C(x2apic, 21)
137
+ C(movbe, 22)
138
+ C(popcnt, 23)
139
+ C(tscdeadline, 24)
140
+ C(aes, 25)
141
+ C(xsave, 26)
142
+ C(osxsave, 27)
143
+ C(avx, 28)
144
+ C(f16c, 29)
145
+ C(rdrand, 30)
146
+ #undef C
147
+ #define D(name, bit) X(name, f1d, bit)
148
+ D(fpu, 0)
149
+ D(vme, 1)
150
+ D(de, 2)
151
+ D(pse, 3)
152
+ D(tsc, 4)
153
+ D(msr, 5)
154
+ D(pae, 6)
155
+ D(mce, 7)
156
+ D(cx8, 8)
157
+ D(apic, 9)
158
+ D(sep, 11)
159
+ D(mtrr, 12)
160
+ D(pge, 13)
161
+ D(mca, 14)
162
+ D(cmov, 15)
163
+ D(pat, 16)
164
+ D(pse36, 17)
165
+ D(psn, 18)
166
+ D(clfsh, 19)
167
+ D(ds, 21)
168
+ D(acpi, 22)
169
+ D(mmx, 23)
170
+ D(fxsr, 24)
171
+ D(sse, 25)
172
+ D(sse2, 26)
173
+ D(ss, 27)
174
+ D(htt, 28)
175
+ D(tm, 29)
176
+ D(pbe, 31)
177
+ #undef D
178
+
179
+ /* cpuid(7): Extended Features. */
180
+ #define B(name, bit) X(name, f7b, bit)
181
+ B(bmi1, 3)
182
+ B(hle, 4)
183
+ B(avx2, 5)
184
+ B(smep, 7)
185
+ B(bmi2, 8)
186
+ B(erms, 9)
187
+ B(invpcid, 10)
188
+ B(rtm, 11)
189
+ B(mpx, 14)
190
+ B(avx512f, 16)
191
+ B(avx512dq, 17)
192
+ B(rdseed, 18)
193
+ B(adx, 19)
194
+ B(smap, 20)
195
+ B(avx512ifma, 21)
196
+ B(pcommit, 22)
197
+ B(clflushopt, 23)
198
+ B(clwb, 24)
199
+ B(avx512pf, 26)
200
+ B(avx512er, 27)
201
+ B(avx512cd, 28)
202
+ B(sha, 29)
203
+ B(avx512bw, 30)
204
+ B(avx512vl, 31)
205
+ #undef B
206
+ #define C(name, bit) X(name, f7c, bit)
207
+ C(prefetchwt1, 0)
208
+ C(avx512vbmi, 1)
209
+ #undef C
210
+
211
+ #undef X
212
+
213
+ #endif /* ZSTD_COMMON_CPU_H */
@@ -0,0 +1,24 @@
1
+ /* ******************************************************************
2
+ * debug
3
+ * Part of FSE library
4
+ * Copyright (c) Yann Collet, Facebook, Inc.
5
+ *
6
+ * You can contact the author at :
7
+ * - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
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.
13
+ ****************************************************************** */
14
+
15
+
16
+ /*
17
+ * This module only hosts one global variable
18
+ * which can be used to dynamically influence the verbosity of traces,
19
+ * such as DEBUGLOG and RAWLOG
20
+ */
21
+
22
+ #include "debug.h"
23
+
24
+ int g_debuglevel = DEBUGLEVEL;
@@ -0,0 +1,107 @@
1
+ /* ******************************************************************
2
+ * debug
3
+ * Part of FSE library
4
+ * Copyright (c) Yann Collet, Facebook, Inc.
5
+ *
6
+ * You can contact the author at :
7
+ * - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
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.
13
+ ****************************************************************** */
14
+
15
+
16
+ /*
17
+ * The purpose of this header is to enable debug functions.
18
+ * They regroup assert(), DEBUGLOG() and RAWLOG() for run-time,
19
+ * and DEBUG_STATIC_ASSERT() for compile-time.
20
+ *
21
+ * By default, DEBUGLEVEL==0, which means run-time debug is disabled.
22
+ *
23
+ * Level 1 enables assert() only.
24
+ * Starting level 2, traces can be generated and pushed to stderr.
25
+ * The higher the level, the more verbose the traces.
26
+ *
27
+ * It's possible to dynamically adjust level using variable g_debug_level,
28
+ * which is only declared if DEBUGLEVEL>=2,
29
+ * and is a global variable, not multi-thread protected (use with care)
30
+ */
31
+
32
+ #ifndef DEBUG_H_12987983217
33
+ #define DEBUG_H_12987983217
34
+
35
+ #if defined (__cplusplus)
36
+ extern "C" {
37
+ #endif
38
+
39
+
40
+ /* static assert is triggered at compile time, leaving no runtime artefact.
41
+ * static assert only works with compile-time constants.
42
+ * Also, this variant can only be used inside a function. */
43
+ #define DEBUG_STATIC_ASSERT(c) (void)sizeof(char[(c) ? 1 : -1])
44
+
45
+
46
+ /* DEBUGLEVEL is expected to be defined externally,
47
+ * typically through compiler command line.
48
+ * Value must be a number. */
49
+ #ifndef DEBUGLEVEL
50
+ # define DEBUGLEVEL 0
51
+ #endif
52
+
53
+
54
+ /* recommended values for DEBUGLEVEL :
55
+ * 0 : release mode, no debug, all run-time checks disabled
56
+ * 1 : enables assert() only, no display
57
+ * 2 : reserved, for currently active debug path
58
+ * 3 : events once per object lifetime (CCtx, CDict, etc.)
59
+ * 4 : events once per frame
60
+ * 5 : events once per block
61
+ * 6 : events once per sequence (verbose)
62
+ * 7+: events at every position (*very* verbose)
63
+ *
64
+ * It's generally inconvenient to output traces > 5.
65
+ * In which case, it's possible to selectively trigger high verbosity levels
66
+ * by modifying g_debug_level.
67
+ */
68
+
69
+ #if (DEBUGLEVEL>=1)
70
+ # define ZSTD_DEPS_NEED_ASSERT
71
+ # include "zstd_deps.h"
72
+ #else
73
+ # ifndef assert /* assert may be already defined, due to prior #include <assert.h> */
74
+ # define assert(condition) ((void)0) /* disable assert (default) */
75
+ # endif
76
+ #endif
77
+
78
+ #if (DEBUGLEVEL>=2)
79
+ # define ZSTD_DEPS_NEED_IO
80
+ # include "zstd_deps.h"
81
+ extern int g_debuglevel; /* the variable is only declared,
82
+ it actually lives in debug.c,
83
+ and is shared by the whole process.
84
+ It's not thread-safe.
85
+ It's useful when enabling very verbose levels
86
+ on selective conditions (such as position in src) */
87
+
88
+ # define RAWLOG(l, ...) { \
89
+ if (l<=g_debuglevel) { \
90
+ ZSTD_DEBUG_PRINT(__VA_ARGS__); \
91
+ } }
92
+ # define DEBUGLOG(l, ...) { \
93
+ if (l<=g_debuglevel) { \
94
+ ZSTD_DEBUG_PRINT(__FILE__ ": " __VA_ARGS__); \
95
+ ZSTD_DEBUG_PRINT(" \n"); \
96
+ } }
97
+ #else
98
+ # define RAWLOG(l, ...) {} /* disabled */
99
+ # define DEBUGLOG(l, ...) {} /* disabled */
100
+ #endif
101
+
102
+
103
+ #if defined (__cplusplus)
104
+ }
105
+ #endif
106
+
107
+ #endif /* DEBUG_H_12987983217 */