mirror of
https://github.com/dogecoin/dogecoin.git
synced 2026-01-31 02:20:53 +00:00
enforce explicit experimental configuration through annotation
Introduces a new support header that exposes the macro EXPERIMENTAL_FEATURE that (a) allows us to clearly mark blocks of code as experimental (or entire files) and (b) enforces that none of the annotated code gets compiled if --enable-experimental was not configured through a static assertion. Existing experimental features are annotated: - AVX2 using the intel-ipsec-mb dependency for SHA1/256/512 - ARMv8 intrinsics for SHA1/256 - ARMv82 intrinsics for SHA512 - SSE2 for scrypt
This commit is contained in:
parent
2c46336ce6
commit
330cea911f
@ -143,6 +143,7 @@ BITCOIN_CORE_H = \
|
||||
support/allocators/zeroafterfree.h \
|
||||
support/cleanse.h \
|
||||
support/events.h \
|
||||
support/experimental.h \
|
||||
support/lockedpool.h \
|
||||
sync.h \
|
||||
threadsafety.h \
|
||||
|
||||
@ -28,12 +28,16 @@
|
||||
*/
|
||||
|
||||
#include "crypto/scrypt.h"
|
||||
#include "support/experimental.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <emmintrin.h>
|
||||
|
||||
// this entire functionality is experimental
|
||||
EXPERIMENTAL_FEATURE
|
||||
|
||||
static inline void xor_salsa8_sse2(__m128i B[4], const __m128i Bx[4])
|
||||
{
|
||||
__m128i X0, X1, X2, X3;
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
#include "crypto/sha1.h"
|
||||
|
||||
#include "crypto/common.h"
|
||||
#include "support/experimental.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
@ -71,6 +72,9 @@ const uint32_t k4 = 0xCA62C1D6ul;
|
||||
void Transform(uint32_t* s, const unsigned char* chunk)
|
||||
{
|
||||
#if defined(USE_ARMV8) || defined(USE_ARMV82)
|
||||
// this entire block is experimental
|
||||
EXPERIMENTAL_FEATURE
|
||||
|
||||
uint32x4_t ABCD, ABCD_SAVED;
|
||||
uint32x4_t TMP0, TMP1;
|
||||
uint32x4_t MSG0, MSG1, MSG2, MSG3;
|
||||
@ -241,6 +245,7 @@ void Transform(uint32_t* s, const unsigned char* chunk)
|
||||
|
||||
#elif USE_AVX2
|
||||
// Perform SHA1 one block (Intel AVX2)
|
||||
EXPERIMENTAL_FEATURE
|
||||
sha1_one_block_avx2(chunk, s);
|
||||
#else
|
||||
// Perform SHA one block (legacy)
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
#include "crypto/sha256.h"
|
||||
|
||||
#include "crypto/common.h"
|
||||
#include "support/experimental.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
@ -91,6 +92,9 @@ void inline Initialize(uint32_t* s)
|
||||
void Transform(uint32_t* s, const unsigned char* chunk)
|
||||
{
|
||||
#if defined(USE_ARMV8) || defined(USE_ARMV82)
|
||||
// entire block is experimental
|
||||
EXPERIMENTAL_FEATURE
|
||||
|
||||
uint32x4_t STATE0, STATE1, ABEF_SAVE, CDGH_SAVE;
|
||||
uint32x4_t MSG0, MSG1, MSG2, MSG3;
|
||||
uint32x4_t TMP0, TMP1, TMP2;
|
||||
@ -247,6 +251,7 @@ void Transform(uint32_t* s, const unsigned char* chunk)
|
||||
|
||||
#elif USE_AVX2
|
||||
// Perform SHA256 one block (Intel AVX2)
|
||||
EXPERIMENTAL_FEATURE
|
||||
sha256_one_block_avx2(chunk, s);
|
||||
#else
|
||||
// Perform SHA256 one block (legacy)
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
#include "crypto/sha512.h"
|
||||
|
||||
#include "crypto/common.h"
|
||||
#include "support/experimental.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
@ -100,6 +101,8 @@ void inline Round(uint64_t a, uint64_t b, uint64_t c, uint64_t& d, uint64_t e, u
|
||||
|
||||
#ifdef USE_ARMV82
|
||||
|
||||
EXPERIMENTAL_FEATURE
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* Hardware-accelerated implementation of SHA-512 using Arm NEON.
|
||||
*/
|
||||
@ -311,6 +314,7 @@ void Transform(uint64_t* s, const unsigned char* chunk)
|
||||
{
|
||||
#ifdef USE_AVX2
|
||||
// Perform SHA512 one block (Intel AVX2)
|
||||
EXPERIMENTAL_FEATURE
|
||||
sha512_one_block_avx2(chunk, s);
|
||||
#elif USE_ARMV82
|
||||
sha512_neon_core core;
|
||||
|
||||
22
src/support/experimental.h
Normal file
22
src/support/experimental.h
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright (c) 2022 The Dogecoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#ifndef DOGECOIN_SUPPORT_EXPERIMENTAL_H
|
||||
#define DOGECOIN_SUPPORT_EXPERIMENTAL_H
|
||||
|
||||
// include config for experimental flag
|
||||
#if defined(HAVE_CONFIG_H)
|
||||
#include "config/bitcoin-config.h"
|
||||
#endif //HAVE_CONFIG_H
|
||||
|
||||
#if defined(ALLOW_DOGECOIN_EXPERIMENTAL)
|
||||
#define EXPERIMENTAL_FEATURES_ALLOWED 1
|
||||
#else
|
||||
#define EXPERIMENTAL_FEATURES_ALLOWED 0
|
||||
#endif // ALLOW_DOGECOIN_EXPERIMENTAL
|
||||
|
||||
#define EXPERIMENTAL_FEATURE static_assert(EXPERIMENTAL_FEATURES_ALLOWED == 1, \
|
||||
"Experimental features need to be explicitly enabled during configuration.");
|
||||
|
||||
#endif //BITCOIN_SUPPORT_EXPERIMENTAL_H
|
||||
Loading…
x
Reference in New Issue
Block a user