0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-02 09:46:52 -05:00
bitcoin-bitcoin-core/src/crypto
fanquake 8da62a1041
Merge bitcoin/bitcoin#29263: serialization: c++20 endian/byteswap/clz modernization
86b7f28d6c serialization: use internal endian conversion functions (Cory Fields)
432b18ca8d serialization: detect byteswap builtins without autoconf tests (Cory Fields)
297367b3bb crypto: replace CountBits with std::bit_width (Cory Fields)
52f9bba889 crypto: replace non-standard CLZ builtins with c++20's bit_width (Cory Fields)

Pull request description:

  This replaces #28674, #29036, and #29057. Now ready for testing and review.

  Replaces platform-specific endian and byteswap functions. This is especially useful for kernel, as it means that our deep serialization code no longer requires bitcoin-config.h.

  I apologize for the size of the last commit, but it's hard to avoid making those changes at once.

  All platforms now use our internal functions rather than libc or platform-specific ones, with the exception of MSVC.

  Sadly, benchmarking showed that not all compilers are capable of detecting and optimizing byteswap functions, so compiler builtins are instead used where possible. However, they're now detected via macros rather than autoconf checks.

  This[ matches how libc++ implements std::byteswap for c++23](https://github.com/llvm/llvm-project/blob/main/libcxx/include/__bit/byteswap.h#L26).

  I suggest we move/rename `compat/endian.h`, but I left that out of this PR to avoid bikeshedding.

  #29057 pointed out some irregularities in benchmarks. After messing with various compilers and configs for a few weeks with these changes, I'm of the opinion that we can't win on every platform every time, so we should take the code that makes sense going forward. That said, if any real-world slowdowns are caused here, we should obviously investigate.

ACKs for top commit:
  maflcko:
    ACK 86b7f28d6c 📘
  fanquake:
    ACK 86b7f28d6c - we can finish pruning out the __builtin_clz* checks/usage once the minisketch code has been updated. This is more good cleanup pre-CMake & for the kernal.

Tree-SHA512: 715a32ec190c70505ffbce70bfe81fc7b6aa33e376b60292e801f60cf17025aabfcab4e8c53ebb2e28ffc5cf4c20b74fe3dd8548371ad772085c13aec8b7970e
2024-03-01 11:19:58 -05:00
..
ctaes Update ctaes 2016-12-08 17:09:07 -08:00
aes.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
aes.h scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
chacha20.cpp crypto, hash: replace custom rotl32 with std::rotl 2024-01-05 17:12:38 +01:00
chacha20.h crypto: make ChaCha20::SetKey wipe buffer 2023-08-17 15:37:41 -04:00
chacha20poly1305.cpp scripted-diff: Fix bitcoin_config_h includes 2024-02-13 20:10:44 +00:00
chacha20poly1305.h refactor: add missing headers for BIP324 ciphersuite 2023-08-15 07:30:48 +05:30
common.h serialization: use internal endian conversion functions 2024-02-28 13:42:38 +00:00
hkdf_sha256_32.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
hkdf_sha256_32.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
hmac_sha256.cpp Update copyright headers to 2018 2018-07-27 07:15:02 -04:00
hmac_sha256.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
hmac_sha512.cpp Update copyright headers to 2018 2018-07-27 07:15:02 -04:00
hmac_sha512.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
muhash.cpp crypto: refactor ChaCha20 classes to use Span<std::byte> interface 2023-08-17 15:26:34 -04:00
muhash.h scripted-diff: Fix bitcoin_config_h includes 2024-02-13 20:10:44 +00:00
poly1305.cpp Switch all callers from poly1305_auth to Poly1305 class 2023-07-12 22:43:55 -04:00
poly1305.h Switch all callers from poly1305_auth to Poly1305 class 2023-07-12 22:43:55 -04:00
ripemd160.cpp clang-tidy: Fix modernize-use-default-member-init in headers 2023-01-31 11:50:10 +00:00
ripemd160.h clang-tidy: Fix modernize-use-default-member-init in headers 2023-01-31 11:50:10 +00:00
sha1.cpp clang-tidy: Fix modernize-use-default-member-init in headers 2023-01-31 11:50:10 +00:00
sha1.h clang-tidy: Fix modernize-use-default-member-init in headers 2023-01-31 11:50:10 +00:00
sha3.cpp crypto, hash: replace custom rotl32 with std::rotl 2024-01-05 17:12:38 +01:00
sha3.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
sha256.cpp build: remove confusing and inconsistent disable-asm option 2024-02-29 19:05:45 +00:00
sha256.h Add ability to specify SHA256 implementation for benchmark purposes 2023-09-20 21:11:55 +01:00
sha256_arm_shani.cpp doc: Fix typos 2022-02-17 03:42:08 +09:00
sha256_avx2.cpp scripted-diff: Use platform-agnostic ALWAYS_INLINE macro 2023-05-04 20:58:01 +01:00
sha256_sse4.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
sha256_sse41.cpp scripted-diff: Use platform-agnostic ALWAYS_INLINE macro 2023-05-04 20:58:01 +01:00
sha256_x86_shani.cpp scripted-diff: Use platform-agnostic ALWAYS_INLINE macro 2023-05-04 20:58:01 +01:00
sha512.cpp clang-tidy: Fix modernize-use-default-member-init in headers 2023-01-31 11:50:10 +00:00
sha512.h clang-tidy: Fix modernize-use-default-member-init in headers 2023-01-31 11:50:10 +00:00
siphash.cpp crypto, hash: replace custom rotl32 with std::rotl 2024-01-05 17:12:38 +01:00
siphash.h refactor: use Span for SipHash::Write 2023-07-17 13:27:46 +02:00