Skip to content

Commit d7c9261

Browse files
committed
Prioritize shani over sse4 and avx2 < 32 blocks (Merkle).
1 parent 91c7f59 commit d7c9261

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

include/bitcoin/system/impl/hash/sha/algorithm_merkle.ipp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,18 @@ merkle_hash_vector(digests_t& digests) NOEXCEPT
404404
// Merkle hash vector dispatch.
405405
if constexpr (use_x512)
406406
merkle_hash_vector<xint512_t>(idigests, iblocks);
407+
408+
// Use if shani is not available or at least 32 blocks.
407409
if constexpr (use_x256)
408-
merkle_hash_vector<xint256_t>(idigests, iblocks);
409-
if constexpr (use_x128)
410+
{
411+
if constexpr (!native)
412+
merkle_hash_vector<xint256_t>(idigests, iblocks);
413+
else if (start >= 32_size)
414+
merkle_hash_vector<xint256_t>(idigests, iblocks);
415+
}
416+
417+
// Only use if shani is not available.
418+
if constexpr (use_x128 && !native)
410419
merkle_hash_vector<xint128_t>(idigests, iblocks);
411420

412421
// iblocks.size() is reduced by vectorization.
@@ -461,7 +470,6 @@ merkle_hash(digests_t& digests) NOEXCEPT
461470
#endif
462471
if constexpr (vector)
463472
{
464-
// TODO: test vector vs. native performance for the 4 lane scenario.
465473
// Merkle block vectorization is applied at 16/8/4 lanes (as available)
466474
// and falls back to native/normal (as available) for 3/2/1 lanes.
467475
merkle_hash_vector(digests);

0 commit comments

Comments
 (0)