Loop Unrolling
6-95
Optimizing Assembly Code via Linear Assembly
6.9.2
Translating C Code to Linear Assembly
Example 6–53 shows the unrolled inner loop with 16 instructions and the
possibility of achieving a loop with a minimum iteration interval of 3.
Example 6–53. Linear Assembly for Unrolled If-Then-Else Inner Loop
AND
codeword,maski,condi
; condi = codeword & maski
[condi] MVK
1,condi
; !(!(condi))
CMPEQ
theta,condi,ifi
; (theta == !(!(condi)))
LDH
*aptr++,ai
; a[i]
[ifi]
ADD
sumi,ai,sumi
; sum += a[i]
[!ifi] SUB
sumi,ai,sumi
; sum –= a[i]
SHL
maski,1,maski+1
; maski+1 = maski << 1;
AND
codeword,maski+1,condi+1 ; condi+1 = codeword & maski+1
[condi+1]MVK
1,condi+1
; !(!(condi+1))
CMPEQ
theta,condi+1,ifi+1
; (theta == !(!(condi+1)))
LDH
*aptr++,ai+1
; a[i+!]
[ifi+1] ADD
sumi+1,ai+1,sumi+1
; sum += a[i+1]
[!ifi+1] SUB
sumi+1,ai+1,sumi+1
; sum –= a[i+1]
SHL
maski+1,1,maski
; maski = maski+1 << 1;
[cntr]
ADD
–1,cntr,cntr
; decrement counter
[cntr]
B
LOOP
; for LOOP