ARM NEON 指令
HelloNeon中FIR滤波器的C语言实现
[cpp]
/* this is a FIR filter implemented in C */
static void
fir_filter_c(short *output, const short* input, const short* kernel, int width, int kernelSize)
{
int offset = -kernelSize/2;
int nn;
for (nn = 0; nn < width; nn++) {
int sum = 0;
int mm;
for (mm = 0; mm < kernelSize; mm++) {
sum += kernel[mm]*input[nn+offset+mm];
}
output[nn] = (short)((sum + 0x8000) >> 16);
}
}
HelloNeon中FIR滤波器的Neon实现 (在调用前需要确定芯片支持NEON指令,具体见例程)
[cpp]
void
fir_filter_neon_intrinsics(short *output, const short* input, const short* kernel, int width, int kernelSize)
{
int nn, offset = -kernelSize/2;
for (nn = 0; nn < width; nn++)
{
int mm, sum = 0;
int32x4_t sum_vec = vdupq_n_s32(0);
for(mm = 0; mm < kernelSize/4; mm++)
{
int16x4_t kernel_vec = vld1_s16(kernel + mm*4);
int16x4_t input_vec = vld1_s16(input + (nn+offset+mm*4));
sum_vec = vmlal_s16(sum_vec, kernel_vec, input_vec);
}
sum += vgetq_lane_s32(sum_vec, 0);
sum += vgetq_lane_s32(sum_vec, 1);
sum += vgetq_lane_s32(sum_vec, 2);
sum += vgetq_lane_s32(sum_vec, 3);
if(kernelSize & 3)
{
for(mm = kernelSize - (kernelSize & 3); mm < kernelSize; mm++)
sum += kernel[mm] * input[nn+offset+mm];
}
output[nn] = (short)((sum + 0x8000) >> 16);
}
}
输出结果可能如下,下面这个图的数据是我ps出来的,由于台式机不支持NEON指令(除非你开发用的电脑是用ARM芯片 :-P),模拟器上输出的实际数据要么更慢,要么报告Not an ARMv7 CPU !
补充:综合编程 , 其他综合 ,