Download "TMS320C6000 Optimizing C Compiler User's Guide"
Transcript
Interfacing C and C++ With Assembly Language
The TMS320C6000 Programmer’s Guide states that one of the ways to refine
C/C++ code is to use word accesses to operate on 16-bit data stored in the
high and low parts of a 32-bit register. Examples using casts to int pointers are
shown with the use of intrinsics to use certain instructions like _mpyh. This can
be automated by using the _nassert( ); intrinsic to specify that 16-bit short arrays are aligned on a 32-bit (word) boundary.
The following two examples generate the same assembly code:
- Example 1
int dot_product(short *x, short *y, short z)
{
int *w_x = (int *)x;
int *w_y = (int *)y;
int sum1 = 0, sum2 = 0, i;
for (i = 0; i < z/2; i++)
{
sum1 += _mpy(w_x[i], w_y[i]);
sum2 += _mpyh(w_x[i], w_y[i]);
}
return (sum1 + sum2);
}
- Example 2
int dot_product(short *x, short *y, short z)
{
int sum = 0, i;
_nassert (((int)(x) & 0x3) == 0);
_nassert (((int)(y) & 0x3) == 0);
#pragma MUST_ITERATE(20, , 4);
for (i = 0; i < z; i++) sum += x[i] * y[i];
return sum;
}
Note: C++ Syntax for _nassert
In C++ code, _nassert is part of the standard namespace. Thus, the correct
syntax is std::_nassert().
8-36
Related documents
TMS320C6000 Optimizing Compiler User's Guide (Rev. L)
TMS320C55x Optimizing C/C++ Compiler User's Guide
TMS320C6000 Optimizing Compiler v 7.4
TMS320C6000 Assembly Language Tools User's Guide
"TMS320C3x/C4x Optimizing C Compiler User's Guide"
Vodafone SS 08 User's Manual
User`s Manual for NEARCOM Diffractive, Unsteady Wave Driver DUNS
TMS320C3X/C4X CODE GENERATION TOOLS GETTING
Goanna Studio User Guide
MSP430 Optimizing C/C++ Compiler User`s Guide
TMS320C55x Optimizing C/C++ Compiler
SR-MK3-PRO User`s manual