iPhone上两个阵列之间最快的按位方式?

wle*_*lee 11 iphone optimization neon

我有两个图像块存储为1D数组,并在它们的元素之间执行以下按位AND操作.

int compare(unsigned char *a, int a_pitch, 
            unsigned char *b, int b_pitch, int a_lenx, int a_leny) 
{
    int overlap =0 ;

    for(int y=0; y<a_leny; y++) 
        for(int x=0; x<a_lenx; x++) 
        {
            if(a[x + y * a_pitch] & b[x+y*b_pitch]) 
                overlap++ ;
        }
    return overlap ;
}
Run Code Online (Sandbox Code Playgroud)

实际上,我必须做大约220,000次这个工作,所以它在iphone设备上变得非常慢.

我怎么能在iPhone上加速这项工作?

我听说NEON可能有用,但我并不熟悉它.此外,似乎NEON没有按位AND ...

And*_*sky 0

首先,为什么要双循环?您可以使用一个循环和几个指针来完成此操作。

此外,您不需要计算每个像素的 x+y*pitch;只需将两个指针加一即可。加一比 x+y*pitch 快很多。

究竟为什么需要执行此操作?在研究像 NEON 这样的低级解决方案之前,我会确保没有可用的高级优化/更改。