Skip to content

Commit

Permalink
Workaround for .NET Native
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-st committed Apr 24, 2024
1 parent 106a59a commit 2704150
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 89 deletions.
7 changes: 7 additions & 0 deletions src/ZstdSharp/Unsafe/ZSTD_blockCompressor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using System.Runtime.InteropServices;

namespace ZstdSharp.Unsafe
{
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public unsafe delegate nuint ZSTD_blockCompressor(ZSTD_matchState_t* bs, seqStore_t* seqStore, uint* rep, void* src, nuint srcSize);
}
7 changes: 7 additions & 0 deletions src/ZstdSharp/Unsafe/ZSTD_getAllMatchesFn.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using System.Runtime.InteropServices;

namespace ZstdSharp.Unsafe
{
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public unsafe delegate uint ZSTD_getAllMatchesFn(ZSTD_match_t* param0, ZSTD_matchState_t* param1, uint* param2, byte* param3, byte* param4, uint* rep, uint ll0, uint lengthToBeat);
}
130 changes: 65 additions & 65 deletions src/ZstdSharp/Unsafe/ZstdCompress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3098,94 +3098,94 @@ private static nuint ZSTD_entropyCompressSeqStore(seqStore_t* seqStorePtr, ZSTD_
return cSize;
}

private static readonly void*[][] blockCompressor = new void*[4][]
{
new void*[10]
{
(delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> )(&ZSTD_compressBlock_fast),
(delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> )(&ZSTD_compressBlock_fast),
(delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> )(&ZSTD_compressBlock_doubleFast),
(delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> )(&ZSTD_compressBlock_greedy),
(delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> )(&ZSTD_compressBlock_lazy),
(delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> )(&ZSTD_compressBlock_lazy2),
(delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> )(&ZSTD_compressBlock_btlazy2),
(delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> )(&ZSTD_compressBlock_btopt),
(delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> )(&ZSTD_compressBlock_btultra),
(delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> )(&ZSTD_compressBlock_btultra2)
private static readonly ZSTD_blockCompressor[][] blockCompressor = new ZSTD_blockCompressor[4][]
{
new ZSTD_blockCompressor[10]
{
ZSTD_compressBlock_fast,
ZSTD_compressBlock_fast,
ZSTD_compressBlock_doubleFast,
ZSTD_compressBlock_greedy,
ZSTD_compressBlock_lazy,
ZSTD_compressBlock_lazy2,
ZSTD_compressBlock_btlazy2,
ZSTD_compressBlock_btopt,
ZSTD_compressBlock_btultra,
ZSTD_compressBlock_btultra2
},
new void*[10]
{
(delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> )(&ZSTD_compressBlock_fast_extDict),
(delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> )(&ZSTD_compressBlock_fast_extDict),
(delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> )(&ZSTD_compressBlock_doubleFast_extDict),
(delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> )(&ZSTD_compressBlock_greedy_extDict),
(delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> )(&ZSTD_compressBlock_lazy_extDict),
(delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> )(&ZSTD_compressBlock_lazy2_extDict),
(delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> )(&ZSTD_compressBlock_btlazy2_extDict),
(delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> )(&ZSTD_compressBlock_btopt_extDict),
(delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> )(&ZSTD_compressBlock_btultra_extDict),
(delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> )(&ZSTD_compressBlock_btultra_extDict)
new ZSTD_blockCompressor[10]
{
ZSTD_compressBlock_fast_extDict,
ZSTD_compressBlock_fast_extDict,
ZSTD_compressBlock_doubleFast_extDict,
ZSTD_compressBlock_greedy_extDict,
ZSTD_compressBlock_lazy_extDict,
ZSTD_compressBlock_lazy2_extDict,
ZSTD_compressBlock_btlazy2_extDict,
ZSTD_compressBlock_btopt_extDict,
ZSTD_compressBlock_btultra_extDict,
ZSTD_compressBlock_btultra_extDict
},
new void*[10]
{
(delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> )(&ZSTD_compressBlock_fast_dictMatchState),
(delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> )(&ZSTD_compressBlock_fast_dictMatchState),
(delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> )(&ZSTD_compressBlock_doubleFast_dictMatchState),
(delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> )(&ZSTD_compressBlock_greedy_dictMatchState),
(delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> )(&ZSTD_compressBlock_lazy_dictMatchState),
(delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> )(&ZSTD_compressBlock_lazy2_dictMatchState),
(delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> )(&ZSTD_compressBlock_btlazy2_dictMatchState),
(delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> )(&ZSTD_compressBlock_btopt_dictMatchState),
(delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> )(&ZSTD_compressBlock_btultra_dictMatchState),
(delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> )(&ZSTD_compressBlock_btultra_dictMatchState)
new ZSTD_blockCompressor[10]
{
ZSTD_compressBlock_fast_dictMatchState,
ZSTD_compressBlock_fast_dictMatchState,
ZSTD_compressBlock_doubleFast_dictMatchState,
ZSTD_compressBlock_greedy_dictMatchState,
ZSTD_compressBlock_lazy_dictMatchState,
ZSTD_compressBlock_lazy2_dictMatchState,
ZSTD_compressBlock_btlazy2_dictMatchState,
ZSTD_compressBlock_btopt_dictMatchState,
ZSTD_compressBlock_btultra_dictMatchState,
ZSTD_compressBlock_btultra_dictMatchState
},
new void*[10]
new ZSTD_blockCompressor[10]
{
null,
null,
null,
(delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> )(&ZSTD_compressBlock_greedy_dedicatedDictSearch),
(delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> )(&ZSTD_compressBlock_lazy_dedicatedDictSearch),
(delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> )(&ZSTD_compressBlock_lazy2_dedicatedDictSearch),
ZSTD_compressBlock_greedy_dedicatedDictSearch,
ZSTD_compressBlock_lazy_dedicatedDictSearch,
ZSTD_compressBlock_lazy2_dedicatedDictSearch,
null,
null,
null,
null
}
};
private static readonly void*[][] rowBasedBlockCompressors = new void*[4][]
private static readonly ZSTD_blockCompressor[][] rowBasedBlockCompressors = new ZSTD_blockCompressor[4][]
{
new void*[3]
new ZSTD_blockCompressor[3]
{
(delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> )(&ZSTD_compressBlock_greedy_row),
(delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> )(&ZSTD_compressBlock_lazy_row),
(delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> )(&ZSTD_compressBlock_lazy2_row)
ZSTD_compressBlock_greedy_row,
ZSTD_compressBlock_lazy_row,
ZSTD_compressBlock_lazy2_row
},
new void*[3]
new ZSTD_blockCompressor[3]
{
(delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> )(&ZSTD_compressBlock_greedy_extDict_row),
(delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> )(&ZSTD_compressBlock_lazy_extDict_row),
(delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> )(&ZSTD_compressBlock_lazy2_extDict_row)
ZSTD_compressBlock_greedy_extDict_row,
ZSTD_compressBlock_lazy_extDict_row,
ZSTD_compressBlock_lazy2_extDict_row
},
new void*[3]
new ZSTD_blockCompressor[3]
{
(delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> )(&ZSTD_compressBlock_greedy_dictMatchState_row),
(delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> )(&ZSTD_compressBlock_lazy_dictMatchState_row),
(delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> )(&ZSTD_compressBlock_lazy2_dictMatchState_row)
ZSTD_compressBlock_greedy_dictMatchState_row,
ZSTD_compressBlock_lazy_dictMatchState_row,
ZSTD_compressBlock_lazy2_dictMatchState_row
},
new void*[3]
new ZSTD_blockCompressor[3]
{
(delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> )(&ZSTD_compressBlock_greedy_dedicatedDictSearch_row),
(delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> )(&ZSTD_compressBlock_lazy_dedicatedDictSearch_row),
(delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint> )(&ZSTD_compressBlock_lazy2_dedicatedDictSearch_row)
ZSTD_compressBlock_greedy_dedicatedDictSearch_row,
ZSTD_compressBlock_lazy_dedicatedDictSearch_row,
ZSTD_compressBlock_lazy2_dedicatedDictSearch_row
}
};
/* ZSTD_selectBlockCompressor() :
* Not static, but internal use only (used by long distance matcher)
* assumption : strat is a valid strategy */
private static void* ZSTD_selectBlockCompressor(ZSTD_strategy strat, ZSTD_paramSwitch_e useRowMatchFinder, ZSTD_dictMode_e dictMode)
private static ZSTD_blockCompressor ZSTD_selectBlockCompressor(ZSTD_strategy strat, ZSTD_paramSwitch_e useRowMatchFinder, ZSTD_dictMode_e dictMode)
{
void* selectedCompressor;
ZSTD_blockCompressor selectedCompressor;
assert(ZSTD_cParam_withinBounds(ZSTD_cParameter.ZSTD_c_strategy, (int)strat) != 0);
if (ZSTD_rowMatchFinderUsed(strat, useRowMatchFinder) != 0)
{
Expand Down Expand Up @@ -3391,17 +3391,17 @@ private static nuint ZSTD_buildSeqStore(ZSTD_CCtx_s* zc, void* src, nuint srcSiz
}

{
void* blockCompressor = ZSTD_selectBlockCompressor(zc->appliedParams.cParams.strategy, zc->appliedParams.useRowMatchFinder, dictMode);
ZSTD_blockCompressor blockCompressor = ZSTD_selectBlockCompressor(zc->appliedParams.cParams.strategy, zc->appliedParams.useRowMatchFinder, dictMode);
ms->ldmSeqStore = null;
lastLLSize = ((delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint>)blockCompressor)(ms, &zc->seqStore, zc->blockState.nextCBlock->rep, src, srcSize);
lastLLSize = blockCompressor(ms, &zc->seqStore, zc->blockState.nextCBlock->rep, src, srcSize);
}
}
}
else
{
void* blockCompressor = ZSTD_selectBlockCompressor(zc->appliedParams.cParams.strategy, zc->appliedParams.useRowMatchFinder, dictMode);
ZSTD_blockCompressor blockCompressor = ZSTD_selectBlockCompressor(zc->appliedParams.cParams.strategy, zc->appliedParams.useRowMatchFinder, dictMode);
ms->ldmSeqStore = null;
lastLLSize = ((delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint>)blockCompressor)(ms, &zc->seqStore, zc->blockState.nextCBlock->rep, src, srcSize);
lastLLSize = blockCompressor(ms, &zc->seqStore, zc->blockState.nextCBlock->rep, src, srcSize);
}

{
Expand Down
8 changes: 4 additions & 4 deletions src/ZstdSharp/Unsafe/ZstdLdm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ private static nuint ZSTD_ldm_blockCompress(rawSeqStore_t* rawSeqStore, ZSTD_mat
{
ZSTD_compressionParameters* cParams = &ms->cParams;
uint minMatch = cParams->minMatch;
void* blockCompressor = ZSTD_selectBlockCompressor(cParams->strategy, useRowMatchFinder, ZSTD_matchState_dictMode(ms));
ZSTD_blockCompressor blockCompressor = ZSTD_selectBlockCompressor(cParams->strategy, useRowMatchFinder, ZSTD_matchState_dictMode(ms));
/* Input bounds */
byte* istart = (byte*)src;
byte* iend = istart + srcSize;
Expand All @@ -699,7 +699,7 @@ private static nuint ZSTD_ldm_blockCompress(rawSeqStore_t* rawSeqStore, ZSTD_mat
{
nuint lastLLSize;
ms->ldmSeqStore = rawSeqStore;
lastLLSize = ((delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint>)blockCompressor)(ms, seqStore, rep, src, srcSize);
lastLLSize = blockCompressor(ms, seqStore, rep, src, srcSize);
ZSTD_ldm_skipRawSeqStoreBytes(rawSeqStore, srcSize);
return lastLLSize;
}
Expand All @@ -717,7 +717,7 @@ private static nuint ZSTD_ldm_blockCompress(rawSeqStore_t* rawSeqStore, ZSTD_mat
ZSTD_ldm_fillFastTables(ms, ip);
{
int i;
nuint newLitLength = ((delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint>)blockCompressor)(ms, seqStore, rep, ip, sequence.litLength);
nuint newLitLength = blockCompressor(ms, seqStore, rep, ip, sequence.litLength);
ip += sequence.litLength;
for (i = 3 - 1; i > 0; i--)
rep[i] = rep[i - 1];
Expand All @@ -730,7 +730,7 @@ private static nuint ZSTD_ldm_blockCompress(rawSeqStore_t* rawSeqStore, ZSTD_mat

ZSTD_ldm_limitTableUpdate(ms, ip);
ZSTD_ldm_fillFastTables(ms, ip);
return ((delegate* managed<ZSTD_matchState_t*, seqStore_t*, uint*, void*, nuint, nuint>)blockCompressor)(ms, seqStore, rep, ip, (nuint)(iend - ip));
return blockCompressor(ms, seqStore, rep, ip, (nuint)(iend - ip));
}
}
}
Loading

0 comments on commit 2704150

Please sign in to comment.