aboutsummaryrefslogtreecommitdiff
path: root/src/compat
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2019-10-27 12:52:31 -0700
committerPieter Wuille <pieter.wuille@gmail.com>2019-11-12 14:50:44 -0800
commit723c79666770b30cce9f962bed5ece8cc7d74580 (patch)
treeb1dbaecda34a61030ede89845bcb271fb4687277 /src/compat
parentcea3902015185adc88adbd031d919f91bc844fd7 (diff)
downloadbitcoin-723c79666770b30cce9f962bed5ece8cc7d74580.tar.xz
[MOVEONLY] Move cpuid code from random & sha256 to compat/cpuid
Diffstat (limited to 'src/compat')
-rw-r--r--src/compat/cpuid.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/compat/cpuid.h b/src/compat/cpuid.h
new file mode 100644
index 0000000000..0877ad47d3
--- /dev/null
+++ b/src/compat/cpuid.h
@@ -0,0 +1,24 @@
+// Copyright (c) 2017-2019 The Bitcoin Core developers
+// Distributed under the MIT software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#ifndef BITCOIN_COMPAT_CPUID_H
+#define BITCOIN_COMPAT_CPUID_H
+
+#if defined(__x86_64__) || defined(__amd64__) || defined(__i386__)
+#define HAVE_GETCPUID
+
+#include <cpuid.h>
+
+// We can't use cpuid.h's __get_cpuid as it does not support subleafs.
+void static inline GetCPUID(uint32_t leaf, uint32_t subleaf, uint32_t& a, uint32_t& b, uint32_t& c, uint32_t& d)
+{
+#ifdef __GNUC__
+ __cpuid_count(leaf, subleaf, a, b, c, d);
+#else
+ __asm__ ("cpuid" : "=a"(a), "=b"(b), "=c"(c), "=d"(d) : "0"(leaf), "2"(subleaf));
+#endif
+}
+
+#endif // defined(__x86_64__) || defined(__amd64__) || defined(__i386__)
+#endif // BITCOIN_COMPAT_CPUID_H