Skip to content

Replace C bindings for CRC32 fusion calculation #9

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

Merged
merged 16 commits into from
Jun 10, 2025

Conversation

onethumb
Copy link
Contributor

@onethumb onethumb commented Jun 10, 2025

The Problems

The C bindings used to accelerate CRC-32/ISCSI and CRC-32/ISO-HDLC using a fusion approach were fragile and problematic for some environments and build processes.

The Solution

Remove the C bindings and replace them with pure Rust implementations. This also resulted in a material performance boost for smaller inputs (1 KiB).

Changes

  • Removed the C bindings
  • Added CRC-32 fusion calculations in pure Rust

Planned version bump

  • Which: MINOR
  • Why: non-breaking new functionality

Links

Notes

This makes this library 100% pure Rust. 👍

onethumb added 6 commits June 9, 2025 12:34
The C bindings approach has proven to be problematic across a variety of
CI/CD implementations, particularly when cross-compiling to other
targets.

Moving to a pure Rust implementation should eliminate those issues.
By fusing CLMUL and native CRC32 instructions, we can achieve more
throughput on platforms which have native CRC32 instruction support.

These were generated using the ‘fast-crc32’ project, then converted from
C to Rust with the help of Claude.ai.

https://github.com/corsix/fast-crc32/
https://www.corsix.org/content/fast-crc32c-4k
https://www.corsix.org/content/alternative-exposition-crc32_4k_pclmulqdq
https://dougallj.wordpress.com/2022/05/22/faster-crc32-on-the-apple-m1/
AVX512 support has landed in 1.89.0, so we can deprecate the feature
flag and instead rely on the Rust version for AVX512 support, including
VPCLMULQDQ.

https://releases.rs/docs/1.89.0/
rust-lang/rust#138940
Updates the README to include latest benchmarking numbers and
information about acceleration targets.
@onethumb onethumb requested a review from Copilot June 10, 2025 00:39
Copy link

@Copilot Copilot AI left a 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 removes fragile C bindings for CRC-32/ISCSI and CRC-32/ISO-HDLC, replacing them with pure Rust implementations gated by Rust 1.89+ feature detection, and updates benchmark code accordingly.

  • Deleted all generated C source and header files under include/
  • Simplified build.rs by removing C compilation paths
  • Adjusted benches/benchmark.rs to refine the set of algorithms, add measurement times, and swap benchmark order

Reviewed Changes

Copilot reviewed 37 out of 37 changed files in this pull request and generated no comments.

File Description
include/* All C-based CRC implementation files and headers deleted
build.rs Removed C-binding build logic and feature-flag overrides
benches/benchmark.rs Updated CRC algorithm list, enabled Duration measurement, reordered

onethumb added 3 commits June 10, 2025 11:49
I’m going to put this in another PR instead, waiting for 1.89 to hit
stable first. I’ll keep this gated on the “vpclmulqdq” feature flag
until then.
@onethumb onethumb merged commit 2f27164 into awesomized:main Jun 10, 2025
24 checks passed
@ix-xMAC94x ix-xMAC94x mentioned this pull request Jun 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant