Skip to content

Commit bce9a05

Browse files
committed
zstd: upgrade to zstd 1.4.5
Vendored commit b706286adbba780006a47ef92df0ad7a785666b6 from upstream with no modifications.
1 parent 6645432 commit bce9a05

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+3133
-1616
lines changed

zstd/common/bitstream.h

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,15 @@
11
/* ******************************************************************
2-
bitstream
3-
Part of FSE library
4-
Copyright (C) 2013-present, Yann Collet.
5-
6-
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
7-
8-
Redistribution and use in source and binary forms, with or without
9-
modification, are permitted provided that the following conditions are
10-
met:
11-
12-
* Redistributions of source code must retain the above copyright
13-
notice, this list of conditions and the following disclaimer.
14-
* Redistributions in binary form must reproduce the above
15-
copyright notice, this list of conditions and the following disclaimer
16-
in the documentation and/or other materials provided with the
17-
distribution.
18-
19-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20-
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21-
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22-
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23-
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24-
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25-
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26-
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27-
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28-
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30-
31-
You can contact the author at :
32-
- Source repository : https://github.com/Cyan4973/FiniteStateEntropy
2+
* bitstream
3+
* Part of FSE library
4+
* Copyright (c) 2013-2020, Yann Collet, Facebook, Inc.
5+
*
6+
* You can contact the author at :
7+
* - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
8+
*
9+
* This source code is licensed under both the BSD-style license (found in the
10+
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
11+
* in the COPYING file in the root directory of this source tree).
12+
* You may select, at your option, one of the above-listed licenses.
3313
****************************************************************** */
3414
#ifndef BITSTREAM_H_MODULE
3515
#define BITSTREAM_H_MODULE
@@ -48,6 +28,7 @@ extern "C" {
4828
* Dependencies
4929
******************************************/
5030
#include "mem.h" /* unaligned access routines */
31+
#include "compiler.h" /* UNLIKELY() */
5132
#include "debug.h" /* assert(), DEBUGLOG(), RAWLOG() */
5233
#include "error_private.h" /* error codes and messages */
5334

@@ -161,8 +142,7 @@ MEM_STATIC unsigned BIT_highbit32 (U32 val)
161142
{
162143
# if defined(_MSC_VER) /* Visual */
163144
unsigned long r=0;
164-
_BitScanReverse ( &r, val );
165-
return (unsigned) r;
145+
return _BitScanReverse ( &r, val ) ? (unsigned)r : 0;
166146
# elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */
167147
return __builtin_clz (val) ^ 31;
168148
# elif defined(__ICCARM__) /* IAR Intrinsic */
@@ -411,6 +391,23 @@ MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, unsigned nbBits)
411391
return value;
412392
}
413393

394+
/*! BIT_reloadDStreamFast() :
395+
* Similar to BIT_reloadDStream(), but with two differences:
396+
* 1. bitsConsumed <= sizeof(bitD->bitContainer)*8 must hold!
397+
* 2. Returns BIT_DStream_overflow when bitD->ptr < bitD->limitPtr, at this
398+
* point you must use BIT_reloadDStream() to reload.
399+
*/
400+
MEM_STATIC BIT_DStream_status BIT_reloadDStreamFast(BIT_DStream_t* bitD)
401+
{
402+
if (UNLIKELY(bitD->ptr < bitD->limitPtr))
403+
return BIT_DStream_overflow;
404+
assert(bitD->bitsConsumed <= sizeof(bitD->bitContainer)*8);
405+
bitD->ptr -= bitD->bitsConsumed >> 3;
406+
bitD->bitsConsumed &= 7;
407+
bitD->bitContainer = MEM_readLEST(bitD->ptr);
408+
return BIT_DStream_unfinished;
409+
}
410+
414411
/*! BIT_reloadDStream() :
415412
* Refill `bitD` from buffer previously set in BIT_initDStream() .
416413
* This function is safe, it guarantees it will not read beyond src buffer.
@@ -422,10 +419,7 @@ MEM_STATIC BIT_DStream_status BIT_reloadDStream(BIT_DStream_t* bitD)
422419
return BIT_DStream_overflow;
423420

424421
if (bitD->ptr >= bitD->limitPtr) {
425-
bitD->ptr -= bitD->bitsConsumed >> 3;
426-
bitD->bitsConsumed &= 7;
427-
bitD->bitContainer = MEM_readLEST(bitD->ptr);
428-
return BIT_DStream_unfinished;
422+
return BIT_reloadDStreamFast(bitD);
429423
}
430424
if (bitD->ptr == bitD->start) {
431425
if (bitD->bitsConsumed < sizeof(bitD->bitContainer)*8) return BIT_DStream_endOfBuffer;

zstd/common/compiler.h

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
2+
* Copyright (c) 2016-2020, Yann Collet, Facebook, Inc.
33
* All rights reserved.
44
*
55
* This source code is licensed under both the BSD-style license (found in the
@@ -17,7 +17,7 @@
1717
/* force inlining */
1818

