Close

Speed code comparison between C and Assembler

A project log for proximity controlled sampler

A sampler that is controller by a proximity sensor

estEst 07/01/2017 at 18:510 Comments

I have optimized a part of the code that re-samples the audio file, specifically the one that makes the convolution with the Sinc signal to low pass filter the audio file.

The code in C is:

for (i=0;i<nTaps;i++){

out+=(int32_t)inbuffer[i]*FilterTaps[i+FilterOffset[Ratio]];

}

This code takes 348 uS for a filter with 465 taps, this is the time needed to calculate the value of just one sample of the filtered audio signal.

The code below in assembler takes 28 uS to do the same thing

asm ("MOV #0xfffe, W0"); #0xfffe is the tap value

asm ("MUL.SS W0,[W1++],W2");

asm ("ADD W2,W4,W4");

asm ("ADDC W3,W5,W5");

These four instructions are repeated for every tap so no loop is needed. Is a waste of program space but i have plenty. The PIC24 i am using does not have multiply and accumulate instructions for DSP. If I will change to a dsPIC33 those 4 instructions should become one and the processing time should become 28uS/4=7 uS

Discussions