Skip to content

Fix Windows ARM64 (MSVC) build: disable NEON SIMD path#5046

Open
Chessing234 wants to merge 1 commit intofacebookresearch:mainfrom
Chessing234:fix/issue-4993-msvc-arm64-neon
Open

Fix Windows ARM64 (MSVC) build: disable NEON SIMD path#5046
Chessing234 wants to merge 1 commit intofacebookresearch:mainfrom
Chessing234:fix/issue-4993-msvc-arm64-neon

Conversation

@Chessing234
Copy link
Copy Markdown
Contributor

Summary

  • Fixes the Windows ARM64 (MSVC) build failure caused by the NEON SIMD templatization (D95392150 / PR Templatize simdlib types on SIMDLevel #4866)
  • MSVC ARM64 now falls back to the scalar (SIMDLevel::NONE) emulated implementation, which compiles and runs correctly
  • Three root causes are addressed by this workaround: (1) MSVC NEON builtins cannot be used as non-type template parameters, (2) MSVC collapses distinct NEON struct types to the same __n128x2, and (3) missing members/operators on NEON template specializations

Changes

  • faiss/CMakeLists.txt: Added AND NOT MSVC guard to the ARM64 NEON block so COMPILE_SIMD_ARM_NEON is not defined and NEON source files are not compiled on MSVC ARM64
  • cmake/link_to_faiss_lib.cmake: Same guard for the Dynamic Dispatch (DD) mode ARM64 path
  • faiss/impl/simdlib/simdlib_dispatch.h: Added _M_ARM64 recognition (MSVC's equivalent of __aarch64__) with explicit !defined(_MSC_VER) exclusion, plus explanatory comments

Test plan

  • Verify the build succeeds on Windows ARM64 with MSVC: cmake -B build -DFAISS_ENABLE_GPU=OFF -DFAISS_ENABLE_PYTHON=OFF -DBUILD_TESTING=OFF -A ARM64 && cmake --build build
  • Verify existing Linux/macOS aarch64 builds (GCC/Clang) are unaffected and still use the NEON path
  • Verify x86_64 builds are unaffected

Fixes #4993

🤖 Generated with Claude Code

MSVC ARM64 builds fail because MSVC implements NEON intrinsics as
compiler builtins whose addresses cannot be taken, breaking the
function-pointer template pattern in simdlib_neon.h. Additionally,
MSVC collapses distinct NEON struct types (e.g., uint8x16x2_t and
uint16x8x2_t) to the same __n128x2 type, causing overload ambiguity.

This change excludes MSVC ARM64 from the NEON SIMD compilation path
in CMake and in the simdlib dispatch header, causing it to fall back
to the scalar (SIMDLevel::NONE) emulated implementation. This is a
pragmatic workaround that unblocks the build while preserving
correctness; a future change can add proper MSVC NEON support.

Fixes facebookresearch#4993

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@meta-cla meta-cla bot added the CLA Signed label Apr 6, 2026
@algoriddle
Copy link
Copy Markdown
Contributor

Thanks for the fix! The CMakeLists.txt and link_to_faiss_lib.cmake changes look correct.

One simplification: the simdlib_dispatch.h change is redundant. Since the CMakeLists.txt change already ensures COMPILE_SIMD_ARM_NEON is never defined on MSVC ARM64, the #elif defined(COMPILE_SIMD_ARM_NEON) branch can never be reached on MSVC. Adding && !defined(_MSC_VER) and || defined(_M_ARM64) there has no effect — both are dead code. I'd drop that file from the PR and keep just the two CMake changes. A comment in CMakeLists.txt (which you already have) is sufficient to document the workaround.

@alibeklfc
Copy link
Copy Markdown
Contributor

Hi! Thank you for your contribution!
We are now almost done refactoring SIMD code in FAISS. Once we finish, we will review this diff.

@Chessing234
Copy link
Copy Markdown
Contributor Author

Thanks both! @algoriddle fair point — the simdlib_dispatch.h guard is redundant once the CMakeLists.txt change guarantees COMPILE_SIMD_ARM_NEON is never defined on MSVC ARM64. Happy to drop that hunk to keep the diff minimal.

@alibeklfc understood — I'll wait for the SIMD refactor to land before revising, so the fix lines up with the new layout instead of having to be rewritten twice. Ping me if you'd like me to rebase/trim earlier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows ARM64 (MSVC) build broken by NEON SIMD templatization (D95392150)

3 participants