Loop Unrolling
Example 6–54. Linear Assembly for Full Unrolled If-Then-Else Code
.global
_unrolled_if_then:
.reg
cword, mask, theta, ifi, ifi1, a, ai, ai1, cntr
.reg
cdi, cdi1, sumi, sumi1, sum
MV
A4,a
MV
B4,cword
MV
A6,mask
MV
B6,theta
MVK
16,cntr
ZERO
sumi
ZERO
sumi1
LOOP:
.trip 32
AND
.L1X cword,mask,cdi ; cdi = codeword & maski
[cdi]
MVK
.S1 1,cdi
CMPEQ .L1X theta,cdi,ifi
LDH
.D1 *a++,ai
[ifi]
ADD
.L1 sumi,ai,sumi
[!ifi]
SUB
.D1 sumi,ai,sumi
SHL
.S1 mask,1,mask
AND
.L2X cword,mask,cdi1 ; cdi+1 = codeword & maski+1
[cdi1]
MVK
.S2 1,cdi1
CMPEQ .L2 theta,cdi1,ifi1 ; (theta == !(!(cdi+1)))
LDH
.D1 *a++,ai1
[ifi1]
ADD
.L2 sumi1,ai1,sumi1 ; sum += a[i+1]
[!ifi1]
SUB
.D2 sumi1,ai1,sumi1 ; sum –= a[i+1]
SHL
.S1 mask,1,mask
[cntr]
ADD
.D2 –1,cntr,cntr
[cntr]
B
.S2 LOOP
ADD
sumi,sumi1,sum
.return sum
.endproc
6-98
_unrolled_if_then
.cproc
a, cword, mask, theta
; C callable register for 1st operand
; C callable register for 2nd operand
; C callable register for 3rd operand
; C callable register for 4th operand
; cntr = 32/2
; sumi = 0
; sumi+1 = 0
; !(!(cdi))
; (theta == !(!(cdi)))
; a[i]
; sum += a[i]
; sum –= a[i]
; maski+1 = maski << 1;
; !(!(cdi+1))
; a[i+1]
; maski = maski+1 << 1;
; decrement counter
; for LOOP
; Add sumi and sumi+1 for ret value
Need help?
Do you have a question about the TMS320C6000 and is the answer not in the manual?
Questions and answers