Linear Assembly Considerations
8-45
’C64x Programming Considerations
8.3
Linear Assembly Considerations
The ’C64x supports linear assembly programming via the C6000 Assembly
Optimizer. The operation of the Assembly Optimizer is described in detail in
the Optimizing C/C++ Compiler User’s Guide. This section covers ’C64x spe-
cific aspects of linear assembly programming.
8.3.1
Using BDEC and BPOS in Linear Assembly
The ’C64x provides two new instructions, BDEC and BPOS, which are de-
signed to reduce codesize in loops, as well as to reduce pressure on predica-
tion registers. The BDEC instruction combines a decrement, test, and branch
into a single instruction. BPOS is similar, although it does not decrement the
register. For both, these steps are performed in the following sequence.
-
Test the loop register to see if it is negative. If it is negative, no further action
occurs. The branch is not taken and the loop counter is not updated.
-
If the loop counter was not initially negative, decrement the loop counter
and write the new value back to the register file. (This step does not occur
for BPOS .)
-
If the loop counter was not initially negative, issue the branch. Code will
begin executing at the branch’s destination after the branch’s delay slots.
From linear assembly, the branch appears to occur immediately, since lin-
ear assembly programming hides delay slots from the programmer.
This sequence of events causes BDEC to behave somewhat differently than
a separate decrement and predicated branch. First, the decision to branch oc-
curs
before the decrement. Second, the decision to branch is based on wheth-
er the number is
negative, rather than whether the number is zero. Together,
these effects require the programmer to adjust the loop counter in advance of
a loop.
Consider Example 8–18. In this C code, the loop iterates for
count
iterations,
adding 1 to iters each iteration. After the loop, iters contains the number of
times the loop iterated.