823 Commits
Author SHA1 Message Date
ddidderr fc4da0531a feat(rust): move wildcopy behind a narrow ABI leaf
Keep the C header's ZSTD_wildcopy signature as the enum-facing wrapper, but
move its over-copying implementation into rust/src/mem.rs. The wrapper passes
the enum's int representation to ZSTD_rust_wildcopy, where only the two valid
values are converted to ZstdOverlap. This leaves C's ZSTD_copy16/COPY16
helpers available to their direct compression callers and removes the now
unused COPY8 helper. ZSTD_copy16 is marked unused-safe for C translation units
that include the shared header without calling that direct helper.

The Rust leaf preserves the original first-copy behavior for zero and short
lengths, the source-before-destination 8-byte do-while path, the no-overlap
distance assertion, and the first-then-two-COPY16 loop. Its ABI contract does
not take ownership of caller buffers. ABI tests use 32-byte padded buffers and
exercise no-overlap plus offsets 8 and 15 across the boundary lengths, checking
both copied bytes and guard regions.

Test Plan:
- `cargo test mem::tests` -- passed (4 tests)
- `make lib-nomt` and `make lib-mt` -- passed
- `make -C tests test-zstream` -- passed
- `make -C tests test-fullbench` -- completed; its `-P0` run printed the
  existing Scenario 17 diagnostic, but the target returned normally
- `cargo clippy`, `cargo clippy --benches`, `cargo clippy --tests`,
  `cargo +nightly fmt`, then the same three clippy commands -- passed on the
  final repeat
- `git diff --cached --check` -- passed
2026-07-18 16:14:20 +02:00
ddidderr 26b5e202ee feat(rust): port worker pool and pthread wrappers
Replace the common worker pool and debug pthread wrappers with ABI-compatible
Rust implementations. The pool preserves bounded-queue, resize, drain-on-free,
custom-allocator, and no-thread behavior while C supplies only the build-time
multithreading configuration bit.

This moves runtime support without changing C tests or public headers. Codec
and CLI implementations remain C while their dependencies are migrated.

Test Plan:
- cargo fmt --check
- cargo test --all-targets
- cargo clippy --all-targets -- -D warnings
- cargo build --release
- make -C tests poolTests
- ./tests/poolTests
- compile pool and threading shims with -Werror in MT and no-thread modes

Refs: rust/README.md
2026-07-10 20:05:35 +02:00
ddidderr a0f2b2a14c feat(rust): port FSE entropy decoding
Move FSE normalized-count parsing, Huffman statistics decoding, FSE table
construction, and FSE stream decompression into Rust. The C source files now
only retain the headers needed by the existing build configuration.

The implementation keeps the public C ABI and verifies C-generated balanced,
skewed, and Huffman-statistics streams. Compression and the higher-level frame
decoder remain C for now.

Test Plan:
- cargo fmt --check
- cargo test --all-targets
- cargo clippy --all-targets -- -D warnings
- cargo build --release
- compile both C shims with -Werror and -Wredundant-decls

Refs: rust/README.md
2026-07-10 20:04:26 +02:00
ddidderr 554a30da41 fix(rust): remove redundant common shim declarations
The common C shims include headers that already declare every Rust-exported
symbol. Remove duplicate declarations so strict C builds do not report
redundant declarations or macro-expanded aliases.

The shims remain intentionally declaration-only; Rust still owns the exported
implementation.

Test Plan:
- compile debug.c with -Wall -Wextra -Werror
- compile error_private.c with -Wall -Wextra -Werror
- compile zstd_common.c with -Wall -Wextra -Werror

Refs: rust/README.md
2026-07-10 20:03:34 +02:00
ddidderr 089f8e5b4d feat(rust): add common primitive compatibility layer
Introduce the Rust static library and move the shared byte, bitstream, CPU,
error, xxHash, debug, and public-common implementations into it. Thin C shims
preserve the existing header-driven C build while original tests link the Rust
archive.

This establishes the ABI-safe foundation for later codec and CLI ports;
entropy coding, runtime support, codecs, dictionaries, and the CLI remain C.
The top-down migration map documents that boundary and its validation path.

