zstdlib 0.1.0-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGES.md +9 -0
  3. data/Gemfile +3 -0
  4. data/README.md +96 -0
  5. data/Rakefile +29 -0
  6. data/ext/zstdlib/extconf.rb +53 -0
  7. data/ext/zstdlib/ruby/zlib-2.2/zlib.c +4659 -0
  8. data/ext/zstdlib/ruby/zlib-2.3/zlib.c +4686 -0
  9. data/ext/zstdlib/ruby/zlib-2.4/zlib.c +4843 -0
  10. data/ext/zstdlib/ruby/zlib-2.5/zlib.c +4848 -0
  11. data/ext/zstdlib/ruby/zlib-2.6/zlib.c +4890 -0
  12. data/ext/zstdlib/zlib-1.2.11/adler32.c +186 -0
  13. data/ext/zstdlib/zlib-1.2.11/compress.c +86 -0
  14. data/ext/zstdlib/zlib-1.2.11/crc32.c +442 -0
  15. data/ext/zstdlib/zlib-1.2.11/crc32.h +441 -0
  16. data/ext/zstdlib/zlib-1.2.11/deflate.c +2163 -0
  17. data/ext/zstdlib/zlib-1.2.11/deflate.h +349 -0
  18. data/ext/zstdlib/zlib-1.2.11/gzclose.c +25 -0
  19. data/ext/zstdlib/zlib-1.2.11/gzguts.h +218 -0
  20. data/ext/zstdlib/zlib-1.2.11/gzlib.c +637 -0
  21. data/ext/zstdlib/zlib-1.2.11/gzread.c +654 -0
  22. data/ext/zstdlib/zlib-1.2.11/gzwrite.c +665 -0
  23. data/ext/zstdlib/zlib-1.2.11/infback.c +640 -0
  24. data/ext/zstdlib/zlib-1.2.11/inffast.c +323 -0
  25. data/ext/zstdlib/zlib-1.2.11/inffast.h +11 -0
  26. data/ext/zstdlib/zlib-1.2.11/inffixed.h +94 -0
  27. data/ext/zstdlib/zlib-1.2.11/inflate.c +1561 -0
  28. data/ext/zstdlib/zlib-1.2.11/inflate.h +125 -0
  29. data/ext/zstdlib/zlib-1.2.11/inftrees.c +304 -0
  30. data/ext/zstdlib/zlib-1.2.11/inftrees.h +62 -0
  31. data/ext/zstdlib/zlib-1.2.11/trees.c +1203 -0
  32. data/ext/zstdlib/zlib-1.2.11/trees.h +128 -0
  33. data/ext/zstdlib/zlib-1.2.11/uncompr.c +93 -0
  34. data/ext/zstdlib/zlib-1.2.11/zconf.h +534 -0
  35. data/ext/zstdlib/zlib-1.2.11/zlib.h +1912 -0
  36. data/ext/zstdlib/zlib-1.2.11/zutil.c +325 -0
  37. data/ext/zstdlib/zlib-1.2.11/zutil.h +271 -0
  38. data/ext/zstdlib/zlib.mk +14 -0
  39. data/ext/zstdlib/zlibwrapper.mk +14 -0
  40. data/ext/zstdlib/zlibwrapper/zlibwrapper.c +14 -0
  41. data/ext/zstdlib/zstd-1.3.8/lib/common/bitstream.h +455 -0
  42. data/ext/zstdlib/zstd-1.3.8/lib/common/compiler.h +140 -0
  43. data/ext/zstdlib/zstd-1.3.8/lib/common/cpu.h +215 -0
  44. data/ext/zstdlib/zstd-1.3.8/lib/common/debug.c +44 -0
  45. data/ext/zstdlib/zstd-1.3.8/lib/common/debug.h +134 -0
  46. data/ext/zstdlib/zstd-1.3.8/lib/common/entropy_common.c +236 -0
  47. data/ext/zstdlib/zstd-1.3.8/lib/common/error_private.c +54 -0
  48. data/ext/zstdlib/zstd-1.3.8/lib/common/error_private.h +76 -0
  49. data/ext/zstdlib/zstd-1.3.8/lib/common/fse.h +708 -0
  50. data/ext/zstdlib/zstd-1.3.8/lib/common/fse_decompress.c +309 -0
  51. data/ext/zstdlib/zstd-1.3.8/lib/common/huf.h +358 -0
  52. data/ext/zstdlib/zstd-1.3.8/lib/common/mem.h +380 -0
  53. data/ext/zstdlib/zstd-1.3.8/lib/common/pool.c +340 -0
  54. data/ext/zstdlib/zstd-1.3.8/lib/common/pool.h +84 -0
  55. data/ext/zstdlib/zstd-1.3.8/lib/common/threading.c +75 -0
  56. data/ext/zstdlib/zstd-1.3.8/lib/common/threading.h +123 -0
  57. data/ext/zstdlib/zstd-1.3.8/lib/common/xxhash.c +876 -0
  58. data/ext/zstdlib/zstd-1.3.8/lib/common/xxhash.h +305 -0
  59. data/ext/zstdlib/zstd-1.3.8/lib/common/zstd_common.c +83 -0
  60. data/ext/zstdlib/zstd-1.3.8/lib/common/zstd_errors.h +93 -0
  61. data/ext/zstdlib/zstd-1.3.8/lib/common/zstd_internal.h +266 -0
  62. data/ext/zstdlib/zstd-1.3.8/lib/compress/fse_compress.c +721 -0
  63. data/ext/zstdlib/zstd-1.3.8/lib/compress/hist.c +203 -0
  64. data/ext/zstdlib/zstd-1.3.8/lib/compress/hist.h +95 -0
  65. data/ext/zstdlib/zstd-1.3.8/lib/compress/huf_compress.c +798 -0
  66. data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_compress.c +4290 -0
  67. data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_compress_internal.h +860 -0
  68. data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_double_fast.c +499 -0
  69. data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_double_fast.h +38 -0
  70. data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_fast.c +391 -0
  71. data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_fast.h +37 -0
  72. data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_lazy.c +1106 -0
  73. data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_lazy.h +67 -0
  74. data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_ldm.c +597 -0
  75. data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_ldm.h +105 -0
  76. data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_opt.c +1217 -0
  77. data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_opt.h +56 -0
  78. data/ext/zstdlib/zstd-1.3.8/lib/compress/zstdmt_compress.c +2107 -0
  79. data/ext/zstdlib/zstd-1.3.8/lib/compress/zstdmt_compress.h +174 -0
  80. data/ext/zstdlib/zstd-1.3.8/lib/decompress/huf_decompress.c +1232 -0
  81. data/ext/zstdlib/zstd-1.3.8/lib/decompress/zstd_ddict.c +240 -0
  82. data/ext/zstdlib/zstd-1.3.8/lib/decompress/zstd_ddict.h +44 -0
  83. data/ext/zstdlib/zstd-1.3.8/lib/decompress/zstd_decompress.c +1672 -0
  84. data/ext/zstdlib/zstd-1.3.8/lib/decompress/zstd_decompress_block.c +1307 -0
  85. data/ext/zstdlib/zstd-1.3.8/lib/decompress/zstd_decompress_block.h +59 -0
  86. data/ext/zstdlib/zstd-1.3.8/lib/decompress/zstd_decompress_internal.h +168 -0
  87. data/ext/zstdlib/zstd-1.3.8/lib/zstd.h +1766 -0
  88. data/ext/zstdlib/zstd-1.3.8/zlibWrapper/gzclose.c +28 -0
  89. data/ext/zstdlib/zstd-1.3.8/zlibWrapper/gzcompatibility.h +68 -0
  90. data/ext/zstdlib/zstd-1.3.8/zlibWrapper/gzguts.h +227 -0
  91. data/ext/zstdlib/zstd-1.3.8/zlibWrapper/gzlib.c +640 -0
  92. data/ext/zstdlib/zstd-1.3.8/zlibWrapper/gzread.c +670 -0
  93. data/ext/zstdlib/zstd-1.3.8/zlibWrapper/gzwrite.c +671 -0
  94. data/ext/zstdlib/zstd-1.3.8/zlibWrapper/zstd_zlibwrapper.c +1105 -0
  95. data/ext/zstdlib/zstd-1.3.8/zlibWrapper/zstd_zlibwrapper.h +88 -0
  96. data/ext/zstdlib/zstd.mk +14 -0
  97. data/lib/2.2/zstdlib.so +0 -0
  98. data/lib/2.3/zstdlib.so +0 -0
  99. data/lib/2.4/zstdlib.so +0 -0
  100. data/lib/2.5/zstdlib.so +0 -0
  101. data/lib/2.6/zstdlib.so +0 -0
  102. data/lib/zstdlib.rb +6 -0
  103. data/test/zstdlib_test.rb +21 -0
  104. metadata +205 -0