1919
#if !defined(ZSTD_NO_INLINE)
20-
#if defined (__GNUC__) || defined(__cplusplus) || defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */
20+
#if (defined(__GNUC__) && !defined(__STRICT_ANSI__)) || defined(__cplusplus) || defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */
2121
# define INLINE_KEYWORD inline
2222
#else
2323
# define INLINE_KEYWORD
@@ -114,6 +114,9 @@
114114
# include <mmintrin.h> /* https://msdn.microsoft.com/fr-fr/library/84szxsww(v=vs.90).aspx */
115115
# define PREFETCH_L1(ptr) _mm_prefetch((const char*)(ptr), _MM_HINT_T0)
116116
# define PREFETCH_L2(ptr) _mm_prefetch((const char*)(ptr), _MM_HINT_T1)
117+
# elif defined(__aarch64__)
118+
# define PREFETCH_L1(ptr) __asm__ __volatile__("prfm pldl1keep, %0" ::"Q"(*(ptr)))
119+
# define PREFETCH_L2(ptr) __asm__ __volatile__("prfm pldl2keep, %0" ::"Q"(*(ptr)))
117120
# elif defined(__GNUC__) && ( (__GNUC__ >= 4) || ( (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1) ) )
118121
# define PREFETCH_L1(ptr) __builtin_prefetch((ptr), 0 /* rw==read */, 3 /* locality */)
119122
# define PREFETCH_L2(ptr) __builtin_prefetch((ptr), 0 /* rw==read */, 2 /* locality */)
@@ -136,7 +139,7 @@
136139

137140
/* vectorization
138141
* older GCC (pre gcc-4.3 picked as the cutoff) uses a different syntax */
139-
#if !defined(__clang__) && defined(__GNUC__)
142+
#if !defined(__INTEL_COMPILER) && !defined(__clang__) && defined(__GNUC__)
140143
# if (__GNUC__ == 4 && __GNUC_MINOR__ > 3) || (__GNUC__ >= 5)
141144
# define DONT_VECTORIZE __attribute__((optimize("no-tree-vectorize")))
142145
# else
@@ -146,6 +149,19 @@
146149
# define DONT_VECTORIZE
147150
#endif
148151

152+
/* Tell the compiler that a branch is likely or unlikely.
153+
* Only use these macros if it causes the compiler to generate better code.
154+
* If you can remove a LIKELY/UNLIKELY annotation without speed changes in gcc
155+
* and clang, please do.
156+
*/
157+
#if defined(__GNUC__)
158+
#define LIKELY(x) (__builtin_expect((x), 1))
159+
#define UNLIKELY(x) (__builtin_expect((x), 0))
160+
#else
161+
#define LIKELY(x) (x)
162+
#define UNLIKELY(x) (x)
163+
#endif
164+
149165
/* disable warnings */
150166
#ifdef _MSC_VER /* Visual Studio */
151167
# include <intrin.h> /* For Visual 2005 */

