Skip to content

crypto: Refactor RIPEMD-160 functions for inlining - #1800

Merged
chfast merged 1 commit into
masterfrom
crypto/ripemd160-inline
Nov 1, 2026
Merged

chfast merged 1 commit into
masterfrom
crypto/ripemd160-inline

Conversation

@chfast

@chfast chfast commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Force inlining of the helper functions in RIPEMD-160 implementation. The implementation is constructed around inline steps functions, make sure these are always inlined. This actually shortens the code. Additionally, GCC was not able to inline boolean functions behind array of function pointers. Now function specialization is used.

Upstreamed from erigontech@56dd838.

Co-authored-by: Paweł Bylica pawel.bylica@erigon.tech


Instructions per hash of 1024 bytes (x86-64-v2, -O3):

master PR
GCC 14 55.1k 27.5k
GCC 15 151.1k 27.4k
GCC 16 149.1k 27.4k
Clang 23 28.3k 29.4k

@codspeed

codspeed Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will improve performance by 94.81%

⚡ 5 improved benchmarks
✅ 894 untouched benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ test_ripemd160_fixed_size[fork_Osaka-blockchain_test-size_1024-benchmark-gas-value_1M] 12 ms 5 ms ×2.4
⚡ test_ripemd160[fork_Osaka-blockchain_test-benchmark-gas-value_1M] 12 ms 5.1 ms ×2.4
⚡ test_ripemd160_fixed_size[fork_Osaka-blockchain_test-size_256-benchmark-gas-value_1M] 10.7 ms 5 ms ×2.1
⚡ test_ripemd160_fixed_size[fork_Osaka-blockchain_test-size_0-benchmark-gas-value_1M] 7.6 ms 5 ms +53.68%
⚡ test_ripemd160_fixed_size[fork_Osaka-blockchain_test-size_32-benchmark-gas-value_1M] 6.9 ms 4.7 ms +49.1%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing crypto/ripemd160-inline (10a3255) with master (f73ca77)

Open in CodSpeed

@codecov

codecov Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.24%. Comparing base (f73ca77) to head (10a3255).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1800      +/-   ##
==========================================
- Coverage   98.24%   98.24%   -0.01%     
==========================================
  Files         186      186              
  Lines       17176    17175       -1     
  Branches     3921     3922       +1     
==========================================
- Hits        16874    16873       -1     
  Misses        233      233              
  Partials       69       69              
Flag Coverage Δ
eest-develop-gmp 26.95% <100.00%> (-0.01%) ⬇️
eest-legacy 17.23% <0.00%> (+<0.01%) ⬆️
eest-libsecp256k1 29.11% <100.00%> (-0.01%) ⬇️
eest-stable 84.24% <100.00%> (-0.01%) ⬇️
evmone-unittests 94.11% <100.00%> (-0.01%) ⬇️
riscv64 94.82% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
core 96.62% <100.00%> (-0.01%) ⬇️
tooling 94.87% <ø> (ø)
tests 99.82% <ø> (ø)
Files with missing lines Coverage Δ
lib/evmone_precompiles/ripemd160.cpp 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Force inlining of the helper functions in RIPEMD-160 implementation.
The implementation is constructed around inline steps functions,
make sure these are always inlined. This actually shortens the code.
Additionally, GCC was not able to inline boolean functions behind
array of function pointers. Now function specialization is used.

Co-authored-by: Paweł Bylica <pawel.bylica@erigon.tech>
@chfast
chfast force-pushed the crypto/ripemd160-inline branch from 9b4f0ff to 10a3255 Compare November 1, 2026 20:32
@chfast
chfast changed the base branch from ci/codspeed-gcc15 to master November 1, 2026 20:32
@chfast
chfast requested a balanced review from Copilot November 1, 2026 20:55

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the RIPEMD-160 helper-inlining refactor.

No open issues 🎉

What changed in this PR

Refactors RIPEMD-160 helpers to improve compiler inlining, addressing GCC’s difficulty inlining calls through function-pointer arrays while preserving the hash calculations.

Changes:

  • Replaces the Boolean function-pointer array with round-indexed template specializations.
  • Adds always_inline attributes to Boolean helpers and step functions.
File Description
lib/​evmone_precompiles/​ripemd160.cpp Uses specialized Boolean helpers and forces helper inlining in RIPEMD-160 steps.

Review effort: Balanced

@chfast
chfast merged commit 8411c60 into master Nov 1, 2026
39 of 41 checks passed
@chfast
chfast deleted the crypto/ripemd160-inline branch November 1, 2026 20:59
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.

3 participants