comparison contrib/python-zstandard/zstd/common/mem.h @ 42070:675775c33ab6

zstandard: vendor python-zstandard 0.11 The upstream source distribution from PyPI was extracted. Unwanted files were removed. The clang-format ignore list was updated to reflect the new source of files. The project contains a vendored copy of zstandard 1.3.8. The old version was 1.3.6. This should result in some minor performance wins. test-check-py3-compat.t was updated to reflect now-passing tests on Python 3.8. Some HTTP tests were updated to reflect new zstd compression output. # no-check-commit because 3rd party code has different style guidelines Differential Revision: https://phab.mercurial-scm.org/D6199
author Gregory Szorc <gregory.szorc@gmail.com>
date Thu, 04 Apr 2019 17:34:43 -0700
parents 73fef626dae3
children 69de49c4e39c
comparison
equal deleted inserted replaced
42069:668eff08387f 42070:675775c33ab6
35 # define MEM_STATIC static inline 35 # define MEM_STATIC static inline
36 #elif defined(_MSC_VER) 36 #elif defined(_MSC_VER)
37 # define MEM_STATIC static __inline 37 # define MEM_STATIC static __inline
38 #else 38 #else
39 # define MEM_STATIC static /* this version may generate warnings for unused static functions; disable the relevant warning */ 39 # define MEM_STATIC static /* this version may generate warnings for unused static functions; disable the relevant warning */
40 #endif
41
42 #ifndef __has_builtin
43 # define __has_builtin(x) 0 /* compat. with non-clang compilers */
40 #endif 44 #endif
41 45
42 /* code only tested on 32 and 64 bits systems */ 46 /* code only tested on 32 and 64 bits systems */
43 #define MEM_STATIC_ASSERT(c) { enum { MEM_static_assert = 1/(int)(!!(c)) }; } 47 #define MEM_STATIC_ASSERT(c) { enum { MEM_static_assert = 1/(int)(!!(c)) }; }
44 MEM_STATIC void MEM_check(void) { MEM_STATIC_ASSERT((sizeof(size_t)==4) || (sizeof(size_t)==8)); } 48 MEM_STATIC void MEM_check(void) { MEM_STATIC_ASSERT((sizeof(size_t)==4) || (sizeof(size_t)==8)); }
196 200
197 MEM_STATIC U32 MEM_swap32(U32 in) 201 MEM_STATIC U32 MEM_swap32(U32 in)
198 { 202 {
199 #if defined(_MSC_VER) /* Visual Studio */ 203 #if defined(_MSC_VER) /* Visual Studio */
200 return _byteswap_ulong(in); 204 return _byteswap_ulong(in);
201 #elif defined (__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 403) 205 #elif (defined (__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 403)) \
206 || (defined(__clang__) && __has_builtin(__builtin_bswap32))
202 return __builtin_bswap32(in); 207 return __builtin_bswap32(in);
203 #else 208 #else
204 return ((in << 24) & 0xff000000 ) | 209 return ((in << 24) & 0xff000000 ) |
205 ((in << 8) & 0x00ff0000 ) | 210 ((in << 8) & 0x00ff0000 ) |
206 ((in >> 8) & 0x0000ff00 ) | 211 ((in >> 8) & 0x0000ff00 ) |
210 215
211 MEM_STATIC U64 MEM_swap64(U64 in) 216 MEM_STATIC U64 MEM_swap64(U64 in)
212 { 217 {
213 #if defined(_MSC_VER) /* Visual Studio */ 218 #if defined(_MSC_VER) /* Visual Studio */
214 return _byteswap_uint64(in); 219 return _byteswap_uint64(in);
215 #elif defined (__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 403) 220 #elif (defined (__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 403)) \
221 || (defined(__clang__) && __has_builtin(__builtin_bswap64))
216 return __builtin_bswap64(in); 222 return __builtin_bswap64(in);
217 #else 223 #else
218 return ((in << 56) & 0xff00000000000000ULL) | 224 return ((in << 56) & 0xff00000000000000ULL) |
219 ((in << 40) & 0x00ff000000000000ULL) | 225 ((in << 40) & 0x00ff000000000000ULL) |
220 ((in << 24) & 0x0000ff0000000000ULL) | 226 ((in << 24) & 0x0000ff0000000000ULL) |