Closed jblazquez closed 2 months ago
Note that if #383 is merged after this change, it probably needs to change how it detects NEON so it doesn't just check for an __aarch64__
define and instead uses IS_AARCH64
from blake3_impl.h
. Also, the inline ARM assembly won't be compatible with Windows on ARM and this other method would be needed.
Thanks for the fix and for the clear explanation!
Thanks! Will add a note to the other PR I mentioned so it’s compatible with this change.
the inline ARM assembly won't be compatible with Windows on ARM
why not? modern MSVC doesn't support __asm__
?
It doesn't, no. It used to support it for 32-bit Windows apps, but it never supported inline assembly for 64-bit Windows: https://learn.microsoft.com/en-us/cpp/assembler/inline/inline-assembler?view=msvc-170
Inline assembly is not supported on the ARM and x64 processors.
They provide intrinsics for many common uses of inline assembly. For all other use cases, you need to use separate assembly files.
This PR solves two issues when building for Windows on ARM:
blake3_dispatch.c
due to a missing include.The first issue manifests as follows. You can repro in an ARM64 Visual Studio Developer Command Prompt:
The second issue is more subtle. When building for the ARM64EC ABI, the compiler defines the
_M_X64
macro and not the_M_ARM64
macro, to make incremental porting existing X64 Windows code to ARM easier.This means that the BLAKE3 library was detecting ARM64EC as AMD64 and defining
IS_X86
andIS_X86_64
. This causes the library to compile in the SSE2 and SSE4.1 vector implementations of the algorithm instead of NEON, which amazingly does work even when building for Windows on ARM64, because Windows provides an emulated implementation of Intel SIMD instruction sets up to SSE4.2 in thesoftintrin.lib
library. The end result is not ideal though, because it mixes native ARM64 code for the portable parts of the algorithm with emulated Intel SIMD intrinsics.The second change is thus to make the CPU architecture detection in
blake3_impl.h
aware of the ARM64EC ABI so it can choose the NEON implementation.