Skip to content

Implement aarch64 CRC32 LLVM intrinsics#1651

Open
bryancostanich wants to merge 2 commits intorust-lang:mainfrom
bryancostanich:aarch64-crc32-intrinsics
Open

Implement aarch64 CRC32 LLVM intrinsics#1651
bryancostanich wants to merge 2 commits intorust-lang:mainfrom
bryancostanich:aarch64-crc32-intrinsics

Conversation

@bryancostanich
Copy link
Copy Markdown

@bryancostanich bryancostanich commented Apr 25, 2026

Adds support for the eight llvm.aarch64.crc32{,c}{b,h,w,x} intrinsics by lowering them to crc32{,c}{b,h,w,x} inline assembly via the existing codegen_inline_asm_inner helper. Mirrors PR #1490 (the x86 sse42.crc32 family).

This unblocks crc32fast on aarch64 under the cranelift backend, which is pulled in transitively by common crates including pngimage and Bevy's PNG screenshot path. Multiple users have reported this in #171 over the past year (llvm.aarch64.crc32b blocking Tauri builds, llvm.aarch64.crc32x blocking utoipa-swagger-ui, etc.).

What's covered

LLVM intrinsic AArch64 instruction Rust intrinsic
`llvm.aarch64.crc32b` `crc32b Wd, Wn, Wm` `__crc32b`
`llvm.aarch64.crc32h` `crc32h Wd, Wn, Wm` `__crc32h`
`llvm.aarch64.crc32w` `crc32w Wd, Wn, Wm` `__crc32w`
`llvm.aarch64.crc32x` `crc32x Wd, Wn, Xm` `__crc32d`
`llvm.aarch64.crc32cb` `crc32cb Wd, Wn, Wm` `__crc32cb`
`llvm.aarch64.crc32ch` `crc32ch Wd, Wn, Wm` `__crc32ch`
`llvm.aarch64.crc32cw` `crc32cw Wd, Wn, Wm` `__crc32cw`
`llvm.aarch64.crc32cx` `crc32cx Wd, Wn, Xm` `__crc32cd`

Tests

`example/neon.rs` extended with `test_crc32()` covering all eight intrinsics. Reference values were generated by running the same call sequence under the LLVM backend on `aarch64-apple-darwin` and pasted into the assertions.

Verified locally on `aarch64-apple-darwin`:

  • Full `./test.sh` passes.
  • End-to-end smoke test: a tiny crate depending on `crc32fast = "1.5"` compiles and runs under cg_clif, producing a CRC matching `zlib.crc32`.

Refs #171

Covers all 8 LLVM intrinsics (llvm.aarch64.crc32{,c}{b,h,w,x}).
Reference values generated with the LLVM backend on aarch64-apple-darwin.
Currently fails: cg_clif emits a 'not yet supported' trap.
@rustbot

This comment has been minimized.

Lower the eight CRC32 LLVM intrinsics to crc32{,c}{b,h,w,x} inline
assembly via the existing codegen_inline_asm_inner helper, mirroring
the existing x86 sse42.crc32 lowering.

Unblocks crc32fast on aarch64-{apple-darwin,unknown-linux-*}, which is
pulled in transitively by png -> image and Bevy's PNG screenshot path.
@bryancostanich bryancostanich force-pushed the aarch64-crc32-intrinsics branch from 1a985e7 to 7bc02ad Compare April 25, 2026 05:40
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.

2 participants