Skip to content

Commit 95346f4

Browse files
committed
Update zstd to version 1.5.0
Updating zstd lib and removing deprecated files
1 parent 4fa4b6b commit 95346f4

Some content is hidden

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

81 files changed

+5219
-2202
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
[C Zstd Homepage](https://github.com/facebook/zstd)
88

9-
The current headers and C files are from *v1.4.4* (Commit
10-
[10f0e699](https://github.com/facebook/zstd/releases/tag/v1.4.4)).
9+
The current headers and C files are from *v1.5.0* (Commit
10+
[10f0e699](https://github.com/facebook/zstd/releases/tag/v1.5.0)).
1111

1212
## Usage
1313

bitstream.h

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* ******************************************************************
22
* bitstream
33
* Part of FSE library
4-
* Copyright (c) 2013-2020, Yann Collet, Facebook, Inc.
4+
* Copyright (c) Yann Collet, Facebook, Inc.
55
*
66
* You can contact the author at :
77
* - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
@@ -332,7 +332,16 @@ MEM_STATIC FORCE_INLINE_ATTR size_t BIT_getMiddleBits(size_t bitContainer, U32 c
332332
U32 const regMask = sizeof(bitContainer)*8 - 1;
333333
/* if start > regMask, bitstream is corrupted, and result is undefined */
334334
assert(nbBits < BIT_MASK_SIZE);
335+
/* x86 transform & ((1 << nbBits) - 1) to bzhi instruction, it is better
336+
* than accessing memory. When bmi2 instruction is not present, we consider
337+
* such cpus old (pre-Haswell, 2013) and their performance is not of that
338+
* importance.
339+
*/
340+
#if defined(__x86_64__) || defined(_M_X86)
341+
return (bitContainer >> (start & regMask)) & ((((U64)1) << nbBits) - 1);
342+
#else
335343
return (bitContainer >> (start & regMask)) & BIT_mask[nbBits];
344+
#endif
336345
}
337346

338347
MEM_STATIC FORCE_INLINE_ATTR size_t BIT_getLowerBits(size_t bitContainer, U32 const nbBits)

compiler.h

+21-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016-2020, Yann Collet, Facebook, Inc.
2+
* Copyright (c) Yann Collet, Facebook, Inc.
33
* All rights reserved.
44
*
55
* This source code is licensed under both the BSD-style license (found in the
@@ -90,6 +90,7 @@
9090
# endif
9191
#endif
9292

93+
9394
/* target attribute */
9495
#ifndef __has_attribute
9596
#define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */
@@ -149,8 +150,9 @@
149150
}
150151

151152
/* vectorization
152-
* older GCC (pre gcc-4.3 picked as the cutoff) uses a different syntax */
153-
#if !defined(__INTEL_COMPILER) && !defined(__clang__) && defined(__GNUC__)
153+
* older GCC (pre gcc-4.3 picked as the cutoff) uses a different syntax,
154+
* and some compilers, like Intel ICC and MCST LCC, do not support it at all. */
155+
#if !defined(__INTEL_COMPILER) && !defined(__clang__) && defined(__GNUC__) && !defined(__LCC__)
154156
# if (__GNUC__ == 4 && __GNUC_MINOR__ > 3) || (__GNUC__ >= 5)
155157
# define DONT_VECTORIZE __attribute__((optimize("no-tree-vectorize")))
156158
# else
@@ -196,6 +198,22 @@
196198
#define STATIC_BMI2 0
197199
#endif
198200

201+
/* compile time determination of SIMD support */
202+
#if !defined(ZSTD_NO_INTRINSICS)
203+
# if defined(__SSE2__) || defined(_M_AMD64) || (defined (_M_IX86) && defined(_M_IX86_FP) && (_M_IX86_FP >= 2))
204+
# define ZSTD_ARCH_X86_SSE2
205+
# endif
206+
# if defined(__ARM_NEON) || defined(_M_ARM64)
207+
# define ZSTD_ARCH_ARM_NEON
208+
# endif
209+
#
210+
# if defined(ZSTD_ARCH_X86_SSE2)
211+
# include <emmintrin.h>
212+
# elif defined(ZSTD_ARCH_ARM_NEON)
213+
# include <arm_neon.h>
214+
# endif
215+
#endif
216+
199217
/* compat. with non-clang compilers */
200218
#ifndef __has_builtin
201219
# define __has_builtin(x) 0

cover.c

+16-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016-2020, Yann Collet, Facebook, Inc.
2+
* Copyright (c) Yann Collet, Facebook, Inc.
33
* All rights reserved.
44
*
55
* This source code is licensed under both the BSD-style license (found in the
@@ -26,15 +26,16 @@
2626
#include <string.h> /* memset */
2727
#include <time.h> /* clock */
2828

29+
#ifndef ZDICT_STATIC_LINKING_ONLY
30+
# define ZDICT_STATIC_LINKING_ONLY
31+
#endif
32+
2933
#include "mem.h" /* read */
3034
#include "pool.h"
3135
#include "threading.h"
32-
#include "cover.h"
3336
#include "zstd_internal.h" /* includes zstd.h */
34-
#ifndef ZDICT_STATIC_LINKING_ONLY
35-
#define ZDICT_STATIC_LINKING_ONLY
36-
#endif
3737
#include "zdict.h"
38+
#include "cover.h"
3839

3940
/*-*************************************
4041
* Constants
@@ -1062,18 +1063,19 @@ typedef struct COVER_tryParameters_data_s {
10621063
* This function is thread safe if zstd is compiled with multithreaded support.
10631064
* It takes its parameters as an *OWNING* opaque pointer to support threading.
10641065
*/
1065-
static void COVER_tryParameters(void *opaque) {
1066+
static void COVER_tryParameters(void *opaque)
1067+
{
10661068
/* Save parameters as local variables */
1067-
COVER_tryParameters_data_t *const data = (COVER_tryParameters_data_t *)opaque;
1069+
COVER_tryParameters_data_t *const data = (COVER_tryParameters_data_t*)opaque;
10681070
const COVER_ctx_t *const ctx = data->ctx;
10691071
const ZDICT_cover_params_t parameters = data->parameters;
10701072
size_t dictBufferCapacity = data->dictBufferCapacity;
10711073
size_t totalCompressedSize = ERROR(GENERIC);
10721074
/* Allocate space for hash table, dict, and freqs */
10731075
COVER_map_t activeDmers;
1074-
BYTE *const dict = (BYTE * const)malloc(dictBufferCapacity);
1076+
BYTE* const dict = (BYTE*)malloc(dictBufferCapacity);
10751077
COVER_dictSelection_t selection = COVER_dictSelectionError(ERROR(GENERIC));
1076-
U32 *freqs = (U32 *)malloc(ctx->suffixSize * sizeof(U32));
1078+
U32* const freqs = (U32*)malloc(ctx->suffixSize * sizeof(U32));
10771079
if (!COVER_map_init(&activeDmers, parameters.k - parameters.d + 1)) {
10781080
DISPLAYLEVEL(1, "Failed to allocate dmer map: out of memory\n");
10791081
goto _cleanup;
@@ -1103,15 +1105,14 @@ static void COVER_tryParameters(void *opaque) {
11031105
free(data);
11041106
COVER_map_destroy(&activeDmers);
11051107
COVER_dictSelectionFree(selection);
1106-
if (freqs) {
1107-
free(freqs);
1108-
}
1108+
free(freqs);
11091109
}
11101110

11111111
ZDICTLIB_API size_t ZDICT_optimizeTrainFromBuffer_cover(
1112-
void *dictBuffer, size_t dictBufferCapacity, const void *samplesBuffer,
1113-
const size_t *samplesSizes, unsigned nbSamples,
1114-
ZDICT_cover_params_t *parameters) {
1112+
void* dictBuffer, size_t dictBufferCapacity, const void* samplesBuffer,
1113+
const size_t* samplesSizes, unsigned nbSamples,
1114+
ZDICT_cover_params_t* parameters)
1115+
{
11151116
/* constants */
11161117
const unsigned nbThreads = parameters->nbThreads;
11171118
const double splitPoint =

cover.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017-2020, Facebook, Inc.
2+
* Copyright (c) Facebook, Inc.
33
* All rights reserved.
44
*
55
* This source code is licensed under both the BSD-style license (found in the
@@ -8,6 +8,10 @@
88
* You may select, at your option, one of the above-listed licenses.
99
*/
1010

11+
#ifndef ZDICT_STATIC_LINKING_ONLY
12+
# define ZDICT_STATIC_LINKING_ONLY
13+
#endif
14+
1115
#include <stdio.h> /* fprintf */
1216
#include <stdlib.h> /* malloc, free, qsort */
1317
#include <string.h> /* memset */
@@ -16,9 +20,6 @@
1620
#include "pool.h"
1721
#include "threading.h"
1822
#include "zstd_internal.h" /* includes zstd.h */
19-
#ifndef ZDICT_STATIC_LINKING_ONLY
20-
#define ZDICT_STATIC_LINKING_ONLY
21-
#endif
2223
#include "zdict.h"
2324

2425
/**

cpu.h

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

debug.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* ******************************************************************
22
* debug
33
* Part of FSE library
4-
* Copyright (c) 2013-2020, Yann Collet, Facebook, Inc.
4+
* Copyright (c) Yann Collet, Facebook, Inc.
55
*
66
* You can contact the author at :
77
* - Source repository : https://github.com/Cyan4973/FiniteStateEntropy

debug.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* ******************************************************************
22
* debug
33
* Part of FSE library
4-
* Copyright (c) 2013-2020, Yann Collet, Facebook, Inc.
4+
* Copyright (c) Yann Collet, Facebook, Inc.
55
*
66
* You can contact the author at :
77
* - Source repository : https://github.com/Cyan4973/FiniteStateEntropy

divsufsort.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1576,7 +1576,7 @@ sort_typeBstar(const unsigned char *T, int *SA,
15761576
/* Construct the inverse suffix array of type B* suffixes using trsort. */
15771577
trsort(ISAb, SA, m, 1);
15781578

1579-
/* Set the sorted order of tyoe B* suffixes. */
1579+
/* Set the sorted order of type B* suffixes. */
15801580
for(i = n - 1, j = m, c0 = T[n - 1]; 0 <= i;) {
15811581
for(--i, c1 = c0; (0 <= i) && ((c0 = T[i]) >= c1); --i, c1 = c0) { }
15821582
if(0 <= i) {

entropy_common.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* ******************************************************************
22
* Common functions of New Generation Entropy library
3-
* Copyright (c) 2016-2020, Yann Collet, Facebook, Inc.
3+
* Copyright (c) Yann Collet, Facebook, Inc.
44
*
55
* You can contact the author at :
66
* - FSE+HUF source repository : https://github.com/Cyan4973/FiniteStateEntropy
@@ -299,7 +299,7 @@ HUF_readStats_body(BYTE* huffWeight, size_t hwSize, U32* rankStats,
299299
ZSTD_memset(rankStats, 0, (HUF_TABLELOG_MAX + 1) * sizeof(U32));
300300
weightTotal = 0;
301301
{ U32 n; for (n=0; n<oSize; n++) {
302-
if (huffWeight[n] >= HUF_TABLELOG_MAX) return ERROR(corruption_detected);
302+
if (huffWeight[n] > HUF_TABLELOG_MAX) return ERROR(corruption_detected);
303303
rankStats[huffWeight[n]]++;
304304
weightTotal += (1 << huffWeight[n]) >> 1;
305305
} }

error_private.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016-2020, Yann Collet, Facebook, Inc.
2+
* Copyright (c) Yann Collet, Facebook, Inc.
33
* All rights reserved.
44
*
55
* This source code is licensed under both the BSD-style license (found in the

error_private.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016-2020, Yann Collet, Facebook, Inc.
2+
* Copyright (c) Yann Collet, Facebook, Inc.
33
* All rights reserved.
44
*
55
* This source code is licensed under both the BSD-style license (found in the
@@ -21,8 +21,8 @@ extern "C" {
2121
/* ****************************************
2222
* Dependencies
2323
******************************************/
24-
#include "zstd_deps.h" /* size_t */
2524
#include "zstd_errors.h" /* enum list */
25+
#include "zstd_deps.h" /* size_t */
2626

2727

2828
/* ****************************************

fastcover.c

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018-2020, Facebook, Inc.
2+
* Copyright (c) Facebook, Inc.
33
* All rights reserved.
44
*
55
* This source code is licensed under both the BSD-style license (found in the
@@ -16,16 +16,17 @@
1616
#include <string.h> /* memset */
1717
#include <time.h> /* clock */
1818

19+
#ifndef ZDICT_STATIC_LINKING_ONLY
20+
# define ZDICT_STATIC_LINKING_ONLY
21+
#endif
22+
1923
#include "mem.h" /* read */
2024
#include "pool.h"
2125
#include "threading.h"
22-
#include "cover.h"
2326
#include "zstd_internal.h" /* includes zstd.h */
2427
#include "zstd_compress_internal.h" /* ZSTD_hash*() */
25-
#ifndef ZDICT_STATIC_LINKING_ONLY
26-
#define ZDICT_STATIC_LINKING_ONLY
27-
#endif
2828
#include "zdict.h"
29+
#include "cover.h"
2930

3031

3132
/*-*************************************
@@ -462,20 +463,20 @@ typedef struct FASTCOVER_tryParameters_data_s {
462463
* This function is thread safe if zstd is compiled with multithreaded support.
463464
* It takes its parameters as an *OWNING* opaque pointer to support threading.
464465
*/
465-
static void FASTCOVER_tryParameters(void *opaque)
466+
static void FASTCOVER_tryParameters(void* opaque)
466467
{
467468
/* Save parameters as local variables */
468-
FASTCOVER_tryParameters_data_t *const data = (FASTCOVER_tryParameters_data_t *)opaque;
469+
FASTCOVER_tryParameters_data_t *const data = (FASTCOVER_tryParameters_data_t*)opaque;
469470
const FASTCOVER_ctx_t *const ctx = data->ctx;
470471
const ZDICT_cover_params_t parameters = data->parameters;
471472
size_t dictBufferCapacity = data->dictBufferCapacity;
472473
size_t totalCompressedSize = ERROR(GENERIC);
473474
/* Initialize array to keep track of frequency of dmer within activeSegment */
474-
U16* segmentFreqs = (U16 *)calloc(((U64)1 << ctx->f), sizeof(U16));
475+
U16* segmentFreqs = (U16*)calloc(((U64)1 << ctx->f), sizeof(U16));
475476
/* Allocate space for hash table, dict, and freqs */
476-
BYTE *const dict = (BYTE * const)malloc(dictBufferCapacity);
477+
BYTE *const dict = (BYTE*)malloc(dictBufferCapacity);
477478
COVER_dictSelection_t selection = COVER_dictSelectionError(ERROR(GENERIC));
478-
U32 *freqs = (U32*) malloc(((U64)1 << ctx->f) * sizeof(U32));
479+
U32* freqs = (U32*) malloc(((U64)1 << ctx->f) * sizeof(U32));
479480
if (!segmentFreqs || !dict || !freqs) {
480481
DISPLAYLEVEL(1, "Failed to allocate buffers: out of memory\n");
481482
goto _cleanup;

fse.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* ******************************************************************
22
* FSE : Finite State Entropy codec
33
* Public Prototypes declaration
4-
* Copyright (c) 2013-2020, Yann Collet, Facebook, Inc.
4+
* Copyright (c) Yann Collet, Facebook, Inc.
55
*
66
* You can contact the author at :
77
* - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
@@ -336,8 +336,9 @@ size_t FSE_buildCTable_rle (FSE_CTable* ct, unsigned char symbolValue);
336336
/* FSE_buildCTable_wksp() :
337337
* Same as FSE_buildCTable(), but using an externally allocated scratch buffer (`workSpace`).
338338
* `wkspSize` must be >= `FSE_BUILD_CTABLE_WORKSPACE_SIZE_U32(maxSymbolValue, tableLog)` of `unsigned`.
339+
* See FSE_buildCTable_wksp() for breakdown of workspace usage.
339340
*/
340-
#define FSE_BUILD_CTABLE_WORKSPACE_SIZE_U32(maxSymbolValue, tableLog) (maxSymbolValue + 2 + (1ull << (tableLog - 2)))
341+
#define FSE_BUILD_CTABLE_WORKSPACE_SIZE_U32(maxSymbolValue, tableLog) (((maxSymbolValue + 2) + (1ull << (tableLog)))/2 + sizeof(U64)/sizeof(U32) /* additional 8 bytes for potential table overwrite */)
341342
#define FSE_BUILD_CTABLE_WORKSPACE_SIZE(maxSymbolValue, tableLog) (sizeof(unsigned) * FSE_BUILD_CTABLE_WORKSPACE_SIZE_U32(maxSymbolValue, tableLog))
342343
size_t FSE_buildCTable_wksp(FSE_CTable* ct, const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize);
343344

@@ -352,7 +353,7 @@ size_t FSE_buildDTable_raw (FSE_DTable* dt, unsigned nbBits);
352353
size_t FSE_buildDTable_rle (FSE_DTable* dt, unsigned char symbolValue);
353354
/**< build a fake FSE_DTable, designed to always generate the same symbolValue */
354355

355-
#define FSE_DECOMPRESS_WKSP_SIZE_U32(maxTableLog, maxSymbolValue) (FSE_DTABLE_SIZE_U32(maxTableLog) + FSE_BUILD_DTABLE_WKSP_SIZE_U32(maxTableLog, maxSymbolValue))
356+
#define FSE_DECOMPRESS_WKSP_SIZE_U32(maxTableLog, maxSymbolValue) (FSE_DTABLE_SIZE_U32(maxTableLog) + FSE_BUILD_DTABLE_WKSP_SIZE_U32(maxTableLog, maxSymbolValue) + (FSE_MAX_SYMBOL_VALUE + 1) / 2 + 1)
356357
#define FSE_DECOMPRESS_WKSP_SIZE(maxTableLog, maxSymbolValue) (FSE_DECOMPRESS_WKSP_SIZE_U32(maxTableLog, maxSymbolValue) * sizeof(unsigned))
357358
size_t FSE_decompress_wksp(void* dst, size_t dstCapacity, const void* cSrc, size_t cSrcSize, unsigned maxLog, void* workSpace, size_t wkspSize);
358359
/**< same as FSE_decompress(), using an externally allocated `workSpace` produced with `FSE_DECOMPRESS_WKSP_SIZE_U32(maxLog, maxSymbolValue)` */

0 commit comments

Comments
 (0)