Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

visual studio - Detect ARM-64 in preprocessor?

According to Microsoft (here and here), the company will support ARMv8/Aarch64 (ARM-64) in upcoming version of Windows 10. Additionally, Microsoft has already supplied previews so I'm guessing tool support is in place.

For those not aware, the images provided with the article clearly shows a Qualcomm Snapdragon 410. That's an A-53 core, and its Aarch64/ARM-64.

Microsoft defines _M_ARM for ARM-32, and we currently use it to detect NEON availability. ARMv8 supports optional extensions CRC32, AES, SHA-1, and SHA-2. We have code for them written already for Apple and Linux, and we'd like to enable it for Microsoft platforms.

Microsoft also has __M_ARM_FP, but its not clear to use it to detect ARM64. I'm also not clear on the relevance of 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.

I ran some quick tests on the Microsoft compilers I have available (all of them dating back to VC++ 5.0). They failed to consume ARMv8 intrinsics, which is not surprising. I'm guessing I need a MSDN subscription to test with the latest tools, but I no longer have the subscription.

My questions are:

  • How do we detect ARMv8/Aarch64 in the preprocessor (_M_ARM64?)
  • What version of the compiler (_MSC_VER) support ARMv8 instructions

This may be related: What is WINAPI_FAMILY_ONECORE_APP?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

VS starting from VS2017 uses _M_ARM64, see below for more details.

Answers, in reverse order:

  • None of the currently released Visual Studio versions support ARMv8/AArch64, they only support ARMv7. Even though Windows 10 itself shows signs of arm64 support (there's some executables and libraries for arm64), none of the versions of the compiler that have been released so far actually include it, to my knowledge. (Visual Studio 2015 Community at least doesn't include it, and neither does the new Visual Studio "15" Preview 2 that was released a few days ago.) So clearly it exists internally, but it hasn't been made part of any public release yet.

  • As for what define to look for; this is currently unknown, since there's no public documentation for the arm64 target version of the compiler since it's not been released yet, and one can't test empirically either.

I don't see any clear statement from Microsoft in either of your links saying that it will be supported, but at least the Windows 10 SDK does show clear signs of it being worked on.


Edit:

Even though the compiler isn't available, the Windows 10 SDK (which itself contains libs for ARM64) headers and Visual C++ 2015 headers (which have no matching ARM64 libs) also contains references to this. Similarly to _M_ARM, there's also _M_ARM64. A snippet from 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

Edit2:

While no public version of the Visual C++ compiler targeting arm64 is available yet, clang is getting the first parts of support for Windows/arm64, and they also use _M_ARM64:

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


Edit3:

With the latest update of Visual Studio 2017, version 15.4, the ARM64 compiler is released. In the installer, one can manually check the "Visual C++ compilers and libraries for ARM64" item (it isn't enabled by default).

After doing that, you can launch "Developer Command Prompt for VS 2017", and in that shell run "vsdevcmd -arch=arm64 -host_arch=amd64", then you've got the compiler in the path:

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

C:Program Files (x86)Microsoft Visual Studio2017Community>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 Studio2017Community>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 Studio2017Community>

And this compiler predefines _M_ARM64 which allows you to identify it, thus answering this question.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...