错误 C2440:“=”:无法从 'int' 转换为 'uint32x4_t'

error C2440: '=' : cannot convert from 'int' to 'uint32x4_t'

我在 VS2013、MS2015 和 VS2017 下从 ARM 开发人员命令提示编译程序时遇到问题。根据 <stdint.h> and <arm_neon.h> 的文档,headers 是正确的。

这是什么问题,我该如何解决?


这是程序存根。 full program works 在其他编译器下没问题。

#include <stdint.h>
#include <arm_neon.h>

static const uint32_t K[] =
{
    0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5
    /* ... more constants in real code ... */
};

uint32_t state[8] = {0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19};
uint32_t data[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

int main(int argc, char* argv[])
{
    uint32x4_t STATE0, STATE1, ABEF_SAVE, CDGH_SAVE;
    uint32x4_t MSG0, MSG1, MSG2, MSG3;
    uint32x4_t TMP0, TMP1, TMP2;

    STATE0 = vld1q_u32(&state[0]);
    STATE1 = vld1q_u32(&state[4]);

    /* Load message */
    MSG0 = vld1q_u32((const uint32_t *)(data +  0));
    MSG1 = vld1q_u32((const uint32_t *)(data + 16));
    MSG2 = vld1q_u32((const uint32_t *)(data + 32));
    MSG3 = vld1q_u32((const uint32_t *)(data + 48));

    /* Reverse for little endian */
    MSG0 = vreinterpretq_u32_u8(vrev32q_u8(vreinterpretq_u8_u32(MSG0)));
    MSG1 = vreinterpretq_u32_u8(vrev32q_u8(vreinterpretq_u8_u32(MSG1)));
    MSG2 = vreinterpretq_u32_u8(vrev32q_u8(vreinterpretq_u8_u32(MSG2)));
    MSG3 = vreinterpretq_u32_u8(vrev32q_u8(vreinterpretq_u8_u32(MSG3)));

    TMP0 = vaddq_u32(MSG0, vld1q_u32(&K[0x00]));

    /* Rounds 0-3 */
    MSG0 = vsha256su0q_u32(MSG0, MSG1);
    TMP2 = STATE0;
    TMP1 = vaddq_u32(MSG1, vld1q_u32(&K[0x04]));
    STATE0 = vsha256hq_u32(STATE0, STATE1, TMP0);
    STATE1 = vsha256h2q_u32(STATE1, TMP2, TMP0);
    MSG0 = vsha256su1q_u32(MSG0, MSG2, MSG3);

    return 0;
}

下面是错误信息。第37-42行是/* Rounds 0-3 */.

部分
C:\Users\Test\SHA-Intrinsics>cl.exe /DWINAPI_FAMILY=WINAPI_FAMILY_PHONE_APP msvc-arm.c
Microsoft (R) C/C++ Optimizing Compiler Version 18.00.40629 for ARM
Copyright (C) Microsoft Corporation.  All rights reserved.

msvc-arm.c
msvc-arm.c(37) : error C2440: '=' : cannot convert from 'int' to 'uint32x4_t'
msvc-arm.c(40) : error C2440: '=' : cannot convert from 'int' to 'uint32x4_t'
msvc-arm.c(41) : error C2440: '=' : cannot convert from 'int' to 'uint32x4_t'
msvc-arm.c(42) : error C2440: '=' : cannot convert from 'int' to 'uint32x4_t'

VS2017 似乎比 VS2013 和 VS2015 更破:

**********************************************************************
** Visual Studio 2017 RC Developer Command Prompt v15.0
** Copyright (c) 2016 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64_arm'

C:\Program Files (x86)\Microsoft Visual Studio17\BuildTools\VC\Auxiliary\Buil
d>cd C:\Users\Test\SHA-Intrinsics

C:\Users\Test\SHA-Intrinsics>cl.exe /DWINAPI_FAMILY=WINAPI_FAMILY_PHONE_APP msvc-arm.c
Microsoft (R) C/C++ Optimizing Compiler Version 19.10.24728 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

msvc-arm.c
C:\Program Files (x86)\Microsoft Visual Studio17\BuildTools\VC\Tools\MSVC.
10.24728\include\arm_neon.h(17): fatal error C1189: #error:  This header is spec
ific to ARM targets

主要问题似乎是编译器不支持 vsha256 内在函数。如果将 /W3 添加到编译器命令行,您将收到以下附加警告:

msvc-arm.c(37) : warning C4013: 'vsha256su0q_u32' undefined; assuming extern returning int

至于 VS 2017 案例,环境的设置方式有些不对 up/initialized,因为编译器版本横幅显示:

Microsoft (R) C/C++ Optimizing Compiler Version 19.10.24728 for x64

而实际瞄准手臂的人会说:

Microsoft (R) C/C++ Optimizing Compiler Version 19.10.25017 for ARM

(我现在没有正确安装能够帮助您正确初始化环境的那个,但这已经在 中讨论过)。VS 2017 的最终版本与您似乎已经安装的 RC 相比,IIRC 至少在这方面做了一些改变,至少我记得在最终版本中看到的开始菜单条目比我在 RC 中看到的要多。)