Files
bitcoin/src/util
Lőrinc 248b6a27c3 optimization: peel align-head and unroll body to 64 bytes
Benchmarks indicated that obfuscating multiple bytes already gives an order of magnitude speed-up, but:
* GCC still emitted scalar code;
* Clang’s auto-vectorized loop ran on the slow unaligned-load path.

Fix contains:
* peeling the misaligned head enabled the hot loop starting at an 8-byte address;
* `std::assume_aligned<8>` tells the optimizer the promise holds - required to keep Apple Clang happy;
* manually unrolling the body to 64 bytes enabled GCC to auto-vectorize.

Note that `target.size() > KEY_SIZE` condition is just an optimization, the aligned and unaligned loops work without it as well - it's why the alignment calculation still contains `std::min`.

>  C++ compiler .......................... GNU 14.2.0

|             ns/byte |              byte/s |    err% |        ins/byte |        cyc/byte |    IPC |       bra/byte |   miss% |     total | benchmark
|--------------------:|--------------------:|--------:|----------------:|----------------:|-------:|---------------:|--------:|----------:|:----------
|                0.03 |   32,464,658,919.11 |    0.0% |            0.50 |            0.11 |  4.474 |           0.08 |    0.0% |      5.29 | `ObfuscationBench`

> C++ compiler .......................... Clang 20.1.7

|             ns/byte |              byte/s |    err% |        ins/byte |        cyc/byte |    IPC |       bra/byte |   miss% |     total | benchmark
|--------------------:|--------------------:|--------:|----------------:|----------------:|-------:|---------------:|--------:|----------:|:----------
|                0.02 |   41,231,547,045.17 |    0.0% |            0.30 |            0.09 |  3.463 |           0.02 |    0.0% |      5.47 | `ObfuscationBench`

Co-authored-by: Hodlinator <172445034+hodlinator@users.noreply.github.com>
2025-07-16 14:37:19 -07:00
..
2023-03-23 12:55:18 +01:00
2024-08-06 01:38:10 +02:00
2024-08-06 01:38:10 +02:00
2021-05-11 10:38:18 +02:00
2022-12-24 23:49:50 +00:00
2024-01-05 11:22:31 +01:00
2021-12-30 19:36:57 +02:00
2022-12-24 23:49:50 +00:00
2025-07-09 13:57:54 +02:00
2025-07-09 13:57:54 +02:00
2021-03-04 18:24:00 +01:00
2024-01-05 11:22:31 +01:00
2024-06-11 16:28:11 +00:00