Skip to content

Commit 83cd977

Browse files
committed
Ported zstd v1.5.7
1 parent b66b28d commit 83cd977

Some content is hidden

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

74 files changed

+1777
-1239
lines changed

src/Zstd.Extern/x64/libzstd.dll

20.4 KB
Binary file not shown.

src/Zstd.Extern/x86/libzstd.dll

69 KB
Binary file not shown.

src/ZstdSharp/Unsafe/BIT_CStream_t.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
namespace ZstdSharp.Unsafe
22
{
3-
/*-******************************************
4-
* bitStream encoding API (write forward)
5-
********************************************/
63
/* bitStream can mix input from multiple sources.
74
* A critical property of these streams is that they encode and decode in **reverse** direction.
85
* So the first bit sequence you add will be the last to be read, like a LIFO stack.

src/ZstdSharp/Unsafe/BIT_DStream_t.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
namespace ZstdSharp.Unsafe
22
{
3+
/*-********************************************
4+
* bitStream decoding API (read backward)
5+
**********************************************/
36
public unsafe struct BIT_DStream_t
47
{
58
public nuint bitContainer;

src/ZstdSharp/Unsafe/Bitstream.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ private static nuint BIT_closeCStream(BIT_CStream_t* bitC)
158158
BIT_flushBits(bitC);
159159
if (bitC->ptr >= bitC->endPtr)
160160
return 0;
161-
return (nuint)(bitC->ptr - bitC->startPtr + (bitC->bitPos > 0 ? 1 : 0));
161+
return (nuint)(bitC->ptr - bitC->startPtr) + (nuint)(bitC->bitPos > 0 ? 1 : 0);
162162
}
163163

164164
/*-********************************************************

src/ZstdSharp/Unsafe/BlockSummary.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace ZstdSharp.Unsafe
2+
{
3+
public struct BlockSummary
4+
{
5+
public nuint nbSequences;
6+
public nuint blockSize;
7+
public nuint litSize;
8+
}
9+
}

src/ZstdSharp/Unsafe/Compiler.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,16 @@ namespace ZstdSharp.Unsafe
44
{
55
public static unsafe partial class Methods
66
{
7+
/* @return 1 if @u is a 2^n value, 0 otherwise
8+
* useful to check a value is valid for alignment restrictions */
9+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
10+
private static int ZSTD_isPower2(nuint u)
11+
{
12+
return (u & u - 1) == 0 ? 1 : 0;
13+
}
14+
715
/**
8-
* Helper function to perform a wrapped pointer difference without trigging
16+
* Helper function to perform a wrapped pointer difference without triggering
917
* UBSAN.
1018
*
1119
* @returns lhs - rhs with wrapping

src/ZstdSharp/Unsafe/ErrorPrivate.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ private static string ERR_getErrorString(ZSTD_ErrorCode code)
7070
return "Unsupported max Symbol Value : too large";
7171
case ZSTD_ErrorCode.ZSTD_error_maxSymbolValue_tooSmall:
7272
return "Specified maxSymbolValue is too small";
73+
case ZSTD_ErrorCode.ZSTD_error_cannotProduce_uncompressedBlock:
74+
return "This mode cannot generate an uncompressed block";
7375
case ZSTD_ErrorCode.ZSTD_error_stabilityCondition_notRespected:
7476
return "pledged buffer stability condition is not respected";
7577
case ZSTD_ErrorCode.ZSTD_error_dictionary_corrupted:

src/ZstdSharp/Unsafe/FPStats.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace ZstdSharp.Unsafe
2+
{
3+
public struct FPStats
4+
{
5+
public Fingerprint pastEvents;
6+
public Fingerprint newEvents;
7+
}
8+
}

src/ZstdSharp/Unsafe/Fingerprint.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace ZstdSharp.Unsafe
2+
{
3+
public unsafe struct Fingerprint
4+
{
5+
public fixed uint events[1024];
6+
public nuint nbEvents;
7+
}
8+
}

src/ZstdSharp/Unsafe/FseDecompress.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ private static nuint FSE_decompress_usingDTable_generic(void* dst, nuint maxDstS
152152

153153
FSE_initDState(&state1, &bitD, dt);
154154
FSE_initDState(&state2, &bitD, dt);
155+
if (BIT_reloadDStream(&bitD) == BIT_DStream_status.BIT_DStream_overflow)
156+
{
157+
return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected));
158+
}
159+
155160
for (; BIT_reloadDStream(&bitD) == BIT_DStream_status.BIT_DStream_unfinished && op < olimit; op += 4)
156161
{
157162
op[0] = fast != 0 ? FSE_decodeSymbolFast(&state1, &bitD) : FSE_decodeSymbol(&state1, &bitD);

src/ZstdSharp/Unsafe/HUF_DEltX1.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ public struct HUF_DEltX1
77
{
88
/* single-symbol decoding */
99
public byte nbBits;
10-
/* single-symbol decoding */
1110
public byte @byte;
1211
}
1312
}

src/ZstdSharp/Unsafe/HUF_DEltX2.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ public struct HUF_DEltX2
77
{
88
/* double-symbols decoding */
99
public ushort sequence;
10-
/* double-symbols decoding */
1110
public byte nbBits;
12-
/* double-symbols decoding */
1311
public byte length;
1412
}
1513
}

src/ZstdSharp/Unsafe/Hist.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,24 @@ private static bool HIST_isError(nuint code)
1313
/*-**************************************************************
1414
* Histogram functions
1515
****************************************************************/
16+
private static void HIST_add(uint* count, void* src, nuint srcSize)
17+
{
18+
byte* ip = (byte*)src;
19+
byte* end = ip + srcSize;
20+
while (ip < end)
21+
{
22+
count[*ip++]++;
23+
}
24+
}
25+
26+
/*! HIST_count_simple() :
27+
* Same as HIST_countFast(), this function is unsafe,
28+
* and will segfault if any value within `src` is `> *maxSymbolValuePtr`.
29+
* It is also a bit slower for large inputs.
30+
* However, it does not need any additional memory (not even on stack).
31+
* @return : count of the most frequent symbol.
32+
* Note this function doesn't produce any error (i.e. it must succeed).
33+
*/
1634
private static uint HIST_count_simple(uint* count, uint* maxSymbolValuePtr, void* src, nuint srcSize)
1735
{
1836
byte* ip = (byte*)src;

src/ZstdSharp/Unsafe/HufCompress.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,7 @@ private static uint HUF_optimalTableLog(uint maxTableLog, nuint srcSize, uint ma
11431143
* and occupies the same space as a table of HUF_WORKSPACE_SIZE_U64 unsigned */
11441144
private static nuint HUF_compress_internal(void* dst, nuint dstSize, void* src, nuint srcSize, uint maxSymbolValue, uint huffLog, HUF_nbStreams_e nbStreams, void* workSpace, nuint wkspSize, nuint* oldHufTable, HUF_repeat* repeat, int flags)
11451145
{
1146-
HUF_compress_tables_t* table = (HUF_compress_tables_t*)HUF_alignUpWorkspace(workSpace, &wkspSize, (nuint)sizeof(nuint));
1146+
HUF_compress_tables_t* table = (HUF_compress_tables_t*)HUF_alignUpWorkspace(workSpace, &wkspSize, sizeof(ulong));
11471147
byte* ostart = (byte*)dst;
11481148
byte* oend = ostart + dstSize;
11491149
byte* op = ostart;

0 commit comments

Comments
 (0)