#24773 Enable HW-accelerated implementations of SHA256 for MSVC builds

full analysis

https://github.com/bitcoin/bitcoin/pull/24773 · hebasto · +102/-61 in 4 files, 5 commits · labels: Build system, Utils/log/libs

Goal

  • Bring hardware-accelerated SHA256 hashing to MSVC builds on Windows
  • Eliminate significant hashing performance penalties for native Windows developer builds

This PR enables hardware-accelerated SHA256 routines (SSE4.1, AVX2, and SHA-NI) for MSVC builds on Windows. It implements `GetCPUID()` and `AVXEnabled()` using MSVC intrinsics in compat and crypto headers and adjusts CMake introspection to test and enable the corresponding compiler flags under MSVC.

Problem: MSVC builds on Windows cannot compile the GCC-style inline assembly and compiler flags used for hardware-accelerated SHA256, falling back to the generic standard implementation and suffering significant hashing performance penalties.

Category: Build and CI (#44 of 55)

P3 · speedup

  • P3 because official release binaries use MinGW and Guix rather than MSVC
  • Benefit is limited strictly to contributors compiling natively on Windows

It improves CMake compiler detection to support accelerated instructions on MSVC. However, official Windows release binaries are produced with MinGW/GCC in Guix, so this only benefits contributors building natively with MSVC on Windows.

Membership: Modifies cmake/introspection.cmake to check for and set SSE4.1, AVX2, and SHA-NI compiler support under MSVC.

Factors: security/stability 0, bug 0, performance 2, user value 1, leverage 0

Category: Utilities (logging, arguments, libraries) (#49 of 66)

P3 · speedup

  • P3 because hashing operations achieve five- to ten-fold speed improvements
  • Impact is confined to native Windows development rather than end users

It provides 5x to 10x speedups for SHA256 operations on MSVC by enabling hardware-accelerated cryptographic routines via MSVC intrinsics. The impact is limited to native Windows developer builds.

Membership: Modifies src/crypto/sha256.cpp and src/compat/cpuid.h to implement CPUID and AVX detection intrinsics for MSVC.

Factors: security/stability 0, bug 0, performance 2, user value 1, leverage 0

Reviewability: Paused: Waiting on author

  • Paused while waiting on author response regarding a project decision to close it
  • Maintainers decided in a meeting to drop MSVC support in favor of clang-cl in #31507

Maintainers noted that a weekly meeting decided to close this PR in favor of dropping MSVC support in #31507; the PR has been waiting on the author's response for 29 days.

Author status: silent since 2026-08-13

Open concerns:

  • The project direction in #31507 proposes dropping native MSVC support in favor of clang-cl, making additional MSVC-specific workarounds counterproductive.
  • Maintainers noted that the outcome of a recent weekly meeting was to close this PR, but the author has not replied.

Resolved concerns:

  • Separation of the general ALWAYS_INLINE macro into PR #27575.
  • Added SHA256-specific benchmarks in PR #27598 to verify speedups.

Agreement: Blocked

  • Blocked by project decision to deprecate MSVC support in favor of #31507
  • Unaddressed objection: adds MSVC code conflicting with #31507, no author reply (fanquake)
  • Verified by testing five- to ten-fold hashing speedups on Windows (sipsorcery, m3dwards)
  • Concept approval while questioning the AVX2 choice (laanwj)

Blocked: maintainers note the project decided to drop MSVC in favor of #31507; author has not replied.

While the PR previously received positive feedback and testing benchmarks from several contributors, maintainers fanquake and maflcko indicated the project intends to drop MSVC in #31507, and the PR has remained unanswered by the author since August 2026.

  • laanwj: 'Concept ACK—but it does makes me wonder why AVX2 specifically?'
  • sipsorcery: 'tACK e94ae810... Relevant bench_bitcoin.exe results from my Intel i9 CPU machine. Looks up 5 to 10x faster'
  • m3dwards: 'Tested e94ae81 on Windows 11 with VS2022... saw big speed improvement'
  • fanquake: 'seems to go in the opposite direction of your other PRs (by adding more MSVC specific code), such as #31507'
  • fanquake: 'I think so, and it seems like the plan is to go ahead with #31507?'

Review verdicts (DrahtBot): 0 (+1)

Files

0 lines under test/bench/ci.

  • cmake/introspection.cmake +74/-60
  • src/compat/cpuid.h +18/-0
  • src/crypto/sha256.cpp +9/-0
  • src/random.cpp +1/-1

Card

PR 24773 implements MSVC intrinsics for CPUID and AVX detection and updates CMake to enable SSE4.1, AVX2, and SHA-NI hardware-accelerated SHA256 routines on Windows. This resolves a large performance deficit for developers compiling with MSVC, delivering multi-fold SHA256 speedups on supported CPUs. It does not affect official release binaries, which are built using MinGW via Guix. Review is paused and the change is blocked by architectural uncertainty, as maintainers have indicated a preference to drop MSVC support in favor of clang-cl (#31507), awaiting the author's response.

Data

dossier JSON · extract JSON · model openrouter/google/gemini-3.8-flash, generated 2026-09-17T15:48, confidence high, input hash 9c331d730bce2ee1