Skip to content

Commit

Permalink
crypto/sha256: Use pragmas to enforce necessary intrinsics for GCC an…
Browse files Browse the repository at this point in the history
…d Clang

This avoids problems when the user specifies CXXFLAGS explicitly disabling the relevant optimisations.
  • Loading branch information
luke-jr committed May 14, 2020
1 parent 04c0955 commit 14337d0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/crypto/sha256_avx2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@

#include <crypto/common.h>

#if defined(__clang__)
#pragma clang attribute push(__attribute__((__target__("avx,avx2"))), apply_to = function)
#elif defined(__GNUC__)
#pragma GCC target ("avx,avx2")
#endif

namespace sha256d64_avx2 {
namespace {

Expand Down Expand Up @@ -325,4 +331,8 @@ void Transform_8way(unsigned char* out, const unsigned char* in)

}

#if defined(__clang__)
#pragma clang attribute pop
#endif

#endif
10 changes: 10 additions & 0 deletions src/crypto/sha256_shani.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
#include <stdint.h>
#include <immintrin.h>

#if defined(__clang__)
#pragma clang attribute push(__attribute__((__target__("sse4,sha"))), apply_to = function)
#elif defined(__GNUC__)
#pragma GCC target ("sse4,sha")
#endif

namespace {

alignas(__m128i) const uint8_t MASK[16] = {0x03, 0x02, 0x01, 0x00, 0x07, 0x06, 0x05, 0x04, 0x0b, 0x0a, 0x09, 0x08, 0x0f, 0x0e, 0x0d, 0x0c};
Expand Down Expand Up @@ -353,4 +359,8 @@ void Transform_2way(unsigned char* out, const unsigned char* in)

}

#if defined(__clang__)
#pragma clang attribute pop
#endif

#endif
10 changes: 10 additions & 0 deletions src/crypto/sha256_sse41.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@

#include <crypto/common.h>

#if defined(__clang__)
#pragma clang attribute push(__attribute__((__target__("sse4.1"))), apply_to = function)
#elif defined(__GNUC__)
#pragma GCC target ("sse4.1")
#endif

namespace sha256d64_sse41 {
namespace {

Expand Down Expand Up @@ -317,4 +323,8 @@ void Transform_4way(unsigned char* out, const unsigned char* in)

}

#if defined(__clang__)
#pragma clang attribute pop
#endif

#endif

0 comments on commit 14337d0

Please sign in to comment.