Using Word Access for Short Data and Doubleword Access for Floating-Point Data
Example 6–14. Floating-Point Dot Product C Code (Unrolled)
6.4.2
Translating C Code to Linear Assembly
6.4.2.1 Fixed-Point Dot Product
Example 6–15. Linear Assembly for Fixed-Point Dot Product Inner Loop with LDW
LDW
LDW
MPY
MPYH
ADD
ADD
[cntr] SUB
[cntr] B
6-20
float dotp(float a[], float b[])
{
int i;
float sum0, sum1, sum;
sum0 = 0;
sum1 = 0;
for(i=0; i<100; i+=2){
sum0 += a[i] * b[i];
sum1 += a[i + 1] * b[i + 1];
}
sum = sum0 + sum1;
return(sum);
}
The first step in optimizing your code is to translate the C code to linear assem-
bly.
Example 6–15 shows the list of 'C6000 instructions that execute the unrolled
fixed-point dot product loop. Symbolic variable names are used instead of ac-
tual registers. Using symbolic names for data and pointers makes code easier
to write and allows the optimizer to allocate registers. However, you must use
the .reg assembly optimizer directive. See the TMS320C6000 Optimizing
C/C++ Compiler User's Guide for more information on writing linear assembly
code.
*a++,ai_i1
; load ai & a1 from memory
*b++,bi_i1
; load bi & b1 from memory
ai_i1,bi_i1,pi ; ai * bi
ai_i1,bi_i1,pi1 ; ai+1 * bi+1
pi,sum0,sum0
; sum0 += (ai * bi)
pi1,sum1,sum1
; sum1 += (ai+1 * bi+1)
cntr,1,cntr
; decrement loop counter
LOOP
; branch to loop
The two load word (LDW) instructions load a[i], a[i+1], b[i], and b[i+1] on each
iteration.
Need help?
Do you have a question about the TMS320C6000 and is the answer not in the manual?
Questions and answers