Skip to content

Commit

Permalink
Style (rename native hashing lambdas).
Browse files Browse the repository at this point in the history
  • Loading branch information
evoskuil committed Dec 11, 2024
1 parent aa1d372 commit f565476
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
18 changes: 9 additions & 9 deletions include/bitcoin/system/impl/hash/sha/algorithm_double.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ double_hash(const block_t& block) NOEXCEPT
{
static_assert(is_same_type<state_t, chunk_t>);

const auto hash2 = [](const block_t& block) NOEXCEPT
const auto hasher = [](const block_t& block) NOEXCEPT
{
auto state = H::get;
buffer_t buffer{};
Expand All @@ -106,15 +106,15 @@ double_hash(const block_t& block) NOEXCEPT

if (std::is_constant_evaluated())
{
return hash2(block);
return hasher(block);
}
else if constexpr (native && SHA::strength == 256)
{
return native_double_hash(block);
}
else
{
return hash2(block);
return hasher(block);
}
}

Expand All @@ -124,7 +124,7 @@ double_hash(const half_t& half) NOEXCEPT
{
static_assert(is_same_type<state_t, chunk_t>);

const auto hash2 = [](const half_t& half) NOEXCEPT
const auto hasher = [](const half_t& half) NOEXCEPT
{
auto state = H::get;
buffer_t buffer{};
Expand All @@ -145,15 +145,15 @@ double_hash(const half_t& half) NOEXCEPT

if (std::is_constant_evaluated())
{
return hash2(half);
return hasher(half);
}
else if constexpr (native && SHA::strength == 256)
{
return native_double_hash(half);
}
else
{
return hash2(half);
return hasher(half);
}
}

Expand All @@ -163,7 +163,7 @@ double_hash(const half_t& left, const half_t& right) NOEXCEPT
{
static_assert(is_same_type<state_t, chunk_t>);

const auto hash2 = [](const half_t& left, const half_t& right) NOEXCEPT
const auto hasher = [](const half_t& left, const half_t& right) NOEXCEPT
{
auto state = H::get;
buffer_t buffer{};
Expand All @@ -186,15 +186,15 @@ double_hash(const half_t& left, const half_t& right) NOEXCEPT

if (std::is_constant_evaluated())
{
return hash2(left, right);
return hasher(left, right);
}
else if constexpr (native && SHA::strength == 256)
{
return native_double_hash(left, right);
}
else
{
return hash2(left, right);
return hasher(left, right);
}
}

Expand Down
14 changes: 7 additions & 7 deletions include/bitcoin/system/impl/hash/sha/algorithm_native.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@

// Native (SHA-NI or NEON)
// ============================================================================
// The iterative method is used for sha native as it is an order of magnitude
// more efficient and cannot benefit from vectorization.
// The rotating variables method is used for sha native. Tha native
// instructions rely on register locality to achieve performance benefits.
// Implementation of native sha using buffer expansion is horribly slow.
// This split creates bifurcations (additional complexities) in this template.

namespace libbitcoin {
namespace system {
Expand Down Expand Up @@ -98,9 +100,6 @@ round_4(xint128_t& state0, xint128_t& state1, xint128_t message) NOEXCEPT

// Platform agnostic.
// ----------------------------------------------------------------------------
// Individual state vars are used vs. array to ensure register persistence.
// This creates bifurcations in this template because of the lack of a buffer
// and the differing optimal locations for applying endianness conversions.

TEMPLATE
template <bool Swap>
Expand Down Expand Up @@ -223,6 +222,9 @@ native_transform(state_t& state, const auto& block) NOEXCEPT
// accumulation and performs big-endian conversion from state_t to digest_t.
// As padding blocks are generated and therefore do not require endianness
// conversion, those calls are not applied when transforming the pad block.
// This lack of conversion also applies to double hashing. In both cases
// the "inject" functions are using in place of the "input" functions.
// There is no benefit to caching pading because it is not prescheduled.
// ----------------------------------------------------------------------------

TEMPLATE
Expand Down Expand Up @@ -251,8 +253,6 @@ template <size_t Blocks>
typename CLASS::digest_t CLASS::
native_finalize(state_t& state) NOEXCEPT
{
// We could use Blocks to cache padding but given the padding blocks are
// unscheduled when performing native transformations there's no benefit.
return native_finalize(state, Blocks);
}

Expand Down
12 changes: 6 additions & 6 deletions include/bitcoin/system/impl/hash/sha/algorithm_single.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ TEMPLATE
constexpr typename CLASS::digest_t CLASS::
hash(const half_t& half) NOEXCEPT
{
const auto hash1 = [](const half_t& half) NOEXCEPT
const auto hasher = [](const half_t& half) NOEXCEPT
{
auto state = H::get;
buffer_t buffer{};
Expand All @@ -75,23 +75,23 @@ hash(const half_t& half) NOEXCEPT

if (std::is_constant_evaluated())
{
return hash1(half);
return hasher(half);
}
else if constexpr (native && SHA::strength == 256)
{
return native_hash(half);
}
else
{
return hash1(half);
return hasher(half);
}
}

TEMPLATE
constexpr typename CLASS::digest_t CLASS::
hash(const half_t& left, const half_t& right) NOEXCEPT
{
const auto hash1 = [](const half_t& left, const half_t& right) NOEXCEPT
const auto hasher = [](const half_t& left, const half_t& right) NOEXCEPT
{
auto state = H::get;
buffer_t buffer{};
Expand All @@ -106,15 +106,15 @@ hash(const half_t& left, const half_t& right) NOEXCEPT

if (std::is_constant_evaluated())
{
return hash1(left, right);
return hasher(left, right);
}
else if constexpr (native && SHA::strength == 256)
{
return native_hash(left, right);
}
else
{
return hash1(left, right);
return hasher(left, right);
}
}

Expand Down

0 comments on commit f565476

Please sign in to comment.