sha1-checked: implement hardware acceleration on arm64 and x86_64 - #910
Open
srijs wants to merge 1 commit into
Open
sha1-checked: implement hardware acceleration on arm64 and x86_64#910srijs wants to merge 1 commit into
srijs wants to merge 1 commit into
Conversation
srijs
commented
Aug 22, 2026
Author
There was a problem hiding this comment.
This is existing code, moved over from compress.rs and with some pub(crate) exports added.
srijs
commented
Aug 22, 2026
Author
There was a problem hiding this comment.
This is more or less the same as the sha1 implementation, with two key differences:
- It's just a single block rather than a loop over blocks.
- We spill the word sequence (W_0 .. W_79) into
was they are expanded across the rounds.
srijs
force-pushed
the
sha1-checked-hw-accel
branch
from
August 22, 2026 17:35
1991d94 to
3f4a6e8
Compare
srijs
commented
Aug 22, 2026
Author
There was a problem hiding this comment.
Same deal here, based on the original sha1 impl, cut down to a single block, and added word spilling.
srijs
force-pushed
the
sha1-checked-hw-accel
branch
from
August 22, 2026 17:52
3f4a6e8 to
1f3450b
Compare
srijs
force-pushed
the
sha1-checked-hw-accel
branch
from
August 22, 2026 18:04
1f3450b to
4afed0e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
re #909
Implements hardware acceleration for
sha1-checkedon botharm64andx86_64architectures.This is largely based on the existing
sha1implementation, with modifications to spill W0..W79 into a buffer as the message is being expended. The way this then works is by running the happy path via the specialized hardware instructions, and falling back to the scalar implementation only if a potential collision is detected.Also tried to match using
cpufeaturesandcfg-ifas best as possible, yet slightly different as it's somewhat of a different surface here. Let me know where you'd like me to adjust this.Code duplication between
shaandsha1-checkedis obviously one of the not so nice aspects here - if you have ideas or a desire to share the instrinsics code across the crates let me know!Measured with the crate's own bench suite:
sha_ni, cloud sandbox)For comparison, performance relative to plain
sha1on the same backend, i.e. what fraction of un-checked SHA-1's speed detection reaches:sha_ni)Note: On
aarch64, hardware acceleration speeds upsha1andsha1-checkedby about the same factor, so the relative gap to plain SHA-1 barely moves. Onx86_64it doesn't, instead the gap actually widens (but of course still improving the absolute performance).