Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to intx 0.8.0 endian facilities #615

Merged
merged 4 commits into from
Mar 16, 2022
Merged

Switch to intx 0.8.0 endian facilities #615

merged 4 commits into from
Mar 16, 2022

Conversation

yperbasis
Copy link
Member

Switch to the new endian facilities introduced in release 0.8.0 of intx.

@yperbasis yperbasis changed the title Switch to new intx endian facilities Switch to new intx 0.8.0 endian facilities Mar 16, 2022
@yperbasis yperbasis changed the title Switch to new intx 0.8.0 endian facilities Switch to intx 0.8.0 endian facilities Mar 16, 2022
@codecov
Copy link

codecov bot commented Mar 16, 2022

Codecov Report

Merging #615 (fbf499e) into master (711c735) will decrease coverage by 0.11%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #615      +/-   ##
==========================================
- Coverage   81.78%   81.66%   -0.12%     
==========================================
  Files         167      167              
  Lines       13966    13925      -41     
==========================================
- Hits        11422    11372      -50     
- Misses       2544     2553       +9     
Impacted Files Coverage Δ
core/silkworm/common/util.hpp 100.00% <ø> (ø)
core/silkworm/common/endian.hpp 100.00% <100.00%> (ø)
core/silkworm/crypto/snark.cpp 95.28% <100.00%> (ø)
core/silkworm/execution/precompiled.cpp 100.00% <100.00%> (ø)
node/silkworm/rpc/completion_runner.cpp 93.54% <0.00%> (-4.84%) ⬇️
core/silkworm/consensus/base/engine.cpp 93.03% <0.00%> (-1.00%) ⬇️
core/silkworm/execution/evm.cpp 96.68% <0.00%> (-0.83%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 711c735...fbf499e. Read the comment docs.

std::memcpy(&x, bytes, sizeof(x));
return be::load(x);
}
inline uint16_t load_big_u16(const uint8_t* bytes) noexcept { return intx::be::unsafe::load<uint16_t>(bytes); }
Copy link
Contributor

Choose a reason for hiding this comment

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

Just wondering if it's worth to simply make aliases of intx's functions (which is apparently what we're doing here).
Less boilerplate code and more clear intention imho

Something like :

const auto load_big_u16 = intx::be::unsafe::load<uint16_t>;
const auto load_big_u32 = intx::be::unsafe::load<uint32_t>;
const auto load_big_u64 = intx::be::unsafe::load<uint64_t>;
const auto load_little_u16 = intx::le::unsafe::load<uint16_t>;
const auto load_little_u32 = intx::le::unsafe::load<uint32_t>;
const auto load_little_u64 = intx::le::unsafe::load<uint64_t>;
const auto store_big_u16 = intx::be::unsafe::store<uint16_t>;
const auto store_big_u32 = intx::be::unsafe::store<uint32_t>;
const auto store_big_u64 = intx::be::unsafe::store<uint64_t>;

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice! Done in fbf499e.

Copy link
Contributor

Choose a reason for hiding this comment

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

Or even

template <typename T, typename = std::enable_if_t<std::is_integral_v<T> && std::is_unsigned_v<T>>>
const auto load_big = intx::be::unsafe::load<T>;

and then use it as

const auto state_mask{endian::load_big<uint16_t>(v.data()) };

I don't think load_big_u16 vs load_big<uint16_t> makes a big difference in typed keys.

Copy link
Member Author

@yperbasis yperbasis Mar 16, 2022

Choose a reason for hiding this comment

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

I think then it makes sense to get rid of the aliases completely and only call the intx functions directly. I can do that.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think then it makes sense to get rid of the aliases completely and only use the intx functions directly. I can do that.

I personally wouldn't do that. as in namespace endian we already have to/from_big_compact probably keeping aliases makes sense so we don't have to change namespaces. But is a matter of taste

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, then to my mind the current version with the aliases (same as the boost names, e.g. load_big_u32) is fine.

@yperbasis yperbasis merged commit 1eae7c4 into master Mar 16, 2022
@yperbasis yperbasis deleted the update_intx branch March 16, 2022 10:28
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