-
Notifications
You must be signed in to change notification settings - Fork 11
Add CRC-16 support #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Begins adding CRC-16 support using known good values.
Add CRC-16 exponents constant and update keys() function
1.1 Add CRC-16 exponents constant and update keys() function
Write property test for CRC-16 computation matches reference
No idea how this got left behind. :(
Includes notes on CRC-16 support plus helper functions for the most popular variants, among other small improvements.
Better future proofing, easier for consumers to use. Marks Crc32Custom and Crc64Custom as deprecated.
Matches the aarch64 approach more closely, avoiding stack overflows on x86_64
No target features gate against this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds hardware-accelerated CRC-16 support to the crc-fast library, addressing issue #18. The implementation extends the existing CRC-32 and CRC-64 infrastructure to support all known CRC-16 variants plus custom parameters.
Key Changes:
- Adds CRC-16 support for 31 known variants with hardware acceleration
- Introduces
CrcCustomalgorithm variant that's width-agnostic (replacesCrc32CustomandCrc64Custom) - Adds
init_algorithmfield toCrcParamsfor pre-computed bit-reversed init values for reflected CRC-16 - Refactors CRC-16 and CRC-32 to share common 32-bit-space SIMD operations
Reviewed changes
Copilot reviewed 40 out of 42 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/crc16/* | New CRC-16 module with algorithm implementation and constants for 31 variants |
| src/structs.rs | Adds Width16 implementation and init_algorithm computation in CrcParams::new() |
| src/lib.rs | Updates checksum functions to use init_algorithm and handle CRC-16 enum variants |
| src/traits.rs | Changes keys parameter from by-value to by-reference (&[u64; 23]) |
| src/generate.rs | Adds CRC-16 key generation functions with polynomial formatting and Barrett reduction |
| src/crc32/width32_ops.rs | New shared module for 32-bit-space operations used by both CRC-16 and CRC-32 |
| src/ffi.rs | Adds CRC-16 FFI enum variants and CrcCustom support |
| src/combine.rs | Updates to use init_algorithm instead of init |
| src/arch/mod.rs | Adds Width16 dispatch routing for all architecture targets |
| test files | Adds comprehensive tests for CRC-16 with property-based testing |
| README.md, Cargo.toml | Updates documentation and dependencies |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The Problem
The library currently only supports CRC-32 and CRC-64 widths, but there was a request for CRC-16 in #18.
The Solution
Implement CRC-16 in a relatively future-proof way to enable future widths to be added more easily as well.
Changes
CrcCustomthat's width-agnostic, which supports 16, 32, and 64 bit widths today, but can support more in the futurePlanned version bump
MINORLinks
Notes
Should enable other future widths if anyone desires them.