@@ -0,0 +1,140 @@
1
+ /*
2
+ * Copyright (c) 2016-present, 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
+ /*-*******************************************************
15
+ * Compiler specifics
16
+ *********************************************************/
17
+ /* force inlining */
18
+
19
+ #if !defined(ZSTD_NO_INLINE)
20
+ #if defined (__GNUC__) || defined(__cplusplus) || defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */
21
+ # define INLINE_KEYWORD inline
22
+ #else
23
+ # define INLINE_KEYWORD
24
+ #endif
25
+
26
+ #if defined(__GNUC__)
27
+ # define FORCE_INLINE_ATTR __attribute__((always_inline))
28
+ #elif defined(_MSC_VER)
29
+ # define FORCE_INLINE_ATTR __forceinline
30
+ #else
31
+ # define FORCE_INLINE_ATTR
32
+ #endif
33
+
34
+ #else
35
+
36
+ #define INLINE_KEYWORD
37
+ #define FORCE_INLINE_ATTR
38
+
39
+ #endif
40
+
41
+ /**
42
+ * FORCE_INLINE_TEMPLATE is used to define C "templates", which take constant
43
+ * parameters. They must be inlined for the compiler to elimininate the constant
44
+ * branches.
45
+ */
46
+ #define FORCE_INLINE_TEMPLATE static INLINE_KEYWORD FORCE_INLINE_ATTR
47
+ /**
48
+ * HINT_INLINE is used to help the compiler generate better code. It is *not*
49
+ * used for "templates", so it can be tweaked based on the compilers
50
+ * performance.
51
+ *
52
+ * gcc-4.8 and gcc-4.9 have been shown to benefit from leaving off the
53
+ * always_inline attribute.
54
+ *
55
+ * clang up to 5.0.0 (trunk) benefit tremendously from the always_inline
56
+ * attribute.
57
+ */
58
+ #if !defined(__clang__) && defined(__GNUC__) && __GNUC__ >= 4 && __GNUC_MINOR__ >= 8 && __GNUC__ < 5
59
+ # define HINT_INLINE static INLINE_KEYWORD
60
+ #else
61
+ # define HINT_INLINE static INLINE_KEYWORD FORCE_INLINE_ATTR
62
+ #endif
63
+
64
+ /* force no inlining */
65
+ #ifdef _MSC_VER
66
+ # define FORCE_NOINLINE static __declspec(noinline)
67
+ #else
68
+ # ifdef __GNUC__
69
+ # define FORCE_NOINLINE static __attribute__((__noinline__))
70
+ # else
71
+ # define FORCE_NOINLINE static
72
+ # endif
73
+ #endif
74
+
75
+ /* target attribute */
76
+ #ifndef __has_attribute
77
+ #define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */
78
+ #endif
79
+ #if defined(__GNUC__)
80
+ # define TARGET_ATTRIBUTE(target) __attribute__((__target__(target)))
81
+ #else
82
+ # define TARGET_ATTRIBUTE(target)
83
+ #endif
84
+
85
+ /* Enable runtime BMI2 dispatch based on the CPU.
86
+ * Enabled for clang & gcc >=4.8 on x86 when BMI2 isn't enabled by default.
87
+ */
88
+ #ifndef DYNAMIC_BMI2
89
+ #if ((defined(__clang__) && __has_attribute(__target__)) \
90
+ || (defined(__GNUC__) \
91
+ && (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)))) \
92
+ && (defined(__x86_64__) || defined(_M_X86)) \
93
+ && !defined(__BMI2__)
94
+ # define DYNAMIC_BMI2 1
95
+ #else
96
+ # define DYNAMIC_BMI2 0
97
+ #endif
98
+ #endif
99
+
100
+ /* prefetch
101
+ * can be disabled, by declaring NO_PREFETCH build macro */
102
+ #if defined(NO_PREFETCH)
103
+ # define PREFETCH_L1(ptr) (void)(ptr) /* disabled */
104
+ # define PREFETCH_L2(ptr) (void)(ptr) /* disabled */
105
+ #else
106
+ # if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_I86)) /* _mm_prefetch() is not defined outside of x86/x64 */
107
+ # include <mmintrin.h> /* https://msdn.microsoft.com/fr-fr/library/84szxsww(v=vs.90).aspx */
108
+ # define PREFETCH_L1(ptr) _mm_prefetch((const char*)(ptr), _MM_HINT_T0)
109
+ # define PREFETCH_L2(ptr) _mm_prefetch((const char*)(ptr), _MM_HINT_T1)
110
+ # elif defined(__GNUC__) && ( (__GNUC__ >= 4) || ( (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1) ) )
111
+ # define PREFETCH_L1(ptr) __builtin_prefetch((ptr), 0 /* rw==read */, 3 /* locality */)
112
+ # define PREFETCH_L2(ptr) __builtin_prefetch((ptr), 0 /* rw==read */, 2 /* locality */)
113
+ # else
114
+ # define PREFETCH_L1(ptr) (void)(ptr) /* disabled */
115
+ # define PREFETCH_L2(ptr) (void)(ptr) /* disabled */
116
+ # endif
117
+ #endif /* NO_PREFETCH */
118
+
119
+ #define CACHELINE_SIZE 64
120
+
121
+ #define PREFETCH_AREA(p, s) { \
122
+ const char* const _ptr = (const char*)(p); \
123
+ size_t const _size = (size_t)(s); \
124
+ size_t _pos; \
125
+ for (_pos=0; _pos<_size; _pos+=CACHELINE_SIZE) { \
126
+ PREFETCH_L2(_ptr + _pos); \
127
+ } \
128
+ }
129
+
130
+ /* disable warnings */
131
+ #ifdef _MSC_VER /* Visual Studio */
132
+ # include <intrin.h> /* For Visual 2005 */
133
+ # pragma warning(disable : 4100) /* disable: C4100: unreferenced formal parameter */
134
+ # pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */
135
+ # pragma warning(disable : 4204) /* disable: C4204: non-constant aggregate initializer */
136
+ # pragma warning(disable : 4214) /* disable: C4214: non-int bitfields */
137
+ # pragma warning(disable : 4324) /* disable: C4324: padded structure */
138
+ #endif
139
+
140
+ #endif /* ZSTD_COMPILER_H */
@@ -0,0 +1,215 @@
1
+ /*
2
+ * Copyright (c) 2018-present, 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 <string.h>
20
+
21
+ #include "mem.h"
22
+
23
+ #ifdef _MSC_VER
24
+ #include <intrin.h>
25
+ #endif
26
+
27
+ typedef struct {
28
+ U32 f1c;
29
+ U32 f1d;
30
+ U32 f7b;
31
+ U32 f7c;
32
+ } ZSTD_cpuid_t;
33
+
34
+ MEM_STATIC ZSTD_cpuid_t ZSTD_cpuid(void) {
35
+ U32 f1c = 0;
36
+ U32 f1d = 0;
37
+ U32 f7b = 0;
38
+ U32 f7c = 0;
39
+ #if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86))
40
+ int reg[4];
41
+ __cpuid((int*)reg, 0);
42
+ {
43
+ int const n = reg[0];
44
+ if (n >= 1) {
45
+ __cpuid((int*)reg, 1);
46
+ f1c = (U32)reg[2];
47
+ f1d = (U32)reg[3];
48
+ }
49
+ if (n >= 7) {
50
+ __cpuidex((int*)reg, 7, 0);
51
+ f7b = (U32)reg[1];
52
+ f7c = (U32)reg[2];
53
+ }
54
+ }
55
+ #elif defined(__i386__) && defined(__PIC__) && !defined(__clang__) && defined(__GNUC__)
56
+ /* The following block like the normal cpuid branch below, but gcc
57
+ * reserves ebx for use of its pic register so we must specially
58
+ * handle the save and restore to avoid clobbering the register
59
+ */
60
+ U32 n;
61
+ __asm__(
62
+ "pushl %%ebx\n\t"
63
+ "cpuid\n\t"
64
+ "popl %%ebx\n\t"
65
+ : "=a"(n)
66
+ : "a"(0)
67
+ : "ecx", "edx");
68
+ if (n >= 1) {
69
+ U32 f1a;
70
+ __asm__(
71
+ "pushl %%ebx\n\t"
72
+ "cpuid\n\t"
73
+ "popl %%ebx\n\t"
74
+ : "=a"(f1a), "=c"(f1c), "=d"(f1d)
75
+ : "a"(1));
76
+ }
77
+ if (n >= 7) {
78
+ __asm__(
79
+ "pushl %%ebx\n\t"
80
+ "cpuid\n\t"
81
+ "movl %%ebx, %%eax\n\t"
82
+ "popl %%ebx"
83
+ : "=a"(f7b), "=c"(f7c)
84
+ : "a"(7), "c"(0)
85
+ : "edx");
86
+ }
87
+ #elif defined(__x86_64__) || defined(_M_X64) || defined(__i386__)
88
+ U32 n;
89
+ __asm__("cpuid" : "=a"(n) : "a"(0) : "ebx", "ecx", "edx");
90
+ if (n >= 1) {
91
+ U32 f1a;
92
+ __asm__("cpuid" : "=a"(f1a), "=c"(f1c), "=d"(f1d) : "a"(1) : "ebx");
93
+ }
94
+ if (n >= 7) {
95
+ U32 f7a;
96
+ __asm__("cpuid"
97
+ : "=a"(f7a), "=b"(f7b), "=c"(f7c)
98
+ : "a"(7), "c"(0)
99
+ : "edx");
100
+ }
101
+ #endif
102
+ {
103
+ ZSTD_cpuid_t cpuid;
104
+ cpuid.f1c = f1c;
105
+ cpuid.f1d = f1d;
106
+ cpuid.f7b = f7b;
107
+ cpuid.f7c = f7c;
108
+ return cpuid;
109
+ }
110
+ }
111
+
112
+ #define X(name, r, bit) \
113
+ MEM_STATIC int ZSTD_cpuid_##name(ZSTD_cpuid_t const cpuid) { \
114
+ return ((cpuid.r) & (1U << bit)) != 0; \
115
+ }
116
+
117
+ /* cpuid(1): Processor Info and Feature Bits. */
118
+ #define C(name, bit) X(name, f1c, bit)
119
+ C(sse3, 0)
120
+ C(pclmuldq, 1)
121
+ C(dtes64, 2)
122
+ C(monitor, 3)
123
+ C(dscpl, 4)
124
+ C(vmx, 5)
125
+ C(smx, 6)
126
+ C(eist, 7)
127
+ C(tm2, 8)
128
+ C(ssse3, 9)
129
+ C(cnxtid, 10)
130
+ C(fma, 12)
131
+ C(cx16, 13)
132
+ C(xtpr, 14)
133
+ C(pdcm, 15)
134
+ C(pcid, 17)
135
+ C(dca, 18)
136
+ C(sse41, 19)
137
+ C(sse42, 20)
138
+ C(x2apic, 21)
139
+ C(movbe, 22)
140
+ C(popcnt, 23)
141
+ C(tscdeadline, 24)
142
+ C(aes, 25)
143
+ C(xsave, 26)
144
+ C(osxsave, 27)
145
+ C(avx, 28)
146
+ C(f16c, 29)
147
+ C(rdrand, 30)
148
+ #undef C
149
+ #define D(name, bit) X(name, f1d, bit)
150
+ D(fpu, 0)
151
+ D(vme, 1)
152
+ D(de, 2)
153
+ D(pse, 3)
154
+ D(tsc, 4)
155
+ D(msr, 5)
156
+ D(pae, 6)
157
+ D(mce, 7)
158
+ D(cx8, 8)
159
+ D(apic, 9)
160
+ D(sep, 11)
161
+ D(mtrr, 12)
162
+ D(pge, 13)
163
+ D(mca, 14)
164
+ D(cmov, 15)
165
+ D(pat, 16)
166
+ D(pse36, 17)
167
+ D(psn, 18)
168
+ D(clfsh, 19)
169
+ D(ds, 21)
170
+ D(acpi, 22)
171
+ D(mmx, 23)
172
+ D(fxsr, 24)
173
+ D(sse, 25)
174
+ D(sse2, 26)
175
+ D(ss, 27)
176
+ D(htt, 28)
177
+ D(tm, 29)
178
+ D(pbe, 31)
179
+ #undef D
180
+
181
+ /* cpuid(7): Extended Features. */
182
+ #define B(name, bit) X(name, f7b, bit)
183
+ B(bmi1, 3)
184
+ B(hle, 4)
185
+ B(avx2, 5)
186
+ B(smep, 7)
187
+ B(bmi2, 8)
188
+ B(erms, 9)
189
+ B(invpcid, 10)
190
+ B(rtm, 11)
191
+ B(mpx, 14)
192
+ B(avx512f, 16)
193
+ B(avx512dq, 17)
194
+ B(rdseed, 18)
195
+ B(adx, 19)
196
+ B(smap, 20)
197
+ B(avx512ifma, 21)
198
+ B(pcommit, 22)
199
+ B(clflushopt, 23)
200
+ B(clwb, 24)
201
+ B(avx512pf, 26)
202
+ B(avx512er, 27)
203
+ B(avx512cd, 28)
204
+ B(sha, 29)
205
+ B(avx512bw, 30)
206
+ B(avx512vl, 31)
207
+ #undef B
208
+ #define C(name, bit) X(name, f7c, bit)
209
+ C(prefetchwt1, 0)
210
+ C(avx512vbmi, 1)
211
+ #undef C
212
+
213
+ #undef X
214
+
215
+ #endif /* ZSTD_COMMON_CPU_H */
@@ -0,0 +1,44 @@
1
+ /* ******************************************************************
2
+ debug
3
+ Part of FSE library
4
+ Copyright (C) 2013-present, 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
+ - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
33
+ ****************************************************************** */
34
+
35
+
36
+ /*
37
+ * This module only hosts one global variable
38
+ * which can be used to dynamically influence the verbosity of traces,
39
+ * such as DEBUGLOG and RAWLOG
40
+ */
41
+
42
+ #include "debug.h"
43
+
44
+ int g_debuglevel = DEBUGLEVEL;
@@ -0,0 +1,134 @@
1
+ /* ******************************************************************
2
+ debug
3
+ Part of FSE library
4
+ Copyright (C) 2013-present, 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
+ - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
33
+ ****************************************************************** */
34
+
35
+
36
+ /*
37
+ * The purpose of this header is to enable debug functions.
38
+ * They regroup assert(), DEBUGLOG() and RAWLOG() for run-time,
39
+ * and DEBUG_STATIC_ASSERT() for compile-time.
40
+ *
41
+ * By default, DEBUGLEVEL==0, which means run-time debug is disabled.
42
+ *
43
+ * Level 1 enables assert() only.
44
+ * Starting level 2, traces can be generated and pushed to stderr.
45
+ * The higher the level, the more verbose the traces.
46
+ *
47
+ * It's possible to dynamically adjust level using variable g_debug_level,
48
+ * which is only declared if DEBUGLEVEL>=2,
49
+ * and is a global variable, not multi-thread protected (use with care)
50
+ */
51
+
52
+ #ifndef DEBUG_H_12987983217
53
+ #define DEBUG_H_12987983217
54
+
55
+ #if defined (__cplusplus)
56
+ extern "C" {
57
+ #endif
58
+
59
+
60
+ /* static assert is triggered at compile time, leaving no runtime artefact.
61
+ * static assert only works with compile-time constants.
62
+ * Also, this variant can only be used inside a function. */
63
+ #define DEBUG_STATIC_ASSERT(c) (void)sizeof(char[(c) ? 1 : -1])
64
+
65
+
66
+ /* DEBUGLEVEL is expected to be defined externally,
67
+ * typically through compiler command line.
68
+ * Value must be a number. */
69
+ #ifndef DEBUGLEVEL
70
+ # define DEBUGLEVEL 0
71
+ #endif
72
+
73
+
74
+ /* DEBUGFILE can be defined externally,
75
+ * typically through compiler command line.
76
+ * note : currently useless.
77
+ * Value must be stderr or stdout */
78
+ #ifndef DEBUGFILE
79
+ # define DEBUGFILE stderr
80
+ #endif
81
+
82
+
83
+ /* recommended values for DEBUGLEVEL :
84
+ * 0 : release mode, no debug, all run-time checks disabled
85
+ * 1 : enables assert() only, no display
86
+ * 2 : reserved, for currently active debug path
87
+ * 3 : events once per object lifetime (CCtx, CDict, etc.)
88
+ * 4 : events once per frame
89
+ * 5 : events once per block
90
+ * 6 : events once per sequence (verbose)
91
+ * 7+: events at every position (*very* verbose)
92
+ *
93
+ * It's generally inconvenient to output traces > 5.
94
+ * In which case, it's possible to selectively trigger high verbosity levels
95
+ * by modifying g_debug_level.
96
+ */
97
+
98
+ #if (DEBUGLEVEL>=1)
99
+ # include <assert.h>
100
+ #else
101
+ # ifndef assert /* assert may be already defined, due to prior #include <assert.h> */
102
+ # define assert(condition) ((void)0) /* disable assert (default) */
103
+ # endif
104
+ #endif
105
+
106
+ #if (DEBUGLEVEL>=2)
107
+ # include <stdio.h>
108
+ extern int g_debuglevel; /* the variable is only declared,
109
+ it actually lives in debug.c,
110
+ and is shared by the whole process.
111
+ It's not thread-safe.
112
+ It's useful when enabling very verbose levels
113
+ on selective conditions (such as position in src) */
114
+
115
+ # define RAWLOG(l, ...) { \
116
+ if (l<=g_debuglevel) { \
117
+ fprintf(stderr, __VA_ARGS__); \
118
+ } }
119
+ # define DEBUGLOG(l, ...) { \
120
+ if (l<=g_debuglevel) { \
121
+ fprintf(stderr, __FILE__ ": " __VA_ARGS__); \
122
+ fprintf(stderr, " \n"); \
123
+ } }
124
+ #else
125
+ # define RAWLOG(l, ...) {} /* disabled */
126
+ # define DEBUGLOG(l, ...) {} /* disabled */
127
+ #endif
128
+
129
+
130
+ #if defined (__cplusplus)
131
+ }
132
+ #endif
133
+
134
+ #endif /* DEBUG_H_12987983217 */