Repository navigation
keccak: Use shared int_bytes.hpp helpers and constexpr dispatch - #1775
Conversation
0b09a81 to
a44ca60
Compare
Merging this PR will improve performance by 1.45%1 warning
Performance Changes
Tip Curious why performance improved? Comment Comparing |
Move byteswap(), to_le(), load_le() and store_le() out of the RIPEMD-160 implementation to share them with other hash functions.
Replace the local load_le() and to_le64() helpers and the preprocessor fallbacks with the shared int_bytes.hpp helpers. Make keccakf1600_best constexpr on targets without runtime dispatch. The generated code is identical.
a44ca60 to
f86cbcd
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1775 +/- ##
==========================================
- Coverage 98.23% 98.23% -0.01%
==========================================
Files 184 185 +1
Lines 17135 17131 -4
Branches 3912 3912
==========================================
- Hits 16833 16829 -4
Misses 233 233
Partials 69 69
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🟢 Approval recommended
The focused refactor preserves byte-order handling, input processing, and dispatch behavior, with no blocking issues identified.
No open issues 🎉
What changed in this PR
This PR consolidates integer byte-order helpers used by RIPEMD-160 and Keccak while preserving the public Keccak API and hash behavior.
Changes:
- Extract shared byte-swap, little-endian load, and store helpers into
int_bytes.hpp. - Use
std::byteinternally in Keccak, replacing local helpers and compiler-specific fallbacks. - Make the Keccak function pointer
constexprwhere runtime dispatch is unnecessary.
| File | Description |
|---|---|
lib/evmone_precompiles/ripemd160.cpp |
Replace local byte-order helpers with the shared header. |
lib/evmone_precompiles/keccak.cpp |
Adopt shared helpers, byte-based input, and constant dispatch where applicable. |
lib/evmone_precompiles/int_bytes.hpp |
Define shared integral byte-conversion helpers. |
lib/evmone_precompiles/CMakeLists.txt |
Register the new header in the precompiles target. |
Review effort: Balanced
Move byteswap(), to_le(), load_le() and store_le() out of the RIPEMD-160 implementation into a new int_bytes.hpp header (std::byte interface). load_le() now requires std::integral like to_le(), which it already depended on.
Use them in Keccak instead of the local load_le() and to_le64() helpers and the preprocessor fallbacks (__has_builtin, __builtin_memcpy, BYTE_ORDER). keccak() now takes std::byte input; ethash_keccak256() keeps its uint8_t API.
Make keccakf1600_best constexpr on targets without the x86 runtime dispatch.
The generated code is identical at -O3 and -O1 for clang-23, g++-15 and g++-16 on x86-64, and clang-23 on aarch64 (also with the SHA3 path). RIPEMD-160 code is identical too.