bitcoin/src/util
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
..
any.h refactor: Split util::AnyPtr into its own file 2023-05-20 12:03:33 +02:00
asmap.cpp crypto: replace CountBits with std::bit_width 2024-02-26 16:13:12 +00:00
asmap.h refactor: Move fs.* to util/fs.* 2023-03-23 12:55:18 +01:00
batchpriority.cpp refactor: Move ScheduleBatchPriority to its own file 2023-05-20 12:03:30 +02:00
batchpriority.h refactor: Move ScheduleBatchPriority to its own file 2023-05-20 12:03:30 +02:00
bip32.cpp Merge bitcoin/bitcoin#26076: Switch hardened derivation marker to h 2023-05-08 13:31:28 -04:00
bip32.h Switch hardened derivation marker to h in descriptors 2023-04-04 18:33:08 +02:00
bitdeque.h Add bitdeque, an std::deque<bool> analogue that does bit packing. 2022-08-23 11:34:10 -04:00
bytevectorhash.cpp refactor: use Span for SipHash::Write 2023-07-17 13:27:46 +02:00
bytevectorhash.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
chaintype.cpp refactor: Create chaintype files 2023-05-09 11:33:09 +02:00
chaintype.h refactor: Create chaintype files 2023-05-09 11:33:09 +02:00
check.cpp removed StrFormatInternalBug quote delimitation 2023-08-18 04:04:06 +00:00
check.h Export assert from util/check.h 2023-11-24 13:11:36 +01:00
epochguard.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
error.cpp Add test for unspendable transactions and parameter 'maxburnamount' to sendrawtransaction. 2023-02-20 11:38:52 -07:00
error.h Add test for unspendable transactions and parameter 'maxburnamount' to sendrawtransaction. 2023-02-20 11:38:52 -07:00
exception.cpp refactor: Extract util/exception from util/system 2023-03-13 17:09:47 +01:00
exception.h refactor: Extract util/exception from util/system 2023-03-13 17:09:47 +01:00
fastrange.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
fees.cpp Fix clang-tidy readability-const-return-type violations 2023-02-01 11:33:35 +01:00
fees.h Fix clang-tidy readability-const-return-type violations 2023-02-01 11:33:35 +01:00
fs.cpp Add tests for C++20 std::u8string 2023-12-11 17:42:05 +01:00
fs.h refactor: Rename fs::path::u8string() to fs::path::utf8string() 2023-12-14 16:22:40 +01:00
fs_helpers.cpp Merge bitcoin/bitcoin#28075: util: Remove DirIsWritable, GetUniquePath 2023-12-13 10:06:16 +00:00
fs_helpers.h Remove DirIsWritable, GetUniquePath 2023-10-26 10:32:56 +02:00
golombrice.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
hash_type.h move-only: Add util/hash_type 2021-05-11 10:38:18 +02:00
hasher.cpp refactor: use Span for SipHash::Write 2023-07-17 13:27:46 +02:00
hasher.h Bump g++ minimum supported version to 10 2023-10-30 15:12:26 +01:00
insert.h refactor: Split util::insert into its own file 2023-05-20 12:03:31 +02:00
macros.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
message.cpp Make WitnessUnknown members private 2023-09-12 12:14:31 -04:00
message.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
moneystr.cpp refactor: use braced init for integer constants instead of c style casts 2023-01-03 19:31:29 -06:00
moneystr.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
overflow.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
overloaded.h doc: Clarify C++20 comments 2024-01-05 11:22:31 +01:00
rbf.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
rbf.h scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
readwritefile.cpp refactor: Move fs.* to util/fs.* 2023-03-23 12:55:18 +01:00
readwritefile.h refactor: Move fs.* to util/fs.* 2023-03-23 12:55:18 +01:00
result.h util: Add void support to util::Result 2023-05-24 08:55:47 -04:00
serfloat.cpp Add platform-independent float encoder/decoder 2021-05-24 16:04:44 -07:00
serfloat.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
signalinterrupt.cpp util: Get rid of uncaught exceptions thrown by SignalInterrupt class 2023-12-04 15:39:15 -04:00
signalinterrupt.h util: Get rid of uncaught exceptions thrown by SignalInterrupt class 2023-12-04 15:39:15 -04:00
sock.cpp sock: change Sock::SendComplete() to take Span 2023-10-31 18:19:22 +01:00
sock.h sock: change Sock::SendComplete() to take Span 2023-10-31 18:19:22 +01:00
spanparsing.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
spanparsing.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
strencodings.cpp util: Work around ParseHex gcc cross compiler bug 2023-03-07 11:33:42 +01:00
strencodings.h doc: remove out-of-date external link in src/util/strencodings.h 2023-08-24 15:51:25 -06:00
string.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
string.h test: Throw error when -signetchallenge is non-hex 2023-05-25 19:24:05 +02:00
syserror.cpp Show descriptive error messages when FileCommit fails 2023-06-30 09:48:21 -04:00
syserror.h Show descriptive error messages when FileCommit fails 2023-06-30 09:48:21 -04:00
thread.cpp refactor: Extract util/exception from util/system 2023-03-13 17:09:47 +01:00
thread.h scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
threadinterrupt.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
threadinterrupt.h util: Add SignalInterrupt class and use in shutdown.cpp 2023-06-28 09:49:28 +02:00
threadnames.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
threadnames.h scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
time.cpp refactor: Remove unused GetTimeMillis 2023-05-08 12:40:48 +02:00
time.h [refactor] Remove compat.h from kernel headers 2023-09-12 22:51:48 +02:00
tokenpipe.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
tokenpipe.h util: Add RAII TokenPipe 2021-03-04 18:24:00 +01:00
trace.h Revert "tracepoints: Disables -Wgnu-zero-variadic-macro-arguments to compile without warnings" 2023-12-07 11:06:13 +01:00
transaction_identifier.h Add transaction_identifier::size to allow Span conversion 2024-02-27 14:19:15 +00:00
translation.h refactor: Avoid copy of bilingual_str when formatting, Fix ADL violation 2023-06-15 16:21:29 +02:00
types.h doc: Clarify C++20 comments 2024-01-05 11:22:31 +01:00
ui_change_type.h wallet: Do not include server symbols 2020-06-27 11:39:09 -04:00
vector.h chainparams: add blockhash to AssumeutxoData 2023-09-30 06:38:47 -04:00