Repository navigation
Conversation
Each of the 80 steps of a RIPEMD-160 line depends on the previous step of that line, but the left and right lines are independent. The macro-generated `compress` ran all 80 left steps and then all 80 right steps, so the two dependency chains were 80 steps (about 900 instructions) apart and the CPU could not overlap them. Advance both lines one step at a time, expressed through the standard message-order, rotation and constant tables and a fully unrolled macro, so the out-of-order core runs the two chains side by side. The additions of each step are ordered so that only the boolean function, one addition, the rotation and the final addition are on the chain. On an x86-64 build with default flags this takes 708 cycles per block down to 462 cycles per block (hashing 64 KiB repeatedly, `perf stat` cycles:u). Digests are unchanged: the existing test vectors pass, and 16800 random inputs of 0 to 2099 bytes match ripemd 0.2.0.
DaniPopes
marked this pull request as ready for review
November 9, 2026 17:44
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.
Each of the 80 steps of a RIPEMD-160 line depends on the previous step of that line, but the left and right lines are independent of each other. The macro-generated
compressran all 80 left steps and then all 80 right steps, so the two dependency chains started about 900 instructions apart and the CPU could not overlap them. The function ran at about 2.5 instructions per cycle, limited by one serial chain at a time.This rewrites
compressfor RIPEMD-160 so that both lines advance one step at a time. The message order, rotation and constant tables are now plain arrays, the 80 steps are fully unrolled by a macro, and the additions of each step are ordered so that only the boolean function, one addition, the rotation and the final addition lie on the chain. RIPEMD-128, -256 and -320 are not changed.On x86-64 with default flags (no
target-cpu), hashing 64 KiB repeatedly on an AMD EPYC 4245P pinned at 4 GHz:The same change in an EVM that calls this crate for the RIPEMD-160 precompile (criterion, full transaction including the precompile call, median of 5 alternating runs on the same machine):
The existing test vectors pass on 1.85 and stable, and the new
compressmatches the old one on 16800 random inputs of 0 to 2099 bytes. I only measured x86-64.