在预处理器中检测 ARM-64?

Detect ARM-64 in preprocessor?

根据 Microsoft 的说法(here and here), the company will support ARMv8/Aarch64 (ARM-64) in upcoming version of Windows 10. Additionally, Microsoft has already supplied previews 所以我猜工具支持已经到位。

对于那些不知道的人,images provided with the article 清楚地显示了 Qualcomm Snapdragon 410。那是一个 A-53 核心,它的 Aarch64/ARM-64。

Microsoft 为 ARM-32 定义了 _M_ARM,我们目前使用它来检测 NEON 可用性。 ARMv8 支持可选扩展 CRC32、AES、SHA-1 和 SHA-2。我们已经为 Apple 和 Linux 编写了代码,我们希望为 Microsoft 平台启用它。

微软也有__M_ARM_FP,但是不清楚用它来检测ARM64。我也不清楚 x86 的相关性:

Expands to an integer literal value indicating which /arch compiler option was used:

  • In the range 30-39 if no /arch ARM option was specified, indicating the default architecture for ARM was used (VFPv3).
  • In the range 40-49 if /arch:VFPv4 was used.
  • See /arch (x86) for more information.

我 运行 对我可用的 Microsoft 编译器进行了一些快速测试(所有这些都可以追溯到 VC++ 5.0)。它们未能使用 ARMv8 内在函数,这并不奇怪。我猜我需要 MSDN 订阅才能使用最新工具进行测试,但我不再订阅了。

我的问题是:


这可能是相关的:What is WINAPI_FAMILY_ONECORE_APP?

VS从VS2017开始使用_M_ARM64,详见下文

答案,倒序排列:

  • None 当前发布的 Visual Studio 版本支持 ARMv8/AArch64,它们只支持 ARMv7。尽管 Windows 10 本身显示了 arm64 支持的迹象(有一些 arm64 的可执行文件和库),据我所知,到目前为止已发布的编译器版本的 none 实际上包含它。 (Visual Studio 2015 Community 至少不包含它,几天前发布的新 Visual Studio “15” Preview 2 也不包含它。)很明显它在内部存在,但它没有'尚未成为任何 public 版本的一部分。

  • 至于define要找什么;这是目前未知的,因为没有 public 编译器的 arm64 目标版本的文档,因为它尚未发布,而且也无法根据经验进行测试。

我在你们的任何一个链接中都没有看到 Microsoft 有任何明确的声明说它将受到支持,但至少 Windows 10 SDK 确实显示出它正在开发中的明确迹象。


编辑:

即使编译器不可用,Windows 10 SDK(它本身包含 ARM64 的库)headers 和 Visual C++ 2015 headers(没有匹配的 ARM64 libs) 也包含对此的引用。与 _M_ARM 类似,还有 _M_ARM64。来自 vc/include/intrin.h 的片段:

#if defined (_M_ARM)
    #include <armintr.h>
    #include <arm_neon.h>
#endif

#if defined (_M_ARM64)
    #include <arm64intr.h>
    #include <arm64_neon.h>
#endif

编辑2:

虽然还没有针对 arm64 的 public 版本的 Visual C++ 编译器可用,但 clang 正在获得对 Windows/arm64 的第一部分支持,并且他们还使用 _M_ARM64:

https://github.com/llvm-project/clang/commit/5b7d7d2b2d0bd7054f51b9d108cdd5299a0ec33e#diff-ed544af3ae6807a8513b1cabb3233941R6576


编辑 3:

随着Visual Studio2017最新更新,版本15.4,ARM64编译器发布。在安装程序中,可以手动检查 "Visual C++ compilers and libraries for ARM64" 项(默认情况下未启用)。

完成后,您可以启动 "Developer Command Prompt for VS 2017",然后在 shell 运行 "vsdevcmd -arch=arm64 -host_arch=amd64" 中,您将在路径中获得编译器:

**********************************************************************
** Visual Studio 2017 Developer Command Prompt v15.4.0
** Copyright (c) 2017 Microsoft Corporation
**********************************************************************

C:\Program Files (x86)\Microsoft Visual Studio17\Community>vsdevcmd -arch=arm64 -host_arch=amd64
**********************************************************************
** Visual Studio 2017 Developer Command Prompt v15.4.0
** Copyright (c) 2017 Microsoft Corporation
**********************************************************************

C:\Program Files (x86)\Microsoft Visual Studio17\Community>cl
Microsoft (R) C/C++ Optimizing Compiler Version 19.11.25547 for ARM64
Copyright (C) Microsoft Corporation.  All rights reserved.

usage: cl [ option... ] filename... [ /link linkoption... ]

C:\Program Files (x86)\Microsoft Visual Studio17\Community>

并且这个编译器预定义了_M_ARM64,让你可以识别它,从而回答这个问题。