zstdlib 0.13.0-x86-linux
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +6 -0
- data/CHANGES.md +107 -0
- data/Gemfile +3 -0
- data/README.md +107 -0
- data/Rakefile +59 -0
- data/ext/zstdlib_c/extconf.rb +59 -0
- data/ext/zstdlib_c/ruby/zlib-2.2/zstdlib.c +4675 -0
- data/ext/zstdlib_c/ruby/zlib-2.3/zstdlib.c +4702 -0
- data/ext/zstdlib_c/ruby/zlib-2.4/zstdlib.c +4859 -0
- data/ext/zstdlib_c/ruby/zlib-2.5/zstdlib.c +4864 -0
- data/ext/zstdlib_c/ruby/zlib-2.6/zstdlib.c +4906 -0
- data/ext/zstdlib_c/ruby/zlib-2.7/zstdlib.c +4895 -0
- data/ext/zstdlib_c/ruby/zlib-3.0/zstdlib.c +4994 -0
- data/ext/zstdlib_c/ruby/zlib-3.1/zstdlib.c +5076 -0
- data/ext/zstdlib_c/ruby/zlib-3.2/zstdlib.c +5090 -0
- data/ext/zstdlib_c/ruby/zlib-3.3/zstdlib.c +5090 -0
- data/ext/zstdlib_c/zlib-1.3.1/adler32.c +164 -0
- data/ext/zstdlib_c/zlib-1.3.1/compress.c +75 -0
- data/ext/zstdlib_c/zlib-1.3.1/crc32.c +1049 -0
- data/ext/zstdlib_c/zlib-1.3.1/crc32.h +9446 -0
- data/ext/zstdlib_c/zlib-1.3.1/deflate.c +2139 -0
- data/ext/zstdlib_c/zlib-1.3.1/deflate.h +377 -0
- data/ext/zstdlib_c/zlib-1.3.1/gzclose.c +23 -0
- data/ext/zstdlib_c/zlib-1.3.1/gzguts.h +214 -0
- data/ext/zstdlib_c/zlib-1.3.1/gzlib.c +582 -0
- data/ext/zstdlib_c/zlib-1.3.1/gzread.c +602 -0
- data/ext/zstdlib_c/zlib-1.3.1/gzwrite.c +631 -0
- data/ext/zstdlib_c/zlib-1.3.1/infback.c +628 -0
- data/ext/zstdlib_c/zlib-1.3.1/inffast.c +320 -0
- data/ext/zstdlib_c/zlib-1.3.1/inffast.h +11 -0
- data/ext/zstdlib_c/zlib-1.3.1/inffixed.h +94 -0
- data/ext/zstdlib_c/zlib-1.3.1/inflate.c +1526 -0
- data/ext/zstdlib_c/zlib-1.3.1/inflate.h +126 -0
- data/ext/zstdlib_c/zlib-1.3.1/inftrees.c +299 -0
- data/ext/zstdlib_c/zlib-1.3.1/inftrees.h +62 -0
- data/ext/zstdlib_c/zlib-1.3.1/trees.c +1117 -0
- data/ext/zstdlib_c/zlib-1.3.1/trees.h +128 -0
- data/ext/zstdlib_c/zlib-1.3.1/uncompr.c +85 -0
- data/ext/zstdlib_c/zlib-1.3.1/zconf.h +543 -0
- data/ext/zstdlib_c/zlib-1.3.1/zlib.h +1938 -0
- data/ext/zstdlib_c/zlib-1.3.1/zutil.c +299 -0
- data/ext/zstdlib_c/zlib-1.3.1/zutil.h +254 -0
- data/ext/zstdlib_c/zlib.mk +14 -0
- data/ext/zstdlib_c/zlibwrapper/zlibwrapper.c +10 -0
- data/ext/zstdlib_c/zlibwrapper.mk +14 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/allocations.h +55 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/bits.h +200 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/bitstream.h +457 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/compiler.h +450 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/cpu.h +249 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/debug.c +30 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/debug.h +116 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/entropy_common.c +340 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/error_private.c +63 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/error_private.h +168 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/fse.h +640 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/fse_decompress.c +313 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/huf.h +286 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/mem.h +426 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/pool.c +371 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/pool.h +90 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/portability_macros.h +158 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/threading.c +182 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/threading.h +150 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/xxhash.c +18 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/xxhash.h +7020 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/zstd_common.c +48 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/zstd_deps.h +111 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/zstd_internal.h +392 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/zstd_trace.h +163 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/clevels.h +134 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/fse_compress.c +625 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/hist.c +181 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/hist.h +75 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/huf_compress.c +1464 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_compress.c +7153 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_compress_internal.h +1534 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_compress_literals.c +235 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_compress_literals.h +39 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_compress_sequences.c +442 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_compress_sequences.h +54 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_compress_superblock.c +688 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_compress_superblock.h +32 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_cwksp.h +748 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_double_fast.c +770 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_double_fast.h +50 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_fast.c +968 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_fast.h +38 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_lazy.c +2199 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_lazy.h +202 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_ldm.c +730 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_ldm.h +117 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_ldm_geartab.h +106 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_opt.c +1576 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_opt.h +80 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstdmt_compress.c +1882 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstdmt_compress.h +113 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/decompress/huf_decompress.c +1944 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/decompress/huf_decompress_amd64.S +595 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/decompress/zstd_ddict.c +244 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/decompress/zstd_ddict.h +44 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/decompress/zstd_decompress.c +2407 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/decompress/zstd_decompress_block.c +2215 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/decompress/zstd_decompress_block.h +73 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/decompress/zstd_decompress_internal.h +240 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/zdict.h +474 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/zstd.h +3089 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/zstd_errors.h +114 -0
- data/ext/zstdlib_c/zstd-1.5.6/zlibWrapper/gzclose.c +26 -0
- data/ext/zstdlib_c/zstd-1.5.6/zlibWrapper/gzcompatibility.h +68 -0
- data/ext/zstdlib_c/zstd-1.5.6/zlibWrapper/gzguts.h +229 -0
- data/ext/zstdlib_c/zstd-1.5.6/zlibWrapper/gzlib.c +587 -0
- data/ext/zstdlib_c/zstd-1.5.6/zlibWrapper/gzread.c +637 -0
- data/ext/zstdlib_c/zstd-1.5.6/zlibWrapper/gzwrite.c +631 -0
- data/ext/zstdlib_c/zstd-1.5.6/zlibWrapper/zstd_zlibwrapper.c +1200 -0
- data/ext/zstdlib_c/zstd-1.5.6/zlibWrapper/zstd_zlibwrapper.h +91 -0
- data/ext/zstdlib_c/zstd.mk +15 -0
- data/lib/2.4/zstdlib_c.so +0 -0
- data/lib/2.5/zstdlib_c.so +0 -0
- data/lib/2.6/zstdlib_c.so +0 -0
- data/lib/2.7/zstdlib_c.so +0 -0
- data/lib/3.0/zstdlib_c.so +0 -0
- data/lib/3.1/zstdlib_c.so +0 -0
- data/lib/3.2/zstdlib_c.so +0 -0
- data/lib/3.3/zstdlib_c.so +0 -0
- data/lib/zstdlib.rb +6 -0
- data/test/zstdlib_test.rb +21 -0
- metadata +243 -0
@@ -0,0 +1,426 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
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 MEM_H_MODULE
|
12
|
+
#define MEM_H_MODULE
|
13
|
+
|
14
|
+
#if defined (__cplusplus)
|
15
|
+
extern "C" {
|
16
|
+
#endif
|
17
|
+
|
18
|
+
/*-****************************************
|
19
|
+
* Dependencies
|
20
|
+
******************************************/
|
21
|
+
#include <stddef.h> /* size_t, ptrdiff_t */
|
22
|
+
#include "compiler.h" /* __has_builtin */
|
23
|
+
#include "debug.h" /* DEBUG_STATIC_ASSERT */
|
24
|
+
#include "zstd_deps.h" /* ZSTD_memcpy */
|
25
|
+
|
26
|
+
|
27
|
+
/*-****************************************
|
28
|
+
* Compiler specifics
|
29
|
+
******************************************/
|
30
|
+
#if defined(_MSC_VER) /* Visual Studio */
|
31
|
+
# include <stdlib.h> /* _byteswap_ulong */
|
32
|
+
# include <intrin.h> /* _byteswap_* */
|
33
|
+
#endif
|
34
|
+
|
35
|
+
/*-**************************************************************
|
36
|
+
* Basic Types
|
37
|
+
*****************************************************************/
|
38
|
+
#if !defined (__VMS) && (defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) )
|
39
|
+
# if defined(_AIX)
|
40
|
+
# include <inttypes.h>
|
41
|
+
# else
|
42
|
+
# include <stdint.h> /* intptr_t */
|
43
|
+
# endif
|
44
|
+
typedef uint8_t BYTE;
|
45
|
+
typedef uint8_t U8;
|
46
|
+
typedef int8_t S8;
|
47
|
+
typedef uint16_t U16;
|
48
|
+
typedef int16_t S16;
|
49
|
+
typedef uint32_t U32;
|
50
|
+
typedef int32_t S32;
|
51
|
+
typedef uint64_t U64;
|
52
|
+
typedef int64_t S64;
|
53
|
+
#else
|
54
|
+
# include <limits.h>
|
55
|
+
#if CHAR_BIT != 8
|
56
|
+
# error "this implementation requires char to be exactly 8-bit type"
|
57
|
+
#endif
|
58
|
+
typedef unsigned char BYTE;
|
59
|
+
typedef unsigned char U8;
|
60
|
+
typedef signed char S8;
|
61
|
+
#if USHRT_MAX != 65535
|
62
|
+
# error "this implementation requires short to be exactly 16-bit type"
|
63
|
+
#endif
|
64
|
+
typedef unsigned short U16;
|
65
|
+
typedef signed short S16;
|
66
|
+
#if UINT_MAX != 4294967295
|
67
|
+
# error "this implementation requires int to be exactly 32-bit type"
|
68
|
+
#endif
|
69
|
+
typedef unsigned int U32;
|
70
|
+
typedef signed int S32;
|
71
|
+
/* note : there are no limits defined for long long type in C90.
|
72
|
+
* limits exist in C99, however, in such case, <stdint.h> is preferred */
|
73
|
+
typedef unsigned long long U64;
|
74
|
+
typedef signed long long S64;
|
75
|
+
#endif
|
76
|
+
|
77
|
+
|
78
|
+
/*-**************************************************************
|
79
|
+
* Memory I/O API
|
80
|
+
*****************************************************************/
|
81
|
+
/*=== Static platform detection ===*/
|
82
|
+
MEM_STATIC unsigned MEM_32bits(void);
|
83
|
+
MEM_STATIC unsigned MEM_64bits(void);
|
84
|
+
MEM_STATIC unsigned MEM_isLittleEndian(void);
|
85
|
+
|
86
|
+
/*=== Native unaligned read/write ===*/
|
87
|
+
MEM_STATIC U16 MEM_read16(const void* memPtr);
|
88
|
+
MEM_STATIC U32 MEM_read32(const void* memPtr);
|
89
|
+
MEM_STATIC U64 MEM_read64(const void* memPtr);
|
90
|
+
MEM_STATIC size_t MEM_readST(const void* memPtr);
|
91
|
+
|
92
|
+
MEM_STATIC void MEM_write16(void* memPtr, U16 value);
|
93
|
+
MEM_STATIC void MEM_write32(void* memPtr, U32 value);
|
94
|
+
MEM_STATIC void MEM_write64(void* memPtr, U64 value);
|
95
|
+
|
96
|
+
/*=== Little endian unaligned read/write ===*/
|
97
|
+
MEM_STATIC U16 MEM_readLE16(const void* memPtr);
|
98
|
+
MEM_STATIC U32 MEM_readLE24(const void* memPtr);
|
99
|
+
MEM_STATIC U32 MEM_readLE32(const void* memPtr);
|
100
|
+
MEM_STATIC U64 MEM_readLE64(const void* memPtr);
|
101
|
+
MEM_STATIC size_t MEM_readLEST(const void* memPtr);
|
102
|
+
|
103
|
+
MEM_STATIC void MEM_writeLE16(void* memPtr, U16 val);
|
104
|
+
MEM_STATIC void MEM_writeLE24(void* memPtr, U32 val);
|
105
|
+
MEM_STATIC void MEM_writeLE32(void* memPtr, U32 val32);
|
106
|
+
MEM_STATIC void MEM_writeLE64(void* memPtr, U64 val64);
|
107
|
+
MEM_STATIC void MEM_writeLEST(void* memPtr, size_t val);
|
108
|
+
|
109
|
+
/*=== Big endian unaligned read/write ===*/
|
110
|
+
MEM_STATIC U32 MEM_readBE32(const void* memPtr);
|
111
|
+
MEM_STATIC U64 MEM_readBE64(const void* memPtr);
|
112
|
+
MEM_STATIC size_t MEM_readBEST(const void* memPtr);
|
113
|
+
|
114
|
+
MEM_STATIC void MEM_writeBE32(void* memPtr, U32 val32);
|
115
|
+
MEM_STATIC void MEM_writeBE64(void* memPtr, U64 val64);
|
116
|
+
MEM_STATIC void MEM_writeBEST(void* memPtr, size_t val);
|
117
|
+
|
118
|
+
/*=== Byteswap ===*/
|
119
|
+
MEM_STATIC U32 MEM_swap32(U32 in);
|
120
|
+
MEM_STATIC U64 MEM_swap64(U64 in);
|
121
|
+
MEM_STATIC size_t MEM_swapST(size_t in);
|
122
|
+
|
123
|
+
|
124
|
+
/*-**************************************************************
|
125
|
+
* Memory I/O Implementation
|
126
|
+
*****************************************************************/
|
127
|
+
/* MEM_FORCE_MEMORY_ACCESS : For accessing unaligned memory:
|
128
|
+
* Method 0 : always use `memcpy()`. Safe and portable.
|
129
|
+
* Method 1 : Use compiler extension to set unaligned access.
|
130
|
+
* Method 2 : direct access. This method is portable but violate C standard.
|
131
|
+
* It can generate buggy code on targets depending on alignment.
|
132
|
+
* Default : method 1 if supported, else method 0
|
133
|
+
*/
|
134
|
+
#ifndef MEM_FORCE_MEMORY_ACCESS /* can be defined externally, on command line for example */
|
135
|
+
# ifdef __GNUC__
|
136
|
+
# define MEM_FORCE_MEMORY_ACCESS 1
|
137
|
+
# endif
|
138
|
+
#endif
|
139
|
+
|
140
|
+
MEM_STATIC unsigned MEM_32bits(void) { return sizeof(size_t)==4; }
|
141
|
+
MEM_STATIC unsigned MEM_64bits(void) { return sizeof(size_t)==8; }
|
142
|
+
|
143
|
+
MEM_STATIC unsigned MEM_isLittleEndian(void)
|
144
|
+
{
|
145
|
+
#if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
|
146
|
+
return 1;
|
147
|
+
#elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
|
148
|
+
return 0;
|
149
|
+
#elif defined(__clang__) && __LITTLE_ENDIAN__
|
150
|
+
return 1;
|
151
|
+
#elif defined(__clang__) && __BIG_ENDIAN__
|
152
|
+
return 0;
|
153
|
+
#elif defined(_MSC_VER) && (_M_AMD64 || _M_IX86)
|
154
|
+
return 1;
|
155
|
+
#elif defined(__DMC__) && defined(_M_IX86)
|
156
|
+
return 1;
|
157
|
+
#else
|
158
|
+
const union { U32 u; BYTE c[4]; } one = { 1 }; /* don't use static : performance detrimental */
|
159
|
+
return one.c[0];
|
160
|
+
#endif
|
161
|
+
}
|
162
|
+
|
163
|
+
#if defined(MEM_FORCE_MEMORY_ACCESS) && (MEM_FORCE_MEMORY_ACCESS==2)
|
164
|
+
|
165
|
+
/* violates C standard, by lying on structure alignment.
|
166
|
+
Only use if no other choice to achieve best performance on target platform */
|
167
|
+
MEM_STATIC U16 MEM_read16(const void* memPtr) { return *(const U16*) memPtr; }
|
168
|
+
MEM_STATIC U32 MEM_read32(const void* memPtr) { return *(const U32*) memPtr; }
|
169
|
+
MEM_STATIC U64 MEM_read64(const void* memPtr) { return *(const U64*) memPtr; }
|
170
|
+
MEM_STATIC size_t MEM_readST(const void* memPtr) { return *(const size_t*) memPtr; }
|
171
|
+
|
172
|
+
MEM_STATIC void MEM_write16(void* memPtr, U16 value) { *(U16*)memPtr = value; }
|
173
|
+
MEM_STATIC void MEM_write32(void* memPtr, U32 value) { *(U32*)memPtr = value; }
|
174
|
+
MEM_STATIC void MEM_write64(void* memPtr, U64 value) { *(U64*)memPtr = value; }
|
175
|
+
|
176
|
+
#elif defined(MEM_FORCE_MEMORY_ACCESS) && (MEM_FORCE_MEMORY_ACCESS==1)
|
177
|
+
|
178
|
+
typedef __attribute__((aligned(1))) U16 unalign16;
|
179
|
+
typedef __attribute__((aligned(1))) U32 unalign32;
|
180
|
+
typedef __attribute__((aligned(1))) U64 unalign64;
|
181
|
+
typedef __attribute__((aligned(1))) size_t unalignArch;
|
182
|
+
|
183
|
+
MEM_STATIC U16 MEM_read16(const void* ptr) { return *(const unalign16*)ptr; }
|
184
|
+
MEM_STATIC U32 MEM_read32(const void* ptr) { return *(const unalign32*)ptr; }
|
185
|
+
MEM_STATIC U64 MEM_read64(const void* ptr) { return *(const unalign64*)ptr; }
|
186
|
+
MEM_STATIC size_t MEM_readST(const void* ptr) { return *(const unalignArch*)ptr; }
|
187
|
+
|
188
|
+
MEM_STATIC void MEM_write16(void* memPtr, U16 value) { *(unalign16*)memPtr = value; }
|
189
|
+
MEM_STATIC void MEM_write32(void* memPtr, U32 value) { *(unalign32*)memPtr = value; }
|
190
|
+
MEM_STATIC void MEM_write64(void* memPtr, U64 value) { *(unalign64*)memPtr = value; }
|
191
|
+
|
192
|
+
#else
|
193
|
+
|
194
|
+
/* default method, safe and standard.
|
195
|
+
can sometimes prove slower */
|
196
|
+
|
197
|
+
MEM_STATIC U16 MEM_read16(const void* memPtr)
|
198
|
+
{
|
199
|
+
U16 val; ZSTD_memcpy(&val, memPtr, sizeof(val)); return val;
|
200
|
+
}
|
201
|
+
|
202
|
+
MEM_STATIC U32 MEM_read32(const void* memPtr)
|
203
|
+
{
|
204
|
+
U32 val; ZSTD_memcpy(&val, memPtr, sizeof(val)); return val;
|
205
|
+
}
|
206
|
+
|
207
|
+
MEM_STATIC U64 MEM_read64(const void* memPtr)
|
208
|
+
{
|
209
|
+
U64 val; ZSTD_memcpy(&val, memPtr, sizeof(val)); return val;
|
210
|
+
}
|
211
|
+
|
212
|
+
MEM_STATIC size_t MEM_readST(const void* memPtr)
|
213
|
+
{
|
214
|
+
size_t val; ZSTD_memcpy(&val, memPtr, sizeof(val)); return val;
|
215
|
+
}
|
216
|
+
|
217
|
+
MEM_STATIC void MEM_write16(void* memPtr, U16 value)
|
218
|
+
{
|
219
|
+
ZSTD_memcpy(memPtr, &value, sizeof(value));
|
220
|
+
}
|
221
|
+
|
222
|
+
MEM_STATIC void MEM_write32(void* memPtr, U32 value)
|
223
|
+
{
|
224
|
+
ZSTD_memcpy(memPtr, &value, sizeof(value));
|
225
|
+
}
|
226
|
+
|
227
|
+
MEM_STATIC void MEM_write64(void* memPtr, U64 value)
|
228
|
+
{
|
229
|
+
ZSTD_memcpy(memPtr, &value, sizeof(value));
|
230
|
+
}
|
231
|
+
|
232
|
+
#endif /* MEM_FORCE_MEMORY_ACCESS */
|
233
|
+
|
234
|
+
MEM_STATIC U32 MEM_swap32_fallback(U32 in)
|
235
|
+
{
|
236
|
+
return ((in << 24) & 0xff000000 ) |
|
237
|
+
((in << 8) & 0x00ff0000 ) |
|
238
|
+
((in >> 8) & 0x0000ff00 ) |
|
239
|
+
((in >> 24) & 0x000000ff );
|
240
|
+
}
|
241
|
+
|
242
|
+
MEM_STATIC U32 MEM_swap32(U32 in)
|
243
|
+
{
|
244
|
+
#if defined(_MSC_VER) /* Visual Studio */
|
245
|
+
return _byteswap_ulong(in);
|
246
|
+
#elif (defined (__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 403)) \
|
247
|
+
|| (defined(__clang__) && __has_builtin(__builtin_bswap32))
|
248
|
+
return __builtin_bswap32(in);
|
249
|
+
#else
|
250
|
+
return MEM_swap32_fallback(in);
|
251
|
+
#endif
|
252
|
+
}
|
253
|
+
|
254
|
+
MEM_STATIC U64 MEM_swap64_fallback(U64 in)
|
255
|
+
{
|
256
|
+
return ((in << 56) & 0xff00000000000000ULL) |
|
257
|
+
((in << 40) & 0x00ff000000000000ULL) |
|
258
|
+
((in << 24) & 0x0000ff0000000000ULL) |
|
259
|
+
((in << 8) & 0x000000ff00000000ULL) |
|
260
|
+
((in >> 8) & 0x00000000ff000000ULL) |
|
261
|
+
((in >> 24) & 0x0000000000ff0000ULL) |
|
262
|
+
((in >> 40) & 0x000000000000ff00ULL) |
|
263
|
+
((in >> 56) & 0x00000000000000ffULL);
|
264
|
+
}
|
265
|
+
|
266
|
+
MEM_STATIC U64 MEM_swap64(U64 in)
|
267
|
+
{
|
268
|
+
#if defined(_MSC_VER) /* Visual Studio */
|
269
|
+
return _byteswap_uint64(in);
|
270
|
+
#elif (defined (__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 403)) \
|
271
|
+
|| (defined(__clang__) && __has_builtin(__builtin_bswap64))
|
272
|
+
return __builtin_bswap64(in);
|
273
|
+
#else
|
274
|
+
return MEM_swap64_fallback(in);
|
275
|
+
#endif
|
276
|
+
}
|
277
|
+
|
278
|
+
MEM_STATIC size_t MEM_swapST(size_t in)
|
279
|
+
{
|
280
|
+
if (MEM_32bits())
|
281
|
+
return (size_t)MEM_swap32((U32)in);
|
282
|
+
else
|
283
|
+
return (size_t)MEM_swap64((U64)in);
|
284
|
+
}
|
285
|
+
|
286
|
+
/*=== Little endian r/w ===*/
|
287
|
+
|
288
|
+
MEM_STATIC U16 MEM_readLE16(const void* memPtr)
|
289
|
+
{
|
290
|
+
if (MEM_isLittleEndian())
|
291
|
+
return MEM_read16(memPtr);
|
292
|
+
else {
|
293
|
+
const BYTE* p = (const BYTE*)memPtr;
|
294
|
+
return (U16)(p[0] + (p[1]<<8));
|
295
|
+
}
|
296
|
+
}
|
297
|
+
|
298
|
+
MEM_STATIC void MEM_writeLE16(void* memPtr, U16 val)
|
299
|
+
{
|
300
|
+
if (MEM_isLittleEndian()) {
|
301
|
+
MEM_write16(memPtr, val);
|
302
|
+
} else {
|
303
|
+
BYTE* p = (BYTE*)memPtr;
|
304
|
+
p[0] = (BYTE)val;
|
305
|
+
p[1] = (BYTE)(val>>8);
|
306
|
+
}
|
307
|
+
}
|
308
|
+
|
309
|
+
MEM_STATIC U32 MEM_readLE24(const void* memPtr)
|
310
|
+
{
|
311
|
+
return (U32)MEM_readLE16(memPtr) + ((U32)(((const BYTE*)memPtr)[2]) << 16);
|
312
|
+
}
|
313
|
+
|
314
|
+
MEM_STATIC void MEM_writeLE24(void* memPtr, U32 val)
|
315
|
+
{
|
316
|
+
MEM_writeLE16(memPtr, (U16)val);
|
317
|
+
((BYTE*)memPtr)[2] = (BYTE)(val>>16);
|
318
|
+
}
|
319
|
+
|
320
|
+
MEM_STATIC U32 MEM_readLE32(const void* memPtr)
|
321
|
+
{
|
322
|
+
if (MEM_isLittleEndian())
|
323
|
+
return MEM_read32(memPtr);
|
324
|
+
else
|
325
|
+
return MEM_swap32(MEM_read32(memPtr));
|
326
|
+
}
|
327
|
+
|
328
|
+
MEM_STATIC void MEM_writeLE32(void* memPtr, U32 val32)
|
329
|
+
{
|
330
|
+
if (MEM_isLittleEndian())
|
331
|
+
MEM_write32(memPtr, val32);
|
332
|
+
else
|
333
|
+
MEM_write32(memPtr, MEM_swap32(val32));
|
334
|
+
}
|
335
|
+
|
336
|
+
MEM_STATIC U64 MEM_readLE64(const void* memPtr)
|
337
|
+
{
|
338
|
+
if (MEM_isLittleEndian())
|
339
|
+
return MEM_read64(memPtr);
|
340
|
+
else
|
341
|
+
return MEM_swap64(MEM_read64(memPtr));
|
342
|
+
}
|
343
|
+
|
344
|
+
MEM_STATIC void MEM_writeLE64(void* memPtr, U64 val64)
|
345
|
+
{
|
346
|
+
if (MEM_isLittleEndian())
|
347
|
+
MEM_write64(memPtr, val64);
|
348
|
+
else
|
349
|
+
MEM_write64(memPtr, MEM_swap64(val64));
|
350
|
+
}
|
351
|
+
|
352
|
+
MEM_STATIC size_t MEM_readLEST(const void* memPtr)
|
353
|
+
{
|
354
|
+
if (MEM_32bits())
|
355
|
+
return (size_t)MEM_readLE32(memPtr);
|
356
|
+
else
|
357
|
+
return (size_t)MEM_readLE64(memPtr);
|
358
|
+
}
|
359
|
+
|
360
|
+
MEM_STATIC void MEM_writeLEST(void* memPtr, size_t val)
|
361
|
+
{
|
362
|
+
if (MEM_32bits())
|
363
|
+
MEM_writeLE32(memPtr, (U32)val);
|
364
|
+
else
|
365
|
+
MEM_writeLE64(memPtr, (U64)val);
|
366
|
+
}
|
367
|
+
|
368
|
+
/*=== Big endian r/w ===*/
|
369
|
+
|
370
|
+
MEM_STATIC U32 MEM_readBE32(const void* memPtr)
|
371
|
+
{
|
372
|
+
if (MEM_isLittleEndian())
|
373
|
+
return MEM_swap32(MEM_read32(memPtr));
|
374
|
+
else
|
375
|
+
return MEM_read32(memPtr);
|
376
|
+
}
|
377
|
+
|
378
|
+
MEM_STATIC void MEM_writeBE32(void* memPtr, U32 val32)
|
379
|
+
{
|
380
|
+
if (MEM_isLittleEndian())
|
381
|
+
MEM_write32(memPtr, MEM_swap32(val32));
|
382
|
+
else
|
383
|
+
MEM_write32(memPtr, val32);
|
384
|
+
}
|
385
|
+
|
386
|
+
MEM_STATIC U64 MEM_readBE64(const void* memPtr)
|
387
|
+
{
|
388
|
+
if (MEM_isLittleEndian())
|
389
|
+
return MEM_swap64(MEM_read64(memPtr));
|
390
|
+
else
|
391
|
+
return MEM_read64(memPtr);
|
392
|
+
}
|
393
|
+
|
394
|
+
MEM_STATIC void MEM_writeBE64(void* memPtr, U64 val64)
|
395
|
+
{
|
396
|
+
if (MEM_isLittleEndian())
|
397
|
+
MEM_write64(memPtr, MEM_swap64(val64));
|
398
|
+
else
|
399
|
+
MEM_write64(memPtr, val64);
|
400
|
+
}
|
401
|
+
|
402
|
+
MEM_STATIC size_t MEM_readBEST(const void* memPtr)
|
403
|
+
{
|
404
|
+
if (MEM_32bits())
|
405
|
+
return (size_t)MEM_readBE32(memPtr);
|
406
|
+
else
|
407
|
+
return (size_t)MEM_readBE64(memPtr);
|
408
|
+
}
|
409
|
+
|
410
|
+
MEM_STATIC void MEM_writeBEST(void* memPtr, size_t val)
|
411
|
+
{
|
412
|
+
if (MEM_32bits())
|
413
|
+
MEM_writeBE32(memPtr, (U32)val);
|
414
|
+
else
|
415
|
+
MEM_writeBE64(memPtr, (U64)val);
|
416
|
+
}
|
417
|
+
|
418
|
+
/* code only tested on 32 and 64 bits systems */
|
419
|
+
MEM_STATIC void MEM_check(void) { DEBUG_STATIC_ASSERT((sizeof(size_t)==4) || (sizeof(size_t)==8)); }
|
420
|
+
|
421
|
+
|
422
|
+
#if defined (__cplusplus)
|
423
|
+
}
|
424
|
+
#endif
|
425
|
+
|
426
|
+
#endif /* MEM_H_MODULE */
|