aboutsummaryrefslogtreecommitdiff
path: root/src/crypto/sha256.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2017-07-13 23:33:11 -0700
committerPieter Wuille <pieter.wuille@gmail.com>2017-07-20 09:03:53 -0700
commitc1ccb15b0e847eb95623f9d25dc522aa02dbdbe8 (patch)
tree659366f3215952eebac27e504d4a25b070732f0d /src/crypto/sha256.cpp
parent2991c91d88f3d17ac6b38bddfa6f1b6b8d835c0f (diff)
downloadbitcoin-c1ccb15b0e847eb95623f9d25dc522aa02dbdbe8.tar.xz
Add SSE4 based SHA256
Diffstat (limited to 'src/crypto/sha256.cpp')
-rw-r--r--src/crypto/sha256.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/crypto/sha256.cpp b/src/crypto/sha256.cpp
index 3649dc4be0..4ecf509039 100644
--- a/src/crypto/sha256.cpp
+++ b/src/crypto/sha256.cpp
@@ -3,13 +3,19 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "crypto/sha256.h"
-
#include "crypto/common.h"
#include <string.h>
-
#include <atomic>
+#if defined(__x86_64__) || defined(__amd64__)
+#include <cpuid.h>
+namespace sha256_sse4
+{
+void Transform(uint32_t* s, const unsigned char* chunk, size_t blocks);
+}
+#endif
+
// Internal implementation code.
namespace
{
@@ -140,6 +146,14 @@ void (*Transform)(uint32_t*, const unsigned char*, size_t) = sha256::Transform;
std::string SHA256AutoDetect()
{
+#if defined(__x86_64__) || defined(__amd64__)
+ uint32_t eax, ebx, ecx, edx;
+ if (__get_cpuid(1, &eax, &ebx, &ecx, &edx) && (ecx >> 19) & 1) {
+ Transform = sha256_sse4::Transform;
+ return "sse4";
+ }
+#endif
+
return "standard";
}