小编cpl*_*les的帖子

如何使用此宏来测试内存是否对齐?

我是一个SIMD初学者,我读过这个文章的话题(因为我使用AVX2兼容机).

现在,我已经阅读了这个问题来检查你的指针是否对齐.

我正在用这个玩具示例测试它main.cpp:

#include <iostream>
#include <immintrin.h>

#define is_aligned(POINTER, BYTE_COUNT) \
    (((uintptr_t)(const void *)(POINTER)) % (BYTE_COUNT) == 0)


int main()
{
  float a[8];
  for(int i=0; i<8; i++){
    a[i]=i;
  }
  __m256 evens = _mm256_set_ps(2.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0, 16.0);
  std::cout<<is_aligned(a, 16)<<" "<<is_aligned(&evens, 16)<<std::endl;   
  std::cout<<is_aligned(a, 32)<<" "<<is_aligned(&evens, 32)<<std::endl;   

}
Run Code Online (Sandbox Code Playgroud)

然后编译它icpc -std=c++11 -o main main.cpp.

最终的印刷是:

1 1
1 1
Run Code Online (Sandbox Code Playgroud)

但是,如果我在4张照片之前加上3行:

for(int i=0; i<8; i++)
  std::cout<<a[i]<<" ";
std::cout<<std::endl;
Run Code Online (Sandbox Code Playgroud)

这是结果:

0 1 2 3 …
Run Code Online (Sandbox Code Playgroud)

c++ simd vectorization c++11 avx2

7
推荐指数
1
解决办法
765
查看次数

低效的内存访问模式和不规则的步幅访问

我正在尝试优化这个功能:

bool interpolate(const Mat &im, float ofsx, float ofsy, float a11, float a12, float a21, float a22, Mat &res)
{         
   bool ret = false;
   // input size (-1 for the safe bilinear interpolation)
   const int width = im.cols-1;
   const int height = im.rows-1;
   // output size
   const int halfWidth  = res.cols >> 1;
   const int halfHeight = res.rows >> 1;
   float *out = res.ptr<float>(0);
   const float *imptr  = im.ptr<float>(0);
   for (int j=-halfHeight; j<=halfHeight; ++j)
   {
      const float rx = ofsx …
Run Code Online (Sandbox Code Playgroud)

c++ parallel-processing intel vectorization intel-advisor

5
推荐指数
1
解决办法
472
查看次数