refactor(compress): move frame progression dispatch to Rust

Move the public ZSTD_getFrameProgression MT-versus-single-thread worker-count
branch into a Rust-owned scalar projection. C continues to compute the
single-thread scalar inputs and keeps the private ZSTDMT context behind a
callback; the compile-time ZSTD_MULTITHREAD adapter remains local to C. Add
C/Rust layout assertions and focused Rust tests for both dispatch paths and
null-state fallback.

Test Plan:
- `git diff --cached --check`
- Not run: Cargo, make, builds, native tests, and heavy verification per request.
This commit is contained in:
2026-07-21 08:38:26 +02:00
parent e01f79fb1a
commit 11dc99899b
2 changed files with 194 additions and 12 deletions
+56 -12
View File
@@ -729,6 +729,34 @@ typedef char ZSTD_rust_compress_begin_advanced_state_layout[
ZSTD_frameProgression ZSTD_rust_frameProgression(U64 consumedSrcSize,
size_t buffered,
U64 producedCSize);
typedef ZSTD_frameProgression (*ZSTD_rust_frameProgressionMTorST_f)(
void* context);
typedef struct {
U64 consumedSrcSize;
U64 producedCSize;
size_t buffered;
void* mtContext;
ZSTD_rust_frameProgressionMTorST_f mtFrameProgression;
int nbWorkers;
} ZSTD_rust_frameProgressionMTorSTState;
typedef char ZSTD_rust_frame_progression_mt_or_st_state_layout[
(sizeof(ZSTD_rust_frameProgressionMTorST_f) == sizeof(void*)
&& offsetof(ZSTD_rust_frameProgressionMTorSTState, consumedSrcSize) == 0
&& offsetof(ZSTD_rust_frameProgressionMTorSTState, producedCSize)
== sizeof(U64)
&& offsetof(ZSTD_rust_frameProgressionMTorSTState, buffered)
== 2 * sizeof(U64)
&& offsetof(ZSTD_rust_frameProgressionMTorSTState, mtContext)
== 2 * sizeof(U64) + sizeof(size_t)
&& offsetof(ZSTD_rust_frameProgressionMTorSTState, mtFrameProgression)
== 2 * sizeof(U64) + sizeof(size_t) + sizeof(void*)
&& offsetof(ZSTD_rust_frameProgressionMTorSTState, nbWorkers)
== 2 * sizeof(U64) + sizeof(size_t) + 2 * sizeof(void*)
&& sizeof(ZSTD_rust_frameProgressionMTorSTState)
== (sizeof(void*) == 8 ? 48 : 32))
? 1 : -1];
ZSTD_frameProgression ZSTD_rust_frameProgressionMTorST(
const ZSTD_rust_frameProgressionMTorSTState* state);
size_t ZSTD_rust_resetCCtxForSimpleCompression(void* cctx);
size_t ZSTD_rust_prepareCCtxForSimpleCompression(void* cctx,
size_t srcSize,
@@ -4411,21 +4439,37 @@ size_t ZSTD_estimateCStreamSize(int compressionLevel)
* tells how much data has been consumed (input) and produced (output) for current frame.
* able to count progression inside worker threads (non-blocking mode).
*/
ZSTD_frameProgression ZSTD_getFrameProgression(const ZSTD_CCtx* cctx)
static ZSTD_frameProgression ZSTD_rust_frameProgression_MT(void* context)
{
#ifdef ZSTD_MULTITHREAD
if (cctx->appliedParams.nbWorkers > 0) {
return ZSTDMT_getFrameProgression(cctx->mtctx);
}
return ZSTDMT_getFrameProgression((const ZSTDMT_CCtx*)context);
#else
(void)context;
return (ZSTD_frameProgression){ 0 };
#endif
{
size_t const buffered = (cctx->inBuff == NULL) ? 0 :
cctx->inBuffPos - cctx->inToCompress;
if (buffered) assert(cctx->inBuffPos >= cctx->inToCompress);
assert(buffered <= ZSTD_BLOCKSIZE_MAX);
return ZSTD_rust_frameProgression(cctx->consumedSrcSize, buffered,
cctx->producedCSize);
} }
}
ZSTD_frameProgression ZSTD_getFrameProgression(const ZSTD_CCtx* cctx)
{
size_t const buffered = (cctx->inBuff == NULL) ? 0 :
cctx->inBuffPos - cctx->inToCompress;
ZSTD_rust_frameProgressionMTorSTState state = {
cctx->consumedSrcSize,
cctx->producedCSize,
buffered,
NULL,
NULL,
0
};
if (buffered) assert(cctx->inBuffPos >= cctx->inToCompress);
assert(buffered <= ZSTD_BLOCKSIZE_MAX);
#ifdef ZSTD_MULTITHREAD
state.mtContext = cctx->mtctx;
state.mtFrameProgression = ZSTD_rust_frameProgression_MT;
state.nbWorkers = (int)cctx->appliedParams.nbWorkers;
#endif
return ZSTD_rust_frameProgressionMTorST(&state);
}
typedef size_t (*ZSTD_rust_toFlushNow_f)(void* context);
typedef struct {