zstd/common/cpu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018-present, Facebook, Inc.
2+
* Copyright (c) 2018-2020, Facebook, Inc.
33
* All rights reserved.
44
*
55
* This source code is licensed under both the BSD-style license (found in the

zstd/common/debug.c

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,15 @@
11
/* ******************************************************************
2-
debug
3-
Part of FSE library
4-
Copyright (C) 2013-present, Yann Collet.
5-
6-
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
7-
8-
Redistribution and use in source and binary forms, with or without
9-
modification, are permitted provided that the following conditions are
10-
met:
11-
12-
* Redistributions of source code must retain the above copyright
13-
notice, this list of conditions and the following disclaimer.
14-
* Redistributions in binary form must reproduce the above
15-
copyright notice, this list of conditions and the following disclaimer
16-
in the documentation and/or other materials provided with the
17-
distribution.
18-
19-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20-
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21-
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22-
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23-
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24-
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25-
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26-
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27-
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28-
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30-
31-
You can contact the author at :
32-
- Source repository : https://github.com/Cyan4973/FiniteStateEntropy
2+
* debug
3+
* Part of FSE library
4+
* Copyright (c) 2013-2020, Yann Collet, Facebook, Inc.
5+
*
6+
* You can contact the author at :
7+
* - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
8+
*
9+
* This source code is licensed under both the BSD-style license (found in the
10+
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
11+
* in the COPYING file in the root directory of this source tree).
12+
* You may select, at your option, one of the above-listed licenses.
3313
****************************************************************** */
3414

3515

zstd/common/debug.h

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,15 @@
11
/* ******************************************************************
2-
debug
3-
Part of FSE library
4-
Copyright (C) 2013-present, Yann Collet.
5-
6-
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
7-
8-
Redistribution and use in source and binary forms, with or without
9-
modification, are permitted provided that the following conditions are
10-
met:
11-
12-
* Redistributions of source code must retain the above copyright
13-
notice, this list of conditions and the following disclaimer.
14-
* Redistributions in binary form must reproduce the above
15-
copyright notice, this list of conditions and the following disclaimer
16-
in the documentation and/or other materials provided with the
17-
distribution.
18-
19-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20-
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21-
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22-
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23-
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24-
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25-
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26-
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27-
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28-
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30-
31-
You can contact the author at :
32-
- Source repository : https://github.com/Cyan4973/FiniteStateEntropy
2+
* debug
3+
* Part of FSE library
4+
* Copyright (c) 2013-2020, Yann Collet, Facebook, Inc.
5+
*
6+
* You can contact the author at :
7+
* - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
8+
*
9+
* This source code is licensed under both the BSD-style license (found in the
10+
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
11+
* in the COPYING file in the root directory of this source tree).
12+
* You may select, at your option, one of the above-listed licenses.
3313
****************************************************************** */
3414

3515

zstd/common/entropy_common.c

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,16 @@
1-
/*
2-
Common functions of New Generation Entropy library
3-
Copyright (C) 2016, Yann Collet.
4-
5-
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
6-
7-
Redistribution and use in source and binary forms, with or without
8-
modification, are permitted provided that the following conditions are
9-
met:
10-
11-
* Redistributions of source code must retain the above copyright
12-
notice, this list of conditions and the following disclaimer.
13-
* Redistributions in binary form must reproduce the above
14-
copyright notice, this list of conditions and the following disclaimer
15-
in the documentation and/or other materials provided with the
16-
distribution.
17-
18-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19-
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20-
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21-
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22-
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23-
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24-
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25-
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26-
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27-
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29-
30-
You can contact the author at :
31-
- FSE+HUF source repository : https://github.com/Cyan4973/FiniteStateEntropy
32-
- Public forum : https://groups.google.com/forum/#!forum/lz4c
33-
*************************************************************************** */
1+
/* ******************************************************************
2+
* Common functions of New Generation Entropy library
3+
* Copyright (c) 2016-2020, Yann Collet, Facebook, Inc.
4+
*
5+
* You can contact the author at :
6+
* - FSE+HUF source repository : https://github.com/Cyan4973/FiniteStateEntropy
7+
* - Public forum : https://groups.google.com/forum/#!forum/lz4c
8+
*
9+
* This source code is licensed under both the BSD-style license (found in the
10+
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
11+
* in the COPYING file in the root directory of this source tree).
12+
* You may select, at your option, one of the above-listed licenses.
13+
****************************************************************** */
3414

3515
/* *************************************
3616
* Dependencies

zstd/common/error_private.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
2+
* Copyright (c) 2016-2020, Yann Collet, Facebook, Inc.
33
* All rights reserved.
44
*
55
* This source code is licensed under both the BSD-style license (found in the
@@ -47,6 +47,7 @@ const char* ERR_getErrorString(ERR_enum code)
4747
/* following error codes are not stable and may be removed or changed in a future version */
4848
case PREFIX(frameIndex_tooLarge): return "Frame index is too large";
4949
case PREFIX(seekableIO): return "An I/O error occurred when reading/seeking";
50+
case PREFIX(dstBuffer_wrong): return "Destination buffer is wrong";
5051
case PREFIX(maxCode):
5152
default: return notErrorCode;
5253
}

