Skip to content

Commit

Permalink
crypto: move intel avx2 transform to sha256_avx2.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
xanimo committed May 3, 2024
1 parent 9c77e66 commit f8d3e2a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
22 changes: 7 additions & 15 deletions src/crypto/sha256.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ namespace sha256d64_sse41
void Transform_4way(unsigned char* out, const unsigned char* in);
}

namespace sha256avx2
{
void Transform(uint32_t* s, const unsigned char* chunk, size_t blocks);
}

namespace sha256d64_avx2
{
void Transform_8way(unsigned char* out, const unsigned char* in);
Expand Down Expand Up @@ -303,19 +308,6 @@ void Transform_ARMV8(uint32_t* s, const unsigned char* chunk, size_t blocks)
#endif
}

/** Perform one SHA-256 transformation, processing a 64-byte chunk. (AVX2) */
void Transform_AVX2(uint32_t* s, const unsigned char* chunk, size_t blocks)
{
#if USE_AVX2
// Perform SHA256 one block (Intel AVX2)
EXPERIMENTAL_FEATURE
while (blocks--) {
sha256_one_block_avx2(chunk, s);
chunk += 64;
}
#endif
}

/** Perform a number of SHA-256 transformations, processing 64-byte chunks. */
void Transform(uint32_t* s, const unsigned char* chunk, size_t blocks)
{
Expand Down Expand Up @@ -823,8 +815,8 @@ void inline Initialize_transform_ptr()
#endif
#if defined(USE_AVX2)
if (capabilities.enabled_avx) {
sha256::transform_ptr = sha256::Transform_AVX2;
sha256::transfrom_ptr_d64 = sha256::TransformD64Wrapper<sha256::Transform_AVX2>;
sha256::transform_ptr = sha256avx2::Transform;
sha256::transfrom_ptr_d64 = sha256::TransformD64Wrapper<sha256avx2::Transform>;
}
#endif
assert(SelfTest());
Expand Down
21 changes: 21 additions & 0 deletions src/crypto/sha256_avx2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,28 @@

#include "crypto/sha256.h"
#include "crypto/common.h"
#include "support/experimental.h"

#if (defined(__ia64__) || defined(__x86_64__)) && \
!defined(__APPLE__) && \
(defined(USE_AVX2))
#include <intel-ipsec-mb.h>
#endif

namespace sha256avx2 {
/** Perform a number of SHA-256 transformations, processing 64-byte chunks. (AVX2) */
void Transform(uint32_t* s, const unsigned char* chunk, size_t blocks)
{
#if USE_AVX2
// Perform SHA256 one block (Intel AVX2)
EXPERIMENTAL_FEATURE
while (blocks--) {
sha256_one_block_avx2(chunk, s);
chunk += 64;
}
#endif
}
}
namespace sha256d64_avx2 {
namespace {

Expand Down

0 comments on commit f8d3e2a

Please sign in to comment.