Skip to content

sha2: use #[inline] on riscv_zknh sha512 unroll compress_block - #967

Closed
devonjonte wants to merge 1 commit into
RustCrypto:masterfrom
devonjonte:fix/sha512-riscv-zknh-inline
Closed

devonjonte wants to merge 1 commit into
RustCrypto:masterfrom
devonjonte:fix/sha512-riscv-zknh-inline

Conversation

@devonjonte

Copy link
Copy Markdown
Contributor

sha2/src/sha512/riscv_zknh/unroll.rs:15-16 combines #[inline(always)] with #[target_feature(enable = "zknh")]:

#[inline(always)]
#[target_feature(enable = "zknh")]
fn compress_block(state: &mut [u64; 8], block: &[u8; 128]) {

rustc rejects #[inline(always)] on #[target_feature] functions without #![feature(target_feature_inline_always)] (error: cannot use #[inline(always)] with #[target_feature], rust-lang/rust#145574), even when the target feature is enabled globally via -C target-feature=+zknh. Because sha2/src/lib.rs enables only riscv_ext_intrinsics, compiling with --cfg sha2_backend="riscv-zknh" or --cfg sha2_512_backend="riscv-zknh" (default unrolled rounds) fails to build.

This changes line 15 to #[inline], matching sha2/src/sha256/riscv_zknh/unroll.rs:15.

rustc rejects #[inline(always)] combined with #[target_feature] unless
#![feature(target_feature_inline_always)] is enabled (rust-lang/rust#145574),
so selecting --cfg sha2_backend="riscv-zknh" (or sha2_512_backend="riscv-zknh")
with default unrolled rounds fails to compile.

Match sha2/src/sha256/riscv_zknh/unroll.rs:15 by using #[inline].
@newpavlov

newpavlov commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

It works on recent Nightly releases, no? IIRC using just #[inline] results in compress_block not being inlined.

@devonjonte

Copy link
Copy Markdown
Contributor Author

You're right — I tested against an older local nightly (1.101.0-nightly 2026-09-30) before rust-lang/rust#145574 landed; CI's 1.102.0-nightly (2026-11-30) already accepts #[inline(always)] with #[target_feature] cleanly on riscv64-zknh and riscv32-zknh.

Closing this since riscv-zknh is nightly-only (#![feature(riscv_ext_intrinsics)]) and #[inline(always)] is intentional for compress_block codegen. Thanks for checking!

@devonjonte devonjonte closed this Dec 2, 2026
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