c - Is a binary operation faster than memmove? -


i'm writing digital filter, , need keep last x values , sum them together.

now there 2 possible approaches this. either shift whole array using memmove make room next value, , have right indexes array hard-coded values in summing algorithm.

memmove(&fifo[0], &fifo[1], 12 * 4); // shift array left  result += factor[1] * (fifo[5] + fifo[7]); result += factor[2] * (fifo[4] + fifo[8]); result += factor[3] * (fifo[3] + fifo[9]); result += factor[4] * (fifo[2] + fifo[10]); result += factor[5] * (fifo[1] + fifo[11]); result += factor[6] * (fifo[0] + fifo[12]); 

or alternatively, don't copy memory, increment counter instead, , calculate each index using modulo operation (like circular buffer).

i++; // increment index  result += factor[1] * (fifo[(i + 5) % 13] + fifo[(i + 7) % 13]); result += factor[2] * (fifo[(i + 4) % 13] + fifo[(i + 8) % 13]); result += factor[3] * (fifo[(i + 3) % 13] + fifo[(i + 9) % 13]); result += factor[4] * (fifo[(i + 2) % 13] + fifo[(i + 10) % 13]); result += factor[5] * (fifo[(i + 1) % 13] + fifo[(i + 11) % 13]); result += factor[6] * (fifo[(i + 0) % 13] + fifo[(i + 12) % 13]); 

since embedded arm cpu, wondering more efficient. since assume cpu has move @ least 1 32-bit value internally modulo operation, moving whole array fast calculating right indexes?

i've done on cortex m0 (lpc11c14) fir filter of size 15 (savitzky-golay measuring line voltage).

i found in case copying slower using circular buffer of size 16 , computing indices using modulo operator. note 16 power of two, makes division cheap.

i tried several variants , used port pin measuring execution time, recommend same.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -