Optimising an 1D heat equation using SIMD

眉间皱痕 提交于 2019-12-04 13:19:45

The wise words of Mysticial in code:

  xmm7 = InvDxDx * dtAlpha; // precalculate
  xmm6 = -2*xmm7;
  xmm0 = *ptr++;   // has values d0, d1
  xmm1 = *ptr++;   // has values d2, d3
  while (loop--) {
     xmm2  = xmm0;  // take a copy of d0,d1
     xmm0 += xmm1;  // d0+d2, d1+d3
     xmm2 = shufps (xmm2,xmm1, 0x47);  // the middle elements d1,d2 ??
     xmm0 *= xmm7;  // sum of outer elements * factor
     xmm2 *= xmm6;  // -2 * center element * factor
     // here's still a nasty dependency
     xmm2 += xmm0;
     xmm0 = xmm1;    // shift registers
     *out_ptr ++= xmm2;  // flush
     xmm1 = *ptr++;  // read in new values

  }

This can be improved by dividing the loop into 2 segments, each working 502 entries apart or from different tasks and interleaving the results, which breaks the dependency chain.

Also, the shift register approach xmm0 <- xmm1, xmm1 <- new can be avoided by unrolling the loop twice and changing the meanings of xmm0 and xmm1 every other case.

This points another big issue: when using intrinsics, registers are spilled to memory all the time.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!