Skip to content

fix x86_64 arch detection when cross-compiling on macos arm64#6730

Open
LudovicoYIN wants to merge 2 commits into
Tencent:masterfrom
LudovicoYIN:fix-x86_64-cross-compile-on-macos-arm64
Open

fix x86_64 arch detection when cross-compiling on macos arm64#6730
LudovicoYIN wants to merge 2 commits into
Tencent:masterfrom
LudovicoYIN:fix-x86_64-cross-compile-on-macos-arm64

Conversation

@LudovicoYIN
Copy link
Copy Markdown

@LudovicoYIN LudovicoYIN commented May 19, 2026

Summary

Fix #6505 — when cross-compiling ncnn for x86_64 on macOS arm64 with
-DCMAKE_OSX_ARCHITECTURES=x86_64, the target architecture is incorrectly
detected as ARM, causing all x86 SIMD optimizations (SSE/AVX/AVX2/AVX512)
to be skipped.

Root cause

In CMakeLists.txt:164, CMAKE_SYSTEM_PROCESSOR always reports the host
CPU (arm64), even when CMAKE_OSX_ARCHITECTURES is explicitly set to
x86_64. This causes the ARM arch branch to match, setting
NCNN_TARGET_ARCH to arm instead of x86.

Fix

On Apple platforms, skip the CMAKE_SYSTEM_PROCESSOR arm match when
CMAKE_OSX_ARCHITECTURES is explicitly set to a non-arm architecture.

Before / After

Before After
Target arch arm 64bit x86 64bit
NEON/VFPv4/SVE attempted, all FAIL skipped
SSE/AVX/AVX2/FMA/F16C skipped all detected
AVX512/VNNI/BF16/FP16 skipped all detected
Build output x86_64 (no SIMD) x86_64 (full SIMD)

@tencent-adm
Copy link
Copy Markdown
Member

tencent-adm commented May 19, 2026

CLA assistant check
All committers have signed the CLA.

@LudovicoYIN
Copy link
Copy Markdown
Author

@nihui This PR fixes the arch detection issue in #6505. PTAL when you have a moment, thanks!

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.93%. Comparing base (07ecc25) to head (a815923).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6730      +/-   ##
==========================================
- Coverage   95.96%   95.93%   -0.03%     
==========================================
  Files         970      970              
  Lines      403093   403668     +575     
==========================================
+ Hits       386820   387273     +453     
- Misses      16273    16395     +122     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes incorrect target architecture detection when cross-compiling ncnn for x86_64 on Apple Silicon (macOS arm64) with -DCMAKE_OSX_ARCHITECTURES=x86_64, which previously caused the build to be treated as ARM and skipped all x86 SIMD feature detection.

Changes:

  • Adjust ARM-architecture detection on Apple platforms to avoid using CMAKE_SYSTEM_PROCESSOR (host CPU) when CMAKE_OSX_ARCHITECTURES is explicitly set to a non-ARM architecture.
  • Ensures x86_64 cross-compiles on macOS arm64 properly follow the x86 feature-probing path (SSE/AVX/etc.).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

compile for x86_64 on macos arm64

4 participants