c++ - 在有足够空间的情况下加载到 Array 会导致 Stack Smashing?

标签 c++ intrinsics avx avx512 stack-smash

当执行下面的代码时,我得到一个Stack Smashing错误。

const uint size = 62;

...
for (int i=0; i < 10; ++i){
    // mask = elements != zero
    // input = epi32 m512 data containing 1 byte values
    _mm512_mask_compress_epi32(input, mask, input);
    // get just elements != 0 as previous mask. 
    __mmask16 mask1 = _mm512_cmpneq_epi32_mask(compressed, _mm512_setzero_epi32());
    // append the non-zero elements to the uchar* 
    _mm512_mask_cvtusepi32_storeu_epi8((uchar*)str+pos, mask1, compressed); // uncommenting = no error, truncating mask = no error

     // add size of the inserted elements by counting 1's in mask
     pos += sizeOfInsertion;

     // print the position of the pointer AFTER storing
     void* pp = (void*) ((uchar*) str + pos);
     std::cout << pp << std::endl;
}

为了调查这个问题,我在插入元素时检查了指针的位置。 在开头 (指向 str[0]) 我有 0x7ffce3468d30,在结尾 0x7ffce3468d69。减去这些地址我得到 3E = 62。所以它应该适合声明的数组。 将掩码移动 1(截断一个元素),它不会引发错误。

最佳答案

失败在于压缩。我不介意将不匹配掩码的值归零,因此数据不会连续存储,因此堆栈会溢出。

简而言之:

_mm512_maskz_compress_epi32(mask, input);

成功了。

关于c++ - 在有足够空间的情况下加载到 Array 会导致 Stack Smashing?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56214886/

相关文章:

c++ - Boost 或 STL 是否提供类似于 QString 的功能?

c++ - 如何动态构建完整的二叉树?

c++ - 如何检索 RTTI 以外的 C++ 类信息

c - 如何从 AVX 内在函数中获得用于计算基本统计数据的性能提升?

c++ - boost ,使用 tcp 通过网络发送文件,首选方法?

c++ - 将 SSE 翻译成 Neon : How to pack and then extract 32bit result

c++ - _mm_prefetch 是异步的吗?分析显示有很多周期

c - 英特尔内部函数的问题

c++ - 使用 SIMD 优化列式最大值

c++ - AVX 中的水平异或