优化我的内部循环(ARM、android ndk)

优化我的内部循环(ARM、android ndk),android,c++,c,optimization,android-ndk,Android,C++,C,Optimization,Android Ndk,我正在android上编写一个图像处理应用程序,我正在尝试使用NDK来加速它。我有以下for循环: int x, y, c, idx; const int pitch3 = pitch * 3; float adj, result; ... // px, py, u, u_bar are all float arrays of size nx*ny*3 // theta, tau, denom are float constants // idx >= pitch3 for(y=1

我正在android上编写一个图像处理应用程序,我正在尝试使用NDK来加速它。我有以下for循环:

int x, y, c, idx;
const int pitch3 = pitch * 3;
float adj, result;

...

// px, py, u, u_bar are all float arrays of size nx*ny*3
// theta, tau, denom are float constants
// idx >= pitch3  
for(y=1;y<ny;++y)
{
  for(x=1;x<nx;++x)
  {
    for(c=0;c<3;++c)
    {
      adj = -px[idx] - py[idx] + px[idx - 3] + py[idx - pitch3];
      result = ((u[idx] - tau * adj) + tau * f[idx]) * denom;
      u_bar[idx] = result + theta * (result - u[idx]);
      u[idx] = result;
      ++idx;
    }
  }
}
intx,y,c,idx;
常数int pitch3=节距*3;
浮动调整,结果;
...
//px、py、u、u_条都是大小为nx*ny*3的浮点数组
//θ、tau、denom是浮点常数
//idx>=pitch3

对于(y=1;y由于您是以平面结构访问阵列,因此3个级别的循环仅增加用于idx的值。您可以循环(idx=pitch3;idx
另一个选择是转移到定点数学。你真的需要超过64位的动态范围吗?

也许我遗漏了一些东西,但你的计算似乎没有使用任何循环变量y、x或c。因此,从这个意义上说,计算可以移到循环之外。你是为armeabi还是armeabi-v7a构建的?前者使用soft浮点,后者使用硬浮点,但限制您使用带有ARMv7 CPU的设备。