libdeflate 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/test.yml +34 -0
- data/README.md +1 -6
- data/ext/libdeflate/extconf.rb +18 -7
- data/ext/libdeflate/libdeflate_ext.c +17 -17
- data/lib/libdeflate/version.rb +1 -1
- data/libdeflate.gemspec +2 -1
- metadata +13 -84
- data/.gitmodules +0 -3
- data/.travis.yml +0 -5
- data/ext/libdeflate/libdeflate/.gitignore +0 -19
- data/ext/libdeflate/libdeflate/COPYING +0 -21
- data/ext/libdeflate/libdeflate/Makefile +0 -231
- data/ext/libdeflate/libdeflate/Makefile.msc +0 -64
- data/ext/libdeflate/libdeflate/NEWS +0 -57
- data/ext/libdeflate/libdeflate/README.md +0 -170
- data/ext/libdeflate/libdeflate/common/common_defs.h +0 -351
- data/ext/libdeflate/libdeflate/common/compiler_gcc.h +0 -134
- data/ext/libdeflate/libdeflate/common/compiler_msc.h +0 -95
- data/ext/libdeflate/libdeflate/lib/adler32.c +0 -213
- data/ext/libdeflate/libdeflate/lib/adler32_impl.h +0 -281
- data/ext/libdeflate/libdeflate/lib/aligned_malloc.c +0 -57
- data/ext/libdeflate/libdeflate/lib/aligned_malloc.h +0 -13
- data/ext/libdeflate/libdeflate/lib/bt_matchfinder.h +0 -357
- data/ext/libdeflate/libdeflate/lib/crc32.c +0 -368
- data/ext/libdeflate/libdeflate/lib/crc32_impl.h +0 -286
- data/ext/libdeflate/libdeflate/lib/crc32_table.h +0 -526
- data/ext/libdeflate/libdeflate/lib/decompress_impl.h +0 -404
- data/ext/libdeflate/libdeflate/lib/deflate_compress.c +0 -2817
- data/ext/libdeflate/libdeflate/lib/deflate_compress.h +0 -14
- data/ext/libdeflate/libdeflate/lib/deflate_constants.h +0 -66
- data/ext/libdeflate/libdeflate/lib/deflate_decompress.c +0 -889
- data/ext/libdeflate/libdeflate/lib/gzip_compress.c +0 -95
- data/ext/libdeflate/libdeflate/lib/gzip_constants.h +0 -45
- data/ext/libdeflate/libdeflate/lib/gzip_decompress.c +0 -130
- data/ext/libdeflate/libdeflate/lib/hc_matchfinder.h +0 -405
- data/ext/libdeflate/libdeflate/lib/lib_common.h +0 -35
- data/ext/libdeflate/libdeflate/lib/matchfinder_avx2.h +0 -53
- data/ext/libdeflate/libdeflate/lib/matchfinder_common.h +0 -205
- data/ext/libdeflate/libdeflate/lib/matchfinder_neon.h +0 -61
- data/ext/libdeflate/libdeflate/lib/matchfinder_sse2.h +0 -53
- data/ext/libdeflate/libdeflate/lib/unaligned.h +0 -202
- data/ext/libdeflate/libdeflate/lib/x86_cpu_features.c +0 -169
- data/ext/libdeflate/libdeflate/lib/x86_cpu_features.h +0 -48
- data/ext/libdeflate/libdeflate/lib/zlib_compress.c +0 -87
- data/ext/libdeflate/libdeflate/lib/zlib_constants.h +0 -21
- data/ext/libdeflate/libdeflate/lib/zlib_decompress.c +0 -91
- data/ext/libdeflate/libdeflate/libdeflate.h +0 -274
- data/ext/libdeflate/libdeflate/programs/benchmark.c +0 -558
- data/ext/libdeflate/libdeflate/programs/checksum.c +0 -197
- data/ext/libdeflate/libdeflate/programs/detect.sh +0 -62
- data/ext/libdeflate/libdeflate/programs/gzip.c +0 -603
- data/ext/libdeflate/libdeflate/programs/prog_util.c +0 -530
- data/ext/libdeflate/libdeflate/programs/prog_util.h +0 -162
- data/ext/libdeflate/libdeflate/programs/test_checksums.c +0 -135
- data/ext/libdeflate/libdeflate/programs/tgetopt.c +0 -118
- data/ext/libdeflate/libdeflate/tools/afl-fuzz/Makefile +0 -12
- data/ext/libdeflate/libdeflate/tools/afl-fuzz/deflate_compress/fuzz.c +0 -40
- data/ext/libdeflate/libdeflate/tools/afl-fuzz/deflate_compress/inputs/0 +0 -0
- data/ext/libdeflate/libdeflate/tools/afl-fuzz/deflate_decompress/fuzz.c +0 -28
- data/ext/libdeflate/libdeflate/tools/afl-fuzz/deflate_decompress/inputs/0 +0 -3
- data/ext/libdeflate/libdeflate/tools/afl-fuzz/gzip_decompress/fuzz.c +0 -28
- data/ext/libdeflate/libdeflate/tools/afl-fuzz/gzip_decompress/inputs/0 +0 -0
- data/ext/libdeflate/libdeflate/tools/afl-fuzz/prepare_for_fuzz.sh +0 -14
- data/ext/libdeflate/libdeflate/tools/afl-fuzz/zlib_decompress/fuzz.c +0 -28
- data/ext/libdeflate/libdeflate/tools/afl-fuzz/zlib_decompress/inputs/0 +0 -3
- data/ext/libdeflate/libdeflate/tools/android_build.sh +0 -104
- data/ext/libdeflate/libdeflate/tools/checksum_benchmarks.sh +0 -76
- data/ext/libdeflate/libdeflate/tools/exec_tests.sh +0 -30
- data/ext/libdeflate/libdeflate/tools/gen_crc32_multipliers.c +0 -108
- data/ext/libdeflate/libdeflate/tools/gen_crc32_table.c +0 -100
- data/ext/libdeflate/libdeflate/tools/gzip_tests.sh +0 -412
- data/ext/libdeflate/libdeflate/tools/make-windows-releases +0 -21
- data/ext/libdeflate/libdeflate/tools/mips_build.sh +0 -9
- data/ext/libdeflate/libdeflate/tools/msc_test.bat +0 -3
- data/ext/libdeflate/libdeflate/tools/pgo_build.sh +0 -23
- data/ext/libdeflate/libdeflate/tools/produce_gzip_benchmark_table.sh +0 -37
- data/ext/libdeflate/libdeflate/tools/run_tests.sh +0 -305
- data/ext/libdeflate/libdeflate/tools/windows_build.sh +0 -10
@@ -1,134 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* compiler_gcc.h - definitions for the GNU C Compiler. This also handles clang
|
3
|
-
* and the Intel C Compiler (icc).
|
4
|
-
*
|
5
|
-
* TODO: icc is not well tested, so some things are currently disabled even
|
6
|
-
* though they maybe can be enabled on some icc versions.
|
7
|
-
*/
|
8
|
-
|
9
|
-
#if !defined(__clang__) && !defined(__INTEL_COMPILER)
|
10
|
-
# define GCC_PREREQ(major, minor) \
|
11
|
-
(__GNUC__ > (major) || \
|
12
|
-
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))
|
13
|
-
#else
|
14
|
-
# define GCC_PREREQ(major, minor) 0
|
15
|
-
#endif
|
16
|
-
|
17
|
-
/* Note: only check the clang version when absolutely necessary!
|
18
|
-
* "Vendors" such as Apple can use different version numbers. */
|
19
|
-
#ifdef __clang__
|
20
|
-
# ifdef __apple_build_version__
|
21
|
-
# define CLANG_PREREQ(major, minor, apple_version) \
|
22
|
-
(__apple_build_version__ >= (apple_version))
|
23
|
-
# else
|
24
|
-
# define CLANG_PREREQ(major, minor, apple_version) \
|
25
|
-
(__clang_major__ > (major) || \
|
26
|
-
(__clang_major__ == (major) && __clang_minor__ >= (minor)))
|
27
|
-
# endif
|
28
|
-
#else
|
29
|
-
# define CLANG_PREREQ(major, minor, apple_version) 0
|
30
|
-
#endif
|
31
|
-
|
32
|
-
#ifndef __has_attribute
|
33
|
-
# define __has_attribute(attribute) 0
|
34
|
-
#endif
|
35
|
-
#ifndef __has_feature
|
36
|
-
# define __has_feature(feature) 0
|
37
|
-
#endif
|
38
|
-
#ifndef __has_builtin
|
39
|
-
# define __has_builtin(builtin) 0
|
40
|
-
#endif
|
41
|
-
|
42
|
-
#ifdef _WIN32
|
43
|
-
# define LIBEXPORT __declspec(dllexport)
|
44
|
-
#else
|
45
|
-
# define LIBEXPORT __attribute__((visibility("default")))
|
46
|
-
#endif
|
47
|
-
|
48
|
-
#define inline inline
|
49
|
-
#define forceinline inline __attribute__((always_inline))
|
50
|
-
#define restrict __restrict__
|
51
|
-
#define likely(expr) __builtin_expect(!!(expr), 1)
|
52
|
-
#define unlikely(expr) __builtin_expect(!!(expr), 0)
|
53
|
-
#define prefetchr(addr) __builtin_prefetch((addr), 0)
|
54
|
-
#define prefetchw(addr) __builtin_prefetch((addr), 1)
|
55
|
-
#define _aligned_attribute(n) __attribute__((aligned(n)))
|
56
|
-
|
57
|
-
/*
|
58
|
-
* Support for the following x86 instruction set extensions was introduced by
|
59
|
-
* the following gcc versions:
|
60
|
-
*
|
61
|
-
* PCLMUL 4.4
|
62
|
-
* AVX 4.6
|
63
|
-
* BMI2 4.7
|
64
|
-
* AVX2 4.7
|
65
|
-
*
|
66
|
-
* With clang, __has_builtin() can be used to detect the presence of one of the
|
67
|
-
* associated builtins.
|
68
|
-
*
|
69
|
-
* Additionally, gcc 4.4 introduced the 'target' function attribute. With
|
70
|
-
* clang, support for this can be detected with with __has_attribute(target).
|
71
|
-
*
|
72
|
-
* However, prior to gcc 4.9 and clang 3.8, x86 intrinsics not available in the
|
73
|
-
* main target could not be used in 'target' attribute functions. Unfortunately
|
74
|
-
* clang has no feature test macro for this so we have to check its version.
|
75
|
-
*/
|
76
|
-
#define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE \
|
77
|
-
(GCC_PREREQ(4, 4) || __has_attribute(target))
|
78
|
-
#if COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE
|
79
|
-
# define COMPILER_SUPPORTS_TARGET_INTRINSICS \
|
80
|
-
(GCC_PREREQ(4, 9) || CLANG_PREREQ(3, 8, 7030000))
|
81
|
-
# define COMPILER_SUPPORTS_PCLMUL_TARGET \
|
82
|
-
(GCC_PREREQ(4, 4) || __has_builtin(__builtin_ia32_pclmulqdq128))
|
83
|
-
# define COMPILER_SUPPORTS_AVX_TARGET \
|
84
|
-
(GCC_PREREQ(4, 6) || __has_builtin(__builtin_ia32_maxps256))
|
85
|
-
# define COMPILER_SUPPORTS_BMI2_TARGET \
|
86
|
-
(GCC_PREREQ(4, 7) || __has_builtin(__builtin_ia32_pdep_di))
|
87
|
-
# define COMPILER_SUPPORTS_AVX2_TARGET \
|
88
|
-
(GCC_PREREQ(4, 7) || __has_builtin(__builtin_ia32_pmaddwd256))
|
89
|
-
#endif
|
90
|
-
|
91
|
-
/* Newer gcc supports __BYTE_ORDER__. Older gcc doesn't. */
|
92
|
-
#ifdef __BYTE_ORDER__
|
93
|
-
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
|
94
|
-
#endif
|
95
|
-
|
96
|
-
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16)
|
97
|
-
# define bswap16 __builtin_bswap16
|
98
|
-
#endif
|
99
|
-
|
100
|
-
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32)
|
101
|
-
# define bswap32 __builtin_bswap32
|
102
|
-
#endif
|
103
|
-
|
104
|
-
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64)
|
105
|
-
# define bswap64 __builtin_bswap64
|
106
|
-
#endif
|
107
|
-
|
108
|
-
#if defined(__x86_64__) || defined(__i386__) || defined(__ARM_FEATURE_UNALIGNED)
|
109
|
-
# define UNALIGNED_ACCESS_IS_FAST 1
|
110
|
-
#endif
|
111
|
-
|
112
|
-
/* With gcc, we can access unaligned memory through 'packed' structures. */
|
113
|
-
#define DEFINE_UNALIGNED_TYPE(type) \
|
114
|
-
\
|
115
|
-
struct type##unaligned { \
|
116
|
-
type v; \
|
117
|
-
} __attribute__((packed)); \
|
118
|
-
\
|
119
|
-
static forceinline type \
|
120
|
-
load_##type##_unaligned(const void *p) \
|
121
|
-
{ \
|
122
|
-
return ((const struct type##unaligned *)p)->v; \
|
123
|
-
} \
|
124
|
-
\
|
125
|
-
static forceinline void \
|
126
|
-
store_##type##_unaligned(type v, void *p) \
|
127
|
-
{ \
|
128
|
-
((struct type##unaligned *)p)->v = v; \
|
129
|
-
}
|
130
|
-
|
131
|
-
#define bsr32(n) (31 - __builtin_clz(n))
|
132
|
-
#define bsr64(n) (63 - __builtin_clzll(n))
|
133
|
-
#define bsf32(n) __builtin_ctz(n)
|
134
|
-
#define bsf64(n) __builtin_ctzll(n)
|
@@ -1,95 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* compiler_msc.h - definitions for the Microsoft C Compiler
|
3
|
-
*/
|
4
|
-
|
5
|
-
#define LIBEXPORT __declspec(dllexport)
|
6
|
-
|
7
|
-
/*
|
8
|
-
* Old versions (e.g. VS2010) of MSC don't have the C99 header stdbool.h.
|
9
|
-
* Beware: the below replacement isn't fully standard, since normally any value
|
10
|
-
* != 0 should be implicitly cast to a bool with value 1... but that doesn't
|
11
|
-
* happen if bool is really just an 'int'.
|
12
|
-
*/
|
13
|
-
typedef int bool;
|
14
|
-
#define true 1
|
15
|
-
#define false 0
|
16
|
-
#define __bool_true_false_are_defined 1
|
17
|
-
|
18
|
-
/* Define ssize_t */
|
19
|
-
#ifdef _WIN64
|
20
|
-
typedef long long ssize_t;
|
21
|
-
#else
|
22
|
-
typedef int ssize_t;
|
23
|
-
#endif
|
24
|
-
|
25
|
-
/*
|
26
|
-
* Old versions (e.g. VS2010) of MSC have stdint.h but not the C99 header
|
27
|
-
* inttypes.h. Work around this by defining the PRI* macros ourselves.
|
28
|
-
*/
|
29
|
-
#include <stdint.h>
|
30
|
-
#define PRIu8 "hhu"
|
31
|
-
#define PRIu16 "hu"
|
32
|
-
#define PRIu32 "u"
|
33
|
-
#define PRIu64 "llu"
|
34
|
-
#define PRIi8 "hhi"
|
35
|
-
#define PRIi16 "hi"
|
36
|
-
#define PRIi32 "i"
|
37
|
-
#define PRIi64 "lli"
|
38
|
-
#define PRIx8 "hhx"
|
39
|
-
#define PRIx16 "hx"
|
40
|
-
#define PRIx32 "x"
|
41
|
-
#define PRIx64 "llx"
|
42
|
-
|
43
|
-
/* Assume a little endian architecture with fast unaligned access */
|
44
|
-
#define CPU_IS_LITTLE_ENDIAN() 1
|
45
|
-
#define UNALIGNED_ACCESS_IS_FAST 1
|
46
|
-
|
47
|
-
/* __restrict has nonstandard behavior; don't use it */
|
48
|
-
#define restrict
|
49
|
-
|
50
|
-
/* ... but we can use __inline and __forceinline */
|
51
|
-
#define inline __inline
|
52
|
-
#define forceinline __forceinline
|
53
|
-
|
54
|
-
/* Byte swap functions */
|
55
|
-
#define bswap16 _byteswap_ushort
|
56
|
-
#define bswap32 _byteswap_ulong
|
57
|
-
#define bswap64 _byteswap_uint64
|
58
|
-
|
59
|
-
/* Bit scan functions (32-bit) */
|
60
|
-
|
61
|
-
static forceinline unsigned
|
62
|
-
bsr32(uint32_t n)
|
63
|
-
{
|
64
|
-
_BitScanReverse(&n, n);
|
65
|
-
return n;
|
66
|
-
}
|
67
|
-
#define bsr32 bsr32
|
68
|
-
|
69
|
-
static forceinline unsigned
|
70
|
-
bsf32(uint32_t n)
|
71
|
-
{
|
72
|
-
_BitScanForward(&n, n);
|
73
|
-
return n;
|
74
|
-
}
|
75
|
-
#define bsf32 bsf32
|
76
|
-
|
77
|
-
#ifdef _M_X64 /* Bit scan functions (64-bit) */
|
78
|
-
|
79
|
-
static forceinline unsigned
|
80
|
-
bsr64(uint64_t n)
|
81
|
-
{
|
82
|
-
_BitScanReverse64(&n, n);
|
83
|
-
return n;
|
84
|
-
}
|
85
|
-
#define bsr64 bsr64
|
86
|
-
|
87
|
-
static forceinline unsigned
|
88
|
-
bsf64(uint64_t n)
|
89
|
-
{
|
90
|
-
_BitScanForward64(&n, n);
|
91
|
-
return n;
|
92
|
-
}
|
93
|
-
#define bsf64 bsf64
|
94
|
-
|
95
|
-
#endif /* _M_X64 */
|
@@ -1,213 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* adler32.c - Adler-32 checksum algorithm
|
3
|
-
*
|
4
|
-
* Originally public domain; changes after 2016-09-07 are copyrighted.
|
5
|
-
*
|
6
|
-
* Copyright 2016 Eric Biggers
|
7
|
-
*
|
8
|
-
* Permission is hereby granted, free of charge, to any person
|
9
|
-
* obtaining a copy of this software and associated documentation
|
10
|
-
* files (the "Software"), to deal in the Software without
|
11
|
-
* restriction, including without limitation the rights to use,
|
12
|
-
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
13
|
-
* copies of the Software, and to permit persons to whom the
|
14
|
-
* Software is furnished to do so, subject to the following
|
15
|
-
* conditions:
|
16
|
-
*
|
17
|
-
* The above copyright notice and this permission notice shall be
|
18
|
-
* included in all copies or substantial portions of the Software.
|
19
|
-
*
|
20
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
21
|
-
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
22
|
-
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
23
|
-
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
24
|
-
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
25
|
-
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
26
|
-
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
27
|
-
* OTHER DEALINGS IN THE SOFTWARE.
|
28
|
-
*/
|
29
|
-
|
30
|
-
#include "x86_cpu_features.h"
|
31
|
-
|
32
|
-
#include "libdeflate.h"
|
33
|
-
|
34
|
-
/* The Adler-32 divisor, or "base", value. */
|
35
|
-
#define DIVISOR 65521
|
36
|
-
|
37
|
-
/*
|
38
|
-
* MAX_BYTES_PER_CHUNK is the most bytes that can be processed without the
|
39
|
-
* possibility of s2 overflowing when it is represented as an unsigned 32-bit
|
40
|
-
* integer. This value was computed using the following Python script:
|
41
|
-
*
|
42
|
-
* divisor = 65521
|
43
|
-
* count = 0
|
44
|
-
* s1 = divisor - 1
|
45
|
-
* s2 = divisor - 1
|
46
|
-
* while True:
|
47
|
-
* s1 += 0xFF
|
48
|
-
* s2 += s1
|
49
|
-
* if s2 > 0xFFFFFFFF:
|
50
|
-
* break
|
51
|
-
* count += 1
|
52
|
-
* print(count)
|
53
|
-
*
|
54
|
-
* Note that to get the correct worst-case value, we must assume that every byte
|
55
|
-
* has value 0xFF and that s1 and s2 started with the highest possible values
|
56
|
-
* modulo the divisor.
|
57
|
-
*/
|
58
|
-
#define MAX_BYTES_PER_CHUNK 5552
|
59
|
-
|
60
|
-
/* Select the implementations to compile in. */
|
61
|
-
|
62
|
-
#define NEED_GENERIC_IMPL 1 /* include generic impl unless overridden */
|
63
|
-
|
64
|
-
/* Include the SSE2 implementation? */
|
65
|
-
#define NEED_SSE2_IMPL 0
|
66
|
-
#ifdef __SSE2__
|
67
|
-
# include <emmintrin.h>
|
68
|
-
# undef NEED_SSE2_IMPL
|
69
|
-
# define NEED_SSE2_IMPL 1
|
70
|
-
# undef NEED_GENERIC_IMPL
|
71
|
-
# define NEED_GENERIC_IMPL 0 /* generic impl not needed */
|
72
|
-
#endif
|
73
|
-
|
74
|
-
/* Include the AVX2 implementation? */
|
75
|
-
#define NEED_AVX2_IMPL 0
|
76
|
-
#if defined(__AVX2__) || \
|
77
|
-
(X86_CPU_FEATURES_ENABLED && COMPILER_SUPPORTS_AVX2_TARGET && \
|
78
|
-
COMPILER_SUPPORTS_TARGET_INTRINSICS)
|
79
|
-
# include <immintrin.h>
|
80
|
-
# undef NEED_AVX2_IMPL
|
81
|
-
# define NEED_AVX2_IMPL 1
|
82
|
-
# ifdef __AVX2__ /* compiling for AVX2, i.e. can we assume it's there? */
|
83
|
-
# undef NEED_GENERIC_IMPL
|
84
|
-
# define NEED_GENERIC_IMPL 0 /* generic impl not needed */
|
85
|
-
# undef NEED_SSE2_IMPL
|
86
|
-
# define NEED_SSE2_IMPL 0 /* SSE2 impl not needed */
|
87
|
-
# endif /* otherwise, we can build an AVX2 version, but we won't know whether
|
88
|
-
we can use it until runtime */
|
89
|
-
#endif
|
90
|
-
|
91
|
-
/* Include the NEON implementation? */
|
92
|
-
#define NEED_NEON_IMPL 0
|
93
|
-
#ifdef __ARM_NEON
|
94
|
-
# include <arm_neon.h>
|
95
|
-
# undef NEED_NEON_IMPL
|
96
|
-
# define NEED_NEON_IMPL 1
|
97
|
-
# undef NEED_GENERIC_IMPL
|
98
|
-
# define NEED_GENERIC_IMPL 0 /* generic impl not needed */
|
99
|
-
#endif
|
100
|
-
|
101
|
-
#define NUM_IMPLS (NEED_GENERIC_IMPL + NEED_SSE2_IMPL + NEED_AVX2_IMPL + \
|
102
|
-
NEED_NEON_IMPL)
|
103
|
-
|
104
|
-
/* Define the generic implementation if needed. */
|
105
|
-
#if NEED_GENERIC_IMPL
|
106
|
-
static u32 adler32_generic(u32 adler, const void *buffer, size_t size)
|
107
|
-
{
|
108
|
-
u32 s1 = adler & 0xFFFF;
|
109
|
-
u32 s2 = adler >> 16;
|
110
|
-
const u8 *p = buffer;
|
111
|
-
const u8 * const end = p + size;
|
112
|
-
|
113
|
-
while (p != end) {
|
114
|
-
size_t chunk_size = MIN(end - p, MAX_BYTES_PER_CHUNK);
|
115
|
-
const u8 *chunk_end = p + chunk_size;
|
116
|
-
size_t num_unrolled_iterations = chunk_size / 4;
|
117
|
-
|
118
|
-
while (num_unrolled_iterations--) {
|
119
|
-
s1 += *p++;
|
120
|
-
s2 += s1;
|
121
|
-
s1 += *p++;
|
122
|
-
s2 += s1;
|
123
|
-
s1 += *p++;
|
124
|
-
s2 += s1;
|
125
|
-
s1 += *p++;
|
126
|
-
s2 += s1;
|
127
|
-
}
|
128
|
-
while (p != chunk_end) {
|
129
|
-
s1 += *p++;
|
130
|
-
s2 += s1;
|
131
|
-
}
|
132
|
-
s1 %= DIVISOR;
|
133
|
-
s2 %= DIVISOR;
|
134
|
-
}
|
135
|
-
|
136
|
-
return (s2 << 16) | s1;
|
137
|
-
}
|
138
|
-
#define DEFAULT_IMPL adler32_generic
|
139
|
-
#endif /* NEED_GENERIC_IMPL */
|
140
|
-
|
141
|
-
#define TARGET_SSE2 100
|
142
|
-
#define TARGET_AVX2 200
|
143
|
-
#define TARGET_NEON 300
|
144
|
-
|
145
|
-
/* Define the SSE2 implementation if needed. */
|
146
|
-
#if NEED_SSE2_IMPL
|
147
|
-
# define FUNCNAME adler32_sse2
|
148
|
-
# define TARGET TARGET_SSE2
|
149
|
-
# define ALIGNMENT_REQUIRED 16
|
150
|
-
# define BYTES_PER_ITERATION 32
|
151
|
-
# define ATTRIBUTES
|
152
|
-
# define DEFAULT_IMPL adler32_sse2
|
153
|
-
# include "adler32_impl.h"
|
154
|
-
#endif
|
155
|
-
|
156
|
-
/* Define the AVX2 implementation if needed. */
|
157
|
-
#if NEED_AVX2_IMPL
|
158
|
-
# define FUNCNAME adler32_avx2
|
159
|
-
# define TARGET TARGET_AVX2
|
160
|
-
# define ALIGNMENT_REQUIRED 32
|
161
|
-
# define BYTES_PER_ITERATION 32
|
162
|
-
# ifdef __AVX2__
|
163
|
-
# define ATTRIBUTES
|
164
|
-
# define DEFAULT_IMPL adler32_avx2
|
165
|
-
# else
|
166
|
-
# define ATTRIBUTES __attribute__((target("avx2")))
|
167
|
-
# endif
|
168
|
-
# include "adler32_impl.h"
|
169
|
-
#endif
|
170
|
-
|
171
|
-
/* Define the NEON implementation if needed. */
|
172
|
-
#if NEED_NEON_IMPL
|
173
|
-
# define FUNCNAME adler32_neon
|
174
|
-
# define TARGET TARGET_NEON
|
175
|
-
# define ALIGNMENT_REQUIRED 16
|
176
|
-
# define BYTES_PER_ITERATION 32
|
177
|
-
# define ATTRIBUTES
|
178
|
-
# define DEFAULT_IMPL adler32_neon
|
179
|
-
# include "adler32_impl.h"
|
180
|
-
#endif
|
181
|
-
|
182
|
-
typedef u32 (*adler32_func_t)(u32, const void *, size_t);
|
183
|
-
|
184
|
-
/*
|
185
|
-
* If multiple implementations are available, then dispatch among them based on
|
186
|
-
* CPU features at runtime. Otherwise just call the single one directly.
|
187
|
-
*/
|
188
|
-
#if NUM_IMPLS == 1
|
189
|
-
# define adler32_impl DEFAULT_IMPL
|
190
|
-
#else
|
191
|
-
static u32 dispatch(u32, const void *, size_t);
|
192
|
-
|
193
|
-
static adler32_func_t adler32_impl = dispatch;
|
194
|
-
|
195
|
-
static u32 dispatch(u32 adler, const void *buffer, size_t size)
|
196
|
-
{
|
197
|
-
adler32_func_t f = DEFAULT_IMPL;
|
198
|
-
#if NEED_AVX2_IMPL && !defined(__AVX2__)
|
199
|
-
if (x86_have_cpu_features(X86_CPU_FEATURE_AVX2))
|
200
|
-
f = adler32_avx2;
|
201
|
-
#endif
|
202
|
-
adler32_impl = f;
|
203
|
-
return adler32_impl(adler, buffer, size);
|
204
|
-
}
|
205
|
-
#endif /* NUM_IMPLS != 1 */
|
206
|
-
|
207
|
-
LIBDEFLATEAPI u32
|
208
|
-
libdeflate_adler32(u32 adler, const void *buffer, size_t size)
|
209
|
-
{
|
210
|
-
if (buffer == NULL) /* return initial value */
|
211
|
-
return 1;
|
212
|
-
return adler32_impl(adler, buffer, size);
|
213
|
-
}
|