deflate-ruby 0.1.0

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 (100) hide show
  1. checksums.yaml +7 -0
  2. data/CLAUDE.md +138 -0
  3. data/LICENSE.txt +21 -0
  4. data/README.md +117 -0
  5. data/ext/deflate_ruby/deflate_ruby.c +301 -0
  6. data/ext/deflate_ruby/extconf.rb +34 -0
  7. data/ext/deflate_ruby/libdeflate/CMakeLists.txt +270 -0
  8. data/ext/deflate_ruby/libdeflate/COPYING +22 -0
  9. data/ext/deflate_ruby/libdeflate/NEWS.md +494 -0
  10. data/ext/deflate_ruby/libdeflate/README.md +228 -0
  11. data/ext/deflate_ruby/libdeflate/common_defs.h +747 -0
  12. data/ext/deflate_ruby/libdeflate/lib/adler32.c +162 -0
  13. data/ext/deflate_ruby/libdeflate/lib/arm/adler32_impl.h +358 -0
  14. data/ext/deflate_ruby/libdeflate/lib/arm/cpu_features.c +230 -0
  15. data/ext/deflate_ruby/libdeflate/lib/arm/cpu_features.h +214 -0
  16. data/ext/deflate_ruby/libdeflate/lib/arm/crc32_impl.h +600 -0
  17. data/ext/deflate_ruby/libdeflate/lib/arm/crc32_pmull_helpers.h +156 -0
  18. data/ext/deflate_ruby/libdeflate/lib/arm/crc32_pmull_wide.h +226 -0
  19. data/ext/deflate_ruby/libdeflate/lib/arm/matchfinder_impl.h +78 -0
  20. data/ext/deflate_ruby/libdeflate/lib/bt_matchfinder.h +342 -0
  21. data/ext/deflate_ruby/libdeflate/lib/cpu_features_common.h +93 -0
  22. data/ext/deflate_ruby/libdeflate/lib/crc32.c +262 -0
  23. data/ext/deflate_ruby/libdeflate/lib/crc32_multipliers.h +377 -0
  24. data/ext/deflate_ruby/libdeflate/lib/crc32_tables.h +587 -0
  25. data/ext/deflate_ruby/libdeflate/lib/decompress_template.h +777 -0
  26. data/ext/deflate_ruby/libdeflate/lib/deflate_compress.c +4129 -0
  27. data/ext/deflate_ruby/libdeflate/lib/deflate_compress.h +15 -0
  28. data/ext/deflate_ruby/libdeflate/lib/deflate_constants.h +56 -0
  29. data/ext/deflate_ruby/libdeflate/lib/deflate_decompress.c +1208 -0
  30. data/ext/deflate_ruby/libdeflate/lib/gzip_compress.c +90 -0
  31. data/ext/deflate_ruby/libdeflate/lib/gzip_constants.h +45 -0
  32. data/ext/deflate_ruby/libdeflate/lib/gzip_decompress.c +144 -0
  33. data/ext/deflate_ruby/libdeflate/lib/hc_matchfinder.h +401 -0
  34. data/ext/deflate_ruby/libdeflate/lib/ht_matchfinder.h +234 -0
  35. data/ext/deflate_ruby/libdeflate/lib/lib_common.h +106 -0
  36. data/ext/deflate_ruby/libdeflate/lib/matchfinder_common.h +224 -0
  37. data/ext/deflate_ruby/libdeflate/lib/riscv/matchfinder_impl.h +97 -0
  38. data/ext/deflate_ruby/libdeflate/lib/utils.c +141 -0
  39. data/ext/deflate_ruby/libdeflate/lib/x86/adler32_impl.h +134 -0
  40. data/ext/deflate_ruby/libdeflate/lib/x86/adler32_template.h +518 -0
  41. data/ext/deflate_ruby/libdeflate/lib/x86/cpu_features.c +183 -0
  42. data/ext/deflate_ruby/libdeflate/lib/x86/cpu_features.h +169 -0
  43. data/ext/deflate_ruby/libdeflate/lib/x86/crc32_impl.h +160 -0
  44. data/ext/deflate_ruby/libdeflate/lib/x86/crc32_pclmul_template.h +495 -0
  45. data/ext/deflate_ruby/libdeflate/lib/x86/decompress_impl.h +57 -0
  46. data/ext/deflate_ruby/libdeflate/lib/x86/matchfinder_impl.h +122 -0
  47. data/ext/deflate_ruby/libdeflate/lib/zlib_compress.c +82 -0
  48. data/ext/deflate_ruby/libdeflate/lib/zlib_constants.h +21 -0
  49. data/ext/deflate_ruby/libdeflate/lib/zlib_decompress.c +104 -0
  50. data/ext/deflate_ruby/libdeflate/libdeflate-config.cmake.in +3 -0
  51. data/ext/deflate_ruby/libdeflate/libdeflate.h +411 -0
  52. data/ext/deflate_ruby/libdeflate/libdeflate.pc.in +18 -0
  53. data/ext/deflate_ruby/libdeflate/programs/CMakeLists.txt +105 -0
  54. data/ext/deflate_ruby/libdeflate/programs/benchmark.c +696 -0
  55. data/ext/deflate_ruby/libdeflate/programs/checksum.c +218 -0
  56. data/ext/deflate_ruby/libdeflate/programs/config.h.in +19 -0
  57. data/ext/deflate_ruby/libdeflate/programs/gzip.c +688 -0
  58. data/ext/deflate_ruby/libdeflate/programs/prog_util.c +521 -0
  59. data/ext/deflate_ruby/libdeflate/programs/prog_util.h +225 -0
  60. data/ext/deflate_ruby/libdeflate/programs/test_checksums.c +200 -0
  61. data/ext/deflate_ruby/libdeflate/programs/test_custom_malloc.c +155 -0
  62. data/ext/deflate_ruby/libdeflate/programs/test_incomplete_codes.c +385 -0
  63. data/ext/deflate_ruby/libdeflate/programs/test_invalid_streams.c +130 -0
  64. data/ext/deflate_ruby/libdeflate/programs/test_litrunlen_overflow.c +72 -0
  65. data/ext/deflate_ruby/libdeflate/programs/test_overread.c +95 -0
  66. data/ext/deflate_ruby/libdeflate/programs/test_slow_decompression.c +472 -0
  67. data/ext/deflate_ruby/libdeflate/programs/test_trailing_bytes.c +151 -0
  68. data/ext/deflate_ruby/libdeflate/programs/test_util.c +237 -0
  69. data/ext/deflate_ruby/libdeflate/programs/test_util.h +61 -0
  70. data/ext/deflate_ruby/libdeflate/programs/tgetopt.c +118 -0
  71. data/ext/deflate_ruby/libdeflate/scripts/android_build.sh +118 -0
  72. data/ext/deflate_ruby/libdeflate/scripts/android_tests.sh +69 -0
  73. data/ext/deflate_ruby/libdeflate/scripts/benchmark.sh +10 -0
  74. data/ext/deflate_ruby/libdeflate/scripts/checksum.sh +10 -0
  75. data/ext/deflate_ruby/libdeflate/scripts/checksum_benchmarks.sh +253 -0
  76. data/ext/deflate_ruby/libdeflate/scripts/cmake-helper.sh +17 -0
  77. data/ext/deflate_ruby/libdeflate/scripts/deflate_benchmarks.sh +119 -0
  78. data/ext/deflate_ruby/libdeflate/scripts/exec_tests.sh +38 -0
  79. data/ext/deflate_ruby/libdeflate/scripts/gen-release-archives.sh +37 -0
  80. data/ext/deflate_ruby/libdeflate/scripts/gen_bitreverse_tab.py +19 -0
  81. data/ext/deflate_ruby/libdeflate/scripts/gen_crc32_multipliers.c +199 -0
  82. data/ext/deflate_ruby/libdeflate/scripts/gen_crc32_tables.c +105 -0
  83. data/ext/deflate_ruby/libdeflate/scripts/gen_default_litlen_costs.py +44 -0
  84. data/ext/deflate_ruby/libdeflate/scripts/gen_offset_slot_map.py +29 -0
  85. data/ext/deflate_ruby/libdeflate/scripts/gzip_tests.sh +523 -0
  86. data/ext/deflate_ruby/libdeflate/scripts/libFuzzer/deflate_compress/corpus/0 +0 -0
  87. data/ext/deflate_ruby/libdeflate/scripts/libFuzzer/deflate_compress/fuzz.c +95 -0
  88. data/ext/deflate_ruby/libdeflate/scripts/libFuzzer/deflate_decompress/corpus/0 +3 -0
  89. data/ext/deflate_ruby/libdeflate/scripts/libFuzzer/deflate_decompress/fuzz.c +62 -0
  90. data/ext/deflate_ruby/libdeflate/scripts/libFuzzer/fuzz.sh +108 -0
  91. data/ext/deflate_ruby/libdeflate/scripts/libFuzzer/gzip_decompress/corpus/0 +0 -0
  92. data/ext/deflate_ruby/libdeflate/scripts/libFuzzer/gzip_decompress/fuzz.c +19 -0
  93. data/ext/deflate_ruby/libdeflate/scripts/libFuzzer/zlib_decompress/corpus/0 +3 -0
  94. data/ext/deflate_ruby/libdeflate/scripts/libFuzzer/zlib_decompress/fuzz.c +19 -0
  95. data/ext/deflate_ruby/libdeflate/scripts/run_tests.sh +416 -0
  96. data/ext/deflate_ruby/libdeflate/scripts/toolchain-i686-w64-mingw32.cmake +8 -0
  97. data/ext/deflate_ruby/libdeflate/scripts/toolchain-x86_64-w64-mingw32.cmake +8 -0
  98. data/lib/deflate_ruby/version.rb +5 -0
  99. data/lib/deflate_ruby.rb +71 -0
  100. metadata +191 -0
