Joh*_*n C 9 c++ assembly arm filtering
我正在ARM9处理器上实现FIR滤波器,并尝试使用SMLAL指令.
最初我实现了以下过滤器并且它完美地工作,除了这种方法使用太多的处理能力在我们的应用程序中使用.
uint32_t DDPDataAcq::filterSample_8k(uint32_t sample)
{
// This routine is based on the fir_double_z routine outline by Grant R Griffin
// - www.dspguru.com/sw/opendsp/alglib.htm
int i = 0;
int64_t accum = 0;
const int32_t *p_h = hCoeff_8K;
const int32_t *p_z = zOut_8K + filterState_8K;
/* Cast the sample to a signed 32 bit int
* We need to preserve the signdness of the number, so if the 24 bit
* sample is negative we need to move the sign bit up to the MSB and pad the number
* with 1's to preserve 2's compliment.
*/
int32_t s = sample;
if (s & 0x800000)
s |= ~0xffffff;
// store input sample at the beginning of the delay line as well as ntaps more
zOut_8K[filterState_8K] = zOut_8K[filterState_8K+NTAPS_8K] = s;
for (i =0; i<NTAPS_8K; ++i)
{
accum += (int64_t)(*p_h++) * (int64_t)(*p_z++);
}
//convert the 64 bit accumulator back down to 32 bits
int32_t a = (int32_t)(accum >> 9);
// decrement state, wrapping if below zero
if ( --filterState_8K < 0 )
filterState_8K += NTAPS_8K;
return a;
}
Run Code Online (Sandbox Code Playgroud)
我一直试图用内联汇编替换乘法累加,因为即使打开优化,GCC也没有使用MAC指令.我用以下内容替换了for循环:
uint32_t accum_low = 0;
int32_t accum_high = 0;
for (i =0; i<NTAPS_4K; ++i)
{
__asm__ __volatile__("smlal %0,%1,%2,%3;"
:"+r"(accum_low),"+r"(accum_high)
:"r"(*p_h++),"r"(*p_z++));
}
accum = (int64_t)accum_high << 32 | (accum_low);
Run Code Online (Sandbox Code Playgroud)
我现在使用SMLAL指令获得的输出不是我期望的过滤数据.我得到的随机值似乎与原始信号或我期望的数据没有模式或连接.
我有一种感觉,我将64位累加器分成指令的高位和低位寄存器,或者我把它们重新组合在一起是错误的.无论哪种方式,我都不确定为什么我无法通过内联汇编交换C代码来获得正确的输出.