fec-rs
A pure Rust Reed-Solomon erasure coding library with runtime SIMD acceleration.
Features
- Pure Rust — No C/C++ dependencies or FFI. Everything is implemented in safe Rust
(with targeted
unsafefor SIMD intrinsics). - Runtime SIMD detection — Automatically uses the fastest available instruction set
via
std::is_x86_feature_detected!. A single binary works on all x86_64 systems. - GF(2^8) — Operates over the Galois field GF(2^8) with generating polynomial 29 (0x1D), compatible with the Moonlight streaming protocol.
- Shard-by-shard encoding — Incremental encoding via
ShardByShardfor streaming use cases. - Reconstruction — Reconstruct missing data and/or parity shards from any sufficient subset.
SIMD Acceleration
On x86_64, the library automatically detects CPU features at runtime and uses the best available instruction set:
- GFNI + AVX2 — Single-instruction GF multiply on 32 bytes (Intel Alder Lake+, AMD Zen 4+)
- AVX2 — VPSHUFB split-table nibble lookup on 32 bytes
- GFNI + SSE — Single-instruction GF multiply on 16 bytes
- SSSE3 — VPSHUFB split-table nibble lookup on 16 bytes
- Scalar — Lookup table fallback
Parallel Encoding
Enable the parallel feature for optional rayon-based parallel encoding:
= { = "0.1", = ["parallel"] }
When enabled, large encode workloads automatically distribute parity shard computation across threads. Small workloads use the sequential path to avoid overhead.
Usage
use ReedSolomon;
let rs = new.unwrap;
let mut shards: = vec!;
// Encode parity
rs.encode.unwrap;
// Verify
assert!;
// Simulate loss of shard 0
let mut recovery: = shards.into_iter.map.collect;
recovery = None;
// Reconstruct
rs.reconstruct.unwrap;
License: BSD-2-Clause