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,169 @@
1
+ /*
2
+ * x86/cpu_features.h - feature detection for x86 CPUs
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_CPU_FEATURES_H
29
+ #define LIB_X86_CPU_FEATURES_H
30
+
31
+ #include "../lib_common.h"
32
+
33
+ #if defined(ARCH_X86_32) || defined(ARCH_X86_64)
34
+
35
+ #define X86_CPU_FEATURE_SSE2 (1 << 0)
36
+ #define X86_CPU_FEATURE_PCLMULQDQ (1 << 1)
37
+ #define X86_CPU_FEATURE_AVX (1 << 2)
38
+ #define X86_CPU_FEATURE_AVX2 (1 << 3)
39
+ #define X86_CPU_FEATURE_BMI2 (1 << 4)
40
+ /*
41
+ * ZMM indicates whether 512-bit vectors (zmm registers) should be used. On
42
+ * some CPUs, to avoid downclocking issues we don't set ZMM even if the CPU and
43
+ * operating system support AVX-512. On these CPUs, we may still use AVX-512
44
+ * instructions, but only with xmm and ymm registers.
45
+ */
46
+ #define X86_CPU_FEATURE_ZMM (1 << 5)
47
+ #define X86_CPU_FEATURE_AVX512BW (1 << 6)
48
+ #define X86_CPU_FEATURE_AVX512VL (1 << 7)
49
+ #define X86_CPU_FEATURE_VPCLMULQDQ (1 << 8)
50
+ #define X86_CPU_FEATURE_AVX512VNNI (1 << 9)
51
+ #define X86_CPU_FEATURE_AVXVNNI (1 << 10)
52
+
53
+ #if defined(__GNUC__) || defined(__clang__) || defined(_MSC_VER)
54
+ /* Runtime x86 CPU feature detection is supported. */
55
+ # define X86_CPU_FEATURES_KNOWN (1U << 31)
56
+ extern volatile u32 libdeflate_x86_cpu_features;
57
+
58
+ void libdeflate_init_x86_cpu_features(void);
59
+
60
+ static inline u32 get_x86_cpu_features(void)
61
+ {
62
+ if (libdeflate_x86_cpu_features == 0)
63
+ libdeflate_init_x86_cpu_features();
64
+ return libdeflate_x86_cpu_features;
65
+ }
66
+ /*
67
+ * x86 intrinsics are also supported. Include the headers needed to use them.
68
+ * Normally just immintrin.h suffices. With clang in MSVC compatibility mode,
69
+ * immintrin.h incorrectly skips including sub-headers, so include those too.
70
+ */
71
+ # include <immintrin.h>
72
+ # if defined(_MSC_VER) && defined(__clang__)
73
+ # include <tmmintrin.h>
74
+ # include <smmintrin.h>
75
+ # include <wmmintrin.h>
76
+ # include <avxintrin.h>
77
+ # include <avx2intrin.h>
78
+ # include <avx512fintrin.h>
79
+ # include <avx512bwintrin.h>
80
+ # include <avx512vlintrin.h>
81
+ # if __has_include(<avx512vlbwintrin.h>)
82
+ # include <avx512vlbwintrin.h>
83
+ # endif
84
+ # if __has_include(<vpclmulqdqintrin.h>)
85
+ # include <vpclmulqdqintrin.h>
86
+ # endif
87
+ # if __has_include(<avx512vnniintrin.h>)
88
+ # include <avx512vnniintrin.h>
89
+ # endif
90
+ # if __has_include(<avx512vlvnniintrin.h>)
91
+ # include <avx512vlvnniintrin.h>
92
+ # endif
93
+ # if __has_include(<avxvnniintrin.h>)
94
+ # include <avxvnniintrin.h>
95
+ # endif
96
+ # endif
97
+ #else
98
+ static inline u32 get_x86_cpu_features(void) { return 0; }
99
+ #endif
100
+
101
+ #if defined(__SSE2__) || \
102
+ (defined(_MSC_VER) && \
103
+ (defined(ARCH_X86_64) || (defined(_M_IX86_FP) && _M_IX86_FP >= 2)))
104
+ # define HAVE_SSE2(features) 1
105
+ # define HAVE_SSE2_NATIVE 1
106
+ #else
107
+ # define HAVE_SSE2(features) ((features) & X86_CPU_FEATURE_SSE2)
108
+ # define HAVE_SSE2_NATIVE 0
109
+ #endif
110
+
111
+ #if defined(__PCLMUL__) || (defined(_MSC_VER) && defined(__AVX2__))
112
+ # define HAVE_PCLMULQDQ(features) 1
113
+ #else
114
+ # define HAVE_PCLMULQDQ(features) ((features) & X86_CPU_FEATURE_PCLMULQDQ)
115
+ #endif
116
+
117
+ #ifdef __AVX__
118
+ # define HAVE_AVX(features) 1
119
+ #else
120
+ # define HAVE_AVX(features) ((features) & X86_CPU_FEATURE_AVX)
121
+ #endif
122
+
123
+ #ifdef __AVX2__
124
+ # define HAVE_AVX2(features) 1
125
+ #else
126
+ # define HAVE_AVX2(features) ((features) & X86_CPU_FEATURE_AVX2)
127
+ #endif
128
+
129
+ #if defined(__BMI2__) || (defined(_MSC_VER) && defined(__AVX2__))
130
+ # define HAVE_BMI2(features) 1
131
+ # define HAVE_BMI2_NATIVE 1
132
+ #else
133
+ # define HAVE_BMI2(features) ((features) & X86_CPU_FEATURE_BMI2)
134
+ # define HAVE_BMI2_NATIVE 0
135
+ #endif
136
+
137
+ #ifdef __AVX512BW__
138
+ # define HAVE_AVX512BW(features) 1
139
+ #else
140
+ # define HAVE_AVX512BW(features) ((features) & X86_CPU_FEATURE_AVX512BW)
141
+ #endif
142
+
143
+ #ifdef __AVX512VL__
144
+ # define HAVE_AVX512VL(features) 1
145
+ #else
146
+ # define HAVE_AVX512VL(features) ((features) & X86_CPU_FEATURE_AVX512VL)
147
+ #endif
148
+
149
+ #ifdef __VPCLMULQDQ__
150
+ # define HAVE_VPCLMULQDQ(features) 1
151
+ #else
152
+ # define HAVE_VPCLMULQDQ(features) ((features) & X86_CPU_FEATURE_VPCLMULQDQ)
153
+ #endif
154
+
155
+ #ifdef __AVX512VNNI__
156
+ # define HAVE_AVX512VNNI(features) 1
157
+ #else
158
+ # define HAVE_AVX512VNNI(features) ((features) & X86_CPU_FEATURE_AVX512VNNI)
159
+ #endif
160
+
161
+ #ifdef __AVXVNNI__
162
+ # define HAVE_AVXVNNI(features) 1
163
+ #else
164
+ # define HAVE_AVXVNNI(features) ((features) & X86_CPU_FEATURE_AVXVNNI)
165
+ #endif
166
+
167
+ #endif /* ARCH_X86_32 || ARCH_X86_64 */
168
+
169
+ #endif /* LIB_X86_CPU_FEATURES_H */
@@ -0,0 +1,160 @@
1
+ /*
2
+ * x86/crc32_impl.h - x86 implementations of the gzip CRC-32 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_CRC32_IMPL_H
29
+ #define LIB_X86_CRC32_IMPL_H
30
+
31
+ #include "cpu_features.h"
32
+
33
+ /*
34
+ * pshufb(x, shift_tab[len..len+15]) left shifts x by 16-len bytes.
35
+ * pshufb(x, shift_tab[len+16..len+31]) right shifts x by len bytes.
36
+ */
37
+ static const u8 MAYBE_UNUSED shift_tab[48] = {
38
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
39
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
40
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
41
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
42
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
43
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
44
+ };
45
+
46
+ #if defined(__GNUC__) || defined(__clang__) || defined(_MSC_VER)
47
+ /* PCLMULQDQ implementation */
48
+ # define crc32_x86_pclmulqdq crc32_x86_pclmulqdq
49
+ # define SUFFIX _pclmulqdq
50
+ # define ATTRIBUTES _target_attribute("pclmul")
51
+ # define VL 16
52
+ # define USE_SSE4_1 0
53
+ # define USE_AVX512 0
54
+ # include "crc32_pclmul_template.h"
55
+
56
+ /*
57
+ * PCLMULQDQ/AVX implementation. Compared to the regular PCLMULQDQ
58
+ * implementation, this still uses 128-bit vectors, but it has two potential
59
+ * benefits. First, simply compiling against the AVX target can improve
60
+ * performance significantly (e.g. 10100 MB/s to 16700 MB/s on Skylake) without
61
+ * actually using any AVX intrinsics, probably due to the availability of
62
+ * non-destructive VEX-encoded instructions. Second, AVX support implies SSSE3
63
+ * and SSE4.1 support, and we can use SSSE3 and SSE4.1 intrinsics for efficient
64
+ * handling of partial blocks. (We *could* compile a variant with
65
+ * PCLMULQDQ+SSE4.1 without AVX, but for simplicity we currently don't bother.)
66
+ */
67
+ # define crc32_x86_pclmulqdq_avx crc32_x86_pclmulqdq_avx
68
+ # define SUFFIX _pclmulqdq_avx
69
+ # define ATTRIBUTES _target_attribute("pclmul,avx")
70
+ # define VL 16
71
+ # define USE_SSE4_1 1
72
+ # define USE_AVX512 0
73
+ # include "crc32_pclmul_template.h"
74
+ #endif
75
+
76
+ /*
77
+ * VPCLMULQDQ/AVX2 implementation. This is used on CPUs that have AVX2 and
78
+ * VPCLMULQDQ but don't have AVX-512, for example Intel Alder Lake.
79
+ *
80
+ * Currently this can't be enabled with MSVC because MSVC has a bug where it
81
+ * incorrectly assumes that VPCLMULQDQ implies AVX-512:
82
+ * https://developercommunity.visualstudio.com/t/Compiler-incorrectly-assumes-VAES-and-VP/10578785
83
+ *
84
+ * gcc 8.1 and 8.2 had a similar bug where they assumed that
85
+ * _mm256_clmulepi64_epi128() always needed AVX512. It's fixed in gcc 8.3.
86
+ */
87
+ #if GCC_PREREQ(8, 3) || CLANG_PREREQ(6, 0, 10000000)
88
+ # define crc32_x86_vpclmulqdq_avx2 crc32_x86_vpclmulqdq_avx2
89
+ # define SUFFIX _vpclmulqdq_avx2
90
+ # define ATTRIBUTES _target_attribute("vpclmulqdq,pclmul,avx2")
91
+ # define VL 32
92
+ # define USE_SSE4_1 1
93
+ # define USE_AVX512 0
94
+ # include "crc32_pclmul_template.h"
95
+ #endif
96
+
97
+ #if GCC_PREREQ(8, 1) || CLANG_PREREQ(6, 0, 10000000) || MSVC_PREREQ(1920)
98
+ /*
99
+ * VPCLMULQDQ/AVX512 implementation using 256-bit vectors. This is very similar
100
+ * to the VPCLMULQDQ/AVX2 implementation but takes advantage of the vpternlog
101
+ * instruction and more registers. This is used on CPUs that support AVX-512
102
+ * but where using 512-bit vectors causes downclocking. This should also be the
103
+ * optimal implementation on CPUs that support AVX10/256 but not AVX10/512.
104
+ */
105
+ # define crc32_x86_vpclmulqdq_avx512_vl256 crc32_x86_vpclmulqdq_avx512_vl256
106
+ # define SUFFIX _vpclmulqdq_avx512_vl256
107
+ # define ATTRIBUTES _target_attribute("vpclmulqdq,pclmul,avx512bw,avx512vl")
108
+ # define VL 32
109
+ # define USE_SSE4_1 1
110
+ # define USE_AVX512 1
111
+ # include "crc32_pclmul_template.h"
112
+
113
+ /*
114
+ * VPCLMULQDQ/AVX512 implementation using 512-bit vectors. This is used on CPUs
115
+ * that have a good AVX-512 implementation including VPCLMULQDQ. This should
116
+ * also be the optimal implementation on CPUs that support AVX10/512.
117
+ */
118
+ # define crc32_x86_vpclmulqdq_avx512_vl512 crc32_x86_vpclmulqdq_avx512_vl512
119
+ # define SUFFIX _vpclmulqdq_avx512_vl512
120
+ # define ATTRIBUTES _target_attribute("vpclmulqdq,pclmul,avx512bw,avx512vl")
121
+ # define VL 64
122
+ # define USE_SSE4_1 1
123
+ # define USE_AVX512 1
124
+ # include "crc32_pclmul_template.h"
125
+ #endif
126
+
127
+ static inline crc32_func_t
128
+ arch_select_crc32_func(void)
129
+ {
130
+ const u32 features MAYBE_UNUSED = get_x86_cpu_features();
131
+
132
+ #ifdef crc32_x86_vpclmulqdq_avx512_vl512
133
+ if ((features & X86_CPU_FEATURE_ZMM) &&
134
+ HAVE_VPCLMULQDQ(features) && HAVE_PCLMULQDQ(features) &&
135
+ HAVE_AVX512BW(features) && HAVE_AVX512VL(features))
136
+ return crc32_x86_vpclmulqdq_avx512_vl512;
137
+ #endif
138
+ #ifdef crc32_x86_vpclmulqdq_avx512_vl256
139
+ if (HAVE_VPCLMULQDQ(features) && HAVE_PCLMULQDQ(features) &&
140
+ HAVE_AVX512BW(features) && HAVE_AVX512VL(features))
141
+ return crc32_x86_vpclmulqdq_avx512_vl256;
142
+ #endif
143
+ #ifdef crc32_x86_vpclmulqdq_avx2
144
+ if (HAVE_VPCLMULQDQ(features) && HAVE_PCLMULQDQ(features) &&
145
+ HAVE_AVX2(features))
146
+ return crc32_x86_vpclmulqdq_avx2;
147
+ #endif
148
+ #ifdef crc32_x86_pclmulqdq_avx
149
+ if (HAVE_PCLMULQDQ(features) && HAVE_AVX(features))
150
+ return crc32_x86_pclmulqdq_avx;
151
+ #endif
152
+ #ifdef crc32_x86_pclmulqdq
153
+ if (HAVE_PCLMULQDQ(features))
154
+ return crc32_x86_pclmulqdq;
155
+ #endif
156
+ return NULL;
157
+ }
158
+ #define arch_select_crc32_func arch_select_crc32_func
159
+
160
+ #endif /* LIB_X86_CRC32_IMPL_H */