If-Then-Else Statements in a Loop
6-90
6.8.5
Linear Assembly Resource Allocation
Now that the graph is split and you know the minimum iteration interval, you
can allocate functional units and registers to the instructions. You must ensure
that no resource is used more than twice.
Example 6–49 shows the linear assembly with the functional units and regis-
ters that are used in the inner loop.
Example 6–49. Linear Assembly for Full If-Then-Else Code
.global _if_then
_if_then: .cproc
a, cword, mask, theta
.reg
cond, if, ai, sum, cntr
MVK
32,cntr
; cntr = 32
ZERO
sum
; sum = 0
LOOP:
.trip 32
AND
.S2X
cword,mask,cond ; cond = codeword & mask
[cond]
MVK
.S2
1,cond
; !(!(cond))
CMPEQ
.L2
theta,cond,if
; (theta == !(!(cond)))
LDH
.D1
*a++,ai
; a[i]
[if]
ADD
.L1
sum,ai,sum
; sum += a[i]
[!if]
SUB
.D1
sum,ai,sum
; sum –= a[i]
SHL
.S1
mask,1,mask
; mask = mask << 1;
[cntr]
ADD
.L2
–1,cntr,cntr
; decrement counter
[cntr]
B
.S1
LOOP
; for LOOP
.return
sum
.endproc