Test Plan:
- cargo fmt --check
- cargo test --all-targets
- cargo clippy --all-targets -- -D warnings
- cargo build --release

Refs: rust/README.md
2026-07-10 20:02:17 +02:00
Yann Collet 54e9d46db4 added __clang__ to compiler-specific alignment attribute
when clang is used within msvc, `__GNUC__` isn't defined,
so testing `__clang__` explicitly is required.
2025-02-05 13:48:24 -08:00
Yann Collet bcf404c0ab changed C11 keyword to _Alignas
so that it doesn't depend on #include
2025-02-05 13:25:14 -08:00
Yann ColletandGitHub 26a2b5d5df Merge pull request #4265 from pps83/static-bmi2-check
Check `STATIC_BMI2` instead of `STATIC_BMI2 == 1`
2025-01-31 14:39:20 -08:00
Pavel P 0cda0100ea fix formatting 2025-01-24 03:03:22 +02:00
Pavel P f7e8fc339b Check STATIC_BMI2 instead of STATIC_BMI2 == 1 2025-01-24 03:03:21 +02:00
Pavel P 0a183620a3 Reorder __BMI2__ check
+ if `__BMI2__` defined, then set STATIC_BMI2 for all compilers
 + use `defined(_MSC_VER) && defined(__AVX2__)` as fallback for ms compiler
2025-01-24 03:02:47 +02:00
Pavel P d486ccc9e9 Update comment for STATIC_BMI2 macro 2025-01-24 03:02:47 +02:00
Pavel P 1b15e888fc Move STATIC_BMI2 block as-is to portability_macros.h 2025-01-24 03:02:46 +02:00
Yann ColletandGitHub a7b59bcb7f Merge pull request #4257 from pps83/dev-x64test
Use _M_X64 only without mixing with _M_AMD64
2025-01-23 12:50:27 -08:00
Yann ColletandGitHub 55c0c5bdca Merge pull request #4258 from pps83/dev-ZSTD_ALIGNED
Implement ZSTD_ALIGNED for ms compiler
2025-01-22 15:09:35 -08:00
Pavel P a0872a8372 Implement ZSTD_ALIGNED for ms compiler 2025-01-21 02:33:25 +02:00
Pavel P 6c1d1cc600 Use _M_X64 only without mixing with _M_AMD64 2025-01-21 02:27:39 +02:00
Yann ColletandGitHub 48b186f76b Merge pull request #4253 from facebook/BitContainerType
minor: use BitContainerType when appropriate
2025-01-19 18:35:36 -08:00
Yann Collet 82346b92bb minor: generalize BitContainerType
technically equivalent to `size_t`,
but it's the proper type for underlying register representation.

This makes it possible to control register type, and therefore size, independently from `size_t`,
which can be useful on systems where `size_t` is 32-bit, while the architecture supports 64-bit registers.
2025-01-19 18:05:57 -08:00
Yann Collet 4bbf4a285d enable DYNAMIC_BMI2 by default on x86 (32-bit mode)
so far was only enabled for x64 (64-bit mode)
2025-01-19 08:11:59 -08:00
Yann Collet a556559841 no longer limit automated BMI2 detection to x64
this was previously no triggered in x86 32-bit mode,
due to a limitation in `bitstream.h`, that was fixed in #4248.

Now, `bmi2` will be automatically detected and triggered
at compilation time, if the corresponding instruction set is enabled,
even in 32-bit mode.

Also: updated library documentation, to feature STATIC_BMI2 build variable
2025-01-19 00:08:57 -08:00
Yann Collet 27d7940631 minor: cosmetic, indentation 2025-01-18 22:49:16 -08:00
Yann Collet 9efb09749b added a CI test for x86 32-bit + avx2 combination
which is expected to be quite rare, but nonetheless possible.

