简体   繁体   English

错误:'18446744069414584320ull'从'long long unsigned int'到'int'的缩小转换{} [-Wnarrowing]

[英]error: narrowing conversion of ‘18446744069414584320ull’ from ‘long long unsigned int’ to ‘int’ inside { } [-Wnarrowing]

What is wrong with this piece of code?这段代码有什么问题? I'm using GCC 6.3.我正在使用 GCC 6.3。

https://ideone.com/ektGEp https://ideone.com/ektGEp

a.cpp: In function 'int main()':`a.cpp:26:24: error: narrowing conversion of '18446744069414584320ull' from 'long long unsigned int' to 'int' inside { } [-Wnarrowing] a.cpp:在函数 'int main()':`a.cpp:26:24: 错误:'18446744069414584320ull' 从 'long long unsigned int' 到 'int' 的缩小转换 { } [-Wnarrowing]

#include <iostream>
using namespace std;
#include <smmintrin.h>
#include <emmintrin.h>
#include <tmmintrin.h>

typedef union {
        __m64  mm64[2];
        __m128 mm128i;
} sse2_t;

#define const_epi32( i3,i2,i1,i0 )      \
            { static_cast<unsigned long long> (static_cast<unsigned long long>(i1) << 32), \
              static_cast<unsigned long long> (static_cast<unsigned long long>(i3) << 32) }

int main() {

        sse2_t arr_val[3] = { const_epi32(0,-1,0,-1),
                          const_epi32(0, 0,-1, -1),
                          const_epi32(0, 0,0, 1024) 
                        }; //error!

        sse2_t val = const_epi32(0,-1,0,-1); // ok!
        // your code goes here
        return 0;
}

The types __m64 and __m128 are very special, representing vector registers, which means that you cannot assign values to them in the usual way (like you seem to be trying to do in your code). __m64__m128类型非常特殊,表示向量寄存器,这意味着您不能以通常的方式为它们赋值(就像您在代码中试图做的那样)。 You need to use special load functions to put data into registers, and special store functions to get data back from there.您需要使用特殊的加载函数将数据放入寄存器,并使用特殊的存储函数从那里取回数据。

Here is an example of how you could load data (four floats) into a __m128 variable:以下是如何将数据(四个浮点数)加载到__m128变量的__m128

#include <cstring>
#include <smmintrin.h>
int main() {
  float f[4];
  memset(f, 0, 16);
  __m128 a = _mm_load_ps(f);
  return 0;
}

This page has lots of info about all the different types and intrinsic functions available: https://software.intel.com/sites/landingpage/IntrinsicsGuide/此页面包含有关所有不同类型和可用内在函数的大量信息: https : //software.intel.com/sites/landingpage/IntrinsicsGuide/

#define const_epi32( i3,i2,i1,i0 )      \
        { _m_from_int64( (static_cast<unsigned long long>(i1) << 32), \
          _m_from_int64( (static_cast<unsigned long long>(i3) << 32) }

The part const_epi32(0, 0,-1, -1) is causing the warning since you are assigning '0xffffFFFFffffFFFF' to a 32 bit 'int' which is narrowing.部分const_epi32(0, 0,-1, -1)导致警告,因为您将 '0xffffFFFFffffFFFF' 分配给正在缩小的 32 位 'int'。

I assume the other cases do not cause a warning since the assigned value is a constant 0 which does not suffer from narrowing.我假设其他情况不会引起警告,因为分配的值是一个常数 0,不会受到缩小的影响。

The other question is, why is __m64 an int .另一个问题是,为什么__m64int I assume that __m64 cannot be directly assigned to (being an MM register) and that the narrowing check (at least for constant assignment) is bogus in the compiler.我假设__m64不能直接分配给(作为 MM 寄存器),并且缩小检查(至少对于常量分配)在编译器中是虚假的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:{}中的&#39;199&#39;从&#39;int&#39;到&#39;char&#39;的转换变窄 - error: narrowing conversion of ‘199’ from ‘int’ to ‘char’ inside { } [-Wnarrowing] 缩小从int到long unsigned int {}的转换在C ++ 11中是不正确的 - narrowing conversion from int to long unsigned int {} is ill-formed in C++11 没有从long unsigned int转换为long unsigned int& - No conversion from long unsigned int to long unsigned int& 错误:从&#39;int(*)()&#39;到&#39;long unsigned int&#39;的无效转换 - error: invalid conversion from 'int (*)()' to 'long unsigned int' C ++ [错误]分配只读位置&#39;*(a +((sizetype)((((long long unsigned int)min)* 4ull)))&#39;&#39; - C++ [Error] assignment of read-only location '*(a + ((sizetype)(((long long unsigned int)min) * 4ull)))' 在C ++中从无符号long long转换为unsigned int - Conversion from unsigned long long to unsigned int in C++ 为什么“ unsigned int ui = {-1};”会缩小转换错误? - Why is “unsigned int ui = {-1};” a narrowing conversion error? 缩小从 int 到 unsigned char 的转换 - Narrowing conversion from int to unsigned char 是转换int - &gt; unsigned long long由标准定义 - Is conversion int -> unsigned long long defined by the standard 从“unsigned int”到“int”的转换需要缩小转换 - conversion from 'unsigned int' to 'int' requires a narrowing conversion
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM