Move subblock partitioning, literal and sequence section emission, entropy
fallback, and repcode repair into Rust. Keep a narrow C wrapper to read the
opaque compression context and invoke the existing C entropy-stat builder;
the Rust side owns only verified C-shaped leaf layouts.
Test Plan:
- cargo clippy
- cargo clippy --benches
- cargo clippy --tests
- cargo +nightly fmt
- cargo test zstd_compress_superblock::tests -- --nocapture
- cargo test --target i686-unknown-linux-gnu zstd_compress_superblock::tests
- byte-exact C control across 16 target-size and input-shape cases
- fuzzer, zstreamtest, invalidDictionaries, and bounded native test matrix
Refs: Rust sequence entropy port 887af204
56 lines
2.4 KiB
C
56 lines
2.4 KiB
C
/*
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under both the BSD-style license (found in the
|
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
|
* in the COPYING file in the root directory of this source tree).
|
|
* You may select, at your option, one of the above-listed licenses.
|
|
*/
|
|
|
|
/* The implementation lives in rust/src/zstd_compress_superblock.rs. Keep the
|
|
* context extraction here: ZSTD_CCtx is intentionally opaque to Rust, while
|
|
* the small sequence and entropy leaf layouts are asserted in both sources. */
|
|
#include "zstd_compress_superblock.h"
|
|
#include "zstd_compress_internal.h"
|
|
|
|
typedef char ZSTD_rust_superblock_seqdef_layout[(sizeof(SeqDef) == 8) ? 1 : -1];
|
|
typedef char ZSTD_rust_superblock_fse_layout[(sizeof(ZSTD_fseCTables_t) == 3552) ? 1 : -1];
|
|
typedef char ZSTD_rust_superblock_entropy_offset[
|
|
(offsetof(ZSTD_compressedBlockState_t, entropy) == 0) ? 1 : -1];
|
|
typedef char ZSTD_rust_superblock_rep_offset[
|
|
(offsetof(ZSTD_compressedBlockState_t, rep) == sizeof(ZSTD_entropyCTables_t)) ? 1 : -1];
|
|
typedef char ZSTD_rust_superblock_seqstore_long_length_pos[
|
|
(offsetof(SeqStore_t, longLengthPos) == 9 * sizeof(size_t) + 4) ? 1 : -1];
|
|
typedef char ZSTD_rust_superblock_seqstore_layout[
|
|
(sizeof(SeqStore_t) == 9 * sizeof(size_t) + 8) ? 1 : -1];
|
|
|
|
size_t ZSTD_rust_compressSuperBlock(
|
|
const SeqStore_t* seqStore,
|
|
const ZSTD_compressedBlockState_t* prevCBlock,
|
|
ZSTD_compressedBlockState_t* nextCBlock,
|
|
const ZSTD_CCtx_params* cctxParams,
|
|
void* workspace, size_t wkspSize,
|
|
int bmi2, U32 windowLog, size_t targetCBlockSize,
|
|
void* dst, size_t dstCapacity,
|
|
const void* src, size_t srcSize,
|
|
U32 lastBlock);
|
|
|
|
size_t ZSTD_compressSuperBlock(ZSTD_CCtx* zc,
|
|
void* dst, size_t dstCapacity,
|
|
const void* src, size_t srcSize,
|
|
unsigned lastBlock)
|
|
{
|
|
return ZSTD_rust_compressSuperBlock(
|
|
&zc->seqStore,
|
|
zc->blockState.prevCBlock,
|
|
zc->blockState.nextCBlock,
|
|
&zc->appliedParams,
|
|
zc->tmpWorkspace, zc->tmpWkspSize,
|
|
zc->bmi2, zc->appliedParams.cParams.windowLog,
|
|
zc->appliedParams.targetCBlockSize,
|
|
dst, dstCapacity,
|
|
src, srcSize,
|
|
lastBlock);
|
|
}
|