This test is initially expected to fail, before integration of #4248 fix
2025-01-18 22:49:16 -08:00
Yann ColletandGitHub a469e7c083 Merge pull request #4248 from pps83/dev-bzhi32
Use _bzhi_u32 for 32-bit builds when building with STATIC_BMI2
2025-01-18 22:48:24 -08:00
Pavel P fcd684b9b4 update sizeof check 2025-01-19 02:37:35 +02:00
Pavel P d60c4d75e9 remove unrelated changes 2025-01-19 02:36:00 +02:00
Pavel P 462484d5dc change to BitContainerType 2025-01-19 02:34:41 +02:00
Pavel P 26e5fb3614 handle 32bit size_t when building for x64 2025-01-18 23:37:50 +02:00
Pavel P 936927a427 handle 32bit size_t when building for x64 2025-01-18 23:30:55 +02:00
Pavel P ee17f4c6d2 Use _bzhi_u32 for 32-bit builds when building with STATIC_BMI2
`_bzhi_u64` is available only for 64-bit builds, while `BIT_getLowerBits` expects `nbBits` to be less than `BIT_MASK_SIZE` (`BIT_MASK_SIZE` is 32)
2025-01-18 21:33:04 +02:00
Pavel P 46e17b805b [asm] Enable x86_64 asm for windows builds 2025-01-18 05:33:08 +02:00
Yann ColletandYann Collet 8bff69af86 Alignment instruction ZSTD_ALIGNED() in common/compiler.h 2025-01-15 17:11:27 -08:00
Yann Collet 6f8e6f3c97 create new compilation macro ZSTD_ARCH_X86_AVX2 2025-01-15 17:11:27 -08:00
MessyHack 42d704ad5e should check defined(_M_X64) not defined(_M_X86) when building with MSVC.
_M_X86 is only defined under MSVC 32Bit
_M_X64 is only defined under MSVC 64Bit
2025-01-10 22:47:48 -08:00
Victor ZhangandGitHub a610550e2c Merge pull request #4218 from facebook/externC
Move #includes out of `extern "C"` blocks
2025-01-07 10:06:08 -08:00
Yann Collet a2ff6ea784 improve ZSTD_getFrameHeader on skippable frames
now reports:
- the header size
- the magic variant (within @dictID field)
2024-12-29 12:26:04 -08:00
Yann Collet b339efff2b add dedicated error code for special case
ZSTD_compressSequencesAndLiterals() cannot produce an uncompressed block
2024-12-20 10:37:00 -08:00
Yann ColletandYann Collet 0a5c0807af minor conversion warning fix 2024-12-20 10:36:59 -08:00
Yann Collet 477a01067f codemod: symbolEncodingType_e -> SymbolEncodingType_e 2024-12-20 10:36:56 -08:00
Yann Collet b4a40a845f move Sequences definition to zstd_compress_internal.h
they should not be in common/zstd_internal.h,
since these definitions are not shared beyond lib/compress/.
2024-12-20 10:36:55 -08:00
Victor Zhang 8f49db5a02 Revert "Remove unnecessary extern C declarations from xxhash.h"
This reverts commit 10b9d81909.
2024-12-19 17:54:41 -08:00
Victor Zhang 10b9d81909 Remove unnecessary extern C declarations from xxhash.h 2024-12-19 16:54:32 -08:00
Victor Zhang d0d5ce4c00 Remove extern C blocks from lib/* internal APIs (except xxhash.h) 2024-12-19 16:00:11 -08:00
Victor Zhang d51e6072a8 Test: remove extern C from some lib/common files 2024-12-19 14:59:02 -08:00
Victor Zhang a7bb6d6c49 Oopsie with xxhash.h [1/?] 2024-12-18 12:41:53 -08:00
Victor Zhang 07ffcc6b65 Separate xxhash includes from extern C blocks 2024-12-18 12:35:10 -08:00
Victor Zhang 63acf9a995 Oopsie with huf.h, debug.h 2024-12-18 09:56:50 -08:00
Victor Zhang 58a7f4b869 Oopsie with threading.h 2024-12-17 18:37:33 -08:00
Victor Zhang 5222dd87cf Oopsie with fse.h 2024-12-17 18:11:58 -08:00
Victor Zhang fc726da774 Move #includes out of extern "C" blocks
Do some include shuffling for `**.h` files within lib, programs, tests, and zlibWrapper.
`lib/legacy` and `lib/deprecated` are untouched.
`#include`s within `extern "C"` blocks in .cpp files are untouched.

todo: shuffling for `xxhash.h`
2024-12-17 17:55:07 -08:00