【问题标题】:error C2440: '=' : cannot convert from 'int' to 'uint32x4_t'错误 C2440:“=”:无法从“int”转换为“uint32x4_t”
【发布时间】:2017-08-13 21:15:43
【问题描述】:

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

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


这是程序存根。 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 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

【问题讨论】:

    标签: c visual-studio arm intrinsics


    【解决方案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 中看到的要多。)

    【讨论】:

    • 谢谢。我再次下载了 Visual Studio 2017 Build Tools。安装程序是shows the product as a RC,而不是最终版本。你知道在哪里可以找到最终版本吗?微软的网站一团糟,搜索似乎大部分都被破坏了。另请参阅Visual Studio 2017 Downloads(在其他工具和框架下找到它)和VC++ 2017 Build Tools FAQ
    • 我不知道普通的 Build Tools 安装程序 - 我刚刚从 visualstudio.com 免费下载了完整的社区版。它有一个非常灵活的安装程序,所以如果你愿意的话,也许你可以只选择构建工具而不需要 IDE。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-25
    相关资源
    最近更新 更多