下面的代码用于缩放图像,但性能不佳。我用谷歌搜索并找到了一些建议,将代码转换为Neon ASM以获得更好的性能。
inline void insetw32(char *pb_dst, char *pb_pFore, char *pb_pBack, char *pmix, int w)
{
register char bbm = (char)(pmix[0]<<24>>24);
for(int i = 0;i< w;i++)
{
*pb_dst++ = (((*pb_pFore++ - *pb_pBack++) * bbm)>>8) + *pb_pBack;
*pb_dst++ = (((*pb_pFore++ - *pb_pBack++) * bbm)>>8) + *pb_pBack;
*pb_dst++ = (((*pb_pFore++ - *pb_pBack++) * bbm)>>8) + *pb_pBack;
*pb_dst++ = (((*pb_pFore++ - *pb_pBack++) * bbm)>>8) + *pb_pBack;
}
}
我尝试用NEON翻译代码,性能比C语言快2倍,但是我使用MMX的相同代码在x86平台上的速度提高了4倍,还有其他改善方法吗?或者我的NEON代码有什么错误吗?
uint8x8_t fac1 = vdup_n_u8(bbm);
int16x8_t fac = vmovl_u8(fac1);
w /= 2; // 8/ 4
while (w--)
{
int8x8_t temp8;
int16x8_t temp16;
uint8x8_t rgbaFore = vld1_u8(pb_pFore);
uint8x8_t rgbaBack = vld1_u8(pb_pBack);
uint8x8_t rgbaDst = vld1_u8(pb_dst);
int16x8_t fore = vmovl_u8(rgbaFore);
int16x8_t back = vmovl_u8(rgbaBack);
temp16 = vsubq_s16(fore, back);
temp16 = vmulq_s16(temp16, fac);
temp8 = vshrn_n_s16(temp16, 8);
temp8 = vadd_u8(temp8, rgbaBack);
vst1_u8(pb_dst, temp8);
pb_dst += 8;
pb_pFore += 8;
pb_pBack += 8;
}