Writing C/C++ Code
3-2
3.1
Writing C/C++ Code
This chapter shows you how to analyze and tailor your code to be sure you are
getting the best performance from the ’C6000 architecture.
3.1.1
Tips on Data Types
Give careful consideration to the data type size when writing your code. The
’C6000 compiler defines a size for each data type (signed and unsigned):
-
char
8 bits
-
short
16 bits
-
int
32 bits
-
long
40 bits
-
float
32 bits
-
double
64 bits
Based on the size of each data type, follow these guidelines when writing C
code:
-
Avoid code that assumes that int and long types are the same size, be-
cause the ’C6000 compiler uses long values for 40-bit operations. This
can cause extra instructions to be generated and limit functional unit
selection.
-
Use the short data type for fixed-point multiplication inputs whenever pos-
sible because this data type provides the most efficient use of the 16-bit
multiplier in the ’C6000 (1 cycle for “short * short” versus 5 cycles for “int
* int”).
-
Use int or unsigned int types for loop counters, rather than short or un-
signed short data types, to avoid unnecessary sign-extension instructions.
-
When using floating-point instructions on a floating-point device such as
the ’C6700, use the –mv6700 compiler switch so the code generated will
use the device’s floating-point hardware instead of performing the task
with fixed point hardware. For example, if the –mv6700 option is not used,
the RTS floating-point multiply will be used instead of the MPYSP instruc-
tion.
-
When using the ’C6400 device, use the –mv6400 compiler switch so the
code generated will use the device’s additional hardware and instructions.