zstd/common/error_private.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
2+
* Copyright (c) 2016-2020, Yann Collet, Facebook, Inc.
33
* All rights reserved.
44
*
55
* This source code is licensed under both the BSD-style license (found in the
@@ -49,14 +49,18 @@ typedef ZSTD_ErrorCode ERR_enum;
4949
/*-****************************************
5050
* Error codes handling
5151
******************************************/
52-
#undef ERROR /* reported already defined on VS 2015 (Rich Geldreich) */
52+
#undef ERROR /* already defined on Visual Studio */
5353
#define ERROR(name) ZSTD_ERROR(name)
5454
#define ZSTD_ERROR(name) ((size_t)-PREFIX(name))
5555

5656
ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); }
5757

5858
ERR_STATIC ERR_enum ERR_getErrorCode(size_t code) { if (!ERR_isError(code)) return (ERR_enum)0; return (ERR_enum) (0-code); }
5959

60+
/* check and forward error code */
61+
#define CHECK_V_F(e, f) size_t const e = f; if (ERR_isError(e)) return e
62+
#define CHECK_F(f) { CHECK_V_F(_var_err__, f); }
63+
6064

6165
/*-****************************************
6266
* Error Strings

zstd/common/fse.h

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,15 @@
11
/* ******************************************************************
2-
FSE : Finite State Entropy codec
3-
Public Prototypes declaration
4-
Copyright (C) 2013-2016, Yann Collet.
5-
6-
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
7-
8-
Redistribution and use in source and binary forms, with or without
9-
modification, are permitted provided that the following conditions are
10-
met:
11-
12-
* Redistributions of source code must retain the above copyright
13-
notice, this list of conditions and the following disclaimer.
14-
* Redistributions in binary form must reproduce the above
15-
copyright notice, this list of conditions and the following disclaimer
16-
in the documentation and/or other materials provided with the
17-
distribution.
18-
19-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20-
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21-
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22-
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23-
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24-
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25-
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26-
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27-
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28-
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30-
31-
You can contact the author at :
32-
- Source repository : https://github.com/Cyan4973/FiniteStateEntropy
2+
* FSE : Finite State Entropy codec
3+
* Public Prototypes declaration
4+
* Copyright (c) 2013-2020, Yann Collet, Facebook, Inc.
5+
*
6+
* You can contact the author at :
7+
* - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
8+
*
9+
* This source code is licensed under both the BSD-style license (found in the
10+
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
11+
* in the COPYING file in the root directory of this source tree).
12+
* You may select, at your option, one of the above-listed licenses.
3313
****************************************************************** */
3414

3515
#if defined (__cplusplus)

0 commit comments

Comments
 (0)