@@ -0,0 +1,141 @@
1
+ /*
2
+ * utils.c - utility functions for libdeflate
3
+ *
4
+ * Copyright 2016 Eric Biggers
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person
7
+ * obtaining a copy of this software and associated documentation
8
+ * files (the "Software"), to deal in the Software without
9
+ * restriction, including without limitation the rights to use,
10
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the
12
+ * Software is furnished to do so, subject to the following
13
+ * conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be
16
+ * included in all copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25
+ * OTHER DEALINGS IN THE SOFTWARE.
26
+ */
27
+
28
+ #include "lib_common.h"
29
+
30
+ #ifdef FREESTANDING
31
+ # define malloc NULL
32
+ # define free NULL
33
+ #else
34
+ # include <stdlib.h>
35
+ #endif
36
+
37
+ malloc_func_t libdeflate_default_malloc_func = malloc;
38
+ free_func_t libdeflate_default_free_func = free;
39
+
40
+ void *
41
+ libdeflate_aligned_malloc(malloc_func_t malloc_func,
42
+ size_t alignment, size_t size)
43
+ {
44
+ void *ptr = (*malloc_func)(sizeof(void *) + alignment - 1 + size);
45
+
46
+ if (ptr) {
47
+ void *orig_ptr = ptr;
48
+
49
+ ptr = (void *)ALIGN((uintptr_t)ptr + sizeof(void *), alignment);
50
+ ((void **)ptr)[-1] = orig_ptr;
51
+ }
52
+ return ptr;
53
+ }
54
+
55
+ void
56
+ libdeflate_aligned_free(free_func_t free_func, void *ptr)
57
+ {
58
+ (*free_func)(((void **)ptr)[-1]);
59
+ }
60
+
61
+ LIBDEFLATEAPI void
62
+ libdeflate_set_memory_allocator(malloc_func_t malloc_func,
63
+ free_func_t free_func)
64
+ {
65
+ libdeflate_default_malloc_func = malloc_func;
66
+ libdeflate_default_free_func = free_func;
67
+ }
68
+
69
+ /*
70
+ * Implementations of libc functions for freestanding library builds.
71
+ * Normal library builds don't use these. Not optimized yet; usually the
72
+ * compiler expands these functions and doesn't actually call them anyway.
73
+ */
74
+ #ifdef FREESTANDING
75
+ #undef memset
76
+ void * __attribute__((weak))
77
+ memset(void *s, int c, size_t n)
78
+ {
79
+ u8 *p = s;
80
+ size_t i;
81
+
82
+ for (i = 0; i < n; i++)
83
+ p[i] = c;
84
+ return s;
85
+ }
86
+
87
+ #undef memcpy
88
+ void * __attribute__((weak))
89
+ memcpy(void *dest, const void *src, size_t n)
90
+ {
91
+ u8 *d = dest;
92
+ const u8 *s = src;
93
+ size_t i;
94
+
95
+ for (i = 0; i < n; i++)
96
+ d[i] = s[i];
97
+ return dest;
98
+ }
99
+
100
+ #undef memmove
101
+ void * __attribute__((weak))
102
+ memmove(void *dest, const void *src, size_t n)
103
+ {
104
+ u8 *d = dest;
105
+ const u8 *s = src;
106
+ size_t i;
107
+
108
+ if (d <= s)
109
+ return memcpy(d, s, n);
110
+
111
+ for (i = n; i > 0; i--)
112
+ d[i - 1] = s[i - 1];
113
+ return dest;
114
+ }
115
+
116
+ #undef memcmp
117
+ int __attribute__((weak))
118
+ memcmp(const void *s1, const void *s2, size_t n)
119
+ {
120
+ const u8 *p1 = s1;
121
+ const u8 *p2 = s2;
122
+ size_t i;
123
+
124
+ for (i = 0; i < n; i++) {
125
+ if (p1[i] != p2[i])
126
+ return (int)p1[i] - (int)p2[i];
127
+ }
128
+ return 0;
129
+ }
130
+ #endif /* FREESTANDING */
131
+
132
+ #ifdef LIBDEFLATE_ENABLE_ASSERTIONS
133
+ #include <stdio.h>
134
+ #include <stdlib.h>
135
+ NORETURN void
136
+ libdeflate_assertion_failed(const char *expr, const char *file, int line)
137
+ {
138
+ fprintf(stderr, "Assertion failed: %s at %s:%d\n", expr, file, line);
139
+ abort();
140
+ }
141
+ #endif /* LIBDEFLATE_ENABLE_ASSERTIONS */
@@ -0,0 +1,134 @@
1
+ /*
2
+ * x86/adler32_impl.h - x86 implementations of Adler-32 checksum algorithm
3
+ *
4
+ * Copyright 2016 Eric Biggers
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person
7
+ * obtaining a copy of this software and associated documentation
8
+ * files (the "Software"), to deal in the Software without
9
+ * restriction, including without limitation the rights to use,
10
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the
12
+ * Software is furnished to do so, subject to the following
13
+ * conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be
16
+ * included in all copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25
+ * OTHER DEALINGS IN THE SOFTWARE.
26
+ */
27
+
28
+ #ifndef LIB_X86_ADLER32_IMPL_H
29
+ #define LIB_X86_ADLER32_IMPL_H
30
+
31
+ #include "cpu_features.h"
32
+
33
+ /* SSE2 and AVX2 implementations. Used on older CPUs. */
34
+ #if defined(__GNUC__) || defined(__clang__) || defined(_MSC_VER)
35
+ # define adler32_x86_sse2 adler32_x86_sse2
36
+ # define SUFFIX _sse2
37
+ # define ATTRIBUTES _target_attribute("sse2")
38
+ # define VL 16
39
+ # define USE_VNNI 0
40
+ # define USE_AVX512 0
41
+ # include "adler32_template.h"
42
+
43
+ # define adler32_x86_avx2 adler32_x86_avx2
44
+ # define SUFFIX _avx2
45
+ # define ATTRIBUTES _target_attribute("avx2")
46
+ # define VL 32
47
+ # define USE_VNNI 0
48
+ # define USE_AVX512 0
49
+ # include "adler32_template.h"
50
+ #endif
51
+
52
+ /*
53
+ * AVX-VNNI implementation. This is used on CPUs that have AVX2 and AVX-VNNI
54
+ * but don't have AVX-512, for example Intel Alder Lake.
55
+ *
56
+ * Unusually for a new CPU feature, gcc added support for the AVX-VNNI
57
+ * intrinsics (in gcc 11.1) slightly before binutils added support for
58
+ * assembling AVX-VNNI instructions (in binutils 2.36). Distros can reasonably
59
+ * have gcc 11 with binutils 2.35. Because of this issue, we check for gcc 12
60
+ * instead of gcc 11. (libdeflate supports direct compilation without a
61
+ * configure step, so checking the binutils version is not always an option.)
62
+ */
63
+ #if GCC_PREREQ(12, 1) || CLANG_PREREQ(12, 0, 13000000) || MSVC_PREREQ(1930)
64
+ # define adler32_x86_avx2_vnni adler32_x86_avx2_vnni
65
+ # define SUFFIX _avx2_vnni
66
+ # define ATTRIBUTES _target_attribute("avx2,avxvnni")
67
+ # define VL 32
68
+ # define USE_VNNI 1
69
+ # define USE_AVX512 0
70
+ # include "adler32_template.h"
71
+ #endif
72
+
73
+ #if GCC_PREREQ(8, 1) || CLANG_PREREQ(6, 0, 10000000) || MSVC_PREREQ(1920)
74
+ /*
75
+ * AVX512VNNI implementation using 256-bit vectors. This is very similar to the
76
+ * AVX-VNNI implementation but takes advantage of masking and more registers.
77
+ * This is used on CPUs that support AVX-512 but where using 512-bit vectors
78
+ * causes downclocking. This should also be the optimal implementation on CPUs
79
+ * that support AVX10/256 but not AVX10/512.
80
+ */
81
+ # define adler32_x86_avx512_vl256_vnni adler32_x86_avx512_vl256_vnni
82
+ # define SUFFIX _avx512_vl256_vnni
83
+ # define ATTRIBUTES _target_attribute("avx512bw,avx512vl,avx512vnni")
84
+ # define VL 32
85
+ # define USE_VNNI 1
86
+ # define USE_AVX512 1
87
+ # include "adler32_template.h"
88
+
89
+ /*
90
+ * AVX512VNNI implementation using 512-bit vectors. This is used on CPUs that
91
+ * have a good AVX-512 implementation including AVX512VNNI. This should also be
92
+ * the optimal implementation on CPUs that support AVX10/512.
93
+ */
94
+ # define adler32_x86_avx512_vl512_vnni adler32_x86_avx512_vl512_vnni
95
+ # define SUFFIX _avx512_vl512_vnni
96
+ # define ATTRIBUTES _target_attribute("avx512bw,avx512vnni")
97
+ # define VL 64
98
+ # define USE_VNNI 1
99
+ # define USE_AVX512 1
100
+ # include "adler32_template.h"
101
+ #endif
102
+
103
+ static inline adler32_func_t
104
+ arch_select_adler32_func(void)
105
+ {
106
+ const u32 features MAYBE_UNUSED = get_x86_cpu_features();
107
+
108
+ #ifdef adler32_x86_avx512_vl512_vnni
109
+ if ((features & X86_CPU_FEATURE_ZMM) &&
110
+ HAVE_AVX512BW(features) && HAVE_AVX512VNNI(features))
111
+ return adler32_x86_avx512_vl512_vnni;
112
+ #endif
113
+ #ifdef adler32_x86_avx512_vl256_vnni
114
+ if (HAVE_AVX512BW(features) && HAVE_AVX512VL(features) &&
115
+ HAVE_AVX512VNNI(features))
116
+ return adler32_x86_avx512_vl256_vnni;
117
+ #endif
118
+ #ifdef adler32_x86_avx2_vnni
119
+ if (HAVE_AVX2(features) && HAVE_AVXVNNI(features))
120
+ return adler32_x86_avx2_vnni;
121
+ #endif
122
+ #ifdef adler32_x86_avx2
123
+ if (HAVE_AVX2(features))
124
+ return adler32_x86_avx2;
125
+ #endif
126
+ #ifdef adler32_x86_sse2
127
+ if (HAVE_SSE2(features))
128
+ return adler32_x86_sse2;
129
+ #endif
130
+ return NULL;
131
+ }
132
+ #define arch_select_adler32_func arch_select_adler32_func
133
+
134
+ #endif /* LIB_X86_ADLER32_IMPL_H */