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

时间:2017-03-21 23:29:21

标签: c visual-studio arm intrinsics

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

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

这是程序存根。其他编译器下的<arm_neon.h>罚款。

#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 Studio\2017\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 Studio\2017\BuildTools\VC\Tools\MSVC\14.
10.24728\include\arm_neon.h(17): fatal error C1189: #error:  This header is spec
ific to ARM targets

1 个答案:

答案 0 :(得分:1)

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

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

对于VS 2017案例,由于编译器版本横幅说:

,环境设置/初始化的方式不正确。
Microsoft (R) C/C++ Optimizing Compiler Version 19.10.24728 for x64

虽然实际上瞄准武器的人会说:

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

(我现在没有正确安装那个,以便能够帮助您正确地初始化环境,但这已在https://stackoverflow.com/a/41728434/3115956中讨论过了.VS 2017 IIRC的最终版本确实如此与你似乎已安装的RC相比,至少改变一些与此相关的东西,至少我记得在最终版本中看到了比我在RC中看到的更多的开始菜单条目。)