Memory Banks
6-120
6.12.1 FIR Filter Inner Loop
Example 6–65 shows the inner loop from the final assembly in Example 6–64.
The LDHs from the h array are in parallel with LDHs from the x array. If x[1] is
on an even halfword (bank 0) and h[0] is on an odd halfword (bank 1),
Example 6–65 has no memory conflicts. However, if both x[1] and h[0] are on
an even halfword in memory (bank 0) and they are in the same memory block,
every cycle incurs a memory pipeline stall and the loop runs at half the speed.
Example 6–65. Final Assembly Code for Inner Loop of FIR Filter
LOOP:
ADD
.L2X
A8,B9,B9
; sum1 += x1 * h0
||
ADD
.L1
A7,A9,A9
; sum0 += x0 * h0
||
MPY
.M2
B1,B0,B7
;* x1 * h1
||
MPY
.M1X
B1,A1,A8
;* x1 * h0
||[B2]
B
.S2
LOOP
;** branch to inner loop
||
LDH
.D1
*A5++[2],A1
;**** h0 = h[i]
||
LDH
.D2
*B5++[2],B1
;**** x1 = x[j+i+1]
ADD
.L1X
B7,A9,A9
; sum0 += x1 * h1
||
ADD
.L2
B8,B9,B9
; sum1 += x0 * h1
||
MPY
.M2X
A0,B0,B8
;* x0 * h1
||
MPY
.M1
A0,A1,A7
;** x0 * h0
||[B2]
SUB
.S2
B2,1,B2
;*** decrement inner loop cntr
||
LDH
.D2
*B4++[2],B0
;**** h1 = h[i+1]
||
LDH
.D1
*A4++[2],A0
;**** x0 = x[j+i+2]
It is not always possible to fully control how arrays are aligned, especially if one
of the arrays is passed into a function as a pointer and that pointer has different
alignments each time the function is called. One solution to this problem is to
write an FIR filter that avoids memory hits, regardless of the x and h array align-
ments.
If accesses to the even and odd elements of an array (h or x) are scheduled
on the same cycle, the accesses are always on adjacent memory banks. Thus,
to write an FIR filter that never has memory hits, even and odd elements of the
same array must be scheduled on the same loop cycle.