Detect ARM-64 in preprocessor?

后端 未结 1 1661
轻奢々
轻奢々 2020-12-20 06:51

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 previ

相关标签:
1条回答
  • 2020-12-20 07:22

    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 Studio\2017\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 Studio\2017\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 Studio\2017\Community>
    

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

    0 讨论(0)
提交回复
热议问题