If-Then-Else Statements in a Loop
6-91
Optimizing Assembly Code via Linear Assembly
6.8.6
Final Assembly
Example 6–50 shows the final assembly code after software pipelining. The
performance of this loop is 70 cycles (2
32 + 6).
Example 6–50. Assembly Code for If-Then-Else
MVK
.S2
32,B0
; set up loop counter
[B0] ADD
.L2
–1,B0,B0
; decrement counter
[B0] ADD
.L2
–1,B0,B0
; decrement counter
||[B0] B
.S1
LOOP
; for LOOP
||
LDH
.D1
*A4++,A5
; a[i]
SHL
.S1
A6,1,A6
; mask = mask << 1;
||
AND
.S2X
B4,A6,B2
; cond = codeword & mask
[B2] MVK
.S2
1,B2
; !(!(cond))
||[B0] ADD
.L2
–1,B0,B0
; decrement counter
||[B0] B
.S1
LOOP
;* for LOOP
||
LDH
.D1
*A4++,A5
;* a[i]
CMPEQ
.L2
B6,B2,B1
; (theta == !(!(cond)))
||
SHL
.S1
A6,1,A6
;* mask = mask << 1;
||
AND
.S2X
B4,A6,B2
;* cond = codeword & mask
||
ZERO
.L1
A7
; zero out accumulator
LOOP:
[B0] ADD
.L2
–1,B0,B0
; decrement counter
||[B2] MVK
.S2
1,B2
;* !(!(cond))
||[B0] B
.S1
LOOP
;** for LOOP
||
LDH
.D1
*A4++,A5
;** a[i]
[B1] ADD
.L1
A7,A5,A7
; sum += a[i]
||[!B1]SUB
.D1
A7,A5,A7
; sum –= a[i]
||
CMPEQ
.L2
B6,B2,B1
;* (theta == !(!(cond)))
||
SHL
.S1
A6,1,A6
;** mask = mask << 1;
||
AND
.S2X
B4,A6,B2
;** cond = codeword & mask
; Branch occurs here