I'm currently writing some of my first assembly code for a new project, I am applying a small non-recursive filter algorithm to some saw tooth wave data held in memory, in order to blunt the edges.
Using thumb2 instruction set on a cortex m3.
The algorithm being used is:
y[0] = x[-2]/8 + x[-1]/8 + x[0]/4 + x[1]/8 + x[2]/8
I have spent a long time looking at my code but cannot seem to optimize it any further. The Assembly code I have written is in a loop for the length of data and I have applied the algorithm as so:
LDMIA r0,{r5-r9} ; get the next 5 data values to be filtered
ADD r5,r5,r9 ; sum x[-2] with x[2]
ADD r6,r6,r8 ; sum x[-1] with x[1]
ADD r9,r5,r6 ; sum x[-2]+x[2] with x[-1]+x[1]
ADD r7,r7,r9,LSR #1 ; sum x[0] with (x[-2]+x[2]+x[-1]+x[1])/2
MOV r7,r7,LSR #2 ; form (x[0] + (x[-2]+x[-1]+x[1]+x[2])/2)/4
STR r7,[r3],#4 ; save calculated filtered value
ADD r0,r0,#4 ; move pointer address forward
SUBS r4,r4,#1 ; decrement loop counter
Can any one see anywhere I could have better optimized this?