Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/common/huf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ use libc::size_t;
use crate::lib::common::fse::FSE_DECOMPRESS_WKSP_SIZE_U32;
use crate::lib::zstd::ZSTD_btultra;

pub(crate) const HUF_BLOCKSIZE_MAX: core::ffi::c_int = 128 * 1024;
pub(crate) const HUF_BLOCKSIZE_MAX: usize = 128 * 1024;

pub(crate) const HUF_WORKSPACE_SIZE: core::ffi::c_int = ((8) << 10) + 512;
pub(crate) const HUF_WORKSPACE_SIZE: usize = (8 << 10) + 512;

/// Max runtime value of tableLog (due to static allocation); can be modified up to HUF_TABLELOG_ABSOLUTEMAX.
pub(crate) const HUF_TABLELOG_MAX: usize = 12;
/// Default tableLog value when none specified
pub(crate) const HUF_TABLELOG_DEFAULT: core::ffi::c_int = 11;
pub(crate) const HUF_SYMBOLVALUE_MAX: core::ffi::c_int = 255;
pub(crate) const HUF_TABLELOG_DEFAULT: u32 = 11;
pub(crate) const HUF_SYMBOLVALUE_MAX: u32 = 255;

pub(crate) const HUF_CTABLE_WORKSPACE_SIZE_U32: usize =
(4 * (HUF_SYMBOLVALUE_MAX as usize + 1)) + 192;
Expand All @@ -23,7 +23,7 @@ const _: () = assert!(
"HUF_TABLELOG_MAX is too large !"
);

pub(crate) const HUF_CTABLEBOUND: core::ffi::c_int = 129;
pub(crate) const HUF_CTABLEBOUND: usize = 129;

pub(crate) type HUF_CElt = size_t;

Expand Down
18 changes: 9 additions & 9 deletions lib/compress/huf_compress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ pub unsafe fn HUF_writeCTable_wksp(
if workspaceSize < ::core::mem::size_of::<HUF_WriteCTableWksp>() {
return Error::GENERIC.to_error_code();
}
if maxSymbolValue > HUF_SYMBOLVALUE_MAX as core::ffi::c_uint {
if maxSymbolValue > HUF_SYMBOLVALUE_MAX {
return Error::maxSymbolValue_tooLarge.to_error_code();
}
*((*wksp).bitsToWeight).as_mut_ptr() = 0;
Expand Down Expand Up @@ -672,7 +672,7 @@ unsafe fn HUF_sort(
n = n.wrapping_add(1);
}
}
pub const STARTNODE: core::ffi::c_int = HUF_SYMBOLVALUE_MAX + 1;
pub const STARTNODE: core::ffi::c_int = HUF_SYMBOLVALUE_MAX as i32 + 1;
unsafe fn HUF_buildTree(huffNode: *mut nodeElt, maxSymbolValue: u32) -> core::ffi::c_int {
let huffNode0 = huffNode.sub(1);
let mut nonNullRank: core::ffi::c_int = 0;
Expand Down Expand Up @@ -817,9 +817,9 @@ pub unsafe fn HUF_buildCTable_wksp(
return Error::workSpace_tooSmall.to_error_code();
}
if maxNbBits == 0 {
maxNbBits = HUF_TABLELOG_DEFAULT as u32;
maxNbBits = HUF_TABLELOG_DEFAULT;
}
if maxSymbolValue > HUF_SYMBOLVALUE_MAX as u32 {
if maxSymbolValue > HUF_SYMBOLVALUE_MAX {
return Error::maxSymbolValue_tooLarge.to_error_code();
}
ptr::write_bytes(
Expand Down Expand Up @@ -879,7 +879,7 @@ pub unsafe fn HUF_validateCTable(
(bad == 0) as core::ffi::c_int
}
pub fn HUF_compressBound(size: size_t) -> size_t {
(HUF_CTABLEBOUND as size_t).wrapping_add(size.wrapping_add(size >> 8).wrapping_add(8))
HUF_CTABLEBOUND.wrapping_add(size.wrapping_add(size >> 8).wrapping_add(8))
}
pub const HUF_BITS_IN_CONTAINER: size_t = (::core::mem::size_of::<size_t>()).wrapping_mul(8);
unsafe fn HUF_initCStream(
Expand Down Expand Up @@ -1418,20 +1418,20 @@ unsafe fn HUF_compress_internal(
if dstSize == 0 {
return 0;
}
if srcSize > HUF_BLOCKSIZE_MAX as size_t {
if srcSize > HUF_BLOCKSIZE_MAX {
return Error::srcSize_wrong.to_error_code();
}
if huffLog > HUF_TABLELOG_MAX as core::ffi::c_uint {
return Error::tableLog_tooLarge.to_error_code();
}
if maxSymbolValue > HUF_SYMBOLVALUE_MAX as core::ffi::c_uint {
if maxSymbolValue > HUF_SYMBOLVALUE_MAX {
return Error::maxSymbolValue_tooLarge.to_error_code();
}
if maxSymbolValue == 0 {
maxSymbolValue = HUF_SYMBOLVALUE_MAX as core::ffi::c_uint;
maxSymbolValue = HUF_SYMBOLVALUE_MAX;
}
if huffLog == 0 {
huffLog = HUF_TABLELOG_DEFAULT as core::ffi::c_uint;
huffLog = HUF_TABLELOG_DEFAULT;
}
if flags & HUF_flags_preferRepeat as core::ffi::c_int != 0
&& !repeat.is_null()
Expand Down
13 changes: 6 additions & 7 deletions lib/compress/zstd_compress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5658,7 +5658,7 @@ unsafe fn ZSTD_buildBlockEntropyStats_literals(
.wrapping_mul(::core::mem::size_of::<core::ffi::c_uint>());
let nodeWksp = countWkspStart.add(countWkspSize);
let nodeWkspSize = wkspEnd.offset_from_unsigned(nodeWksp);
let mut maxSymbolValue = HUF_SYMBOLVALUE_MAX as core::ffi::c_uint;
let mut maxSymbolValue = HUF_SYMBOLVALUE_MAX;
let mut huffLog = LitHufLog;
let mut repeat = (*prevHuf).repeatMode;
libc::memcpy(
Expand Down Expand Up @@ -5904,7 +5904,7 @@ unsafe fn ZSTD_estimateBlockSize_literal(
writeEntropy: core::ffi::c_int,
) -> size_t {
let countWksp = workspace as *mut core::ffi::c_uint;
let mut maxSymbolValue = HUF_SYMBOLVALUE_MAX as core::ffi::c_uint;
let mut maxSymbolValue = HUF_SYMBOLVALUE_MAX;
let literalSectionHeaderSize =
(3 + (litSize >= ((1) << 10) as size_t) as core::ffi::c_int
+ (litSize >= (16 * ((1) << 10)) as size_t) as core::ffi::c_int) as size_t;
Expand Down Expand Up @@ -8494,7 +8494,7 @@ pub unsafe extern "C" fn ZSTD_estimateCDictSize_advanced(
dictLoadMethod: ZSTD_dictLoadMethod_e,
) -> size_t {
(ZSTD_cwksp_alloc_size(::core::mem::size_of::<ZSTD_CDict>()))
.wrapping_add(ZSTD_cwksp_alloc_size(HUF_WORKSPACE_SIZE as size_t))
.wrapping_add(ZSTD_cwksp_alloc_size(HUF_WORKSPACE_SIZE))
.wrapping_add(ZSTD_sizeof_matchState(
&cParams,
ZSTD_resolveRowMatchFinderMode(ZSTD_ParamSwitch_e::ZSTD_ps_auto, &cParams),
Expand Down Expand Up @@ -8569,8 +8569,7 @@ unsafe fn ZSTD_initCDict_internal(
(*cdict).dictContentSize = dictSize;
(*cdict).dictContentType = dictContentType;
(*cdict).entropyWorkspace =
ZSTD_cwksp_reserve_object(&mut (*cdict).workspace, HUF_WORKSPACE_SIZE as size_t)
as *mut u32;
ZSTD_cwksp_reserve_object(&mut (*cdict).workspace, HUF_WORKSPACE_SIZE) as *mut u32;
ZSTD_reset_compressedBlockState(&mut (*cdict).cBlockState);
let err_code = ZSTD_reset_matchState(
&mut (*cdict).matchState,
Expand Down Expand Up @@ -8615,7 +8614,7 @@ unsafe fn ZSTD_createCDict_advanced_internal(
customMem: ZSTD_customMem,
) -> *mut ZSTD_CDict {
let workspaceSize = (ZSTD_cwksp_alloc_size(::core::mem::size_of::<ZSTD_CDict>()))
.wrapping_add(ZSTD_cwksp_alloc_size(HUF_WORKSPACE_SIZE as size_t))
.wrapping_add(ZSTD_cwksp_alloc_size(HUF_WORKSPACE_SIZE))
.wrapping_add(ZSTD_sizeof_matchState(
&cParams,
useRowMatchFinder,
Expand Down Expand Up @@ -8896,7 +8895,7 @@ pub unsafe extern "C" fn ZSTD_initStaticCDict(
::core::mem::size_of::<*mut core::ffi::c_void>(),
))
})
.wrapping_add(ZSTD_cwksp_alloc_size(HUF_WORKSPACE_SIZE as size_t))
.wrapping_add(ZSTD_cwksp_alloc_size(HUF_WORKSPACE_SIZE))
.wrapping_add(matchStateSize);
let mut cdict = core::ptr::null_mut::<ZSTD_CDict>();
let mut params = ZSTD_CCtx_params_s {
Expand Down
2 changes: 1 addition & 1 deletion lib/compress/zstd_compress_literals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ pub unsafe fn ZSTD_compressLiterals(
dstCapacity.wrapping_sub(lhSize),
src,
srcSize,
HUF_SYMBOLVALUE_MAX as core::ffi::c_uint,
HUF_SYMBOLVALUE_MAX,
LitHufLog,
entropyWorkspace,
entropyWorkspaceSize,
Expand Down
6 changes: 3 additions & 3 deletions lib/dictBuilder/cover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ fn train_from_buffer_cover(
}
return Error::srcSize_wrong.to_error_code();
}
if dictBufferCapacity < ZDICT_DICTSIZE_MIN as size_t {
if dictBufferCapacity < ZDICT_DICTSIZE_MIN {
if displayLevel >= 1 {
eprintln!("dictBufferCapacity must be at least {}", 256,);
}
Expand Down Expand Up @@ -1129,7 +1129,7 @@ pub(super) fn COVER_selectDict(
}
largestDict = dictContentSize;
largestCompressed = totalCompressedSize;
dictContentSize = ZDICT_DICTSIZE_MIN as size_t;
dictContentSize = ZDICT_DICTSIZE_MIN;
while dictContentSize < largestDict {
candidateDictBuffer[..largestDict].copy_from_slice(&largestDictbuffer[..largestDict]);
dictContentSize = unsafe {
Expand Down Expand Up @@ -1349,7 +1349,7 @@ unsafe fn optimize_train_from_buffer_cover(
}
return Error::srcSize_wrong.to_error_code();
}
if dict.len() < ZDICT_DICTSIZE_MIN as size_t {
if dict.len() < ZDICT_DICTSIZE_MIN {
if displayLevel >= 1 {
eprintln!("dictBufferCapacity must be at least {}", 256);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/dictBuilder/fastcover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ fn train_from_buffer_fastcover(
}
return Error::srcSize_wrong.to_error_code();
}
if dictBufferCapacity < ZDICT_DICTSIZE_MIN as size_t {
if dictBufferCapacity < ZDICT_DICTSIZE_MIN {
if displayLevel >= 1 {
eprintln!("dictBufferCapacity must be at least {}", 256);
}
Expand Down Expand Up @@ -773,7 +773,7 @@ fn optimize_train_from_buffer_fastcover(
}
return Error::srcSize_wrong.to_error_code();
}
if dict.len() < ZDICT_DICTSIZE_MIN as size_t {
if dict.len() < ZDICT_DICTSIZE_MIN {
if displayLevel >= 1 {
eprintln!("dictBufferCapacity must be at least {}", 256);
}
Expand Down
Loading