Home

TMS320C6000 Optimizing Compiler User's Guide (Rev. L)

image

Contents

1. Contents 3 6 Performing Program Level Optimization pm and 03 Options 3 6 1 Controlling Program Level Optimization opn Option 3 6 2 Optimization Considerations When Mixing C C and Assembly 3 7 Indicating Whether Certain Aliasing Techniques Are Used 22000055 3 7 1 Use the ma Option When Certain Aliases are Used 3 7 2 Use the mt Option to Indicate That These Techniques Are Not Used 3 7 3 Using the mt Option With the Assembly Optimizer 3 8 Prevent Reordering of Associative Floating Point Operations 3 9 Use Caution With asm Statements in Optimized Code 02222 00 eee 3 10 Automatic Inline Expansion oi Option 0 0 6 eee eee 3 11 Using the Interlist Feature With Optimization 0 cece eee eee ee 3 12 Debugging and Profiling Optimized Code 0 eens 3 12 1 Debugging Optimized Code symdebug dwarf symdebug coff and O Options schohsctedetaorsdbeaneee etek Oh aai ye Meee ies ed 3 12 2 Profiling Optimized Code 0 ccna 3 13 What Kind of Optimization Is Being Performed 00c cece eee eee 3 13 1 Cost Based Register Allocation 0 0 cece cece eens 3 13 2 Alias Disambiguation 00 ccc eee 3 13 3 Branch Optimizations and Control Flow Simplification 3 13 4 Data Flow
2. 055 3 11 Using the Interlist Feature With Optimization 3 12 Debugging and Profiling Optimized Code 5 3 13 What Kind of Optimization Is Being Performed 3 1 Invoking Optimization 3 1 Invoking Optimization The C C compiler is able to perform various optimizations High level optimizations are performed in the optimizer and low level target specific optimizations occur in the code generator High level optimizations must be used to achieve optimal code Figure 3 1 illustrates the execution flow of the compiler with the optimizer and code generator Figure 3 1 Compiling a C C Program With Optimization 3 2 C C Parser Optimizer Code source file gt P gt generator The easiest way to invoke optimization is to use the cl6x compiler program specifying the On option on the cl6x command line The n denotes the level of optimization 0 1 2 and 3 which controls the type and degree of optimization g 00 Performs control flow graph simplification Allocates variables to registers Performs loop rotation Eliminates unused code Simplifies expressions and statements Expands calls to functions declared inline Lj 01 Performs all O0 optimizations plus m Performs local copy constant propagation mM Removes unused assignments E Eliminates local common expressions Invoking Optimization Lj 02 Performs all 01
3. Interfacing C and C With Assembly Language The most straightforward way to align an array in a structure or class is to declare right before the array a scalar that requires the desired alignment So if you want 8 byte alignment use a long or double If you want 4 byte alignment use an int or float For example struct s long not_used 8 byte aligned short buffer 50 also 8 byte aligned J If you want to declare several arrays contiguously and maintain a given alignment you can do so by keeping the array size measured in bytes an even multiple of the desired alignment For example struct s long not_used 8 byte aligned short buf1 50 also 8 byte aligned short buf2 50 4 byte aligned hi Because the size of buf1 is 50 2 bytes per short 100 bytes and 100 is an even multiple of 4 not 8 buf2 is only aligned on a 4 byte boundary Padding buf1 out to 52 elements makes buf2 8 byte aligned Within a structure or class there is no way to enforce an array alignment greater than 8 For the purposes of SIMD optimization this is not necessary Note Alignment With Program Level Optimization In most cases program level optimization see section 3 6 on page 3 20 entails compiling all of your source files with a single invocation of the compiler while using the pm 03 options This allows the compiler to see all of your source code at once thus enabling optimizations t
4. 000s 7 10 2 Enabling Strict ISO Mode and Relaxed ISO Mode ps and pr OPtionS e sccccntadniew aaa vee eae eae ee aed 7 10 3 Enabling Embedded C Mode pe Option 2 0e eee Run Time Environment 0 0 cece eee eee eee eee eee eee eee eee eeeaeeee Discusses memory and register conventions stack organization function call conventions and system initialization Provides information needed for interfacing assembly language to C programs 8 1 Memory Model 0 205 cesta devine eee eee ree eked eee dvd dveekeree denen dds 8 1 1 SECIONS ea samin ieee hacia a EE Ale ean Mihaly ean EEAS 8 1 2 C C System Stack 0 cece eee teens 8 1 3 Dynamic Memory Allocation 0 cece eects 8 1 4 Initialization of Variables nananana cee tenets 8 1 5 Memory Models 000 cece eee eee 8 1 6 Position Independent Data 00 c cece eee 8 2 Object Representation 0 0 ccc cece e eens 8 2 1 Data Type Storage 0 cee ene 8 2 2 BIL ICIS sie ea acids ener ate teats ee tea eke eee eae ee Rea 8 2 3 Character String Constants 0 00 e eee eee eens 8 3 Register Conventions 0 0 0 c cece t ee eee eens 8 4 Function Structure and Calling Conventions 00 000 e eee eee ees 8 4 1 How a Function Makes a Call 0 00 ccc cece eee eed 8 4 2 How a Called Function Responds 22 eseeee eee eee need 8 4 3 Accessing Arguments and
5. _j Aremark is less serious than a warning It indicates something that is valid and probably intended but may need to be checked Compilation continues and object code is generated if no errors are detected By default remarks are not issued Use the pdr compiler option to enable remarks Diagnostics are written to standard error with a form like the following example test c line 5 error a break statement may only be used within a loop or switch break By default the source line is omitted Use the pdv compiler option to enable the display of the source line and the error position The above example makes use of this option The message identifies the file and line involved in the diagnostic and the source line itself with the position indicated by the character follows the message If several diagnostics apply to one source line each diagnostic has the form shown the text of the source line is displayed several times with an appropriate position indicated each time Using the C C Compiler 2 31 Understanding Diagnostic Messages 2 32 Long messages are wrapped to additional lines when necessary You can use a command line option pden to request that the diagnostic s numeric identifier be included in the diagnostic message When displayed the diagnostic identifier also indicates whether the diagnostic can have its severity overridden on the command line If the severity can be overridden the dia
6. endproc register registero Use the proc endproc directive pair to delimit a section of your code that you want the assembly optimizer to optimize This section is called a procedure Use proc at the beginning of the section and endproc at the end of the section In this way you can set off sections of your assembly code that you want to be optimized like functions The directives must be used in pairs do not use proc without the corresponding endproc Specify a label with the proc directive You can have multiple procedures in a linear assembly file Use the optional register parameter in the proc directive to indicate which registers are live in and use the optional register parameter of the endproc directive to indicate which registers are live out for each procedure The register can be an actual register or a symbolic name For example PROC x A5 y B7 ENDPROC y A value is live in if it has been defined before the procedure and is used as an input to the procedure A value is live out if it has been defined before or within the procedure and is used as an output from the procedure If you do not specify any registers with the endproc directive it is assumed that no registers are live out Only code within procedures is optimized The assembly optimizer copies any code that is outside of procedures to the output file and does not modify it Here is a block move example in which proc and endproc are us
7. Efficient enough Yes Complete No Yes More C C optimizations No m Write refine linear assembly Phase 3 Write linear Assembly optimize assembly Yes Complete Code Development Flow to Increase Performance There are three phases of code development for the C6000 _ Phase 1 write in C You can develop your C C code for phase 1 without any knowledge of the C6000 Use the stand alone simulator with the g option see section 6 4 Using the Profiling Capability of the Stand Alone Simulator on page 6 8 to identify any inefficient areas in your C C code To improve the performance of your code proceed to phase 2 J Phase 2 refine your C C code In phase 2 use the intrinsics and compiler options that are described in this book to improve your C C code Use the stand alone simulator with the g option to check the performance of your altered code Refer to the TMS320C6000 Programmer s Guide for hints on refining C C code If your code is still not as efficient as you would like it to be proceed to phase 3 I Phase 3 write linear assembly In this phase you extract the time critical areas from your C C code and rewrite the code in linear assembly You can use the assembly optimizer to optimize this code When you are writing your first pass of linear assembly you should not be concerned with the pipeline structure or with assigning registers Later when you are refining your li
8. char strb what char ptr ptr strstr stra strb The pointer ptr now points to the w in what in the first string strtod strtol strtoll strtoul strtoull Syntax for C Syntax for C Defined in Description strtod strtol strtoll strtoul strtoull String to Number include lt stdlib h gt double strtod const char st char endptr long strtol const char st char endptr int base long long strtoll const char st char endptr int base unsigned long strtoul const char st char endptr int base unsigned long long strtoull const char st char endptr int base include lt cstdlib gt double std strtod const char st char endptr long std strtol const char st char endptr int base long long std strtoll const char st char endptr int base unsigned long std strtoul const char st char endptr int base unsigned long long std strtoull const char st char endptr int base strtod c strtol c strtoll c strtoul c and strtoull c in rts src These functions convert ASCII strings to numeric values For each function argument st points to the original string Argument endptr points to a pointer the functions set this pointer to point to the first character after the converted string The functions that convert to integers also have a third argument base which tells the function what base to interpret the string in I The strtod functi
9. 4 4 Assembly Optimizer Directives 0 000 cece teeta Contents xi Contents xii 4 5 Avoiding Memory Bank Conflicts With the Assembly Optimizer 4 5 1 Preventing Memory Bank Conflicts 6000 cece cece eee 4 5 2 A Dot Product Example That Avoids Memory Bank Conflicts 4 5 3 Memory Bank Conflicts for Indexed Pointers 000 cece eee eee 4 5 4 Memory Bank Conflict Algorithm 00 cece eee eee eee 4 6 Memory Alias Disambiguation 0 000 ee eee ees 4 6 1 How the Assembly Optimizer Handles Memory References Default 4 6 2 Using the mt Option to Handle Memory References 4 6 3 Using the no_mdep Directive 0 ec eete eee 4 6 4 Using the mdep Directive to Identify Specific Memory Dependences 4 6 5 Memory Alias Examples 0000 cece ee eee eee eee eee Linking C G 4 COd i000 ces cee caer eee cece eae eee ee eee eee se eed eee Describes how to link in a separate step or as part of the compile step and how to meet the special requirements of linking C code 5 1 Invoking the Linker Through the Compiler Z Option 0000eee eens 5 1 1 Invoking the Linker as a Separate Step 0c cee eee ee eee 5 1 2 Invoking the Linker as Part of the Compile Step 0005 5 1 3 Disabling the Linker c Compiler Option 0000 eee eee aes 52 IWIMKEFOPUOMS sisp yee ets es ima Hade
10. Setting Default Compiler Options C_OPTION and C_C6X_OPTION Contents 2 5 Controlling the Preprocessor 0000 cece eect eet teens 2 5 1 Predefined Macro Names 0 cc cece eet eee eee ees 2 5 2 The Search Path for include Files 0 e eee ee eee eee 2 5 3 Generating a Preprocessed Listing File ppo Option 2 5 4 Continuing Compilation After Preprocessing ppa Option 2 5 5 Generating a Preprocessed Listing File With Comments DDC OPlON sirs Aaien eaa aa De i saat on da a 2 5 6 Generating a Preprocessed Listing File With Line Control Information PplOptliON srito irradia epi bine AS eid ae rede peewee E a 2 5 7 Generating Preprocessed Output for a Make Utility ppd Option 2 5 8 Generating a List of Files Included With the include Directive SPP OPUON oisi Sensara ooann oea aa Ea a i a E E a ee ee eeeee ee 2 6 Understanding Diagnostic Messages 0 0 cece eee 2 6 1 Controlling Diagnostics 00sec teens 2 6 2 How You Can Use Diagnostic Suppression Options 2 7 Other Messages 0 0 0 cc eee a E G 2 8 Generating Cross Reference Listing Information px Option 2 9 Generating a Raw Listing File pl Option 00 c cece eee 2 10 Using Inline Function Expansion 0 000 c cece nett 2 10 1 Inlining Intrinsic Operators 0 ees 2 10 2 Automatic INNIN se sires cee vaceds Sopa
11. Square brackets and identify an optional parameter If you use an optional parameter you specify the information within the brackets you do not enter the brackets themselves This is an example of a command that has an optional parameter load6x options filename out The load6x command has two parameters The first parameter options is optional The second parameter filename out is required Braces and indicate that you must choose one of the parameters within the braces you do not enter the braces themselves This is an example of a command with braces that are not included in the actual syntax but indicate that you must specify either the c or cr option cl6x z c cr filenames o name ouft l libraryname Notational Conventions Related Documentation From Texas Instruments LJ The TMS320C6200 core is referred to as C6200 The TMS320C6400 core is referred to as 6400 The TMS320C6700 core is referred to as 6700 TMS320C6000 and C6000 can refer to either C6200 6400 or C6700 Related Documentation From Texas Instruments The following books describe the TMS320C6000 and related support tools To obtain any of these TI documents call the Texas Instruments Literature Response Center at 800 477 8924 When ordering identify the book by its title and literature number located on the title page TMS320C6000 Assembly Language Tools User s Guide literature number SPRU186 d
12. _j The offset indicates the relative offset from the origin in characters O The origin is used to indicate which of the base locations the offset is measured from The origin must be a value returned by one of the following macros SEEK_SET 0x0000 Beginning of file SEEK_CUR 0x0001 Current value of the file position indicator SEEK_END 0x0002 End of file The return function is one of the following new value of the file position indicator if successful EOF if fails Syntax for C Syntax for C Description Return Value open Open File or Device For I O include lt stdio h gt include lt file h gt int open const char path unsigned flags int file_descriptor include lt cstdio gt include lt file h gt int std open const char path unsigned flags int file_descriptor The open function opens the device or file specified by path and prepares it for I O _ The path is the filename of the file to be opened including path information _j The flags are attributes that specify how the device or file is manipulated The flags are specified using the following symbols O RDONLY 0x0000 open for reading O WRONLY 0x0001 open for writing O_RDWR 0x0002 open for read amp write O APPEND 0x0008 append on each write O CREAT 0x0200 open with file create O TRUNC 0x0400 open with truncation O BINARY 0x8000 open in binar
13. allocation A process in which the linker calculates the final memory addresses of output sections American National Standards Institute ANSI An organization that esta blishes standards voluntarily followed by industries archive library A collection of individual files grouped into a single file by the archiver archiver A software program that collects several individual files into a single file called an archive library With the archiver you can add delete extract or replace members of the archive library assembler A software program that creates a machine language program from a source file that contains assembly language instructions direc tives and macro definitions The assembler substitutes absolute opera tion codes for symbolic operation codes and absolute or relocatable addresses for symbolic addresses assembly optimizer A software program that optimizes linear assembly code which is assembly code that has not been register allocated or scheduled The assembly optimizer is automatically invoked with the compiler program cl6x when one of the input files has a sa extension assignment statement A statement that initializes a variable with a value A 1 Glossary A 2 autoinitialization The process of initializing global C variables contained in the cinit section before program execution begins autoinitialization at run time An autoinitialization method used by the linker when linking C code
14. Note No Previously Allocated Objects Are Available After minit Calling the minit function makes all the memory space in the heap available again Any objects that you allocated previously will be lost do not try to access them Syntax for C Syntax for C Defined in Description Example mktime Convert to Calendar Time include lt time h gt time_t mktime register struct tm tptr include lt ctime gt time_t std mktime register struct tm tptr mktime c in rts src The mktime function converts a broken down time expressed as local time into proper calendar time The tptr argument points to a structure that holds the broken down time The function ignores the original values of tm_wday and tm_yday and does not restrict the other values in the structure After successful completion of time conversions tm_wday and tm_yday are set appropriately and the other components in the structure have values within the restricted ranges The final value of tm_mday is not sent until tm_mon and tm_year are determined The return value is encoded as a value of type time_t If the calendar time cannot be represented the function returns the value 1 For more information about the functions and types that the time h ctime header declares and defines see section 9 3 18 Time Functions time h ctime on page 9 27 This example determines the day of the week that July 4 2001 falls on include lt time h gt
15. O O O O O O O O O L Interrupt Flexibility Options mi Option 2 11 Interrupt Flexibility Options mi Option On the C6000 architecture interrupts cannot be taken in the delay slots of a branch In some instances the compiler can generate code that cannot be interrupted for a potentially large number of cycles For a given real time system there may be a hard limit on how long interrupts can be disabled The min option specifies an interrupt threshold value n The threshold value specifies the maximum number of cycles that the compiler can disable interrupts If the n is omitted the compiler assumes that the code is never interrupted In Code Composer Studio to specify that the code is never interrupted select the Interrupt Threshold check box and leave the text box blank in the Build Options dialog box on the Compiler tab Advanced category If the min option is not specified then interrupts are only explicitly disabled around software pipelined loops When using the min option the compiler analyzes the loop structure and loop counter to determine the maximum number of cycles it takes to execute a loop If it can determine that the maximum number of cycles is less than the threshold value the compiler generates the fastest optimal version of the loop If the loop is smaller than 6 cycles interrupts are not able to occur because the loop is always executing inside the delay slots of a branch Otherwise the compiler generates
16. The ISO standard identifies some features of the C language that are affected by characteristics of the target processor run time environment or host environment For reasons of efficiency or practicality this set of features can differ among standard compilers This section describes how these features are implemented for the C6000 C C compiler The following list identifies all such cases and describes the behavior of the C6000 C C compiler in each case Each description also includes a reference to more information Many of the references are to the formal ISO standard or to the second edition of The C Programming Language by Kernighan and Ritchie K amp R Identifiers and Constants J All characters of all identifiers are significant Case is significant uppercase and lowercase characters are distinct for identifiers These characteristics apply to all identifiers internal and external ISO 3 1 2 K amp R A2 3 I The source host and execution target character sets are assumed to be ASCII There are no multibyte characters ISO 2 2 1 K amp R A12 1 J Hex or octal escape sequences in character or string constants may have values up to 32 bits ISO 3 1 3 4 K amp R A2 5 2 Character constants with multiple characters are encoded as the last character in the sequence For example abe c ISO 3 1 3 4 K amp R A2 5 2 7 1 2 Data Types 7 1 3 Conversions 7 1 4 Expressions Lj Characteristics
17. The register usage for the schedule found at the given ii is displayed This information can be used when writing linear assembly to balance register pressure on both sides of the register file For example ii 11 Cannot allocate machine registers Regs Live Always 3 0 A B side Max Regs Live 20 14 Max Condo Regs Live 2 1 m Regs Live Always The number of values that must be assigned a register for the duration of the whole loop body This means that these values must always be allocated registers for any given schedule found for the loop m Max Regs Live Maximum number of values live at any given cycle in the loop that must be allocated to a register This indicates the maximum number of registers required by the schedule found m Max Cond Regs Live Maximum number of registers live at any given cycle in the loop kernel that must be allocated to a condition register Lj Cycle count too high Not profitable With the schedule that the compiler found for the loop it is more efficient to use a non software pipelined version J Did not find schedule The compiler was unable to find a schedule for the software pipeline at the given ii iteration interval You should simplify the loop and or eliminate loop carried dependencies J Iterations in parallel gt minimum or maximum trip count A software pipeline schedule was found but the schedule has more iterations in parallel than the minimum or maximum loop trip count You m
18. fraction Breaks value into a signed integer and a signed fraction Returns xY Returns xY Returns xi t Returns xi t Returns x rounded to the nearest integer t Returns x rounded to the nearest integer t Returns the reciprocal square root of x t Returns the reciprocal square root of x t Returns the sine of x Returns the sine of x Returns the hyperbolic sine of x Returns the hyperbolic sine of x Returns the nonnegative square root of x Returns the nonnegative square root of x Returns the tangent of x Returns the tangent of x Returns the hyperbolic tangent of x Returns the hyperbolic tangent of x Returns x truncated toward 0 t Returns x truncated toward 0 t T Enhanced math function See section 9 3 10 on page 9 22 for information on accessing this function Run Time Support Functions P F Lre ee 0 10 j Gl 12 N IN QO 19S SNe En i AR ojlo a 9 33 Summary of Run Time Support Functions and Macros d Nonlocal jumps macro and function setimp h csetjmp Function or Macro int setimp jmp_buf env void longjmp jmp_buf env int _ val e Variable argument macros stdarg h cstdarg Macro type va_arg va_list type Description Page Saves calling environment for use by longjmp this is a macro Uses jmp_buf argument to restore a previously saved environment Description Page Accesses the next argument of type type in a 9 109 void va_end va_list void
19. is prefixed to the identifier name C functions are prefixed with an underscore also but the function name is modified further Mangling is the process of embedding a function s signature the number and types of its parameters into its name Mangling occurs only in C code The mangling algorithm used closely follows that described in The Annotated Reference Manual ARM Mangling allows function overloading operator overloading and type safe linking For example the general form of a C linkname for a function named func is _func__Fparmcodes Where parmcodes is a sequence of letters that encodes the parameter types of func For this simple C source file int foo int i global C function This is the resulting assembly code foo_ Fi The linkname of foo is _foo__ Fi indicating that foo is a function that takes a single argument of type int To aid inspection and debugging a name demangling utility is provided that demangles names into those found in the original C source See Chapter 11 C Name Demangling for more information TMS320C6000 C C Language Implementation 7 33 Initializing Static and Global Variables 7 9 7 9 1 7 34 Initializing Static and Global Variables The ISO C standard specifies that global extern and static variables without explicit initializations must be initialized to 0 before the program begins running This task is typically done when the program is loaded Becau
20. long long std Ilabs long long i abs c in rts src The C C compiler supports three functions that return the absolute value of an integer H The abs function returns the absolute value of an integer i _ The labs function returns the absolute value of a long i J The llabs function returns the absolute value of a long long i Run Time Support Functions 9 41 acos acosf acos acosf Syntax for C Syntax for C Defined in Description Example acosh acoshf Syntax for C Syntax for C Defined in Description 9 42 Arc Cosine include lt math h gt double acos double x float acosf float x include lt cmath gt double std acos double x float std acosf float x acos c and acosf c in rts src The acos and acosf functions return the arc cosine of a floating point argument x which must be in the range 1 1 The return value is an angle in the range 0 70 radians double 3Pi_ Over 2 3Pi Over 2 acos 1 0 Pi acos 0 0 Pi 2 acos 1 0 0 0 Hyperbolic Arc Cosine define _TlENHANCED_MATH_H 1 include lt math h gt double acosh double x float acoshf float x define _Tl ENHANCED_MATH_H 1 include lt cmath gt double std acosh double x float std acoshf float x acosh c and acoshf c in rts src The acosh and acoshf functions return the hyperbolic arc cosine of a floating point argument x which must be in the range 1 infinity The
21. prod3 prod4 tmp1 a 2 b 2 tmp1 suml suml a 3 b 3 PPeasae rH Ounuy T G w ent 4 ent cnt 4 loop if cnt 0 goto loop DD sum0 sumi sum compute final result return sum endproc Example 4 2 is refined C code for computing a dot product Using the Assembly Optimizer 4 9 What You Need to Know to Write Linear Assembly Example 4 2 C Code for Computing a Dot Product int dotp short a shortb int sumo int sumi int sum for i 0 i lt 100 4 i 4 ali Bil ali 1 b i 1 a i 2 b i 2 a i 3 b i 3 return The old method of partitioning registers indirectly by partitioning instructions can still be used Side and functional unit specifiers can still be used on instructions However functional unit specifiers L S D M are ignored Side specifiers are translated into partitioning constraints on the corresponding symbolic names if any For example MV 1 x y translated to REGA y LDW D2T2 u v w translated to REGB u v w 4 3 3 Functional Unit Specification for Linear Assembly 4 10 Specifying functional units has been deprecated by the ability to partition registers directly See section 4 3 2 on page 4 8 for details While you can use the unit specifier field in linear assembly only the register side information is used by the compiler You specify a functional unit by following the assembler i
22. source code that calls as sembly functions The assembly language functions do not call C C functions but they modify C C variables Try both of these solutions and choose the one that works best with your code E Compile with pm O3 op1 E Add the volatile keyword to those variables that may be modified by the assembly functions and compile with pm O3 op2 See section 3 6 1 on page B 21 for information about the opn option Optimizing Your Code 3 23 Performing Program Level Optimization pm and O3 Options 3 24 Situation Solution Your application consists of C C source code and assem bly source code The assembly functions are interrupt service routines that call C C functions the C C functions that the assembly functions call are never called from C C These C C functions act like main they function as entry points into C C Add the volatile keyword to the C C variables that may be modified by the interrupts Then you can optimize your code in one of these ways m You achieve the best optimization by applying the FUNC_EXT_CALLED pragma to all of the entry point functions called from the assembly language interrupts and then compiling with pm O3 op2 Be sure that you use the pragma with all of the entry point functions f you do not the compiler might remove the entry point func tions that are not preceded by the FUNC_EXT_CALL pragma mH Compile with pm O3 op
23. through call assembly optimizer direc tive 4 1514 17 using the stack general utility 9 26 37 inline expansion 2 38 2 42 42 inlining defined prototype effects of pk option responsibilities of called function responsibilities of calling function structure 8 19 subsections L5 13 5 15 fwrite function g compiler option g linker option g stand alone simulator option general purpose registers 32 bit data 8 9 8 10 40 bit data 64 bit data double precision floating point data halfword general utility functions minit generating linknames list of include files symbolic debugging directives get file position function getc function getchar function getenv function gets function global constructors and destructors global symbol defined Index global variables accessing assembler variables from C C 8 44 autoinitialization initializing reserved space gmtime function Greenwich mean time function Gregorian time gsm h header h C name demangler option h library build utility option 10 4 h linker option h stand alone simulator option header files assert h header cassert header cctype header cerrno header cfloat header ciso646 climits header cmath header csetjmp header cstdarg header cstdio header cstdlib header cstring header ctime header ctype h header errno h header file h header float h header 9 19 9
24. 10 4 tokens va_arg macro tolower function va_end macro 9 23 9 109 toupper function va_list data type trampolines linker option va_start macro trigonometric math function variable argument macros trigraph sequence defined described trip assembly optimizer directive summary of trip count variable argument macros usage defined variables corre Bel accessing assembler variables from C C 8 44 trunc function accessing local variables truncate functions 9 108 autoinitialization truncf function 9 108 compiling register variables defined type_info structure initializing typeinfo header 9 28 global static U vfprintf function 9 110 volatile assembly optimizer directive u C name demangler option volatile keyword u compiler option vprintf function 9 110 u library build utility option vsprintf function 9 111 u linker option uint_fastN_t unsigned integer type uint_leastN_t unsigned integer type uintmax_t unsigned integer type w linker option UINTN_C macro warning messages uintN_t unsigned integer type wildcards use uintprt_t unsigned integer type write block of data function Index 20 write functions Index write I O function x linker option xml_link_info linker option z compiler option 2 4 2 17 overriding with c compiler option z stand alone simulator option Index 21
25. 8 8 5 Initialization of Variables at Load Time ccc cece nee eee Run Time Support Functions 0 0 e cece eee eee Describes the libraries and header files included with the C C compiler as well as the macros functions and types that they declare Summarizes the run time support functions according to category header Provides an alphabetical reference of the non ISO run time support functions 9 1 9 2 9 3 9 4 9 5 LIDFANGS reece aths PEE EELE E Par nee tee E E EE EE nee 9 1 1 Linking Code With the Object Library 000 eee eee eee 9 1 2 Modifying a Library Function 0 00 e eee eee eee 9 1 3 Building a Library With Different Options 000 cece eens The C VO Functions assaia aa min anaa aa E a see eambee geese se eneeeeees 9 2 1 Overview of Low Level I O Implementation 000 cece ee 9 2 2 Adding a Device for C VO i cee eens Header Files 4 iiccieiies innere tesieni ane Eade dee ee bed een 9 3 1 Diagnostic Messages assert h cassert 00 ccc ee eee eee 9 3 2 Character Typing and Conversion ctype h cctype 2 25 9 3 3 Error Reporting errno h cerrnO 1 2 22 eee eee 9 3 4 Low Level Input Output Functions file h 0 000s 9 3 5 Fast Macros Static Inline Functions gsm h 000 cece eee eee 9 3 6 Limits float h cfloat and limits h climits 0000s 9 3 7 Format Conversion of Integer Types inttypes
26. C6000 internal data memory bank boundary The constant specifies a specific memory bank to start your variables on See Figure 4 1 on page 4 33 for a graphic representation of memory banks The value of constant depends on the C6000 device C6200 The C6200 devices contain four memory banks 0 1 2 and 3 constant can be 0 or 2 C6400 The C6400 devices contain 8 memory banks constant can be 0 2 4 or 6 C6700 The C6700 devices contain 8 memory banks constant can be 0 2 4 or 6 The syntax of the pragma in C is pragma DATA_MEM_BANK symbol constant The syntax of the pragma in C is pragma DATA_MEM_BANK constant Both global and local variables can be aligned with the DATA_MEM_BANK pragma The DATA_MEM_BANK pragma must reside inside the function that contains the local variable being aligned The symbol can also be used as a parameter in the DATA_SECTION pragma 7 20 Pragma Directives When optimization is enabled the tools may or may not use the stack to store the values of local variables The DATA_MEM_BANK pragma allows you to align data on any data memory bank that can hold data of the symbofs type size This is useful if you need to align data in a particular way to avoid memory bank conflicts in your hand coded assembly code versus padding with zeros and having to account for the padding in your code This pragma increases the amount of space used in data memory by a small a
27. Converts calendar time to local time Returns the difference between two calendar times Converts local time to Greenwich Mean Time Converts time_t value to broken down time Converts broken down time to a time_t value Formats a time into a character string Returns the current calendar time co Jol cn 2 M IRI e o 9 5 1 9 gi oj jor N 9 106 a abs labs Ilabs 9 5 Description of Run Time Support Functions and Macros Syntax for C Syntax for C Defined in Description Example abs labs llabs Syntax for C Syntax for C Defined in Description This section describes the run time support functions and macros For each function or macro the syntax is given in both C and C Because the functions and macros originated from C header files however program examples are shown in C code only The same program in C code would differ in that the types and functions declared in the header file are introduced into the std namespace Abort include lt stdlib h gt void abort void include lt cstdlib gt void std abort void exit c in rts src The abort function terminates the program void abort void exit EXIT_FAILURE See the exit function on pagel 9 57 Absolute Value include lt stdlib h gt int abs int i long labs long i long long Ilabs long long i include lt cstdlib gt int std abs int i long std labs long i
28. For example if the trip count could be 5 or greater you can specify the argument list as follows pragma MUST ITERATE 5 However if the trip count could be any nonzero multiple of 5 the pragma would look like this pragma MUST _ITERATE 5 5 Note the blank field for max It is sometimes necessary for you to provide min and multiple in order for the compiler to perform unrolling This is especially the case when the compiler cannot easily determine how many iterations the loop will perform i e the loop has a complex exit condition Pragma Directives When specifying a multiple via the MUST_ITERATE pragma results of the program are undefined if the trip count is not evenly divisible by multiple Also results of the program are undefined if the trip count is less than the minimum or greater than the maximum specified If no min is specified zero is used If no max is specified the largest possible number is used If multiple MUST_ITERATE pragmas are specified for the same loop the smallest max and largest min are used 7 7 14 2 Using MUST_ITERATE to Expand Compiler Knowledge of Loops Through the use of the MUST_ITERATE pragma you can guarantee that a loop executes a certain number of times The example below tells the compiler that the loop is guaranteed to run exactly 10 times pragma MUST _ITERATE 10 10 for i 0 i lt trip count i In this example the compiler attempts to generate a
29. For more information see section 8 3 Register Conventions on page 8 17 and section 8 4 Function Structure and Calling Conventions on page Please see the proc directive on page 4 25 for the types of instructions that cannot appear in a cproc region Use the optional variable to represent function parameters The variable entries are very similar to parameters declared in a C C function The arguments to the cproc directive can be of the following types 1 Machine register names If you specify a machine register name its position in the argument list must correspond to the argument passing conventions for C For example the C C compiler passes the first argument to a function in register A4 This means that the first argument in a cproc directive must be A4 or a symbolic name Up to ten arguments can be used with the cproc directive J Variable names If you specify a variable name then the assembly optimizer ensures that either the variable name is allocated to the appropriate argument passing register or the argument passing register is copied to the register allocated for the variable name For example the first argument in a C C call is passed in register A4 so if you specify the following cproc directive frame cproc argl The assembly optimizer either allocates arg1 to A4 or arg1 is allocated to a different register such as B7 and an MV A4 B7 is automatically generated 4 18 cproc endproc I
30. In C the argument func is the name of a function In C the pragma applies to the next function declared The syntax of the pragma in C is pragma NMI_INTERRUPT func The syntax of the pragma in C is pragma NMI_INTERRUPT The code generated for the function will return via the NRP versus the IRP as for a function declared with the interrupt keyword or INTERRUPT pragma Except for _c_int00 which is the name reserved for the system reset interrupt for C programs the name of the interrupt function does not need to conform to a naming convention 7 7 16 The PROB_ITERATE Pragma 7 30 The PROB_ITERATE pragma specifies to the compiler certain properties of a loop You assert that these properties are true in the common case The PROB_ITERATE pragma aids the compiler in choosing the best loops and loop transformations that is software pipelining and nested loop transformations PROB_ITERATE is useful only when the MUST_ITERATE pragma is not used or the PROB_ITERATE parameters are more constraining than the MUST_ITERATE parameters No statements are allowed between the PROB_ITERATE pragma and the for while or do while loop to which it applies However other pragmas such as UNROLL and MUST_ITERATE may appear between the PROB_ITERATE pragma and the loop The syntax of the pragma for C and C is pragma PROB_ITERATE min max Where min and max are the minimum and maximum trip coun
31. Option ma mb mc me mhn min min mo msn mt mu mvn Effect Assumes aliased variables Compiles C6400 code compatible with array alignment restrictions of version 4 0 tools or C6200 C6700 object code Prevents reordering of associative floating point operations Produces object code in big endian format Allows speculative execution Specifies an interrupt threshold value Changes near and far assumptions on four levels ml0 ml1 ml2 and mI3 Turns on function subsections Controls code size on four levels ms0 ms1 ms2 and ms3 Indicates that specific aliasing techniques are not used Turns off software pipelining Selects target version Library Build Utility 3 28 b EN D o Je gp fa j gt M ER e2 o a N Ni 10 ol Options Summary Table 10 1 Summary of Options and Their Effects Continued c Options that control the parser Option Effect Disables definition controlled inlining but 03 optimizations still perform automatic inlining Makes code K amp R compatible Enables relaxed mode ignores strict ISO violations Enables strict ISO mode for C C not K amp R C d Parser options that control diagnostics Option pdr pdv pdw Effect Issues remarks nonserious warnings Provides verbose diagnostics that display the original source with line wrap Suppresses warning diagnostics errors a
32. The return value is an angle in the range 10 2 1 2 radians double realval radians realval 1 0 radians asin realval asin returns 7 2 Hyperbolic Arc Sine define _TlENHANCED_ MATH_H 1 include lt math h gt double asinh double x float asinhf float x define _Tl ENHANCED MATH_H 1 include lt cmath gt double std asinh double x float std asinhf float x asinh c and asinhf c in rts src The asinh and asinhf functions return the hyperbolic arc sine of a floating point number x A range error occurs if the magnitude of the argument is too large Run Time Support Functions 9 45 assert Syntax for C Syntax for C Defined in Description Example 9 46 Insert Diagnostic Information Macro include lt assert h gt void assert int expr include lt cassert gt void std assert int expr assert h cassert as macro The assert macro tests an expression depending upon the value of the expression assert either issues a message and aborts execution or continues execution This macro is useful for debugging If expr is false the assert macro writes information about the call that failed to the standard output device and aborts execution Lj If expr is true the assert macro does nothing The header file that defines the assert macro refers to another macro NDEBUG If you have defined NDEBUG as a macro name when the assert h header is included in the source file the assert
33. _mem8 a high p gt gt 32 low unsigned int p void alt_store_longlong_unaligned void a int high int low long long p _itoll high low _mems a py 8 5 4 Using MUST_ITERATE and _nassert to Enable SIMD and Expand Compiler Knowledge of Loops Through the use of MUST_ITERATE and _nassert you can guarantee that a loop executes a certain number of times This example tells the compiler that the loop is guaranteed to run exactly 10 times pragma MUST_ITERATE 10 10 for i 0 i lt trip count i MUST_ITERATE can also be used to specify a range for the trip count as well as a factor of the trip count For example pragma MUST _ITERATE 8 48 8 for i 0 i lt trip i This example tells the compiler that the loop executes between 8 and 48 times and that the trip variable is a multiple of 8 8 16 24 32 40 48 The compiler can now use all this information to generate the best loop possible by unrolling better even when the min option is used to specify that interrupts do occur every n cycles 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
34. arrays are aligned on a 32 bit word boundary The following two examples generate the same assembly code Run Time Environment 8 37 Interfacing C and C With Assembly Language J Example 1 int dot_product short x short y short z int w_x int x int w_y int y int sumi 0 sum2 0 i for i 0 i lt 2 2 i suml _mpy w_x i w_ylil l sum2 mpyh w_x i w_yl il return suml sum2 Lj Example 2 int dot_product short x short y short z int sum 0 i _nassert int x amp 0x3 0 _nassert int y amp 0x3 0 pragma MUST_ITERATE 20 4 for i 0 i lt z i sum x i ylil return sum a Note C Syntax for _nassert In C code _nassert is part of the standard namespace Thus the correct syntax is std _nassert 8 5 5 Methods to Align Data 8 38 In the following code the _nassert tells the compiler for every invocation of f that ptr is aligned to an 8 byte boundary Such an assertion often leads to the compiler producing code which operates on multiple data values with a single instruction also known as SIMD single instruction multiple data optimization void f short ptr _nassert int ptr 8 0 a loop operating on data accessed by ptr The following subsections describe methods you can use to ensure the data referenced by ptr is aligned You have to employ one of these metho
35. c cr filenames options o name out l library Ink cma cl6x z C cr filenames options 0 name out library Ink cmd The command that invokes the linker Options that tell the linker to use special conventions defined by the C C environment When you use cl6x z you must use c or cr The c option uses automatic variable initialization at run time the cr option uses variable initialization at load time Names of object files linker command files or archive libraries The default extension for all input files is ob any other extension must be explicitly specified The linker can determine whether the input file is an object or ASCII file that contains linker commands The default output filename is a out unless you use the o option to name the output file Options affect how the linker handles your object files Linker options can only appear after the z option on the command line but may otherwise be in any order Options are discussed in section 5 2 on page ES Names the output file lowercase L Identifies the appropriate archive library containing C C run time support and floating point math functions or linker command files If you are linking C C code you must use a run time support library You can use the libraries included with the compiler or you can create your own run time support library If you have specified a run time support library in a linker command file y
36. continued preprocessor 2 10 2 2952 30_ standalone simulator 6 4 output file options summar module defined overview of files section defined packed data optimization concerns parameters compiling register parameters parser defined summary of options partition registers directly in linear assembly partitioning defined passing arguments through the loader 6 616 7 pdel compiler option pden compiler option pdf compiler option 2 33 pdr compiler option 3 pds compiler option 2 33 pdse compiler option pdsr compiler option 2 33 pdsw compiler option 2 3 pdv compiler option 2 3 pdw compiler option 2 34 pe compiler option perror function pi compiler option pinit section allocating in memory pipelined loop epilog defined described pipelined loop prolog defined described pk compiler option 7 36 7 38 placing run time support off chip pm compiler option pointer combinations pop defined position file indicator function N oo w w B Index position independent data pow function power functions powf function powi function powif function ppa compiler option ppc compiler option 2 30 ppd compiler option ppi compiler option ppl compiler option ppo compiler option pr compiler option pragma defined pragma directive pragma directives 7 18 7 32 CODE_SECTION DATA_ALIGN DATA_MEM_BANK DATA_SECTION FUNC_C
37. include lt cstdio gt void std perror const char _s perror c in rts src The perror function maps the error number in _s to a string and prints the error message pow powf Syntax for C Syntax for C Defined in Description Example powi powif Syntax for C Syntax for C Defined in Description powi powif Raise to a Power include lt math h gt double pow double x double y float powf float x float y include lt cmath gt double std pow double x double y float std powf float x float y pow c and powf c in rts src The pow and powf functions return x raised to the power y These pow functions are equivalent mathematically to exp y x log x but are faster and more accurate A domain error occurs if x 0 and y lt 0 or if x is negative and y is not an integer A range error occurs if the result is too large to represent double x Y Z x Y x r y return value 8 0 Raise to an Integer Power define _TI_ENHANCED_MATH_H 1 include lt math h gt double powi double x int y float powif float x int y define Tl ENHANCED MATH_H 1 include lt cmath gt double std powi double x int y float std powif float x int y powi c and powif c in rts src The powi and powif functions return xi These powi functions are equivalent mathematically to pow x double i but are faster and have similar accuracy A domain error occurs if x 0 andi lt 0 or
38. long long _itoll uint src2 uint src7 t See the TMS320C6000 Programmer s Guide for more information Builds a new long long register pair by reinterpreting two unsigned values where src2 is the high odd register and src1 is the low even register See section 8 5 3 Using Unaligned Data and 64 Bit Values for details on manipulating 8 byte data quantities 8 28 Interfacing C and C With Assembly Language Table 8 3 TMS320C6000 C C Compiler Intrinsics Continued Assembly C C Compiler Intrinsic Instruction Description uint _lo double src Returns the low even register of a double register pair uint _Imbd uint src7 uint src2 LMBD Searches for a leftmost 1 or 0 of src2 determined by the LSB of src1 Returns the number of bits up to the bit change double _Itod long src Reinterprets long register pair src as a double register pair int_mpy int src7 int src2 MPY Multiplies the 16 LSBs of src1 by the 16 LSBs of int_mpyus uint src int src2 MPYUS src2 and returns the result Values can be signed or unsigned int_mpysu int src7 uint src2 MPYSU uint_mpyu uint src7 uint src2 MPYU int_mpyh int src7 int src2 MPYH Multiplies the 16 MSBs of src1 by the 16 MSBs int_mpyhus uint src1 int src2 MPYHUS of src2 and returns the result Values can be signed or unsigned int_mpyhsu int src7 uint src2 MPYHSU uint_mpyhu uint src7 uint src2 MPYHU int_mpyhl int src7 int src2 MPY
39. ptn LDW Allows aligned loads and stores of 4 bytes to STW memoryt const uint amp _amem4_const const LDW Allows aligned loads of 4 bytes from memoryt void ptn double amp _amemd8 void ptn LDW LDW Allows aligned loads and stores of 8 bytes to STW STW memorytt For C64x _amemd corresponds to different assembly instructions than when used with other C6000 devices see Table 8 4 for specifics const double amp _amemd8_const const LDDW Allows aligned loads of 8 bytes from memorytt void ptr uint _clr uint src2 uint csta uint cstb CLR Clears the specified field in src2 The beginning and ending bits of the field to be cleared are specified by csta and cstb respectively uint _clrr uint src2 int src1 CLR Clears the specified field in src2 The beginning and ending bits of the field to be cleared are specified by the lower 10 bits of src1 ulong _dtol double src t See the TMS320C6000 Programmer s Guide for more information Reinterprets double register pair src as an unsigned long register pair See section 8 5 3 Using Unaligned Data and 64 Bit Values for details on manipulating 8 byte data quantities Run Time Environment 8 27 Interfacing C and C With Assembly Language Table 8 3 TMS320C6000 C C Compiler Intrinsics Continued Description Extracts the specified field in src2 sign extended to 32 bits The extract is performed by a shift left followed by a signed shift right csta and cstb are the
40. static const char const wday Sunday Monday Tuesday Wednesday Thursday Friday Saturday struct tm time str time_str tm_year time_str tm_mon time_str tm_mday time_str tm_hour time_str tm_min time_str tm_sec time_str tm_isdst 2001 1900 PROoOOS AKN 1 1 1 1 1 1 mktime amp time_ str After calling this function time_str tm_wday contains the day of the week for July 4 2001 Run Time Support Functions 9 79 modf modff modf modff Syntax for C Syntax for C Defined in Description Example Syntax for C Syntax for C Defined in Description 9 80 Signed Integer and Fraction include lt math h gt double modf double value double ip float modff float value float ip include lt cmath gt double std modf double value double ip float std modff float value float ip modf c and modff c in rts src The modf and modff functions break a value into a signed integer and a signed fraction Each of the two parts has the same sign as the input argument The function returns the fractional part of value and stores the integer as a double at the object pointed to by iptr double value ipart fpart value 10 125 fpart modf value amp ipart After execution ipart contains 10 0 and fpart contains 125 Map Error Number include lt stdio h gt void perror const char _s
41. there are two restrictions associated with the arrays af and bf _ Because LDW is being used the arrays must be be aligned to start on word boundaries H To avoid a memory bank conflict one array must start in bank 0 and the other array in bank 2 If they start in the same bank then a memory bank conflict occurs every cycle and the loop computes a result every two cycles instead of every cycle due to a memory bank stall For example Bank conflict MVK 0 AO MVK 8 BO LDW AO Al LDW BO B1 No bank conflict MVK 0 AO MVK 4 BO LDW AO Al LDW BO B1 Example 4 5 C Code for Dot Product int dotp short al short b int sum0 0 suml 0 sum i for i 0 i lt 100 2 i 2 sum0 a i b i suml a i 1 b i 1 return sum0O sumil Using the Assembly Optimizer 4 37 Avoiding Memory Bank Conflicts With the Assembly Optimizer Example 4 6 Linear Assembly for Dot Product _dotp cproc a b reg sum0 suml i reg vali val2 prodl prod2 MVK 50 i i 100 2 ZERO sum0 multiply result 0 ZERO suml multiply result 0 loop trip 50 LDW a vall load a 0 1 banko LDW b val2 load b 0 1 bank2 MPY vall val2 prod1 a 0 b 0 MPYH vall val2 prod2 a l b 1 ADD prod1l sum0 sumO sum0O a 0 b 0 ADD prod2 suml1 suml suml a l b 1 i ADD 1 i i i i B loop if 1 goto loop ADD sum0 sum
42. 0 0 000 cece eee ees Special Cases With the mi Option 000 tne tena Do Not Lower the Optimization Level to Control Code Size 01 eee eens The On Option Applies to the Assembly Optimizer 0 cece eens Software Pipelining Can Significantly Increase Code Size 6 cece ees More Details on Software Pipelining Information 00sec eee eee Turning Off Redundant Loops 000s cece eee nent EE Disabling Code Size Optimizations or Reducing the Optimization Level The ms Option is Equivalent to mMsO asuun anaana aaneen Do Not Lower the Optimization Level to Control Code Size 02 eee eens Compiling Files With the pm and k Options 00 cc cece teen eee O3 Optimization and Inlining seiss sninen ninni tee ea aaa eee Inlining and Code Size s sa 6 tenet eee e eens Impact on Performance and Code Size 2 cece tenes Symbolic Debugging Options Affect Performance and Code Size 0 cece eee Prolile PONS foe tte 52a echid orenian i a Anata gam EE a E a A auace A E A ae ashe Paden Do Not Use Scheduled Assembly Code as Source 6 cette Reserving Registers A4 and A5 1 ene ttn tne eens Memory Dependency Exception 0 ccc cece eee e eee eea Memory Dependence Bank Conflict 000 cette eee eee Order of Processing Arguments in the Linker 0000 cece cent eet teens The c
43. 0 7 of the register and moving the second byte of memory to bits 8 15 Figure 8 1 Char and Short Data Storage Format MS LS SinedGbt SSSSSSSSSESSSSSSSSSsSsss siiiil ii 31 7 0 MS LS Unsigned 0o 00000000000000000000000 JUUUUUUUU 8 bit char ai s 5 Signed 16 bit short MS LS Unsigned 59 90000000000000 UUUUUUUUUUUUUUUU 16 bit short 31 15 0 Legend S sign MS most significant signed integer LS least significant U unsigned integer Run Time Environment 8 9 Object Representation 8 2 1 2 enum float and int Data Types signed and unsigned The int unsigned int enum and float data types are stored in memory as 32 bit objects see Figure 8 2 Objects of these types are loaded to and stored from bits 0 31 of a register In big endian mode 4 byte objects are loaded to registers by moving the first byte that is the lower address of memory to bits 24 31 of the register moving the second byte of memory to bits 16 23 moving the third byte to bits 8 15 and moving the fourth byte to bits 0 7 In little endian mode 4 byte objects are loaded to registers by moving the first byte that is the lower address of memory to bits 0 7 of the register moving the second byte to bits 8 15 moving the third byte to bits 16 23 and moving the fourth byte to bits 24 31 Figure 8 2 32 Bit Data Storage Format Single MS LS precision S EE EEE EE EIMMMMMMMMMMMMMMMM MM MM MMM floating point 34 23 0 Signed 3
44. 17 Register Conventions Table 8 2 Register Usage Register AO Al A2 A3 A4 A5 AG A7 A8 A9 A10 A11 A12 A13 A14 A15 A16 A31 Function Preserved By Parent Parent Parent Parent Parent Parent Parent Parent Parent Parent Child Child Child Child Child Child Parent Special Uses Structure register pointer to a returned structure Argument 1 or return value Argument 1 or return value with A4 for doubles longs and long longs Argument 3 Argument 3 with A6 for doubles longs and long longs Argument 5 Argument 5 with A8 for doubles longs and long longs Argument 7 Argument 7 with A10 for doubles longs and long longs Argument 9 Argument 9 with A12 for doubles longs and long longs Frame pointer FP C64x only Register BO B1 B2 B3 B4 B5 B6 B7 B8 B9 B10 B11 B12 B13 B14 B15 B16 B31 Function Preserved By Parent Parent Parent Parent Parent Parent Parent Parent Parent Parent Child Child Child Child Child Child Parent Special Uses Return register address to return to Argument 2 Argument 2 with B4 for doubles longs and long longs Argument 4 Argument 4 with B6 for doubles longs and long longs Argument 6 Argument 6 with B8 for doubles longs and long longs Argument 8 Argument 8 with B10 for doubles longs and long longs Argument 10
45. 20 gsm h header iso646 h limits h header 9 19 9 20 linkage h header list of math h header new header setjmp h header stdarg h header stddef h header stdint h stdio h header stdlib h header Index 9 Index header files continued typeinfo header heap align function described reserved space heap linker option with malloc heap size function help compiler option hex conversion utility defined described HUGE_VAL macro hyperbolic math functions described hyperbolic arc cosine functions hyperbolic arc cotangent functions hyperbolic arc sine functions hyperbolic arc tangent functions hyperbolic cosine functions hyperbolic cotangent functions hyperbolic sine functions 9 106 hyperbolic tangent functions i compiler option i linker option i stand alone simulator option VO adding a device described functions close flush buffer unlink write implementation overview low level definitions summary of functions 9 34 9 36 _IDECL macro Index 10 identifiers in C language implementation defined behavior 7 2 7 4 include files adding a directory to be searched specifying a search path preprocessor directive generating list of files included include files using ahi assembler option indirect call defined initialization at load time defined described of variables at load time at run time types initialization tables initialized
46. 4 bytes If args is not specified or if not enough space is allocated through args the loader will print a warning message which includes the suggested size needed Using the Stand Alone Simulator 6 7 Using the Profiling Capability of the Stand Alone Simulator 6 4 Using the Profiling Capability of the Stand Alone Simulator Invoking load6x with the g option runs the standalone simulator in profiling mode Source files must be compiled with the at least the default level of symbolic debug information The profile results resemble the results given by the profiler in the Code Composer Studio debugger The profile results are stored in a text file called by the same name as the out file with the vaa extension For example to create a profile information file called file vaa enter the following load6 x g file out Example 6 3 runs three different versions of the dot product routines and prints out the result of each routine Example 6 3 Profiling Dot Product Routines load x q g t out vall 11480 val2 11480 val3 11480 lt t vaa gt Program Name c6xcode t out Start Address 01409680 main in line 46 c6xcode t c Stop Address 014001c0 exit Run Cycles 17988 Profile Cycles 17988 BP Hits 61 Name Count Inclusive Incl Max Exclusive Excl Max Address Size Full Name dot_prod1 1 1024 1024 1024 1024 01409c20 168 _dot_prod1 dot_prod2 1 842 842 842 842 01409b20 232 _dot_prod2 main al 1
47. Argument 10 with B12 for doubles longs and long longs Data page pointer DP Stack pointer SP C64x only Function Structure and Calling Conventions 8 4 Function Structure and Calling Conventions The C C compiler imposes a strict set of rules on function calls Except for special run time support functions any function that calls or is called by a C C function must follow these rules Failure to adhere to these rules can disrupt the C C environment and cause a program to fail 8 4 1 How a Function Makes a Call A function parent function performs the following tasks when it calls another function child function 1 Arguments passed to a function are placed in registers or on the stack If arguments are passed to a function up to the first ten arguments are placed in registers A4 B4 A6 B6 A8 B8 A10 B10 A12 and B12 If longs long longs doubles or long doubles are passed they are placed in register pairs A5 A4 B5 B4 A7 A6 and so on Any remaining arguments are placed on the stack that is the stack pointer points to the next free location SP offset points to the eleventh argument and so on Arguments placed on the stack must be aligned to a value appropriate for their size An argument that is not declared in a prototype and whose size is less than the size of int is passed as an int An argument that is a float is passed as double if it has no prototype declared A structure argument is passed as
48. C C compiler produces data tables for initializing global variables Section 8 8 3 Initialization Tables on page 8 53 discusses the format of these tables These tables are in a named section called cinit The initialization tables are used in one of the following ways Lj Global variables are initialized at run time Use the c linker option see section 8 8 4 Autoinitialization of Variables at Run Time on page Lj Global variables are initialized at load time Use the cr linker option see section 8 8 5 Initialization of Variables at Load time on page When you link a C C program you must use either the c or cr linker option These options tell the linker to select initialization at run time or load time When you compile and link programs the c linker option is the default If used the c linker option must follow the z option See section 5 1 The following list outlines the linking conventions used with c or cr I The symbol _c_int00 is defined as the program entry point it identifies the beginning of the C C boot routine in boot obj When you use c or cr _c_int0O is automatically referenced ensuring that boot obj is automatically linked in from the run time support library I The cinit output section is padded with a termination record so that the loader load time initialization or the boot routine run time initialization knows when to stop reading the initialization tables Co
49. C language I O requests A library build utility is provided with the code generation tools that lets you create customized run time support libraries The use of this utility is covered in Chapter 10 Library Build Utility Topic 9 1 Libraries sis cincteuere ate eleva avete x cteve cals ne ciainialein ie cisaeieweimtaeg wie clays rele 9 2 mhe C VOFEUNCtIONS m eae e aa e e a e oS hHeadenkiles riae E 9 4 Summary of Run Time Support Functions and Macros 9 5 Description of Run Time Support Functions and Macros 9 1 Libraries 9 1 Libraries The following libraries are included with the TMS320C6000 C C compiler Lj rts6200 lib rts6400 lib and rts6700 lib run time support object libraries for use with little endian C C code Lj rts6200e lib rts6400e lib and rts6700e lib run time support object libraries for use with big endian C C code Q rts src run time support source library The run time support object libraries are built from the C C and assembly source contained in the rts src library The run time support libraries do not contain functions involving signals and locale issues They do contain the following ISO C C standard library C I O library Low level support functions that provide I O to the host operating system Intrinsic arithmetic routines System startup routine _c_int00 Functions and macros that allow C C to access specific instructions O O O O O L You
50. Description Syntax for C Syntax for C Defined in Description difftime Calendar Time include lt time h gt char ctime const time_t timer include lt ctime gt char std ctime const time_t timer ctime c in rts src The ctime function converts a calendar time pointed to by timer to local time in the form of a string This is equivalent to asctime localtime timer The function returns the pointer returned by the asctime function For more information about the functions and types that the time h ctime header declares and defines see section 9 3 18 Time Functions time h ctime on pagel 9 27 Time Difference include lt time h gt double difftime time_t time1 time_t time0 include lt ctime gt double std difftime time_t time1 time_t time0 difftime c in rts src The difftime function calculates the difference between two calendar times time1 minus timeO The return value expresses seconds For more information about the functions and types that the time h ctime header declares and defines see section 9 3 18 Time Functions time h ctime on pagel 9 27 Run Time Support Functions 9 55 div Idiv lldiv div Idiv lldiv Syntax for C Syntax for C Defined in Description 9 56 Division include lt stdlib h gt div_t div int numer int denom Idiv_t Idiv long numer long denom IIdiv_t IIdiv long long numer long long denom include lt cstdlib g
51. Guide explains how to use the assembler The linker combines object files into a single executable object module As it creates the executable module it performs relocation and resolves external references The linker accepts relocatable COFF object files and object libraries as input See Linking C C Code for information about invoking the linker See the TMS320C6000 Assembly Language Tools User s Guide for a complete description of the linker The archiver allows you to collect a group of files into a single archive file called a library Additionally the archiver allows you to modify a library by deleting replacing extracting or adding members One of the most useful applications of the archiver is building a library of object modules The TMS320C6000 Assembly Language Tools User s Guide explains how to use the archiver Introduction 1 3 Software Development Tools Overview E You can use the library build utility to build your own customized run time support library see Library Build Utility Standard run time support library functions for C and C are provided as source code in rts src The object code for the run time support functions is compiled for little endian mode versus big endian mode into standard libraries as follows m For little endian C and C code rts6200 lib rts6400 lib and rts6700 lib E For big endian C and C code rts6200e lib rts6400e lib and rts6700e lib The run time support librari
52. L S LS is the resource bound value as determined by the number of instructions that use the L and S units It is calculated with the following formula Bound L S LS ceil L S LS 2 Bound L S D LS LSD is the resource bound value as determined by the number of instructions that use the D L and S unit It is calculated with the following formula Bound L S D LS SLED ceil L S D LS LSD 3 Minimum required memory pad The number of bytes that are read if speculative execution is enabled See section 3 2 3 Collapsing Prologs and Epilogs for Improved Performance and Code Size on page 3 14 for more information Optimizing Software Pipelining 3 2 2 1 Loop Disqualified for Software Pipelining Messages The following messages appear if the loop is completely disqualified for software pipelining m Bad loop structure This error is very rare and can stem from the following m An asm statement inserted in the C code inner loop m Parallel instructions being used as input to the Linear Assembly Optimizer Complex control flow such as GOTO statements and breaks Loop contains a call Sometimes the compiler may not be able to inline a function call that is in a loop Because the compiler could not inline the function call the loop could not be software pipelined Too many instructions There are too many instructions in the loop to software pipeline Software pipelinin
53. Local Variables 0 ccc ee eeee 8 5 Interfacing C and C With Assembly Language 0 00 eeeeee ee ees 8 5 1 Using Assembly Language Modules With C C Code 8 5 2 Using Intrinsics to Access Assembly Language Statements 8 5 3 Using Unaligned Data and 64 Bit Values 00 0 c cece eee eee 8 5 4 Using MUST_ITERATE and _nassert to Enable SIMD and Expand CompilerKnowledge of Loops 2 eeeeeeeeeeeees 8 5 5 Methods to Align Data 0 eect eed 8 5 6 SAT Bit Side Elects 0 cce0un tise veae ian otade EEEREN vealed 8 5 7 IRP and AMR Conventions 6 0 0 cece eee cece tne tenes 8 5 8 Using Inline Assembly Language 2 ceeee cece e eens 8 5 9 Accessing Assembly Language Variables From C C 0005 8 6 Interrupt Handling scencuscnn weenie weer eee ELERE adcerad 8 6 1 Saving Registers During Interrupts 0 00 cece eee eee ee 8 6 2 Using C C Interrupt Routines 0 0 0 c cece eee 8 6 3 Using Assembly Language Interrupt Routines 05 Contents 8 7 _Run Time Support Arithmetic Routines 0 0 0 eens 8 8 System Initialization 0 0 teen n ees 8 8 1 Automatic Initialization of Variables 0 00 0 ccc cee ees 8 8 2 Global Constructors 2 0 nunnan eranen nanara 8 8 3 Initialization Tables tii icceec sin eeden edad daecataae ane ean ee ed a a 8 8 4 Autoinitialization of Variables at Run Time
54. O for the C6000 is described in section 9 2 The C IO Functions on pag e 9 4 9 3 5 Fast Macros Static Inline Functions gsm h The gsm h header file contains fast macros and static inline function definitions to define the basic ETSI math operations of a GSM vocoder Header Files 9 3 6 Limits float h cfloat and limits h climits The float h cfloat and limits h climits headers define macros that expand to useful limits and parameters of the TMS320C6000 s numeric representations Table 9 1 and Table 9 2 list these macros and their limits Table 9 1 Macros That Supply Integer Type Range Limits limits h climits Macro Value Description CHAR_BIT 8 Number of bits in type char SCHAR_MIN 128 Minimum value for a signed char SCHAR_MAX 127 Maximum value for a signed char UCHAR_MAX 255 Maximum value for an unsigned char CHAR_MIN SCHAR_MIN Minimum value for a char CHAR_MAX SCHAR_MAX Maximum value for a char SHRT_MIN 32 768 Minimum value for a short int SHRT_MAX 32 767 Maximum value for a short int USHRT_MAX 65 535 Maximum value for an unsigned short int INT_MIN INT_MAX 1 Minimum value for an int INT_MAX 2 147 483 647 Maximum value for an int UINT_MAX 4 294 967 295 Maximum value for an unsigned int LONG_MIN LONG_MAX 1 Minimum value for a long int LONG_MAX 549 755 813 887 Maximum value for a long int ULONG_MAX 1 099 511 627 775 Maximum value for an unsigned long int LLONG_MIN LLONG_MAX 1 Minimum value for a lon
55. RE KEKE k k k k k k k k k k k k CIR sect yeinitsa 8 54 System Initialization The cinit section must contain only initialization tables in this format When interfacing assembly language modules do not use the cinit section for any other purpose Figure 8 9 Format of Initialization Records in the pinit Section pinit section Address of constructor 1 Address of constructor 2 Address of constructor 3 Address of constructor n When you use the c or cr option the linker combines the cinit sections from all the C modules and appends a null word to the end of the composite cinit section This terminating record appears as a record with a size field of 0 and marks the end of the initialization tables Likewise the c or cr linker option causes the linker to combine all of the pinit sections from all C C modules and append a null word to the end of the composite pinit section The boot routine knows the end of the global constructor table when it encounters a null constructor address The const qualified variables are initialized differently see section 7 4 1 The const Keyword on page 7 7 Run Time Environment 8 55 System Initialization 8 8 4 Autoinitialization of Variables at Run Time Autoinitializing variables at run time is the default method of autoinitialization To use this method invoke the linker with the c option Using this method the cinit section
56. REGA y REGB u v w MV x y LDW u v w The rega and regb directives are valid within procedures only that is within occurrences of the proc and endproc directive pair or the cproc and endproc directive pair When a variable is declared with the rega or regb directive it is not necessary to declare that variable with the reg directive The old method of partitioning registers indirectly by partitioning instructions can still be used Side and functional unit specifiers can still be used on instructions However functional unit specifiers L S D M and crosspath information are ignored Side specifiers are translated into partitioning constraints on the corresponding variable names if any For example MV 1X Z Yy translated to REGA y LDW D2T2 u v w translated to REGB u v w Reserve a Register reserve register registero The reserve directive prevents the assembly optimizer from using the specified register in a proc or cproc region If a reserved register is explicitly assigned in a proc or cproc region then the assembly optimizer can also use that register For example the variable tmp1 can be allocated to register A7 even though it is in the reserve list since A7 was explicitly defined in the ADD instruction cproc reserve a7 areg tmp1 ADD a6 b4 a7 endproc Example 1 Example 2 Syntax Description return pey Note Reserving Registers A4 and A5
57. Sets the file position indicator for the stream that _fp points to to _pos The pointer _pos must be a value from fgetpos on the same stream Obtains the current value of the file position indicator for the stream that _ fp points to Writes a block of data from the memory pointed to by _ptr to the stream that _fp points to Reads the next character in the stream that _ fp points to A macro that calls fgetc and supplies stdin as the argument Performs the same function as fgets using stdin as the input stream Maps the error number in _s to a string and prints the error message Performs the same function as fprintf but uses stdout as its output stream A macro that performs like FPU Run Time Support Functions 9 35 Summary of Run Time Support Functions and Macros f C I O functions stdio h cstdio Continued Function Description Page A macro that calls fputc and uses stout as the int putchar int _ x int puts const char _ptr int remove const char _file int rename const char _old const char _new void rewind register FILE _fp int scanf const char _fmt void setbuf register FILE _fp char _buf int setvbuf register FILE _fp register char _buf register int _type register size_t _ size int sprintf char _string const char _ format int sscanf const char _str const char _fmt FILE tmpfile void char tmpnam char _s int ungetc in
58. Software pipelining is a technique use to schedule from a loop so that multiple iterations of a loop execute in parallel See section 3 2 Optimizing Software Pipelining on page 3 4 lfor more information Optimizing Your Code 3 45 3 46 Chapter 4 Using the Assembly Optimizer The assembly optimizer allows you to write assembly code without being concerned with the pipeline structure of the C6000 or assigning registers It accepts linear assembly code which is assembly code that may have had register allocation performed and is unscheduled The assembly optimizer assigns registers and uses loop optimizations to turn linear assembly into highly parallel assembly Topic Page 4 1 Code Development Flow to Increase Performance 4 2 4 2 About the Assembly Optimizer cceeceeeeeeeeeeees 4 4 4 3 What You Need to Know to Write Linear Assembly 4 4 4 4 Assembly Optimizer Directives 0 00ceece eee cence 4 5 Avoiding Memory Bank Conflicts With the Assembly Optimizer 4 6 Memory Alias Disambiguation cce cence eee eee 4 1 Code Development Flow to Increase Performance 4 1 Code Development Flow to Increase Performance You can achieve the best performance from your C6000 code if you follow this flow when you are writing and debugging your code Phase 1 Write C C code Develop C C code Yes Complete No Refine C C code Phase 2 code
59. The C Programming Language second edition by Brian W Kernighan and Dennis M Ritchie published by Prentice Hall Englewood Cliffs New Jersey 1988 The C Programming Language second edition Bjame Stroustrup pub lished by Addison Wesley Publishing Company Reading Massachusetts 1990 Trademarks Trademarks Solaris and SunOS are trademarks of Sun Microsystems Inc UNIX is a registered trademark in the United States and other countries licensed exclusively through X Open Company Limited Windows and Windows NT are registered trademarks of Microsoft Corporation The Texas Instruments logo and Texas Instruments are registered trademarks of Texas Instruments Incorporated Trademarks of Texas Instruments include TI XDS Code Composer Code Composer Studio TMS320 TMS320C6000 and 320 Hotline On line All other brand or product names are trademarks or registered trademarks of their respective companies or organizations Read This First vii viii Contents INTFOCUCTION o isc5 ed betes ecawed eevee nen s tered rend Neda ten eee eae ees Provides an overview of the TMS320C6000 software development tools specifically the optimizing C compiler 1 1 Software Development Tools Overview 00 c cece e eee teen eee 1 2 C C Compiler Overview 00 nent eens 1 2 1 ISO Standard rreren ek ROE a kabee ete hated lake hide aed heeds 1 2 2 OUTDUTIFIICS maigran ene ancien ga eM e Se Bate ha eee aie 1 2 3
60. The MUST_ITERATE Pragma The MUST_ITERATE pragma specifies to the compiler certain properties of a loop You guarantee that these properties are always true Through the use of the MUST_ITERATE pragma you can guarantee that a loop executes a specific number of times Anytime the UNROLL pragma is applied to a loop MUST_ITERATE should be applied to the same loop Here the MUST_ITERATE pragma s third argument multiple is the most important and should always be specified Furthermore the MUST_ITERATE pragma should be applied to any other loops as often as possible This is because the information provided via the pragma especially the minimum number of iterations aids the compiler in choosing the best loops and loop transformations that is software pipelining and nested loop transformations It also helps the compiler reduce code size No statements are allowed between the MUST_ITERATE pragma and the for while or do while loop to which it applies However other pragmas such as UNROLL and PROB_ITERATE can appear between the MUST_ITERATE pragma and the loop 7 7 14 1 The MUST_ITERATE Pragma Syntax 7 28 The syntax of the pragma for C and C is pragma MUST_ITERATE min max multiple The arguments min and max are programmer guaranteed minimum and maximum trip counts The trip count is the number of times a loop iterates The trip count of the loop must be evenly divisible by multiple All arguments are optional
61. The linker uses this method when you invoke the linker with the c option The linker loads the cinit section of data tables into memory and variables are initialized at run time big endian An addressing protocol in which bytes are numbered from left to right within a word More significant bytes in a word have lower numbered addresses Endian ordering is hardware specific and is deter mined at reset See also little endian block A set of statements that are grouped together within braces and treated as an entity bss section One of the default COFF sections You use the bss directive to reserve a specified amount of space in the memory map that you can use later for storing data The bss section is uninitialized byte Per ANSI C the smallest addressable unit that can hold a character C C compiler A software program that translates C source statements into assembly language source statements A utility that lets you com pile assemble and optionally link in one step The compiler runs one or more source modules through the compiler including the parser opti mizer and code generator the assembler and the linker C C optimizer See optimizer code generator A compiler tool that takes the file produced by the parser or the optimizer and produces an assembly language source file COFF See common object file format command file A file that contains linker or hex conversion utility options and names input fil
62. The number does not contain a decimal For example version 5 14 is represented as 514 Defined to indicate that compiler conforms to ISO C Standard See section 7 1 Characteristics of TMS320C6000 C on page 7 2 lfor exceptions to ISO C conformance T Specified by the ISO standard You can use the names listed in Table 2 3 in the same manner as any other defined name For example printf s aS TIME f DATE translates to a line such as printf SS SS 13 58 17 Jan 14 1997 2 5 2 The Search Path for include Files The include preprocessor directive tells the compiler to read source statements from another file When specifying the file you can enclose the filename in double quotes or in angle brackets The filename can be a complete pathname partial path information or a filename with no path information LJ If you enclose the filename in double quotes the compiler searches for the file in the following directories in this order 1 The directory that contains the current source file The current source file refers to the file that is being compiled when the compiler encounters the include directive Directories named with the I option Directories set with the C6X_C_DIR or C_DIR environment variable Using the C C Compiler 2 27 Controlling the Preprocessor J If you enclose the filename in angle brackets lt gt the compiler searches for the file in the following direc
63. Too many reads of one register The same register can be read a maximum of 4 times per cycle with the C6200 or C6700 core The C6400 core can read the same register any number of times per cycle Trip variable used in loop Can t adjust trip count The loop trip counter has a use in the loop other than as a loop trip counter Optimizing Your Code 3 11 Optimizing Software Pipelining 3 2 2 3 Investigative Feedback The following messages can appear when the compiler or assembly optimizer detects that performance can be improved with the software pipeline J Loop carried dependency bound is much larger than unpartitioned resource bound There may be a potential memory alias disambiguation problem This means that there are two pointers that may or may not point to the same location and thus the compiler must assume they might This can cause a dependency often between the load of one pointer and the store of another that does not really exist For software pipelined loops this can greatly degrade performance I Two loops are generated one not software pipelined If the trip count is too low it is illegal to execute the software pipelined version of the loop In this case the compiler could not guarantee that the minimum trip count would be high enough to always safely execute the pipelined version Hence it generated a non pipelined version as well Code is generated so that at run time the appropriate version of the loop wil
64. Transitions into and out of include files a _j Diagnostics E Preprocessed source line if nontrivial processing was performed comment removal is considered trivial other preprocessing is nontrivial Each source line in the raw listing file begins with one of the identifiers listed in Table 2 4 Table 2 4 Raw Listing File Identifiers 2 36 Identifier Definition N Normal line of source X Expanded line of source It appears immediately following the normal line of source if nontrivial preprocessing occurs Skipped source line false if clause L Change in source position given in the following format L line number filename key Where line number is the line number in the source file The key is present only when the change is due to entry exit of an include file Possible values of key are as follows 1 entry into an include file 2 exit from an include file Generating a Raw Listing File pl Option The pl option also includes as defined in Table 2 5 Table 2 5 Raw Listing File Diagnostic Identifiers Diagnostic identifier Definition E Error F Fatal R Remark W Warning Diagnostic raw listing information is displayed in the following format S filename line number column number diagnostic S One of the identifiers in Table 2 5 that indicates the severity of the diagnostic filename The source file line number The line number in the source file column number The column number in the source
65. Used in the load6x environment clock returns a cycle accurate count The clock function returns 1 when used with the HLL debugger A host specific clock function can be written You must also define the CLOCKS_PER_SEC macro according to the units of your clock so that the value returned by clock number of clock ticks can be divided by CLOCKS_PER_SEC to produce a value in seconds For more information about the functions and types that the time h ctime header declares and defines see section 9 3 18 Time Functions time h ctime on page 9 27 cos cosf Syntax for C Syntax for C Defined in Description Example cosh coshf Syntax for C Syntax for C Defined in Description Example cosh coshf Cosine include lt math h gt double cos double x float cosf float x include lt cmath gt double std cos double x float std cosf float x cos c and cosf c in rts src The cos and cosf functions return the cosine of a floating point number x The angle x is expressed in radians An argument with a large magnitude might produce a result with little or no significance double radians cval radians 0 0 cval cos radians cval 0 0 Hyperbolic Cosine include lt math h gt double cosh double x float coshf float x include lt cmath gt double std cosh double x float std coshf float x cosh c and coshf c in rts src The cosh and coshf funct
66. _NDEVICE found in stdio h cstdio The structure representing a device is also defined in stdio h cstdio and is composed of the following fields name String for device name flags Flags that specify whether the device supports multiple streams or not function pointers Pointers to the device level functions g CLOSE J LSEEK J OPEN Jg READ Jg RENAME Jg WRITE J UNLINK The first entry in the device table is predefined to be the host device on which the debugger is running The low level routine add_device finds the first empty position in the device table and initializes the device fields with the passed in arguments For a complete description see the add_device function on page 9 7 9 14 The C I O Functions 3 Once the device is added call fopen to open a stream and associate it with that device Use devicename filename as the first argument to fopen The following program illustrates adding and using a device for C I O include lt stdio h gt BORK RK KK RK RK KK KK KK RR KK I k ke k RRR KK RR RRR RK k k k k k Declarations of the user defined device drivers BORK RRR RK RR kkk k k k k k k k k k k k k RR k k k k k k k k RR RR RRR RR k k RR k k k k k k RR k k RK k k k k k extern int my_open const char path unsigned flags int fno extern int my_close int fno extern int my_read int fno char buffer unsigned count extern int my _write int fno const char buffer unsigned count exte
67. _rcpsp float src RCPSP Computes the approximate 32 bit float reciprocal Run Time Environment 8 35 Interfacing C and C With Assembly Language Table 8 5 TMS320C67x C C Compiler Intrinsics Continued Assembly C C Compiler Intrinsic Instruction Description double _rsqrdp double src RSQRDP Computes the approximate 64 bit double square root reciprocal float _rsqrsp float src RSQRSP Computes the approximate 32 bit float square root reciprocal int _spint float SPINT Converts 32 bit float to 32 bit signed integer 8 5 3 Using Unaligned Data and 64 Bit Values using the rounding mode set by the CSR register The C64x family has support for unaligned loads and stores of 64 bit and 32 bit values via the use of the _mem8 memd8 and _mem4 intrinsics The _lo and _hi intrinsics are useful for extracting the two 32 bit portions from a 64 bit double Example 8 2 shows the usage of the _lo hi mem8 and _memd8 intrinsics Example 8 2 Using the _lo and _hi Intrinsics double d _memd8 a high hi d low _lo d double d _mem8d a d void load_longlong_unaligned void a void store_longlong_unaligned void a int high int low int high int low itod high low 8 36 Interfacing C and C With Assembly Language Example 8 3 Using the _lo and _hi Intrinsics With long long Integers void alt_load_longlong_ unaligned void a int high int low long long p
68. a A gt D D e Iere Tee Al IAI TAT Ial A R Go do J Ja Sie e A A A cl joy S ef IPL IS AT TARP PR NT INT IN Sre A gt 9 51 9 51 9 2 oj al o wj j 1 9 3 Summary of Run Time Support Functions and Macros c Floating point math functions math h cmath Continued Function Description Page float cotf float x Returns the cotangent of x t double coth double x Returns the hyperbolic cotangent of x t 9 54 float cothf float x Returns the hyperbolic cotangent of x t 9 54 double exp double x Returns eX double exp10 double x Returns 10 0 t float exp10f float x Returns 10 0 t 9 57 double exp2 double x Returns 2 0 t 9 58 float exp2f float x Returns 2 0 t float expf float x Returns eX double fabs double x Returns the absolute value of x 9 59 float fabsf float x Returns the absolute value of x 9 59 double floor double x Returns the largest integer lt x expands inline except when pi is used 9 61 9 61 float floorf float x Returns the largest integer lt x expands inline except when pi is used Returns the exact floating point remainder of x y Returns the exact floating point remainder of x y double fmod double x double y float fmodf float x float y double frexp double value int exp Returns f and exp such that 5 lt f lt 1 and value 9 65 is equal to f x 2 amp xP float frexpf float value int exp Returns f
69. a floating point number x A range error occurs if the magnitude of the argument is too large These functions are equivalent to eX e 2 but are computationally faster and more accurate double x y x X 0 0 sinh x y 0 0 Syntax for C Syntax for C Defined in Description sqrt sartf Syntax for C Syntax for C Defined in Description Example Syntax for C Syntax for C Defined in Description sscanf Write Stream include lt stdio h gt int sprintf char _string const char _ format include lt cstdio gt int std sprintf char _string const char _format sprintf c in rts src The sprintf function writes to the array pointed to by _ string The string pointed to by _format describes how to write the stream Square Root include lt math h gt double sqrt double x float sqrtf float x include lt cmath gt double std sqrt double x float std sqrtf float x sqrt c and sartf c in rts src The sqrt function returns the nonnegative square root of a real number x A domain error occurs if the argument is negative double x y 100 0 sqrt x x y return value 10 0 See rand srand on page 9 84 Read Stream include lt stdio h gt int sscanf const char _str const char _ fmt include lt cstdio gt int std sscanf const char _str const char _ fmt sscanf c in rts src The sscanf function read
70. a section other than bss and therefore must be declared far in C 3 Use the def or global directive to make the definition external 4 Precede the name with an underscore in assembly language 5 In C C declare the variable as extern and access it normally Example 8 6 shows how you can access a variable defined in bss Example 8 6 Accessing an Assembly Language Variable From C 8 44 a C program extern int varl External variable far extern int var2 External variable varl 1 Use the variable var2 1 Use the variable b Assembly language program Note the use of underscores in the following lines bss _varl1 4 4 Define the variable global var Declare it as external _var2 usect mysect 4 4 Define the variable global _var2 Declare it as external Interfacing C and C With Assembly Language 8 5 9 2 Accessing Assembly Language Constants You can define global constants in assembly language by using the set def and global directives or you can define them in a linker command file using a linker assignment statement These constants are accessible from C C only with the use of special operators For normal variables defined in C C or assembly language the symbol table contains the address of the value of the variable For assembler constants however the symbol table contains the value of the constant The compiler cannot tell whic
71. a set of software development tools which includes an optimizing C C compiler an assembly optimizer an assembler a linker and assorted utilities This chapter provides an overview of these tools and introduces the features of the optimizing C C compiler The assembly optimizer is discussed in Chapter 4 The assembler and linker are discussed in detail in the TMS320C6000 Assembly Language Tools User s Guide Topic Page 1 1 Software Development Tools Overview 0eceeceneeeees 1 2 1 2 C C Compiler Overview 0c cee eee cence eee eee e ees 1 5 1 3 Code Composer Studio and the Compiler cs0eee0e 1 8 Software Development Tools Overview 1 1 Software Development Tools Overview Figure 1 1 illustrates the C6000 software development flow The shaded portion of the figure highlights the most common path of software development for C language programs The other portions are peripheral functions that enhance the development process Figure 1 1 TMS320C6000 Software Development Flow Macro source files C C source files Linear assembly Assembler source Macro library Assembly optimized file Library of object files Run time support Linker library Executable COFF file Debugging tools Software Development Tools Overview The following list describes the tools that are shown in Figure 1 1 m The
72. allocation rule has two exceptions I If the keyword volatile is also specified in the definition of an object for example volatile const int x Volatile keywords are assumed to be allocated to RAM The program does not modify a const volatile object but something external to the program might LJ Ifthe object has automatic storage allocated on the stack In both cases the storage for the object is the same as if the const keyword were not used The placement of the const keyword within a definition is important For example the first statement below defines a constant pointer p to a variable int The second statement defines a variable pointer q to a constant int int const p const int q amp X amp X Using the const keyword you can define large constant tables and allocate them into system ROM For example to allocate a ROM table you could use the following definition far const int digits 0 1 2 3 4 5 6 7 8 9 TMS320C6000 C C Language Implementation 7 7 Keywords 7 4 2 The cregister Keyword The C6000 compiler extends the C C language by adding the cregister keyword to allow high level language access to control registers When you use the cregister keyword on an object the compiler compares the name of the object to a list of standard control registers for the C6000 see Table 7 2 If the name matches the compiler generates the code to reference the control register If the name does not ma
73. and an unsigned divide routine If the application requires only signed division then only the signed divide routine is required for linking By default both the signed and unsigned routines are linked in since they exist in the same obj file The mo compiler option remedies this problem by placing each function in a file in its own subsection Thus only the functions that are referenced in the application are linked into the final executable This can result in an overall code size reduction Linking C C Code 5 13 Controlling the Linking Process 5 14 However be aware that using the mo compiler option can result in overall code size growth if all or nearly all functions are being referenced This is because any section containing code must be aligned to a 32 byte boundary to support the C6000 branching mechanism When the mo option is not used all functions in a source file are usually placed in a common section which is aligned When mo is used each function defined in a source file is placed in a unique section Each of the unique sections requires alignment If all the functions in the file are required for linking code size may increase due to the additional alignment padding for the individual subsections Thus the mo compiler option is advantageous for use with libraries where normally only a limited number of the functions in a file are used in any one executable The alternative to the mo option is to place
74. and include that file with the option Invokes the assembler with the hc assembler option to tell the assembler to copy the specified file for the assembly module The file is inserted before source file statements The copied file appears in the assembly listing files Invokes the assembler with the hi assembler option to tell the assembler to include the specified file for the assembly module The file is included before source file statements The included file does not appear in the assembly listing files Invokes the assembler with the I lowercase L assembler option to produce an assembly listing file Performs preprocessing for assembly files but instead of writing preprocessed output writes a list of dependency lines suitable for input to a standard make utility The list is written to a file with the same name as the source file but with a ppa extension Performs preprocessing for assembly files but instead of writing preprocessed output writes a list of files included with the include directive The list is written to a file with the same name as the source file but with a ppa extension Using the C C Compiler 2 23 Changing the Compiler s Behavior With Options as Invokes the assembler with the s assembler option to put labels in the symbol table Label definitions are written to the COFF symbol table for use with symbolic debugging auname Undefines the predefined constant name This option overrides
75. b gt Sam I am 0 c gt I do not strncat a c size a gt I do not b gt Sam I am 0 c gt I do not like green like them 0 eggs and ham 0 Sam I am 0 eggs and ham 0 Sam I am I do not like 0o eggs and ham 0 fj fj f fj fj sa et fj fj ay ies Syntax for C Syntax for C Defined in Description Example strncmp Compare Strings include lt string h gt int strncmp const char string1 const char string2 size_t n include lt cstring gt int std strncmp const char string1 const char string2 size_t n strncmp c in rts src The strncmp function compares up to n characters of string2 with string1 The function returns one of the following values lt 0 if string1 is less than string2 0 if string1 is equal to string2 gt 0_ if string1 is greater than string2 char stra why ask why char strb just do it char stre why not size_t size 4 if stremp stra strb size gt 0 statements here execute LE ETE strc size 0 statements here execute also Run Time Support Functions 9 99 strncpy Syntax for C Syntax for C Defined in Description Example 9 100 String Copy include lt string h gt char strncpy register char dest register const char src register size_t n include lt cstring gt char strncpy register char dest
76. can control how the run time support functions are called in terms of near or far calls with the mr option For more information see section 7 4 4 3 Controlling How Run Time Support Functions Are Called mr Option on page 7 12 9 1 1 Linking Code With the Object Library 9 2 When you link your program you must specify the object library as one of the linker input files so that references to the I O and run time support functions can be resolved You should specify libraries ast on the linker command line because the linker searches a library for unresolved references when it encounters the library on the command line You can also use the x linker option to force repeated searches of each library until the linker can resolve no more references When a library is linked the linker includes only those library members required to resolve undefined references For more information about linking see the TMS320C6000 Assembly Language Tools User s Guide C C and mixed C and C programs can use the same run time support library Run time support functions and variables that can be called and referenced from both C and C will have the same linkage Libraries 9 1 2 Modifying a Library Function You can inspect or modify library functions by using the archiver to extract the appropriate source file or files from the source libraries For example the following command extracts two source files ar6 x x rts srce atoi c st
77. characters isprint Identifies printable ASCII characters including spaces ASCII characters 32 126 ispunct Identifies ASCII punctuation characters isspace Identifies ASCII tab horizontal or vertical space bar carriage return form feed and new line characters isupper Identifies uppercase ASCII alphabetic characters isxdigit Identifies hexadecimal digits 0 9 a f A F The C C compiler also supports a set of macros that perform these same functions The macros have the same names as the functions but are prefixed with an underscore for example _isascii is the macro equivalent of the isascii function In general the macros execute more efficiently than the functions 9 70 labs llabs Idexp Idexpf Syntax for C Syntax for C Defined in Description Example KAZA LC LAY Syntax for C Syntax for C Defined in Description localtime See abs labs llabs on pagd 9 41 Multiply by a Power of 2 include lt math h gt double Idexp double x int exp float Idexpf float x int exp include lt cmath gt double std ldexp double x int exp float std ldexpf float x int exp Idexp c and Idexpf c in rts src The Idexp and Idexpf functions multiply a floating point number x by 2 XP and return x x 2 XP The exp can be a negative or a positive value A range error occurs if the result is too large double result ldexp 1 5 5 result is 48 0 ldexp 6 0 3 result is 0 7
78. compiler option 2 18 symdebug skeletal compiler option 2 18 sysmem section allocating in memory described _SYSMEM_SIZE system constraints SYSMEM_SIZE system initialization described initialization tables system stack t stand alone simulator option tan function tanf function tangent functions tanh function tanhf function target system defined temporary file creation function test an expression function test EOF function test error function text section allocating in memory defined described _TILENHANCED_ MATH_H symbol time function 9 106 time functions asctime function 9 44 clock function ctime function described difftime function gmtime function 9 69 localtime mktime Index 19 Index undefining a constant 2 17 2 24 ungetc function 9 109 strftime function summary of 55 unguarded definition controlled inlining 9 106 uninitialized sections time function __TIME__ macro 2 27 allocating in memory time h header defined time functions continued described 9 2749 28 list summary of functions 9 40 unlink I O function 9 13 time_t data type UNROLL pragma TMP_MAX macro unsigned defined tmpfile function 9 107 using unaligned data and 64 bit vaules tmpnam function utilities overview 1 7 _TMS320C6200 macro _TMS320C6400 macro _TMS320C6700 macro _TMS320C6X macro v C name demangler option 11 2 toascii function v library build utility option
79. counter When the trip counter reaches a limit equal to the trip count the loop terminates The C6000 tools use the trip count to determine whether or not a loop can be pipelined The structure of a software pipelined loop requires the execution of a minimum number of loop iterations a minimum trip count in order to fill or prime the pipeline The minimum trip count for a software pipelined loop is determined by the number of iterations executing in parallel In Figure 3 2 on page 3 4 the minimum trip count is five In the following example A B and C are instructions in a software pipeline so the minimum trip count for this single cycle software pipelined loop is three A B C ou gt A lt Three iterations in parallel minimum trip count B C When the C6000 tools cannot determine the trip count for a loop then by default two loops and control logic are generated The first loop is not pipelined and it executes if the run time trip count is less than the loop s minimum trip count The second loop is the software pipelined loop and it executes when the run time trip count is greater than or equal to the minimum trip count At any given time one of the loops is a redundant loop foo N N is the trip count After finding a software pipeline for the loop the compiler transforms foo as below assuming the minimum trip count for the loop is 3 Two versions of the loop would be generated and the following compar
80. declarations float h header 9 19 9 20 external symbol defined floating point math functions remainder functions Gi summary of functions 9 3149 33 f linker option floor function floorf function f stand alone simulator option fl f ush I O buffer function fa compiler option imod function tapsJunetign fmodf function fabst function fo compiler option far keyword fopen function far section FOPEN_MAX macro ee cn Bl fp compiler option fpos_t datatype 9 25 af RS manto fprintf function Tate Lenor fputc function 9 63 fb compiler option fouts function fc compiler option ft gompiler option fclose function fraction and exponent functions feof function 9 59 fread function ferror function free function ff compiler option freopen function fflush function frexp function fg compiler option frexpf function fgetc function fs compiler option fgetpos function fscanf function fgets function fseek function file fsetpos function copy ft compiler option 2 22 o eel ftell function removal function FUNC_CANNOT_INLINE pragma rename function FUNC_EXT_CALLED pragma FILE data type described __FILE__ macro use with pm option file h header FUNC_INTERRUPT_THRESHOLD pragma file level optimization FUNC_IS_PURE pragma defined FUNC_IS_SYSTEM pragma Index 8 FUNC_NEVER_RETURNS pragma FUNC_NO_GLOBAL_ASG pragma FUNC_NO_IND_ASG pragma function alphabetic reference call bypassing normal calls conventions 8 19 8 22
81. delta is determined by the assembly optimizer as it constructs the schedule for the software pipeline The base offset and stride are supplied by the load and store instructions and or by the mptr directive Avoiding Memory Bank Conflicts With the Assembly Optimizer An LD B BU H HU W or ST B H W operation in linear assembly can have memory bank information associated with it implicitly by using the mptr directive The mptr directive associates a register with the information that allows the assembly optimizer to determine automatically whether two memory operations have a bank conflict If the assembly optimizer determines that two memory operations have a memory bank conflict then it does not schedule them in parallel The syntax is mptr register base offset stride For example mptr a_0 a 0 16 mptr a_4 a 4 16 LDW a_0 4 vall base a offset 0 stride 16 LDW a_4 4 val2 base a offset 4 stride 16 mptr dptr D 0 8 DH dptr dod DH dptr dl DH dptr d2 LDH dptr d3 base D offset 0 stride 8 base D offset 2 stride 8 base D offset 4 stride 8 base D offset 6 stride 8 Pee In this example the offset for dptr is updated after every memory access The offset is updated only when the pointer is modified by a constant This occurs for the pre post increment decrement addressing modes See page 4 21 for information about the mptr directive Using the Assembly Optimizer 4 35
82. e nee ene nes 7 7 4 The DATA_SECTION Pragma 2 00sec eee ete eee ees 7 7 5 The FUNC_CANNOT_INLINE Pragma 002 20 cee eeeeee ees 7 7 6 The FUNC_EXT_CALLED Pragma 060 ketini Daini 7 7 7 The FUNC_INTERRUPT_THRESHOLD Pragma 7 7 8 The FUNC IS PURE Pragma 0 00 c cece e eee ene ene ia 7 79 The FUNC_IS_ SYSTEM Pragma 0c cece neces 7 7 10 The FUNC_NEVER_RETURNS Pragma 0000eee eee 7 7 11 The FUNC_NO_GLOBAL_ASG Pragma 6 c cece eee eee 7 7 12 The FUNC _NO_IND_ASG Pragma 0 00 c cece ence e neces 7 7 13 The INTERRUPT Pragma 0 0c cece eee nent eee 7 7 14 The MUST_ITERATE Pragma 0 0 c cece eee 7 7 15 The NMILINTERRUPT Pragma 0060 cece eee eee eee ee 7 7 16 The PROB_ITERATE Pragma 006 c eee e eee eee 7 7 17 The STRUCT_ALIGN Pragma 0000 e eee eee ee 7 7 18 The UNROLL Pragma 2 cece cece eee eee 7 8 Generating LinknameS 0 0c cece eee eee eee eee ees Contents xiii Contents xiv 7 9 Initializing Static and Global Variables eeuse cece eee ees 7 9 1 Initializing Static and Global Variables With the Linker 7 9 2 Initializing Static and Global Variables With the const Type Qualifier 7 10 Changing the ISO C Language Mode cece eee tee eee eee ees 7 10 1 Compatibility With K amp R C pk Option
83. each of size bytes Divides numer by denom producing a quotient and a remainder Deallocates memory space allocated by malloc calloc or realloc Returns the environment information for the variable associated with _ string Terminates a program normally Returns the absolute value of i expands inline Returns the absolute value of i expands inline Divides numer by denom Divides numer by denom 9 56 ie 4j K Converts val to the equivalent string Converts val to the equivalent string 9 74 Allocates memory for an object of size bytes Allocates memory for an object of size bytes aligned to an alignment byte boundary N Run Time Support Functions 9 3 Summary of Run Time Support Functions and Macros g General functions stdlib h cstdlib Continued Function Description Page void minit void Resets all the memory previously allocated by malloc calloc or realloc void qsort void base size_t nmemb Sorts an array of nmemb members base points to size_t size int compar const void the first member of the unsorted array and size const void specifies the size of each member int rand void Returns a sequence of pseudorandom integers in the range 0 to RAND_MAX void realloc void packet size_t size Changes the size of an allocated memory space void srand unsigned int seed Resets the random number generator double strtod const char st char endptr Converts a string to a floating point value 9 103 lo
84. either single letters or sequences of characters Individual options cannot be combined An option with a required parameter should be specified with an equal sign before the parameter to clearly associate the parameter with the option For example the option to undefine a constant can be expressed as U name Although not recommended you can separate the option and the parameter with or without a space as in U name or Uname An option with an optional parameter should be specified with an equal sign before the parameter to clearly associate the parameter with the option For example the option to specify the maximum amount of optimization can be expressed as O 3 Although not recommended you can specify the parameter directly after the option as in O3 No space is allowed between the option and the optional parameter so O 3 is not accepted Files and options except the z option can occur in any order The z option must follow all other compiler options and precede any linker options You can define default options for the compiler by using the C_OPTION or C6X_C_OPTION environment variable For a detailed description of these environment variables see section 2 4 Setting Default Compiler Options C_OPTION and C6X_C_OPTION on page 2 25 Table 2 1 summarizes all options including linker options Use the page references in the table for more complete descriptions of the options For an online summary of the options
85. enter cl6x with no parameters on the command line Using the C C Compiler 2 5 Changing the Compiler s Behavior With Options Table 2 1 Compiler Options Summary a Options that control the compiler Option filename C Dname def h Idirectory k Uname verbose Z Effect Interprets contents of a file as an extension to the command line Multiple instances may be used Disables linking negates z Predefines name Help Defines include search path Keeps the assembly language asm file Compiles or assembly optimizes only Suppresses progress messages quiet Interlists optimizer comments if available and assembly source statements otherwise interlists C and assembly source statements Interlists C source and assembly statements Undefines name Displays a banner and function progress information Enables linking N roll wo RR 4 2 a ale P g gt o N a D MIN KORN foe Kop N a D N L D N a D 2 17 Changing the Compiler s Behavior With Options Table 2 1 Compiler Options Summary Continued b Options that control symbolic debugging and profiling Option 9 profile breakpt symdebug coff symdebug dwarf symdebug none symdebug skeletal Effect Enables symbolic debugging symdebug dwarf equivalent to Enables breakpoint based profiling Enables symbolic debugging using the alter
86. f x 2 XP The power is stored in the int pointed to by exp If value is 0 both parts of the result are 0 double fraction int exp fraction frexp 3 0 amp exp after execution fraction is 75 and exp is 2 Run Time Support Functions 9 65 fscanf Syntax for C Syntax for C Defined in Description Syntax for C Syntax for C Defined in Description Syntax for C Defined in Description 9 66 Read Stream include lt stdio h gt int fscanf FILE _fp const char _fmt include lt cstdio gt int std fscanf FILE _fp const char _fmt fscanf c in rts src The fscanf function reads from the stream pointed to by _ fp The string pointed to by _fmt describes how to read the stream Set File Position Indicator include lt stdio h gt int fseek register FILE _fp long _ offset int _ptrname include lt cstdio gt int std fseek register FILE _fp long _ offset int _ptrname fseek c in rts src The fseek function sets the file position indicator for the stream pointed to by _fp The position is specified by _ptrname For a binary file use _ offset to position the indicator from _ptrname For a text file offset must be 0 Set File Position Indicator include lt stdio h gt int fsetpos FILE _fp const foos_t _pos fsetpos c in rts src The fsetpos function sets the file position indicator for the stream pointed to by _fp to_pos The pointer _pos must be a va
87. file diagnostic The message text for the diagnostic Diagnostics after the end of file are indicated as the last line of the file with a column number of 0 When diagnostic message text requires more than one line each subsequent line contains the same file line and column information but uses a lowercase version of the diagnostic identifier For more information about diagnostic messages see section 2 6 Understanding Diagnostic Messages on page 2 31 Using the C C Compiler 2 37 Using Inline Function Expansion 2 10 Using Inline Function Expansion When an inline function is called the C C source code for the function is inserted at the point of the call This is known as inline function expansion Inline function expansion is advantageous in short functions for the following reasons Lj It saves the overhead of a function call OJ Once inlined the optimizer is free to optimize the function in context with the surrounding code There are several types of inline function expansion _j inlining with intrinsic operators intrinsics are always inlined Automatic inlining J J Definition controlled inlining with the unguarded inline keyword J Definition controlled inlining with the guarded inline keyword Note Function Inlining Can Greatly Increase Code Size Expanding functions inline increases code size especially inlining a function that is called in a number of places Function inlining is optimal fo
88. for C Defined in Description 9 76 Memory Compare include lt string h gt int memcmp const void cs const void ct size_t n include lt cstring gt int std mememp const void cs const void ct size_t n memcmp c in rts src The memcmp function compares the first n characters of the object that ct points to with the object that cs points to The function returns one of the following values lt 0 if csis less than ct 0 if cs is equal to ct gt 0_ if csis greater than ct The memcmp function is similar to strncmp except that the objects that memcmp compares can contain values of 0 Memory Block Copy Nonoverlapping include lt string h gt void memcpy void s1 const void s2 register size_t n include lt cstring gt void std memcpy void s1 const void s2 register size_t n memcpy c in rts src The memcpy function copies n characters from the object that s2 points to into the object that s1 points to If you attempt to copy characters of overlapping objects the function s behavior is undefined The function returns the value of s1 The memcpy function is similar to strncpy except that the objects that memcpy copies can contain values of 0 memmove Syntax for C Syntax for C Defined in Description Syntax for C Syntax for C Defined in Description memset Memory Block Copy Overlapping include lt string h gt void memmove void s1 const voi
89. fpfilename for a C source file For example if you have a C source file called files and an assembly language source file called assy use the fa and fc options to force the correct interpretation cl6x fc file s fa assy You cannot use the fa fc fl and fo options with wildcard specifications The fg option causes the compiler to process C files as C files By default the compiler treats files with a c extension as C files See section 2 3 4 Specifying Filenames on page 2 19 for more information about filename extension conventions Changing the Compiler s Behavior With Options 2 3 6 Changing How the Compiler Program Interprets and Names Extensions ea ec el eo ep and es Options You can use options to change how the compiler program interprets filename extensions and names the extensions of the files that it creates The ea el and eo options must precede the filenames they apply to on the command line You can use wildcard specifications with these options An extension can be up to nine characters in length Select the appropriate option for the type of extension you want to specify eal new extension for an assembly language file ec new extension for a C source file el new extension for a linear assembly source file eof new extension for an object file ep new extension for a C source file es new extension sets default extension for listing fi
90. freely and can completely remove variables or expressions Although the compiler never optimizes out an asm statement except when it is unreachable the surrounding environment where the assembly code is inserted can differ significantly from the original C C source code It is usually safe to use asm statements to manipulate hardware controls such as interrupt masks but asm statements that attempt to interface with the C C environment or access C C variables can have unexpected results After compilation check the assembly output to make sure your asm statements are correct and maintain the integrity of the program Automatic Inline Expansion oi Option 3 10 Automatic Inline Expansion oi Option When optimizing with the O3 option the compiler automatically inlines small functions A command line option oisize specifies the size threshold Any function larger than the size threshold is not automatically inlined You can use the oisize option in the following ways _j If you set the size parameter to 0 oi0 automatic inline expansion is disabled _j If you set the size parameter to a nonzero integer the compiler uses this size threshold as a limit to the size of the functions it automatically inlines The compiler multiplies the number of times the function is inlined plus 1 if the function is externally visible and its declaration cannot be safely removed by the size of the function The compiler inlin
91. function writes to the stream pointed to by _ fp The string pointed to by _format describes how to write the stream Write Character include lt stdio h gt int fputc int _c register FILE _fp include lt cstdio gt int std fputc int _c register FILE _fp fputc c in rts src The fputc function writes a character to the stream pointed to by _ fp Write String include lt stdio h gt int fputs const char _ptr register FILE _fp include lt cstdio gt int std fputs const char _ptr register FILE _fp fputs c in rts src The fputs function writes the string pointed to by _ ptr to the stream pointed to by _ fp Run Time Support Functions 9 63 fread Syntax for C Syntax for C Defined in Description Syntax for C Syntax for C Defined in Description Example 9 64 Read Stream include lt stdio h gt size_t fread void _ptr size_t _size size_t count FILE _fp include lt cstdio gt size_t std fread void _ptr size_t _size size_t count FILE _fp fread c in rts src The fread function reads from the stream pointed to by _ fp The input is stored in the array pointed to by _ ptr The number of objects read is _count The size of the objects is _ size Deallocate Memory include lt stdlib h gt void free void packet include lt cstdlib gt void free void packet memory c in rts src The free function deallocates memory space pointed to by packet that
92. h 2 0005 9 3 8 Alternative Spellings iso646 h ciso646 0 002 cece ee 9 3 9 Function Calls as near or far linkage h 00 2c eee eee ee 9 3 10 Floating Point Math math h cmath 0 e eee 9 3 11 Nonlocal Jumps setjmp h csetjmp 60000 cece eee eee ee 9 3 12 Variable Arguments stdarg h cstdarg cece eee 9 3 13 Standard Definitions sttdef h cstddef 00 0c eee eee 9 3 14 Integer Types Stdint h 0 eens 9 3 15 Input Output Functions stdio h cstdio 0 eee eee 9 3 16 General Utilities stdlib h cstdlib 0 cee eee 9 3 17 String Functions string h cstring 00 6 9 3 18 Time Functions time h ctime 0 eee 9 3 19 Exception Handling exception and stdexcept ee eee 9 3 20 Dynamic Memory Management new 0c cece eee eee 9 3 21 Run Time Type Information typeinfo 0 cee eee eee Summary of Run Time Support Functions and Macros 000eeee eee Description of Run Time Support Functions and Macros 0 00 ees Contents XV Contents 10 Library Build Utility 2125 sijsccnisaerieseivaaetansetdacednanatdayadaatadaguieess Describes the utility that custom makes run time support libraries for the options used to compile code You can use this utility to install header files in a directory and to create custom libraries from source archives 10 1
93. is declared by the ctype h header Before you can use the isdigit function you must first include ctype h include lt ctype h gt val isdigit num You can include headers in any order You must however include a header before you reference any of the functions or objects that it declares Sections 9 3 1 Diagnostic Messages assert h cassert on page 9 17 through 9 3 21 Run Time Type Information typeinfo on page 9 28 describe the header files that are included with the C6000 C C compiler Section 9 4 Summary of Run Time Support Functions and Macros on page 9 29 I sts the functions that these headers declare Header Files 9 3 1 Diagnostic Messages assert h cassert The assert h cassert header defines the assert macro which inserts diagnostic failure messages into programs at run time The assert macro tests a run time expression Lj If the expression is true nonzero the program continues running _ Ifthe expression is false the macro outputs a message that contains the expression the source file name and the line number of the statement that contains the expression then the program terminates using the abort function The assert h cassert header refers to another macro named NDEBUG assert h cassert does not define NDEBUG If you have defined NDEBUG as a macro name when you include assert h cassert assert is turned off and does nothing If NDEBUG is not defined assert is enabled The assert
94. is loaded into memory along with all the other initialized sections The linker defines a special symbol called cinit that points to the beginning of the initialization tables in memory When the program begins running the C C boot routine copies data from the tables pointed to by cinit into the specified variables in the bss section This allows initialization data to be stored in ROM and copied to RAM each time the program starts Figure 8 10 illustrates autoinitialization at run time Use this method in any system where your application runs from code burned into ROM Figure 8 10 Autoinitialization at Run Time 8 56 Object file Memory Initialization Scio eae section oaaer ROM bss section RAM System Initialization 8 8 5 Initialization of Variables at Load Time Initialization of variables at load time enhances performance by reducing boot time and by saving the memory used by the initialization tables To use this method invoke the linker with the cr option When you use the cr linker option the linker sets the STYP_COPY bit in the cinit section s header This tells the loader not to load the cinit section into memory The cinit section occupies no space in the memory map The linker also sets the cinit symbol to 1 normally cinit points to the beginning of the initialization tables This indicates to the boot routine that the initialization tables are not present in memory accordin
95. iso646 h ciso646 The iso646 h ciso646 header defines the following eleven macros that expand to the corresponding tokens Macro Token Macro Token and amp amp not_eq l and_eq amp or bitand amp or_eq bitor xor A compl xor_eq N not 9 3 9 Function Calls as near or far linkage h The linkage h header declares macros that determine how code and data in the run time support library is accessed Depending on the value of the _FAR_RTS macro the CODE ACCESS macro is set to force calls to run time support functions to be either user default near or far The _FAR_RTS macro is set according to the use of the mr compiler option The _DATA_ACCESS macro is set to always be far The _IDECL macro determines how inline functions are declared All header files that define functions or data declare include lt linkage h gt Functions are modified with CODE ACCESS for example extern _CODE ACCESS void exit int _status Data is modified with DATA_ACCESS for example extern DATA ACCESS unsigned char _ctypes_ 9 3 10 Floating Point Math math h cmath The math h cmath header declares several trigonometric exponential and hyperbolic math functions These functions are listed in Table 9 3 c on page 9 31 The math functions expect arguments either of type double or of type float and return values either of type double or of type float respectively Except where indicated all trigonometric functions use a
96. least two cycles to execute 4 instructions 2 parallel D units Unpartitioned resource bound The best possible resource bound values before the instructions in the loop are partitioned to a particular side Partitioned resource bound The resource bound values after the instructions are partitioned Resource partition This table summarizes how the instructions have been partitioned This information can be used to help assign functional units when writing linear assembly Each table entry has values for the A side and B side registers An asterisk is used to mark those entries that determine the resource bound value The table entries represent the following terms m L units is the total number of instructions that require L units Optimizing Your Code 3 7 Optimizing Software Pipelining 3 8 S units is the total number of instructions that require S units D units is the total number of instructions that require D units M units is the total number of instructions that require M units X cross paths is the total number of X cross paths T address paths is the total number of address paths Long read path is the total number of long read port paths Long write path is the total number of long write port paths Logical ops LS is the total number of instructions that can use either the L or S unit Addition ops LSD is the total number of instructions that can use either the L or S or D unit Bound
97. level optimization prolog The portion of code in a function that sets up the stack See also pipelined loop prolog push An operation that places a data object on a stack for temporary storage Glossary A 7 Glossary A 8 redundant loops Two versions of the same loop where one is a software pipelined loop and the other is an unpipelined loop Redundant loops are generated when the TMS320C6000 tools cannot guarantee that the trip count is large enough to pipeline a loop for maximum performance relocation A process in which the linker adjusts all the references to a symbol when the symbol s address changes run time environment The run time parameters in which your program must function These parameters are defined by the memory and register conventions stack organization function call conventions and system initialization run time support functions Standard ISO functions that perform tasks that are not part of the C language such as memory allocation string conversion and string searches run time support library A library file rts src that contains the source for the run time support functions section A relocatable block of code or data that will ultimately be contiguous with other sections in the memory map section header A portion of a COFF object file that contains information about a section in the file Each section has its own header The header points to the section s starting address conta
98. line If you have set z in the environment variable and want to compile only use the compiler c option These additional examples assume C_OPTION is set as shown above cl6x c compiles and links cl6x c c only compiles cl6x c z Ink cmd compiles and links using a command file cl6 x c c z Ilnk cmd only compiles c overrides z For more information about compiler options see section 2 3 Changing the Compiler s Behavior With Options on page 2 5 For more information about linker options see section 5 2 Linker Options on page 5 5 Using the C C Compiler 2 25 Controlling the Preprocessor 2 5 Controlling the Preprocessor This section describes specific features that control the C6000 preprocessor which is part of the parser A general description of C preprocessing is in section A12 of K amp R The C6000 C C compiler includes standard C C preprocessing functions which are built into the first pass of the compiler The preprocessor handles m E E m Macro definitions and expansions include files Conditional compilation Various other preprocessor directives specified in the source file as lines beginning with the character The preprocessor produces self explanatory error messages The line number and the filename where the error occurred are printed along with a diagnostic message 2 5 1 Predefined Macro Names The compiler maintains and recognizes the predefined macro nam
99. line 12 warning statement is unreachable Because it is standard programming practice to include break statements at the end of each case arm to avoid the fall through condition these warnings can be ignored Using the pden option you can find out the diagnostic identifier for these warnings Here is the result ferr c err c line 9 warning 111 D statement is unreachable err c line 12 warning 111 D statement is unreachable Next you can use the diagnostic identifier of 111 as the argument to the pdsr option to treat this warning as a remark This compilation now produces no diagnostic messages because remarks are disabled by default Although this type of control is useful it can also be extremely dangerous The compiler often emits messages that indicate a less than obvious problem Be careful to analyze all diagnostics emitted before using the suppression options Other Messages Generating Cross Reference Listing Information px Option 2 7 Other Messages Other error messages that are unrelated to the source such as incorrect command line syntax or inability to find specified files are usually fatal They are identified by the symbol gt gt preceding the message 2 8 Generating Cross Reference Listing Information px Option The px option generates a cross reference listing file that contains reference information for each identifier in the source file The px option is separate from ax w
100. loaded program For example load6 x q x my _program out a b c In this example q and x are arguments for load6x a b and c are arguments to be passed to the loaded program on the target So in this case when my_program is loaded the boot code needs to create an argc and argv value and pass them to the main function The argc value is 4 and argv is an array of pointers to the four strings my_program out a b and c Passing Arguments to a Program Through the Loader 6 3 2 Reserving Target Memory to Store the Arguments args Linker Option The arguments from the host load6x program must be passed to the target system so the boot code can pass the information to main This requires target memory in which to store the strings and the array of pointers to those strings The linker args size option instructs the linker to allocate memory on the target so that the loader can use that memory to store all the contents of the argv array and the argc variable It is your responsibility to make the size big enough to accommodate all the arguments passed on the loader command line For Example 6 2 on C6x there are four arguments and four strings The C standard states that argv must always have an extra NULL pointer after all the legitimate arguments For Example 6 2 this requires a total of 48 bytes Array of five pointers 20 bytes Space for the strings my_program out a b and c 24 bytes Space for argc
101. log10 and log10f functions return the base 10 logarithm of a real number x A domain error occurs if x is negative a range error occurs if x is 0 float x y x x 10 0 log10f x y approx 1 0 Cole PICOT PAi Syntax for C Syntax for C Defined in Description Example Syntax for C Syntax for C Defined in Description Ilitoa Base 2 Logarithm define _TI_ENHANCED_MATH_H 1 include lt math h gt double log2 double x float log2f float x define _TlENHANCED MATH_H 1 include lt cmath gt double std log2 double x float std log2f float x log2 c and log2f c in rts src The log2 and log2f functions return the base 2 logarithm of a real number x A domain error occurs if x is negative a range error occurs if x is 0 float x y x yY 2 03 log2 x y approx 1 0 See setimp longjmp on page 9 88 Convert Long Long Integer to ASCII no prototype provided int Iltoa long long val char buffer no prototype provided int std Iltoa long long val char buffer lltoa c in rts srce The Iltoa function is a nonstandard non ISO function and is provided for compatibility The standard equivalent is sprintf The function is not prototyped in rts src The Iltoa function converts a long long integer n to an equivalent ASCII string and writes it into the buffer If the input number val is negative a leading minus sign is output The Iltoa function returns the
102. macro is defined as define assert ignore The header file that defines the assert macro refers to another macro NASSERT If you have defined NASSERT as a macro name when the assert h header is included in the source file the assert macro behaves as if it is a call to the _nassert intrinsic In this example an integer i is divided by another integer j Since dividing by 0 is an illegal operation the example uses the assert macro to test j before the division If j 0 assert issues a message and aborts the program int i j assert j q i j atan atanf Syntax for C Syntax for C Defined in Description Example atan2 atan2f Syntax for C Syntax for C Defined in Description Example atan2 atan2f Polar Arc Tangent include lt math h gt double atan double x float atanf float x include lt cmath gt double std atan double x float std atanf float x atan c and atanf c in rts src The atan and atanf functions return the arc tangent of a floating point argument x The return value is an angle in the range 7 2 1 2 radians double realval radians realval 0 0 radians atan realval radians 0 0 Cartesian Arc Tangent include lt math h gt double atan2 double y double x float atan2f float y float x include lt cmath gt double std atan2 double y double x float std atan2f float y float x atan2 c and atan2f c in rts src
103. must link all C C programs with code to initialize and execute the program called a bootstrap routine also known as the boot obj object module When a C C program begins running it must execute boot obj first The boot obj module contains code and data to initialize the run time environment the linker automatically extracts boot obj and links it when you use c and include the appropriate run time support library in the link The archive libraries listed below contain C C run time support functions rts6200 lib rts6400 lib rts6700 lib rts6200e lib rts6400e lib rts6700e lib The boot obj module contains code and data for initializing the run time environment The module performs the following tasks 1 Sets up the stack and configuration registers 2 Processes the cinit run time initialization table and autoinitializes global variables when using the c option 3 Calls all global constructors pinit 4 Calls main 5 Calls exit when main returns The run time support object libraries contain boot obj You can 4 Use the archiver to extract boot obj from the library and then link the module in directly _ Include the appropriate run time support library as an input file the linker automatically extracts boot obj when you use the c or cr option A sample bootstrap routine is _c_int00 provided in boot obj in the run time support object libraries The entry point is usually set to the starting address of the bootstr
104. name The pragma must appear before any declaration or reference to the function that you want to keep The syntax of the pragma in C is pragma FUNC_IS_ SYSTEM func The syntax of the pragma in C is pragma FUNC_IS SYSTEM In C the argument func is the name of the function to treat as an ISO standard function In C the pragma applies to the next function declared TMS320C6000 C C Language Implementation 7 25 Pragma Directives 7 7 10 The FUNC_NEVER_RETURNS Pragma The FUNC_NEVER_RETURNS pragma specifies to the compiler that the function never returns to its caller The pragma must appear before any declaration or reference to the function that you want to keep The syntax of the pragma in C is pragma FUNC_NEVER_RETURNS func The syntax of the pragma in C is pragma FUNC_NEVER_RETURNS In C the argument func is the name of the function that does not return In C the pragma applies to the next function declared 7 7 11 The FUNC_NO_GLOBAL_ASG Pragma The FUNC_NO_GLOBAL_ASG pragma specifies to the compiler that the function makes no assignments to named global variables and contains no asm statements The pragma must appear before any declaration or reference to the function that you want to keep The syntax of the pragma in C is pragma FUNC_NO GLOBAL _ASG func The syntax of the pragma in C is pragma FUNC_NO GLOBAL_
105. occurs for xxx seconds I O events include system calls Pauses after each internal I O error Does not pause for EOF Using the Stand Alone Simulator 6 5 Passing Arguments to a Program Through the Loader 6 3 Passing Arguments to a Program Through the Loader In general for any command line tool you can pass arguments on the command line to the program for example Example 6 2 Passing Options on the Command Line 6 3 1 6 6 cl6x a b c d file c C provides a standard mechanism for communicating arguments to a program through the argc and argv arguments to main In C you can declare the function main as taking two arguments as shown int main int argc char argv The command name is included so there are six arguments in Example 6 2 cl6x a b C d file c O O O O O L The number of command line arguments is stored in argc An array of pointers to strings containing the arguments is stored in argv Determining Which Arguments Effect Which Program The loader and the run time environment allow you to pass command line arguments to the program being loaded just as if the target program was run directly from the command line The syntax to pass arguments is load6x options filename out options Command line options before the object filename are treated as arguments for the loader The loader treats any command line options after the object filename as command line arguments to the
106. of TMS320C6000 C For information about the representation of data types see section 7 3 on page 7 6 ISO 3 1 2 5 K amp R A4 2 The type size_t which is the result of the sizeof operator is unsigned int ISO 3 3 3 4 K amp R A7 4 8 The type ptrdiff_t which is the result of pointer subtraction is int ISO 3 3 6 K amp R A7 7 Float to integer conversions truncate toward 0 ISO 3 2 1 3 K amp R A6 3 Pointers and integers can be freely converted ISO 3 3 4 K amp R A6 6 When two signed integers are divided and either is negative the quotient is negative and the sign of the remainder is the same as the sign of the numerator The slash mark is used to find the quotient and the percent symbol is used to find the remainder For example 10 3 3 10 3 3 10 3 1 10 3 1 ISO 3 3 5 K amp R A7 6 A signed modulus operation takes the sign of the dividend the first operand A right shift of a signed value is an arithmetic shift that is the sign is preserved ISO 3 3 7 K amp R A7 8 TMS320C6000 C C Language Implementation 7 3 Characteristics of TMS320C6000 C 7 1 5 Declarations 7 1 6 Preprocessor 7 4 E The register storage class is effective for all chars shorts ints and pointer types For more information see section 7 5 Register Variables on page 7 16 ISO 3 5 1 K amp R A2 1 Structure members are packed into words ISO 3 5 2 1 K amp R A8 3 A bit
107. of the function and deallocates the space at the end of the function 8 4 2 How a Called Function Responds 8 20 A called function child function must perform the following tasks 1 The called function child allocates enough space on the stack for any local variables temporary storage areas and arguments to functions that this function might call This allocation occurs once at the beginning of the function and may include the allocation of the frame pointer FP The frame pointer is used to read arguments from the stack and to handle register spilling instructions If any arguments are placed on the stack or if the frame size exceeds 128K bytes the frame pointer A15 is allocated in the following manner a The old A15 is saved on the stack b The new frame pointer is set to the current SP B15 Function Structure and Calling Conventions c The frame is allocated by decrementing SP by a constant d Neither A15 FP nor B15 SP is decremented anywhere else within this function If the above conditions are not met the frame pointer A15 is not allocated In this situation the frame is allocated by subtracting a constant from register B15 SP Register B15 SP is not decremented anywhere else within this function If the called function calls any other functions the return address must be saved on the stack Otherwise it is left in the return register B3 and is overwritten by the next function call If
108. open Ue uneton mv compiler option operand defined mw compiler option optimizations aa alias disambiguation branch N control flow simplification controlling the level of n compiler option cost based register allocation name mangling defined data flow nasser intrinsic expression simplification Ni file level NASSERT macro defined natural logarithm functions deserbed NDEBUG macro 9 17 9 46 induction variables near keyword information file options near position independent data inline expansion levels new header new_handler type istor tee nfo extension loop invariant code motion NMI_INTERRUPT pragma program level no_mdep assembly optimizer directive 4 23 4 43 defined nonlocal jump function described nonlocal jump functions and macros register targeting described register tracking register variables f 9 34 i SUTIY S strength reduction 3 43 notation conventions iv 5 optimized code pec ce e debugging 3 33 profiling 3 33 fe optimizer defined A 7 o C name demangler option 11 2 cr AZL o compiler option invoking with compiler options o linker option summary of options o stand alone simulator option options obj extension assembler object file defined Ger name eel oa compiler shell summary object librar eanveniions defined defined linking code with diagnostics 2 11 2 33 offsetof macro library build utility 10 4 0 6 oi compiler option linker 5 5 5 7 Index 14 options
109. or a register side with the rega and regb directives see page The reg directive allows you to use descriptive names for values that are stored in registers The assembly optimizer chooses a register for you such that its use agrees with the functional units chosen for the instructions that operate on the value See page for further details and examples of the reg directive Registers can be directly partitioned through two directives The rega directive is used to constrain a symbolic name to A side registers The regb directive is used to constrain a symbolic name to B side registers See page 4 28 for further details on the rega and regb directives Example 4 1 is a hand coded linear assembly program that computes a dot product compare to Example 4 2 which illustrates C code What You Need to Know to Write Linear Assembly Example 4 1 Linear Assembly Code for Computing a Dot Product cproc a 0 b_0 rega a_4 tmp0 sum0 prodl prod2 regb b_ 4 tmpl suml prod3 prod4 reg cnt sum reg val0 vali D 4 a0 a4 D 4 b 0 b 4 K 100 ent ERO sumo RO sumi 25 a_0 2 valo a 0 1 b 0 2 vall b 0 1 val0 vall prodl b 0 val0 vall prod2 b 1 prodl prod2 tmpo a 0 b 0 tmp0 sum0 sum0 a 1 b 1 U KI Oo Oo L L ME MPYH Al Al o o a_4 2 valo a 2 3 b 4 2 vall b 2 3 val0 vall prod3 b 2 val0 vall prod4 b 3
110. or modules the identifier should not begin with an underscore _ See section 7 8 Generating Linknames on page 7 33 for more information Any object or function declared in assembly language that is accessed or called from C C must be declared with the def or global directive in the assembly language modifier This declares the symbol as external and allows the linker to resolve references to it Likewise to access a C C function or object from assembly language declare the C C object with the ref or global directive in the assembly language module This creates an undeclared external reference that the linker resolves Interfacing C and C With Assembly Language Example 8 1 illustrates a C function called main which calls an assembly language function called asmfunc The asmfunc function takes its single argument adds it to the C global variable called gvar and returns the result Example 8 1 Calling an Assembly Language Function From C C a C program extern C extern int asmfunc int a declare external as function int gvar 4 define global variable void main int i 5 i asmfunc i call function normally b Assembly language program global _asmfunc global _gvar _asmfunc LDW b14 _gvar A3 NOP 4 ADD a3 a4 a3 STW a3 b14 _gvar MV a3 a4 B b3 NOP 5 In the C program in Example 8 1 the extern declaration of asmfunc is op
111. proce dure 4 2914 30_ return assembly optimizer directive rev stand alone simulator option rewind function round function roundf function rounding functions rsqrt function rsqrtf function rts library build utility option 10 4 run time environment defined function call conventions 8 194 8 22 interfacing C with assembly lan guage 8 2318 45 interrupt handling described saving registers introduction memory model during autoinitialization dynamic memory allocation sections register conventions stack system initialization run time initialization linking process of variables run time support functions defined introduction summary 9 29 9 40 Index run time support continued libraries described library build utility 10 1 linking C code 5 8 library defined described macros summary 9 2919 40 standard libraries 10 2 s compiler option s extension s option compilar 248 linker 5 6 s stand alone simulator option sa extension SAT bit side effects saving registers during interrupts scanf function searches section allocating memory bss cinit const created by the compiler defined described far 8 3 header defined text uninitialized SEEK_CUR macro SEEK_END macro SEEK_SET macro set file position functions fseek function 9 66 fsetpos function 9 66 set_new_handler function setbuf fun
112. redundant loop The remainder is due to the prolog and epilog The prolog and epilog of a software pipelined loop consists of up to p 1 stages of length ii where p is the number of iterations that are executed in parallel during the steady state and ii is the cycle time for the pipelined loop body During prolog and epilog collapsing the compiler tries to collapse as many stages as possible However overcollapsing can have a negative performance impact Thus by default the compiler attempts to collapse as many stages as possible without sacrificing performance When ms0 ms1 options are invoked the compiler increasingly favors code size over performance 3 2 3 1 Speculative Execution When prologs and epilogs are collapsed instructions might be speculatively executed thereby causing loads to addresses beyond either end of the range explicitly read within the loop By default the compiler cannot speculate loads because this could cause an illegal memory location to be read Sometimes the compiler can predicate these loads to prevent over execution However this can increase register pressure and might decrease the total amount collapsing which can be performed When the speculate_loadsn option is used the speculative threshold is increased from the default of 0 to n When the threshold is n the compiler can allow a load to be speculatively executed as the memory location it reads will be no more than n bytes before or afte
113. register const char src register size_t n strncpy c in rts src The strncpy function copies up to n characters from src into dest If src is n characters long or longer the null character that terminates src is not copied If you attempt to copy characters from overlapping strings the function s behavior is undefined If src is shorter than n characters strncpy appends null characters to dest so that dest contains n characters The function returns the value of dest Note that stro contains a leading space to make it five characters long Also note that the first five characters of strc are an a space the word am and another space so that after the second execution of strncpy stra begins with the phrase am followed by two spaces In the comments the notation 0 rep resents the null character char stra 100 she is the one mother warned you of char strb 100 he is char strc 100 I am the one father warned you of char strd 100 oops int length 5 strncpy stra strb length stra gt he is the one mother warned you of 0 strb gt he is 0 strc gt I am the one father warned you of 0 strd gt oops 0 strncpy stra strc length stra gt I am the one mother warned you of 0 strb gt he is 0 strce gt I am the one father warned you of 0 strd gt oops 0 strncpy stra
114. return value is 0 0 acot acotf Syntax for C Syntax for C Defined in Description Example acot2 acot2f Syntax for C Syntax for C Defined in Description acot2 acot2f Polar Arc Cotangent define _TI_ENHANCED_MATH_H 1 include lt math h gt double acot double x float acotf float x define _TI_ENHANCED_MATH_H 1 include lt cmath gt double std acot double x float std acotf float x acot c and acoif c in rts src The acot and acotf functions return the arc cotangent of a floating point argument x The return value is an angle in the range 0 70 2 radians double realval radians realval 0 0 radians acotf realval return value Pi 2 Cartesian Arc Cotangent define _Tl ENHANCED MATH_H 1 include lt math h gt double acot2 double x double y float acot2f float x float y define _TlENHANCED MATH_H 1 include lt cmath gt double std acot2 double x double y float std acot2f float x float y acot2 c and acot2f c in rts src The acot2 and acot2f functions return the inverse cotangent of x y The function uses the signs of the arguments to determine the quadrant of the return value Both arguments cannot be 0 The return value is an angle in the range T T radians Run Time Support Functions 9 43 acoth acothf acoth acothf Syntax for C Syntax for C Defined in Description Syntax for C Syntax for C Defined in De
115. run time support library as one of the linker input files When C C programs are linked the linker sets the entry point value in the executable output module to the symbol c_int00 This does not however set the hardware to automatically vector to c_int0O at reset see the TMS320C6000 CPU and Instruction Set Reference Guide The c_int00 function performs the following tasks to initialize the environment 1 It defines a section called stack for the system stack and sets up the initial stack pointers 2 It initializes global variables by copying the data from the initialization tables in the cinit section to the storage allocated for the variables in the bss section If you are initializing variables at load time cr option a loader performs this step before the program runs it is not performed by the boot routine For more information see section 8 8 1 Automatic Initialization of Variables 3 It calls the function main to run the C C program You can replace or modify the boot routine to meet your system requirements However the boot routine must perform the operations listed above to correctly initialize the C C environment See section 9 1 on page 9 2 for a list of the standard run time support libraries that are shipped with the C6000 code generation tools Run Time Environment 8 51 System Initialization 8 8 1 Automatic Initialization of Variables Some global variables must have initial values assigned
116. seconds Since these functions and the CLOCKS_PER_SEC macro are system specific only stubs are provided in the library To use the other time functions you must supply custom versions of these functions Run Time Support Functions 9 27 Header Files Ee Note Writing Your Own Clock Function The clock function works with the stand alone simulator load6x Used in the load6x environment clock returns a cycle accurate count The clock function returns 1 when used with the HLL debugger A host specific clock function can be written You must also define the CLOCKS_PER_SEC macro according to the units of your clock so that the value returned by clock number of clock ticks can be divided by CLOCKS_PER_SEC to produce a value in seconds 9 3 19 Exception Handling exception and stdexcept Exception handling is not supported The exception and stdexcept include files which are for C only are empty 9 3 20 Dynamic Memory Management new The new header which is for C only defines functions for new new delete delete and their placement versions The type new_handler and the function set_new_handler are also provided to support error recovery during memory allocation 9 3 21 Run Time Type Information typeinfo 9 28 The typeinfo header which is for C only defines the type_info structure which is used to re
117. sections allocating in memory defined described inline assembly language automatic expansion declaring functions as definition controlled disabling function expansion intrinsic operators restrictions unguarded definition controlled inline keyword _INLINE macro _ INLINE preprocessor symbol input file changing default extensions changing interpretation of filenames default extensions extensions summary of options summary of options input output definitions int_fastN_t integer type int_leastN_t integer type integer division integrated preprocessor defined interfacing C and assembly 8 23 45 interlist utilit defined described invoking with compiler 2 17 2 46 used with the optimizer interrupt flexibility options handling described saving registers 7 10 interrupt keyword INTERRUPT pragma intmax_t integer type INTN_C macro intN_t integer type intprt_t integer type intrinsics defined inlining operators using to call assembly language state ments inverse tangent of y x invoking C name demangler 11 2 compiler library build utility 10 3 linker through compiler S214 standalone simulator isalnum function isalpha function isascii function iscntrl function isdigit function isgraph function islower function ISO defined standards overview 1 5 TMS320C6000 differences from from standard C from standard C iso646 h header isprint functi
118. size of the heap in bytes directly after the option For more information see section 8 1 3 Dynamic Memory Allocation on page 8 5 Syntax for C Syntax for C Defined in Description Syntax for C Syntax for C Defined in Description memchr Align Heap include lt stdlib h gt void memalign size_t alignment size_t _ size include lt stdlib h gt void std memalign size_t alignment size_t _ size memory c in rts src The memalign function performs like the ANS ISO standard malloc function except that it returns a pointer to a block of memory that is aligned to an alignment byte boundary Thus if _size is 128 and alignment is 16 memalign returns a pointer to a 128 byte block of memory aligned on a 16 byte boundary Find First Occurrence of Byte include lt string h gt void memchr const void cs int c size_t n include lt cstring gt void std memchr const void cs int c size_t n memchr c in rts src The memchr function finds the first occurrence of c in the first n characters of the object that cs points to If the character is found memchr returns a pointer to the located character otherwise it returns a null pointer 0 The memchr function is similar to strchr except that the object that memchr searches can contain values of 0 and c can be 0 Run Time Support Functions 9 75 memcmp Syntax for C Syntax for C Defined in Description Syntax for C Syntax
119. software pipelined loop even without the pragma However if MUST_ITERATE is not specified for a loop such as this the compiler generates code to bypass the loop to account for the possibility of O iterations With the pragma specification the compiler knows that the loop iterates at least once and can eliminate the loop bypassing code MUST_ITERATE can specify a range for the trip count as well as a factor of the trip count For example pragma MUST_ITERATE 8 48 8 for i 0 i lt trip count i This example tells the compiler that the loop executes between 8 and 48 times and that the trip_count variable is a multiple of 8 8 16 24 32 40 48 The multiple argument allows the compiler to unroll the loop You should also consider using MUST_ITERATE for loops with complicated bounds In the following example for i2 ipos 2 i2 lt 40 i2 5 The compiler would have to generate a divide function call to determine at run time the exact number of iterations performed The compiler will not do this In this case using MUST_ITERATE to specify that the loop always executes 8 times allows the compiler to attempt to generate a software pipelined loop pragma MUST_ITERATE 8 8 for i2 ipos 2 i2 lt 40 i2 5 TMS320C6000 C C Language Implementation 7 29 Pragma Directives 7 7 15 The NMI_INTERRUPT Pragma The NMILINTERRUPT pragma enables you to handle non maskable interrupts directly with C code
120. strd length stra gt oops 0 strb gt he is 0 strc gt I am the one father warned you of 0 strd gt oops 0 Syntax for C Syntax for C Defined in Description Example Syntax for C Syntax for C Defined in Description Example strrehr Find Any Matching Character include lt string h gt char std strpbrk const char string const char chs include lt cstring gt char std strpbrk const char string const char chs strpbrk c in rts src The strpbrk function locates the first occurrence in string of any character in chs If strpbrk finds a matching character it returns a pointer to that character otherwise it returns a null pointer 0 char stra it was not me char strb wave char a a strpbrk stra strb After this example a points to the w in was Find Last Occurrence of a Character include lt string h gt char strrchr const char string int c include lt cstring gt char std strrchr const char string int c strrchr c in rts src The strrchr function finds the last occurrence of c in string If strrchr finds the character it returns a pointer to the character otherwise it returns a null pointer 0 char a When zz comes home char b the search is on for zs char the z Tol Z i After this example b points to the z in zs near the end of the string Ru
121. the addressing mode used to access near data which is limited to a 15 bit unsigned offset from DP B14 the data page pointer For some applications it may be desirable to have multiple data pages with separate instances of near data For example a multi channel application may have multiple copies of the same program running with different data pages The functionality is supported by the C6000 compiler s memory model and is referred to as position independent data Position independent data means that all near data accesses are relative to the data page DP pointer allowing for the DP to be changed at run time There are three areas where position independent data is implemented by the compiler 1 Near direct memory access STW B4 DP a global ia bss _a 4 4 All near direct accesses are relative to the DP 2 Near indirect memory access MVK _a Sbss AO ADD DP A0 A0 The expression _a bss calculates the offset of the symbol _a from the start of the bss section The compiler defines the global bss in generated assembly code The value of bss is the starting address of the bss section 3 Initialized near pointers The cinit record for an initialized near pointer value is stored as an offset from the beginning of the bss section During the autoinitialization of global variables the data page pointer is added to these offsets See section 8 8 3 Initialization Tables on page Run Time Environment
122. the called function modifies any registers numbered A10 to A15 or B10 to B15 it must save them either in other registers or on the stack The called function can modify any other registers without saving them If the called function expects a structure argument it receives a pointer to the structure instead If writes are made to the structure from within the called function space for a local copy of the structure must be allocated on the stack and the local structure must be copied from the passed pointer to the structure If no writes are made to the structure it can be referenced in the called function indirectly through the pointer argument You must be careful to declare functions properly that accept structure arguments both at the point where they are called so that the structure argument is passed as an address and at the point where they are declared so the function knows to copy the structure to a local copy The called function executes the code for the function If the called function returns any integer pointer or float type the return value is placed in the A4 register If the function returns a double long double long or long long type the value is placed in the A5 A4 register pair If the function returns a structure the caller allocates space for the structure and passes the address of the return space to the called function in A3 To return a structure the called function copies the structure to the memory b
123. the program must be less than 32K bytes The compiler sets the data page pointer register DP which is B14 during run time initialization to point to the beginning of the bss section Then the compiler can access all objects in oss global and static variables and constant tables with direct addressing without modifying the DP The large memory model does not restrict the size of the bss section unlimited space is available for static and global data However when the compiler accesses any global or static object that is not stored in bss it must first load the object s address into a register before a global data item is accessed This task produces two extra assembly instructions For example the following compiler generated assembly language uses the MVKL and MVKH instructions to move the global variable _x into the AO register then loads the BO register using a pointer to AO MVKL x AO MVKH x AO LDW AO BO To use the large memory model invoke the compiler with the mln option For more information on the min option see section 7 4 4 4 Large Model Option ml on page 7 13 For more information on the storage allocation of global and static variables see section 7 4 4 The near and far Keywords on page 7 11 8 6 Memory Model 8 1 6 Position Independent Data Near global and static data are stored in the bss section All near data for a program must fit within 32K bytes of memory This limit comes from
124. this is not a general practice an exception to this is memory mapped I O although you can access physical memory locations with C C pointer types ss The compiler produces relocatable blocks of code and data called sections The sections are allocated into memory in a variety of ways to conform to a variety of system configurations For more information about sections and allocating them see the introductory COFF information in the TMS320C6000 Assembly Language Tools User s Guide The C6000 compiler creates the following sections J Initialized sections contain data or executable code The C C compiler creates the following initialized sections m The cinit section contains tables for initializing variables and constants m The const section contains string literals floating point constants and data defined with the C C qualifier const provided the constant is not also defined as volatile m The switch section contains jump tables for large switch statements E The text section contains all the executable code Memory Model 3 Uninitialized sections reserve space in memory usually RAM A program can use this space at run time to create and store variables The compiler creates the following uninitialized sections m The bss section reserves space for global and static variables When you specify the c linker option at program startup the C boot routine copies data out of the cinit section which ca
125. to be mangled If you enter dem6x calories in a banana asm the result is shown in Example 11 2 The linknames in Example 11 1 b ct_ 6bananaFv are demangled _calories 6bananaFv and dt_ 6bananaFv Sample Usage of the C Name Demangler Example 11 2 Result After Running the C Name Demangler _calories_in_a_banana CALL ob banana banana 10 STW D2T2 B3 SP 16 9 MVKL S2 RLO B3 10 MVKH 52 RLO B3 A 10 ADD SIX 8 SP A4 A 10 NOP it RLO CALL OCCURS A 10 CALL S1 banana calories 12 MVKL a82 RL1 B3 A 12 MVKH S2 RL1 B3 7 12 ADD S1X 8 SP A4 x 12 NOP 2 RLI CALL OCCURS 12 CALL S1 banana banana 13 STW D2T1 A4 SP 4 A 12 ADD SIX 8 SP A4 A 13 MVKL S2 RL2 B3 13 MVK S2 0x2 B4 13 MVKH S2 RL2 B3 13 RL2 CALL OCCURS Fi 13 LDW D2TL SP 4 A4 12 LDW D2T2 SP 16 B3 13 NOP 4 RET 82 B3 13 NOP 5 BRANCH OCCURS A 13 C Name Demangler 11 5 Appendix A Glossary ANSI See American National Standards Institute alias disambiguation A technique that determines when two pointer expressions cannot point to the same location allowing the compiler to freely optimize such expressions aliasing The ability for a single object to be accessed in more than one way such as when two pointers point to a single object It can disrupt optimiza tion because any indirect reference could refer to any other object
126. to ASCII long long integer to ASCII string to number time to string function to ASCII function copy file using ahc assembler option copy string function cos function cosf function cosh function coshf function 9 53 cosine functions 9 53 cost based register allocation optimization cot function cotangent hyperbolic functions 9 54 polar functions cotf function coth function cothf function cproc assembly optimizer directive cr linker option cregister keyword cross reference listing defined generating with assembler generating with compiler shell cross reference utility csetjmp header described summary of functions and macros cstdarg header described summary of macros Index 5 Index cstdio header described summary of functions 9 34 9 36 cstdlib header described summary of functions cstring header described summary of functions 9 38 ctime function ctime header described summary of functions 9 40 ctype h header data types continued struct_tm time_t va_list _DATA_ACCESS macro 9 22 DATA_ALIGN pragma 7 20 DATA_MEM_BANK pragma DATA_SECTION pragma __DATE__ macro 7 22 daylight savings time deallocate memory function debugging optimized code declarations in C language declare described summary of functions 9 30 circular addressing with circ directive memory reference as volatile variables in l
127. to them before a C C program starts running The process of retrieving these variables data and intializing the variables with the data is called autoinitialization The compiler builds tables in a special section called cinit that contains data for initializing global and static variables Each compiled module contains these initialization tables The linker combines them into a single table a single cinit section The boot routine or a loader uses this table to initialize all the system variables Note Initializing Variables In ISO C global and static variables that are not explicitly initialized are set to 0 before program execution The C6000 C C compiler does not perform any preinitialization of uninitialized variables Explicitly initialize any variable that must have an initial value of 0 The easiest method is to have the stand alone simulator using the b option clear the bss section before the program starts running Another method is to set a fill value of 0 in the linker control map for the bss section You cannot use these methods with code that is burned into ROM Global variables are either autoinitialized at run time or at load time For information see sections 8 8 4 Autoinitialization of Variables at Run Time on page 8 56 and 8 8 5 Initialization of Variables at Load Time on page 8 57 Also see section 7 9 Initializing Static and Global Variables on page 8 8 2 Global Constructors 8 5
128. used OK if not Under ISO the result of these two definitions is a single definition for the object a For most K amp R compilers this sequence is illegal because int a is defined twice ISO prohibits but K amp R allows objects with external linkage to be redeclared as static extern int a static int a illegal unless pk used Unrecognized escape sequences in string and character constants are explicitly illegal under ISO but ignored under K amp R char 4 yg same as q if pk used error if not TMS320C6000 C C Language Implementation 7 37 Changing the ISO C Language Mode Lj ISO specifies that bit fields must be of type int or unsigned With pk bit fields can be legally defined with any integral type For example struct s short f 2 illegal unless pk used OJ K amp R syntax allows a trailing comma in enumerator lists enum a b c illegal unless pk used Lj K amp R syntax allows trailing tokens on preprocessor directives endif NAME illegal unless pk used 7 10 2 Enabling Strict ISO Mode and Relaxed ISO Mode ps and pr Options Use the ps option when you want to compile under strict ISO mode In this mode error messages are provided when non ISO features are used and language extensions that could invalidate a strictly conforming program are disabled Examples of such extensions are the inline and asm keywords Use the pr option when
129. va_start va_list parmN f C I O functions stdio h cstdio Function int add_device char name unsigned flags int dopen int dclose int dread int dwrite fpos_t dlseek int dunlink int drename void clearerr FILE _fp int fclose FILE _fp int feof FILE _fp int ferror FILE _fp int fflush register FILE _fp int fgetc register FILE _fp int fgetpos FILE _fp fpos_t pos char fgets char _ptr register int _ size register FILE _fp 9 34 variable argument list Resets the calling mechanism after using va_arg 9 109 Initializes ap to point to the first operand in the 9 109 variable argument list Description Page Adds a device record to the device table 9 7 Clears the EOF and error indicators for the stream that _ fp points to Flushes the stream that _fp points to and closes the file associated with that stream Tests the EOF indicator for the stream that _fp points to Tests the error indicator for the stream that _ fp points to Flushes the I O buffer for the stream that _fp points to Reads the next character in the stream that _ fp points to Stores the object that pos points to to the current value of the file position indicator for the stream that _ fp points to Reads the next _ size minus 1 characters from the stream that _fp points to into array _ ptr f C I O functions stdio h cstdio Continued Function
130. wud gan aan nde hawt 2 10 3 Unguarded Definition Controlled Inlining 00ee cece 2 10 4 Guarded Inlining and the _INLINE Preprocessor Symbol 2 10 5 inlining Restrictions 0 ett 2 11 Interrupt Flexibility Options mi Option 0000 cee cece ees 2 12 Linking C6400 Code With C6200 C6700 Older C6400 Object Code 213 USING INISNISE ics Geils Bhatia iia debate ane hee Rae Panera de hele 3 Optimizing Your Code 2 ccc eee ee eee Describes how to optimize your C code including such features as software pipelining and loop unrolling Also describes the types of optimizations that are performed when you use the optimizer 3 1 Invoking Optimization 2 4 cecva ened een enering a cans 3 2 Optimizing Software Pipelining 0 cece eee eens 3 2 1 Turn Off Software Pipelining mu Option 00 cece eee 3 2 2 Software Pipelining Information 0 cc eee eee eens 3 2 3 Collapsing Prologs and Epilogs for Improved Performance and Code SIZ i earesa denis amaisa aa Weed A A E EEA A TE ede ae 33 Redundant LOOPS sidered tir Sieedeeeeretes E ENN EE SARENA DAIRE EDNA 3 4 Reducing Code Size ms Option 000 c cece eens 3 5 Performing File Level Optimization 03 Option 0 00 eee ee 3 5 1 Controlling File Level Optimization oln Option 3 5 2 Creating an Optimization Information File onn Option
131. 1 A4 compute final result return A4 endproc Example 4 7 Dot Product Software Pipelined Kernel L2 BO BO PIPED LOOP KERNEL ADD ADD MPY MPYH ADD LDW LDW L2 B7 B4 B4 14 SEL A5 A0 A0 15 M2X B6 A4 B7 7 12 M1X B6 A4 A5 s a3 S1 L2 7 18 S2 OxffffffFLL BO Bo LT D2T2 B5 B6 10 DITL A34 A4 rae e ee lt 0 7 gt sum0 a 0 b 0 lt 0 7 gt suml a 1 b 1 lt 2 5 gt a 0 b 0 lt 2 5 gt a 1 b 1 lt 5 2 gt if i goto loop lt 6 1 gt i lt 7 0 gt load a 0 1 banko lt 7 0 gt load b 0 1 bank2 4 38 It is not always possible to control fully how arrays and other memory objects are aligned This is especially true when a pointer is passed into a function and that pointer may have different alignments each time the function is called A solution to this problem is to write a dot product routine that cannot have memory hits This would eliminate the need for the arrays to use different memory banks If the dot product loop kernel is unrolled once then four LDW instructions execute in the loop kernel Assuming that nothing is known about the bank alignment of arrays a and b except that they are word aligned the only safe assumptions that can be made about the array accesses are that a O 1 cannot conflict with a 2 3 and that b 0 1 cannot conflict with b 2 3 Example 4 8 shows the unrolled loop kernel Avoiding Memory Bank Confl
132. 2 All global C variables that have constructors must have their constructor called before main The compiler builds a table of global constructor addresses that must be called in order before main in a section called pinit The linker combines the pinit section form each input file to form a single table in the pinit section The boot routine uses this table to execute the constructors System Initialization 8 8 3 Initialization Tables The tables in the cinit section consist of variable size initialization records Each variable that must be autoinitialized has a record in the cinit section Figure 8 8 shows the format of the cinit section and the initialization records Figure 8 8 Format of Initialization Records in the cinit Section cinit section Initialization record 1 Initialization record 2 5s Initialization record Initialization record 3 N N Size in Pointer to Initialization N bytes bss area data e Initialization record n The fields of an initialization record contain the following information _ The first field of an initialization record is the size in bytes of the initialization data _j The second field contains the starting address of the area within the bss section where the initialization data must be copied _ The third field contains the data that is copied into the bss section to initialize the variable Each variable that must be autoiniti
133. 2 bit MS LS integer or SE A PA ttt tb bbb te E enum 34 0 MS LS sl ae uuuUuUUUUUUUUUUUUUUUUUUUUUUUUUUUY 31 0 Legend S sign E exponent MS most significant M mantissa signed integer LS least significant U unsigned integer 8 10 Object Representation 8 2 1 3 long Data Types signed and unsigned Long and unsigned long data types are stored in an odd even pair of registers see Figure 8 3 and are always referenced as a pair in the format of odd register even register for example A1 A0 In little endian mode the lower address is loaded into the even register and the higher address is loaded into the odd register if data is loaded from location 0 then the byte at 0 is the lowest byte of the even register In big endian mode the higher address is loaded into the even register and the lower address is loaded into the odd register if data is loaded from location 0 then the byte at 0 is the highest byte of the odd register but is ignored Figure 8 3 40 Bit Data Storage Format a Signed 40 bit long S M Odd register X X X XXX XXXXXXXXXXXXXXXXXX S 31 8 7 6 0 LS 31 0 b Unsigned 40 bit long MS Odd register XIX XX XXXXXXXXXXXXXXXXXXxXX UUUUUUUU 31 8 7 0 LS Even register UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU 31 0 Legend S sign signed integer MS most significant U unsigned integer X unused LS least significant Run Time Environment 8 1 Object Representation 8 2 1 4 long lo
134. 20C6000 Technical Brief literature number SPRU197 gives an introduction to the C6000 platform of digital signal processors develop ment tools and third party support Read This First V Related Documentation Related Documentation vi You can use the following books to supplement this user s guide ANSI X3 159 1989 Programming Language C Alternate version of the 1989 C Standard American National Standards Institute C A Reference Manual fourth edition by Samuel P Harbison and Guy L Steele Jr published by Prentice Hall Englewood Cliffs New Jersey International Standard ISO 14882 1998 Programming Languages C The C standard ISO IEC 14882 1998 International Standard Programming Languages C The C Standard International Organization for Standardiza tion ISO IEC 9899 1989 International Standard Programming Languages C The 1989 C Standard International Organization for Standardiza tion ISO IEC 9899 1999 International Standard Programming Languages C The C Standard International Organization for Standardization Programming Embedded Systems in C and C by Michael Barr Andy Oram Editor published by O Reilly amp Associates ISBN 1565923545 February 1999 Programming in C Steve G Kochan Hayden Book Company The Annotated C Reference Manual Margaret A Ellis and Bjame Stroustrup published by Addison Wesley Publishing Company Reading Massachusetts 1990
135. 3 Because you do not use the FUNC_EXT_CALL pragma you must use the op3 op tion which is less aggressive than the op2 option and your optimization may not be as effective Keep in mind that if you use pm O3 without additional op tions the compiler removes the C functions that the assembly functions call Use the FUNC_EXT_CALLED pragma to keep these functions Indicating Whether Certain Aliasing Techniques Are Used 3 7 Indicating Whether Certain Aliasing Techniques Are Used Aliasing occurs when you can access a single object in more than one way such as when two pointers point to the same object or when a pointer points to a named object Aliasing can disrupt optimization because any indirect reference can refer to another object The compiler analyzes the code to determine where aliasing can and cannot occur then optimizes as much as possible while preserving the correctness of the program The compiler behaves conservatively The following sections describe some aliasing techniques that may be used in your code These techniques are valid according to the ISO C standard and are accepted by the C6000 compiler however they prevent the optimizer from fully optimizing your code 3 7 1 Use the ma Option When Certain Aliases are Used The compiler when invoked with optimization assumes that any variable whose address is passed as an argument to a function is not subsequently modified by an alias set up in the called func
136. 4 7 1 Define and Use Control Registers 0 00 c eee teens 7 2 Use of the restrict type qualifier with pointers 00 00 e cece eee eee 7 3 Use of the restrict type qualifier with arrays 006 eee eee ee 7 4 Using the CODE_SECTION Pragma 0 00 cece eect eee 7 5 Using the DATA_MEM_BANK Pragma 0 00 ee eee eee Contents xix Examples P o CO N I OANDAAKRWNDY DD po a i XX Using the DATA_SECTI Calling an Assembly La Using the _lo and_hi In Using the _lo and_hi In An Array in a Structure An Array in a Class ON Pragma aiaei aya aiaia Taaa ia a ah aai nguage Function From C C INSIS rsa a a E 5 lt rE d aea a A A A os 2g Aanicad trinsics With long long Integers Accessing an Assembly Language Variable From cece cece eens Accessing an Assembly Language Constant From 2 eee ees AMR and SAT Handling Initialization Table Name Mangling Result After Running the C Name Demangler 0 0 arnan eee eee eee Case Sensitivity in Filename Extensions 00 00 0 cece cece tenet nee ene eeed No Default Extension for Source Files is Assume 000 cee eee eee eee Specifying Path Information in Angle Brackets 0 0 c cece ete e ene e ene eed Function Inlining Can Greatly Increase Code Size 2 1 tence tenes RTS Library Files Are Not Built With mi Option
137. 4 1 Near and far data objects Global and static data objects can be accessed in the following two ways near keyword The compiler assumes that the data item can be accessed relative to the data page pointer For example LDW dp _ address a0 far keyword The compiler cannot access the data item via the dp This can be required if the total amount of program data is larger than the offset allowed 32K from the DP For example MVKL _address al MVKH _address al LDW al a0 Once a variable has been defined to be far all external references to this variable in other C files or headers must also contain the far keyword This is also true of the near keyword However you will get compiler or linker errors when the far keyword is not used everywhere Not using the near keyword everywhere only leads to slower data access times By default the compiler generates small memory model code which means that every data object is handled as if it were declared near unless it is actually declared far If an object is declared near it is loaded using relative offset addressing from the data page pointer DP which is B14 DP points to the beginning of the bss section TMS320C6000 C C Language Implementation 7 11 Keywords If you use the DATA_SECTION pragma the object is indicated as a far variable and this cannot be overridden If you reference this object in another file then you need to use extern far when declaring this object in the oth
138. 5 result result See div Idiv lidiv on page 9 56 Local Time include lt time h gt struct tm localtime const time_t timer include lt ctime gt struct tm std localtime const time_t timer localtime c in rts src The localtime function converts a calendar time pointed to by timer into a broken down time which is expressed as local time The function returns a pointer to the converted time For more information about the functions and types that the time h ctime header declares and defines see section 9 3 18 Time Functions time h ctime on page 9 27 Run Time Support Functions 9 71 log logf log logf Syntax for C Syntax for C Defined in Description Example log10 log10f Syntax for C Syntax for C Defined in Description Example 9 72 Natural Logarithm include lt math h gt double log double x float logf float x include lt cmath gt double std log double x float std logf float x log c and logf c in rts src The log and logf functions return the natural logarithm of a real number x A domain error occurs if x is negative a range error occurs if x is 0 float x y x Y 2 718282 logf x y approx 1 0 Common Logarithm include lt math h gt double log10 double x float log10f float x include lt cmath gt double std log10 double x float std log10f float x log10 c and log10f c in rts src The
139. 6400 code with C6200 C6700 Older C6400 object code object library with run time support libraries linknames generated by the compiler listing file creating cross reference defined generating with preprocessor Index 12 little endian changing to big defined F _LITTLE_ENDIAN macro lidiv function litoa function load6x loader defined using with linker local time convert broken down time to local time convert calendar to local time described local variables accessing localtime function log function log10 function log10f function log2 function log2f function logf function long long division longjmp function 9 23 9 88 loop rotation optimization loop unrolling defined loop invariant optimizations loops expand ome knowledge with _nassert 8 37 optimization redundant software pipelining 3 44 3 15 low level I O functions lseek I O function ltoa function m linker option ma compiler option macro _CODE_ACCESS DAMALS FAR RTS _IDECL ie ees BUFSIZ macro continued CLK_TCK CLOCKS_PER_SEC 9 27 52 defined EOF 2 2612 27_ expansions macro call defined macro definition defined macro expansion defined 9 17 46 9 24 9 25 predefined names 2 26 2 27 RAND_MAX SEEK_CUR SEEK_END SEEK_SET malloc function allocating memory dynamic memory allocation reversing map assembly optimizer directive map file def
140. 6x 0 mk6x o0 10 2 12 RTS 12 RTS 12 RTS 12 RTS 12 RTS 12 RTS The run time support libraries that are shipped with the C6000 code generation tools are built with the following command strings rts sre me rts src mv6400 mv6400 me mv6700 mv6700 me rts rts 1 rts6200 lib 1 rts6200e lib SEC rts sre rts 1 rts6400 1ib src l rts6400e lib 1 rts6700 1lib sre l rts6700e lib The base option set for every library is Optimization level 2 o or o2 option Comment base C6200 base C6200 big endian base C6400 base C6400 big endian base C6700 base C6700 big endian 1 Global structures and arrays accessed as far data function calls are far calls ml2 option 1 Enables compiling of a C run time support library based on TI proprietary source code contained in rts src RTS option Invoking the Library Build Utility 10 2 Invoking the Library Build Utility The syntax for invoking the library build utility is mk6x options src_arch1 lobj lib1 src_arch2 lobj lib2 mk6x options src_arch lobj lib Command that invokes the utility Options affect how the library build utility treats your files Options can appear anywhere on the command line or in a linker command file Options are discussed in section 10 2 and 10 4 The name of a source archive file For each source archive named mk6x builds a
141. 7980 17980 125 125 01409680 576 _main dot_prod3 1 89 89 89 89 01498ce0 124 _dot_prod3 6 8 Selecting Silicon Revision to Simulate rev Option 6 5 Selecting Silicon Revision to Simulate rev Option A new silicon revision option allows the standalone simulator to support both revisions 2 and 3 of C6000 silicon By default the standalone simulator simulates revision 2 silicon load6x rev value ile out The valid values are 2 to select revision 2 silicon and 3 to select revision 3 silicon In revision 3 silicon the internal data memory has been divided into two memory spaces 0x8000000 0x80007fff and Ox800800 O0x800ffff allowing accesses to the same bank of memory if you are accessing different halves For example MVK S2 0x80000000 B5 MVKH S2 0x80000000 B5 MVK S1 0x80008000 A5 MVKH S1 0x80008000 A5 LDW D2 B5 B6 LDW D1 A5 A6 In this example the LDW instructions in parallel do not cause a memory bank conflict in revision 3 silicon while it will in revision 2 silicon For an illustration of an interleaved memory with two memory spaces as for revision 3 silicon see Figure 4 2 on pagel 4 34 If the q option is not used the load6x banner lists the selected silicon revision Using the Stand Alone Simulator 6 9 Stand Alone Simulator Example 6 6 Stand Alone Simulator Example A typical use of the stand alone simulator is running code that includes the clock function to find the num
142. 8 7 Object Representation 8 2 Object Representation This section explains how various data objects are sized aligned and accessed 8 2 1 Data Type Storage Table 8 1 lists register and memory storage for various data types Table 8 1 Data Representation in Registers and Memory Data Type char unsigned char short unsigned short int unsigned int enum float long unsigned long long long unsigned long long double long double struct array Register Storage Bits 0 7 of register Bits 0 7 of register Bits 0 15 of register Bits 0 15 of register Entire register Entire register Entire register Entire register Bits 0 39 of even odd register pair Bits 0 39 of even odd register pair Even odd register pair Even odd register pair Even odd register pair Even odd register pair Members are stored as their individual types require Members are stored as their individual types require Memory Storage 8 bits aligned to 8 bit boundary 8 bits aligned to 8 bit boundary 16 bits aligned to 16 bit boundary 16 bits aligned to 16 bit boundary 32 bits aligned to 32 bit boundary 32 bits aligned to 32 bit boundary 32 bits aligned to 32 bit boundary 32 bits aligned to 32 bit boundary 64 bits aligned to 64 bit boundary 64 bits aligned to 64 bit boundary 64 bits aligned to 64 bit boundary 64 bits aligned to 64 bit boundary 64 bits aligned to 64 bit boundary 64 bits aligned to 64 bit boundary Multiple of 8
143. 94 char stra why ask why char strb just do it char strce why ask why if stremp stra strb gt 0 statements here execute if strcoll stra strc 0 statements here execute also String Copy include lt string h gt char strepy register char dest register const char src include lt cstring gt char std strepy register char dest register const char src strcpy c in rts src The strcpy function copies src including a terminating null character into dest If you attempt to copy strings that overlap the function s behavior is undefined The function returns a pointer to dest In the following example the strings pointed to by a and b are two separate and distinct memory locations In the comments the notation 0 represents the null character char al a The quick black fox char b jumps over a gt The quick black fox 0 b gt jumps over 0 strcpy a b a gt jumps over 0 b gt jumps over 0 Syntax for C Syntax for C Defined in Description Example Syntax for C Syntax for C Defined in Description strerror Find Number of Unmatching Characters include lt string h gt size_t strespn register const char string const char chs include lt cstring h gt size_t std strespn register const char string const char chs strcspn c in r
144. ANNOT_INLINE FUNC_EXT_CALLED FUNC_INTERRUPT_THRESHOLD FUNC_IS_ PURE FUNC_IS_SYSTEM FUNC_NEVER_RETURNS FUNC_NO_GLOBAL_ASG FUNC_NO_IND_ASG INTERRUPT 7 27 MUST_ITERATE NMI_INTERRUPT PROB_ITERATE STRUCT_ALIGN UNROLL pref assembly optimizer directive preinitialized variables global and static preprocessed listing file assembly dependency lines assembly include files generating raw information generating with line directives generating with comments preprocessor controlling 2 2642 30 defined directives in C language error messages _ INLINE symbol Index 15 Index preprocessor continued options predefining constant names for symbols prevent reordering of associative floating point operations printf function priority linker option PROB_ITERATE pragma proc assembly optimizer directive processor time function profile breakpt compiler option profiling capability of stand alone simulator profiling optimized code program termination functions abort function atexit function exit function program level optimization controlling defined performing progress information suppressing prolog defined prolog collapsing speculative execution ps compiler option pseudorandom integer generation functions ptrdiff_t pirdiff_t data type push defined A 7 putc function 9 82 putchar function 9 82 puts function px compiler option q
145. ASG In C the argument func is the name of the function that makes no assignments In C the pragma applies to the next function declared 7 26 Pragma Directives 7 7 12 The FUNC_NO_IND_ASG Pragma The FUNC_NO_IND_ASG pragma specifies to the compiler that the function makes no assignments through pointers and contains no asm statements The pragma must appear before any declaration or reference to the function that you want to keep The syntax of the pragma in C is pragma FUNC_NO _IND_ASG func The syntax of the pragma in C is pragma FUNC_NO _IND_ASG In C the argument func is the name of the function that makes no assignments In C the pragma applies to the next function declared 7 7 13 The INTERRUPT Pragma The INTERRUPT pragma enables you to handle interrupts directly with C code In C the argument func is the name of a function In C the pragma applies to the next function declared The syntax of the pragma in C is pragma INTERRUPT func The syntax of the pragma in C is pragma INTERRUPT The code for the function will return via the IRP interrupt return pointer Except for _c_int00 which is the name reserved for the system reset interrupt for C programs the name of the interrupt the func argument does not need to conform to a naming convention TMS320C6000 C C Language Implementation 7 27 Pragma Directives 7 7 14
146. Avoiding Memory Bank Conflicts With the Assembly Optimizer Example 4 4 shows loads and stores extracted from a loop that is being software pipelined Example 4 4 Load and Store Instructions That Specify Memory Bank Information mptr Ain IN 16 mptr Bin IN 4 16 mptr Aco COEF 16 mptr Bco COEF 4 16 mptr Aout optr 0 4 mptr Bout optr 2 4 LDW Ain 2 Ain12 IN k i amp IN k i 1 LDW Bin 2 Bin23 IN k i 2 amp IN k i 1 LDW Ain 2 Ain34 IN k i 4 amp IN k i 3 LDW Bin 2 Bin56 IN k i 6 amp IN k i 5 LDW Bco 4 2 Bcol2 COEF i amp COEF i 1 LDW Aco 4 2 Aco23 COEF i 2 amp COEF i 3 LDW Bco 2 Bin34 COEF i 4 amp COEF i 5 LDW Aco 2 Ain56 COEF i 6 amp COEF i 7 STH Assum Aout 2 oPtr r gt gt 15 STH Bssum Bout 2 oPtr i gt gt 15 4 36 Avoiding Memory Bank Conflicts With the Assembly Optimizer 4 5 2 A Dot Product Example That Avoids Memory Bank Conflicts The C code in Example 4 5 implements a dot product function The inner loop is unrolled once to take advantage of the C6000 s ability to operate on two 16 bit data items in a single 32 bit register LDW instructions are used to load two consecutive short values The linear assembly instructions in Example 4 6 implement the dotp loop kernel Example 4 7 shows the loop kernel determined by the assembly optimizer For this loop kernel
147. C6400 only A1 A2 BO B1 B2 or symbolic The mnemonic is a machine instruction such as ADDK MVKH B or assembly optimizer directive Such as proc trip The optional unit specifier enables you to specify the functional unit operand Only the specified unit side is used other specifications are ignored The preferred method is specifying register sides The operand list is not required for all instructions or directives The operands can be symbols constants or expressions and must be separated by commas Comments are optional Comments that begin in column 1 must begin with a semicolon or an asterisk comments that begin in any other column must begin with a semicolon The C6000 assembly optimizer reads up to 200 characters per line Any characters beyond 200 are truncated Keep the operational part of your source statements that is everything other than comments less than 200 characters in length for correct assembly Your comments can extend beyond the character limit but the truncated portion is not included in the asm file Follow these guidelines in writing linear assembly code _j All statements must begin with a label a blank an asterisk or a semicolon _ Labels are optional if used they must begin in column 1 _ One or more blanks must separate each field Tab characters are interpreted as blanks You must separate the operand list from the preceding field with a blank Using the Assembly Optimize
148. Compiler Interface 0 000 ccc eee nee eee 1 2 4 Compiler Operation 1 0 0 0 6 0 ccc ete eens 1 2 5 Utile S asama Mba ea Nee Mab ee deena a A dete Aa aa 1 3 Code Composer Studio and the Compiler Using the C C Compiler 000 cece eee eee eee Describes how to operate the C C compiler Contains instructions for invoking the compiler which compiles assembles and links a C C source file Discusses the interlist feature options and compiler errors 2 1 2 2 2 3 2 4 About the Compiler 0000 cece cece aa a a Invoking the C C Compiler 00 ccc nea Changing the Compiler s Behavior With Options 000 eee ee 2 3 1 Frequently Used Options 0 00 c cece eect eee eee 2 3 2 Selecting Target CPU Version mv Option 0000ee eee 2 3 3 Symbolic Debugging and Profiling Options 00e eee ee 2 3 4 Specifying Filenames 0000 cece cece eens 2 3 5 Changing How the Compiler Program Interprets Filenames fa fc fg fl fo and fp Options 0 0 cece eee eee 2 3 6 Changing How the Compiler Program Interprets and Names Extensions ea ec el eo ep and es Options 2 3 7 Specifying Directories fb ff fr fs and ft Options 2 3 8 Options That Control the Assembler 0 0 0 cece cece eens 2 3 9 Deprecated OptionS 0 cece cee ene
149. FILE fopen const char _fname const char _mode int fprintf FILE _fp const char _ format int fputc int _c register FILE _fp int fputs const char _ptr register FILE _fp size_t fread void _ptr size_t _size size_t _count FILE _fp FILE freopen const char _fname const char _mode register FILE _fp int fscanf FILE _fp const char _fmt int fseek register FILE _fp long _ offset int _ptrname int fsetpos FILE _fp const fpos_t _pos long ftell FILE _fp size_t fwrite const void _ptr size_t _size size_t _count register FILE _fp int getc FILE _fp int getchar void char gets char _ptr void perror const char _s int printf const char _format int putc int _x FILE _fp Summary of Run Time Support Functions and Macros Description Page Opens the file that _fname points to _mode points to a string describing how to open the file Writes a single character _c to the stream that _fp points to Writes to the stream that _fp points to Writes the string pointed to by _ptr to the stream pointed to by _ fp Reads from the stream pointed to by _fp and stores the input to the array pointed to by _ ptr Opens the file that _fname points to using the stream that _fp points to _mode points to a string describing how to open the file Reads formatted input from the stream that _fp points to Sets the file position indicator for the stream that _ fp points to
150. HL Multiplies the 16 MSBs of src1 by the 16 LSBs of int_mpyhuls uint src1 int src2 MPYHULS src2 and returns the result Values can be signed or unsigned int_mpyhslu int src7 uint src2 MPYHSLU uint_mpyhlu uint src7 uint src2 MPYHLU int_mpyhl int src7 int src2 MPYLH Multiplies the 16 LSBs of src1 by the 16 MSBs of int_mpyluhs uint src1 int src2 MPYLUHS src2 and returns the result Values can be signed or unsigned int_mpylshu int src7 uint src2 MPYLSHU uint_mpylhu uint src7 uint src2 MPYLHU void _nassert int Generates no code Tells the optimizer that the expression declared with the assert function is true this gives a hint to the optimizer as to what optimizations might be valid uint _norm int src2 NORM Returns the number of bits up to the first uint _Inorm long src2 T See the TMS320C6000 Programmer s Guide for more information nonredundant sign bit of src2 See section 8 5 3 Using Unaligned Data and 64 Bit Values for details on manipulating 8 byte data quantities Run Time Environment 8 29 Interfacing C and C With Assembly Language Table 8 3 TMS320C6000 C C Compiler Intrinsics Continued Assembly C C Compiler Intrinsic Instruction Description int_sadd int src7 int src2 SADD Adds srci to src2 and saturates the result long _Isadd int src7 long src2 Retumis We result int _sat long src2 SAT Converts a 40 bit long to a 32 bit signed int and saturates
151. I patent right copyright mask work right or other TI intellectual property right relating to any combination machine or process in which TI products or services are used Information published by TI regarding third party products or services does not constitute a license from TI to use such products or services or a warranty or endorsement thereof Use of such information may require a license from a third party under the patents or other intellectual property of the third party or a license from TI under the patents or other intellectual property of TI Reproduction of information in TI data books or data sheets is permissible only if reproduction is without alteration and is accompanied by all associated warranties conditions limitations and notices Reproduction of this information with alteration is an unfair and deceptive business practice TI is not responsible or liable for such altered documentation Resale of TI products or services with statements different from or beyond the parameters stated by TI for that product or service voids all express and any implied warranties for the associated TI product or service and is an unfair and deceptive business practice Tl is not responsible or liable for any such statements Following are URLs where you can obtain information on other Texas Instruments products and application solutions Products Applications Amplifiers amplifier ti com Audio www ti com audio Data Converters dataconverter
152. In C a character string is terminated by the first byte with a value of 0 a null character The returned result does not include the terminating null character char stra who is there char strb abcdefghijklmnopqrstuvwxyz char stre abcdefg size_t length length strlen stra length 13 length strlen strb length 26 length strlen strc length 7 Run Time Support Functions 9 97 strncat Syntax for C Syntax for C Defined in Description Example 9 98 Concatenate Strings include lt string h gt char strnceat char dest const char src size_t n include lt cstring gt char strneat char dest const char src size_t n strncat c in rts src The strncat function appends up to n characters of src including a terminating null character to dest The initial character of src overwrites the null character that originally terminated dest strncat appends a null character to the result The function returns the value of dest In the following example the character strings pointed to by a b and c were assigned the values shown in the comments In the comments the notation 0 represents the null character like green like them like green like them char a b c size_t size 13 a gt I do not b gt Sam I am 0 c gt I do not strncat a b size a gt I do not
153. Instead use the ms option to control the code size performance tradeoff Higher O levels combined with high ms levels generally result in the smallest code size For more information see section 3 4 Reducing Code Size ms Option on page 3 17 Optimizing Your Code 3 3 Optimizing Software Pipelining Note The On Option Applies to the Assembly Optimizer The On option should also be used with the assembly optimizer Although the assembly optimizer does not perform all the optimizations described here key optimizations such as software pipelining and loop unrolling require the O option to be specified 3 2 Optimizing Software Pipelining Software pipelining is a technique used to schedule instructions from a loop so that multiple iterations of the loop execute in parallel The compiler always attempts to software pipeline In general code size and performance are better when you use the O2 or O3 option See section 3 1 Invoking Optimization You should also use the ms option to reduce code size Figure 3 2 illustrates a software pipelined loop The stages of the loop are represented by A B C D and E In this figure a maximum of five iterations of the loop can execute at one time The shaded area represents the loop kernel In the loop kernel all five stages execute in parallel The area above the kernel is known as the pipelined loop prolog and the area below the kernel is known as the pipelined loop ep
154. Interlist Feature With Optimization Example 3 2 The Function From Example 2 3 Compiled With the O2 and os Options _main 5 printf Hello world n 6 return 0 STW D2 B3 SP 12 line 3 B S1 _printf NOP 2 MVKL S1 SL1 0 A0 MVKH ool SL1 0 A0 MVKL S2 RLO B3 STW D2 AO SP 4 MVKH Sa RLO B3 RLO CALL OCCURS line 4 ZERO L1 A4 line 5 LDW D2 SP 12 B3 NOP 4 B S2 B3 NOP 5 BRANCH OCCURS endfunc 7 000080400h 12 When you use the ss and os options with optimization the compiler inserts its comments and the interlist feature runs before the assembler merging the original C C source into the assembly file Example 3 3 shows the function from Example 2 3 on page 2 47 ompiled with the optimization O2 and the ss and os options The assembly file contains compiler comments and C source interlisted with assembly code Optimizing Your Code 3 31 Using the Interlist Feature With Optimization Example 3 3 The Function From Example 2 3 Compiled With the O2 os and ss Options _main pee 5 eee See ee printf Hello world n 7 6 return 0 STW D2 B3 SP 12 5 printf Hello world n B S1 printf NOP 2 MVKL S1 SL1 0 A0 MVKH SL SL1 0 A0 MVKL S2 RLO B3 STW D2 AO SP 4 MVKH S2 RLO B3 RLO CALL OCCURS 6 return 0
155. Interrupt Handling on page Run Time Environment 8 23 Interfacing C and C With Assembly Language 8 24 Ly When you call a C C function from assembly language load the designated registers with arguments and push the remaining arguments onto the stack as described in section 8 4 1 How a Function Makes a Call on page Remember that only A10 to A15 and B10 to B15 are preserved by the C C compiler C C functions can alter any other registers save any other registers whose contents need to be preserved by pushing them onto the stack before the function is called and restore them after the function returns Functions must return values correctly according to their C C declarations Integers and 32 bit floating point float values are returned in A4 Doubles long doubles longs and long longs are returned in A5 A4 Structures are returned by copying them to the address in A3 No assembly module should use the cinit section for any purpose other than autoinitialization of global variables The C C startup routine assumes that the cinit section consists entirely of initialization tables Disrupting the tables by putting other information in cinit can cause unpredictable results The compiler assigns linknames to all external objects Thus when you are writing assembly language code you must use the same linknames as those assigned by the compiler For identifiers that are to be used only in an assembly language module
156. LJ Copy propagation Following an assignment to a variable the compiler replaces references to the variable with its value The value can be another variable a constant or a common subexpression This can result in increased opportunities for constant folding common subexpression elimination or even total elimination of the variable see Example 3 5 on page 3 39 hna Example 3 6 on page J Common subexpression elimination When two or more expressions produce the same value the compiler computes the value once saves it and reuses it I Redundant assignment elimination Often copy propagation and common subexpression elimination optimizations result in unnecessary assignments to variables variables with no subsequent reference before another assignment or before the end of the function The compiler removes these dead assignments see Example 3 6 3 13 5 Expression Simplification For optimal evaluation the compiler simplifies expressions into equivalent forms requiring fewer instructions or registers Operations between constants are folded into single constants For example a b 4 c 1 becomes a b c 3 see Example 3 6 In Example 3 6 the constant 3 assigned to a is copy propagated to all uses of a a becomes a dead variable and is eliminated The sum of multiplying j by 3 plus multiplying j by 2 is simplified into b j 5 The assignments to a and b are eliminated and their values returned Optimizin
157. LOO Symbol 5 achat siete oe a a aE a E aA E ago acs Aub ater Mantes ded vba atees Defining Global Variables in Assembly Code 0 00 t eens Avoid Disrupting the C C Environment With asm Statements 00 eee eee The Linker Defines the Memory Map 006 e eee eens Use Only Code in Program Memory 00 cece eee cee tet ee eee eee LACK Overload betas a tes ate i Aten dade Stok us E E ER ED E ENS OP SEmaANCS serrit rur cadet eek ee wate ie whee oat wea haa AEA EESE E AAN end a ante dl SLACK Allocation sets aes trig toed scares aon AERD ohh AER EERE EAEE E ee teense eee A Intrinsic Instructions in C versus Assembly Language 00eeee cece eee e eee es C Syntax for nassert 2 0 tected detente teen need Alignment With Program Level Optimization 000 c eee eeeeeee eee Contents xxi Notes Using the asm Statement 00 cc nent eee eens Initializing Variables 22 4 d 73 aiai urinii one E hey dared REE ees Tha CVO Buffer Failte sy cea ok te ek ae lee et eee ee eed eigen Sale Use Unique Function Names 0 0c eee ees Writing Your Own Clock Function 000 c cece aaie iini i aa i a E Writing Your Own Clock Function isinin tiirus eenia eben eens No Previously Allocated Objects Are Available After minit The time Function Is Target System Specific 0 0 eee xxii Chapter 1 Introduction The TMS320C6000 is supported by
158. NOP 5 BRANCH OCCURS 9 global a bss _a 40 4 Optimizing Your Code 3 37 What Kind of Optimization Is Being Performed 3 13 2 Alias Disambiguation C and C programs generally use many pointer variables Frequently compilers are unable to determine whether or not two or more values lowercase L symbols pointer references or structure references refer to the same memory location This aliasing of memory locations often prevents the compiler from retaining values in registers because it cannot be sure that the register and memory continue to hold the same values over time Alias disambiguation is a technique that determines when two pointer expressions cannot point to the same location allowing the compiler to freely optimize such expressions 3 13 3 Branch Optimizations and Control Flow Simplification 3 38 The compiler analyzes the branching behavior of a program and rearranges the linear sequences of operations basic blocks to remove branches or redundant conditions Unreachable code is deleted branches to branches are bypassed and conditional branches over unconditional branches are simplified to a single conditional branch When the value of a condition is determined at compile time through copy propagation or other data flow analysis the the compiler can delete a conditional branch Switch case lists are analyzed in the same way as conditional branches and are sometimes eliminated entirely Some s
159. OOP KERNEL B1 SUB S2 B1 1 B1 lt 0 8 gt ADD L2 B9 B5 B9 21 lt 0 8 gt sumo a 0 b 0 ADD LI A6 A0 A0 22 lt 0 8 gt sumil a 1 b 1 MPY M2X B8 A4 B9 19 lt 1 6 gt a 0 b 0 MPYH M1 X B8 A4 A6 20 lt 1 6 gt a 1 b 1 BO B S1 L2 32 lt 2 4 gt if i goto loop B1 LDW D1T1 A3 8 A4 24 lt 3 2 gt load a 2 3 bankx 2 A1 LDW D2T2 B6 8 B8 17 lt 4 0 gt load a 0 1 bankx A1 SUB S1 A1 1 A1 lt 0 9 gt ADD L2 B5 B9 B5 28 lt 0 9 gt sumo a 2 b 2 ADD L1 A6 A0 A0 29 lt 0 9 gt sumil a 3 b 3 MPY M2X A4 B7 B5 26 lt 1 7 gt al2 b 2 MPYH M1X A4 B7 A6 27 lt 1 7 gt a 3 b 3 BO ADD S2 1 B0 B0 31 lt 3 3 gt i A1 LDW D2T2 B4 8 B7 25 lt 4 1 gt load b 2 3 banky 2 Al LDW D1T1 A5 8 A4 18 lt 4 1 gt load b 0 1 banky Without the mptr directives in Example 4 8 the loads of a 0 1 and b 0 1 are scheduled in parallel and the loads of a 2 3 and b 2 3 are scheduled in parallel This results in a 50 chance that a memory conflict will occur on every cycle However the loop kernel shown in Example 4 9 can never have a memory bank conflict In Example 4 6 if mptr directives had been used to specify that a and b point to different bases then the assembly optimizer would never find a schedule for a 1 cycle loop kernel because there would al
160. Optimization 3 11 Using the Interlist Feature With Optimization 3 30 You control the output of the interlist feature when compiling with optimization the On option with the os and ss options _j The os option interlists compiler comments with assembly source statements J The ss and os options together interlist the compiler comments and the original C C source with the assembly code When you use the os option with optimization the interlist feature does not run as a separate pass Instead the compiler inserts comments into the code indicating how the compiler has rearranged and optimized the code These comments appear in the assembly language file as comments starting with The C C source code is not interlisted unless you use the ss option also The interlist feature can affect optimized code because it might prevent some optimization from crossing C C statement boundaries Optimization makes normal source interlisting impractical because the compiler extensively rearranges your program Therefore when you use the os option the compiler writes reconstructed C C statements Example 3 2 shows the function from Example 2 3 on pagel 2 47 ompiled with optimization O2 and the os option The assembly file contains compiler comments interlisted with assembly code Note Impact on Performance and Code Size The ss option can have a negative effect on performance and code size Using the
161. Optimizations 0 0 eee 3 13 5 Expression Simplification 00 0 cece eee 3 13 6 Inline Expansion of Functions 000 cece eee ee eee 3 13 7 Induction Variables and Strength Reduction 2 00 eeeeee 3 13 8 Loop Invariant Code Motion 0 00 cece eee eee 3 13 9 LOOP Rotation sie decide Meta es cies dake weg gamle eae bet ade wade wien 3 13 10 Register Variables 0 0 cece eee ened 3 13 11 Register Tracking Targeting 0 0 cece eee 3 13 12 Software Pipelining 0 0 c eect Using the Assembly Optimizer 00 cece eee Describes the assembly optimizer which schedules instructions and allocates registers for you Also describes how to write code for the assembly optimizer including information about the directives that you should use with the assembly optimizer 4 1 Code Development Flow to Increase Performance 0 eee c eee ene ees 4 2 Aboutthe Assembly Optimizer 0 c cece eens 4 3 What You Need to Know to Write Linear Assembly 0 0 ccc eee eee eee 4 3 1 Linear Assembly Source Statement Format 0000 cece eee 4 3 2 Register Specification for Linear Assembly 000 cece eee eee 4 3 3 Functional Unit Specification for Linear Assembly 45 4 3 4 Using Linear Assembly Source Comments 022 0eeeeeeee 4 3 5 Assembly File Retains Your Symbolic Register Names
162. R RR RK KK KK RK RR KK RR KR RK RK KR k k RK RR RR RR k k k k k k k k k k k k KK RK k kk strlen S E E K KK KK RR KK KR KR KK KR KK KR KK KR RK KR k k k k k k k k RR KK k k k kk undef _INLINE include lt string h gt _CODE ACCESS size_t strlen cont char string size t n size t 1 const char s string 1 do n while s return n Using the C C Compiler 2 41 Using Inline Function Expansion 2 10 5 Inlining Restrictions 2 42 There are several restrictions on what functions can be inlined for both automatic inlining and definition controlled inlining Functions with local static variables or a variable number of arguments are not inlined with the exception of functions declared as static inline In functions declared as static inline expansion occurs despite the presence of local static variables In addition a limit is placed on the depth of inlining for recursive or nonleaf functions Furthermore inlining should be used for small functions or functions that are called in a few places though the compiler does not enforce this A function may be disqualified from inlining if it Returns a struct or union Has a struct or union parameter Has a volatile parameter Has a variable length argument list Declares a struct union or enum type Contains a static variable Contains a volatile variable Is recursive Contains a pragma Has too large of a stack too many local variables
163. Register pairs A register pair is specified as arghi arglo and represents a 40 bit argument or a 64 bit type double argument for C6700 For example the cproc defined as follows fens Cproc argl arg2hi arg2lo arg3 B6 arg5 B9 B8 return res endproc corresponds to a C function declared as int fcn int argl long arg2 int arg3 int arg4 int arg5 long arg6 In this example the fourth argument of cproc is register B6 This is allowed since the fourth argument in the C C calling conventions is passed in B6 The sixth argument of cproc is the actual register pair B9 B8 This is allowed since the sixth argument in the C C calling conventions is passed in B8 or B9 B8 for longs If you are calling a procedure from C source you must use the appropriate linkname for the procedure label Otherwise you can force C naming conventions by using the extern C declaration See section 7 8 Generating Linknames on page 7 33 and section 8 5 Interfacing C C with Assembly Language on page or more information When endproc is used with a cproc directive it cannot have arguments The live out set for a cproc region is determined by any return directives that appear in the cproc region A value is ive out if it has been defined before or within the procedure and is used as an output from the procedure Returning a value from a cproc region is handled by the return directive The return branch is automatically genera
164. Standard Run Time Support Libraries 10 2 Invoking the Library Build Utility 10 3 Library Build Utility Options 0 0 tenes 10 4 Options Summary sissie few ide had tha Pada neiii eaaa ii oe ld hee oa a i 11 C Name Demangler 00 0 cece eee eee A xvi Describes the C name demangler and tells you how to invoke and use it 11 1 Invoking the C Name Demangler 11 2 C Name Demangler Options 0 0 cece ete eae 11 3 Sample Usage of the C Name Demangler 0 cece eee eee eens GIOSSANY 4 iis2 eens Soa tenes cures wea eee Sree nena ee eta Seen taa gens Defines terms and acronyms used in this book Figures TMS320C6000 Software Development Flow 00 cece eee eee e eee es C C Compiler 2 asii minani aosa teen nent teen eens Compiling a C C Program With Optimization Software Pipelined LOOP 00 cece eee eee etree eens 4 Bank Interleaved Memory 0 000 cece eee nent eee eee ees 4 Bank Interleaved Memory With Two Memory Spaces 2 000eeeeeeees Char and Short Data Storage Format 00 e eee 32 Bit Data Storage Format 40 Bit Data Storage Format 64 Bit Data Storage Format 0 0 cece eens Double Precision Floating Point Data Storage Format 0 cece eee eee ee Bit Field Packing in Big Endian and Little Endian Formats 000 000 Register Argument Conventions 00 6 cece teen eee Format of Initi
165. TMS320C6000 Optimizing Compiler User s Guide Literature Number SPRU187L May 2004 BR ne eas SOY INK rm INSTRUM ENTS Printed on Recycled Paper IMPORTANT NOTICE Texas Instruments Incorporated and its subsidiaries TI reserve the right to make corrections modifications enhancements improvements and other changes to its products and services at any time and to discontinue any product or service without notice Customers should obtain the latest relevant information before placing orders and should verify that such information is current and complete All products are sold subject to Tl s terms and conditions of sale supplied at the time of order acknowledgment Tl warrants performance of its hardware products to the specifications applicable at the time of sale in accordance with Tl s standard warranty Testing and other quality control techniques are used to the extent TI deems necessary to support this warranty Except where mandated by government requirements testing of all parameters of each product is not necessarily performed TI assumes no liability for applications assistance or customer product design Customers are responsible for their products and applications using TI components To minimize the risks associated with customer products and applications customers should provide adequate design and operating safeguards TI does not warrant or represent that any license either express or implied is granted under any T
166. Targeting ccc cece eect teen ee ee tenes 4 1 Linear Assembly Code for Computing a Dot Product 0 0c e eee 4 2 C Code for Computing a Dot Product 0 ccc eect nee en enes 4 3 Lmac Function Code Showing Comments 0 00 eee eee e eee eee 4 4 Load and Store Instructions That Specify Memory Bank Information 4 5 C Code for Dot Product a 20 ccd hedd er radied ended ced eda gee ine eee ete ee 4 6 Linear Assembly for Dot Product 00 cece eee eet eee aes 4 7 Dot Product Software Pipelined Kernel 00 cece eee eee eens 4 8 Dot Product From Example 4 6 Unrolled to Prevent Memory Bank Conflicts 4 9 Unrolled Dot Product Kernel From Example 4 7 0 00 cece ee 4 10 Using mptr for Indexed Pointers ccc cece eee tenes 4 11 Annotatinga Memory Reference 0 cece eet eens 4 12 Software Pipeline Using mdep Id1 stl 0 cece 4 13 Software Pipeline Using mdep st1 Id1 and mdep Id1 st1_ 0 000 008 5 1 Sample Linker Command File 0 0c cece eee eee eens 6 1 Sample Stand Alone Simulator Banners saaana anrr eee ees 6 2 Passing Options on the Command Line 0 00 c cece cette eens 6 3 Profiling Dot Product Routines 0 0 cece teens 6 4 Code With Clock Function 0 eee eee eae 6 5 Stand Alone Simulator Results After Compiling and Linking Example 6
167. The atan2 and atan2f functions return the inverse tangent of y x The function uses the signs of the arguments to determine the quadrant of the return value Both arguments cannot be 0 The return value is an angle in the range 7 7 radians double rvalu 0 0 rvalv 1 0 radians radians atan2 rvalu rvalv radians 0 0 Run Time Support Functions 9 47 atanh atanhf atanh atanhf Syntax for C Syntax for C Defined in Description Syntax for C Syntax for C Defined in Description 9 48 Hyperbolic Arc Tangent define _TlENHANCED_MATH_H 1 include lt math h gt double atanh double y double x float atanhf float x define _TlENHANCED_MATH_H 1 include lt cmath gt double std atanh double y double x float std atanhf float x atanh c and atanhf c in rts src The atanh and atanhf functions return the hyperbolic arc tangent of a floating point argument x The return value is in the range 1 0 1 0 Register Function Called by Exit include lt stdlib h gt int atexit void fun void include lt cstdlib gt int std atexit void fun void exit c in rts src The atexit function registers the function that is pointed to by fun to be called without arguments at normal program termination Up to 32 functions can be registered When the program exits through a call to the exit function the functions that were registered are called without arguments in reverse
168. URS For more information about using the interlist feature with the optimizer see section 3 11 Using the Interlist feature With the Optimizer on page 3 30 Using the C C Compiler 2 47 2 48 Chapter 3 Optimizing Your Code The compiler tools can perform many optimizations that improve the execution speed and reduce the size of C and C programs by performing tasks such as simplifying loops software pipelining rearranging statements and expressions and allocating variables into registers This chapter describes how to invoke different levels of optimization and describes which optimizations are performed at each level This chapter also describes how you can use the Interlist feature when performing optimization and how you can profile or debug optimized code Topic 3 invoking Optimization e syeyeyyayeye oversees eee ects a 3 2 Optimizing Software Pipelining 00eeseeeee eee e eee SOMME GUMNGalnt Loops a stetetelelaeelsteteteley 3 4 Reducing Code Size ms Option 00 00eeee eee eee 3 5 Performing File Level Optimization O3 Option 3 6 Performing Program Level Optimization pm and O3 Options 00 2 cece eee eee eens 3 7 Indicating Whether Certain Aliasing Techniques Are Used 3 8 Prevent Reordering of Associative Floating Point Operations 3 9 Use Caution With asm Statements in Optimized Code 3 10 Automatic Inline Expansion oi Option
169. VING plus J PPD DPD gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt ENTERING plus KKK KKK KK lt lt lt lt lt lt lt lt lt ccc e lt lt lt lt lt lt lt lt lt lt lt lt LEAVING plus B S2 B3 NOP 4 MVK S1 12 A4 BRANCH OCCURS 3 13 7 Induction Variables and Strength Reduction Induction variables are variables whose value within a loop is directly related to the number of executions of the loop Array indices and control variables for loops are often induction variables Strength reduction is the process of replacing inefficient expressions involving induction variables with more efficient expressions For example code that indexes into a sequence of array elements is replaced with code that increments a pointer through the array Induction variable analysis and strength reduction together often remove all references to your loop control variable allowing its elimination see Example 3 4 on page Optimizing Your Code 3 43 What Kind of Optimization Is Being Performed 3 13 8 Loop Invariant Code Motion This optimization identifies expressions within loops that always compute to the same value The computation is moved in front of the loop and each occurrence of the expression in the loop is replaced by a reference to the precomputed value 3 13 9 Loop Rotation The compiler eva
170. When inside of a cproc region that contains a call statement A4 and A5 cannot be specified in a reserve statement The calling convention mandates that A4 and A5 are used as the return registers for a call statement The reserve in this example guarantees that the assembly optimizer does not use A10 to A13 or B10 to B13 for the variables tmp1 to tmp5 test proc a4 b4 reg tmpl tmp2 tmp3 tmp4 tmp5 reserve al0 all al2 al3 b10 b11 b12 b13 endproc a4 The assembly optimizer may generate less efficient code if the available register pool is overly restricted In addition it is possible that the available register pool is constrained such that allocation is not possible and an error message is generated For example the following code generates an error since all of the conditional registers have been reserved but a conditional register is required for the variable tmp lt GDPEOG sex reserve al a2 b0 b1 b2 reg tmp temp seas endproc Return a Value to a C Callable Procedure return argument The return directive function is equivalent to the return statement in C C code It places the optional argument in the appropriate register for a return value as per the C C calling conventions see section 8 4 on page The optional argument can have the following meanings _j Zero arguments implies a cproc region that has no return value similar to a void function in C C code J An argument im
171. X OPO ise ste wreleccse E ciccniscs bie elev wae ie otis eunsereveisi seca Saco ned 2 9 Generating a Raw Listing File pl Option 2 10 Using Inline Function Expansion c see e eee e eee 2 11 Interrupt Flexibility Options mi Option 5 2 12 Linking C6400 Code With C6200 C6700 Older C6400 Object Code wise ejeitesersies ee eelsincs aie share eels Hs cists se helene Poe WECM ea 2 1 About the Compiler 2 1 2 2 About the Compiler The compiler cl6x allows you to compile assemble and optionally link in one step The compiler performs the following steps on one or more source modules I The compiler which includes the parser and optimizer accepts C C source code and produces C6x assembly language source code You can compile C and C files in a single command The compiler uses the conventions for filename extensions to distinguish between different file types See section Specifying Filenames for more information J The assembler generates a COFF object file 1 The linker combines your object files to create an executable object file The link step is optional so you can compile and assemble many modules independently and link the later See Linking C C Code for information about linking the files in a separate step By default the compiler does not perform the link step You can invoke the linker by using the z compiler option Figure 2 1 illu
172. ZERO LI A4 LDW D2 4 SP 12 B3 NOP 4 B S2 B3 NOP 5 BRANCH OCCURS 3 32 Debugging and Profiling Optimized Code 3 12 Debugging and Profiling Optimized Code Debugging fully optimized code is not recommended because the compiler s extensive rearrangement of code and the many to many allocation of variables to registers often make it difficult to correlate source code with object code Profiling code that has been built with the symdebug dwarf or g option or the symdebug coff option STABS debug is not recommended as well because these options can significantly degrade performance To remedy these problems you can use the options described in the following sections to optimize your code in such a way that you can still debug or profile the code 3 12 1 Debugging Optimized Code symdebug dwarf symdebug coff and O Options To debug optimized code use the O option in conjunction with one of the symbolic debugging options symdebug dwarf or symdebug coff The symbolic debugging options generate directives that are used by the C C source level debugger but they disable many compiler optimizations When you use the O option which invokes optimization with the symdebug dwarf or symdebug coff option you turn on the maximum amount of optimization that is compatible with debugging If you are having trouble debugging loops in your code you can use the mu option to turn off software pi
173. _device mydevice MSA my_open my_close my_read my_write my_lseek my unlink my_rename fid fopen mydevice test w fprintf fid Hello world n fclose fid 9 8 Syntax for C Syntax for C Description Return Value close Close File or Device For I O include lt stdio h gt include lt file h gt int close int file_descripton include lt cstdio gt include lt file h gt int std close int file_descripton The close function closes the device or file associated with file_descriptor The file_descriptor is the stream number assigned by the low level routines that is associated with the opened device or file The return value is one of the following 0 if successful 1 if fails Run Time Support Functions 9 9 Iseek Syntax for C Syntax for C Description Return Value Set File Position Indicator include lt stdio h gt include lt file h gt long Iseek int file_descriptor long offset int origin include lt cstdio gt include lt file h gt long std lseek int file_descriptor long offset int origin The Iseek function sets the file position indicator for the given file to origin offset The file position indicator measures the position in characters from the beginning of the file J The file_descriptor is the stream number assigned by the low level routines that the device level driver must associate with the opened file or device
174. a loop that can be interrupted and still generate correct results single assignment code which in most cases degrades the performance of the loop The min option does not comprehend the effects of the memory system When determining the maximum number of execution cycles for a loop the compiler does not compute the effects of using slow off chip memory or memory bank conflicts It is recommended that a conservative threshold value is used to adjust for the effects of the memory system See section 7 7 7 The FUNC_INTERRUPT_THRESHOLD Pragma on page 7 24 or the TMS320C6000 Programmer s Guide for more information Using the C C Compiler 2 43 Interrupt Flexibility Options mi Option 2 44 Note RTS Library Files Are Not Built With mi Option The run time support library files provided with the compiler are not built with the interrupt flexibility option Please refer to the readme file to see how the run time support library files were built for your release See Library Build Utility to build your own run time support library files with the interrupt flexibility option Note Special Cases With the mi Option The miO option generates the same code to disable interrupts around software pipelined loops as when the mi option is not used The mi option the threshold value is omitted means that no code is added to disable interrupts around software pipelined loops Also loop performance does not degrade becau
175. abled and the prototype is declared as static inline only if _INLINE is true _INLINE is automatically defined for you when the optimizer is used and pi is not specified The second definition for the library ensures that the callable version of strlen exists when inlining is disabled Since this is not an inline function the _INLINE preprocessor symbol is undefined undef before string h is included to generate a noninline version of strlen s prototype Using Inline Function Expansion Example 2 2 How the Run Time Support Library Uses the _INLINE Preprocessor Symbol a string h BRK KK KR KK RK RK RK RR KK KK KK RK I RRR RRR RK RRR k k k k k k string h vx xx Copyright c 1993 1999 Texas Instruments Incorporated Excerpted BRK KK KK RK RK KKK RK RK RK KR I KK RRR I k k RR k k k k k k KR RR k k k k k ifdef INLINE define IDECL static inline else define _IDECL extern _CODE ACCESS endif _IDECL size_t strlen const char _ string Gl ifdef _INLINI S EEEk KKK k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k A kkk k RR KR RK RR strlen EAk kkk kkk kkk kkk kkk kkk kkk kkk kkk kkk kkk kk kkk kkk kkk kkk kkk kkk kk kkk kkk kkk kkk kkk kkk static inline size_t strlen const char string size_t n size_t 1 const char s string 1 do n while s return n endif b strlen c BO
176. alization Records in the cinit Section Format of Initialization Records in the pinit Section Autoinitialization at Run Time Initialization at Load TIME kk cette tenn ete n teen eens Interaction of Data Structures in I O Functions The First Three Streams in the Stream Table l P P PP o O o O o o P Ea o o E NH HSH OAONOOARPWNH NH NH H Contents xvii Tables 2 1 Compiler Options Summary 2 000 cece eee teenies 2 2 Compiler Backwards Compatibility Options Summary 00000 cece eee eee 2 3 Predefined Macro NameS 2 00c cece eee tee moeda tandiu Piave Wi Riy aiani 2 4 Raw Listing File Identifiers 0 cece ete 2 5 Raw Listing File Diagnostic Identifiers ccc cece eee eee eee 3 1 Options That You Can Use With O3 0 tenet neeees 3 2 Selecting a Level for the ol Option 00 0 cece cece tenes 3 3 Selecting a Level for the on Option 000s 3 4 Selecting a Level for the op Option 0c ccc eects 3 5 Special Considerations When Using the op Option 0002 cece eee eee 4 1 Assembly Optimizer Directives Summary 000 cece nett es 5 1 Sections Created by the Compiler 0c cee n teeta 7 1 TMS320C6000 C C Data Types 0 cent eee eee 7 2 Valid Control Registers 0 0 2 0 cbass tid ekidno a Aini iinne 8 1 Data Representation in Registers and Memory 1 eee 8 2 Register Usage se
177. alized has an initialization record in the cinit section Example 8 9 a shows initialized global variables defined in C Example 8 9 b shows the corresponding initialization table The section cinit c is a subsection in the cinit section that contains all scalar data The subsection is handled as one record during initialization which minimizes the overall size of the cinit section Run Time Environment 8 53 System Initialization Example 8 9 Initialization Table a Initialized variables defined in C int x short i 23 int p amp x int a 5 1 2 3 4 5 b Initialized information for variables defined in a global x bss _x 4 4 sect m ginit g align 8 field CIR 8 32 field _i 0 32 field 23 16 i o sect text global i i usect bss c 2 2 sect w Cane ee align 4 field x32 p o sect text global p Pp usect bss c 4 4 sect Cane align 8 field IR 1 32 ield _a 0 32 field 15 32 _al0 field 2 32 afl field 3 32 z alzi field 4 32 _al3 field 5 32 _al4 IR_1 set 20 32 64 96 128 00000 sect text global a bss _a 20 4 PRR RRR k k k k k RR k k KKK KKK KKK KERR k RK k k RK KKK k k k k k k KK k k k k k KK k k k k k k k k k k k KKK k k k KK MARK THE END OF THE SCALAR INIT RECORD IN CINIT C p RRR RRR KR k k k k k k KR KK KKK KKK KKK RRR KKK KK RK KKK k k k RK RK k k k KR
178. alls to far _j ml2 defaults all aggregate data and calls to far J ml3 defaults all data and calls to far If no level is specified all data and functions default to near Near data is accessed via the data page pointer more efficiently while near calls are executed more efficiently using a PC relative branch Use these options if you have too much static and extern data to fit within a 15 bit scaled offset from the beginning of the bss section or if you have calls where the called function is more than 1M words away from the call site The linker issues an error message when these situations occur See section 7 4 4 The near and far Keywords on pagg 7 11 And section 8 1 5 Memory Models on page 8 6 for more information Selects the target CPU version For more information about the mv option see page Produce verbose software pipelining report Compiles or assembly optimizes only The specified source files are compiled or assembly optimized but not assembled or linked This option overrides z The output is assembly language output from the compiler Suppresses banners and progress information from all the tools Only source filenames and error messages are output Changing the Compiler s Behavior With Options S Invokes the interlist feature which interweaves optimizer comments or C C source with assembly source If the optimizer is invoked On option optimizer comments are interlisted with the assemb
179. an2f float y float x float atanf float x double atanh double x float atanhf float x double ceil double x float ceilf float x double cos double x float cosf float x double cosh double x float coshf float x double cot double x Description Returns the arc cosine of x Returns the arc cosine of x Returns the hyperbolic arc cosine of x t Returns the hyperbolic arc cosine of x t Returns the arc cotangent of x t Returns the arc cotangent of x y t Returns the arc cotangent of x y t Returns the arc cotangent of x t Returns the hyperbolic arc cotangent of x t Returns the hyperbolic arc cotangent of x t Returns the arc sine of x Returns the arc sine of x Returns the hyperbolic arc sine of x t Returns the hyperbolic arc sine of x t Returns the arc tangent of x Returns the arc tangent of y x Returns the arc tangent of y x Returns the arc tangent of x Returns the hyperbolic arc tangent of x t Returns the hyperbolic arc tangent of x t Returns the smallest integer 2 x expands inline except when pi is used Returns the smallest integer x expands inline except when pi is used Returns the cosine of x Returns the cosine of x Returns the hyperbolic cosine of x Returns the hyperbolic cosine of x Returns the cotangent of x t T Enhanced math function See section 9 3 10 on page 9 22 for information on accessing this function Run Time Support Functions S S amp Q NI ore ka a
180. and exp such that 5 lt f lt 1 and value 9 65 double Idexp double x int exp float Idexpf float x int exp double log double x Returns the natural logarithm of x 9 72 double log10 double x Returns the base 10 logarithm of x 9 72 float log10f float x Returns the base 10 logarithm of x double log2 double x Returns the base 2 logarithm of x t float log2f float x Returns the base 2 logarithm of x t 9 72 float logf float x Returns the natural logarithm of x 9 72 is equal to f x 2 xP Returns x x 2 amp XP Returns x x 2 amp XP T Enhanced math function See section 9 3 10 on page 9 22 for information on accessing this function 9 32 Pri N IN PEN Summary of Run Time Support Functions and Macros c Floating point math functions math h cmath Continued Function double modf double value double ip float modff float value float ip double pow double x double y float powf float x float y double powi double x int y float powif float x int y double round double x float roundf float x double rsqrt double x float rsqrtf float x double sin double x float sinf float x double sinh double x float sinhf float x double sqrt double x float sqrtf float x double tan double x float tanf float x double tanh double x float tanhf float x double trunc double x float truncf float x Description Page Breaks value into a signed integer and a signed
181. and line defined linker comments defined in linear assembly source code linear assembly common logarithm functions compare strings functions any number of characters in entire string compatibility with K amp R C compiler Compiler Consultant Advice tool defined described 2 1 2 48 diagnostic messages 2 3142 34 diagnostic options 2 33 3 34 frequently used options 2 15 2 18 invoking optimizer 3 243 4 options assembler compiler conventions deprecated input file extension input files linker optimizer output files parser profiling summary 2 6 24 2 9 overview 1 5 8 2 2 preprocessor options 2 2942 30_ sections __COMPILER_VERSION__ macro compiling C C code after preprocessing compile only overview commands and options 2 2 2 3 with the optimizer 3 243 4 concatenate strings functions any number of characters entire string const keyword const section allocating in memory described constant accessing assembler constants from C C 8 45 C language character strings defined escape sequences in character constants string consultant compiler option Index control registers accessing from C C 7 8 control flow simplification controlling diagnostic messages 2 33 2 34 conventions function calls notational register conversions C language described convert 9 108 case function long integer
182. any ad options for the specified constant ax Invokes the assembler with the x assembler option to produce a symbolic cross reference in the listing file For more information about assembler options see the TMS320C6000 Assembly Language Tools User s Guide 2 3 9 Deprecated Options Several compiler options have been deprecated The compiler continues to accept these options but they are not recommended for use Future releases of the tools will not support these options Table 2 2 lists the deprecated options and the options that have replaced them Table 2 2 Compiler Backwards Compatibility Options Summary 2 24 Old Option Effect New Option gp Allows function level profiling of optimized code g gt Enables symbolic debugging using the alternate symdebug coff STABS debugging format gw Enables symbolic debugging using the DWARF symdebug dwarf debugging format or g Additionally the symdebug profile_coff option has been added to enable function level profiling of optimized code with symbolic debugging using the STABS debugging format the symdebug coff or gt option Setting Default Compiler Options C_OPTION and C_C6X_OPTION 2 4 Setting Default Compiler Options C_OPTION and C_C6X_OPTION You might find it useful to set the compiler assembler and linker default options using the C_OPTION or C6X_C_OPTION environment variable If you do this the compiler uses the default options and or input file
183. ap routine Chapter 9 describes additional run time support functions that are included in the library These functions include ISO C standard run time support a aaa Note The _c_int00 Symbol One important function contained in the run time support library is _c_intOO The symbol _c_int00 is the starting point in boot obj if you use the c or cr linker option _c_int0O is automatically defined as the entry point for the program If your program begins running from reset you should set up the reset vector to branch to _c_int00 so that the processor executes boot obj first eee eee eee sss Linking C C Code 5 9 Controlling the Linking Process 5 3 3 Global Object Constructors Global C variables having constructors and destructors require their constructors to be called during program initialization and their destructors to be called during program termination The C C compiler produces a table of constructors to be called at startup The table is contained in a named section called pinit The constructors are invoked in the order that they occur in the table Global constructors are called after initialization of other global variables and before main is called Global destructors are invoked during exit similar to functions registered through atexit Section 8 8 3 Initialization Tables on page 8 53 discusses the format of the pinit table 5 3 4 Specifying the Type of Initialization 5 10 The
184. as a a a a a a es AE a a a a a a a a a Seti et pF pene oases Se poses FEAR PEOR a jana PEN ar PENE E E E FREER S ETS PO EE E PERPE EN PEN L2 LDW D2T2 B4 B0 8 ME aa eee ee ee Sat en eed ee eats Ss Sasa SSeS Se eae ee See Sees E _ L3 NOP 4 BO B rsi L7 del NOP 4 BO LDW D2T2 B4 B0 10 BRANCH OCCURS 8 pF ae a a a penny ee ra PEEN Ss et i E a pe et a n a LDW D2T2 B4 B0 2 NOP 4 BO B S1 L3 i 9 NOP 4 BO LDW D2T2 B4 B0 8 BRANCH OCCURS 9 pe Ha aa aa ae ee a a aaa ras se n dea as ase as ra a a a ae a a a a at se aos eK L5 LDW D2T2 B4 B0 10 pe i a a aa at eas Ra a as a eat a a a a a a a a aa D A aai a ee a a a e a a a a aK Le pF a E res os a eer Pe et NN eg eer at Ne Ren nd aCe fea Tn ee oS ei L7 NOP 4 BO B S1 L6 10 NOP 4 Bo LDW D2T2 B4 B0 10 BRANCH OCCURS 10 pe ee a oS eae Se a Se a Sas ee se Steers a Se ete a eal ee Ss Se ee Se a a _ S2 B3 12 NOP 5 BRANCH OCCURS 12 3 40 What Kind of Optimization Is Being Performed 3 13 4 Data Flow Optimizations Collectively the following data flow optimizations replace expressions with less costly ones detect and remove unnecessary assignments and avoid operations that produce values that are already computed The compiler with optimization enabled performs these data flow optimizations both locally within basic blocks and globally across entire functions
185. ase is to pass the address of an offset from an array for example f amp buffer 3 This code passes an unaligned address to ptr thus violating the presumption coded in the _nassert There is no direct remedy for this case Avoid this practice whenever possible Run Time Environment 8 39 Interfacing C and C With Assembly Language 8 5 5 3 Dynamic Memory Allocation Ordinary dynamic memory allocation does not guarantee that the address of the buffer is aligned for example buffer malloc 100 sizeof short You should use memalign with an alignment of 8 instead for example buffer memalign 8 100 sizeof short If you are using BIOS memory allocation routines be sure to pass the alignment factor as the last argument using the syntax that follows buffer MEM_alloc segid 100 sizeof short 8 See the TMS320C6000 DSP BIOS Help for more information about BIOS memory allocation routines and the segid parameter in particular 8 5 5 4 Member of a Structure or Class Arrays which are members of a structure or a class are aligned only as the base type of the array requires The automatic alignment described in section 8 5 5 1 Base Address of an Array does not occur Example 8 4 An Array in a Structure struct s short buf1 50 bgp g bufl Example 8 5 An Array in a Class 8 40 class c public short buf1 50 void mfunc void Jz void c mfunc f buf1
186. assembly optimizer allows you to write linear assembly code without being concerned with the pipeline structure or with assigning registers It accepts assembly code that has not been register allocated and is unscheduled The assembly optimizer assigns registers and uses loop optimization to turn linear assembly into highly parallel assembly that takes advantage of software pipelining See Using the Assembly Optimizer for information about invoking the assembly optimizer writing linear assembly code sa files specifying functional units and using assembly optimizer directives The C C compiler accepts C C source code and produces C6000 assembly language source code A compiler optimizer and an interlist feature are parts of the compiler m The compiler enables you to compile assemble and link source modules in one step If any input file has a sa extension the compiler program invokes the assembly optimizer E The optimizer modifies code to improve the efficiency of C programs m The interlist feature interweaves C C source statements with assembly language output See Using the C C Compiler for information about how to invoke the C C compiler the optimizer and the interlist feature using the compiler program The assembler translates assembly language source files into machine language object files The machine language is based on common object file format COFF The TMS320C6000 Assembly Language Tools User s
187. at fmodf float x float y include lt cmath gt double std fmod double x double y float std fmodf float x float y fmod c and fmodf c in rts src The fmod and fmodf functions return the exact floating point remainder of x divided by y If y 0 the function returns 0 The functions are equivalent mathematically to x trunc x y x y but not to the C expression written the same way For example fmod x 3 0 is 0 0 1 0 or 2 0 for any small integer x gt 0 0 When x is large enough that x y can no longer be expressed exactly fmod x 3 0 continues to yield correct answers while the C expression returns 0 0 for all values of x double x yY TY x y r De Je 5 07 fmod x y fmod returns 1 0 Open File include lt stdio h gt FILE fopen const char _ fname const char _mode include lt cstdio gt FILE std fopen const char _fname const char _mode fopen c in rts src The fopen function opens the file that _fname points to The string pointed to by _mode describes how to open the file Syntax for C Syntax for C Defined in Description Syntax for C Syntax for C Defined in Description Syntax for C Syntax for C Defined in Description fputs Write Stream include lt stdio h gt int fprintf FILE _fp const char _ format include lt cstdio gt int std fprintf FILE _fp const char _ format fprint c in rts src The fprintf
188. at is made up entirely of characters that are not in chs Page Maps the error number in errno to an error message string Returns the length of a string Appends up to n characters from src to dest Compares up to n characters in two strings expands inline except when pi is used Copies up to n characters from src to dest 9 100 expands inline except when pi is used Locates the first occurrence in string of any 9 101 character from chs Finds the last occurrence of character c in string 9 101 expands inline except when pi is used Returns the length of the initial segment of string 9 102 which is entirely made up of characters from chs Finds the first occurrence of string2 in string1 Breaks str1 into a series of tokens each delimited 9 104 by a character from str2 Transforms n characters from from to to Run Time Support Functions 9 39 Summary of Run Time Support Functions and Macros i Time support functions time h ctime Function char asctime const struct tm timeptr clock_t clock void char ctime const time_t timer double difftime time_t time1 time_t time0 struct tm gmtime const time_t timer structtm localtime const time_t timer time_t mktime struct tm tptr size_t strftime char out size_t maxsize const char format const struct tm time time_t time time_t timer 9 40 Description Converts a time to a string Determines the processor time used
189. ate an optimization information file that you can read The number following the on denotes the level 0 1 or 2 The resulting file has an nfo extension Use Table 3 3 to select the appropriate level to append to the on option Table 3 3 Selecting a Level for the on Option If you Use this option Do not want to produce an information file but you used the on1 on0 or on2 option in a command file or an environment variable The on0 option restores the default behavior of the optimizer Want to produce an optimization information file on1 Want to produce a verbose optimization information file on2 Optimizing Your Code 3 19 Performing Program Level Optimization pm and O3 Options 3 6 Performing Program Level Optimization pm and 03 Options 3 20 You can specify program level optimization by using the pm option with the O3 option With program level optimization all of your source files are compiled into one intermediate file called a module The module moves to the optimization and code generation passes of the compiler Because the compiler can see the entire program it performs several optimizations that are rarely applied during file level optimization Lj If a particular argument in a function always has the same value the compiler replaces the argument with the value and passes the value instead of the argument QJ Ifa return value of a function is never used the compiler deletes the re
190. ates register saves based on the rules for interrupt functions and the special return sequence for interrupts You can only use the interrupt keyword with a function that is defined to return void and that has no parameters The body of the interrupt function can have local variables and is free to use the stack or global variables For example interrupt void int_handler unsigned int flags The name c_int00 is the C C entry point This name is reserved for the system reset interrupt This special interrupt routine initializes the system and calls the function main Because it has no caller c_int00 does not save any registers Use the alternate keyword __ interrupt if you are writing code for strict ISO mode using the ps compiler option Keywords 7 4 4 The near and far Keywords The C6000 C C compiler extends the C C language with the near and far keywords to specify how global and static variables are accessed and how functions are called Syntactically the near and far keywords are treated as storage class modifiers They can appear before after or in between the storage class specifiers and types With the exception of near and far two storage class modifiers cannot be used together in a single declaration The following examples are legal combinations of near and far with other storage class modifiers far static int x static near int x static int far x far int foo static far int foo 7 4
191. ation entry point A point in target memory where execution starts environment variable A system symbol that you define and assign to a string Environmental variables are often included in batch files for example cshrc epilog The portion of code in a function that restores the stack and returns See also pipelined loop epilog executable module A linked object file that can be executed in a target system Glossary A 3 Glossary A 4 expression A constant a symbol or a series of constants and symbols separated by arithmetic operators external symbol A symbol that is used in the current program module but defined or declared in a different program module file level optimization A level of optimization where the compiler uses the information that it has about the entire file to optimize your code as opposed to program level optimization where the compiler uses information that it has about the entire program to optimize your code function inlining The process of inserting code for a function at the point of call This saves the overhead of a function call and allows the optimizer to optimize the function in the context of the surrounding code global symbol A symbol that is either defined in the current module and accessed in another or accessed in the current module but defined in another hex conversion utility A utility that converts COFF object files into one of several standard ASCII hexadecimal forma
192. ax for C Defined in Description trunc truncf Syntax for C Syntax for C Defined in Description Example 9 108 Convert Case include lt ctype h gt int tolower int c int toupper int c include lt cctype gt int std tolower int c int std toupper int c tolower c and toupper c in rts src These functions convert the case of a single alphabetic character c into uppercase or lowercase Lj The tolower function converts an uppercase argument to lowercase If c is already in lowercase tolower returns it unchanged Q The toupper function converts a lowercase argument to uppercase If c is already in uppercase toupper returns it unchanged The functions have macro equivalents named _tolower and _ toupper Truncate Toward 0 define _Tl ENHANCED_ MATH_H 1 include lt math h gt double trunc double x float truncf float x define _TlENHANCED_MATH_H 1 include lt cmath gt double std trunc double x float std truncf float x trunc c and truncf c in rts src The trunc and truncf functions return a floating point number equal to the nearest integer to x in the direction of 0 float x y U V x 2 35 y truncf x y 2 u 5 65 v truncf v v 5 Syntax for C Syntax for C Defined in Description va_arg va_end va_start Syntax for C Syntax for C Defined in Description va_arg va_end va_start Write Character to Str
193. ber of cycles required to run the code Use printf statements to display your data to the screen Example 6 4 shows an example of the C code for accomplishing this Example 6 4 C Code With Clock Function include lt stdio h gt include lt time h gt main clock t start clock _t overhead clock _t elapsed Calculate the overhead from calling clock clock clock start start overhead Calculate the elapsed time start clock puts Hello world elapsed clock start overhead printf Time ld cycles n long elapsed To compile and link the code in Example 6 4 enter the following text on the command line The z option invokes the linker I linker option names a linker command file and the o linker option names the output file cl6x clock c z 1 1nk60 cmd o clock out To run the stand alone simulator on the resulting executable COFF file enter load6x clock out Example 6 5 Stand Alone Simulator Results After Compiling and Linking Example 6 4 6 10 TMS320C6x Standalone Simulator Version x xx Copyright c 1989 2000 Texas Instruments Incorporated Interrupt to abort Hello world Time 3338 cycles NORMAL COMPLETION 11692 cycles Chapter 7 TMS320C6000 C C Language Implementation The TMS320C6000 C C compiler supports the C C language standard that was developed by a committee of the American National Standards In
194. bit i e you were performing saturated arithmetic when interrupted into the C interrupt service routine which may also perform some saturated arithmetic in your C interrupt service routine it can be done in a similar way as the above example using the SAVE_SAT and RESTORE_SAT macros 8 6 3 Using Assembly Language Interrupt Routines You can handle interrupts with assembly language code as long as you follow the same register conventions the compiler does Like all assembly functions interrupt routines can use the stack access global C C variables and call C C functions normally When calling C C functions be sure that any registers listed in Table 8 2 on page 8 18 are saved because the C C function can modify them Run Time Environment 8 47 Run Time Support Arithmetic Routines 8 7 Run Time Support Arithmetic Routines The run time support library contains a number of assembly language functions that provide arithmetic routines for C C math operations that the C6000 instruction set does not provide such as integer division integer remainder and floating point operations These routines follow the standard C C calling sequence The compiler automatically adds these routines when appropriate they are not intended to be called directly by your programs The source code for these functions is in the source library rts src The source code has comments that describe the operation of the functions You can extract inspec
195. bits aligned to boundary of largest member type members are stored and aligned as their individual types require Members are stored as their individual types require aligned to 64 bit boundary for C64x aligned to 32 bit boundary for all types 32 bits and smaller and to 64 bit boundary for all types larger than 32 bits for C62x and C67x All arrays inside a structure are aligned according to the type of each element in the array Object Representation Table 8 1 Data Representation in Registers and Memory Continued Data Type Register Storage Memory Storage pointer to data member Bits 0 31 of register 32 bits aligned to 32 bit boundary pointer to member function Components stored as their individual 64 bits aligned to 32 bit boundary types require 8 2 1 1 char and short Data Types signed and unsigned The char and unsigned char data types are stored in memory as a single byte and are loaded to and stored from bits 0 7 of a register see Figure 8 1 Objects defined as short or unsigned short are stored in memory as two bytes and are loaded to and stored from bits 0 15 of a register see Figure 8 1 In big endian mode 2 byte objects are loaded to registers by moving the first byte that is the lower address of memory to bits 8 15 of the register and moving the second byte of memory to bits 0 7 In little endian mode 2 byte objects are loaded to registers by moving the first byte that is the lower address of memory to bits
196. c in rts src The fgetpos function stores the object pointed to by pos to the current value of the file position indicator for the stream pointed to by _ fp Syntax for C Syntax for C Defined in Description floor floorf Syntax for C Syntax for C Defined in Description Example floor floorf Read Next Characters include lt stdio h gt char fgets char _ptr register int _size register FILE _fp include lt cstdio gt char std fgets char _ptr register int _size register FILE _fp fgets c in rts src The fgets function reads the specified number of characters from the stream pointed to by _fp The characters are placed in the array named by _ ptr The number of characters read is _ size 1 Floor include lt math h gt double floor double x float floorf float x include lt cmath gt double std floor double x float std floorf float x floor c and floorf c in rts src The floor and floorf functions return a floating point number that represents the largest integer less than or equal to x double answer floor 3 1415 floor 3 5 3 0 4 0 answer answer Run Time Support Functions 9 61 fmod fmodf fmod fmodf Syntax for C Syntax for C Defined in Description Example Syntax for C Syntax for C Defined in Description 9 62 Floating Point Remainder include lt math h gt double fmod double x double y flo
197. case you need to note the dependence relation in both directions and you need to use both directives mdep tdi sti mdep sti ldl Using the Assembly Optimizer 4 45 Memory Alias Disambiguation 4 6 5 Memory Alias Examples 4 46 Following are memory alias examples that use the mdep and no_mdep directives Lj Example 1 The mdep r1 r2 directive declares that LDW must be before STW In this case src and dst might point to the same array fn cproc dst sre ent reg tmp no_mdep mdep ri E2 LDW src ri tmp STW ent dst r2 return tmp endproc Lj Example 2 Here mdep r2 r1 indicates that STW must occur before LDW Since STW is after LDW in the code the dependence relation is across loop iterations The STW instruction writes a value that may be read by the LDW instruction on the next iteration In this case a 6 cycle recurrence is created fn cproc dst sre ent reg tmp no_mdep mdep E27 EL LOOP trip 100 LDW srct r1 tmp STW tmp dst r2 cnt SUB ent 1 ent cnt B LOOP endproc Te Note Memory Dependence Bank Conflict Do not confuse the topic of memory alias disambiguation with the handling of memory bank conflicts They may seem similar because they each deal with memory references and the effect of those memory references on the instruction schedule Alias disambiguation is a correctness issue bank conflicts are a performance issue A memory dependence has a much broader i
198. cesses to a single bank in a given cycle result in a memory stall that halts all pipeline operation for one cycle while the second value is read from memory Two memory operations per cycle are allowed without any stall as long as they do not access the same bank Figure 4 1 4 Bank Interleaved Memory For devices that have more than one memory space Figure 4 2 an access to bank 0 in one memory space does not interfere with an access to bank 0 in another memory space and no pipeline stall occurs Using the Assembly Optimizer 4 33 Avoiding Memory Bank Conflicts With the Assembly Optimizer Figure 4 2 4 Bank Interleaved Memory With Two Memory Spaces 4 5 1 4 34 Memory space 0 Memory space 1 Bank 0 Bank 1 Bank 2 Bank 3 Preventing Memory Bank Conflicts The assembly optimizer uses the assumptions that memory operations do not have bank conflicts If it determines that two memory operations have a bank conflict on any loop iteration it does not schedule the operations in parallel The assembly optimizer checks for memory bank conflicts only for those loops that it is trying to software pipeline The information required for memory bank analysis indicates a base an offset a stride a width and an iteration delta The width is implicitly determined by the type of memory access byte halfword word or double word for the C6400 and C6700 The iteration
199. ches the comments on instructions from the input linear assembly to the output file It attaches the 2 tuple lt x y gt to the comments to specify which iteration and cycle of the loop an instruction is on in the software pipeline The zero based number x represents the iteration the instruction is on during the first execution of the kernel The zero based number y represents the cycle the instruction is scheduled on within a single iteration of the loop See section 4 3 4 Using Linear Assembly Source Comments on page 4 11 fpr an illustration of the use of source comments and the resulting assembly optimizer output What You Need to Know to Write Linear Assembly 4 3 1 Linear Assembly Source Statement Format A source statement can contain five ordered fields label mnemonic unit specifier operand list and comment The general syntax for source statements is as follows abel register mnemonic unit specifie operand list comment label register mnemonic unit specifier operand list comment Labels are optional for all assembly language instructions and for most but not all assembly optimizer directives When used a label must begin in column 1 of a source statement A label can be followed by a colon Square brackets enclose conditional instructions The machine instruction mnemonic is executed based on the value of the register within the brackets valid register names are AO for
200. compiler makes about the IRP and AMR control registers The assumptions should be enforced in all programs and are as follows 1 The AMR must be set to 0 upon calling or returning from a function A function does not have to save and restore the AMR but must ensure that the AMR is 0 before returning The AMR must be set to 0 when interrupts are enabled or the SAVE_AMR and STORE_AMR macros should be used in all interrupts see section 8 6 2 The IRP can be safely modified only when interrupts are disabled The IRP s value must be saved and restored if you use the IRP as a temporary register Interfacing C and C With Assembly Language 8 5 8 Using Inline Assembly Language Within a C C program you can use the asm statement to insert a single line of assembly language into the assembly language file created by the compiler A series of asm statements places sequential lines of assembly language into the compiler output with no intervening code For more information see section 7 6 The asm Statement on page 7 17 The asm statement is useful for inserting comments in the compiler output Simply start the assembly code string with a semicolon as shown below asm this is an assembly language comment Note Using the asm Statement Keep the following in mind when using the asm statement m m Be extremely careful not to disrupt the C C environment The compiler does not check or analyze t
201. compiler option q library build utility option 10 4 q linker option q stand alone simulator option qsort function Index 16 r linker option r stand alone simulator option raise to a power functions rand function RAND_MAX macro random integer functions raw listing file generating with pl option identifiers read character functions multiple characters next character function 9 67 9 68 single character stream functions from standard input 9 87 from string to arra read function read I O function realloc function 8 59 78 change heap size reversing reciprocal square root functions reducing code size redundant loops defined described reg assembly optimizer directive rega assembly optimizer directive regb assembly optimizer directive register parameters compiling register storage class register variables compiling optimizations 3 4413 46 registers accessing control registers from Cic 7 8 a26 4 28 allocation conventions 8 17 18 live in live out partitioning in linear assembl saving during interrupts use in interrupts related documentation y vi relaxed ANSI mode relaxed ISO mode relocation defined remarks remove function removing epilogs aggressively rename function rename I O function reserve a register in linear assembly reserve assembly optimizer directive restrict keyword return a value to C C callable
202. cribed summary of functions stdout macro storage class defined store object function strcat function strchr function strcmp function 9 93 strcoll function strcpy function 9 94 strcspn function strength reduction optimization strerror function strftime function strict ANSI mode strict ISO mode string constants 7 37 string functions 9 26 9 38 break into tokens 9 104 compare any number of characters entire string conversion 9 103 string error string h header described summary of functions strlen function strncat function strncmp function strncpy function 9 10 strpbrk function 9 10 strrchr function 9 101 strspn function strstr function 0 strtod function 9 103 strtok function strtol function 9 103 strtoll function 9 103 strtoul function 9 103 strtoull function STRUCT_ALIGN pragma struct_tm data type structure defined structure members 7 strxfrm function 9 10 STYP_CPY flag suppressing diagnostic messages switch section allocating in memory described symbol defined symbol table creating labels defined symbolic cross reference in listing file symbolic debugging defined disabling minimal default 1 Ke O N Ke a EH k g D ol Index symbolic debugging continued using DWARF format using STABS format symbols case sensitivity symdebug coff compiler option 2 18 symdebug dwarf compiler option symdebug none
203. cs in C C source to directly call an assembly language statement see section 8 5 2 on page Use inline assembly language embedded directly in the C C source see section 8 5 8 on page Use assembly language variables and constants in C C source see section 8 5 9 on page 8 5 1 Using Assembly Language Modules With C C Code Interfacing C C with assembly language functions is straightforward if you follow the calling conventions defined in section 8 4 Function Structure and Calling Conventions on page and the register conventions defined in section 8 3 Register Conventions on page C C code can access variables and call functions defined in assembly language and assembly code can access C C variables and call C C functions Follow these guidelines to interface assembly language and C Lj All functions whether they are written in C C or assembly language must follow the register conventions outlined in section 8 3 Register Conventions on page You must preserve registers A10 to A15 B3 and B10 to B15 and you may need to preserve A3 If you use the stack normally you do not need to explicitly preserve the stack In other words you are free to use the stack inside a function as long as you pop everything you pushed before your function exits You can use all other registers freely without preserving their contents Interrupt routines must save all the registers they use For more information see section 8 6
204. ction Index 17 Index setjmp macro setjmp h header described summary of functions and macros setvbuf function shell program See compiler shift 7 3 signed integer and fraction functions SIMD using _nassert to enable sin function sine functions sinf function sinh function sinhf function size_t size_t data type small memory model _SMALL_MODEL macro software development tools overview 1 2 4 software Avene defined descriction 13 41 15 disabling information sort array function source file defined extensions specify trip count in linear assembly specifying functional units in linear assembly 4 6 specifying registers in linear assembly sprintf function sqrt function sqrtf function square root functions srand function ss compiler option sscanf function STABS debugging format stack pointer 8 4 reserved space stack linker option Index 18 stack section allocating in memory 5 11 described Poe using stand alone simulator 6 12 defined invoking options passing arguments to a program 6 6 6 7 profiling capability reserving target memory to store arguments stand alone preprocessor defined static variable defined initializing stdarg h header described summary of macros 9 34 __STDC__ macro 2 27 stddef h header stden macro stdexcept include file stdin macro stdint h header stdio h header described summary of functions 9 34 9 36 stdlib h header des
205. ctive pair Here is an example in which mdep is used to indicate a dependence between two memory references mdep ldl stl LDW pl 1ld1 inpl name memory reference 1d1 other code STW outp2 p2 st1 name memory reference st1 Avoid Memory Bank Conflicts mptr register symbol base offset stride The mptr directive associates a register with the information that allows the assembly optimizer to determine automatically whether two memory operations have a memory bank conflict If the assembly optimizer determines that two memory operations have a memory bank conflict then it does not schedule them in parallel A memory bank conflict occurs when two accesses to a single memory bank in a given cycle result in a memory stall that halts all pipeline operation for one cycle while the second value is read from memory For more information on memory bank conflicts including how to use the mptr directive to prevent them see section 4 5 on page 4 33 Using the Assembly Optimizer 4 21 mptr Example 4 22 Following are descriptions of the mptr directive parameters registesymbol The name of the register or the symbol used to name a specific memory reference base A symbol that associates related memory accesses offset The offset in bytes from the starting base symbol The offset is an optional parameter and defaults to 0 stride The register loop increment in bytes The stride is an
206. d for each loop The mw option adds additional information displaying the register usage at each cycle of the loop kernel and displays the instruction ordering of a single iteration of the software pipelined loop Note More Details on Software Pipelining Information Refer to or Appendix Al of the TMS320C6000 Programmer s Guide for details on all the information and messages that can appear in the Software Pipelining Information comment block before each loop Optimizing Your Code 3 5 Optimizing Software Pipelining Example 3 1 Software Pipelining Information SOFTWARE PIPELINE INFORMATION Known Minimum Trip Count Known Maximum Trip Count Known Max Trip Count Factor Loop Carried Dependency Bound Unpartitioned Resource Bound Partitioned Resource Bound Resource Partition A side B side L units 2 3 S units 4 4 D units 1 0 M units 0 0 X cross paths 1 3 T address paths 1 0 Long read paths 0 0 Long write paths 0 0 Logical ops LS 0 Addition ops LSD 6 Bound L S LS 3 4 Bound L S D LS LSD 5 OP BFNMNN ND L or S unit 3 L or S or D unit 4 schedule at Searching for software pipeline ii 5 Register is live too ii 6 Did not find schedule ii 7 done Epilog not entirely removed Collapsed epilog stages I Prolog not removed Collapsed prolog stages s0 Minimum required memory pad 2 Minimum safe trip count 2 long Schedule fo
207. d s2 size_t n include lt cstring gt void std memmove void s1 const void s2 size_t n memmove c in rts src The memmove function moves n characters from the object that s2 points to into the object that s1 points to the function returns the value of s1 The memmove function correctly copies characters between overlapping objects Duplicate Value in Memory include lt string h gt void memset void mem int ch size_t length include lt cstring gt void std memset void mem int ch size_t length memset c in rts src The memset function copies the value of ch into the first length characters of the object that mem points to The function returns the value of mem Run Time Support Functions 9 77 minit Syntax for C Syntax for C Defined in Description 9 78 Reset Dynamic Memory Pool no prototype provided void minit void no prototype provided void std minit void memory c in rts src The minit function resets all the space that was previously allocated by calls to the malloc calloc or realloc functions The memory that minit uses is in a special memory pool or heap The constant ___SYSMEM_SIZE defines the size of the heap as 2K bytes You can change this amount at link time by invoking the linker with the heap option and specifying the desired size of the heap in bytes directly after the option For more information refer to section 8 1 3 Dynamic Memory Allocation on page 8 5
208. d functions that perform the following tasks with character arrays strings g Move or copy entire strings or portions of strings 1 Concatenate strings 1 Compare strings J Search strings for characters or other strings OJ Find the length of a string In C all character strings are terminated with a O null character The string functions named sirxxx all operate according to this convention Additional functions that are also declared in string h cstring perform corresponding operations on arbitrary sequences of bytes data objects where a 0 value does not terminate the object These functions are named memxxx When you use functions that move or copy strings be sure that the destination is large enough to contain the result The string functions are listed in Table 9 3 h on page 9 38 Header Files 9 3 18 Time Functions time h ctime The time h ctime header defines one macro and several types and declares functions that manipulate dates and times Times are represented in the following ways I As an arithmetic value of type time_t When expressed in this way a time is represented as a number of seconds since 12 00 AM January 1 1900 The time_t type is a synonym for the type unsigned long IJ As a structure of type struct_tm This structure contains members for expressing time as a combination of years months days hours minutes and seconds A time represented like this is called broken down time The structure
209. d number y represents the cycle that the instruction is scheduled on within a single iteration of the loop Using the Assembly Optimizer 4 11 What You Need to Know to Write Linear Assembly Example 4 3 shows code for a function called Lmac that contains comments Example 4 3 Lmac Function Code Showing Comments Lmac cproc A4 B4 reg t0O t1 p i sh sl MVK 10034 ZERO sh ZERO sl loop trip 100 LDH a44 tO tO ali LDH b444 t1 tl bfil MPY tO tI p 7 prod t0 ti ADD p sh sl sh sl sum prod i ADD 1 i i _i i B loop if i goto loop return sh sl endproc 4 3 5 Assembly File Retains Your Symbolic Register Names 4 12 In the output assembly file register operands contain your symbolic name This aids you in debugging your linear assembly files and in gluing snippets of linear assembly output into assembly files A map directive see page at the beginning of an assembly function associates the symbolic name with the actual register In other words the symbolic name becomes an alias for the actual register When the compiler splits a user symbol into two symbols and each is mapped to distinct machine register a suffix is appended to instances of the symbolic name to generate unique names so that each unique name is associated with one machine register For example if the compiler associated the symbolic name y with A5 in some instructions and B6 in some others the output assembly c
210. d to the compiler oo ine k op1 Specifies that the module contains variables modified from outside the source code provided to the compiler but does not use functions called from outside the source code op2 Specifies that the module contains no functions or 3 21 variables that are called or modified from outside the source code provided to the compiler default 0p3 Specifies that the module contains functions that are 3 21 called from outside the source code provided to the compiler but does not use variables modified from outside the source code wo oO 0S Interlists optimizer comments with assembly 3 statements The machine specific ma mhn min msn and mt options see Table 2 1 f also effect optimization 2 12 Changing the Compiler s Behavior With Options Table 2 1 Compiler Options Summary Continued k Options that control the assembler Option Effect Page aa Enables absolute listing ac Makes case insignificant in assembly source files 2 23 adname Sets the name symbol 2 23 ahcfilename Copies the specified file for the assembly module ahifilename Includes the specified file for the assembly module 2 23 al Generates an assembly listing file 2 23 apd Performs preprocessing lists only assembly dependencies api Performs preprocessing lists only included include files as Puts labels in the symbol table auname Undefines the predefined constant name 2 24 ax Generates
211. directly into the editable text box that appears at the top of the dialog The information in this book describes how to use the code generation tools from the command line interface For information on using Code Composer Studio consult the Code Composer Studio User s Guide For information on setting code generation tool options within Code Composer Studio consult the Code Generation Tools Help Od a F 0 a Using the C C Compiler The compiler translates your source program in code that the TMS320C6x can execute Source code must be compiled assembled and linked to create an executable object file All of these steps are executed at once by using the compiler cl6x This chapter provides a complete description of how to use the cl6x to compile assemble and link your programs Also included are descriptions of the preprocessor inline function expansion features and interlist utility Topic 2 1 Aboutithe Compiler er eeaeee aeee erect iee leva a eres 2 2 Invoking the C C Compiler eeeeeeeee cece eens 2 3 Changing the Compiler s Behavior With Options 2 4 Setting Default Compiler Options C_OPTION and C6X_C_OPTION 00s00eseeee0s 2 5 Controlling the Preprocessor ceeeeeeeeee eee eens 2 6 Understanding Diagnostic Messages 22 002eeeeee 2 7 Other Messages r ssccesecacsoee EEEIEE OENES 2 8 Generating Cross Reference Listing Information SP
212. ds at every place in your code where f is called Interfacing C and C With Assembly Language 8 5 5 1 Base Address of an Array An argument such as ptr is most commonly passed the base address of an array for example short buffer 100 f buffer When compiling for C64x devices such an array is automatically aligned to an 8 byte boundary When compiling for C62x or C67x such an array is automatically aligned to 4 byte boundary or if the base type requires it an 8 byte boundary This is true whether the array is global static or local This automatic alignment is all that is required to achieve SIMD optimization on those respective devices You still need to include the _nassert because in the general case the compiler cannot guarantee that ptr holds the address of a properly aligned array If you always pass the base address of an array to pointers like ptr then you can use the following macro to reflect that fact if defined _TMS320C6400 define ALIGNED ARRAY ptr _nassert int ptr 8 0 elif defined _TMS320C6200 defined _TMS320C6700 define ALIGNED ARRAY ptr _nassert int ptr 4 0 else define ALIGNED ARRAY ptr empty endif void f short ptr ALIGNED ARRAY ptr a loop operating on data accessed by ptr The macro will work regardless of which C6x device you build for or if you port the code to another target 8 5 5 2 Offset from the Base of an Array A more rare c
213. dule into system memory loop unrolling An optimization that expands small loops so that each itera tion of the loop appears in your code Although loop unrolling increases code size it can improve the efficiency of your code macro A user defined routine that can be used as an instruction macro call The process of invoking a macro macro definition A block of source statements that define the name and the code that make up a macro macro expansion The process of inserting source statements into your code in place of a macro call map file An output file created by the linker that shows the memory configuration section composition section allocation symbol definitions and the addresses at which the symbols were defined for your program memory map A map of target system memory space that is partitioned into functional blocks name mangling A compiler specific feature that encodes a function name with information regarding the function s arguments return types object file An assembled or linked file that contains machine language object code object library An archive library made up of individual object files Glossary operand An argument of an assembly language instruction assembler directive or macro directive that supplies information to the operation performed by the instruction or directive optimizer A software tool that improves the execution speed and reduces the size of C programs See also ass
214. e c linker option when you use the z option This tells the linker to use C C linking conventions autoinitialization of variables at run time If you want to initialize variables at load time use the cr linker option following the z option 5 2 Linker Options Linker Options All command line input following the z option is passed to the linker as parameters and options Following are the options that control the linker along with detailed descriptions of their effects a abs args size C e global_symbol f fill_value g global _symbol h Produces an absolute executable module This is the default if neither a nor r is specified the linker acts as if a is specified Produces an absolute listing file Produces a relocatable executable object module The output module contains the special linker symbols an optional header and all symbol references The relocation information is retained Allocates memory to be used by the loader to pass arguments from the command line of the loader to the program The linker allocates size bytes in an uninitialized args section The __c_args__ symbol contains the address of the args section Disables merge of symbolic debugging information The linker keeps the duplicate entries of symbolic debugging information commonly generated when a C program is compiled for debugging Autoinitializes variables at run time See section 8 8 4 on page 8 56
215. e 2 Example 3 reg This example uses the same code as the block move example on page 4 24 but the reg directive is used move cproc dst src cnt reg tmpl tmp2 loop LDW srct tmpl MV tmp1 tmp2 STW tmp2 dst ADD 4 cnt cnt ent B loop endproc Notice how this example differs from the proc example on page 4 24 symbolic registers declared with reg are allocated as machine registers The code in the following example is invalid because you cannot use a vari able defined by the reg directive with the proc directive move proc dst src cnt WRONG You cannot use a reg dst src cnt variable with proc This example could be corrected as follows move cproc dst src cnt The code in the following example is invalid because a variable defined by the reg directive cannot be used outside of the defined procedure move proc A4 reg tmp LDW A4 tmp MV tmp B5 endproc MV tmp B6 WRONG tmp is invalid outside of the procedure Using the Assembly Optimizer 4 27 reserve rega regb Syntax Description reserve Syntax Description 4 28 Partition Registers Directly rega variable variable2 regb variable variable2 Registers can be directly partitioned through two directives The rega directive is used to constrain a variable name to A side registers The regb directive is used to constrain a variable name to B side registers For example
216. e exp10 double x float exp10f float x define _TlENHANCED_MATH_H 1 include lt cmath gt double std exp10 double x float std exp10f float x exp10 c and exp1Of c in rts src The exp10 and exp10f functions return 10 raised to the power x where x is a real number A range error occurs if the magnitude of x is too large Exponential define _TlENHANCED_MATH_H 1 include lt math h gt double exp2 double x float exp2f float x define _Tl ENHANCED_MATH_H 1 include lt cmath gt double std exp2 double x float std exp2f float x exp2 c and exp 2f c in rts src The exp2 and exp2f functions return 2 to the power x where x is a real number A range error occurs if the magnitude of x is too large fabs fabsf Syntax for C Syntax for C Defined in Description Example Syntax for C Syntax for C Defined in Description Syntax for C Syntax for C Defined in Description feof Absolute Value include lt math h gt double fabs double x float fabsf float x include lt cmath gt double std fabs double x float std fabsf float x fabs c in rts src The fabs and fabsf functions return the absolute value of a floating point number x double x y x 57 5 y fabs x return value 57 5 Close File include lt stdio h gt int fclose FILE _ fp include lt cstdio gt int std fclose FILE _fp fclose c in rts src The fclose functio
217. e keyword inline float volume_sphere float r int foo return 4 0 3 0 PI r r x volume volume_sphere radius The pi option turns off definition controlled inlining This option is useful when you need a certain level of optimization but do not want definition controlled inlining Using the C C Compiler 2 39 Using Inline Function Expansion 2 10 4 Guarded inlining and the INLINE Preprocessor Symbol 2 40 When declaring a function in a header file as static inline additional procedures should be followed to avoid a potential code size increase when inlining is turned off with pi or the optimizer is not run In order to prevent a static inline function in a header file from causing an increase in code size when inlining gets turned off use the following procedure This allows external linkage when inlining is turned off thus only one function definition will exist throughout the object files Lj Prototype a static inline version of the function Then prototype an alternative nonstatic externally linked version of the function Conditionally preprocess these two prototypes with the _INLINE preprocessor symbol as shown in Example 2 2 J Create an identical version of the function definition in a c or cpp file as shown in Example 2 2 In Example 2 2 there are two definitions of the strlen function The first in the header file is an inline definition This definition is en
218. e near calls are executed more efficiently using a PC relative branch Use these options if you have too much static and extern data to fit within a 15 bit scaled offset from the beginning of the bss section or if you have calls in which the called function is more than 1 M word away from the call site The linker issues an error message when these situations occur If an object is declared far its address is loaded into a register and the compiler does an indirect load of that register For more information on the min option see page 2 16 For more information on the differences in the large and small memory models see section 8 1 5 on page 8 6 TMS320C6000 C C Language Implementation 7 13 Keywords 7 4 5 The restrict Keyword To help the compiler determine memory dependencies you can qualify a pointer reference or array with the restrict keyword The restrict keyword is a type qualifier that may be applied to pointers references and arrays Its use represents a guarantee by the programmer that within the scope of the pointer declaration the object pointed to can be accessed only by that pointer Any violation of this guarantee renders the program undefined This practice helps the compiler optimize certain sections of code because aliasing information can be more easily determined In Example 7 2 the restrict Keyword is used to tell the compiler that the function func1 is never called with the pointers a and b
219. e of the C Name Demangler 11 3 Sample Usage of the C Name Demangler Example 11 1 shows a sample C program and the resulting assembly that is output by the C6000 compiler In Example 11 1 b the linknames of all the functions are mangled that is their signature information is encoded into their names Example 11 1 Name Mangling a C Code for calories_in_a_banana class banana public int calories void banana banana int calories _in_a_banana void banana x return x calories C Name Demangler 11 3 Sample Usage of the C Name Demangler b Assembly Output for calories_in_a_banana SE aoe 1 _cCalories_in a _ banana _ Fv RLO RLL RL2 CALL STW MVKL MVKH ADD NOP CALL CALL MVKL ADD MVKH NOP CALL CALL STW ADD MVKL MVK MVKH CALL LDW LDW NOP RET NOP BRANCH OCCURS S1 D2T2 52 S2 S1X OCCURS S1 S2 S1X S2 OCCURS S1 D2T1 S1X S2 S2 lt 52 OCCURS D2T1 D2T2 S2 ct_ 6bananaFv 10 B3 SP 16 7 9 RLO B3 10 RL0 B3 20 8 SP A4 10 1 A 10 _calories 6bananaFv 12 RL1 B3 e 22 8 SP A4 12 RL1 B3 ju fale 2 3 T2 dt_ 6bananaFv 13 A4 SP 4 22 8 SP A4 z ds RL2 B3 ES 0x2 B4 pa ele RL2 B3 eo E3 A 13 SP 4 A4 i2 SP 16 B3 PES 4 B3 as 5 7 13 Executing the C name demangler demangles all names that it believes
220. e the quotes must begin with a label a blank a tab or a comment asterisk or semicolon The compiler performs no checking on the string if there is an error the assembler detects it For more information about the assembly language statements see the TMS320C6000 Assembly Language Tools User s Guide The asm statements do not follow the syntactic restrictions of normal C C statements Each can appear as a statement or a declaration even outside of blocks This is useful for inserting directives at the very beginning of a compiled module _ lt lt lt _ lt lt Ss 00 a S00 0 oo eS Note Avoid Disrupting the C C Environment With asm Statements Be careful not to disrupt the C C environment with asm statements The compiler does not check the inserted instructions Inserting jumps and labels into C C code can cause unpredictable results in variables manipulated in or around the inserted code Directives that change sections or otherwise affect the assembly environment can also be troublesome Be especially careful when you use optimization with asm statements Although the compiler cannot remove asm statements it can significantly rearrange the code order near them and cause undesired results TMS320C6000 C C Language Implementation 7 17 Pragma Directives 7 7 Pragma Directives 7 18 Pragma directives tell the compiler how to treat a certain function object or section of code The C6000 C C compil
221. e this software pipeline schedule and level of collapsing _ Suggestion for a larger value of n to use which might allow additional collapsing This information shows up in the comment block as follows Minimum required memory pad 5 bytes Minimum threshold value mh7 1 For further improvement on this loop try option mh14 For safety the example loop requires that array data referenced within this loop be preceded and followed by a pad of at least 5 bytes This pad can consist of other program data The pad will not be modified In many cases the threshold value namely the minimum value of the argument to mh that is needed to achieve a particular schedule and level of collapsing is the same as the pad However when it is not the comment block will also include the minimum threshold value In the case of this loop the threshold value must be at least 7 to achieve this level of collapsing Another interesting question that arises is whether there is a larger threshold value which would facilitate additional collapsing If there is this information will also be provided For example in the above comment block a threshold value of 14 might facilitate further collapsing Optimizing Your Code 3 15 Redundant Loops 3 3 Redundant Loops Every loop iterates some number of times before the loop terminates The number of iterations is called the trip count The variable used to count each iteration is the trip
222. e value in memory function DWARF debug format dynamic memory allocation defined described 8 5 e linker option ea compiler option ec compiler option EDOM macro EFPOS macro el compiler option embedded C mode emulator defined endproc assembly optimizer directive 4 1744 20 4241 26 ENOENT macro entry point defined environment information function environment variable C_DIR 2 27 p 29 e0 compiler option EOF macro ep compiler option epilog defined Index epilog collapsing speculative execution EPROM programmer 1 4 ERANGE macro errno h header error errno h header file indicators functions mapping function message macro messages See also diagnostic messages handling with options preprocessor escape sequences 7 2 7 37 exception handling exception include file executable module defined exit functions abort function atexit exit function 9 57 exp function exp10 function exp10f function exp2 function exp2f function expf function exponential math functions described exp function exp10 function exp1 Of function exp2 function exp2f function expf function expression defined simplification expressions C language extensions Index 7 Index extensions continued filename extension specification generate function specifying FILENAME_MAX macro find first occurrence of byte function fl compiler option external
223. each function in its own file Chapter 6 Using the Stand Alone Simulator The TMS320C6000 stand alone simulator loads and runs an executable COFF out file When used with the C I O libraries the stand alone simulator supports all C I O functions with standard output to the screen The stand alone simulator gives you a way to gather statistics about your program using the clock function Additional benefits are that the stand alone simulator can be used in a batch file and is included in the code generation tools This chapter describes how to invoke the stand alone simulator It also provides an example of C code and the stand alone simulator results Topic 6 1 Invoking the Stand Alone Simulator 00eeeeeeeee 6 2 Stand Alone Simulator Options 00 eee e eee eee 6 3 Passing Arguments to a Program Through the Loader 6 4 Using the Profiling Capability of the Stand Alone Simulator 6 5 Selecting Silicon Revision to Simulate rev Option 6 6 Stand Alone Simulator Example 00eeeeeeeeeeeeeeeeee 6 1 Invoking the Stand Alone Simulator 6 1 Invoking the Stand Alone Simulator This section shows how to invoke the stand alone simulator to load and run an executable COFF out file This is the general syntax for invoking the stand alone simulator load6x options filename out load6x The command that invokes the stand alone simulator options Option
224. eam include lt stdlib h gt int ungetc int _c register FILE _fp include lt cstdlib gt int std ungetc int _c register FILE _fp ungetc c in rts src The ungetc function writes the character _c to the stream pointed to by _ fp Variable Argument Macros include lt stdarg h gt typedef char va_list type va_arg va_list type void va_end va_list void va_start va_list parmN include lt cstdarg gt typedef char std va_list type std va_arg va_list type void std va_end va_list void std va_start va_list parmN stdarg h in rts src Some functions are called with a varying number of arguments that have varying types Such a function called a variable argument function can use the following macros to step through its argument list at run time The _ap parameter points to an argument in the variable argument list d d The va_start macro initializes _ap to point to the first argument in an argument list for the variable argument function The parmN parameter points to the right most parameter in the fixed declared list The va_arg macro returns the value of the next argument in a call to a variable argument function Each time you call va_arg it modifies _ap so that successive arguments for the variable argument function can be returned by successive calls to va_arg va_arg modifies _ap to point to the next argument in the list The type parameter is a type name it is the type of
225. ed move proc A4 B4 BO no_mdep loop LDW B44 Al MV Al Bl STW B1 A4 ADD 4 BO BO BO B loop endproc proc endproc The following types of instructions are not allowed in proc or cproc see page 4 17 and 4 24 lregions d Instructions that reference the stack pointer register B15 are not allowed in a proc or cproc region Stack space can be allocated by the assembly optimizer in a proc or cproc region for storage of temporary values To allocate this storage area the stack pointer is decremented on entry to the region and incremented on exit from the region Since the stack pointer can change value on entry to the region the assembly optimizer does not allow code that references the stack pointer register Indirect branches are not allowed in a proc or cproc region so that the proc or cproc region exit protocols cannot be bypassed Here is an example of an indirect branch B B4 lt illegal Direct branches to labels not defined in the proc or cproc region are not allowed so that the proc or cproc region exit protocols cannot be bypassed Here is an example of a direct branch outside of a proc region proc B outside lt illegal endproc outside Direct branches to the label associated with a proc directive are not allowed If you require a branch back to the start of the linear assembly function then use the call directive Here is an example of a direct branch to the
226. ede the z linker option and any other linker options must follow the z linker option Source code filenames must be placed before the z linker option Additional object file filenames can be placed after the z linker option Otherwise options and filenames can be placed in any order For example if you want to compile two files named symtab c and file c assemble a third file named seek asm assembly optimize a fourth file named find sa and link to create an executable program called myprogram out you will enter cl6x q symtab c file c seek asm find sa z llnk cmd lrts6200 1lib o myprogram out 2 4 As cl6x encounters each source file it prints the C C filenames and assembly language filenames in square brackets and linear assembly filenames in braces Entering the example command produces these messages symtab c file c seek asm find sa lt Linking gt Changing the Compiler s Behavior With Options 2 3 Changing the Compiler s Behavior With Options Options control the operation of both the compiler and the programs it runs This section provides a description of option conventions and an option summary table It also provides detailed descriptions of the most frequently used options including options used for type checking and assembling The following apply to the compiler options m m m E m Options are preceded by one or two hyphens Options are case sensitive Options are
227. eger such that FLT_RADIX raised to that power minus 1 is a representable finite float double or long double Minimum positive float double or long double number x such that 1 0 x 1 0 Minimum positive float double or long double Maximum float double or long double Minimum negative integers such that 10 raised to that power is in the range of normalized floats doubles or long doubles Maximum positive integers such that 10 raised to that power is in the range of representable finite floats doubles or long doubles Legend FLT_ applies to type float DBL_ applies to type double LDBL_ applies to type long double Note The precision of some of the values in this table has been reduced for readability Refer to the float h cfloat header file supplied with the compiler for the full precision carried by the processor 9 20 Header Files 9 3 7 Format Conversion of Integer Types inttypes h The stdint h header declares sets of integer types of specified widths and defines corresponding sets of macros The inttypes h header contains stdint h and also provides a set of integer types with definitions that are consistent across machines and independent of operating systems and other implementation idiosyncrasies The inttypes h header declares functions for manipulating greatest width integers and converting numeric character strings to greatest width integers Through typedef inttypes h defines integer types of various size
228. einfo gt E lt ciso646 gt No support for bad_cast or bad_type_id is included in the typeinfo header Exception handling is not supported Run time type information RTTI is disabled by default RTTI can be enabled with the rtti compiler option The reinterpret_cast type does not allow casting a pointer to member of one class to a pointer to member of a another class if the classes are unrelated Two phase name binding in templates as described in tesp res and temp dep of the standard is not implemented Template parameters are not implemented The export keyword for templates is not implemented A typedef of a function type cannot include member function cv qualifiers A partial specialization of a class member template cannot be added outside of the class definition TMS320C6000 C C Language Implementation 7 5 Data Types 7 3 Data Types Table 7 1 lists the size representation and range of each scalar data type for the C6000 compiler Many of the range values are available as standard macros in the header file limits h For more information see section 9 3 6 Limits float h and limits h on page 9 19 Table 7 1 TMS320C6000 C C Data Types Type Size char signed char 8 bits unsigned char 8 bits short 16 bits unsigned short 16 bits int signed int 32 bits unsigned int 32 bits long signed long 40 bits unsigned long 40 bits long long signed 64 bits long long unsigned long 64 bits long enum 32 b
229. el routines are comprised of basic I O functions open read write close Ilseek rename and unlink These low level routines provide the interface between the high level functions and the device level drivers that actually perform the I O command on the specified device The low level functions also define and maintain a stream table that associates a file descriptor with a device The stream table interacts with the device table to ensure that an I O command performed on a stream executes the correct device level routine The data structures interact as shown in Figure 9 1 Interaction of Data Structures in I O Functions Stream table Device table file_descriptor1 open read p eeo file_descriptor2 open read p eee The first three streams in the stream table are predefined to be stdin stdout and stderr and they point to the host device and associated device drivers Run Time Support Functions 9 5 The C I O Functions Figure 9 2 The First Three Streams in the Stream Table Stream table Device table file_descriptor1 stdin open file_descriptor2 stdout Host read file_descriptor3 stderr p eee bd open read p eee At the next level are the user definable device level drivers They map directly to the low level I O functions The run time support library includes the device drivers necessary to perform I O on the host on which the debugger is running The speci
230. embers of structures are stored in the same manner as if they were individual objects Arrays are aligned on an 8 byte boundary for C64x and either a 4 byte for all element types of 32 bits or smaller or an 8 byte boundary for C62x or C67x Elements of arrays are stored in the same manner as if they were individual objects Run Time Environment 8 13 Object Representation 8 2 1 7 Pointer to Data Member Types Pointer to data member objects are stored in memory like an unsigned int 32 bit integral type Its value is the byte offset to the data member in the class plus 1 The zero value is reserved to represent the NULL pointer to the data member 8 2 1 8 Pointer to Member Function Types Pointer to member function objects are stored as a structure with three members struct short int d short int i union void int 0 J The parameter d is the offset to be added to the beginning of the class object for this pointer The parameter i is the index into the virtual function table offset by 1 The index enables the NULL pointer to be represented Its value is 1 if the function is nonvirtual The parameter f is the pointer to the member function if it is nonvirtual when i is 0 The 0 is the offset to the virtual function pointer within the class object 8 14 Object Representation 8 2 2 Bit Fields Bit fields are the only objects that are packed within a byte That is two bit fields can be stored in
231. embly optimizer options Command line parameters that allow you to request additional or specific functions when you invoke a software tool output module A linked executable object file that is downloaded and executed on a target system output section A final allocated section in a linked executable module parser A software tool that reads the source file performs preprocessing functions checks the syntax and produces an intermediate file used as input for the optimizer or code generator partitioning The process of assigning a data path to each instruction pipelined loop epilog The portion of code that drains a pipeline in a soft ware pipelined loop See also epilog pipelined loop prolog The portion of code that primes the pipeline in a software pipelined loop See also prolog pop An operation that retrieves a data object from a stack pragma A preprocessor directive that provides directions to the compiler about how to treat a particular statement preprocessor A software tool that interprets macro definitions expands macros interprets header files interprets conditional compilation and acts upon preprocessor directives program level optimization An aggressive level of optimization where all of the source files are compiled into one intermediate file Because the compiler can see the entire program several optimizations are per formed with program level optimization that are rarely applied during file
232. entifier from the beginning of its structure type These types and macros are used by several of the run time support functions 9 3 14 Integer Types stdint h 9 24 The stdint h header declares sets of integer types of specified widths and defines corresponding sets of macros It also defines macros that specify limits of integer types that correspond to types defined in other standard headers Types are defined in these categories m m m Integer types with certain exact widths of the signed form intN_t and of the unsigned form uintN_t Integer types with at least certain specified widths of the signed form int_leastN_t and of the unsigned form uint_leastN_t Fastest integer types with at least certain specified widths of the signed form int_fastN_t and of the unsigned form uint_fastN_t Signed intort_t and unsigned uintptr_t integer types large enough to hold a pointer value Signed intmax_t and unsigned uintmax_t integer types large enough to represent any value of any integer type For each signed type provided by stdint h there is a macro that specifies the minimum or maximum limit Each macro name corresponds to a similar type name described above The INTN_C va ue macro expands to a signed integer constant with the specified value and type int_leastN_t The unsigned UINTN_C value macro expands to an unsigned integer constant with the specified value and type uint_leastN_t Header Files This exam
233. er label proc register registers reg variable variables Description Calls a function Declares circular addressing Start a C C callable procedure End a C C callable procedure End a procedure Assigns a symbol to a register Indicates a memory dependence Avoid memory bank conflicts No memory aliases in the function Assigns a symbol to a register in a set Start a procedure Declare variables Restrictions Page Must manualy insert setup teardown code for circular addressing Valid only within procedures Must use with endproc 4 17 Must use with cproc 4 17 Must use with proc Must use an actual machine register Valid only within procedures 4 21 Valid only within procedures can use variables in the register parameter Valid only within procedures 4 23 Must use actual machine registers 4 23 Must use with endproc 4 24 Valid only within procedures Using the Assembly Optimizer 4 13 Assembly Optimizer Directives Table 4 1 Assembly Optimizer Directives Summary Continued Syntax Description Restrictions Page tega variable variableo Partition symbol to Valid only within procedures A side register regb variable variables Partition symbol to Valid only within procedures B side register reserve register registers Prevents the compiler Valid only within procedures 4 28 from allocating a register return argument Return a
234. er source file This ensures access to the variable since the variable might not be in the bss section For details see section 7 7 4 DATA_SECTION pragma on page 7 22 Note Defining Global Variables in Assembly Code If you also define a global variable in assembly code with the usect directive where the variable is not assigned in the bss section or you allocate a variable into separate section using a pragma DATA_SECTION directive and you want to reference that variable in C code you must declare the variable as extern far This ensures the compiler does not try to generate an illegal access of the variable by way of the data page pointer 7 4 4 2 Near and far function calls Function calls can be invoked in one of two ways near keyword The compiler assumes that destination of the call is within 1 M word of the caller Here the compiler uses the PC relative branch instruction B _ func far keyword The compiler is told by the user that the call is not within 1M word MVKL func al MVKH func al B al By default the compiler generates small memory model code which means that every function call is handled as if it were declared near unless it is actually declared far 7 4 4 3 Controlling How Run Time Support Functions Are Called mr Option 7 12 The mrn option controls how run time support functions are called mr0 Run time support data and calls are near mr1 Run time support data and call
235. er supports the following pragmas CODE_SECTION DATA_ALIGN DATA_MEM_BANK DATA_SECTION FUNC_CANNOT_INLINE FUNC_EXT_CALLED FUNC_INTERRUPT_THRESHOLD FUNC_IS_PURE FUNC_IS_SYSTEM FUNC_NEVER_RETURNS FUNC_NO_GLOBAL_ASG FUNC_NO_IND_ASG INTERRUPT MUST_ITERATE NMI_INTERRUPT PROB_ITERATE STRUCT_ALIGN UNROLL i O O O O O O O O O O O O O O O O Most of these pragmas apply to functions Except for the DATA_MEM_BANK pragma the arguments func and symbol cannot be defined or declared inside the body of a function Pragmas that apply to functions must be specified outside the body of a function and it must occur before any declaration definition or reference to the func or symbol argument If you do not do this the compiler issues a warning For the pragmas that apply to functions or symbols the syntax for the pragmas differs between C and C In C you must supply the name of the object or function to which you are applying the pragma as the first argument In C the name is omitted the pragma applies to the declaration of the object or function that follows it Pragma Directives 7 7 1 The CODE_SECTION Pragma The CODE_SECTION pragma allocates space for the symbol in a section named section name The syntax of the pragma in C is pragma CODE_SECTION symbol section name The syntax of the pragma in C is pragma CODE_SECTION section name The CODE_SECTION pragma is useful if you ha
236. erflow The compiler provides no means to check for stack overflow during compilation or at run time Place the beginning of the stack section in the first address after an unmapped memory space so stack overflow will cause a simulator fault This makes this problem easy to detect Be sure to allow enough space for the stack to grow PR Memory Model 8 1 3 Dynamic Memory Allocation Dynamic memory allocation is not a standard part of the C language The run time support library supplied with the C6000 compiler contains several functions Such as malloc calloc and realloc that allow you to allocate memory dynamically for variables at run time Memory is allocated from a global pool or heap that is defined in the sysmem section You can set the size of the sysmem section by using the heap size option with the linker command The linker also creates a global symbol __SYSMEM_SIZE and assigns it a value equal to the size of the heap in bytes The default size is 0x400 bytes For more information on the heap option see section 5 2 Linker Options on page 5 6 Dynamically allocated objects are not addressed directly they are always accessed with pointers and the memory pool is in a separate section sysmem therefore the dynamic memory pool can have a size limited only by the amount of available memory in your system To conserve space in the bss section you can allocate large arrays from the heap instead of defining them a
237. ers long and must begin with a letter Remaining characters of the variable can be a combination of alphanumeric characters the underscore _ and the dollar sign register Name of the actual register to be assigned a variable When a variable is declared with the map directive it is not necessary to declare that variable with the reg directive Example Here the map directive is used to assign x to register A6 and y to register B7 4 20 The variables are used with a move statement MAP x A6 y B7 MV x y Equivalent to MV A6 B7 Syntax Description Example Syntax Description mptr Indicates a Memory Dependence mdep symbol1 symbol2 The mdep directive identifies a specific memory dependence Following is a description of the mdep directive parameters symbol The symbol parameter is the name of the memory reference The symbol used to name a memory reference has the same syntax restrictions as any assembly symbol For more information about symbols see the TMS320C6000 Assembly Language Tools User s Guide It is in the same space as the symbolic registers You cannot use the same name for a symbolic register and annotating a memory reference The mdep directive tells the assembly optimizer that there is a dependence between two memory references The mdep directive is valid only within procedures that is within occurrences of the proc and endproc directive pair or the cproc and endproc dire
238. es a C I O function For example given the following C program in a file named main c include lt stdio h gt main FILE fid fid fopen myfile w fprintf fid Hello world n fclose fid printf Hello again world n Issuing the following compiler command compiles links and creates the file main out from the C6200 run time support little endian library cl6 x main c z heap 400 1 rts6200 lib o main out Executing main out results in Hello world being output to a file and Hello again world being output to your host s stdout window With properly written device drivers the library also offers facilities to perform I O on a user specified device Note C I O Buffer Failure If there is not enough space on the heap for a C I O buffer buffered operations on the file will fail If a call to printf mysteriously fails this may be the reason Check the size of the heap To set the heap size use the heap option when linking see page The C I O Functions 9 2 1 Overview of Low Level I O Implementation Figure 9 1 The code that implements 1 O is logically divided into layers high level low level and device level The high level functions are the standard C library of stream I O routines printf scanf fopen getchar and so on These routines map an I O request to one or more of the I O commands that are handled by the low level routines The low lev
239. es contain the ISO standard run time support functions compiler utility functions floating point arithmetic functions and C I O functions that are supported by the C6000 compiler See Run Time Environment The hex conversion utility converts a COFF object file into Tl Tagged ASCIl hex Intel Motorola S or Tektronix object format You can download the converted file to an EPROM programmer The TMS320C6000 Assembly Language Tools User s Guide explains how to use the hex conversion utility The cross reference lister uses object files to produce a cross reference listing showing symbols their definitions and their references in the linked source files The TMS320C6000 Assembly Language Tools User s Guide explains how to use the cross reference utility The main product of this development process is a module that can be executed in a TMS320C6000 device You can use one of several debugging tools to refine and correct your code Available products include An instruction accurate and clock accurate software simulator m An XDS emulator The C name demangler is a debugging aid that translates each mangled name it detects to its original name found in the C source code For information about these debugging tools see the TMS320C6000 Code Composer Studio Tutorial and the Code Composer Studio User s Guide C C Compiler Overview 1 2 C C Compiler Overview 1 2 1 ISO Standard The C6000 C C compiler is a full fea
240. es for the linker or hex conversion utility comment A source statement or portion of a source statement that docu ments or improves readability of a source file Comments are not com piled assembled or linked they have no effect on the object file Glossary common object file format COFF A system of object files configured according to a standard developed by AT amp T These files are relocatable in memory space compiler constant A type whose value cannot change cross reference listing An output file created by the assembler that lists the symbols it defined what line they were defined on which lines refer enced them and their final values data section One of the default COFF sections The data section is an initialized section that contains initialized data You can use the data directive to assemble code into the data section direct call A function call where one function calls another using the function s name directives Special purpose commands that control the actions and functions of a software tool disambiguation See alias disambiguation dynamic memory allocation A technique used by several functions such as malloc calloc and realloc to dynamically allocate memory for vari ables at run time This is accomplished by defining a large memory pool heap and using the functions to allocate memory from the heap emulator A hardware development system that duplicates the TMS320C6000 oper
241. es listed in Table 2 3 Table 2 3 Predefined Macro Names Macro Name _TMS320C6X _TMS320C6200 _TMS320C6400 _TMS320C6700 _BIG_ENDIAN _ INLINE _LARGE_MODEL LARGE_MODEL_OPTION _LITTLE_ENDIAN Description Always defined Defined if target is C6200 Defined if target is C6400 Defined if target is C6700 Defined if big endian mode is selected the me option is used otherwise it is undefined Expands to 1 if optimization is used undefined otherwise Regardless of any optimization always undefined when pi is used Defined if large model mode is selected the ml option is used otherwise it is undefined Set to the large model specified by mlIn otherwise it is undefined Defined if little endian mode is selected the me option is not used otherwise it is undefined Tt Specified by the ISO standard 2 26 Controlling the Preprocessor Table 2 3 Predefined Macro Names Continued Macro Name _SMALL_MODEL Description Defined if small model mode is selected the ml option is not used __LINE__t __FILE__t __DATE__t __TIME__t __TI_COMPILER_VERSION__ __STDC__t otherwise it is undefined Expands to the current line number Expands to the current source filename Expands to the compilation date in the form mmm dd yyyy Expands to the compilation time in the form hh mm ss Defined to a 3 or more digit integer that consists of a major version number and a 2 digit minor version number
242. es the function only if the result is less than the size parameter The compiler measures the size of a function in arbitrary units however the optimizer information file created with the on1 or on2 option reports the size of each function in the same units that the oi option uses The oisize option controls only the inlining of functions that are not explicitly declared as inline If you do not use the oisize option the compiler inlines very small functions a Note 03 Optimization and inlining In order to turn on automatic inlining you must use the O3 option The 03 option turns on other optimizations If you desire the O3 optimizations but not automatic inlining use oi0 with the O3 option es _ rvrinwvnannanarawrweer rerrrrrrewrewrererrwrerreeeeeeeeeereeermreaeeoeorreereeerrerrrrererrereerrereoeorrerw Note Inlining and Code Size Expanding functions inline increases code size especially inlining a function that is called in a number of places Function inlining is optimal for functions that are called only from a small number of places and for small functions In order to prevent increases in code size because of inlining use the oi0 and pi options These options cause the compiler to inline intrinsics only If your code size still seems too large see section 3 4 Reducing Code Size ms Option on page 3 17 Optimizing Your Code 3 29 Using the Interlist Feature With
243. escribes the assembly language tools assembler linker and other tools used to develop assembly language code assembler directives macros common object file format and symbolic debugging directives for the C6000 generation of devices Code Composer User s Guide literature number SPRU328 explains how to use the Code Composer development environment to build and debug embedded real time DSP applications TMS320C6000 DSP BIOS User s Guide literature number SPRU303 describes how to use TMS320C6000 DSP BIOS tools and APIs to ana lyze embedded real time DSP applications TMS320C6000 CPU and Instruction Set Reference Guide literature number SPRU189 describes the C6000 CPU architecture instruction set pipeline and interrupts for these digital signal processors TMS320C6201 C6701 Peripherals Reference Guide literature number SPRU190 describes common peripherals available on the TMS320C6201 and TMS320C6701 digital signal processors This book includes information on the internal data and program memories the external memory interface EMIF the host port interface HPI multi channel buffered serial ports McBSPs direct memory access DMA enhanced DMA EDMA expansion bus clocking and phase locked loop PLL and the power down modes TMS320C6000 Programmer s Guide literature number SPRU198 describes ways to optimize C and assembly code for the TMS320C6000 DSPs and includes application program examples TMS3
244. etchar void fgetc c in rts src The getchar function reads the next character from the standard input device Get Environment Information include lt stdlib h gt char getenv const char _ string include lt cstdlib gt char std getenv const char _ string trgdrv c in rts src The getenv function returns the environment information for the variable associated with _ string Read Next From Standard Input include lt stdio h gt char gets char _ptr include lt cstdio gt char std gets char _ptr fgets c in rts src The gets function reads an input line from the standard input device The characters are placed in the array named by _ pir Use the function fgets instead of gets when possible Syntax for C Syntax for C Defined in Description Syntax for C Syntax for C Defined in iSxxx Greenwich Mean Time include lt time h gt struct tm gmtime const time_t timer include lt ctime gt struct tm std gmtime const time_t timer gmtime c in rts src The gmtime function converts a calendar time pointed to by timer into a broken down time which is expressed as Greenwich Mean Time For more information about the functions and types that the time h ctime header declares and defines see section 9 3 18 Time Functions time h ctime on page 9 27 Character Typing include lt ctype h gt int isalnum int c int isalpha int c int isascii int c int isentr
245. ets the compiler applies that information relative to the path information specified with I options and the C_DIR or C6X_C_DIR environment variable For example if you set up C_DIR with the following command C_DIR usr include usr ucb export C DIR or invoke the compiler with the following command cl6x I usr include file c and file c contains this line include lt sys proc h gt the result is that the included file is in the following path usr include sys proc h ewe 2 5 3 Generating a Preprocessed Listing File ppo Option The ppo option allows you to generate a preprocessed version of your source file with an extension of pp The compiler s preprocessing functions perform the following operations on the source file J Each source line ending in a backslash is joined with the following line Trigraph sequences are expanded Comments are removed include files are copied into the file Macro definitions are processed All macros are expanded m m m m E m All other preprocessing directives including line directives and conditional compilation are expanded 2 5 4 Continuing Compilation After Preprocessing ppa Option If you are preprocessing the preprocessor performs preprocessing only By default it does not compile your source code If you want to override this feature and continue to compile after your source code is preprocessed use the ppa option along with the other prep
246. f run time models or target CPUs For more information see Chapter 10 Library Build Utility Stand alone simulator The stand alone simulator load6x loads and runs an executable COFF out file When used with the C I O libraries the stand alone simulator supports all C I O functions with standard output to the screen For more information see Chapter 6 Using the Stand Alone Simulator C name demangler The C name demangler dem6x is a debugging aid that translates each mangled name it detects to its original name found in the C source code For more information see Chapter 11 C Name Demangler Introduction 1 7 Code Composer Studio and the Compiler 1 3 Code Composer Studio and the Compiler Code Composer Studio provides a graphical interface for using the code generation tools A Code Composer Studio project manages the information needed to build a target program or library A project records Lj File names of source code and object libraries J Compiler assembler and linker options _j Include file dependencies When you build a project with Code Composer Studio the appropriate code generation tools are invoked to compile assemble and or link your program Compiler assembler and linker options can be specified within Code Composer Studio s Build Options dialog Nearly all command line options are represented within this dialog Options that are not represented can be specified by typing the option
247. f the mantissa The even memory word contains the least significant part of the mantissa In little endian mode the lower address is loaded into the even register and the higher address is loaded into the odd register In big endian mode the higher address is loaded into the even register and the lower address is loaded into the odd register In little endian mode if code is loaded from location 0 then the byte at 0 is the lowest byte of the even register In big endian mode if code is loaded from location 0 then the byte at 0 is the highest byte of the odd register Figure 8 5 Double Precision Floating Point Data Storage Format 31 MS Oddregister S E EE EEE EEE EE MMM MMM MM MM MM MM MM MM MM 20 0 LS Even register Legend 31 S sign M mantissa E exponent 0 MS most significant LS least significant 8 2 1 6 Structures and Arrays A nested structure is aligned to a boundary required by the largest type it contains For example if the largest type in a nested structure is of type short then the nested structure is aligned to a 2 byte boundary If the largest type in a nested structure is of type long unsigned long double or long double then the nested structure is aligned to an 8 byte boundary Structures always reserve memory in multiples of the size of the largest element type For example if a structure contains an int unsigned int or float a multiple of 4 bytes of storage is reserved in memory M
248. f the following values lt 0 if ptr1 is less than ptr2 O if ptr1 is equal to ptr2 gt 0 if ptr1 is greater than ptr2 int list 10 9 8 7 6 5 4 3 2 1 0 int intemp const void ptr1 const void ptr2 return int ptr1 int ptr2 Syntax for C Syntax for C Defined in Description Example ceil ceilf Syntax for C Syntax for C Defined in Description Example ceil ceilf Allocate and Clear Memory include lt stdlib h gt void calloc size_t num size_t size include lt cstdlib gt void std calloc size_t num size_t size memory c in rts src The calloc function allocates size bytes size is an unsigned integer or size_t for each of num objects and returns a pointer to the space The function initializes the allocated memory to all Os If it cannot allocate the memory that is if it runs out of memory it returns a null pointer 0 The memory that calloc uses is in a special memory pool or heap The constant __SYSMEM_SIZE defines the size of the heap as 2K bytes You can change this amount at link time by invoking the linker with the heap option and specifying the desired size of the heap in bytes directly after the option See section 8 1 3 Dynamic Memory Allocation on page This example uses the calloc routine to allocate and clear 20 bytes prt calloc 10 2 Allocate and clear 20 bytes Ceiling include lt math h gt double ceil double
249. ferB my sect char bufferA 512 char bufferB 512 b C source file char bufferA 512 pragma DATA SECTION my _ sect char bufferB 512 c Assembly source file global _bufferA bss _bufferA 512 4 global _bufferB _bufferB usect my _sect 512 4 Pragma Directives 7 7 5 The FUNC_CANNOT_INLINE Pragma The FUNC_CANNOT_INLINE pragma instructs the compiler that the named function cannot be expanded inline Any function named with this pragma overrides any inlining you designate in any other way such as using the inline keyword Automatic inlining is also overridden with this pragma see section 2 10 Using Inline Function Expansion on page 2 38 The pragma must appear before any declaration or reference to the function that you want to keep The syntax of the pragma in C is pragma FUNC_CANNOT_INLINE fung The syntax of the pragma in C is pragma FUNC_CANNOT_INLINE In C the argument func is the name of the function that cannot be inlined In C the pragma applies to the next function declared 7 7 6 The FUNC_EXT CALLED Pragma When you use the pm option the compiler uses program level optimization When you use this type of optimization the compiler removes any function that is not called directly or indirectly by main You might have C C functions that are called by hand coded assembly instead of main The FUNC_EXT_CALLED
250. fic characteristics of the TMS320C6000 C C compiler as they relate to the ISO C specification 7 1 Characteristics of TMS320C6000 C 1 eee eee 7 1 4 Identifiers and Constants 000 cece eee eee eee 7 1 2 Data TPOS a cccie ds costed Seatac sheen EEEE Soames 7 1 3 CONVEFSIONS rsin Seared anaE Abele nada s Ree pace EEE 7 1 4 Expression Ss satus aid Hiatt e ected i dee pact E ie 7 1 5 DeclarationS siernpre eaa tented 7 1 6 PICPIOCOSSON sac ncsd eras Gee tie See rE ON de ie EEE yeas 7 2 Characteristics of TMS320C6000 C 0 0 c eee tees To iDalaNyPeS ais 22045 Scene ne de abr ce cee eae Pee oa eNey wa oie ea ee cane ene T KOYWONS ta iinew cduieein deka neces E aid goed eda bd went 7 4 1 The const Keyword 0 00 cece cnet teen eee eae 7 4 2 The cregister Keyword 00 ccc eee eens 7 4 3 The interrupt Keyword 000 cece cece eee eens 7 4 4 The near and far Keywords 2 00 e cece eee teen eee es 7 4 5 The restrict Keyword 0 00 c cece eee eee eens 7 4 6 The volatile Keyword 0 0 c cece eens 7 5 Register Variables and Parameters 00 c cece eects 7 6 Theasm Statement 00 0 erinin ia nin eee eens TA Pragma Directives s 2 2 c60 nec avant udani nianie eae dae eae dea eee oe 7 7 The CODE_SECTION Pragma 000 cece eee e eee ee 7 7 2 The DATA_ALIGN Pragma 00c cece cece teens 7 7 3 The DATA_MEM_BANK Pragma 00 cece eect
251. fications for writing device level routines to interface with the low level routines follow Each function must set up and maintain its own data structures as needed Some function definitions perform no action and should just return Syntax for C Defined in Description Return Value add_device Add Device to Device Table include lt file h gt int add_device char name unsigned flags int dopen int dclose int dread int dwrite fpos_t dlseek int dunlink int drename lowlev c in rts src The add_device function adds a device record to the device table allowing that device to be used for input output from C The first entry in the device table is predefined to be the host device on which the debugger is running The func tion add_device finds the first empty position in the device table and initializes the fields of the structure that represent a device To open a stream on a newly added device use fopen with a string of the format devicename filename as the first argument J The name is a character string denoting the device name The name is limited to 8 characters _ The flags are device characteristics The flags are as follows _SSA_ Denotes that the device supports only one open stream at a time _MSA Denotes that the device supports multiple open streams More flags can be added by defining them in stdio h Lj The dopen dclose dread dwrite dlseek d
252. fied with a leading underscore and are accessed by calling them as you do a function For example int xl x2 y y _sadd x1 x2 The intrinsics listed in Table 8 3 are included for all C6000 devices They correspond to the indicated C6000 assembly language instruction s See the TMS320C6000 CPU and Instruction Set Reference Guide for more information Note Intrinsic Instructions in C versus Assembly Language In some instances an intrinsic s exact corresponding assembly language instruction may not be used by the compiler When this is the case the meaning of the program does not change See Table 8 4 on page 8 31 for the listing of C64x specific intrinsics See Table 8 5 on page 8 35 for the listing of C67x specific intrinsics Interfacing C and C With Assembly Language Table 8 3 TMS320C6000 C C Compiler Intrinsics Assembly C C Compiler Intrinsic Instruction Description int _abs int src ABS Returns the saturated absolute value of src int __labs long src int _add2 int src7 int src2 ADD2 Adds the upper and lower halves of src1 to the upper and lower halves of src2 and returns the result Any overflow from the lower half add does not affect the upper half add ushort amp _amem2 void ptr LDHU Allows aligned loads and stores of 2 bytes to STHU memoryt const ushort amp _amem2_const const LDHU Allows aligned loads of 2 bytes from memoryt void ptn uint amp amemA void
253. field defined as an integer is signed Bit fields are packed into words and do not cross word boundaries For more information about bit field packing see section 8 2 2 Bit Fields page 8 15 ISO 3 5 2 1 K amp R A8 3 The interrupt keyword can be applied only to void functions that have no arguments For more information about the interrupt keyword see section 7 4 3 on page 7 10 The preprocessor ignores any unsupported pragma directive ISO 3 8 6 K amp R A12 8 The following pragmas are supported CODE_SECTION DATA_ALIGN DATA_MEM_BANK DATA_SECTION FUNC_CANNOT_INLINE FUNC_EXT_CALLED FUNC_INTERRUPT_THRESHOLD FUNC_IS_PURE FUNC_IS_SYSTEM FUNC_NEVER_RETURNS FUNC_NO_GLOBAL_ASG FUNC_NO_IND_ASG INTERRUPT MUST_ITERATE NMILINTERRUPT PROB_ITERATE STRUCT_ALIGN UNROLL For more information on pragmas see section 7 7 on page 7 18 Characteristics of TAS320C6000 C 7 2 Characteristics of TMS320C6000 C The TMS320C6000 compiler supports C as defined in the ISO IEC 14882 1998 standard The exceptions to the standard are as follows m m Li oO vo O Complete C standard library support is not included C subset and basic language support is included These C headers for C library facilities are not included m lt clocale gt E lt csignal gt E lt cwchar gt lt cwctype gt These C headers are the only C standard library header files included E lt new gt E lt typ
254. for more information Initializes variables at load time See section 8 8 5 on page 8 57 for more information Defines a global_symbol that specifies the primary entry point for the output module Sets the default fill value for null areas within output sections fill_value is a 32 bit constant Defines global_symbol as global even if the global symbol has been made static with the h linker option Makes all global symbols static global symbols are essentially hidden This allows external symbols with the same name in different files to be treated as unique Linking C C Code 5 5 Linker Options 5 6 heap size I directory l ibraryname m filename 0 filename q priority r S stack size Sets the heap size for dynamic memory allocation to size bytes and defines a global symbol that specifies the heap size The default is 1K bytes Alters the library search algorithm to look in directory before looking in the default location This option must appear before the l linker option The directory must follow operating system conventions You can specify up to 128 I options Disables conditional linking that has been set up with the assembler clink directive By default all sections are unconditionally linked lower case L Names an archive library file or linker command filename as linker input The ibraryname is an archive library name and must follow operating system convention
255. fp register char _buf register int _ type register size_t_ size setvbuf c in rts src The setvbuf function defines and associates the buffer used by the stream pointed to by _ fp If _buf is set to null a buffer is allocated If _buf names a buffer that buffer is used for the stream The _ size specifies the size of the buffer The _type specifies the type of buffering as follows _IOFBF Full buffering occurs _IOLBF Line buffering occurs _IONBF No buffering occurs Run Time Support Functions 9 89 sin sinf Syntax for C Syntax for C Defined in Description Example sinh sinhf Syntax for C Syntax for C Defined in Description Example 9 90 Sine include lt math h gt double sin double x float sinf float x include lt cmath gt double std sin double x float std sinf float x sin c and sinf c in rts src The sin and sinf functions return the sine of a floating point number x The angle x is expressed in radians An argument with a large magnitude can produce a result with little or no significance double radian sval sin returns sval radian 3 1415927 sval sin radian sin returns approx 1 0 Hyperbolic Sine include lt math h gt double sinh double x float sinhf float x include lt cmath gt double std sinh double x float std sinhf float x sinh c and sinhf c in rts src The sinh and sinhf functions return the hyperbolic sine of
256. ftware tool to retain symbolic infor mation that can be used by a debugging tool such as a simulator or an emulator target system The system on which the object code you have developed is executed text section One of the default COFF sections The text section is initial ized and contains executable code You can use the text directive to assemble code into the text section trigraph sequence A 3 character sequence that has a meaning as defined by the ISO 646 1983 Invariant Code Set These characters cannot be represented in the C character set and are expanded to one character For example the trigraph is expanded to trip count The number of times that a loop executes before it terminates Glossary A 9 Glossary uninitialized section A COFF section that reserves space in the memory map but that has no actual contents These sections are built with the bss and usect directives unsigned value A value that is treated as a nonnegative number regard less of its actual sign variable A symbol representing a quantity that can assume any of a set of values A 10 in linear assembly source compiler option in linear assembly source gt gt symbol a linker option a stand alone simulator option aa assembler option abort function abs extension abs function absolute listing creating absolute value abs labs functions fabs function fabsf function ac assembler option aco
257. g Your Code 3 41 What Kind of Optimization Is Being Performed Example 3 6 Data Flow Optimizations and Expression Simplification a C source char simplify char j char a 3 char b j a j 2 return b b Compiler output FP set A15 DP set B14 SP set B15 opt 6 x O2 t1 if tl opt Sect vex global _simplify _simplify B S2 B3 NOP 2 MPY M1 5 A4 A0 NOP 1 EXT S1 A0O 24 24 A4 BRANCH OCCURS 3 13 6 Inline Expansion of Functions The compiler replaces calls to small functions with inline code saving the overhead associated with a function call as well as providing increased opportunities to apply other optimizations see Example 3 7 In Example 3 7 the compiler finds the code for the C function plus and replaces the call with the code 3 42 What Kind of Optimization Is Being Performed Example 3 7 Inline Function Expansion a C source int plus int x int y return xX y main int a 3 int b 4 int c 5 return plus a plus b c b Compiler output FP set A15 DP set B14 SP set B15 opt x 03 t2 if t2 opt Sect text global _main _main J PPD DPS gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt ENTERING plus KKK KKK KK eC ec lt c lt ce lt lt lt lt lt lt lt lt lt lt lt LEA
258. g constant is used in one of the following ways Lj To initialize an array of characters For example char s abo When a string is used as an initializer it is simply treated as an initialized array each character is a separate initializer For more information about initialization see section 8 8 System Initialization on page 8 51 In an expression For example strcpy s abc When a string is used in an expression the string itself is defined in the const section with the string assembler directive along with a unique label that points to the string the terminating O byte is included For example the following lines define the string abc and the terminating 0 byte the label SL5 points to the string sect const SL5 string abc 0 String labels have the form SLn where nis a number assigned by the compiler to make the label unique The number begins at O and is increased by 1 for each string defined All strings used in a source module are defined at the end of the compiled assembly language module The label SLn represents the address of the string constant The compiler uses this label to reference the string expression Because strings are stored in the const section possibly in ROM and shared it is bad practice for a program to modify a string constant The following code is an example of incorrect string use const char a abc all Coch Incorrect Register Conven
259. g disabled Software pipelining has been disabled by a command line option Pipelining is turned off when using the mu option not using the O2 or O3 option or using the ms2 or ms3 option Uninitialized trip counter The trip counter may not have been set to an initial value Suppressed to prevent code expansion Software pipelining may be suppressed because of the ms1 option When the ms1 option is used software pipelining is disabled in less promising cases to reduce code size To enable pipelining use ms0 or omit the ms option altogether Loop carried dependency bound too large If the loop has complex loop control try mh according to the recommendations in section 3 2 3 2 Selecting the Best Threshold Value on page 3 15 Cannot identify trip counter The loop trip counter could not be identified or was used incorrectly in the loop body Optimizing Your Code 3 9 Optimizing Software Pipelining 3 2 2 2 Pipeline Failure Messages The following messages can appear when the compiler or assembly optimizer is processing a software pipeline and it fails J Address increment is too large An address register s offset must be adjusted because the offset is out of range of the C6000 s offset addressing mode You must minimize address register offsets J Cannot allocate machine registers A software pipeline schedule was found but it cannot allocate machine registers for the schedule You must simplify the loop
260. g long int LLONG_MAX 9 223 372 036 854 775 807 Maximum value for a long long int ULLONG_MAX 18 446 744 073 709 551 615 Maximum value for an unsigned long long int Note Negative values in this table are defined as expressions in the actual header file so that their type is correct Run Time Support Functions 9 19 Header Files Table 9 2 Macros That Supply Floating Point Range Limits float h cfloat Macro FLT_RADIX FLT_ROUNDS FLT_DIG DBL_DIG LDBL_DIG FLT_MANT_DIG DBL_MANT_DIG LDBL_MANT_DIG FLT_MIN_EXP DBL_MIN_EXP LDBL_MIN_EXP FLT_MAX_EXP DBL_MAX_EXP LDBL_MAX_EXP FLT_EPSILON DBL_EPSILON LDBL_EPSILON FLT_MIN DBL_MIN LDBL_MIN FLT_MAX DBL_MAX LDBL_MAX FLT_MIN_10_EXP DBL_MIN_10_EXP LDBL_MIN_10_EXP FLT_MAX_10_EXP DBL_MAX_10_EXP LDBL_MAX_10_EXP Value 2 1 6 15 15 24 53 53 125 1021 1021 128 1024 1024 1 19209290e 07 2 22044605e 16 2 22044605e 16 1 17549435e 38 2 22507386e 308 2 22507386e 308 3 40282347e 38 1 79769313 e 308 1 79769313e 308 37 307 307 38 308 308 Description Base or radix of exponent representation Rounding mode for floating point addition Number of decimal digits of precision for a float double or long double Number of base FLT_RADIX digits in the mantissa of a float double or long double Minimum negative integer such that FLT_RADIX raised to that power minus 1 is a normalized float double or long double Maximum negative int
261. gly no run time initialization is performed at boot time A loader which is not part of the compiler package must be able to perform the following tasks to use initialization at load time _j Detect the presence of the cinit section in the object file _ Determine that STYP_COPY is set in the cinit section header so that it knows not to copy the cinit section into memory _j Understand the format of the initialization tables Figure 8 11 illustrates the initialization of variables at load time Figure 8 11 Initialization at Load Time Object file Memory cinit section bss section Run Time Environment 8 57 8 58 Chapter 9 Run Time Support Functions Some of the tasks that a C C program performs such as I O dynamic memory allocation string operations and trigonometric functions are not part of the C C language itself However the ISO C standard defines a set of run time support functions that perform these tasks The TMS320C6000 C C compiler implements the complete ISO standard library except for those facilities that handle exception conditions and locale issues properties that depend on local language nationality or culture Using the ISO standard library ensures a consistent set of functions that provide for greater portability In addition to the ISO specified functions the TMS320C6000 run time support library includes routines that give you processor specific commands and direct
262. gnostic identifier includes the suffix D for discretionary otherwise no suffix is present For example Test_name c line 7 error 64 D declaration does not declare anything struct A Test_name c line 9 error 77 this declaration has no storage class or type specifier XXKXX A Because an error is determined to be discretionary based on the error severity associated with a specific context an error can be discretionary in some cases and not in others All warnings and remarks are discretionary For some messages a list of entities functions local variables source files etc is useful the entities are listed following the initial error message test c line 4 error more than one instance of overloaded function f matches the argument list function f int function f float argument types are double 1 5 A In some cases additional context information is provided Specifically the context information is useful when the front end issues a diagnostic while doing a template instantiation or while generating a constructor destructor or assignment operator function For example test c line 7 error A A is inaccessible B 32i A detected during implicit generation of B B at line 7 Without the context information it is difficult to determine to what the error refers 2 6 1 Controlling Diagnostics Understanding Diagnostic Messages The C C compiler pr
263. h cassert header refers to another macro named NASSERT assert h cassert does not define NASSERT If you have defined NASSERT as a macro name when you include assert h cassert assert acts like _nassert The _nassert intrinsic generates no code and tells the compiler that the expression declared with assert is true This gives a hint to the compiler as to what optimizations might be valid If NASSERT is not defined assert is enabled normally The _nassert intrinsic can also be used to guarantee that a pointer has a certain alignment For more information see section 8 5 4 Using _nassert to Enable SIMD and Expand Compiler Knowledge of Loops on page 8 37 The assert function is listed in Table 9 3 a on page 9 30 9 3 2 Character Typing and Conversion ctype h cctype The ctype h cctype header declares functions that test type of characters and converts them The character typing functions test a character to determine whether it is a letter a printing character a hexadecimal digit etc These functions return a value of true a nonzero value or false 0 Character typing functions have names in the form isxxx for example sdigit The character conversion functions convert characters to lowercase uppercase or ASCII and return the converted character Character conversion functions have names in the form toxxx for example toupper Run Time Support Functions 9 17 Header Files The ctype h cctype header also contain
264. h items in the symbol table are values and which are addresses If you try to access an assembler or linker constant by name the compiler attempts to fetch a value from the address represented in the symbol table To prevent this unwanted fetch you must use the amp address of operator to get the value In other words if x is an assembly language constant its value in C C is amp x You can use casts and defines to ease the use of these symbols in your program as in Example 8 7 Example 8 7 Accessing an Assembly Language Constant From C a C program extern int table size external ref define TABLE SIZE int amp table size use cast to hide address of for i 0 i lt TABLE SIZE i use like normal symbol b Assembly language program _table size set 10000 define the constant global table size make it global Because you are referencing only the symbol s value as stored in the symbol table the symbol s declared type is unimportant In Example 8 7 int is used You can reference linker defined symbols in a similar manner Run Time Environment 8 45 Interrupt Handling 8 6 Interrupt Handling As long as you follow the guidelines in this section you can interrupt and return to C C code without disrupting the C C environment When the C C environment is initialized the startup routine does not enable or disable interrupts If your system uses interrupts yo
265. h other For more information see Run Time Environment C C Compiler Overview 1 2 4 Compiler Operation 1 2 5 Utilities The following features pertain to the operation of the compiler d Integrated preprocessor The C C preprocessor is integrated with the parser allowing for faster compilation Stand alone preprocessing or preprocessed listing is also available For more information see section 2 5 Controlling the Preprocessor on page 2 26 Optimization The compiler uses a sophisticated optimization pass that employs several advanced techniques for generating efficient compact code from C C source General optimizations can be applied to any C C code and C6000 specific optimizations take advantage of the features specific to the C6000 architecture For more information about the C C compiler s optimization techniques see Chapter 3 Optimizing Your Code The following features pertain to the compiler utilities Lj Source interlist feature The compiler tools include a utility that interlists your original C C source statements into the assembly language output of the compiler This utility provides you with a method for inspecting the assembly code generated for each C C statement For more information see section 2 13 Using the Interlist Feature on pagel 2 46 Library build utility The library build utility mk6x lets you custom build object libraries from source for any combination o
266. har to register const char from register size_t n strxfrm c in rts src The strxfrm function converts n characters pointed to by from into the n characters pointed to by to Tangent include lt math h gt double tan double x float tanf float x include lt cmath gt double std tan double x float std tanf float x tan c and tanf c in rts src The tan and tanf functions return the tangent of a floating point number x The angle x is expressed in radians An argument with a large magnitude can produce a result with little or no significance double x y 3 1415927 4 0 tan x x yY y approx 1 0 Run Time Support Functions 9 105 tanh tanhf tanh tanhf Syntax for C Syntax for C Defined in Description Example Syntax for C Syntax for C Defined in Description 9 106 Hyperbolic Tangent include lt math h gt double tanh double x float tanhf float x include lt cmath gt double std tanh double x float std tanhf float x tanh c and tanhf c in rts src The tanh and tanhf functions return the hyperbolic tangent of a floating point number x double x Y 0 0 tanh x x y return value 0 0 Time include lt time h gt time_t time time_t timer include lt ctime gt time_t std time time_t timer time c in rts src The time function determines the current calendar time represented in seconds If the calendar time
267. has the following members int tm_sec seconds after the minute 0 59 Int tm min minutes after the hour 0 59 int tm_hour hours after midnight 0 23 int tm_mday day of the month 1 31 int tm_mon months since January 0 11 int tm_year years since 1900 0 and up int tm_wday days since Saturday 0 6 int tm_yday days since January 1 0 365 int tm_isdst daylight savings time flag A time whether represented as a time_t or a struct tm can be expressed from different points of reference _j Calendar time represents the current Gregorian date and time J Local time is the calendar time expressed for a specific time zone The time functions and macros are listed in Table 9 3 i on page 9 40 You can adjust local time for local or seasonal variations Obviously local time depends on the time zone The time h ctime header defines a structure type called tmzone and a variable of this type called _tz You can change the time zone by modifying this structure either at run time or by editing tmzone c and changing the initialization The default time zone is CST Central Standard Time U S A The basis for all the time h ctime functions are the system functions of clock and time Time provides the current time in time_t format and clock provides the system time in arbitrary units You can divide the value returned by clock by the macro CLOCKS_PER_SEC to convert it to
268. hat are rarely applied otherwise Among these optimizations is seeing that for instance all of the calls to the function f are passing the base address of an array to ptr and thus ptr is always correctly aligned for SIMD optimization In such a case the _nassert is not required The compiler automatically determines that ptr must be aligned and produces the optimized SIMD instructions ee Run Time Environment 8 41 Interfacing C and C With Assembly Language 8 5 6 SAT Bit Side Effects 8 5 7 8 42 The saturated intrinsic operations define the SAT bit if saturation occurs The SAT bit can be set and cleared from C C code by accessing the control status register CSR The compiler uses the following steps for generating code that accesses the SAT bit 1 The SAT bit becomes undefined by a function call or a function return This means that the SAT bit in the CSR is valid and can be read in C C code until a function call or until a function returns If the code in a function accesses the CSR then the compiler assumes that the SAT bit is live across the function which means E The SAT bit is maintained by the code that disables interrupts around software pipelined loops Saturated instructions cannot be speculatively executed If an interrupt service routine modifies the SAT bit then the routine should be written to save and restore the CSR IRP and AMR Conventions There are certain assumptions that the
269. he inserted instructions Avoid inserting jumps or labels into C C code because they can pro duce unpredictable results by confusing the register tracking algorithms that the code generator uses Do not change the value of a C C variable when using an asm state ment This is because the compiler does not verify such statements They are inserted as is into the assembly code and potentially can cause problems if you are not sure of their effect Do not use the asm statement to insert assembler directives that change the assembly environment Avoid creating assembly macros in C code and compiling with the g debug option The C environment s debug information and the assem bly macro expansion are not compatible es Run Time Environment 8 43 Interfacing C and C With Assembly Language 8 5 9 Accessing Assembly Language Variables From C C It is sometimes useful for a C C program to access variables or constants defined in assembly language There are several methods that you can use to accomplish this depending on where and how the item is defined a variable defined in the bss section a variable not defined in the bss section or a constant 8 5 9 1 Accessing Assembly Language Global Variables Accessing uninitialized variables from the bss section or a section named with usect is straightforward 1 Use the bss or usect directive to define the variable 2 When you use usect the variable is defined in
270. her op levels Optimizing Your Code 3 21 Performing Program Level Optimization pm and O3 Options Table 3 5 Special Considerations When Using the op Option Then the op If your op is Under these conditions level Not specified The O3 optimization level was specified Defaults to op2 Not specified The compiler sees calls to outside functions Reverts to op0 under the O3 optimization level Not specified Main is not defined Reverts to op0 op1 or op2 No function has main defined as an entry Reverts to op0 point and functions are not identified by the FUNC_EXT_CALLED pragma op1 or op2 No interrupt function is defined Reverts to op0 op1 or op2 Functions are identified by the Remains op1 or FUNC_EXT_CALLED pragma op2 0p3 Any condition Remains op3 In some situations when you use pm and O8 you must use an op option or the FUNC_EXT_CALLED pragma See section 3 6 2 Optimization Considerations When Mixing C and Assembly on page 3 22 for information about these situations 3 6 2 Optimization Considerations When Mixing C C and Assembly 3 22 If you have any assembly functions in your program you need to exercise caution when using the pm option The compiler recognizes only the C C source code and not any assembly code that might be present Because the compiler does not recognize the assembly code calls and variable modifications to C C functions the pm option optimizes ou
271. hf function asm extension asm statement described in optimized code using assembler controlling with compiler defined described options summary assembly language accessing constants global variables variables calling with intrinsics code interfacing embedding including interlisting with C C code interrupt routines module interfacing retaining output assembly listing file creation Index 2 assembly optimizer defined described directives summary 4 1344 15 invoking 4 4 using erta assembly optimizer directives call circ cproc 4 1744 20_ endproc map mdep mptr 4 4245 26 4264 28 z202 4 29 4 30_ 4 30 4 32 volatile assembly source debugging assert function assert h header described summary of functions assign variable to register assign variable to register in set assignment statement defined atan function atan2 function atan2f function atanf function atanh function atanhf function atexit function atof function atoi function atol function atoll function au assembler option autoinitialization at run time defined described defined initialization tables of variables 8 58 52 types of ax assembler option b linker option b stand alone simulator option banner suppressing base 10 logarithm base 2 logarithm big endian defined derned BEL _BIG_ENDIAN macro bit fields allocating size a
272. hich is an assembler rather than a compiler option The cross reference listing file has the same name as the source file with a crl extension The information in the cross reference listing file is displayed in the following format sym id name X filename line number column number sym id An integer uniquely assigned to each identifier name The identifier name X One of the following values X Value Meaning D Definition d Declaration not a definition M Modification A Address taken U Used C Changed used and modified in a single operation R Any other kind of reference E Error reference is indeterminate filename The source file line number The line number in the source file column number The column number in the source file Using the C C Compiler 2 35 Generating a Raw Listing File p Option 2 9 Generating a Raw Listing File pl Option The pl option generates a raw listing file that can help you understand how the compiler is preprocessing your source file Whereas the preprocessed listing file generated with the ppo ppc ppl and ppf preprocessor options shows a preprocessed version of your source file a raw listing file provides a comparison between the original source line and the preprocessed output The raw listing file has the same name as the corresponding source file with a r extension The raw listing file contains the following information Lj Each original source line
273. iagnostic identified by num as an 2 33 error pdsr num Categorizes the diagnostic identified by num as a 2 33 remark pdsw num Categorizes the diagnostic identified by num as a warning pdv Provides verbose diagnostics that display the original source with line wrap pdw Suppresses warning diagnostics errors are still 2 34 issued Using the C C Compiler 2 11 Changing the Compiler s Behavior With Options Table 2 1 Compiler Options Summary Continued j Options that control optimization Option Effect Page 00 Optimizes register usage 3 2 O1 Uses O0 optimizations and optimizes locally 3 2 02 or O Uses 01 optimizations and optimizes globally 03 Uses O2 optimizations and optimizes the file 3 3 oisize Sets automatic inlining size O3 only If size is not 3 29 specified the default is 1 ol0 or oLO Informs the optimizer that your file alters a standard library function ol1 or oL1 Informs the optimizer that your file declares a standard library function ol2 or oL2 Informs the optimizer that your file does not declare 3 18 or alter library functions Overrides the ol0 and ol1 options default on0 Disables the optimization information file 3 19 on1 Produces an optimization information file 3 19 on2 Produces a verbose optimization information file op0 Specifies that the module contains functions and variables that are called or modified from outside the source code provide
274. icts With the Assembly Optimizer Example 4 8 Dot Product From Example 4 6 Unrolled to Prevent Memory Bank Conflicts _dotp2 cproc a_0 b_0 reg a_4 b 4 sum0 suml i reg vall val2 prodl prod2 ADD 4 a 0 a 4 ADD 4 b 0 b 4 MVK 25 1 i 100 4 ZERO sumo multiply result 0 ZERO sum1 multiply result 0 mptr a_0 a 0 8 mptr a_4 a 4 8 mptr b_0 b 0 8 mptr b_ 4 b 4 8 loop trip 25 LDW a_0 2 vall load a 0 1 bankx LDW b 0 2 val2 load b 0 1 banky MPY vall val2 prod1 a 0 b 0 MPYH vall val2 prod2 a l b 1 ADD prod1l sum0 sumO sumO a 0 b 0 ADD prod2 suml1 suml suml a l b 1 LDW a_4 2 vall load a 2 3 bankx 2 LDW b 44 4 2 val2 load b 2 3 banky 2 MPY vall val2 prod1 a 2 b 2 MPYH vall val2 prod2 a 3 b 3 ADD prod1 sum0 sumO sum0O a 2 b 2 ADD prod2 suml1 suml suml a 3 b 3 i ADD 1 i i i i B loop if 0 goto loop ADD sum0 sum1 A4 compute final result return A4 endproc Using the Assembly Optimizer 4 39 Avoiding Memory Bank Conflicts With the Assembly Optimizer The goal is to find a software pipeline in which the following instructions are in parallel LDW a0 2 vall load a 0 1 bankx LDW a2 2 val2 load a 2 3 bankx 2 LDW b0 2 vall load b 0 1 banky LDW b2 2 val2 load b 2 3 banky 2 Example 4 9 Unrolled Dot Product Kernel From Example 4 7 L2 PIPED L
275. ield For more information on functional units including which machine instruction mnemonics require which functional type see the TMS320C6000 CPU and Instruction Set Reference Guide 4 3 4 Using Linear Assembly Source Comments Your comments in linear assembly can begin in any column and extend to the end of the source line A comment can contain any ASCII character including blanks Your xomments are printed in the linear assembly source listing but they do not affect the linear assembly A source statement that contains only a comment is valid If it begins in column 1 it can start with a semicolon or an asterisk Comments that begin anywhere else on the line must begin with a semicolon The asterisk identifies a comment only if it appears in column 1 The assembly optimizer schedules instructions that is it rearranges instructions Stand alone comments are moved to the top of a block of instructions Comments at the end of an instruction statement remain in place with the instruction If you enter comments on instructions in your linear assembly input file the assembly optimizer moves the comments to the output file along with additional information It attaches a 2 tuple lt x y gt to the comments to specify the iteration and cycle of the lop an instruction is on in the software pipeline The zero based number x represents the iteration the instruction is on during the first execution of the loop kernel The zero base
276. ies filename as a linear assembly source file 2 20 regardless of its extension By default the compiler and assembly optimizer treat sa files as linear assembly source files M N fofilename Identifies filename as an object code file regardless of its extension By default the compiler and linker treat obj files as object code files fpfilename Identifies filename as a C file regardless of its 2 20 extension By default the compiler treats C cpp cc and cxx files as a C files e Options that specify directories Option Effect Page fodirectory Specifies an absolute listing file directory 2 22 ffdirectory Specifies an assembly listing file and cross reference listing file directory frdirectory Specifies an object file directory 2 22 fsdirectory Specifies an assembly file directory 2 22 ftdirectory Specifies a temporary file directory 2 22 Changing the Compiler s Behavior With Options Table 2 1 Compiler Options Summary Continued f Options that are machine specific Option consultant ma mb mc me speculate _loadsn min min mo mrn msn mt mu mvn mw Effect Generates compiler Consultant Advice P 2 al aj aj o M Indicates that a specific aliasing technique is used N A a Compiles C6400 code compatible with array alignment restrictions of version 4 0 tools or C6200 C6700 object code Prevents reordering of ass
277. if necessary uint _set uint src2 uint csta uint cstb SET Sets the specified field in src2 to all 1s and returns the src2 value The beginning and ending bits of the field to be set are specified by csta and cstb respectively unit _setr unit src2 int src7 SET Sets the specified field in src2 to all 1s and returns the src2 value The beginning and ending bits of the field to be set are specified by the lower ten bits of src int_smpy int src7 int sr2 SMPY Multiplies src1 by src2 left shifts the result by 1 and returns the result If the result is NE SSMBYO Esher 10t sra SMETE 0x80000000 saturates the result to int_smpyhl int src7 int sr2 SMPYHL Ox7FFFFFFF int_smpylh int src7 int sr2 SMPYLH int __sshl int src2 uint src7 SSHL Shifts src2 left by the contents of src1 saturates the result to 32 bits and returns the result int _ssub int src7 int src2 SSUB Subtracts src2 from src1 saturates the result long _Issub int src7 long src2 and returns the result uint _sube uint src7 uint src2 SUBC Conditional subtract divide step int _sub2 int src7 int src2 SUB2 Subtracts the upper and lower halves of src2 t See the TMS320C6000 Programmer s Guide for more information from the upper and lower halves of src1 and returns the result Borrowing in the lower half subtract does not affect the upper half subtract See section 8 5 3 Using Unaligned Data and 64 Bit Values for details on manipula
278. if x is negative and i is not an integer A range error occurs if the result is too large to represent Run Time Support Functions 9 81 printf Syntax for C Syntax for C Defined in Description Syntax for C Syntax for C Defined in Description Syntax for C Syntax for C Defined in Description 9 82 Write to Standard Output include lt stdio h gt int printf const char _ format include lt cstdio gt int std printf const char _format printf c in rts src The printf function writes to the standard output device The string pointed to by _ format describes how to write the stream Write Character include lt stdio h gt int putc int _x FILE _ fp include lt cstdio gt int std pute int _x FILE _fp fputc c in rts src The putc function writes a character to the stream pointed to by _ fp Write Character to Standard Output include lt stdlib h gt int putchar int _ x include lt cstdlib gt int std putchar int _ x fputc c in rts src The putchar function writes a character to the standard output device Syntax for C Syntax for C Defined in Description Syntax for C Syntax for C Defined in Description qsort Write to Standard Output include lt stdlib h gt int puts const char _ptr include lt cstdlib gt int std puts const char _ptr fputs c in rts src The puts function writes the string pointed to by _ ptr
279. igits that represent the integer portion of the number The fractional part of the number follows then the exponent including an optional sign The first unrecognized character terminates the string The pointer that endptr points to is set to point to this character Break String into Token include lt string h gt char std strtok char str1 const char str2 include lt cstring gt char std strtok char str1 const char str2 strtok c in rts src Successive calls to the strtok function break str1 into a series of tokens each delimited by a character from str2 Each call returns a pointer to the next token After the first invocation of strtok in the example below the pointer stra points to the string excuse 0 because strtok has inserted a null character where the first space used to be In the comments the notation 0 represents the null character char stra excuse me while I kiss the sky char ptr ptr strtok stra ptr gt excuse 0 ptr strtok 0 ptr gt me 0 ptr strtok 0 ptr gt while o Syntax for C Syntax for C Defined in Description tan tanf Syntax for C Syntax for C Defined in Description Example tan tanf Convert Characters include lt string h gt size_t strxfrm register char to register const char from register size_t n include lt cstring gt size_t std strxfrm register c
280. ike them to occur that is linear assembly code Parallel instructions are illegal On the other hand the assembler assumes that you have placed instructions in a location that accounts for any delay slots due to pipeline latency Therefore it is not valid to use code written for the assembler that is scheduled assembly code or assembly optimizer output as input for the assembly optimizer E Linear assembly source statement syntax The linear assembly source programs consist of source statements that can contain assembly optimizer directives assembly language instructions and comments See section 4 3 1 for more information on the elements of a source statement Specifying registers or register sides Registers can be assigned explicitly to user symbols Alternatively symbols can be assigned to the A side or B side leaving the compiler to do the actual register allocation See section 4 3 2 for information on specifying registers Specifying the functional unit The functional unit specifier is optional in both regular assembly code and linear assembly code Specifying the functional unit enables you to control which side of the register file is used for an instruction which helps the assembly optimizer perform functional unit and register allocation This method is obsolete specifying registers is preferred See section 4 3 3 for information on specifying the functional unit Source comments The assembly optimizer atta
281. iler uses the B15 register to manage this stack B15 is the stack pointer SP which points to the next unused location on the stack The linker sets the stack size creates a global symbol _ STACK_SIZE and assigns it a value equal to the stack size in bytes The default stack size is 0x400 1024 bytes You can change the stack size at link time by using the stack option with the linker command For more information on the stack option see section 5 2 Linker Options on page 5 5 At system initialization SP is set to the first 8 byte aligned address before the end highest numerical address of the stack section Since the position of the stack depends on where the stack section is allocated the actual address of the stack is determined at link time The C C environment automatically decrements SP register B15 at the entry to a function to reserve all the space necessary for the execution of that function The stack pointer is incremented at the exit of the function to restore the stack to its state before the function was entered If you interface assembly language routines to C C programs be sure to restore the stack pointer to the state it had before the function was entered For more information about stack and stack pointer see section 8 4 Function Structure and Calling Conventions on page 8 19 _ lt _ i _ Oo lt qQoQi a Q ee mwewoe a Note Stack Ov
282. ilog Figure 3 2 Software Pipelined Loop Pipelined loop prolog The assembly optimizer also software pipelines loops For more information about the assembly optimizer see For more information about software pipelining see the 7MS320C6000 Programmer s Guide 3 4 Optimizing Software Pipelining 3 2 1 Turn Off Software Pipelining mu Option At optimization levels O2 and O3 the compiler attempts to software pipeline your loops You might not want your loops to be software pipelined for debugging reasons Software pipelined loops are sometimes difficult to debug because the code is not presented serially The mu option affects both compiled C C code and assembly optimized code Cr a2 5 ii Note Software Pipelining Can Significantly Increase Code Size To reduce code size use the ms2 or ms3 option on non performance critical code rather than the mu option These code size options not only disable software pipelining they enable code size reduction optimizations 3 2 2 Software Pipelining Information The compiler embeds software pipelined loop information in the asm file This information is used to optimize C C code or linear assembly code The software pipelining information appears as a comment in the asm file before a loop and for the assembly optimizer the information is displayed as the tool is running Example 3 1 illustrates the information that is generate
283. imple control flow constructs are reduced to conditional instructions totally eliminating the need for branches In Example 3 5 the switch statement and the state variable from this simple finite state machine example are optimized completely away leaving a streamlined series of conditional branches What Kind of Optimization Is Being Performed Example 3 5 Control Flow Simplification and Copy Propagation a C source fsm enum ALPHA BETA GAMMA OMEGA state ALPHA int input while state OMEGA switch state case ALPHA state input 0 BETA GAMMA break case BETA state input 0 GAMMA ALPHA break case GAMMA state input 0 GAMMA OMEGA break main sm 39 Optimizing Your Code 3 What Kind of Optimization Is Being Performed Example 3 5 Control Flow Simplification and Copy Propagation Continued b Compiler output FP set A15 DP set B14 SP set B15 OPT6X EXE 03 fsm if fsm opt sect text global _fsm PRR RRR RRR KR KER RK KERR KERR KKK KERR KKK KR KKK RK KERR KR RK KERR KERR KERR KERR KERR KEKE kkk kkk kkk kkk kkk FUNCTION NAME _fsm 7 Regs Modified BO B4 X ix Regs Used B0 B3 B4 oe Local Frame Size 0 Args 0 Auto 0 Save 0 byte p RRR RRR KERR KERR KKK KERR KKK KERR KK KKK KKK KKK KERR KK RK KERR KERR KERR KERR KERR KEE KERR kkk kkk kkk kkk _fsm pF J a es a ee ee a as Sa E
284. inear assembly 4 2644 28 define C C callable function in linear assem d compiler option d stand alone simulator option data flow optimizations data object representation data page pointer DP 7 11 data section defined A 3 data types C language fpos_t how stored in memory storage char and short signed and unsigned double and long double signed and unsigned enum float and int signed and unsigned long long signed and unsigned 8 17 8 12 pointer to data member pointer to member function structures and arrays Index 6 bly 4 17 4 20 procedure in linear assembly 4 2414 26 development flow diagram device adding functions diagnostic identifiers in raw li diagnostic messages assert function controlling described description 2 3142 32 warnings difftime function direct call defined directives 1 2 sting file assembly optimizer 4 1314 33 defined directories alternate for include files for include files specifying 2 16 P 28 disable automatic inline expansion conditional linking ined ee inlining linking 5 4 merge of symbolic debugging information optimization information file optimizations when using breakpoint based pro filer software pipelining symbolic debugging div function div_t data type division division functions documentation Mhil DP data page pointer duplicat
285. ined map stand alone simulator option math h header described summary of functions mb compiler option mdep assembly optimizer directive me compiler option memalign function memchr function memcmp function Index memcpy function memmove function memory alias disambiguation memory siasa 48 examples memory bank scheme interleaved four bank memory with two memory spaces memory banks avoiding conflicts with mptr 4 2144 23 memory compare function memory dependence 4 43 4 44 exceptions memory management functions calloc free malloc function minit realloc function memory map defined memory model described dynamic memory allocation large memory model sections small memory model stack variable initialization memory pool malloc function reserved space 8 3 memory reference annotating default handling by assembly optimizer memset function mh compiler option mi compiler option minit function ee mktime function ml compiler option mo compiler option modf function modff function modulus mptr assembly optimizer directive 4 2144 23 mr compiler option Index 13 Index ms compiler option ol compiler option mt compiler option 3 2614 27 on compiler option inert opi zan 3 27 h 43 op compiler option 3 2143 23 ee k2 open file function 9 62 9 65 multiply by power of 2 function ae z MUST_ITERATE pragma
286. ins the section s size etc software pipelining A technique used by the C C optimizer and the assembly optimizer to schedule instructions from a loop so that multiple iterations of the loop execute in parallel source file A file that contains C C code or assembly language code that is compiled or assembled to form an object file stand alone preprocessor A software tool that expands macros include files and conditional compilation as an independent program It also per forms integrated preprocessing which includes parsing of instructions Glossary stand alone simulator A software tool that loads and runs an executable COFF out file When used with the C I O libraries the stand alone simu lator supports all C I O functions with standard output to the screen static variable A variable whose scope is confined to a function or a program The values of static variables are not discarded when the function or program is exited their previous value is resumed when the function or program is reentered storage class An entry in the symbol table that indicates how to access a symbol structure A collection of one or more variables grouped together under a single name symbol A string of alphanumeric characters that represents an address or a value symbol table A portion of a COFF object file that contains information about the symbols that are defined and used by the file symbolic debugging The ability of a so
287. int src1 int sr2 SMPY2 Performs 16 bit multiplication between pairs of signed packed 16 bit values with an additional 1 bit left shift and saturate into a double result int _spack2 int src1 int sr2 SPACK2 Two signed 32 bit values are saturated to 16 bit values and packed into the return value uint _spacku4 int src7 int sr2 SPACKU4 Four signed 16 bit values are saturated to 8 bit values and packed into the return value int _sshvl int src2 int src1 SSHVL Shifts src2 to the left right src1 bits Saturates the f result if the shifted value is greater than int _sshvr int src2 int src1 SSHVR MAX_INT or less than MIN_INT int _sub4 int src7 int src2 SUB4 Performs 2s complement subtraction between t See the Tms320C6000 Programmer s Guide for more information pairs of packed 8 bit values See section 8 5 3 Using Unaligned Data and 64 Bit Values for details on manipulating 8 byte data quantities 8 34 Interfacing C and C With Assembly Language Table 8 4 TMS320C64x C C Compiler Intrinsics Continued Assembly C C Compiler Intrinsic Instruction Description int _subabs4 int src7 int src2 SUBABS4 Calculates the absolute value of the differences for each pair of packed 8 bit values uint _swap4 uint src SWAP4 Exchanges pairs of bytes an endian swap within each 16 bit value uint _unpkhu4 uint src UNPKHU4 Unpacks the two high unsigned 8 bit values into unsigned packed 16 bit val
288. inues compilation after preprocessing Performs preprocessing only Writes preprocessed output keeping the comments to a file with the same name as the input but with a pp extension Performs preprocessing only but instead of writing preprocessed output writes a list of dependency lines suitable for input to a standard make utility Performs preprocessing only but instead of writing preprocessed output writes a list of files included with the include directive Performs preprocessing only Writes preprocessed output with line control information line directives to a file with the same name as the input but with a pp extension Performs preprocessing only Writes preprocessed output to a file with the same name as the input but with a pp extension Mm EN my INI D w oo A Jol o S Jl 2 2 N a roe oo rm rol vo ow i 2 Q S jelle 2 30 2 30 2 30 2 29 Changing the Compiler s Behavior With Options Table 2 1 Compiler Options Summary Continued i Parser options that control diagnostics Option Effect Page pdel num Sets the error limit to num The compiler abandons 2 33 compiling after this number of errors The default is 100 pden Displays a diagnostic s identifiers along with its text pdf Generates a diagnostics information file 2 33 pdr Issues remarks nonserious warnings pds num Suppresses the diagnostic identified by num pdse num Categorizes the d
289. ion about how you can alter the way that the compiler interprets and names the extensions of assembly source and object files see section 2 3 7 on page You can use wildcard characters to compile or assemble multiple files Wildcard specifications vary by system use the appropriate form listed in your operating system manual For example to compile all of the files in a directory with the extension cpp enter the following cl6x cpp Note No Default Extension for Source Files is Assume If you list a filename called example on the command line the compiler assumes that the entire filename is example not example c No default extensions are added onto files that do not contain an extension Cn Using the C C Compiler 2 19 Changing the Compiler s Behavior With Options 2 3 5 Changing How the Compiler Program Interprets Filenames fa fc fg fl 2 20 fo and fp Options You can use options to change how the compiler interprets your filenames If the extensions that you use are different from those recognized by the compiler you can use the fa fc fl fo and fp options to specify the type of file You can insert an optional space between the option and the filename Select the appropriate option for the type of file you want to specify fafilename for an assembly language source file fcfilename for a C source file flfilename for a linear assembly file fofilename for an object file
290. ions return the hyperbolic cosine of a floating point number x A range error occurs errno is set to the value of EDOM if the magnitude of the argument is too large These functions are equivalent to eX e X 2 but are computationally faster and more accurate double x y x Y 0 0 cosh x return value 1 0 Run Time Support Functions 9 53 cot cotf cot cotf Syntax for C Syntax for C Defined in Description coth cothf Syntax for C Syntax for C Defined in Description 9 54 Polar Cotangent define _Tl ENHANCED_MATH_H 1 include lt math h gt double cot double x float cotf float x define _Tl ENHANCED_MATH_H 1 include lt cmath gt double std cot double x float std cotf float x cot c and cotf c in rts src The cot and cotf functions return the cotangent of a floating point argument x which must not equal 0 0 When x is 0 0 errno is set to the value of EDOM and the function returns the most positive number Hyperbolic Cotangent define _TlENHANCED_MATH_H 1 include lt math h gt double coth double x float cothf float x define _Tl ENHANCED_ MATH_H 1 include lt cmath gt double std coth double x float std cothf float x coth c and cothf c in rts src The coth and cothf functions return the hyperbolic cotangent of a floating point argument x The magnitude of the return value is 1 0 Syntax for C Syntax for C Defined in
291. ions work together to provide pseudorandom sequence generation Lj The rand function O RAND_MAX Lj The srand function sets the value of seed so that a subsequent call to the rand function produces a new sequence of pseudorandom numbers The srand function does not return a value returns pseudorandom integers in the range If you call rand before calling srand rand generates the same sequence it would produce if you first called srand with a seed value of 1 If you call srand with the same seed value rand generates the same sequence of numbers Change Heap Size include lt stdlib h gt void realloc void packet size_t size include lt cstdlib gt void std realloc void packet size_t size memory c in rts src The realloc function changes the size of the allocated memory pointed to by packet to the size specified in bytes by size The contents of the memory space up to the lesser of the old and new sizes is not changed remove Syntax for C Syntax for C Defined in Description Syntax for C Syntax for C Defined in Description rename _j If packet is 0 realloc behaves like malloc _j If packet points to unallocated space realloc takes no action and returns 0 _ If the space cannot be allocated the original memory space is not changed and realloc returns 0 Lj If size 0 and packet is not null realloc frees the space that packet points to If the entire object must be
292. is not available the function returns 1 If timer is not a null pointer the function also assigns the return value to the object that timer points to For more information about the functions and types that the time h ctime header declares and defines see section 9 3 18 Time Functions time h ctime on pagel 9 27 Note The time Function Is Target System Specific The time function is target system specific so you must write your own time function Syntax for C Syntax for C Defined in Description Syntax for C Syntax for C Defined in Description Syntax for C Syntax for C Defined in Description toascii Create Temporary File include lt stdlib h gt FILE tmpfile void include lt cstdlib gt FILE std tmpfile void tmpfile c in rts src The tmpfile function creates a temporary file Generate Valid Filename include lt stdlib h gt char tmpnam char _s include lt cstdlib gt char std tmpnam char _s tmpnam c in rts src The tmpnam function generates a string that is a valid filename Convert to ASCII include lt ctype h gt int toascii int c include lt cctype gt int std toascii int c toascii c in rts src The toascii function ensures that c is a valid ASCII character by masking the lower seven bits There is also an equivalent macro call _toascii Run Time Support Functions 9 107 tolower toupper tolower toupper Syntax for C Synt
293. ison would be used to determine which version should be executed for i 0 i lt N i i is the trip counter foo N if N lt 3 for i 0 i lt N i Unpipelined version else for i 0 1 lt N i Pipelined version foo 50 Execute software pipelined loop foo 2 Execute loop unpipelined Reducing Code Size ms Option You may be able to help the compiler avoid producing redundant loops with the use of pm O3 see section 3 6 on page 3 20 jor the use of the MUST_ITERATE pragma see section 7 7 14 on page Note Turning Off Redundant Loops Specifying any ms option turns off redundant loops 3 4 Reducing Code Size ms Option When using the O or On option you are telling the compiler to optimize your code The higher the value of n the more effort the compiler invests in optimizing your code However you might still need to tell the compiler what your optimization priorities are By default when O2 or O3 is specified the compiler optimizes primarily for performance Under lower optimization levels the priorities are compilation time and debugging ease You can adjust the priorities between performance and code size by using the code size flag msn The ms0 ms1 ms2 and ms3 options increasingly favor code size over performance It is recommended that a code size flag not be used with the most performance critical code Using ms0 or m
294. ither access does not have memory bank information then they do not conflict 2 If both accesses do not have the same base then they conflict 3 The offset stride access width and iteration delta are used to determine if a memory bank conflict will occur The assembly optimizer uses a straightforward analysis of the access patterns and determines if they ever access the same relative bank The stride and offset values are always expressed in bytes The iteration delta is the difference in the loop iterations of the memory references being scheduled in the software pipeline For example given three instructions A B C and a software pipeline with a single cycle kernel then A and C have an iteration delta of 2 PRP a PRP a ORP Memory Alias Disambiguation 4 6 Memory Alias Disambiguation Memory aliasing occurs when two instructions can access the same memory location Such memory references are called ambiguous Memory alias disambiguation is the process of determining when such ambiguity is not possible When you cannot determine whether two memory references are ambiguous you presume they are ambiguous This is the same as saying the two instructions have a memory dependence between them Dependences between instructions constrain the instruction schedule including the software pipeline schedule In general the fewer the dependences the greater freedom you have in choosing a schedule and the better the final schedule pe
295. its float 32 bits double 64 bits long double 64 bits pointers 32 bits references pointer to data members Representation ASCII ASCII 2s complement Binary 2s complement Binary 2s complement Binary 2s complement Binary 2s complement IEEE 32 bit IEEE 64 bit IEEE 64 bit Binary t Figures are minimum precision Range Minimum Maximum 128 127 0 255 32 768 32 767 0 65 535 2 147 483 648 0 549 755 813 888 0 9 223 372 036 854 775 808 2 147 483 648 1 175 494e 38t 2 22 507 385e 308t 2 22 507 385e 308t 0 2 147 483 647 4 294 967 295 549 755 813 887 1 099 511 627 775 9 223 372 036 854 775 807 18 446 744 073 709 551 615 2 147 483 647 3 40 282 346e 38 1 79 769 313e 308 1 79 769 313e 308 OxFFFFFFFF 7 4 Keywords Keywords The C6000 C C compiler supports the standard const register restrict and volatile keywords In addition the C6000 C C compiler extends the C C language through the support of the cregister interrupt near and far keywords 7 4 1 The const Keyword The TMS320C6000 C C compiler supports the ISO standard keyword const This keyword gives you greater optimization and control over allocation of storage for certain data objects You can apply the const qualifier to the definition of any variable or array to ensure that its value is not altered If you define an object as far const the const section allocates storage for the object The const data storage
296. ive SSS ss Using the Assembly Optimizer 4 43 Memory Alias Disambiguation 4 6 4 Using the mdep Directive to Identify Specific Memory Dependences You can use the mdep directive to identify specific memory dependences by annotating each memory reference with a name and using those names with the mdep directive to indicate the actual dependence Annotating a memory reference requires adding information right next to the memory reference in the assembly stream Include the following Immediately after a memory reference symbol The symbol has the same syntax restrictions as any assembly symbol For more information about symbols see the TMS320C6000 Assembly Language Tools User s Guide It is in the same name space as the symbolic registers You cannot use the same name for a symbolic register and annotating a memory reference Example 4 11 Annotating a Memory Reference 4 44 LDW pl 1d1 inpl name memory reference 1d1 other code STW outp2 p2 st1 name memory reference st1 The directive to indicate a specific memory dependence in the previous example is as follows mdep l1di stl This means that whenever Id1 accesses memory at location X some later time in code execution st1 may also access location X This is equivalent to adding a dependence between these two instructions In terms of the software pipeline these two instructions must remain in the same order The Id1 reference
297. l op2 also an indirect call Here are other valid examples that use the call syntax Call fir x h y void function call minimal no arguments call sum vecsum a b returns an int call hi lo _atol string returns a long Since you can use machine register names anywhere you can use symbolic registers it may appear you can change the function calling convention For example call A6 compute It appears that the result is returned in A6 instead of A4 This is incorrect Using machine registers does not override the calling convention After returning from the compute function with the returned result in A4 a MV instruction transfers the result to A6 Here is a complete call example _main puts rand _ltoa const string The random value returned is 0 string 10 0 10 newline charbuf 20 random value bufptr random value stringl stringl ran val hi ran val lo _rand bufptr bufptr get a random value load address of stringl _puts bufptr random_value ran_val_lo ran_val_lo 31 ran_val_hi _ltoa ran_val_hi ran_val_lo bufptr _puts bufptr string2 bufptr string2 bufptr _puts bufptr print out stringl sign extend random value convert it to a string print out the random value load address of string2 print out a newline Syntax Description Example cproc endproc Syntax Description cproc endp
298. l be executed J Uneven resources If the number of resources to do a particular operation is odd unrolling the loop can be beneficial If a loop requires 3 multiplies then a minimum iteration interval of 2 cycles is required to execute this If the loop was unrolled 6 multiplies could be evenly partitioned across the A and B side having a minimum ii of 3 cycles giving improved performance J Larger outer loop overhead in nested loop In cases where the inner loop count of a nested loop is relatively small the time to execute the outer loop can start to become a large percentage of the total execution time For cases where this significantly degrades overall loop performance unrolling the inner loop may be desired Lj There are memory bank conflicts In cases where the compiler generates two memory accesses in one cycle and those accesses are either 8 bytes apart on a C620x device 16 bytes apart on a C670x device or 32 bytes apart on a C640x device and both accesses reside within the same memory block a memory bank stall will occur Memory bank conflicts can be completely avoided by either placing the two accesses in different memory blocks or by writing linear assembly and using the mpir directive to control memory banks J T address paths are resource bound T address paths defined the number of memory accesses that must be sent out on the address bus each loop iteration If these are the resource bound for the loop it i
299. l int c int isdigit int c int isgraph int c int islower int c int isprint int c int ispunct int c int isspace int c int isupper int c int isxdigit int c lt lt include lt cctype gt int std int std int std int std isalnum int c isalpha int c islower int c isprint int c int std isascii int c int std ispunct int c int std iscntrl int c int std isspace int c int std isdigit int c int std isupper int c int std isgraph int c int std isxdigit int c isxxx c and ctype c in rts src Also defined in ctype h cctype as macros Run Time Support Functions 9 69 SXXX Description These functions test a single argument c to see if it is a particular type of character alphabetic alphanumeric numeric ASCII etc If the test is true the function returns a nonzero value if the test is false the function returns 0 The character typing functions include isalnum Identifies alphanumeric ASCII characters tests for any character for which isalpha or isdigit is true isalpha Identifies alphabetic ASCII characters tests for any character for which islower or isupper is true isascii Identifies ASCII characters any character 0 127 iscntrl Identifies control characters ASCII characters 0 31 and 127 isdigit Identifies numeric characters between 0 and 9 inclusive isgraph Identifies any nonspace character islower Identifies lowercase alphabetic ASCII
300. label of a proc directive _func proc B func lt illegal endproc Using the Assembly Optimizer 4 25 reg Syntax Description 4 26 J An if endif loop must be entirely inside or outside of a proc or cproc region It is not alllowed to have part of an if endif loop inside of a proc or cproc region and the other part of the if endif loop outside of the proc or cproc region Here are two examples of legal if endif loops The first loop is outside a cproc region the second loop is inside a proc region Lif cproc endproc endif proc sift endif endproc Here are two examples of if endif loops that are partly inside and partly outside of a cproc or proc region Jif cproc endif endproc proc wif else endproc endif Declare Variables reg variable variableo The reg directive allows you to use descriptive names for values that are stored in registers The assembly optimizer chooses a register for you such that its use agrees with the functional units chosen for the instructions that operate on the value The reg directive is valid within procedures only that is within occurrences of the proc and endproc directive pair or the cproc and endproc directive pair Declaring register pairs explicitly is optional The assembly optimizer will derive when registers are used as pairs Here is an example of declaring a register pair reg A6 A7 Example 1 Exampl
301. le volatile symbol symbolo The volatile directive allows you to designate memory references as volatile Volatile loads and stores are not deleted Volatile loads and stores are not reordered with respect to other volatile loads and stores If the volatile directive references a memory location that may be modified during an interrupt compile with the mi1 option to ensure interruptibility of all code referencing the volatile memory location The st and Id memory references are designated as volatile volatile st ld STW W X st volatile store STW U V LDW Y ld Z volatile load Avoiding Memory Bank Conflicts With the Assembly Optimizer 4 5 Avoiding Memory Bank Conflicts With the Assembly Optimizer The internal memory of the C6000 family varies from device to device See the appropriate device data sheet to determine the memory spaces in your particular device This section discusses how to write code to avoid memory bank conflicts Most C6000 devices use an interleaved memory bank scheme as shown in Figure 4 1 Each number in the diagram represents a byte address A load byte LDB instruction from address 0 loads byte 0 in bank 0 A load halfword LDH from address 0 loads the halfword value in bytes 0 and 1 which are also in bank 0 A load word LDW from address 0 loads bytes 0 through 3 in banks 0 and 1 Because each bank is single ported memory only one access to each bank is allowed per cycle Two ac
302. ler reads in input looking for mangled names All unmangled text is copied to output unaltered All mangled names are demangled before being copied to output Topic Page 11 1 Invoking the C Name Demangler 0eeeeeeeeeeeee 11 2 11 2 C Name Demangler Options 0 c cece cece eens 11 2 11 3 Sample Usage of the C Name Demangler 11 3 Invoking the C Name Demangler 11 1 Invoking the C Name Demangler The syntax for invoking the C name demangler is dem6x options filenames dem6x Command that invokes the C name demangler options Options affect how the name demangler behaves Options can appear anywhere on the command line Options are discussed in section 11 2 filenames Text input files such as the assembly file output by the compiler the assembler listing file and the linker map file If no filenames are specified on the command line dem6x uses standard in By default the C name demangler outputs to standard out You can use the o file option if you want to output to a file 11 2 C Name Demangler Options The following options apply only to the C name demangler h Prints a help screen that provides an online summary of the C name demangler options 0 file Outputs to the given file rather than to standard out u Specifies that external names do not have a C prefix V Enables verbose mode outputs a banner Sample Usag
303. les The following example assembles the file fit rrr and creates an object file named fit o cl6 x ea rrr eo o fit rrr The period in the extension and the space between the option and the extension are optional You can also write the example above as cl6 x earrr eoo fit rrr Using the C C Compiler 2 21 Changing the Compiler s Behavior With Options 2 3 7 Specifying Directories fb ff fr fs and ft Options 2 22 By default the compiler program places the object assembly and temporary files that it creates into the current directory If you want the compiler program to place these files in different directories use the following options fbdirectory ffdirectory frdirectory fsdirectory ftdirectory Specifies the destination directory for absolute listing files The default is to use the same directory as the object file directory To specify an absolute listing file directory type the directory s pathname on the command line after the fb option cl6x fb d abso list Specifies the destination directory for assembly listing files and cross reference listing files The default is to use the same directory as the object file directory To specify an assembly cross reference listing file directory type the directory s pathname on the command line after the ff option cl6x ff d listing Specifies a directory for object files To specify an object file directory type the directo
304. lobal variables because they might not be preinitialized to 0 for the same reasons discussed in section 7 9 For example const int zero may not be initialized to 0 However the initialization of const global and static variables is different because these variables are declared and initialized in a section called const For example const int zero 0 guaranteed to be 0 This corresponds to an entry in the const section s BEGE 1 CONnst _ zero word 0 This feature is particularly useful for declaring a large table of constants because neither time nor space is wasted at system startup to initialize the table Additionally the linker can be used to place the const section in ROM You can use the DATA_SECTION pragma to put the variable in a section other than const For example the following C code pragma DATA SECTION var mysect const int zero 0 is compiled into this assembly code sect mysect __ zero word 0 TMS320C6000 C C Language Implementation 7 35 Changing the ISO C Language Mode 7 10 Changing the ISO C Language Mode The pk pr and ps options let you specify how the C C compiler interprets your source code You can compile your source code in the following modes Li Normal ISO mode Lj K amp R C mode _j Relaxed ISO mode LJ Strict ISO mode The default is normal ISO mode Under normal ISO mode most ISO violations are emitted as errors Strict ISO viola
305. lock pointed to by the extra argument In this way the caller can be smart about telling the called function where to return the structure For example in the statement s f x where s is a structure and f is a function that returns a structure the caller can actually make the call as f amp s x The function f then copies the return structure directly into s performing the assignment automatically Run Time Environment 8 21 Function Structure and Calling Conventions If the caller does not use the return structure value an address value of 0 can be passed as the first argument This directs the called function not to copy the return structure You must be careful to declare functions properly that return structures both at the point where they are called so that the extra argument is passed and at the point where they are declared so the function knows to copy the result 7 Any register numbered A10 to A15 or B10 to B15 that was saved in step 3 is restored 8 If A15 was used as a frame pointer FP the old value of A15 is restored from the stack The space allocated for the function in step 1 is reclaimed at the end of the function by adding a constant to register B15 SP 9 The function returns by jumping to the value of the return register B3 or the saved value of the return register 8 4 3 Accessing Arguments and Local Variables 8 22 A function accesses its stack arguments and local nonregister variables i
306. lone Simulator Version X X Copyright c 1989 2000 by Texas Instruments Incorporated OPTIONS C6 xxx Memory Hierarchy Modeling Simulator OPTIONS REVISION 2 OPTIONS MAP 1 DEFAULT MEMORY MAPPING WARNING Ensure that map modes for linker cmd file and load6 x are same NOTE For details on above options please refer to the readme 1st Loading t out 174 Symbols loaded Done Interrupt to abort Hello world Time 7593 cycles NORMAL COMPLETION 98705 cycles Using the Stand Alone Simulator 6 3 Stand Alone Simulator Options 6 2 Stand Alone Simulator Options 6 4 Following are the options that control the stand alone simulator along with descriptions of their effects a b d d f value h i map value O Xxx q Enables data memory bank conflict checking Initializes all memory in the bss section data with Os The C language ensures that all uninitialized static storage class variables are initialized to 0 at the beginning of the program Because the compiler does not set uninitialized variables the b option enables you to initialize these variables Enables verbose mode Prints internal status messages describing I O at a low level Use dd for more verbose information Initializes all memory in the bss section data with a specified value The value is a 32 bit constant up to 8 hexadecimal digits For example load x f Oxabcdabcd will fill the Oss sec
307. loop counters are non zero Loop invariant means a value of an expression doesn t change within the loop If your code does not contain any of the aliasing techniques described above you should use the mt option to improve the optimization of your code However you must use discretion with the mt option unexpected results may occur if these aliasing techniques appear in your code and the mt option is used 3 7 3 Using the mt Option With the Assembly Optimizer The mt option allows the assembly optimizer to assume there are no memory aliases in your linear assembly i e no memory references ever depend on each other However the assembly optimizer still recognizes any memory dependences you point out with the mdep directive For more information about the mdep directive see pagel 4 21 and 4 44 Optimizing Your Code 3 27 Prevent Reordering of Associative Floating Point Ops Use Caution With asm Statements in Optimized Code 3 8 Prevent Reordering of Associative Floating Point Operations The compiler freely reorders associative floating point operations If you do not wish to have the compiler reorder associative floating point operations use the mc option Specifying the mc option may decrease performance 3 9 Use Caution With asm Statements in Optimized Code 3 28 You must be extremely careful when using asm inline assembly statements in optimized code The compiler rearranges code segments uses registers
308. luates loop conditionals at the bottom of loops saving an extra branch out of the loop In many cases the initial entry conditional check and the branch are optimized out 3 13 10 Register Variables The compiler helps maximize the use of registers for storing local variables parameters and temporary values Accessing variables stored in registers is more efficient than accessing variables in memory Register variables are particularly effective for pointers see Example B 4 bn page 3 36 3 13 11 Register Tracking Targeting The compiler tracks the contents of registers to avoid reloading values if they are used again soon Variables constants and structure references such as a b are tracked through straight line code Register targeting also computes expressions directly into specific registers when required as in the case of assigning to register variables or returning values from functions see Example 3 8 on page 3 44 What Kind of Optimization Is Being Performed Example 3 8 Register Tracking Targeting a C source int x y main x 1 Y Xi b Compiler output FP set A15 DP set B14 SP set B15 opt x 02 t3 if t3 opt Sect text global _main _main LDW D2 B14 _x B4 NOP 1 B S2 B3 NOP 2 ADD L2 1 B4 B4 STW D2 B4 B14 _y STW D2 B4 B14 _x BRANCH OCCURS global X bss _x 4 4 global _y bss _y 4 4 3 13 12 Software Pipelining
309. lue from fgetpos on the same stream Syntax for C Syntax for C Defined in Description Syntax for C Syntax for C Defined in Description Syntax for C Syntax for C Defined in Description getc Get Current File Position Indicator include lt stdio h gt long ftell FILE _fp include lt cstdio gt long std ftell FILE _fp ftell c in rts src The ftell function gets the current value of the file position indicator for the stream pointed to by _ fp Write Block of Data include lt stdio h gt size_t fwrite const void _ptr size_t _size size_t count register FILE fp include lt cstdio gt size_t std fwrite const void _ptr size_t _size size_t _count register FILE _fp fwrite c in rts src The fwrite function writes a block of data from the memory pointed to by _ ptr to the stream that _fp points to Read Next Character include lt stdio h gt int getc FILE _fp include lt cstdio gt int std getc FILE _fp fgetc c in rts src The getc function reads the next character in the file pointed to by _ fp Run Time Support Functions 9 67 getchar Syntax for C Syntax for C Defined in Description Syntax for C Syntax for C Defined in Description Syntax for C Syntax for C Defined in Description 9 68 Read Next Character From Standard Input include lt stdio h gt int getchar void include lt cstdio gt int std g
310. ly language output of the compiler If the optimizer is not invoked C C source statements are interlisted with the assembly language output of the compiler which allows you to inspect the code generated for each C C statement The s option implies the k option The s option can have a negative performance and or code size impact SS Invokes the interlist feature which interweaves original C C source with compiler generated assembly language The interlisted C statements may appear to be out of sequence You can use the interlist feature with the optimizer by combining the os and ss options For more information see section 2 13 Using the Interlist feature on page B 46 The ss option can have a negative performance and or code size impact Uname Undefines the predefined constant name This option overrides any D options for the specified constant Z Runs the linker on the specified object files The z option and its parameters follow all other options on the command line All arguments that follow z are passed to the linker For more information see section 5 1 Invoking the Linker Through the Compiler on page 5 2 2 3 2 Selecting Target CPU Version mv Option Select the target CPU version using the last four digits of the TMS320C6000 part number This selection controls the use of target specific instructions and alignment such as mv6701 or mv6412 Alternatively you can also specify the family of
311. mine that unrolling by a factor of nis safe In order to increase the chances the loop is unrolled the compiler needs to know certain properties _j The loop iterates a multiple of n times This information can be specified to the compiler via the multiple argument in the MUST_ITERATE pragma QJ The smallest possible number of iterations of the loop OJ The largest possible number of iterations of the loop The compiler can sometimes obtain this information itself by analyzing the code However sometimes the compiler can be overly conservative in its assumptions and therefore generates more code than is necessary when unrolling This can also lead to not unrolling at all Furthermore if the mechanism that determines when the loop should exit is complex the compiler may not be able to determine these properties of the loop In these cases you must tell the compiler the properties of the loop by using the MUST_ITERATE pragma Specifying pragma UNROLL 1 asks that the loop not be unrolled Automatic loop unrolling also is not performed in this case If multiple UNROLL pragmas are specified for the same loop it is undefined which unroll pragma is used if any Generating Linknames 7 8 Generating Linknames The compiler transforms the names of externally visible identifiers when creating their linknames The algorithm used depends on the scope within which the identifier is declared For objects and C functions an underscore _
312. mount as padding is used to align data onto the correct bank For C6200 the code in Example 7 5 guarantees that array x begins at an address ending in 4 or c in hexadecimal and that array y begins at an address ending in 4 or c The alignment for array y affects its stack placement Array z is placed in the z_sect section and begins at an address ending in 0 or 8 Example 7 5 Using the DATA_LMEM_BANK Pragma pragma DATA MEM BANK x 2 short x 100 pragma DATA MEM BANK z 0 pragma DATA SECTION z z sect short z 100 void main pragma DATA MEM BANK y 2 short y 100 TMS320C6000 C C Language Implementation 7 21 Pragma Directives 7 7 4 The DATA_SECTION Pragma The DATA_SECTION pragma allocates space for the symbol in a section named section name The syntax of the pragma in C is pragma DATA_SECTION symbol section name The syntax of the pragma in C is pragma DATA_SECTION section name The DATA_SECTION pragma is useful if you have data objects that you want to link into an area separate from the bss section If you allocate a global variable using a DATA_SECTION pragma and you want to reference the variable in C code you must declare the variable as extern far Example 7 6 demonstrates the use of the DATA_SECTION pragma Example 7 6 Using the DATA_SECTION Pragma 7 22 a C source file pragma DATA SECTION buf
313. moved to allocate more space realloc returns a pointer to the new space Any memory freed by this operation is deallocated If an error occurs the function returns a null pointer 0 The memory that calloc uses is in a special memory pool or heap The constant __SYSMEM_SIZE defines the size of the heap as 2K bytes You can change this amount at link time by invoking the linker with the heap option and specifying the desired size of the heap in bytes directly after the option For more information see section 8 1 38 Dynamic Memory Allocation on page 8 5 Remove File include lt stdlib h gt int remove const char _file include lt cstdlib gt int std remove const char _file remove c in rts src The remove function makes the file pointed to by _ file no longer available by that name Rename File include lt stdlib h gt int rename const char old_name const char new_name include lt cstdlib gt int std rename const char old_name const char new_name lowlev c in rts src The rename function renames the file pointed to by old_name The new name is pointed to by new_name Run Time Support Functions 9 85 rewind Syntax for C Syntax for C Defined in Description round roundf Syntax for C Syntax for C Defined in Description Example 9 86 Position File Position Indicator to Beginning of File include lt stdlib h gt int rewind register FILE _fp include lt c
314. mpact on the instruction schedule than a bank conflict It is best to keep these two topics separate a 5 ssSI Ss Chapter 5 Linking C C Code The C C compiler and assembly language tools provide two methods for linking your programs J You can compile individual modules and link them together This method is especially useful when you have multiple source files _j You can compile and link in one step This method is useful when you have a single source module This chapter describes how to invoke the linker with each method It also discusses special requirements of linking C C code including the run time support libraries specifying the type of initialization and allocating the program into memory For a complete description of the linker see the TMS320C6000 Assembly Language Tools User s Guide Topic Page 5 1 Invoking the Linker Through the Compiler z Option 5 2 52s inkewOpllons eaten eee een E 5 5 5 3 Controlling the Linking Process 00eeeeeeeeeeeeeeeee 5 1 Invoking the Linker Through the Compiler z Option 5 1 5 1 1 5 2 Invoking the Linker Through the Compiler z Option This section explains how to invoke the linker after you have compiled and assembled your programs as a separate step or as part of the compile step Invoking the Linker as a Separate Step This is the general syntax for linking C C programs as a separate step cl6x z
315. must always occur before the st1 reference the instructions cannot even be scheduled in parallel It is important to note the directional sense of the directive from Id1 to st1 The opposite from st1 to Id1 is not implied In terms of the software pipeline while every Id1 must occur before every st1 it is still legal to schedule the Id1 from iteration n 1 before the st1 from iteration n Memory Alias Disambiguation Example 4 12 is a picture of the software pipeline with the instructions from two different iterations in different columns In the actual instruction sequence instructions on the same horizontal line are in parallel Example 4 12 Software Pipeline Using mdep Id1 st1 iteration n iteration n 1 LDW ldi STW st1 STH stl If that schedule does not work because the iteration n st1 might write a value the iteration n 1 Idi should read then you must note a dependence relationship from st1 to Id1 mdep sti tai Both directives together force the software pipeline shown in Example 4 13 Example 4 13 Software Pipeline Using mdep st1 Id1 and mdep ld1 st1 iteration n iteration n 1 LDW 1d1 STW st1 LDW 1d1 STW sti Indexed addressing base index is a good example of an addressing mode where you typically do not know anything about the relative sequence of the memory accesses except they sometimes access the same location To correctly model this
316. n Time Support Functions 9 101 strspn Syntax for C Syntax for C Defined in Description Example Syntax for C Syntax for C Defined in Description Example 9 102 Find Number of Matching Characters include lt string h gt size_t strspn register const char string const char chs include lt cstring gt size_t std strspn register const char string const char chs strspn c in rts src The strspn function returns the length of the initial segment of string which is entirely made up of characters in chs If the first character of string is not in chs the strspn function returns 0 char stra who is there char strb abcdefghijklmnopgrstuvwxyz char stre abcdefg size_t length length strspn stra strb length 3 length strspn stra strc length 0 Find Matching String include lt string h gt char strstr register const char string1 const char string2 include lt cstring gt char std strstr register const char string1 const char string2 strstr c in rts src The strstr function finds the first occurrence of string2 in string1 excluding the terminating null character If strstr finds the matching string it returns a pointer to the located string if it does not find the string it returns a null pointer If string2 points to a string with length 0 strstr returns string1 char stra so what do you want for nothing
317. n be in ROM and stores it in the bss section The compiler defines the global symbol bss and assigns bss the value of the starting address of the bss section m The far section reserves space for global and static variables that are declared far m The stack section allocates memory for the system stack This memory passes arguments to functions and allocates local variables m The sysmem section reserves space for dynamic memory allocation The reserved space is used by the malloc calloc and realloc functions If a C C program does not use these functions the compiler does not create the sysmem section a Note Use Only Code in Program Memory With the exception of text the initialized and uninitialized sections cannot be allocated into internal program memory The assembler creates the default sections text bss and data The C C compiler however does not use the data section You can instruct the compiler to create additional sections by using the CODE_SECTION and DATA_SECTION pragmas see sections 7 7 1 The CODE_ SECTION Pragma on page 7 19 and 7 7 4 The DATA_SECTION Pragma on page Run Time Environment 8 3 Memory Model 8 1 2 C C System Stack 8 4 The C C compiler uses a stack to J Save function return addresses Lj Allocate local variables Pass arguments to functions 1 Save temporary results The run time stack grows from the high addresses to the low addresses The comp
318. n df nL e ide ee Sota daa nals a Gale ene 5 3 Controlling the Linking Process 0000 c ete cece eee eee ees 5 3 1 Linking With Run Time Support Libraries 0000 cece eee eee 5 3 2 Run Time Initialization 2 0 0 cece etn eniai 5 3 3 Global Object Constructors asss cect eee ees 5 3 4 Specifying the Type of Initialization 0 cece ees 5 3 5 Specifying Where to Allocate Sections in Memory 00005 5 3 6 A Sample Linker Command File 0000 cece eee eee eee es 5 3 7 Using Function Subsections mo Compiler Option Using the Stand Alone Simulator 00c ee ee eee eee eee Describes how to invoke the stand alone simulator and provides an example 6 1 Invoking the Stand Alone Simulator 000000 c cece eee ees 6 2 Stand Alone Simulator Options 0000s 6 3 Passing Arguments to a Program Through the Loader 0 eee eens 6 3 1 Determining Which Arguments Effect Which Program 6 3 2 Reserving Target Memory to Store the Arguments args Linker Option 0000s cece eee eens 6 4 Using the Profiling Capability of the Stand Alone Simulator 6 5 Selecting Silicon Revision to Simulate rev Option 0 00 cece eee 6 6 Stand Alone Simulator Example 000000 cece cece es Contents 7 TMS320C6000 C C Language Implementation 000ee cece eee eee eee 7 1 Discusses the speci
319. n flushes the stream that _fp points to and closes the file associated with that stream Test EOF Indicator include lt stdio h gt int feof FILE _fp include lt cstdio gt int std feof FILE _fp feof c in rts src The feof function tests the EOF indicator for the stream pointed to by _ fp Run Time Support Functions 9 59 ferror Syntax for C Syntax for C Defined in Description Syntax for C Syntax for C Defined in Description Syntax for C Syntax for C Defined in Description Syntax for C Syntax for C Defined in Description 9 60 Test Error Indicator include lt stdio h gt int ferror FILE _fp include lt cstdio gt int std ferror FILE _fp ferror c in rts src The ferror function tests the error indicator for the stream pointed to by _ fp Flush I O Buffer include lt stdio h gt int fflush register FILE _fp include lt cstdio gt int std fflush register FILE _fp fflush c in rts src The fflush function flushes the I O buffer for the stream pointed to by _ fp Read Next Character include lt stdio h gt int fgetc register FILE _fp include lt cstdio gt int std fgetc register FILE _fp fgetc c in rts src The fgetc function reads the next character in the stream pointed to by _ fp Store Object include lt stdio h gt int fgetpos FILE _fp fpos_t pos include lt cstdio gt int std fgetpos FILE _fp fpos_t pos fgetpos
320. n object library according to the run time model specified by the command line options The optional object library name If you do not specify a name for the library mk6x uses the name of the source archive and appends a ib suffix For each source archive file specified a corresponding object library file is created You cannot build an object library from multiple source archive files The mk6x utility runs the compiler program on each source file in the archive to compile and or assemble it Then the utility collects all the object files into the object library All the tools must be in your PATH environment variable The utility ignores the environment variables C6X_C_OPTION C_OPTION C6X_C_DIR and C_DIR Library Build Utility 10 3 Library Build Utility Options 10 3 Library Build Utility Options Most of the options that are included on the command line correspond directly to options of the same name used with the compiler assembler linker and compiler The following options apply only to the library build utility C h k V 10 4 Extracts C source files contained in the source archive from the library and leaves them in the current directory after the utility completes execution Uses header files contained in the source archive and leaves them in the current directory after the utility completes execution Use this option to install the run time support header files from the rts src archive that is ship
321. n section 5 1 1 Invoking the Linker As a Separate Step All arguments that precede z on the command line are compiler arguments These arguments can be C C source files assembly files linear assembly files or compiler options These arguments are described in section 2 2 Invoking the C C Compiler on page 2 4 You can compile and link a C C program consisting of modules prog1 c prog2 c and prog3 c with an executable filename of prog out with the command cl6 x progl c prog2 c prog3 c Zz C O prog out 1l rts6200 lib Note Order of Processing Arguments in the Linker The order in which the linker processes arguments is important The compiler passes arguments to the linker in the following order 1 Object filenames from the command line 2 Arguments following the z option on the command line 3 Arguments following the z option from the C OPTION or C6X_C_OPTION environment variable eee sss Linking C C Code 5 3 Disabling the Linker c Compiler Option 5 1 3 Disabling the Linker c Compiler Option 5 4 You can override the z option by using the c compiler option The c option is especially helpful if you specify the z option in the C_OPTION or C6X_C_OPTION environment variable and want to selectively disable linking with the c option on the command line The c linker option has a different function than and is independent of the c compiler option By default the compiler uses th
322. n the corresponding position in the return value nta minalint sret See MIN Values can be 16 bit signed or 8 bit unsigned uint _maxu4 uint src1 uint src2 MAX4 uint _minu4 uint src7 uint src2 MINU4 t See the Tms320C6000 Programmer s Guide for more information See section 8 5 3 Using Unaligned Data and 64 Bit Values for details on manipulating 8 byte data quantities 8 32 Interfacing C and C With Assembly Language Table 8 4 TMS320C64x C C Compiler Intrinsics Continued Assembly C C Compiler Intrinsic Instruction Description ushort amp _mem2 void ptr LDB LDB Allows unaligned loads and stores of 2 bytes to STB STB memoryt const ushort amp _mem2_const const LDB LDB Allows unaligned loads of 2 bytes to memoryt void ptr uint amp _mem4 void ptr LDNW Allows unaligned loads and stores of 4 bytes to STNW memoryt const uint amp _mem4_const const LDNW Allows unaligned loads of 4 bytes from memoryt void ptr long long amp _mem8 amp void ptr LDNDW Allows unaligned loads and stores of 8 bytes to STNDW memoryt const long long amp _mem8_const const LDNDW Allows unaligned loads of 8 bytes from memoryt void ptr double amp _memd8 void pir LDNDW Allows unaligned loads and stores of 8 bytes to STNDW memoryt const double amp _memd8_const const LDNDW Allows unaligned loads of 8 bytes from memorytt void ptr double _mpy2 int src7 int src2 MPY2 Return
323. n trying to reduce code size do not lower the level of optimization In fact you might see an increase in code size when lowering the level of optimization Instead use the ms option to control the code size performance tradeoff For more information see section 3 4 Reducing Code Size ms Option on page 3 17 Controlling File Level Optimization oln Option When you invoke the compiler with the O3 option some of the optimizations use known properties of the standard library functions If your file redeclares any of these standard library functions these optimizations become ineffective The ol lowercase L option controls file level optimizations The number following the ol denotes the level 0 1 or 2 Use Table 3 2 to select the appropriate level to append to the ol option Table 3 2 Selecting a Level for the ol Option If your source file Use this option Declares a function with the same name as a standard library ol0 function Contains but does not alter functions declared in the standard ol1 library Does not alter standard library functions but you used the ol0 ol2 or ol1 option in a command file or an environment variable The ol2 option restores the default behavior of the optimizer Performing File Level Optimization O3 Option 3 5 2 Creating an Optimization Information File onn Option When you invoke the compiler with the O3 option you can use the on option to cre
324. names that you name with C6X_C_OPTION or C_OPTION every time you run the compiler Setting the default options with these environment variables is useful when you want to run the compiler consecutive times with the same set of options and or input files After the compiler reads the command line and the input filenames it looks for the C6X_C_OPTION environment variable first and then reads and processes it If it does not find the C6X_C_OPTION it reads the C_OPTION environment variable and processes it The table below shows how to set the C_OPTION environment variable Select the command for your operating system Operating System Enter UNIX Bourne shell C_OPTION option options export C_OPTION Windows set C_OPTION option options Environment variable options are specified in the same way and have the same meaning as they do on the command line For example if you want to always run quietly the q option enable C C source interlisting the s option and link the z option for Windows set up the C_OPTION environment variable as follows set C OPTION q sS z In the following examples each time you run the compiler it runs the linker Any options following z on the command line or in C_OPTION are passed to the linker This enables you to use the C_OPTION environment variable to specify default compiler and linker options and then specify additional compiler and linker options on the command
325. nate STABS debugging format Enables symbolic debugging using the DWARF debugging format equivalent to g Disables all symbolic debugging Enables minimal symbolic debugging that does not hinder optimizations default behavior c Options that change the default file extensions Option eal Jextension ec Jextension el extension eo extension ep Jextension es Jextension Effect Sets a default extension for assembly source files Sets a default extension for C source files Sets a default extension for linear assembly source files Sets a default extension for object files Sets a default extension for C source files Sets a default extension for listing files Using the C C Compiler ro ro n 0 k pr 9 oo 2 g oo oO nm N a EN N n S Nile V ine arg 2 7 Changing the Compiler s Behavior With Options Table 2 1 Compiler Options Summary Continued d Options that specify files Option Effect Page fafilename Identifies filename as an assembly source file regardless of its extension By default the compiler and assembler treat asm files as assembly source files fcfilename Identifies filename as a C source file regardless of its 2 20 extension By default the compiler treats c files as C source files fg Processes all source files with a C extension as C 2 20 source files flfilename Identif
326. nd most performance analysis capabilities Generates as much symbolic debugging information as possible without hindering optimization Generally this consists of global scope information only This option reflects the default behavior of the compiler See section 2 3 9 on page 2 24 fpr a list of deprecated symbolic debugging options Changing the Compiler s Behavior With Options 2 3 4 Specifying Filenames The input files that you specify on the command line can be C source files C source files assembly source files linear assembly files or object files The compiler uses filename extensions to determine the file type Extension File Type Cc C source C Depends on operating system CPP CXX CC C source Sa Linear assembly asm abs or s extension begins with s Assembly source obj Object nna Note Case Sensitivity in Filename Extensions Case sensitivity in filename extensions is determined by your operating system If your operating system is not case sensitive a file with a C extension is interpreted as a C file If your operating system is case sensitive a file with a C extension is interpreted as a C file The conventions for filename extensions allow you to compile C and C files and optimize and assemble assembly files with a single command For information about how you can alter the way that the compiler interprets individual filenames see section 2 3 5 on page 2 20 For informat
327. nd type block copy functions nonoverlapping memor overlapping memory defined memory allocation boot obj 5 85 10 branch optimizations bsearch function bss section allocating in memory defined described 8 3 buffer define and associate function specification function BUFSIZE macro byte defined Index c compiler option how linker option differs C extension c extension C language characteristics 7 2 7 4 constants conversions data types declarations expressions identifiers pragmas C library build utility option 10 4 c linker option 5 2J 5 10 how compiler option differs C language characteristics C name demangler C C compiler defined described C C language accessing assembler constants accessing assembler global variables accessing assembler variables const keyword cregister keyword 7 114113 global constructors and destructors interlisting with assembl interrupt keyword near keyword 7 1147 13 placing assembler statements in pragma directives 7 18 7 32 restrict keyword volatile keyword C_C6X_OPTION C_DIR environment variable C6X_C_DIR environment variable 2 27 P 29 _c_int00 described C_OPTION Index 3 Index calendar time ctime function 9 55 mktime function 9 7 time function 9 106 call assembly optimizer directive 4 15 4 17 calling conven
328. ndirectly through register A15 FP or through register B15 SP one of which points to the top of the stack Since the stack grows toward smaller addresses the local and argument data for a function are accessed with a positive offset from FP or SP Local variables temporary storage and the area reserved for stack arguments to functions called by this function are accessed with offsets smaller than the constant subtracted from FP or SP at the beginning of the function Stack arguments passed to this function are accessed with offsets greater than or equal to the constant subtracted from register FP or SP at the beginning of the function The compiler attempts to keep register arguments in their original registers if optimization is used or if they are defined with the register keyword Otherwise the arguments are copied to the stack to free those registers for further allocation For information on whether FP or SP is used to access local variables temporary storage and stack arguments see section 8 4 2 How a Called Function Responds on pagel 8 20 For more information on the C C System stack see section 8 1 2 C C System Stack on page 8 4 Interfacing C and C With Assembly Language 8 5 Interfacing C and C With Assembly Language The following are ways to use assembly language with C C code m LJ Use separate modules of assembled code and link them with compiled C C modules see section 8 5 1 Use intrinsi
329. near assembly code you might want to add more details to your code such as partitioning registers Improving performance in this stage takes more time than in phase 2 so try to refine your code as much as possible before using phase 3 Then you should have smaller sections of code to work on in this phase Using the Assembly Optimizer 4 3 About the Assembly Optimizer What You Need to Know to Write Linear Assembly 4 2 About the Assembly Optimizer If you are not satisfied with the performance of your C C code after you have used all of the C C optimizations that are available you can use the assembly optimizer to make it easier to write assembly code for the C6000 The assembly optimizer performs several tasks including the following J Schedules instructions to maximize performance using the instruction level parallelism of the C6000 Li Ensures that the instructions conform to the C6000 latency requirements Lj Allocates registers for your source code Like the C C compiler the assembly optimizer performs software pipelining Software pipelining is a technique used to schedule instructions from a loop so that multiple iterations of the loop execute in parallel The code generation tools attempt to software pipeline your code with inputs from you and with information that it gathers from your program For more information see section 3 2 Software Pipelining on page 3 4 To invoke the assembly optimizer use the com
330. ng Data Types signed and unsigned Long long and unsigned long long data types are stored in an odd even pair of registers see Figure 8 4 and are always referenced as a pair in the format of odd register even register for example A1 A0 In little endian mode the lower address is loaded into the even register and the higher address is loaded into the odd register if data is loaded from location 0 then the byte at 0 is the lowest byte of the even register In big endian mode the higher address is loaded into the even register and the lower address is loaded into the odd register if data is loaded from location 0 then the byte at 0 is the highest byte of the odd register Figure 8 4 64 Bit Data Storage Format a Signed 64 bit long MS Odd register wo k Oo Even register 31 0 b Unsigned 64 bit long MS Oddregister UJUUUUUUUUUUUUUUUUUUUUYUUUUUUUUUUU 0 wo erd LS Even register U U U U UUUUUUUUUUUUUUUUUUUUUUUUUUUU 31 0 Legend S sign signed integer MS most significant U unsigned integer X unused LS least significant 8 12 Object Representation 8 2 1 5 double and long double Data Types Double and long double data types are stored in an odd even pair of registers see Figure 8 5 and can only exist in a register in one format as a pair in the format of odd register even register for example A1 A0 The odd memory word contains the sign bit exponent and the most significant part o
331. ng strtol const char st char endptr int base Converts a string to a long integer 9 103 long long strtoll const char st char endptr Converts a string to a long long integer 9 103 int base unsigned long strtoul const char st Converts a string to an unsigned long integer 9 103 char endptr int base unsigned long long strtoull const char st Converts a string to an unsigned long long integer 9 103 char endptr int base h String functions string h cstring Function Description Page void memchr const void cs int c size_t n Finds the first occurrence of c in the first n characters of cs expands inline except when pi is used int mememp const void cs const void ct Compares the first n characters of cs to ct size_t n expands inline except when pi is used void memepy void s1 const void s2 Copies n characters from s1 to s2 register size_t n void memmove void s1 const void s2 Moves n characters from s1 to s2 size_t n void memset void mem int ch size_t length Copies the value of ch into the first length characters of mem expands inline except when pi is used char streat char string1 const char string2 Appends string2 to the end of string1 char strchr const char string int c Finds the first occurrence of character c in s expands inline if x is used 9 38 h String functions string h cstring Continued Function int stremp register const char stri
332. ng1 register const char s2 int strcoll const char string1 const char string2 char strcpy register char dest register const char src size_t strespn register const char string const char chs char strerror int errno size_t strlen const char string char strncat char dest const char src register size_t n int strncmp const char string1 const char string2 size_t n char strncpy register char dest register const char src register size_t n char strpbrk const char string const char chs char strrehr const char string int c size_t strspn register const char string const char chs char strstr register const char string1 const char string2 char strtok char str1 const char str2 size_t strxfrm register char to register const char from register size_t n Summary of Run Time Support Functions and Macros Description Compares sirings and returns one of the following values lt 0 if string1 is less than string2 0 if string1 is equal to string2 gt 0 if string1 is greater than string2 Expands inline if x is used Compares sirings and returns one of the following values lt 0 if string1 is less than string2 0 if string1 is equal to string2 gt 0 if stringi is greater than string2 Copies string src into dest expands inline except when pi is used Returns the length of the initial segment of string th
333. ngles expressed in radians The math h cmath header also defines one macro named HUGE_VAL The math functions use this macro to represent out of range values When a function produces a floating point return value that is too large to represent it returns HUGE_VAL instead 9 22 Header Files The math h cmath header includes enhanced math functions that are available when you define the _TI ENHANCED_MATH_H symbol in your source file When you define the _TI ENHANCED_MATH_H symbol the HUGE_VALF symbol is made visible HUGE_VALF is the float counterpart to HUGE_VAL For all math h cmath functions domain and range errors are handled by setting errno to EDOM or ERANGE as appropriate The function input outputs are rounded to the nearest legal value 9 3 11 Nonlocal Jumps setjmp h csetjmp The setjmp h csetjmp header defines a type and a macro and declares a function for bypassing the normal function call and return discipline These include J The jmp_buf type is an array type suitable for holding the information needed to restore a calling environment J The setjmp macro saves its calling environment in its jmp_buf argument for later use by the longjmp function _ The longjmp function uses its jmp_buf argument to restore the program environment The nonlocal jmp macro and function are listed in Table 9 3 d on page 9 34 9 3 12 Variable Arguments stdarg h cstdarg Some functions can have a variable number of arg
334. nstruction with a period and a functional unit specifier One instruction can be assigned to each functional unit in a single instruction cycle There are eight functional units two of each functional type and two address paths The two of each functional type are differentiated by the data path each uses A or B D1 and D2 Data addition subtraction operations L1 and L2 Arithmetic logic unit ALU compares long data arithmetic M1 and M2 Multiply operations S1 and S2 Shift ALU branch field operations T1 and T2 Address paths What You Need to Know to Write Linear Assembly There are several ways to enter the unit specifier filed in linear assembly Of these only the specific register side information is recognized and used 4 You can specify the particular functional unit for example D1 _ You can specify the D1 or D2 functional unit followed by T1 or T2 to specify that the nonmemory operand is on a specific register side T1 specifies side A and T2 specifies side B For example LDW D1T2 A3 A4 B3 LDW D1T2 src dst J You can specify only the functional type for example M and the assembly optimizer assigns the specific unit for example M2 _ You can specify only the data path for example 1 and the assembly optimizer assigns the functional type for example L1 Whether you specify the functional unit or not the assembly optimizer selects the functional unit based on the mnemonic f
335. nt name for the preprocessor This is equivalent to inserting define name def at the top of each C source file If the optional def is omitted the name is set to 1 If you want to define a quoted string and keep the quotation marks do one of the following 1 For Windows use Dname string def For example Dcar sedan g For UNIX use Dname string def For example Dear sedan 4 For Code Composer Studio enter the definition in a file and include that file with the option Help Using the C C Compiler 2 15 Changing the Compiler s Behavior With Options Idirectory k min MV num MW n uppercase i Adds directory to the list of directories that the compiler searches for include files Each pathname must be preceded by the I option If you do not specify a directory name the preprocessor ignores the I option For more information see section 2 5 2 1 Changing the include File Search Path With the 1 Option on page 2 28 Retains the assembly language output from the compiler or assembly optimizer Normally the compiler deletes the output assembly language file after assembly is complete Produces code in big endian format By default little endian code is produced Generates large memory model code on four levels ml0 ml1 ml2 and ml3 _j ml0 defaults aggregate data structs and arrays to far _j ml1 defaults all function c
336. ntation 0 cece cece cece eee e eee eee 8 3 Register Conventions 2 says eres eres ee eee feelers 8 4 Function Structure and Calling Conventions 8 5 Interfacing C and C With Assembly Language CH neh handing ooosooonnonocnnocnnoonacannooonnnnooodnononL 8 7 Run Time Support Arithmetic Routines 5 4 8 8 System initialization lt eseese ne cece eel E EE A rile esses 8 1 Memory Model 8 1 Memory Model 8 1 1 8 2 Sections The C6000 compiler treats memory as a single linear block that is partitioned into subblocks of code and data Each subblock of code or data generated by a C program is placed in its own continuous memory space The compiler assumes that a full 32 bit address space is available in target memory rmo Note The Linker Defines the Memory Map The linker not the compiler defines the memory map and allocates code and data into target memory The compiler assumes nothing about the types of memory available about any locations not available for code or data holes or about any locations reserved for I O or control purposes The compiler produces relocatable code that allows the linker to allocate code and data into the appropriate memory spaces For example you can use the linker to allocate global variables into on chip RAM or to allocate executable code into external ROM You can allocate each block of code or data individually into memory but
337. ntf Write Stream include lt stdio h gt int vsprintf char _string const char _format va_list _ ap include lt cstdio gt int std vsprintf char _string const char _format va_list _ap vsprintf c in rts src The vsprintf function writes to the array pointed to by _ string The string pointed to by _format describes how to write the stream The argument list is given by _ap Run Time Support Functions 9 111 9 112 Chapter 10 Library Build Utility When using the C C compiler you can compile your code under a number of different configurations and options that are not necessarily compatible with one another Since it would be cumbersome to include all possible combinations in individual run time support libraries this package includes the source archive rts src which contains all run time support functions You can build your own run time support libraries by using the mk6x utility described in this chapter and the archiver described in the TMS320C6000 Assembly Language Tools User s Guide Topic Page 10 1 Standard Run Time Support Libraries 10 2 Invoking the Library Build Utility cece eee eee ees 10 3 Library Build Utility Options 0 cece eee eee eee eee 10 4 Options SUMIMANY stare esseen seers ole ols ete eig es E AAT a 10 1 Standard Run Time Support Libraries 10 1 Standard Run Time Support Libraries Command mk6x o0 mk6x o0 mk6x o0 mk6x o0 mk
338. ntrolling the Linking Process D When using initialization at load time the cr linker option the following occur m The linker sets the symbol cinit to 1 This indicates that the initialization tables are not in memory so no initialization is performed at run time m The STYP_COPY flag is set in the cinit section header STYP_COPY is the special attribute that tells the loader to perform autoinitialization directly and not to load the cinit section into memory The linker does not allocate space in memory for the cinit section LJ When autoinitializing at run time c linker option the linker defines the symbol cinit as the starting address of the cinit section The boot routine uses this symbol as the starting point for autoinitialization 5 3 5 Specifying Where to Allocate Sections in Memory The compiler produces relocatable blocks of code and data These blocks called sections are allocated in memory in a variety of ways to conform to a variety of system configurations The compiler creates two basic kinds of sections initialized and uninitialized Table 5 1 summarizes the sections Table 5 1 Sections Created by the Compiler a Initialized sections Name cinit const pinit switch text Contents Tables for explicitly initialized global and static variables Global and static const variables that are explicitly initialized and contain string literals Table of constructors to be called at startup J
339. nts into the assembly language output of the compiler The interlist feature enables you to inspect the assembly code generated for each C statement The interlist behaves differently depending on whether or not the optimizer is used and depending on which options you specify The easiest way to invoke the interlist feature is to use the ss option To compile and run the interlist on a program called function c enter cl6x ss function The ss option prevents the compiler from deleting the interlisted assembly language output file The output assembly file function asm is assembled normally When you invoke the interlist feature without the optimizer the interlist runs as a separate pass between the code generator and the assembler It reads both the assembly and C C source files merges them and writes the C C statements into the assembly file as comments Using the ss option can cause performance and or code size degradation Example 2 3 shows a typical interlisted assembly file Using Interlist Example 2 3 An Interlisted Assembly Language File _main STW D2 B3 SP 12 STW D2 A10 SP 8 5 printf Hello world n B S1 _printf NOP 2 MVKL S1 SL1 0 A0 MVKH 61 SL1 0 A0 MVKL S2 RLO B3 STW D2 AO SP 4 MVKH S2 RLO B3 RLO CALL OCCURS 6 return 0 ZERO Li A10 MV L1 A10 A4 LDW D2 SP 8 A10 LDW D2 SP 12 B3 NOP 4 B S2 B3 NOP 5 BRANCH OCC
340. number of characters placed in the buffer Run Time Support Functions 9 73 ltoa Syntax for C Syntax for C Defined in Description Syntax for C Syntax for C Defined in Description 9 74 Convert Long Integer to ASCII no prototype provided int Itoa long val char buffer no prototype provided int std ltoa long val char buffer ltoa c in rts src The lItoa function is a nonstandard non ISO function and is provided for compatibility The standard equivalent is sprintf The function is not prototyped in rts src The ltoa function converts a long integer n to an equivalent ASCII string and writes it into the buffer If the input number val is negative a leading minus sign is output The Itoa function returns the number of characters placed in the buffer Allocate Memory include lt stdlib h gt void malloc size_t size include lt stdlib h gt void std malloc size_t size memory c in rts src The malloc function allocates space for an object of size bytes and returns a pointer to the space If malloc cannot allocate the packet that is if it runs out of memory it returns a null pointer 0 This function does not modify the memory it allocates The memory that malloc uses is in a special memory pool or heap The constant ___SYSMEM_SIZE defines the size of the heap as 2K bytes You can change this amount at link time by invoking the linker with the heap option and specifying the desired
341. o o Pig ofo _ i a a yoy ay a oj r al ja body Il pe oj o D a oj o m st S oj lol o TA D T D gi a dd i ka NJ JN 2 3 1 Frequently Used Options Changing the Compiler s Behavior With Options Following are detailed descriptions of options that you will probably use frequently filename C consultant Dname def h Appends the contents of a file to the command line You can use this option to avoid limitations on command line length or C style comments imposed by the host operating system Use a or at the beginning of a line in the command file to include comments You can also include comments by delimiting them with and You can use the option multiple times to specify multiple files For instance the following indicates that file3 should be compiled as source and file1 and file2 are files cl6 x filel file2 file3 Suppresses the linker and overrides the z option which specifies linking Use this option when you have z specified in the C_OPTION or C6X_C_OPTION environment variable and you do not want to link For more information see section 5 1 3 Disabling the Linker c Compiler Option on page 5 4 Generates compile time loop information through the Compiler Consultant Advice tool See the TMS320C6000 Code Composer Studio Online Help for more information about the Compiler Consultant Advice tool Predefines the consta
342. o the general aliasing rule for these types given in section 3 3 of the ISO specification is ignored If you have code similar to the following example do not use the mt option long 1 char p char amp l p 2 5 J The mt option indicates that indirect references on two pointers P and Q are not aliases if P and Q are distinct parameters of the same function activated by the same call at run time If you have code similar to the following example do not use the mt option g int j int a 20 f amp a amp a Bad f amp a 42 amp a j Also Bad int ptrl int ptr2 Indicating Whether Certain Aliasing Techniques Are Used J The mt option indicates that each subscript expression in an array reference A E1 En evaluates to a nonnegative value that is less than the corresponding declared array bound Do not use mt if you have code similar to the following example static int ary 20 20 int g return 5 4 4 is a negative index return 0 96 96 exceeds 20 as an index return 4 16 This one is OK int int a ant J return ary i j In this example ary 5 4 ary 0 96 and ary 4 16 access the same memory location Only the reference ary 4 16 is acceptable with the mt option because both of its indices are within the bounds 0 19 LJ The mt option indicates that loop invariant counter increments and decrements of
343. oat _mpyf float float Float multiplication float _subf float float Float subtraction int _ divi int int Signed integer division int _remi int int Signed integer remainder uint _divu uint uint Unsigned integer division uint _remu uint uint Unsigned integer remainder long _divli long long Signed long division long _remli long long Signed long remainder ulong _divul ulong ulong Unsigned long division ulong _remul ulong ulong Unsigned long remainder 8 50 long long _divlli long long long long long long _remlli long long long long ulong long _mpyll ulong long ulong long ulong long _divull ulong long ulong long ulong long _remull ulong long ulong long Signed long long division Signed long long remainder Unsigned long long multiplication Unsigned long long division Unsigned long long remainder System Initialization 8 8 System Initialization Before you can run a C C program you must create the C C run time environment The C C boot routine performs this task using a function called c_int00 The run time support source library rts src contains the source to this routine in a module named boot c To begin running the system the c_int00 function can be branched to or called but it is usually vectored to by reset hardware You must link the c_int00 function with the other object modules This occurs automatically when you use the c or cr linker option and include a standard
344. ociative floating point operations Produces object code in big endian format na Uli o Po A oO Allows speculative execution of loads with bounded address ranges Specifies an interrupt threshold value 2 43 Changes near and far assumptions on four levels ml0 ml1 and ml2 and mlI3 7 11 Turns on function subsections 5 13 Make calls to run time support functions near mr0 7 12 or far mr1 Controls code size on four levels ms0 ms1 ms2 3 17 and ms3 Allows the compiler to make certain assumptions about aliasing and loops 4 43 Turns off software pipelining 3 5 Selects target version 2 17 Produce verbose software pipelining report 3 5 Using the C C Compiler 2 9 Changing the Compiler s Behavior With Options Table 2 1 Compiler Options Summary Continued 2 10 g Options that control parsing Option pi rtti Effect Enables embedded C mode Disables definition controlled inlining but O3 optimizations still perform automatic inlining Allows K amp R compatibility Generates a raw listing file Combines source files to perform program level optimization Enables relaxed mode ignores strict ISO violations Enables strict ISO mode for C C not K amp R C Generates a cross reference listing file Enables run time type information RTT h Parser options that control preprocessing Option ppa ppe ppd ppi ppl ppo Effect Cont
345. ode might look like MAP y A5 MAP y B6 ADD S2X y 4 y Equivalent to add A5 4 B6 To disable this format with symbolic names and display assembly instructions with actual registers instead compile with the machine_regs option 4 4 Assembly Optimizer Directives Assembly Optimizer Directives Assembly optimizer directives supply data for and control the assembly optimization process The assembly optimizer optimizes linear assembly code that is contained within procedures that is code within the proc and endproc directives or within the cproc and endproc directives If you do not use these directives in your linear assembly file your code will not be optimized by the assembly optimizer This section describes these directives and others that you can use with the assembly optimizer Table 4 1 summarizes the assembly optimizer directives It provides the syntax for each directive a description of each directive any restrictions that you should keep in mind and a page reference for more detail Table 4 1 Assembly Optimizer Directives Summary Syntax call ret_reg func_name arg1 arg2 cire variable 1 register1 variable2 register2 label cproc variable variables endproc endproc register registero map variable 1 register1 variable2 register2 mdep symbol7 symbol2 mptr register symbol base offset stride no_mdep pref variable register regist
346. og K amp R C Kernighan and Ritchie C the de facto standard as defined in the first edition of The C Programming Language K amp R Most K amp R C programs written for earlier non ISO C compilers should correctly compile and run without modification label A symbol that begins in column 1 of an assembler source statement and corresponds to the address of that statement A label is the only assembler statement that can begin in column 1 linear assembly Assembly code that has not been register allocated or scheduled which is used as input for the assembly optimizer Linear assembly files have a sa extension linker A software program that combines object files to form an object module that can be allocated into system memory and executed by the device listing file An output file created by the assembler that lists source state ments their line numbers and their effects on the section program counter SPC Glossary A 5 Glossary A 6 little endian An addressing protocol in which bytes are numbered from right to left within a word More significant bytes in a word have higher num bered addresses Endian ordering is hardware specific and is deter mined at reset See also big endian live in A value that is defined before a procedure and used as an input to that procedure live out A value that is defined within a procedure and used as an output from that procedure loader A device that places an executable mo
347. on el mvn q speculate_loads n Effect Page Changes the default extension for assembly optimizer source files Changes how assembly optimizer source files are identified Keeps the assembly language asm file Specifies an interrupt threshold value Controls code size on four levels ms0 ms1 ms2 and ms3 Presumes no memory aliasing 3 27 Turns off software pipelining 3 5 Select target version 2 17 Generates verbose software pipelining information Compiles or assembly optimizes only does not assemble Increases level of optimization 00 01 02 3 2 and 03 Suppresses progress messages Allows speculative execution of loads with bounded address ranges 1 TMS320C6000 instructions When you are writing your linear assembly your code does not need to indicate the following Pipeline latency m Register usage m Which unit is being used As with other code generation tools you might need to modify your linear assembly code until you are satisfied with its performance When you do this you will probably want to add more detail to your linear assembly For example you might want to partition or assign some registers Using the Assembly Optimizer 4 5 What You Need to Know to Write Linear Assembly 4 6 Note Do Not Use Scheduled Assembly Code as Source The assembly optimizer assumes that the instructions in the input file are placed in the logical order in which you would l
348. on ispunch function isspace function isupper function Index isxdigit function isxxx function j linker option jmp_buf data wee 9 23 jump function jump macro jumps nonlocal functions k compiler option k library build utility option K amp R C compatibility with ANSI C defined related document kernel defined cores BEL keyword restrict volatile l library build utility option l linker option 5 2 5 8 L_tmpnam macro label case sensitivity ac compiler option defined retaining labs function large memory model 8 6 _LARGE_MODEL macro LARGE_MODEL_OPTION macro Idexp function Idexpf function Index 11 Index Idiv function Idiv_t data type libraries run time support library build utility 10 1 0 6 compiler aie assembler options 10 5 40 6 described 1 4 optional object librar 10 3 options 10 44 0 6 limits floating point types integer types limits h header 9 19 9 20 __LINE__ macro linear assembly assembly optimizer directives 4 1344 23 defined 4 1 described 4 register specification source comments specifying functional units specifying registers writing 4 4 4 12 linkage h header linker 5 12 13 8 command file disabling invoking invoking hrough the compiler 5 2 as part of the compile step as separate step options SR aa summary of options 217 suppressing 2 15 linking C C code C
349. on converts a string to a floating point value The string must have the following format space sign digits digits e E sign integer The function returns the converted string if the original string is empty or does not have the correct format the function returns a 0 If the converted string would cause an overflow the function returns HUGE_VAL if the converted string would cause an underflow the function returns 0 If the converted string overflows or underflows errno is set to the value of ERANGE I The strtol function converts a string to a long integer The string must have the following format space sign digits digits e E sign integer I The sirtoll function converts a string to a long long integer The string must have the following format space sign digits digits e E sign integer Run Time Support Functions 9 103 strtok Syntax for C Syntax for C Defined in Description Example 9 104 J The strtoul function converts a string to an unsigned long integer Specify the string in the following format space sign digits digits e E sign integer I The sirtoull function converts a string to an unsigned long long integer Specify the string in the following format space sign digits digits e E sign integer The space is indicated by a horizontal or vertical tab space bar carriage return form feed or new line Following the space is an optional sign and d
350. opened file or device Li The buffer is the location of the buffer where the read characters are placed 1 The count is the number of characters to read from the device or file The function returns one of the following values 0 if EOF was encountered before the read was complete number of characters read in every other instance 1 if fails Rename File include lt stdio h gt include lt file h gt int rename const char o d_name const char new_name include lt cstdio gt include lt file h gt int std rename const char o d_name const char new_name The rename function changes the name of a file Lj The old_name is the current name of the file g The new_name is the new name for the file The function returns one of the following values 0 if successful Non 0_ if not successful Syntax for C Syntax for C Description Return Value Syntax for C Syntax for C Description Return Value write Delete File include lt stdio h gt include lt file h gt int unlink const char path include lt cstdio gt include lt file h gt int std unlink const char path The unlink function deletes the file specified by path The path is the filename of the file to be opened including path information The function returns one of the following values 0 if successful 1 if fails Write Characters to Buffer include lt stdio h gt include lt file h gt int wri
351. optimizations plus Performs software pipelining See section 3 2 on page 3 4 Performs loop optimizations Eliminates global common subexpressions Eliminates global unused assignments Converts array references in loops to incremented pointer form Performs loop unrolling The optimizer uses O2 as the default if you use O without an optimization level g 03 Performs all O2 optimizations plus m Removes all functions that are never called Simplifies functions with return values that are never used Inlines calls to small functions Oo Reorders function declarations so that the attributes of called functions are known when the caller is optimized m Propagates arguments into function bodies when all calls pass the same value in the same argument position Identifies file level variable characteristics If you use O3 see section 3 5 Performing File Level Optimization O3 Option on page 3 18 for more information The levels of optimizations described above are performed by the stand alone optimization pass The code generator performs several additional optimizations particularly processor specific optimizations It does so regardless of whether you invoke the optimizer These optimizations are always enabled although they are more effective when the optimizer is used Note Do Not Lower the Optimization Level to Control Code Size When trying to reduce code size do not lower the level of optimization
352. optional parameter and defaults to 0 The mptr directive tells the assembly optimizer that when the register or symbol name is used as a memory pointer in an LD B BU H HU W or ST B H W instruction it is initialized to point to base offset and is incremented by stride each time through the loop The mptr directive is valid within procedures only that is within occurrences of the proc and endproc directive pair or the cproc and endproc directive pair The symbols used for base symbol names are in a name space separate from all other labels This means that a symbolic register or assembly label can have the same name as a memory bank base name For example mptr Darray Darray Here is an example in which mptr is used to avoid memory bank conflicts _blkcp cproc i reg ptrl ptr2 tmpl tmp2 MVK 0x0 ptrl ptrl address 0 MVK 0x8 ptr2 ptr2 address 8 loop strips 50 mptr ptril a 0 4 mptr foo a 8 4 potential conflict LDW ptrl tmpl load 0 bank 0 STW tmpl ptr2 foo store 8 bank 0 i ADD 1 i i i i B loop if 0 goto loop endproc Syntax Description Example Syntax Description Example no_mdep No Memory Aliases in the Function no_mdep The no_mdep directive tells the assembly optimizer that no memory dependences occur within that function with the exception of any dependences pointed to with the mdep directive Here is an example in which no_mde
353. order of their registration atof atoi atol atoll Syntax for C Syntax for C Defined in Description atof atoi atol atoll Convert String to Number include lt stdlib h gt double atof const char st int atoi const char st long atol const char st long long atoll const char st include lt cstdlib gt double std atof const char st int std atoi const char st long std atol const char st long long std atoll char st atof c atoi c atol c and atoll c in rts src These functions convert strings to numeric representations I The atof function converts a string into a floating point value Argument st points to the string the string must have the following format space sign digits digits e E sign integer I The atoi function converts a string into an integer Argument st points to the string the string must have the following format space sign digits I The atol function converts a string into a long integer Argument st points to the string the string must have the following format space sign digits I The atoll function converts a string into a long long integer Argument st points to the string the string must have the following format space sign digits The space is indicated by a space character a horizontal or vertical tab a carriage return a form feed or a new line Following the space is an optional sign and the digits that repre
354. ou do not need this parameter Contains options filenames directives or commands for the linker Invoking the Linker Through the Compiler z Option When you specify a library as linker input the linker includes and links only those library members that resolve undefined references The linker uses a default allocation algorithm to allocate your program into memory You can use the MEMORY and SECTIONS directives in the linker command file to customize the allocation process For information see the TMS320C6000 Assembly Language Tools User s Guide You can link a C C program consisting of modules prog1 obj prog2 obj and prog3 obj with an executable filename of prog out with the command cl6 x z c progl prog2 prog3 o prog out 1l rts6200 1lib 5 1 2 Invoking the Linker as Part of the Compile Step This is the general syntax for linking C C programs as part of the compile step cl6x filenames options z c cr filenames options o name out l library Ink cma The z option divides the command line into the compiler options the options before z and the linker options the options following z The z option must follow all source files and compiler options on the command line All arguments that follow z on the command line are passed to the linker These arguments can be linker command files additional object files linker options or libraries These arguments are the same as described i
355. ovides diagnostic options that allow you to modify how the parser interprets your code These options control diagnostics pdel num pden pdf pdr pds num pdse num pdsrnum pdsw num Sets the error limit to num which can be any decimal value The compiler abandons compiling after this number of errors The default is 100 Displays a diagnostic s numeric identifier along with its text Use this option in determining which arguments you need to supply to the diagnostic suppression options pds pdse pdsr and pdsw This option also indicates whether a diagnostic is discretionary A discretionary diagnostic is one whose severity can be overridden A discretionary diagnostic includes the suffix D otherwise no suffix is present See section 2 6 Understanding Diagnostic Messages on page 2 31 for more information Produces a diagnostics information file with the same name as the corresponding source file with an err extension Issues remarks nonserious warnings which are suppressed by default Suppresses the diagnostic identified by num To determine the numeric identifier of a diagnostic message use the pden option first in a separate compile Then use pds num to suppress the diagnostic You can suppress only discretionary diagnostics Categorizes the diagnostic identified by num as an error To determine the numeric identifier of a diagnostic message use the pden option first in a
356. p is used fn cproc dst sre cnt no_mdep no memory aliasing in this function endproc Assign a Variable to a Register in a Set pref variable register 1 register2 The pref directive communicates a preference to assign a variable to one of a list of registers Symbols variables are stored in the substitution symbol table The association between symbolic names and actual registers is wiped out at the beginning and end of each linear assembly function variable A valid symbol name to be assigned to the register The substitution symbol is up to 128 characters long and must begin with a letter Remaining characters of the variable can be a combination of alphanumeric characters the underscore _ and the dollar sign register List of actual registers to be assigned a variable There is no guarantee that the variable will be assigned to any register in the specified group The compiler may ignore the preference When a variable is declared with the pref directive it is not necessary to declare that variable with the reg directive Here x is given a preference to be assigned to either A6 or B7 However It would be correct for the compiler to assign x to B3 for example instead PREF x A6 B7 Preference to assign x to either A6 or B7 Using the Assembly Optimizer 4 23 proc endproc proc endproc Syntax Description Example 4 24 Define a Procedure label proc register registero
357. packh 4 uint src7 uint src2 PACKH4 Packs alternate bytes into return value Can uint _packl4 uint src7 uint src2 PACKL4 pack high or low bytes uint _packhl2 uint src1 uint src2 PACKHL2 The upper lower halfword of src1 is placed in the 9 upper halfword the return value The lower upper Bin _packlh2 uint fei Mint shee PAGKEHA halfword of src2 is placed in the lower halfword the return value uint _rotl uint src7 uint src2 ROTL Rotates src2 to the left by the amount in src1 int _sadd2 int src7 int src2 SADD2 Performs saturated addition between pairs of int_saddus2 uint src1 int src2 SADDUS2 16 bit values in src and src2 Values for src1 can be signed or unsigned uint _saddu4 uint src7 uint src2 SADDU4 Performs saturated addition between pairs of 8 bit unsigned values in src1 and src2 uint _shfl uint src2 SHFL The lower 16 bits of src2 are placed in the even bit positions and the upper 16 bits of src are placed in the odd bit positions uint _shlmb uint src1 uint src2 SHLMB Shifts src2 left right by one byte and the uint _shrmb uint src1 uint src2 SHRMB most least significant byte of src1 is merged into the least most significant byte position int _shr2 int src7 uint src2 SHR2 For each 16 bit quantity in src2 the quantity is uint shru2 uint src7 uint src2 SHRU2 arithmetically or logically shifted right by srci number of bits src2 can contain signed or unsigned values double _smpy2
358. pe eee eee 0 kkk KKKK kkkkkk 1 KKKK KKKK kkkkkk x 2 KKKK KKKK kkkkkk 3 kk KKKKK kkkkkk Pia 4 kk KKKKK KKKKKK z 5 K KKKKK kkkkkk 6 kk KKKKK A kk k 7 kkk kkkkxk KKKKKKK 7 8 KKKK KKKKK A k k k k k k KK 9 kkkkkkkkkk KKKKKKKK 10 kkkk k kkkkkkkk 11 RRR KKK RK KEK kkkkkkkk 12 k k k Ak k A k k Hid 13 KKKK KKKKK KKKKKKK 14 kkk KKKKK kkkkkk ace eee A This example shows that on cycle 0 first execute packet of the loop kernel registers AO A1 A2 A6 A7 A8 A9 BO B1 B2 B4 B5 B6 B7 B8 and B9 are all live during this cycle 13 Optimizing Your Code 3 Optimizing Software Pipelining 3 2 3 Collapsing Prologs and Epilogs for Improved Performance and Code Size When a loop is software pipelined a prolog and epilog are generally required The prolog is used to pipe up the loop and epilog is used to pipe down the loop In general a loop must execute a minimum number of iterations before the software pipelined version can be safely executed If the minimum known trip count is too small either a redundant loop is added or software pipelining is disabled Collapsing the prolog and epilog of a loop can reduce the minimum trip count necessary to safely execute the pipelined loop Collapsing can also substantially reduce code size Some of this code size growth is due to the
359. ped with the tools Overwrites files By default the utility aborts any time it attempts to create an object file when an object file of the same name already exists in the current directory regardless of whether you specified the name or the utility derived it Suppresses header information quiet Uses default options to compile proprietary C source code into a run time support library This option is required if you want to build your own version of the standard C6000 run time support libraries Does not use the header files contained in the source archive when building the object library If the desired headers are already in the current directory there is no reason to reinstall them This option gives you flexibility in modifying run time support functions to suit your application Prints progress information to the screen during execution of the utility Normally the utility operates silently no screen messages 10 4 Options Summary Options Summary The other options you can use with the library build utility correspond directly to the options used with the compiler and assembler Table 10 1 lists these options These options are described in detail on the indicated page below Table 10 1 Summary of Options and Their Effects a Options that control the compiler Option Dname def 9 Uname Effect Predefines name Enables symbolic debugging Undefines name b Options that are machine specific
360. peline unroll or eliminate the loop Strength reduction turns the array references into efficient pointer references with autoincrements Example 3 4 Strength Reduction Induction Variable Elimination Register Variables and Software Pipelining a C source int a 10 main int i for i 0 i lt 10 i a i 0 3 36 What Kind of Optimization Is Being Performed b Compiler output Example 3 4 Strength Reduction Induction Variable Elimination Register Variables and Software Pipelining Continued FP set A15 DP set B14 SP set B15 opt x 02 33 32 if j3_32 opt sseck text global _main _main pe a ee N A us a 2 Sees we a a ee a aes MVK S1 _a A0 MVKH S1 _a A0 MV L2X AO B4 ZERO Feral A3 ZERO D2 B5 MVK S2 2 B0 7 pF nc i ys ft oat a sas a es a a i N ENE L2 PIPED LOOP PROLOG BO B S1 L3 7 BO B S1 L3 7 BO B S1 L3 7 BO B S1 L3 7 BO SUB LA BO 2 B0 7 ADD S2 8 B4 B4 del BO B S1 L3 7 BO SUB L2 BO 2 B0 e 7 I a a a a ee os anes rey ee NS as ere L3 PIPED LOOP KERNEL STW D1T1 A3 A0 8 8 STW D2T2 B5 B4 4 8 ADD S2 8 B4 B4 8 BO B S1 L3 7 BO SUB L2 BO 2 B0 7 pee SSS SSS Se SS a Sa a i 4 L4 PIPED LOOP EPILOG p a ae a a os eats se on aoe Peyn JEN SA ti es i Pye B S2 B3 i l
361. pelining See section 3 2 1 on page 3 5 for more information Note Symbolic Debugging Options Affect Performance and Code Size Using the symdebug dwarf or symdebug coff option can cause a significant performance and code size degradation of your code Use these options for debugging only Using symdebug dwarf or symdebug coff when profiling is not recommended eee sss Optimizing Your Code 3 33 Debugging and Profiling Optimized Code 3 12 2 Profiling Optimized Code 3 34 To profile optimized code use optimization O0 through O3 without any debug option By default the compiler generates a minimal amount of debug information without affecting optimizations code size or performance If you have a breakpoint based profiler use the profile breakpt option with the O option The profile breakpt option disables optimizations that would cause incorrect behavior when using a breakpoint based profiler If you need to profile code at a finer grain that the function level in Code Composer Studio you can use the symdebug dwarf or symdebug coff option although this is not recommended You might see a significant performance degradation because the compiler cannot use all optimizations with symdebug dwarf or symdebug coff It is recommended that outside of Code Composer Studio you use the clock function aT Note Profile Points In Code Composer Studio when symbolic debugging is not used
362. piler program cl6x The assembly optimizer is automatically invoked by the compiler program if one of your input files has a sa extension You can specify C C source files along with your linear assembly files For more information about the compiler program see section 2 1 on page 2 2 4 3 What You Need to Know to Write Linear Assembly 4 4 By using the C6000 profiling tools you can identify the time critical sections of your code that need to be rewritten as linear assembly The source code that you write for the assembly optimizer is similar to assembly source code However linear assembly code does not need to be partitioned scheduled or register allocated The intention is for you to let the assembly optimizer determine this information for you When you are writing linear assembly code you need to know about these items Lj Assembly optimizer directives Your linear assembly file can be a combination of assembly optimizer code and regular assembly source Use the assembly optimizer directives to differentiate the assembly optimizer code from the regular assembly code and to provide the assembly optimizer with additional information about your code The assembly optimizer directives are described in section 4 4 on page 4 13 What You Need to Know to Write Linear Assembly I Options that affect what the assembly optimizer does The following compiler options affect the behavior of the assembly optimizer Opti
363. ple shows a macro defined in stdint h that uses the smallest integer that can hold at least 16 bits typedef uint least 16 id number extern id_number lookup_user char uname For detailed information on the stdint h header see the ISO IEC 9899 1999 International Standard Programming Languages C The C Standard 9 3 15 Input Output Functions stdio h cstdio The stdio h cstdio header defines seven macros two types a structure and a number of functions The types and structure are _j The size_t type is an unsigned integer type that is the data type of the sizeof operator Originally defined in sttdef h cstddef _ The fpos_t type is a signed integer type that can uniquely specify every position within a file D The FILE type is a structure type that records all the information necessary to control a stream The macros are J The NULL macro expands to a null pointer constant 0 Originally defined in sttdef h cstddef It is not redefined if it was already defined Li The BUFSIZ macro expands to the size of the buffer that setbuf uses The EOFmacro is the end of file marker Li J The FOPEN_MAX macro expands to the largest number of files that can be open at one time D The FILENAME_MAX macro expands to the length of the longest file name in characters _j The L_tmpnam macro expands to the longest filename string that tmpnam can generate J The SEEK_CUR SEEK_SET and SEEK_END macros expand
364. plies a cproc region that has a 32 bit return value similar to an int function in C C code Using the Assembly Optimizer 4 29 trip Example Syntax Description 4 30 Lj A register pair of the format hi lo implies a cproc region that has a 40 bit long a 64 bit long long or a 64 bit type double return value similar to a long long long double function in C C code Arguments to the return directive can be either symbolic register names or machine register names All return statements in a cproc region must be consistent in the type of the return value Itis not legal to mix a return arg with a return hi lo in the same cproc region The return directive is unconditional To perform a conditional return simply use a conditional branch around a return The assembly optimizer removes the branch and generates the appropriate conditional code For example to return if condition cc is true code the return as cc B around return around This example uses a symbolic register name tmp and a machine register A5 as return arguments cproc reg tmp return tmp lt legal symbolic name return a5 lt legal actual name Specify Trip Count Values label trip minimum value maximum value factor The trip directive specifies the value of the trip count The trip count indicates how many times a loop iterates The trip directive is valid within procedures only Following are description
365. ply an alias for a type i e a struct this pragma can be applied to the struct the typedef of the struct or any typedef derived from them and affects all aliases of the base type This example aligns any st_tag structure variables on a page boundary typedef struct st_tag int a short b st_typedef pragma STRUCT ALIGN st_tag 128 Any use of STRUCT_ALIGN with a basic type int short float or a variable results in an error TMS320C6000 C C Language Implementation 7 31 Pragma Directives 7 7 18 The UNROLL Pragma 7 32 The UNROLL pragma specifies to the compiler how many times a loop should be unrolled The UNROLL pragma is useful for helping the compiler utilize SIMD instructions on the C6400 family It is also useful in cases where better utilization of software pipeline resources are needed over a non unrolled loop The optimizer must be invoked use 01 02 or 03 in order for pragma specified loop unrolling to take place The compiler has the option of ignoring this pragma No statements are allowed between the UNROLL pragma and the for while or do while loop to which it applies However other pragmas such as MUST_ITERATE and PROB_ITERATE may appear between the UNROLL pragma and the loop The syntax of the pragma is for both C and C pragma UNROLL n If possible the compiler unrolls the loop so there are n copies of the original loop The compiler only unrolls if it can deter
366. pointing to objects that overlap in memory You are promising that accesses through a and b will never conflict this means that a write through one pointer cannot affect a read from any other pointers The precise semantics of the restrict Keyword are described in the 1999 version of the ISO C Standard Example 7 2 Use of the restrict type qualifier with pointers void funcl int restrict a int restrict b funcl s code here Example 7 3 illustrates using the restrict keyword when passing arrays to a function Here the arrays c and d should not overlap nor should c and d point to the same array Example 7 3 Use of the restrict type qualifier with arrays 7 14 void func2 int c restrict int d restrict int i for i 0 i lt 64 i efi d i dli 1 Keywords 7 4 6 The volatile Keyword The compiler analyzes data flow to avoid memory accesses whenever possible If you have code that depends on memory accesses exactly as written in the C C code you must use the volatile keyword to identify these accesses A variable qualified with a volatile keyword is allocated to an uninitialized section as opposed to a register The compiler does not optimize out any references to volatile variables In the following example the loop waits for a location to be read as OxFF unsigned int ctrl while ctrl OxFF In this example ctrl is a loop invariant exp
367. pragma specifies to the optimizer to keep these C functions or any other functions that these C C functions call These functions act as entry points into C C The pragma must appear before any declaration or reference to the function that you want to keep The syntax of the pragma in C is pragma FUNC_EXT_CALLED func The syntax of the pragma in C is pragma FUNC_EXT_CALLED TMS320C6000 C C Language Implementation 7 23 Pragma Directives In C the argument func is the name of the function that you do not want removed In C the pragma applies to the next function declared Except for _c_int00 which is the name reserved for the system reset interrupt for C C programs the name of the interrupt the func argument does not need to conform to a naming convention When you use program level optimization you may need to use the FUNC_EXT_CALLED pragma with certain options See section 3 6 2 Optimization Considerations When Mixing C and Assembly on page 3 22 7 7 7 The FUNC_INTERRUPT_THRESHOLD Pragma 7 24 The compiler allows interrupts to be disabled around software pipelined loops for threshold cycles within the function This implements the mi option for a single function see section 2 11 Interrupt Flexibility Options on page The FUNC_INTERRUPT_THRESHOLD pragma always overrides the min command line option A threshold value less than 0 assumes that the function is never inter
368. present C type information at run time Summary of Run Time Support Functions and Macros 9 4 Summary of Run Time Support Functions and Macros Table 9 3 summarizes the run time support header files in alphabetical order provided with the TMS320C6000 ANSI ISO C C compiler Most of the functions described are per the ISO standard and behave exactly as described in the standard The functions and macros listed in Table 9 3 are described in detail in section 9 5 Description of Run Time Support Functions and Macros on page 9 41 For a complete description of a function or macro see the indicated page A superscripted number is used in the following descriptions to show exponents For example xY is the equivalent of x to the power y Run Time Support Functions 9 29 Summary of Run Time Support Functions and Macros Table 9 3 Summary of Run Time Support Functions and Macros a Error message macro assert h cassert Macro void assert int expr Description Page Inserts diagnostic messages into programs b Character typing and conversion functions ctype h cctype Function int isalnum int c int isalpha int c int isascii int c int isentrl int c int isdigit int c int isgraph int c int islower int c int isprint int c int ispunct int c int isspace int c int isupper int c int isxdigit int c int toascii int c int tolower int char c int toupper int char c Descrip
369. profile points can only be set at the beginning and end of functions What Kind of Optimization Is Being Performed 3 13 What Kind of Optimization Is Being Performed The TMS320C6000 C C compiler uses a variety of optimization techniques to improve the execution speed of your C C programs and to reduce their size Following are the optimizations performed by the compiler Optimization Page Cost based register allocation 3 36 Alias disambiguation 3 38 Branch optimizations and control flow simplification Data flow optimizations 3 41 Copy propagation Common subexpression elimination Redundant assignment elimination Expression simplification Inline expansion of functions 3 42 Induction variable optimizations and strength reduction Loop invariant code motion Loop rotation 3 44 Register variables 3 44 Register tracking targeting Software pipelining 3 45 Optimizing Your Code 3 35 What Kind of Optimization Is Being Performed 3 13 1 Cost Based Register Allocation The compiler when optimization is enabled allocates registers to user variables and compiler temporary values according to their type use and frequency Variables used within loops are weighted to have priority over others and those variables whose uses do not overlap can be allocated to the same register Induction variable elimination and loop test replacement allow the compiler to recognize the loop as a simple counting loop and software pi
370. program level optimization which you invoke with pm O8 by using the op option Specifically the op option indicates if functions in other modules can call a module s external functions or modify a module s external variables The number following op indicates the level you set for the module that you are allowing to be called or modified The O3 option combines this information with its own file level analysis to decide whether to treat this module s external function and variable declarations as if they had been declared static Use Table 3 4 to select the appropriate level to append to the op option Table 3 4 Selecting a Level for the op Option If your module Use this option Has functions that are called from other modules and global op0 variables that are modified in other modules Does not have functions that are called by other modules but has op1 global variables that are modified in other modules Does not have functions that are called by other modules or op2 global variables that are modified in other modules Has functions that are called from other modules but does not op3 have global variables that are modified in other modules In certain circumstances the compiler reverts to a different op level from the one you specified or it might disable program level optimization altogether Table 3 5 lists the combinations of op levels and conditions that cause the compiler to revert to ot
371. r you can use the register name directly Note that IFR is read only See the TMS320C6000 CPU and Instruction Set Reference Guide for detailed information on the control registers See Example 7 1 for an example that declares and uses control registers Example 7 1 Define and Use Control Registers extern extern extern extern extern extern extern extern extern main cregister cregis cregis cregis cregis cregis cregis cregis cregis Ler Cer cer cer Ler Ler cer cer printf AMR volatil volatil volatil volatil volatil volatil volatil volatil volatil unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned x n AMR int int int int int int int int int CSR IFR ISR ICR IER FADCR FAUCR FMCR TMS320C6000 C C Language Implementation 7 9 Keywords 7 4 3 The interrupt Keyword 7 10 The C6000 compiler extends the C C language by adding the interrupt keyword which specifies that a function is treated as an interrupt function Functions that handle interrupts follow special register saving rules and a special return sequence When C C code is interrupted the interrupt routine must preserve the contents of all machine registers that are used by the routine or by any function called by the routine When you use the interrupt keyword with the definition of the function the compiler gener
372. r 4 7 What You Need to Know to Write Linear Assembly Lj Comments are optional Comments that begin in column 1 can begin with an asterisk or a semicolon or but comments that begin in any other column must begin with a semicolon Lj If you set up a conditional instruction the register must be surrounded by square brackets LJ A mnemonic cannot begin in column 1 or it is interpreted as a label See the TMS320C6000 Assembly Language Tools User s Guide for information on the syntax of C6000 instructions including conditional instructions labels and operands 4 3 2 Register Specification for Linear Assembly 4 8 There are only two cross paths in the C6000 This limits the C6000 to one source read from each data path s opposite register file per cycle The compiler must select a side for each instruction this is called partitioning It is recommended that you do not initially partition the linear assembly source code by hand This allow the compiler more freedom to partition and optimize your code If the compiler does not find an optimal partition in a software pipelined loop then you can partition enough instructions by hand to force optimal partitioning by using functional unit specifiers If you add functional unit specifiers to your linear assembly source code this gives the compiler more information on where these and subsequent instructions should go You select registers for partitioning with the reg directive
373. r expands to Character Expands to a The abbreviated weekday name Mon Tue SA The full weekday name Ab The abbreviated month name Jan Feb B The locale s full month name oC The date and time representation d The day of the month as a decimal number 0 31 H The hour 24 hour clock as a decimal number 00 23 Al The hour 12 hour clock as a decimal number 01 12 j The day of the year as a decimal number 001 366 m The month as a decimal number 01 12 M The minute as a decimal number 00 59 pP The locale s equivalency of either a m or p m S The seconds as a decimal number 00 59 U The week number of the year Sunday is the first day of the week as a decimal number 00 52 X The date representation AX The time representation Ay The year without century as a decimal number 00 99 Syntax for C Syntax for C Defined in Description Example strlen Character Expands to YY The year with century as a decimal number SL The time zone name or by no characters if no time zone exists For more information about the functions and types that the time h ctime header declares and defines see section 9 3 18 Time Functions time h ctime on page 9 27 Find String Length include lt string h gt size_t strlen const char string include lt cstring h gt size_t std strlen const char string strlen c in rts src The strlen function returns the length of string
374. r functions that are called only from a small number of places and for small functions If your code size seems too large see section 3 4 Reducing Code Size ms Option on page 3 17 2 10 1 Inlining Intrinsic Operators There are many intrinsic operators for the C6000 All of them are automatically inlined by the compiler The inlining happens automatically whether or not you use the optimizer For details about intrinsics and a list of the intrinsics see section 8 5 2 Using Intrinsics to Access Assembly Language Statements on page 8 26 2 10 2 Automatic Inlining When compiling C C source code with the O3 option inline function expansion is performed on small functions For more information see section 3 10 Automatic Inline Expansion oi Option on page 3 29 2 38 Using Inline Function Expansion 2 10 3 Unguarded Definition Controlled Inlining The inline keyword specifies that a function is expanded inline at the point at which it is called rather than by using standard calling procedures The compiler performs inline expansion of functions declared with the inline keyword You must invoke the optimizer with any O option O0 O1 O2 or O3 to turn on definition controlled inlining Automatic inlining is also turned on when using O3 The following example shows usage of the inline keyword where the function call is replaced by the code in the called function Example 2 1 Using the inlin
375. r some location explicitly read within the loop If the n is omitted the compiler assumes the speculative threshold is unlimited To specify this in Code Composer Studio select the Speculate Threshold check box and leave the text box blank in the Build Options dialog box on the Compiler tab Advanced category Optimizing Software Pipelining Collapsing can usually reduce the minimum safe trip count If the minimum known trip count is less than the minimum safe trip count a redundant loop is required Otherwise pipelining must be suppressed Both these values can be found in the comment block preceding a software pipelined loop Known Minimum Trip Count 1 Minimum safe trip count 7 If the minimum safe trip count is greater than the minimum known trip count use of mh is highly recommended not only for code size but for performance When using mh you must ensure that potentially speculated loads will not cause illegal reads This can be done by padding the data sections and or stack as needed by the required memory pad in both directions The required memory pad for a given software pipelined loop is also provided in the comment block for that loop fg Minimum required memory pad 8 bytes 3 2 3 2 Selecting the Best Threshold Value When a loop is software pipelined the comment block preceding the loop provides the following information g Required memory pad for this loop _ The minimum value of n needed to achiev
376. rage for each pair of signed 8 bit values uint _bitc4 uint src BITC4 For each of the 8 bit quantities in src the number of 1 bits is written to the corresponding position in the return value uint _bitr uint src BITR Reverses the order of the bits int _cmpeq2 int src1 int src2 CMPEQ2 Performs equality comparisons on each pair of 16 bit values Equality results are packed into the two least significant bits of the return value int_cmpegqA int src1 int src2 CMPEQ4 Performs equality comparisons on each pair of 8 bit values Equality results are packed into the four least significant bits of the return value int_cmpgt2 int src1 int src2 CMPGT2 Compares each pair of signed 16 bit values T See the Tms320C6000 Programmer s Guide for more information Results are packed into the two least significant bits of the return value See section 8 5 3 Using Unaligned Data and 64 Bit Values for details on manipulating 8 byte data quantities Run Time Environment 8 31 Interfacing C and C With Assembly Language Table 8 4 TMS320C64x C C Compiler Intrinsics Continued Assembly C C Compiler Intrinsic Instruction Description uint_cmpgtuA uint src7 uint src2 CMPGTU4 Compares each pair of 8 bit values Results are packed into the four least significant bits of the return value uint _deal uint src DEAL The odd and even bits of src are extracted into two separate 16 bit values int _dotp2 int src7 in
377. ragma or the interrupt keyword For more information see section 7 7 13 The INTERRUPT Pragma on page 7 27 land section 7 4 3 The interrupt Keyword on page 7 10 You are responsible for handling the AMR control register and the SAT bit in the CSR correctly inside an interrupt By default the compiler does not do anything extra to save restore the AMR and the SAT bit Macros for handling the SAT bit and the AMR register are included in the c6x h header file 8 46 Interrupt Handling For example you are using circular addressing in some hand assembly code that is the AMR does not equal 0 This hand assembly code can be interrupted into a C code interrupt service routine The C code interrupt service routine assumes that the AMR is set to 0 You need to define a local unsigned int temporary variable and call the SAVE_AMR and RESTORE_AMR macros at the beginning and end of your C interrupt service routine to correctly save restore the AMR inside the C interrupt service routine Example 8 8 AMR and SAT Handling include lt c6x h gt interrupt void interrupt_func unsigned int temp_amr define other local variables used inside interrupt save the AMR to a temp location and set it to 0 SAVE_AMR temp_amr code and function calls for interrupt service routine restore the AMR for you hand assembly code before exiting e RESTORE AMR temp_amr If you need to save restore the SAT
378. rcpy c To modify a function extract the source as in the previous example Make the required changes to the code recompile and reinstall the new object file or files into the library For example cl6 x options atoi c strcpy c j recompile ar x r rts6200 lib atoi obj strcpy obj j rebuild library You can also build a new library this way rather than rebuilding into rts6200 lib For more information about the archiver see the TMS320C6000 Assembly Language Tools User s Guide 9 1 3 Building a Library With Different Options You can create a new library from rts src by using the library build utility mk6x For example use this command to build an optimized run time support library mk6x u 02 x rts srce l rts lib The u option tells the mk6x utility to use the header files in the current directory rather than extracting them from the source archive The use of the O2 option does not affect compatibility with code compiled without this option For more information on the library build utility see Chapter 10 Library Build Utility Run Time Support Functions 9 3 The C I O Functions 9 2 The C I O Functions 9 4 The C I O functions make it possible to access the host s operating system to perform I O The capability to perform I O on the host gives you more options when debugging and testing code To use the I O functions include the header file stdio h or cstdio for C code for each module that referenc
379. re still issued e Options that control the optimization level Option Effect Compiles with register optimization Compiles with o0 optimization local optimization Compiles with 01 optimization global optimization Compiles with 02 optimization file optimization Note that mk6x automatically sets ol0 and op0 f Option that controls the assembler Option as Effect Keeps labels as symbols g Options that change the default file extensions Option Effect ea Jnew extension Sets default extension for assembly files eo new extension Sets default extension for object files 10 6 Page 2 40 bs i ete inl be co l do l Page 2 33 2 34 2 3 R fe fe felly V M IN p 2 21 Chapter 11 C Name Demangler The C compiler implements function overloading operator overloading and type safe linking by encoding a function s signature in its link level name The process of encoding the signature into the linkname is often referred to as name mangling When you inspect mangled names such as in assembly files or linker output it can be difficult to associate a mangled name with its corresponding name in the C source code The C name demangler is a debugging aid that translates each mangled name it detects to its original name found in the C source code These topics tells you how to invoke and use the C name demangler The C name demang
380. rect calls A register pair is not allowed The label of the called function must be defined in the file If the code for the function is not in the file the label must be defined with the global or ref directive If you are calling a C C function you must use the appropriate linkname of that function See section 7 8 Generating Linknames on pagel7 33 for more information arguments Optional Symbolic machine registers passed as an argument The arguments are passed in this order and cannot be a constant memory reference or other expression You can use the cl6x mlin option to indicate whether a call is near or far If the min option is set to 0 or if no level is specified default the call is near If the min option is set to 1 2 or 3 the call is far To force a far call you must explicitly load the address of the function in a register and then issue an indirect call For example MVK func reg MVKH func reg call reg opl1 forcing a far call Using the Assembly Optimizer 4 15 call stringi string2 _main 4 16 global global sect bss text cproc reg call MVKL MVKH call MV SHR call call MVKL MVKH call endproc If you want to use for indirection you must abide by C C syntax rules and use the following alternate syntax call ret_reg ireg arg1 arg2 For example call driver opl op2 indirect call reg driver call driver op
381. register variable The register designator is ignored for objects of other types such as arrays The register storage class is meaningful for parameters as well as local variables Normally in a function some of the parameters are copied to a location on the stack where they are referenced during the function body The compiler copies a register parameter to a register instead of the stack which speeds access to the parameter within the function For more information about registers see section 8 3 Register Conventions on page 8 17 The asm Statement 7 6 The asm Statement The TMS320C6000 C C compiler can embed C6000 assembly language instructions or directives directly into the assembly language output of the compiler This capability is an extension to the C C language the asm statement The asm statement provides access to hardware features that C C cannot provide The asm statement is syntactically like a call to a function named asm with one string constant argument asm assembler text The compiler copies the argument string directly into your output file The assembler text must be enclosed in double quotes All the usual character string escape codes retain their definitions For example you can insert a byte directive that contains quotes as follows asm STR byte abc The inserted code must be a legal assembly language statement Like all assembly language statements the line of code insid
382. ression so the loop is optimized down to a single memory read To correct this define ctrl as volatile unsigned int ctrl Here the ctrl pointer is intended to reference a hardware location such as an interrupt flag TMS320C6000 C C Language Implementation 7 15 Register Variables and Parameters 7 5 Register Variables and Parameters 7 16 The TMS320C6000 C C compiler treats register variables variables defined with the register keyword differently depending on whether you use the o option J Compiling with optimization The compiler ignores any register definitions and allocates registers to variables and temporary values by using an algorithm that makes the most efficient use of registers J Compiling without optimization If you use the register keyword you can suggest variables as candidates for allocation into registers The compiler uses the same set of registers for allocating temporary expression results as it uses for allocating register variables The compiler attempts to honor all register definitions If the compiler runs out of appropriate registers it frees a register by moving its contents to memory If you define too many objects as register variables you limit the number of registers the compiler has for temporary expression results This limit causes excessive movement of register contents to memory Any object with a scalar type integral floating point or pointer can be defined as a
383. rforms 4 6 1 How the Assembly Optimizer Handles Memory References Default The assembly optimizer assumes all memory references are always aliased they always depend on one another This presumption is safe for all possible input This gives you complete control over how possible memory aliases are to be handled In some cases this presumption is overly conservative In such cases the extra instruction dependences due to the presumed memory aliases can cause the assembly optimizer to emit instruction schedules that have less parallelism and do not perform well To handle these cases the assembly optimizer provides one option and two directives 4 6 2 Using the mt Option to Handle Memory References In the assembly optimizer the mt option means no memory references ever depend on each other The mt option does not mean the same thing to the compiler The compiler interprets the mt switch to indicate several specific cases of memory aliasing are guaranteed not to occur For more information about using the mt option see section 3 7 2 page 3 26 4 6 3 Using the no_mdep Directive You can specify the no_mdep directive anywhere in a c proc function Whenever it is used you guarantee that no memory dependences occur within that function Note Memory Dependency Exception For both of these methods mt and no_mdep the assembly optimizer recognizes any memory dependences the user points out with the mdep direct
384. ription exp expf Syntax for C Syntax for C Defined in Description Example exp expf Normal Termination include lt stdlib h gt void exit int status include lt cstdlib gt void std exit int status exit c in rts src The exit function terminates a program normally All functions registered by the atexit function are called in reverse order of their registration The exit function can accept EXIT_FAILURE as a value See the abort function on page You can modify the exit function to perform application specific shut down tasks The unmodified function simply runs in an infinite loop until the system is reset The exit function cannot return to its caller Exponential include lt math h gt double exp double x float expf float x include lt cmath gt double std exp double x float std expf float x exp c and expf c in rts src The exp and expf functions return the exponential function of real number x The return value is the number e raised to the power x A range error occurs if the magnitude of x is too large double x y x y 2 0 exp x y approx 7 38 e e e is 2 17828 Run Time Support Functions 9 57 exp10 exp1 Of exp10 exp1 Of Syntax for C Syntax for C Defined in Description exp2 exp2f Syntax for C Syntax for C Defined in Description 9 58 Exponential define _TlENHANCED_MATH_H 1 include lt math h gt doubl
385. rn long my_lseek int fno long offset int origin extern int my_unlink const char path extern int my_rename const char old_ name char new_name main FILE fid add_device mydevice MSA my_open my_close my_read my_write my_lseek my unlink my_rename fid fopen mydevice test w fprintf fid Hello world n fclose fid Run Time Support Functions 9 15 Header Files 9 3 Header Files Each run time support function is declared in a header file Each header file declares the following J A set of related functions or macros _j Any types that you need to use the functions Lj Any macros that you need to use the functions These are the header files that declare the ISO C run time support functions assert h inttypes h setjmp h stdio h ctype h iso646 h stdarg h stdlib h errno h limits h stddef h string h float h math h stdint h time h In addition to the ISO C header files the following C header files are included cassert climits cstdio new cctype cmath cstdlib stdexcept cerrno csetjmp cstring typeinfo cfloat cstdarg ctime ciso646 cstddef exception Furthermore the following header files are included for the additional functions we provide c6x h cpy_tbl h file h gsm h linkage h To use a run time support function you must first use the include preprocessor directive to include the header file that declares the function For example in C the isdigit function
386. roc Declare Circular Addressing circ variable register variable register The circ directive assigns a variable name to a machine register and declares the variable as available for circular addressing The compiler then assigns the variable to the register and ensures that all code transformations are safe in this situation You must insert setup teardown code for circular addressing variable A valid symbol name to be assigned to the register The variable is up to 128 characters long and must begin with a letter Remaining characters of the variable can be a combination of alphanumeric characters the underscore _ and the dollar sign register Name of the actual register to be assigned a variable The compiler assumes that it is safe to speculate any load using an explicitly declared circular addressing variable as the address pointer and may exploit this assumption to perform optimizations When a variable is declared with the circ directive it is not necessary to declare that variable with the reg directive The circ directive is equivalent to using map page 4 20 with a circular declaration Here the symbolic name Ri is assigned to actual register Mi and Ri is declared as potentially being used for circular addressing CIRC R1 M1 R2 M2 Define a C Callable Procedure label cproc variable variables endproc Use the cproc endproc directive pair to delimit a section of your code tha
387. rocessing options For example use ppa with ppo to perform preprocessing write preprocessed output to a file with a pp extension and then compile your source code Using the C C Compiler 2 29 Controlling the Preprocessor 2 5 5 2 5 6 2 5 7 2 5 8 2 30 Generating a Preprocessed Listing File With Comments ppc Option The ppc option performs all of the preprocessing functions except removing comments and generates a preprocessed version of your source file with a pp extension Use the ppc option instead of the ppo option if you want to keep the comments Generating a Preprocessed Listing File With Line Control Information ppl Option By default the preprocessed output file contains no preprocessor directives If you want to include the line directives use the ppl option The ppl option performs preprocessing only and writes preprocessed output with line control information line directives to a file with the same name as the source file but with a pp extension Generating Preprocessed Output for a Make Utility ppd Option The ppd option performs preprocessing only but instead of writing preprocessed output writes a list of dependency lines suitable for input to a standard make utility The list is written to a file with the same name as the source file but with a pp extension Generating a List of Files Included With the include Directive ppi Option The ppi option performs preproce
388. rras an AEn LEI INIRE A dee Rate OAs ee ne 8 3 TMS320C6000 C C Compiler Intrinsics 2 2 0 kee ee ees 8 4 TMS320C64x C C Compiler Intrinsics 0 ee eee 8 5 TMS320C67x C C Compiler Intrinsics 0 000 eee 8 6 Summary of Run Time Support Arithmetic Functions 0000s 9 1 Macros That Supply Integer Type Range Limits limits h climits 9 2 Macros That Supply Floating Point Range Limits float h cfloat 9 3 Summary of Run Time Support Functions and Macros sasaa aars eee eee 10 1 Summary of Options and Their Effects 0 cece eens xviii Examples 2 1 Using the inline keyword 2 0 c cece nee eens 2 2 How the Run Time Support Library Uses the _INLINE Preprocessor Symbol 2 3 An Interlisted Assembly Language File cece eee cee eee ees 3 1 Software Pipelining Information 00 cece eee eee eens 3 2 The Function From Example 2 3 Compiled With the O2 and os Options 3 3 The Function From Example 2 3 Compiled With the O2 os and ss Options 3 4 Strength Reduction Induction Variable Elimination Register Variables and Software Pipelining iseis isasi sarie dasi eee eee eee eens 3 5 Control Flow Simplification and Copy Propagation 0 0c cece cece e eee 3 6 Data Flow Optimizations and Expression Simplification 0 00222 e eee 3 7 Inline Function Expansion 0 0 r cece ete teen eee 3 8 Register Tracking
389. rupted which is equivalent to an interrupt threshold of infinity The syntax of the pragma in C is pragma FUNC_INTERRUPT_THRESHOLD func threshold The syntax of the pragma in C is pragma FUNC_INTERRUPT_THRESHOLD threshold The following examples demonstrate the use of different thresholds 1 pragma FUNC INTERRUPT THRESHOLD foo 2000 The function foo must be interruptible at least every 2 000 cycles O pragma FUNC INTERRUPT THRESHOLD foo 1 The function foo must always be interruptible 1 pragma FUNC INTERRUPT THRESHOLD foo 1 The function foo is never interrupted Pragma Directives 7 7 8 The FUNC_IS PURE Pragma The FUNC_IS_ PURE pragma specifies to the compiler that the named function has no side effects This allows the compiler to do the following _j Delete the call to the function if the function s value is not needed _j Delete duplicate functions The pragma must appear before any declaration or reference to the function The syntax of the pragma in C is pragma FUNC_IS_PURE func The syntax of the pragma in C is pragma FUNC_IS_ PURE In C the argument func is the name of a function In C the pragma applies to the next function declared 7 7 9 The FUNC_IS SYSTEM Pragma The FUNC_IS_ SYSTEM pragma specifies to the compiler that the named function has the behavior defined by the ISO standard for a function with that
390. ry s pathname on the command line after the fr option cl6x fr d object Specifies a directory for assembly files To specify an assembly file directory type the directory s pathname on the command line after the fs option cl6x fs d assembly Specifies a directory for temporary intermediate files To specify a temporary directory type the directory s pathname on the command line after the ft option cl6x ft c temp Changing the Compiler s Behavior With Options 2 3 8 Options That Control the Assembler Following are assembler options that you can use with the compiler aa adname ahcfilename ahifilename apd api Invokes the assembler with the a assembler option which creates an absolute listing An absolute listing shows the absolute addresses of the object code makes case insignificant in the assembly language source files For example c makes the symbols ABC and abc equivalent f you do not use this option case is significant this is the default Predefines the constant name for the assembler If the optional def is omitted the name is set to 1 If you want to define a quoted string and keep the quotation marks do one of the following Lj For Windows use adname string def For example adcar sedan 399 g For UNIX use adname adcar sedan string def For example 1 For Code Composer Studio enter the definition in a file
391. s Produces a map or listing of the input and output sections including null areas and places the listing in filename The filename must follow operating system conventions Names the executable output module The filename must follow operating system conventions If the o option is not used the default filename is a out Requests a quiet run Suppresses the banner Satisfies each unresolved reference by the first library that contains a definition for that symbol Retains relocation entries in the output module Creates a smaller output section by stripping symbol table information and line number entries from the output module Sets the C C system stack size to size bytes and defines a global symbol that specifies the stack size The default is 1K bytes Linker Options trampolines Generates a trampoline code section for each call that is linked out of range of its called destination The trampoline code section contains a sequence of instructions that performs a transparent long branch to the original called address Each calling instruction that is out of range from the called function is redirected to the trampoline u symbol Places the unresolved external symbol symbol into the output module s symbol table This forces the linker to search a library and include the member that defines the symbol W Displays a message when the linker encounters one or more input sections that do not have a corresponding ou
392. s You are free to typedef integer types as standard C integer types or as the types provided in inttypes h Consistent use of the inttypes h header greatly increases the portability of your program across platforms The header declares three types _ The imaxdiv_ttype a structure type of the type of the value returned by the imaxdiv function _ The intmax_ttype an integer type large enough to represent any value of any signed integer type _j The uintmax_ttype an integer type large enough to represent any value of any unsigned integer type The header declares several macros and functions J For each size type available on the architecture and provided in stdint h there are several fprintf and fscanf macros For example three fprintf macros for signed integers are PRId32 PRIdLEAST32 and PRIdFAST32 An example use of these macros is printf The largest integer value is 020 PRIxMAX n i J The imaxabs function that computes the absolute value of an integer of type intmax_t _j The strtoimax and strtoumax functions which are equivalent to the strtol strtoll strtoul and strtoull functions The initial portion of the string is converted to intmax_t and uintmax_t respectively For detailed information on the inttypes h header see the ISO IEC 9899 1999 International Standard Programming Languages C The C Standard Run Time Support Functions 9 21 Header Files 9 3 8 Alternative Spellings
393. s a supplement to this manual References to K amp R C as opposed to ISO C in this manual refer to the C language as defined in the first edition of Kernighan and Ritchie s The C Programming Language Before you use the information about the C C compiler in this user s guide you should install the C C compiler tools Notational Conventions Notational Conventions This document uses the following conventions E Program listings program examples and interactive displays are shown in a special typeface Examples use a bold version of the special typeface for emphasis interactive displays use a bold version of the special typeface to distinguish commands that you enter from items that the system displays such as prompts command output error messages etc Here is a sample of C code include lt stdio h gt main In syntax descriptions the instruction command or directive is in a boldface typeface and parameters are in italics Portions of a syntax that are in bold must be entered as shown portions of a syntax that are in italics describe the type of information that should be entered Syntax that is entered on a command line is centered in a bounded box printf hello world n cl6x options filenames z link_options object files Syntax used in a text file is left justified in a bounded box inline return type function name parameter declarations function
394. s affect how the stand alone simulator acts and how it handles your out file Options can appear anywhere on the command line Options are discussed in section 6 2 Stand Alone Simulator Options filename out Names the out file to be loaded into the stand alone simulator The out file must be an executable COFF file The stand alone simulator can run C6200 C6400 and C6700 files No options are needed to specify either a floating point or fixed point out file The stand alone simulator determines the target version by reading COFF flags in the out file The banner generated upon invoking the stand alone simulator defines the values memory map silicon revision fast or slow version of load6x etc used to load and run the out file Example 6 1 provides two instances of the banner 6 2 Invoking the Stand Alone Simulator Example 6 1 Sample Stand Alone Simulator Banners a The file clock out invoked with no options load6 x clock out TMS320C6x Standalone Simulator Version X X Copyright c 1989 2000 by Texas Instruments Incorporated OPTIONS C6xxx Simulator OPTIONS REVISION 2 OPTIONS MAP 1 DEFAULT MEMORY MAPPING NOTE For details on above options please refer to the readme 1st Loading t out 174 Symbols loaded Done Interrupt to abort Hello world Time 133 cycles NORMAL COMPLETION 9873 cycles b The file closeout invoked with the a option load6x a clock out TMS320C6x Standa
395. s are far Keywords By default run time support functions are called with the same convention as ordinary functions you code yourself If you do not use a ml option to enable one of large memory models then these calls will be near The mr0 option causes Calls to run time support functions to be near regardless of the setting of the ml option The mr0 option is for special situations and typically is not needed The mr1 option causes calls to run time support functions to be far regardless of the setting of the ml option The mr option only addresses how run time support functions are called Calling functions with the far method does not mean those functions must be in off chip memory It simply means those functions can be placed at any distance from where they are called Be default all run time support data is defined as far 7 4 4 4 Large model option ml The large model command line option changes the default near and far assumptions The near and far modifiers always override the default The min option generates large memory model code on four levels ml0 ml1 ml2 and ml3 ml ml0 Aggregate data structs arrays default to far ml1 All calls default to far ml2 All aggregate data and calls default to far ml3 All calls and all data default to far If no level is specified all data and functions default to near Near data is accessed via the data page pointer more efficiently whil
396. s from the string pointed to by str The string pointed to by _format describes how to read the stream Run Time Support Functions 9 91 strcat Syntax for C Syntax for C Defined in Description Example 9 92 Concatenate Strings include lt string h gt char streat char string1 const char string2 include lt cstring gt char std streat char string1 const char string2 strcat c in rts src The strcat function appends a copy of string2 including a terminating null character to the end of string1 The initial character of string2 overwrites the null character that originally terminated string1 The function returns the value of string1 String1 must be large enough to contain the entire string In the following example the character strings pointed to by a b and c are assigned to point to the strings shown in the comments In the comments the notation O represents the null character char a b c a gt The quick black fox 0 b gt jumps over 0 c gt the lazy dog 0 strcat a b a gt The quick black fox jumps over 0 b gt jumps over 0 c gt the lazy dog 0 strcat a c a gt The quick black fox jumps over the lazy dog 0 b gt jumps over 0 c gt the lazy dog 0 Syntax for C Syntax for C Defined in Description Example strcmp strcoll S
397. s function 9 42 acosf function 9 42 acosh function 9 42 acoshf function 9 42 acot function acot2 function 9 43 acot2f function 9 43 acotf function 9 4 acoth function 9 44 acothf function 9 44 ad assembler option add_device function ahc assembler option ahi assembler option 2 23 al assembler option Index alias disambiguation defined described aliasing defined aliasing techniques 3 25 3 27 assigning the address to a global variable indicating certain techniques are not used 3 26 27 returning the address from a function align help function allocate memory allocate and clear memory function allocate memory function sections allocation defined alt h pathname ANSI C compatibility with K amp R C TMS320C6000 C differences from defined apd assembler option api assembler option abs linker option ar linker option arc cosine functions cotangent cartesian functions hyperbolic functions polar functions sine functions tangent cartesian functions hyperbolic functions polar functions Index 1 Index archive librar defined linking archiver defined described args linker option reserving target memory to store arguments arguments accessing arithmetic operations array search function sort function as assembler option ASCII string conversion functions asctime function asin function asinf function asinh function asin
398. s global or static For example instead of a definition such as struct big table 100 use a pointer and call the malloc function struct big table table struct big malloc 100 sizeof struct big 8 1 4 Initialization of Variables The C C compiler produces code that is suitable for use as firmware in a ROM based system In such a system the initialization tables in the cinit section are stored in ROM At system initialization time the C C boot routine copies data from these tables in ROM to the initialized variables in bss RAM In situations where a program is loaded directly from an object file into memory and run you can avoid having the cinit section occupy space in memory A loader can read the initialization tables directly from the object file instead of from ROM and perform the initialization directly at load time instead of at run time You can specify this to the linker by using the cr linker option For more information see section 8 8 System Initialization on page 8 51 Run Time Environment 8 5 Memory Model 8 1 5 Memory Models The compiler supports two memory models that affect how the bss section is allocated into memory Neither model restricts the size of the text or cinit sections m The small memory model which is the default requires that the entire Oss section fit within 32K bytes 32 768 bytes of memory This means that the total space for all static and global data in
399. s macro definitions that perform these same operations The macros run faster than the corresponding functions Use the function version if an argument is passed that has side effects The typing macros expand to a lookup operation in an array of flags this array is defined in ctype c The macros have the same name as the corresponding functions but each macro is prefixed with an underscore for example _isdigit The character typing and conversion functions are listed in Table 9 3 b page 9 3 3 Error Reporting errno h cerrno The errno h cerrno header declares the errno variable The errno variable indicates errors in library functions Errors can occur in a math function if invalid parameter values are passed to the function or if the function returns a result that is outside the defined range for the type of the result When this happens a variable named errno is set to the value of one of the following macros J EDOM for domain errors invalid parameter J ERANGE for range errors invalid result J ENOENT for path errors path does not exist J EFPOS for seek errors file position error C code that calls a math function can read the value of errno to check for error conditions The errno variable is declared in errno h cerrno and defined in errno c 9 3 4 Low Level Input Output Functions file h The file h header declares the low level I O functions used to implement input and output operations How to implement I
400. s of the trip directive parameters label The label represents the beginning of the loop This is a required parameter minimum value The minimum number of times that the loop can iterate This is a required parameter The default is 1 maximum value The maximum number of times that the loop can iterate The maximum value is an optional parameter trip factor The factor used along with minimum value and maximum value to determine the number of times that the loop can iterate In the following example the loop executes some multiple of 8 between 8 and 48 times loop trip 8 48 8 A factor of 2 states that your loop always executes an even number of times allowing the compiler to unroll once this can result in a performance increase The factor is optional when the maximum value is specified You are not required to specify a trip directive with every loop however you should use trip if you know that a loop iterates some number of times This generally means that redundant loops are not generated unless the minimum value is really small saving code size and execution time If you know that a loop always executes the same number of times whenever it is called define maximum value where maximum value equals minimum value as well The compiler may now be able to unroll your loop thereby increasing performance When you are compiling with the interrupt flexibility option min using a trip maximum value allow
401. s often possible to reduce the number of accesses by performing word accesses LDW STW for any short accesses being performed Optimizing Software Pipelining 3 2 2 4 Register Usage Table Generated by the mw Option The mw option places additional software pipeline feedback in the generated assembly file This information includes a single scheduled iteration view of the software pipelined loop If software pipelining succeeds for a given loop and the mw option was used during the compilation process a register usage table is added to the software pipelining information comment block in the generated assembly code The numbers on each row represent the cycle number within the loop kernel Each column represents one register on the TMS320C6000 A0 A15 BO B15 for all C6000 processors and A16 A31 B16 B31 for the C6400 The registers are labeled in the first three rows of the register usage table and should be read columnwise An ina table entry indicates that the register indicated by the column header is live on the kernel execute packet indicated by the cycle number labeling each row An example of the register usage table follows 2 Searching for software pipeline schedule at ii 15 Schedule found with 2 iterations in parallel ok 1 Register Usage Table 7 6 SS Se eS ee ee eet AAAAAAAAAAAAAAAA BBBBBBBBBBBBBBBB 0000000000111111 0000000000111111 0123456789012345 0123456789012345
402. s the compiler to determine the maximum number of cycles that the loop can execute Then the compiler compares that value to the threshold value given by the mi option See section 2 11 Interrupt Flexibility Options mi Option on page 2 43 for more information If the assembly optimizer cannot ensure that the trip count is large enough to pipeline a loop for maximum performance a pipelined version and an unpipelined version of the same loop are generated This makes one of the loops a redundant loop The pipelined or the unpipelined loop is executed based on a comparison between the trip count and the number of iterations of the loop that can execute in parallel If the trip count is greater or equal to the number of parallel iterations the pipelined loop is executed otherwise the unpipelined loop is executed For more information about redundant loops see section 3 3 on page 3 16 Using the Assembly Optimizer 4 31 volatile Example volatile Syntax Description Example 4 32 The trip directive states that the loop will execute 16 24 32 40 or 48 times when the w_vecsum routine is called w_vecsum cproc ptr a ptr b ptr c weight cnt reg ai bi prod scaled_prod ci no_mdep loop trip 16 48 8 1ldh ptr_a al 1ldh ptr_b bi mpy weight ai prod shr prod 15 scaled prod add scaled_prod bi ci sth ci ptr_c ent sub ent 1 cnt ent b loop endproc Declare Memory References as Volati
403. s the products of the lower and higher 16 bit values in src1 and src2 double _mpyhi int src7 int src2 MPYHI Produces a 16 by 32 multiply The result is placed ans into the lower 48 bits of the returned double Can Couple MPYNESTCI Int Sie MEYE use the upper or lower 16 bits of src1 int_mpyhir int src1 int src2 MPYHIR Produces a signed 16 by 32 multiply The result ar is shifted right by 15 bits Can use the upper or int_mpylir int src7 int src2 MPYLIR lower 16 bitsofsiei double _mpysu4 int src7 uint src2 MPYSU4 For each 8 bit quantity in src1 and src2 performs F F an 8 bit by 8 bit multiply The four 16 bit results l 4 1 2 MPYU4 double mpyu4 uint SiGe uint src2 j are packed into a double The results can be signed or unsigned int _mvd int src2 MVD Moves the data from src2 to the return value over four cycles using the multiplier pipeline uint _pack2 uint src1 uint src2 PACK2 The lower upper halfwords of src1 and src2 are uint _packh2 uint src1 uint src2 PACKH2 placed inthe return Value T See the Tms320C6000 Programmer s Guide for more information See section 8 5 3 Using Unaligned Data and 64 Bit Values for details on manipulating 8 byte data quantities Run Time Environment 8 33 Interfacing C and C With Assembly Language Table 8 4 TMS320C64x C C Compiler Intrinsics Continued Assembly C C Compiler Intrinsic Instruction Description uint _
404. s1 is recommended for all but the most performance critical code Using ms2 or ms3 is recommended for seldom executed code Either ms2 or ms3 should be used also if you need the minimum code size In all cases it is generally recommended that the code size flags be combined with O2 or O3 roA Note Disabling Code Size Optimizations or Reducing the Optimization Level If you reduce optimization and or do not use code size flags you are disabling code size optimizations and sacrificing performance S E EENAA Note The ms Option is Equivalent to ms0 If you use ms with no code size level number specified the option level defaults to ms0 pn 5 sSI I SSIS _ Optimizing Your Code 3 17 Performing File Level Optimization 03 Option 3 5 Performing File Level Optimization O3 Option The O3 option instructs the compiler to perform file level optimization You can use the O3 option alone to perform general file level optimization or you can combine it with other options to perform more specific optimizations The options listed in Table 3 1 work with O3 to perform the indicated optimization Table 3 1 Options That You Can Use With 03 3 5 1 If you Use this option Page Have files that redeclare standard library functions oln Want to create an optimization information file onn Want to compile multiple source files pm Note Do Not Lower the Optimization Level to Control Code Size Whe
405. scription 9 44 Hyperbolic Arc Cotangent define _TI_ ENHANCED_MATH_H 1 include lt math h gt double acoth double x float acothf float x define _Tl ENHANCED_MATH_H 1 include lt cmath gt double std acoth double x float std acothf float x acoth c and acothf c in rts src The acothf function returns the hyperbolic arc cotangent of a floating point argument x The magnitude of x must be 0 Convert Internal Time to String include lt time h gt char asctime const struct tm timeptr include lt ctime gt char std asctime const struct tm timeptr asctime c in rts src The asctime function converts a broken down time into a string with the following form Mon Jan 11 11 18 36 1988 n 0 The function returns a pointer to the converted string For more information about the functions and types that the time h ctime header declares and defines see section 9 3 18 Time Functions time h ctime on page 9 27 asin asinf Syntax for C Syntax for C Defined in Description Example asinh asinhf Syntax for C Syntax for C Defined in Description asinh asinhf Arc Sine include lt math h gt double asin double x float asinf float x include lt cmath gt double std asin double x float std asinf float x asin c and asinf c in rts src The asin and asinf functions return the arc sine of a floating point argument x which must be in the range 1 1
406. se the loading process is heavily dependent on the specific environment of the target application system the compiler itself makes no provision for preinitializing variables at run time It is up to your application to fulfill this requirement Initializing Static and Global Variables With the Linker If your loader does not preinitialize variables you can use the linker to preinitialize the variables to O in the object file For example in the linker command file use a fill value of 0 in the bss section SECTIONS bss fill 0x00 Because the linker writes a complete load image of the zeroed bss section into the output COFF file this method can have the unwanted effect of significantly increasing the size of the output file but not the program If you burn your application into ROM you should explicitly initialize variables that require initialization The preceding method initializes bss to 0 only at load time not at system reset or power up To make these variables 0 at run time explicitly define them in your code For more information about linker command files and the SECTIONS directive see the linker description information in the TMS320C6000 Assembly Language Tools User s Guide Initializing Static and Global Variables 7 9 2 Initializing Static and Global Variables With the const Type Qualifier Static and global variables of type const without explicit initializations are similar to other static and g
407. se the compiler is not trying to make the loop interruptible by ensuring that there is at least one cycle in the loop kernel that is not in the delay slot of a branch instruction Linking C6400 Code With C6200 C6700 Older C6400 Object Code 2 12 Linking C6400 Code With C6200 C6700 Older C6400 Object Code In order to facilitate certain packed data optimizations the alignment of top level arrays for the C6400 family was changed from 4 bytes to 8 bytes For C6200 and C6700 code the alignment for top level arrays is always 4 bytes If you are linking C6400 with C6200 6700 code or older C6400 code you may need to take steps to ensure compatibility The following lists the potential alignment conflicts and possible solutions Potential alignment conflicts occur when J Linking new C6400 code with any C6400 code already compiled with the 4 0 tools g Linking new C6400 code with code already compiled with any version of the tools for the C6200 or C6700 family Solutions pick one 41 Recompile the entire application with the mv6400 switch This solution if possible is recommended because it can lead to better performance 1 Compile the new code with the mb option The mb switch changes the alignment of top level arrays to 4 bytes when the mv6400 switch is used Using the C C Compiler 2 45 Using Interlist 2 13 Using Interlist 2 46 The compiler tools include a feature that interlists C C source stateme
408. sent the integer portion of the number In the atof stream the fractional part of the number follows then the exponent including an optional sign The first character that cannot be part of the number terminates the string The functions do not handle any overflow resulting from the conversion Run Time Support Functions 9 49 bsearch Syntax for C Syntax for C Defined in Description Example 9 50 Array Search include lt stdlib h gt void bsearch const void key const void base size_t nmemb size_t size int Compar const void const void include lt cstdlib gt void std bsearch const void key const void base size_t nmemb size_t size int compar const void const void bsearch c in rts src The bsearch function searches through an array of nmemb objects for a member that matches the object that key points to Argument base points to the first member in the array size specifies the size in bytes of each member The contents of the array must be in ascending order If a match is found the function returns a pointer to the matching member of the array if no match is found the function returns a null pointer 0 Argument compar points to a function that compares key to the array elements The comparison function should be declared as int cmp const void ptrl1 const void ptr2 The cmp function compares the objects that ptr1 and ptr2 point to and returns one o
409. separate compile Then use pdse num to recategorize the diagnostic as an error You can alter the severity of discretionary diagnostics only Categorizes the diagnostic identified by num as a remark To determine the numeric identifier of a diagnostic message use the pden option first in a separate compile Then use pdsr num to recategorize the diagnostic as a remark You can alter the severity of discretionary diagnostics only Categorizes the diagnostic identified by num as a warning To determine the numeric identifier of a diagnostic message use the pden option first in a separate compile Then use pdsw numto recategorize the diagnostic as a warning You can alter the severity of discretionary diagnostics only Using the C C Compiler 2 33 Understanding Diagnostic Messages pdv Provides verbose diagnostics that display the original source with line wrap and indicate the position of the error in the source line pdw Suppresses warning diagnostics errors are still issued 2 6 2 How You Can Use Diagnostic Suppression Options 2 34 The following example demonstrates how you can control diagnostic messages issued by the compiler Consider the following code segment int one int i int main switch i case 1 return one break default return 0 break If you invoke the compiler with the q option this is the result err c line 9 warning statement is unreachable err c
410. shift left and shift right amounts respectively Extracts the specified field in src2 sign extended to 32 bits The extract is performed by a shift left followed by a signed shift right the shift left and shift right amounts are specified by the lower 10 bits of src1 Extracts the specified field in src2 zero extended to 32 bits The extract is performed by a shift left followed by a unsigned shift right csta and cstb are the shift left and shift right amounts respectively Assembly C C Compiler Intrinsic Instruction int __ext int src2 uint csta uint cstb EXT int _extr int src2 int src1 EXT uint _extu uint src2 uint csta uint cstb EXTU uint _extur uint src2 int src7 EXTU Extracts the specified field in src2 zero extended to 32 bits The extract is performed by a shift left followed by a unsigned shift right the shift left and shift right amounts are specified by the lower 10 bits of src1 uint _ ftoi float src Reinterprets the bits in the float as an unsigned For example _ftoi 1 0 1065353216U uint _hi double src Returns the high odd register of a double register pair double _itod uint src2 uint src7 Builds a new double register pair by reinterpreting two unsigned values where src2 is the high odd register and src1 is the low even register float _itof uint src Reinterprets the bits in the unsigned as a float For example _itof 0x3f800000 1 0
411. ssing only but instead of writing preprocessed output writes a list of files included with the include directive The list is written to a file with the same name as the source file but with a pp extension Understanding Diagnostic Messages 2 6 Understanding Diagnostic Messages One of the compiler s primary functions is to report diagnostics for the source program When the compiler detects a suspect condition it displays a message in the following format file c line n diagnostic severity diagnostic message file c The name of the file involved line n The line number where the diagnostic applies diagnostic severity The severity of the diagnostic message a description of each severity category follows diagnostic message The text that describes the problem Diagnostic messages have an associated severity as follows I A fatal error indicates a problem of such severity that the compilation cannot continue Examples of problems that can cause a fatal error include command line errors internal errors and missing include files If multiple source files are being compiled any source files after the current one will not be compiled J An error indicates a violation of the syntax or semantic rules of the C C language Compilation continues but object code is not generated _ Awarning indicates something that is valid but questionable Compilation continues and object code is generated if no errors are detected
412. stdlib gt int std rewind register FILE _fp rewind c in rts src The rewind function sets the file position indicator for the stream pointed to by _ fp to the beginning of the file Round to Nearest Integer define _Tl ENHANCED_ MATH_H 1 include lt math h gt double std round double x float std roundf float x define _Tl ENHANCED_ MATH_H 1 include lt cmath gt double round double x float roundf float x round c and roundf c in rts src The round and roundf functions return a floating point number equal to x rounded to the nearest integer When x is an equal distance from two integers the even value is returned float X y Uy Vy Er Sip Oy pF x 2 65 y round x y 3 u 5 28 v roundf u v 5 Eos 3 5 s roundf s s 4 O S65 p roundf o p 6 0 rsqrt rsqrtf Syntax for C Syntax for C Defined in Description Syntax for C Syntax for C Defined in Description Syntax for C Syntax for C Defined in Description setbuf Reciprocal Square Root define _TI_ENHANCED_MATH_H 1 include lt math h gt double rsqrt double x float rsqrtf float x define _TI_ ENHANCED_MATH_H 1 include lt cmath gt double std rsqrt double x float std rsqrtf float x rsqrt c and rsqrtf c in rts src The rsqrt and rsqrtf functions return the reciprocal square root of a real number x The rsqrt x function is equivalent mathema
413. stitute ISO to standardize the C programming language The C language supported by the C6000 is defined by the ISO IEC 14882 1998 standard with certain exceptions Topic Page 7 1 Characteristics of TMS320C6000 C 2 0c eee eee eee eee ee 7 2 Characteristics of TMS320C6000 C 7 3 Data Types s ctscccieerc etarersie chelate sate ote iainlaren sicsa setn a eleseinenvelelcienmenierele TA WROY WOKS aise ce cisrnreeepecetaie a ecaveravajersie eterayeraicrelcja a E E EEE 7 5 Register Variables and Parameters 2 0020eeeeeeeees 7 6 Theiasm Statement e cure sy sys estes e e a e a Tet PragmalDirective sm E 7 6 Generating Linknames lt ce es eeens uenen ennen 7 9 Initializing Static and Global Variables 200005 7 34 7 10 Changing the ISO C Language Mode 200000 7 36 7 1 Characteristics of TMS320C6000 C 7 1 Characteristics of TMS320C6000 C 7 1 1 7 2 ISO C supersedes the de facto C standard that is described in the first edition of The C Programming Language by Kernighan and Ritchie The ISO standard is described in the American National Standard for Information Systems Programming Language C X3 159 1989 The second edition of The C Programming Language is based on the ISO standard and is a reference ISO C encompasses many of the language extensions provided by recent C compilers and formalizes many previously unspecified characteristics of the language
414. strates the path the compiler takes with and without using the linker Figure 2 1 C C Compiler C C source files ne C C compiler reser ia Optimizer TE l optional Assembly optimizer Pe Assembly Code preprocessor i generator SEANA ee ee 4 About the Compiler Executable COFF file For a complete description of the assembler and the linker see the TMS320C6000 Assembly Language Tools User s Guide Using the C C Compiler 2 3 Invoking the C C Compiler 2 2 Invoking the C C Compiler To invoke the compiler enter cl6x options filenames z ink_options object files cl6x Command that runs the compiler and the assembler options Options that affect the way the compiler processes input files The options are listed in Table 2 1 on page 2 6 filenames One or more C C source files assembly language source files linear assembly files or object files z Option that invokes the linker See Linking C C Code for more information about invoking the linker link_options Options that control the linking process object files Name of the additional object files for the linking process The arguments to cl6x are of three types J Compiler options _j Linker options g Files The z linker option is the signal that linking is to be performed If the z linker option is used any compiler options must prec
415. t Introduction 1 5 C C Compiler Overview 1 2 2 Output Files The following features pertain to output files created by the compiler E Assembly source output The compiler generates assembly language source files that you can inspect easily enabling you to see the code generated from the C C source files COFF object files Common object file format COFF allows you to define your system s memory map at link time This maximizes performance by enabling you to link C C code and data objects into specific memory areas COFF also supports source level debugging EPROM programmer data files For stand alone embedded applications the compiler has the ability to place all code and initialization data into ROM allowing C C code to run from reset The COFF files output by the compiler can be converted to EPROM programmer data files by using the hex conversion utility as described in the TMS320C6000 Assembly Language Tools User s Guide 1 2 3 Compiler Interface E E The following features pertain to interfacing with the compiler Compiler program The compiler tools include a compiler program that you use to compile assembly optimize assemble and link programs in a single step For more information see section 2 1 About the compiler Program on page e2 Flexible assembly language interface The compiler has straightforward calling conventions so you can write assembly and C functions that call eac
416. t div_t std div int numer int denom Idiv_t std Idiv long numer long denom IIdiv_t std Ildiv long long numer long long denom div c in rts src These functions support integer division by returning numer numerator divided by denom denominator You can use these functions to determine both the quotient and the remainder in a single operation J The div function performs integer division The input arguments are integers the function returns the quotient and the remainder in a structure of type div_t The structure is defined as follows typedef struct int quot quotient int rem remainder div_t Lj The Idiv function performs long integer division The input arguments are long integers the function returns the quotient and the remainder in a structure of type Idiv_t The structure is defined as follows typedef struct long quot quotient long rem remainder ldiv_t J The lldiv function performs long long integer division The input arguments are long long integers the function returns the quotient and the remainder in a structure of type Ildiv_t The structure is defined as follows typedef struct long long quot quotient long long rem remainder lldiv_t The sign of the quotient is negative if either but not both of the operands is negative The sign of the remainder is the same as the sign of the dividend Syntax for C Syntax for C Defined in Desc
417. t and modify any of the math functions Be sure however that you follow the calling conventions and register saving rules outlined in this chapter Table 8 6 summarizes the run time support functions used for arithmetic Table 8 6 Summary of Run Time Support Arithmetic Functions 8 48 Type Function Description float _cvtdf double Convert double to float int _fixdi double Convert double to signed integer long _fixdli double Convert double to long long long _fixdlli double Convert double to long long uint _fixdu double Convert double to unsigned integer ulong _fixdul double Convert double to unsigned long ulong long _fixdull double Convert double to unsigned long long double _cvtfd float Convert float to double int _fixfi float Convert float to signed integer long _fixfli float Convert float to long long long _fixflli float Convert float to long long uint _fixfu float Convert float to unsigned integer ulong _fixful float Convert float to unsigned long ulong long _fixfull float Convert float to unsigned long long Run Time Support Arithmetic Routines Table 8 6 Summary of Run Time Support Arithmetic Functions Type Function Description double _fltid int Convert signed integer to double float _fltif int Convert signed integer to float double _fltud uint Convert unsigned integer to double float _fltuf uint Convert unsigned integer to float double _fltlid long Conver
418. t you want the assembly optimizer to optimize and treat as a C C callable function This section is called a procedure The cproc directive is similar to the proc directive in that you use cproc at the beginning of a section and endproc at the end of a section In this way you can set off sections of your assembly code that you want to be optimized like functions The directives must be used in pairs do not use cproc without the corresponding endproc Specify a label with the cproc directive You can have multiple procedures in a linear assembly file Using the Assembly Optimizer 4 17 cproc endproc The cproc directive differs from the proc directive in that the compiler treats the cproc region as a C C callable function The assembly optimizer performs some operations automatically in a cproc region in order to make the function conform to the C C calling conventions and to C C register usage conventions These operations include the following I When you use save on entry registers A10 to A15 and B10 to B15 the assembly optimizer saves the registers on the stack and restores their original values at the end of the procedure J If the compiler cannot allocate machine registers to symbolic register names specified with the reg directive see page 4 26 it uses local temporary stack variables With cproc the compiler manages the stack pointer and ensures that space is allocated on the stack for these variables
419. t _c register FILE _fp int vfprintf FILE _fp const char _ format va_list _ap int vprintf const char _format va_list _ap int vsprintf char _string const char _format va_list _ap output stream Writes the string pointed to by _ ptr to stdout Causes the file with the name pointed to by _file to be no longer available by that name Causes the file with the name pointed to by _ old to be known by the name pointed to by _new Sets the file position indicator for the stream pointed to by _ fp to the beginning of the file Performs the same function as fscanf but reads input from stdin Returns no value setbuf is a restricted version of setvbuf and defines and associates a buffer with a stream Defines and associates a buffer with a stream Performs the same function as fprintf but writes to the array that _string points to Performs the same function as fscanf but reads from the string that _str points to Creates a temporary file Generates a string that is a valid filename that is the filename is not already being used Pushes the character specified by _c back into the input stream pointed to by _ fp Performs the same function as fprintf but replaces the argument list with _ap Performs the same function as printf but replaces the argument list with _ap Performs the same function as sprintf but replaces the argument list with _ap 9 36 g General functions stdlib h cs
420. t in the jmp_buf argument for later use by the longjmp function If the return is from a direct invocation the setjmp macro returns the value 0 If the return is from a call to the longjmp function the setjmp macro returns a nonzero value Lj The longjmp function restores the environment that was saved in the jmp_buf argument by the most recent invocation of the setjmp macro If the setjmp macro was not invoked or if it terminated execution irregularly the behavior of longjmp is undefined After longjmp is completed the program execution continues as if the corresponding invocation of setjmp had just returned the value specified by _val The longjmp function does not cause setjmp to return a value of 0 even if _val is 0 If _val is 0 the setjmp macro returns the value 1 Example Syntax for C Syntax for C Defined in Description setvbuf These functions are typically used to effect an immediate return from a deeply nested function call include lt setjmp h gt jmp_buf env main int errcode if errcode setjmp env 0 nest1 else switch errcode nest42 if input ERRCODE42 return to setjmp call in main longjmp env ERRCODE42 Define and Associate Buffer With Stream include lt stdio h gt int setvbuf register FILE _fp register char _buf register int _ type register size_t _size include lt cstdio gt int std setvbuf register FILE _
421. t module The run time support library contains standard C C functions as well as functions used by the compiler to manage the C C environment You must use the l linker option to specify which C6000 run time support library to use The l option also tells the linker to look at the I options and then the C_DIR or C6X_C_DIR environment variable to find an archive path or object file To use the l linker option type on the command line cl6x z c cr filenames l libraryname Generally you should specify the library as the last name on the command line because the linker searches libraries for unresolved references in the order that files are specified on the command line If any object files follow a library references from those object files to that library are not resolved You can use the x option to force the linker to reread all libraries until references are resolved Whenever you specify a library as linker input the linker includes and links only those library members that resolve undefined references By default if a library introduces an unresolved reference and multiple libraries have a definition for it then the definition from the same library that introduced the unresolved reference is used Use the priority option if you want the linker to use the definition from the first library on the command line that contains the definition Controlling the Linking Process 5 3 2 Run Time Initialization You
422. t signed long to double float _fltlif long Convert signed long to float double _fltuld ulong Convert unsigned long to double float _fltulf ulong Convert unsigned long to float double _fitllid long long Convert signed long long to double float _fitllif long long Convert signed long long to float double _fltulld ulong long Convert unsigned long long to double float _fitullf ulong long Convert unsigned long long to float double _absd double Double absolute value float _absf float Float absolute value long _labs long Long absolute value long long _llabs long long Long long absolute value double _negd double Double negate value float _negf float Float negate value long long _negll long Long long negate value long long _lishl long long Long long shift left long long _lishr long long Long long shift right ulong long _lIlshru ulong long Unsigned long long shift right double _addd double double Double addition double _cmpd double double Double comparison double _divd double double Double division Run Time Environment 8 49 Run Time Support Arithmetic Routines Table 8 6 Summary of Run Time Support Arithmetic Functions Type Function Description double _mpyd double double Double multiplication double _ subd double double Double subtraction float _addf float float Float addition float _cmpf float float Float comparison float _divf float float Float division fl
423. t src2 DOTP2 The product of the signed lower 16 bit values of double _Idotp2 int src int src2 LDOTP2 Biel and Sie Ie added 0 ie iproguer Ok Tas signed upper 16 bit values of src1 and src2 The _lo and _ hi intrinsics are needed to access each half of the 64 bit integer result int_dotpn2 int src7 int src2 DOTPN2 The product of the signed lower 16 bit values of src1 and src2 is subtracted from the product of the signed upper 16 bit values of src1 and src2 int_dotpnrsu2 int src7 uint src2 DOTPNRSU2 The product of the lower unsigned 16 bit values in src1 and src2 is subtracted from the product of the signed upper 16 bit values of src1 and src2 2415 is added and the result is sign shifted right by 16 int_dotprsu2 int src7 uint src2 DOTPRSU2 The product of the first signed pair of 16 bit values is added to the product of the unsigned second pair of 16 bit values 215 is added and the result is sign shifted by 16 int_dotprsuA int src7 uint src2 DOTPRSU4 For each pair of 8 bit values in src1 and src2 the uint _dotpu4 uint src1 uint src2 DOTPU4 8 bit value from src1 is multiplied with the 8 bit value from src2 The four products are summed together int_gmpyA int src1 int src2 GMPY4 Performs the galois field multiply on four values in src1 with four parallel values in src2 The four products are packed into the return value int _max2 int src7 int src2 MAX2 Places the larger smaller of each pair of values i pare i i
424. t those C C functions To keep these functions place the FUNC_EXT_CALLED pragma see section 7 7 6 The FUNC_EXT_CALLED Pragma on page 7 23 before any declaration or reference to a function that you want to keep Another approach you can take when you use assembly functions in your program is to use the opn option with the pm and 03 options see section 3 6 1 Controlling Program Level Optimization on page In general you achieve the best results through judicious use of the FUNC_EXT_CALLED pragma in combination with pm 03 and op1 or op2 Performing Program Level Optimization pm and O3 Options If any of the following situations apply to your application use the suggested solution Situation Solution Situation Solution Your application consists of C C source code that calls as sembly functions Those assembly functions do not call any C C functions or modify any C C variables Compile with pm O3 op2 to tell the compiler that outside functions do not call C C functions or modify C C vari ables See section 3 6 1 for information about the op2 option If you compile with the pm O3 options only the compiler reverts from the default optimization level op2 to op0 The compiler uses op0 because it presumes that the calls to the assembly language functions that have a definition in C C may call other C C functions or modify C C variables Your application consists of C C
425. tch the compiler issues an error Table 7 2 Valid Control Registers Register Description AMR Addressing mode register CSR Control status register FADCR C6700 only Floating point adder configuration register FAUCR C6700 only Floating point auxiliary configuration register FMCR C6700 only Floating point multiplier configuration register GFPGFR C6400 only Galois field polynomial generator function register ICR Interrupt clear register IER Interrupt enable register IFR Interrupt flag register IRP Interrupt return pointer ISR Interrupt set register ISTP Interrupt service table pointer NRP Nonmaskable interrupt return pointer The cregister keyword can only be used in file scope The cregister keyword is not allowed on any declaration within the boundaries of a function It can only be used on objects of type integer or pointer The cregister keyword is not allowed on objects of any floating point type or on any structure or union objects The cregister keyword does not imply that the object is volatile If the control register being referenced is volatile that is can be modified by some external control then the object must be declared with the volatile keyword also Keywords To use the control registers in Table 7 2 you must declare each register as follows The c6x h include file defines all the control registers in this manner extern cregister volatile unsigned int register Once you have declared the registe
426. tdlib Function void abort void int abs int i int atexit void fun void double atof const char st int atoi const char st long atol const char st long long atoll const char st void bsearch const void key const void base size_t nmemb size_t size int compar const void const void void calloc size_t num size_t size div_t div int numer int denom void exit int status void free void packet char getenv const char _ string long labs long i long long Ilabs long long i Idiv_t Idiv long numer long denom IIdiv_t IIdiv long long numer long long denom int Iltoa long long val char buffer int Itoa long val char buffer void malloc size_t size void memalign size_t alignment size_t size Summary of Run Time Support Functions and Macros Description Page Returns the absolute value of val expands inline Registers the function pointed to by fun called without arguments at program termination Converts a string to a floating point value expands inline except when pi is used Terminates a program abnormally Converts a string to a long integer value expands inline except when pi is used Converts a string to a long long integer value expands inline except when pi is used Converts a string to an integer Searches through an array of nmemb objects for the object that key points to Allocates and clears memory for num objects
427. te int file_descriptor const char buffer unsigned count include lt cstdio gt include lt file h gt int write int file_descriptor const char buffer unsigned count The write function writes the number of characters specified by count from the buffer to the device or file associated with file_descriptor _j The file_descriptor is the stream number assigned by the low level routines It is associated with the opened file or device _ The buffer is the location of the buffer where the write characters are placed Lj The count is the number of characters to write to the device or file The function returns one of the following values number of characters written if successful 1 if fails Run Time Support Functions 9 13 The C I O Functions 9 2 2 Adding a Device for C I O The low level functions provide facilities that allow you to add and use a device for I O at run time The procedure for using these facilities is 1 Define the device level functions as described in section 9 2 1 Overview of Low Level I O Implementation on page 9 5 Note Use Unique Function Names The function names open close read and so on are used by the low level routines Use other names for the device level functions that you write 2 Use the low level function add_device to add your device to the device_table The device table is a statically defined array that supports n devices where n is defined by the macro
428. ted in a cproc region See page 4 29 for information on the return directive Only code within procedures is optimized The assembly optimizer copies any code that is outside of procedures to the output file and does not modify it See pagel 4 25 for a list of instruction types that cannot be used in cproc regions Using the Assembly Optimizer 4 19 map Example Here is an example in which cproc and endproc are used if then cproc a cword mask theta reg cond if ai sum cntr MVK 327 Cntr t GAEE S 32 ZERO sum sum 0 LOOP AND cword mask cond cond codeword amp mask cond MVK 1 cond cond CMPEQ theta cond if theta cond LDH at al ali if ADD sum ai sum sum ali if SUB sum ai sum sum ali SHL mask 1 mask mask mask lt lt 1 centr ADD 1 Cntr centr decrement counter centr B LOOP for LOOP return sum endproc Ei wa ssign a Variable to a Register Syntax map variable register variable register Description The map directive assigns variable names to machine registers Symbols variables are stored in the substitution symbol table The association between symbolic names and actual registers is wiped out at the beginning and end of each linear assembly function The map directive can be used in assembly and linear assembly files variable A valid symbol name to be assigned to the register The substitution symbol is up to 128 charact
429. the address of the structure It is up to the called function to make a local copy For a function declared with an ellipsis indicating that it is called with varying numbers of arguments the convention is slightly modified The last explicitly declared argument is passed on the stack so that its stack address can act as a reference for accessing the undeclared arguments Figure 8 7 shows the register argument conventions Run Time Environment 8 19 Function Structure and Calling Conventions Figure 8 7 Register Argument Conventions int funcl int a int b int A4 A4 B4 A6 int func2 int a float b int c struct Ad float e int f int g A4 A4 B4 A6 B6 A8 B8 A10 int func3 int a double b float c long double d A4 A4 B5 B4 A6 B7 B6 NOTE The following function has a variable number of arguments int vararg int a int b int G int d T E A4 A4 B4 A6 stack struct A func4 int y A3 A4 2 The calling function must save registers AO to A9 and BO to B9 and A16 to A31 and B16 to B31 for C64x if their values are needed after the call by pushing the values onto the stack The caller parent calls the function child Upon returning the caller reclaims any stack space needed for arguments by adding to the stack pointer This step is needed only in assembly programs that were not compiled from C C code This is because the C C compiler allocates the stack space needed for all calls at the beginning
430. the cross reference file 2 24 Using the C C Compiler 2 13 Changing the Compiler s Behavior With Options Table 2 1 Compiler Options Summary Continued 2 14 I Options that control the linker Options a abs ar b C e global_symbol f fill_value g global_symbol h heap size I directory j l libraryname m filename 0 name out q priority stack size U symbol W X Effect Generates absolute executable output Produce absolute listing file Generates relocatable executable output Disables merge of symbolic debugging information Autoinitializes variables at run time Initializes variables at loadtime Defines entry point Defines fill value Keeps a global_symbol global overrides h Makes global symbols static Sets heap size bytes Defines library search path Disable conditional linking Supplies library or command filename Names the map file Names the output file Suppresses progress messages quiet Satisfies each unresolved reference by the first library that contains a definition for that symbol Generates relocatable non expendable output module Strips symbol table information and line number entries from the output module Sets stack size bytes Creates unresolved external symbol Displays a message when an undefined output section is created Forces rereading of libraries al 0 D Ale Pg m g aj
431. the current argument in the list The va_end macro resets the stack environment after va_start and Va_arg are used Note that you must call va_start to initialize _ap before calling va_arg or va_end Run Time Support Functions 9 109 viprintf Example viprintf Syntax for C Syntax for C Defined in Description Syntax for C Syntax for C Defined in Description 9 110 int printf char fmt va_list ap va_start ap fmt i va_arg ap int Get next arg an integer S va_arg ap char Get next arg a string l va_arg ap long Get next arg a long va_end ap Reset Write to Stream include lt stdio h gt int vfprintf FILE _fp const char _format va_list _ap include lt cstdio gt int std vfprintf FILE _fp const char _format va_list _ap vfprintf c in rts src The vfprintf function writes to the stream pointed to by _fp The string pointed to by _format describes how to write the stream The argument list is given by _ap Write to Standard Output include lt stdio h gt int vprintf const char _format va_list _ap include lt cstdio gt int std vprintf const char _format va_list _ap vprintf c in rts src The vprintf function writes to the standard output device The string pointed to by _format describes how to write the stream The argument list is given by _ap Syntax for C Syntax for C Defined in Description vspri
432. the part for example mv6400 or mv6700 If this option is not used the compiler generates code for the C6200 parts If the mv option is not specified the code generated runs on all C6000 parts however the compiler does not take advantage of target specific instructions or alignment Using the C C Compiler 2 17 Changing the Compiler s Behavior With Options 2 3 3 Symbolic Debugging and Profiling Options g or symdebug dwarft profile breakpt symdebug coff symdebug none symdebug skeletal Generates directives that are used by the C C source level debugger and enables assembly source debugging in the assembler The g option disables many code generator optimizations because they disrupt the debugger You can use the g option with the o option to maximize the amount of optimization that is compatible with debugging see section 3 12 Debugging Optimized Code on page 3 33 For more information on the DWARF debug format see the DWARF Debugging Information Format Specification 1992 1993 UNIX International Inc Disables optimizations that would cause incorrect behavior when using a breakpoint based profiler Enables symbolic debugging using the alternate STABS debugging format This may be necessary to allow debugging with older debuggers or custom tools which do not read the DWARF format Disables all symbolic debugging output This option is not recommended it prevents debugging a
433. the same byte Bit fields can range in size from 1 to 32 bits but they never span a 4 byte boundary For big endian mode bit fields are packed into registers from most significant bit MSB to least significant bit LSB in the order in which they are defined Bit fields are packed in memory from most significant byte MSbyte to least significant byte LSbyte For little endian mode bit fields are packed into registers from the LSB to the MSB in the order in which they are defined and packed in memory from LSbyte to MSbyte see Figure 8 6 Figure 8 6 illustrates bit field packing using the following bit field definitions struct int int int int int x AO represents the least significant bit of the field A A1 represents the next least significant bit etc Again storage of bit fields in memory is done with a byte by byte rather than bit by bit transfer HIW oN We AI Figure 8 6 Bit Field Packing in Big Endian and Little Endian Formats Big endian register Big endian memory Little endian register Little endian memory MS LS XEEEEEEEJ EEDDCCCBIBBBBBBBBIBAAAAAAA X8765432 10102109 87654321 06543210 31 0 Byte 0 Byte 1 Byte 2 Byte 3 BAAAAAAAJBBBBBBBBIEEDDCCCBIXEEEEEEE 06543210 87654321 10102109 X8765432 Legend X not used MS most significant LS least significant Run Time Environment 8 15 Object Representation 8 2 3 Character String Constants 8 16 In C a character strin
434. ti com Automotive www ti com automotive DSP dsp ti com Broadband www ti com broadband Interface interface ti com Digital Control www ti com digitalcontrol Logic logic ti com Military www ti com military Power Mgmt power ti com Optical Networking www ti com opticalnetwork Microcontrollers microcontroller ti com Security www ti com security Telephony www ti com telephony Video amp Imaging www ti com video Wireless www ti com wireless Mailing Address Texas Instruments Post Office Box 655303 Dallas Texas 75265 Copyright 2004 Texas Instruments Incorporated About This Manual Preface Read This First The TMS320C6000 Optimizing C C Compiler User s Guide explains how to use these compiler tools _ Compiler Assembly optimizer Standalone simulator Library build utility C name demangler d m m m The TMS320C6000 C C compiler accepts C and C code conforming to the International Organization for Standardization ISO standards for these languages and produces assembly language source code for the TMS320C6x device The compiler supports the 1989 version of the C language This user s guide discusses the characteristics of the C C compiler It assumes that you already know how to write C programs The C Programming Language second edition by Brian W Kernighan and Dennis M Ritchie describes C based on the ISO C standard You can use the Kernighan and Ritchie hereafter referred to as K amp R book a
435. tically to 1 0 sqrt x but is much faster and has similar accuracy A domain error occurs if the argument is negative Read Stream From Standard Input include lt stdlib h gt int scanf const char _fmt include lt cstdlib gt int std scanf const char _fmt fscanf c in rts src The scanf function reads from the stream from the standard input device The string pointed to by _fmt describes how to read the stream Specify Buffer for Stream include lt stdlib h gt void setbuf register FILE _fp char _buf include lt cstdlib gt void std setbuf register FILE _fp char _buf setbuf c in rts src The setbuf function specifies the buffer used by the stream pointed to by _ fp If buf is set to null buffering is turned off No value is returned Run Time Support Functions 9 87 setjmp longjmp setjmp longjmp Syntax for C Syntax for C Defined in Description 9 88 Nonlocal Jumps include lt setjmp h gt int setjmp jmp_buf env void longjmp jmp_buf env int _val include lt csetjmp gt int std setjmp jmp_buf env void std longjmp jmp_buf env int _ val setimp asm in rts src The setjmp h header defines a type and a macro and declares a function for bypassing the normal function call and return discipline O The jmp_buf type is an array type suitable for holding the information needed to restore a calling environment Q The setjmp macro saves its calling environmen
436. ting 8 byte data quantities The intrinsics listed in Table 8 4 are included only for C64x devices The intrinsics shown correspond to the indicated C6000 assembly language instruction s See the TMS320C6000 CPU and Instruction Set Reference Guide for more information See Table 8 3 o Table 8 5 on page 8 30 n page 8 27 for the listing of generic C6000 intrinsics See 35 for the listing of C67x specific intrinsics Interfacing C and C With Assembly Language Table 8 4 TMS320C64x C C Compiler Intrinsics Assembly C C Compiler Intrinsic Instruction Description int _abs2 int src ABS2 Calculates the absolute value for each 16 bit value int _add4 int src7 int src2 ADD4 Performs 2s complement addition to pairs of packed 8 bit numbers long long amp _amem8 void ptr LDDW Allows aligned loads and stores of 8 bytes to STDW memory const long long amp _amem8_const const LDDW Allows aligned loads of 8 bytes from memory void ptr double amp _amemd8 void ptr LDDW Allows aligned loads and stores of 8 bytes to STDW memorytt For C64x _amemd corresponds to different assembly instructions than when used with other C6000 devices see Table 8 3 const double amp _amemd8_const const LDDW Allows aligned loads of 8 bytes from memorytt void ptn int __avg2 int src7 int src2 AVG2 Calculates the average for each pair of signed 16 bit values uint _avgu4 uint uint AVGU4 Calculates the ave
437. tion Examples include J Returning the address from a function _j Assigning the address to a global variable If you use aliases like this in your code you must use the ma option when you are optimizing your code For example if your code is similar to this use the ma option int glob ptr g int x 1 int p amp x 5 p aliases x glob ptr 10 glob ptr aliases x h x int f int arg glob ptr arg return arg Optimizing Your Code 3 25 Indicating Whether Certain Aliasing Techniques Are Used 3 7 2 Use the mt Option to Indicate That These Techniques Are Not Used 3 26 The mt option informs the compiler that it can make certain assumptions about how aliases are used in your code These assumptions allow the compiler to improve optimization The mt option also specifies that loop invariant counter increments and decrements are non zero Loop invariant means the value of an expression does not change within the loop J The mt option indicates that your code does not use the aliasing technique described in section 3 7 1 If your code uses that technique do not use the mt option however you must compile with the ma option Do not use the ma option with the mt option If you do the mt option overrides the ma option J The mt option indicates that a pointer to a character type does not alias point to an object of another type That is the special exception t
438. tion Page Tests c to see if it is an alphanumeric ASCIl character Tests c to see if it is an alphabetic ASCII character Tests c to see if it is an ASCII character Tests c to see if it is a control character Tests c to see if it is a numeric character Tests c to see if it is any printing character except a space Tests c to see if it is a lowercase alphabetic ASCII charcter Tests c to see if it is a printable ASCII character including a space Tests c to see if it is an ASCII punctuation character Tests c to see if it is an ASCII space bar tab horizontal or vertical carriage return form feed or new line character Tests c to see if it is an uppercase ASCII alphabetic character Tests c to see if it is a hexadecimal digit Masks c into a legal ASCII value Converts c to lowercase if it is uppercase 9 108 Converts c to uppercase if it is lowercase 9 108 Note Functions in ctype h cctype are expanded inline except when the pi option is used 9 30 c Floating point math functions math h cmath Function double acos double x float acosf float x double acosh double x float acoshf float x double acot double x double acot2 double x double y float acot2f float x float y float acotf float x double acoth double x float acothf float x double asin double x float asinf float x double asinh double x float asinhf float x double atan double x double atan2 double y double x float at
439. tion with the hexadecimal value abcdabcd Enables profiling mode Source files must be compiled with at least the default level of symbolic debug information for profiling to work on the stand alone simulator See section 6 4 Using the Profiling Capability of the Stand Alone Simulator g Option on page 6 8 for more information Prints the list of available options for the stand alone simulator Loads the outfile even if it is unexecutable Selects the memory map The value can be 0 for memory map 0 internal program memory begins at 0x1400000 or 1 for memory map 1 Memory map 1 is used by default If the q option is not used the load6x banner lists the selected memory map Sets overall timeout to xxx minutes The stand alone simulator aborts if the loaded program is not finished after xxx minutes Requests a quiet run Suppresses the banner XXX rev value S t Xxx Z Stand Alone Simulator Options Relocates all sections by xxx bytes during the load For more information on relocation see the linker chapter of the TMS320C6000 Assembly Language Tools User s Guide Selects the silicon revision to simulate The value can be 2 for revision 2 or 3 for revision 3 Revision 2 silicon is simulated by default See section 6 5 Selecting Silicon Revision to Simulate rev Option on page 6 9 for more information Time stamp output Sets timeout to xxx seconds The stand alone simulator aborts if no I O event
440. tional because the return type is int Like C C functions you need to declare assembly functions only if they return noninteger values or pass noninteger parameters NT Note SP Semantics The stack pointer must always be 8 byte aligned This is automatically performed by the C compiler and system initialization code in the run time support libraries Any hand assembly code that calls a function defined in C or linear assembly source should also reserve a multiple of 8 bytes on the stack ee j Run Time Environment 8 25 Interfacing C and C With Assembly Language lt _x a aaaaaaaa 96 0 oS aGw_ G G G G G G SGS SS _ __ lt lt Note Stack Allocation Even though the compiler guarantees a doubleword alignment of the stack and the stack pointer SP points to the next free location in the stack space there is only enough guaranteed room to store one 32 bit word at that location The called function must allocate space to store the doubleword Cd 8 5 2 Using Intrinsics to Access Assembly Language Statements 8 26 The C6000 compiler recognizes a number of intrinsic operators Intrinsics allow you to express the meaning of certain assembly statements that would otherwise be cumbersome or inexpressible in C C Intrinsics are used like functions you can use C C variables with these intrinsics just as you would with any normal function The intrinsics are speci
441. tions 8 3 Register Conventions Strict conventions associate specific registers with specific operations in the C C environment If you plan to interface an assembly language routine to a C C program you must understand and follow these register conventions The register conventions dictate how the compiler uses registers and how values are preserved across function calls Table 8 2 summarizes how the compiler uses the TMS320C6000 registers The registers in Table 8 2 are available to the compiler for allocation to register variables and temporary expression results If the compiler cannot allocate a register of a required type spilling occurs Spilling is the process of moving a register s contents to memory to free the register for another purpose Objects of type double long long long or long double are allocated into an odd even register pair and are always referenced as a register pair for example A1 A0 The odd register contains the sign bit the exponent and the most significant part of the mantissa The even register contains the least significant part of the mantissa The A4 register is used with A5 for passing the first argument if the first argument is a double long long long or long double The same is true for B4 and B5 for the second parameter and so on For more information about argument passing registers and return registers see section 8 4 Function Structure and Calling Conventions Run Time Environment 8
442. tions accessing arguments and local variables how a called function responds 8 2018 22 how a function makes a call 8 19 20 register usage calloc function described dynamic memory allocation reversing cassert header described summary of functions cctype header described summary of functions ceil function ceilf function ceiling functions cerrno header cfloat header 9 1949 20 character conversion functions a number of characters described summary of escape sequences in find function matching functions strrchr sirspn read functions multiple characters single character 9 60 sets string constants 9 69 type testing function unmatching function Index 4 cinit section allocating in memory assembly module use of described use during autoinitialization circ assembly optimizer directive ciso646 header cl6x z command 5 2 cl6x command clear EOF functions 9 52 clearerr function clearerrf function climits header 9 19 9 20 CLK_TCK macro 9 27 clock function clock_t data type CLOCKS_PER_SEC macro described close file function close I O function cmath header described summary of functions 9 31 9 33 code generator defined A 2 code size reducing 3 5J 3 17 _CODE_ACCESS macro CODE_SECTION pragma COFF defined A 2 A 3 collapsing epilogs speculative execution collapsing prologs speculative execution command file appending to comm
443. tions those idioms and allowances commonly accepted by C C compilers although violations with a strict interpretation of ISO however are emitted as warnings Language extensions even those that conflict with ISO C are enabled For C code ISO mode designates the latest supported working paper K amp R C mode does not apply to C code 7 10 1 Compatibility With K amp R C pk Option 7 36 The ISO C C language is a superset of the de facto C standard defined in Kernighan and Ritchie s The C Programming Language Most programs written for other non ISO compilers correctly compile and run without modification There are subtle changes however in the language that can affect existing code Appendix C in The C Programming Language second edition referred to in this manual as K amp R summarizes the differences between ISO C and the first edition s C standard the first edition is referred to in this manual as K amp R C To simplify the process of compiling existing C programs with the C6000 ISO C C compiler the compiler has a K amp R option pk that modifies some semantic rules of the language for compatibility with older code In general the pk option relaxes requirements that are stricter for ISO C than for K amp R C The pk option does not disable any new features of the language such as function prototypes enumerations initializations or preprocessor constructs Instead pk simply liberalizes the ISO rules
444. to indicate the position current start of file or end of file respectively in a file _ The TMP_MAX macro expands to the maximum number of unique filenames that tmpnam can generate _j The stderr stdin stdout macros are pointers to the standard error input and output files respectively The input output functions are listed in Table 9 3 f on page 9 34 Run Time Support Functions 9 25 Header Files 9 3 16 General Utilities stdlib h cstdlib The stdlib h cstdlib header defines a macro and types and declares functions The macro is named RAND_ MAX and it returns the largest value returned by the rand function The types are 1 The div_ttype is a structure type that is the type of the value returned by the div function Q The div_ttype is a structure type that is the type of the value returned by the Idiv function The functions are Lj String conversion functions convert strings to numeric representations J Searching and sorting functions search and sort arrays 1 Sequence generation functions generate a pseudo random sequence and choose a starting point for a sequence _j Program exit functions terminate your program normally or abnormally 1 Integer arithmetic that is not provided as a standard part of the C language The general utility functions are listed in Table 9 3 g on page 9 37 9 3 17 String Functions string h cstring 9 26 The string h cstring header declares standar
445. to the standard output device Array Sort include lt stdlib h gt void qsort void base size_t nmemb size_t size int compar const void const void include lt cstdlib gt void std qsort void base size_t nmemb size_t size int compar const void const void qsort c in rts src The qsort function sorts an array of nmemb members Argument base points to the first member of the unsorted array argument size specifies the size of each member This function sorts the array in ascending order Argument compar points to a function that compares key to the array elements Declare the comparison function as int cmp const void ptrl1 const void ptr2 The cmp function compares the objects that ptr1 and ptr2 point to and returns one of the following values lt 0 if ptr1 is less than ptr2 O if ptr1 is equal to ptr2 gt 0 if ptr1 is greater than ptr2 Run Time Support Functions 9 83 rand srand Example Syntax for C Syntax for C Defined in Description Syntax for C Syntax for C Defined in Description 9 84 int list 10 9 8 7 6 5 4 3 2 1 0 int intcmp const void ptr1 const void ptr2 return int ptrl int ptr2 Random Integer include lt stdlib h gt int rand void void srand unsigned int seed include lt cstdlib gt int std rand void void std srand unsigned int seed rand c in rts src These funct
446. tories in this order 1 Directories named with the I option 2 Directories set with the C6X_C_DIR then C_DIR environment vari ables See section 2 5 2 1 Changing the include File Search Path I Option for information on using the I option See the code generation tools CD ROM insert for information on the C_DIR environment variable 2 5 2 1 Changing the include File Search Path I Option 2 28 The I option names an alternate directory that contains include files The format of the I option is I dlrectory 1 directory2 There is no limit to the number of I options per invocation of the compiler each I option names one directory In C source you can use the include directive without specifying any directory information for the file instead you can specify the directory information with the I option For example assume that a file called source c is in the current directory The file source c contains the following directive statement include alt h Assume that the complete pathname for alt h is UNIX 6xtools files alt h Windows _ c 6xtools files alt h The table below shows how to invoke the compiler Select the command for your operating system Operating System Enter UNIX cl6x I 6xtools files source c Windows cl6x Ic 6xtools files source c Controlling the Preprocessor Note Specifying Path Information in Angle Brackets If you specify the path information in angle brack
447. tput section defined in the the SECTIONS directive X Forces rereading of libraries Linker continues to reread libraries until no more references can be resolved xml_link_info file Generates an XML link information file This option causes the linker to generate a well formed XML file containing detailed information about the result of a link The information included in this file includes all of the information that is currently produced in a linker generated map file For more information on linker options see the Linker Description chapter in the TMS320C6000Assembly Language Tools User s Guide Linking C C Code 5 7 Controlling the Linking Process 5 3 Controlling the Linking Process 5 3 1 5 8 Regardless of the method you choose for invoking the linker special requirements apply when linking C C programs You must Lj Include the compiler s run time support library J Specify the type of initialization _j Determine how you want to allocate your program into memory This section discusses how these factors are controlled and provides an example of the standard default linker command file For more information about how to operate the linker see the linker description in the TMS320C6000 Assembly Language Tools User s Guide Linking With Run Time Support Libraries You must link all C C programs with code to initialize and execute the program called a bootstrap routine also known as the boot obj objec
448. ts suitable for loading into an EPROM programmer indirect call A function call where one function calls another function by giving the address of the called function initialization at load time An autoinitialization method used by the linker when linking C C code The linker uses this method when you invoke the linker with the cr option This method initializes variables at load time instead of run time initialized section A COFF section that contains executable code or data An initialized section can be built with the data text or sect directive integrated preprocessor A C C preprocessor that is merged with the parser allowing for faster compilation Stand alone preprocessing or preprocessed listing is also available Glossary interlist feature A feature that inserts as comments your original C C source statements into the assembly language output from the assem bler The C C statements are inserted next to the equivalent assembly instructions intrinsics Operators that are used like functions and produce assembly language code that would otherwise be inexpressible in C or would take greater time and effort to code ISO International Organization for Standardization A worldwide federation of national standards bodies which establishes international standards voluntarily followed by industries kernel The body of a software pipelined loop between the pipelined loop prolog and the pipelined loop epil
449. ts of the loop in the common case The trip count is the number of times a loop iterates Both arguments are optional For example PROB_ITERATE could be applied to a loop that executes for eight iterations in the majority of cases but sometimes may execute more or less than eight iterations pragma PROB ITERATE 8 8 Pragma Directives If only the minimum expected trip count is known say it is 5 the pragma would look like this pragma PROB ITERATE 5 If only the maximum expected trip count is known say it is 10 the pragma would look like this pragma PROB ITERATE 10 Note the blank field for min 7 7 17 The STRUCT_ALIGN Pragma The STRUCT_ALIGN pragma is similar to DATA_ALIGN but it can be applied to a structure union type or typedef and is inherited by any symbol created from that type The STRUCT_ALIGN pragma is supported only in C The syntax of the pragma is pragma STRUCT_ALIGN type constant expression This pragma guarantees that the alignment of the named type or the base type of the named typedef is at least equal to that of the expression The alignment may be greater as required by the compiler The alignment must be a power of 2 The type must be a type or a typedef name If a type it must be either a structure tag or a union tag If a typedef its base type must be either a structure tag or a union tag Since ISO C declares that a typedef is sim
450. ts src The strcspn function returns the length of the initial segment of string which is made up entirely of characters that are not in chs If the first character in string is in chs the function returns 0 char stra who is there char strb abcdefghijklmnopqrstuvwxyz char stre abcdefg size_t length length strespn stra strb length 0 length strespn stra strc length 9 String Error include lt string h gt char strerror int errno include lt cstring gt char std strerror int errno strerror c in rts src The strerror function returns the string string error This function is supplied to provide ISO compatibility Run Time Support Functions 9 95 sirftime Syntax for C Syntax for C Defined in Description 9 96 Format Time include lt time h gt size_t strftime char out size_t maxsize const char format const struct tm time include lt ctime gt size_t std strftime char out size_t maxsize const char format const struct tm time strftime c in rts src The sirftime function formats a time pointed to by time according to a format string and returns the formatted time in the string out Up to maxsize characters can be written to out The format parameter is a string of characters that tells the strftime function how to format the time the following list shows the valid characters and describes what each characte
451. tured optimizing compiler that translates standard ISO C programs into C6000 assembly language source The following subsections describe the key features of the compiler The following features pertain to ISO standards d ISO standard C The C6000 C C compiler fully conforms to the ISO C standard as defined by the ISO specification and described in the second edition of Kernighan and Ritchie s The C Programming Language K amp R The ISO C standard includes extensions to C that provide maximum portability and increased capability ISO standard C The C6000 C C compiler supports C as defined by the ISO C Standard and described in Ellis and Stroustrup s The Annotated C Reference Manual ARM The compiler also supports embedded C For a description of unsupported C features see section 7 2 Characteristics of TMS320C6000 C on page 7 5 ISO standard run time support The compiler tools come with a complete run time library All library functions conform to the ISO C C library standard The library includes functions for standard input and output string manipulation dynamic memory allocation data conversion timekeeping trigonometry and exponential and hyperbolic functions Functions for signal handling are not included because these are target system specific The library includes the ISO C subset as well as those components necessary for language support For more information see Run Time Environmen
452. turn code in the function Lj If a function is not called directly or indirectly by main the compiler removes the function To see which program level optimizations the compiler is applying use the on2 option to generate an information file See section 3 5 2 Creating an Optimization Information File onn Option on page 3 19 for more information In Code Composer Studio when the pm option is used C and C files that have the same options are compiled together However if any file has a file specific option that is not selected as a project wide option that file is compiled separately For example if every C and C file in your project has a different set of file specific options each is compiled separately even though program level optimization has been specified To compile all C and C files together make sure the files do not have file specific options Be aware that compiling C and C files together may not be safe if previously you used a file specific option such as ma _ _ _ _ _ _ S SO _ _ _ e VU 00S oa ess sSsSsesesSseSesesSGeFe Note Compiling Files With the pm and k Options If you compile all files with the pm and k options the compiler produces only one asm file not one for each corresponding source file a Performing Program Level Optimization pm and O3 Options 3 6 1 Controlling Program Level Optimization opn Option You can control
453. u must handle any required enabling or masking of interrupts Such operations have no effect on the C C environment and are easily incorporated with asm statements or calling an assembly language function 8 6 1 Saving Registers During Interrupts When C C code is interrupted the interrupt routine must preserve the contents of all machine registers that are used by the routine or by any functions called by the routine The compiler handles register preservation if the interrupt service routine is written in C C 8 6 2 Using C C Interrupt Routines A C C interrupt routine is like any other C C function in that it can have local variables and register variables however it should be declared with no arguments and should return void C C interrupt routines can allocate up to 32K on the stack for local variables For example interrupt void example void If a C C interrupt routine does not call any other functions only those registers that the interrupt handler attempts to define are saved and restored However if a C C interrupt routine does call other functions these functions can modify unknown registers that the interrupt handler does not use For this reason the routine saves all usable registers if any other functions are called Interrupts branch to the interrupt return pointer IRP Do not call interrupt handling functions directly Interrupts can be handled directly with C C functions by using the interrupt p
454. ues uint _unpklu4 uint src UNPKLU4 Unpacks the two low unsigned 8 bit values into unsigned packed 16 bit values uint _xpnd2 uint src XPND2 Bits 1 and 0 of src are replicated to the upper and lower halfwords of the result respectively uint _xpnd4 uint src XPND4 Bits 3 and 0 of src are replicated to bytes 3 through 0 of the result T See the Tms320C6000 Programmer s Guide for more information See section 8 5 3 Using Unaligned Data and 64 Bit Values for details on manipulating 8 byte data quantities The intrinsics listed in Table 8 5 are included only for C67x devices The intrinsics shown correspond to the indicated C6000 assembly language instruction s See the TMS320C6000 CPU and Instruction Set Reference Guide for more information See Table 8 3 on page 8 27 for the listing of generic C6000 intrinsics See Table 8 4 on page 8 31 for the listing of C64x specific intrinsics Table 8 5 TMS320C67x C C Compiler Intrinsics Assembly C C Compiler Intrinsic Instruction Description int _dpint double src DPINT Converts 64 bit double to 32 bit signed integer using the rounding mode set by the CSR register double _fabs double src ABSDP Returns absolute value of src float _fabsf float src ABSSP double _mpyid int src7 int src2 MPYID Produces a signed integer multiply The result is placed in a register pair double _rcpdp double src RCPDP Computes the approximate 64 bit double reciprocal float
455. uments whose types can differ Such functions are called variable argument functions The stdarg h cstdarg header declares macros and a type that help you to use variable argument functions I The macros are va_start va_arg and va_end These macros are used when the number and type of arguments can vary each time a function is called Lj The type va_list is a pointer type that can hold information for va_start va_end and va_arg A variable argument function can use the macros declared by stdarg h cstdarg to step through its argument list at run time when the function knows the number and types of arguments actually passed to it You must ensure that a call to a variable argument function has visibility to a prototype for the function in order for the arguments to be handled correctly The variable argument functions are listed in Table 9 3 e page 9 34 Run Time Support Functions 9 23 Header Files 9 3 13 Standard Definitions sttdef h cstddef The stddef h cstddef header defines these types and macros m m The ptrdiff_t type is a signed integer type that is the data type resulting from the subtraction of two pointers The size_t type is an unsigned integer type that is the data type of the sizeof operator The NULL macro expands to a null pointer constant 0 The offsetof type identifier macro expands to an integer that has type size_t The result is the value of an offset in bytes to a structure member id
456. ump tables for large switch statements Executable code and constants b Uninitialized sections Name bss far stack sysmem Contents Global and static variables Global and static variables declared far Stack Memory for malloc functions heap Linking C C Code 5 11 Controlling the Linking Process When you link your program you must specify where to allocate the sections in memory In general initialized sections are linked into ROM or RAM uninitialized sections are linked into RAM With the exception of text the initialized and uninitialized sections created by the compiler cannot be allocated into internal program memory See section 8 1 1 on page 8 2 or a complete description of how the compiler uses these sections The linker provides MEMORY and SECTIONS directives for allocating sections For more information about allocating sections into memory see the linker chapter in the TMS320C6000 Assembly Language Tools User s Guide 5 3 6 A Sample Linker Command File 5 12 Example 5 1 shows a typical linker command file that links a C program The command file in this example is named Ink cmd and lists several linker options C Tells the linker to use autoinitialization at run time heap Tells the linker to set the C heap size at 0x2000 bytes stack Tells the linker to set the stack size to 0x0100 bytes l Tells the linker to use an archive library file rts6200 lib for input To link the program
457. und with 3 iterations in parallel bytes 3 6 Optimizing Software Pipelining The terms defined below appear in the software pipelining information For more information on each term see the TMS320C6000 Programmer s Guide m Loop unroll factor The number of times the loop was unrolled specifically to increase performance based on the resource bound constraint in a software pipelined loop Known minimum trip count The minimum number of times the loop will be executed Known maximun trip count The maximum number of times the loop will be executed Known max trip count factor Factor that would always evenly divide the loops trip count This information can be used to possibly unroll the loop Loop label The label you specified for the loop in the linear assembly input file This field is not present for C C code Loop carried dependency bound The distance of the largest loop carry path A loop carry path occurs when one iteration of a loop writes a value that must be read in a future iteration Instructions that are part of the loop carry bound are marked with the symbol Iteration interval ii The number of cycles between the initiation of successive iterations of the loop The smaller the iteration interval the fewer cycles it takes to execute a loop Resource bound The most used resource constrains the minimum iteration interval For example if four instructions require a D unit they require at
458. unlink drename specifiers are function pointers to the device drivers that are called by the low level functions to perform I O on the specified device You must declare these functions with the interface specified in section 9 2 1 Overview of Low Level I O Implementation on page 9 5 The device drivers for the host that the TMS320C6000 debugger is run on are included in the C I O library The function returns one of the following values 0 if successful 1 if fails Run Time Support Functions 9 7 add_device Example This example does the following Lj Adds the device mydevice to the device table J Opens a file named test on that device and associates it with the file fid J Writes the string Hello world into the file LJ Closes the file include lt stdio h gt BOR RK KK RK KR KK KK KKK KK RR KK KK k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k kk Declarations of the user defined device drivers S EEE KK K k RK k k k k k k k k KK k k k k k KR RK k k k k k KK k k RK k k k k RR k k k k k k k k k k k k k k KK k k k kk extern int my_open char path unsigned flags int fno extern int my_close int fno extern int my_read int fno char buffer unsigned count extern int my_write int fno char buffer unsigned count extern int my_lseek int fno long offset int origin extern int my_unlink char path extern int my_rename char old_ name char new_name main FILE fid add
459. use the following syntax cl6x z object_file s o outfile m mapfile Ink cmd The MEMORY and possibly the SECTIONS directives might require modification to work with your system See the TMS320C6000 Assembly Language Tools User s Guide for more information on these directives Controlling the Linking Process Example 5 1 Sample Linker Command File cC heap 0x2000 stack 0x010 MEMORY VECS PMEM BMEM SECTIONS vectors text data stack bss sysmem zeinit const cio sf r 0 1 rts6200 1ib 0 00000000h 1 00000400h 80000000h 1 VVVV VV VV VV 00400h reset amp interrupt vectors OFCOOh intended for initialization 10000h bss sysmem stack cinit ou il VECS PMEM BMEM BMEM BMEM BMEM BMEM BMEM BMEM BMEM 5 3 7 Using Function Subsections mo Compiler Option When the linker places code into an executable file it allocates all the functions in a single source file as a group This means that if any function in a file needs to be linked into an executable then all the functions in the file are linked in This can be undesirable if a file contains many functions and only a few are required for an executable This situation may exist in libraries where a single file contains multiple functions but the application only needs a subset of those functions An example is a library obj file that contains a signed divide routine
460. ust enable redundant loops or communicate the trip information Lj Speculative threshold exceeded It would be necessary to speculatively load beyond the threshold currently specified by the mh option You must increase the mh threshold as recommended in the software pipeline feedback located in the assembly file Optimizing Software Pipelining Register is live too long A register must have a value that exists is live for more than ii cycles You may insert MV instructions to split register lifetimes that are too long If the assembly optimizer is being used the sa file line numbers of the instructions that define and use the registers that are live too long are listed after this failure message ii 9 Register is live too long 10 gt 17 This means that the instruction that defines the register value is on line 10 and the instruction that uses the register value is on line 17 in the sa file Too many predicates live on one side The C6000 has predicate or conditional registers available for use with conditional instructions There are 5 predicate registers on the C6200 and C6700 and 6 predicate registers on the C6400 There are two or three on the A side and three on the B side Sometimes the particular partition and schedule combination requires more than these available registers Schedule found with N iterations in parallel A software pipeline schedule was found with N iterations executing in parallel
461. value to a Valid only within cproc procedures 4 29 procedure label trip min T trip count Valid only within procedures 4 30 volatile variable variable2 Designate memory Use mil if reference may be reference volatile modified during an interrupt Syntax Description call Calls a Function call ret_reg func_name arg1 arg2 Use the call directive to call a function Optionally you can specify a register that is assigned the result of the call The register can be a symbolic or machine register The call directive adheres to the same register and function calling conventions as the C C compiler For information see section 8 3 Register Conventions on page 8 17 land section 8 4 Function Structure and Calling Conventions on page 8 19 There is no support for alternative register or function calling conventions You cannot call a function that has a variable number of arguments such as printf No error checking is performed to ensure the correct number and or type of arguments is passed You cannot pass or return structures through the call directive Following is a description of the call directive parameters ret_reg Optional Symbolic machine register that is assigned the result of the call If not specified the assembly optimizer presumes the call overwrites the registers A5 and A4 with a result func_name The name of the function to call or the name of the symbolic machine register for indi
462. ve code objects that you want to link into an area separate from the text section Example 7 4 demonstrates the use of the CODE_SECTION pragma Example 7 4 Using the CODE_SECTION Pragma a C source file pragma CODE SECTION fn my sect int fn int x return x b Generated assembly code sect my sect global En PRR RRR RRR KERR KERR KKK KEK RRR KKK KERR KKK KER KKK KERR KK KKK RRR KKK KERR KERR KEE R KK KEK kkk kkk kkk kk FUNCTION NAME _fn x x F i Regs Modified SP Regs Used A4 B3 SP ae Local Frame Size 0 Args 4 Auto 0 Save 4 byte ekkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk fn a eS Se 1 RET S2 B3 6 SUB D2 SP 8 SP 4 STW D2T1 A4 SP 4 lal ADD S2 8 SP SP lel NOP 2 BRANCH OCCURS gt F l TMS320C6000 C C Language Implementation 7 19 Pragma Directives 7 7 2 The DATA_ALIGN Pragma The DATA_ALIGN pragma aligns the symbol to an alignment boundary The alignment boundary is the maximum of the symbol s default alignment value or the value of the constant in bytes The constant must be a power of 2 The syntax of the pragma in C is pragma DATA_ALIGN symbol constant The syntax of the pragma in C is pragma DATA_ALIGN constant 7 7 3 The DATA_MEM_BANK Pragma The DATA_MEM_BANK pragma aligns a symbol or variable to a specified
463. was previously allocated by a malloc calloc or realloc call This makes the memory space available again If you attempt to free unallocated space the function takes no action and returns For more information see section 8 1 3 Dynamic Memory Allocation on page 8 5 This example allocates ten bytes and frees them char x x malloc 10 allocate 10 bytes free x free 10 bytes Syntax for C Syntax for C Defined in Description frexp frexpf Syntax for C Syntax for C Defined in Description Example frexp frexpf Open File include lt stdio h gt FILE freopen const char _fname const char _mode register FILE _fp include lt cstdio gt FILE std freopen const char _fname const char _mode register FILE _fp fopen c in rts src The freopen function opens the file pointed to by _fname and associates with it the stream pointed to by _ fp The string pointed to by _mode describes how to open the file Fraction and Exponent include lt math h gt double frexp double value int exp float frexpf float value int exp include lt cmath gt double std frexp double value int exp float std frexpf float value int exp frexp c and frexpf c in rts src The frexp and frexpf functions break a floating point number into a normalized fraction f and the integer power of 2 These functions return f and exp such that 0 5 lt f lt 1 0 and value
464. ways be a memory bank conflict However it would find a schedule for a 2 cycle loop kernel 4 40 Avoiding Memory Bank Conflicts With the Assembly Optimizer 4 5 3 Memory Bank Conflicts for Indexed Pointers When determining memory bank conflicts for indexed memory accesses it is sometimes necessary to specify that a pair of memory accesses always conflict or that they never conflict This can be accomplished by using the mptr directive with a stride of 0 A stride of 0 indicates that there is a constant relation between the memory accesses regardless of the iteration delta Essentially only the base offset and width are used by the assembly optimizer to determine a memory bank conflict Recall that the stride is optional and defaults to 0 In Example 4 10 the mptr directive is used to specify which memory accesses conflict and which never conflict Example 4 10 Using mptr for Indexed Pointers S S L L mptr mptr mptr mptr DW DW TH TH a RS b RS G XY d XY 2 a i0a AO a and b always conflict with each other b 4 i0b BO Al c ila c and d never conflict with each other B2 d ilb Using the Assembly Optimizer 4 41 Avoiding Memory Bank Conflicts With the Assembly Optimizer 4 5 4 Memory Bank Conflict Algorithm 4 42 The assembly optimizer uses the following process to determine if two memory access instructions might have a memory bank conflict 1 If e
465. without revoking any of the features Changing the ISO C Language Mode The specific differences between the ISO version of C and the K amp R version of C are as follows d The integral promotion rules have changed regarding promoting an unsigned type to a wider signed type Under K amp R C the result type was an unsigned version of the wider type under ISO the result type is a signed version of the wider type This affects operations that perform differently when applied to signed or unsigned operands namely comparisons division and mod and right shift unsigned short u int i if Ue a SIGNED comparison unless pk used ISO prohibits combining two pointers to different types in an operation In most K amp R compilers this situation produces only a warning Such cases are still diagnosed when pk is used but with less severity int p char q p error without pk warning with pk External declarations with no type or storage class only an identifier are illegal in ISO but legal in K amp R a illegal unless pk used ISO interprets file scope definitions that have no initializers as tentative definitions In a single module multiple definitions of this form are fused together into a single definition Under K amp R each definition is treated as a separate definition resulting in multiple definitions of the same object and usually an error For example int a int a illegal if pk
466. x float ceilf float x include lt cmath gt double std ceil double x float std ceilf float x ceil c and ceilf c in rts src The ceil and ceilf functions return a floating point number that represents the smallest integer greater than or equal to x extern float ceil float answer 4 0 3 0 answer answer answer answer ceilf 3 1415 ceilf 3 5 Run Time Support Functions 9 51 clearerr Syntax for C Syntax for C Defined in Description Syntax for C Syntax for C Defined in Description 9 52 Clear EOF and Error Indicators include lt stdio h gt void clearerr FILE _fp include lt cstdio gt void std clearerr FILE _fp clearerr c in rts src The clearerr functions clears the EOF and error indicators for the stream that _ fp points to Processor Time include lt time h gt clock_t clock void include lt ctime gt clock_t std clock void clock c in rts src The clock function determines the amount of processor time used It returns an approximation of the processor time used by a program since the program began running The time in seconds is the return value divided by the value of the macro CLOCKS_PER_SEC If the processor time is not available or cannot be represented the clock function returns the value of clock_t 1 eS Note Writing Your Own Clock Function The clock function works with the stand alone simulator load6x
467. y mode These parameters can be ignored in some cases depending on how data is interpreted by the device However the high level I O calls look at how the file was opened in an fopen statement and prevent certain actions depending on the open attributes I The file_descriptor is the stream number assigned by the low level routines that is associated with the opened file or device The next available file descriptor in order from 3 to 20 is assigned to each new device opened You can use the finddevice function to return the device structure and use this pointer to search the _ stream array for the same pointer The file descriptor number is the other member of the _ stream array The function returns one of the following values 1 if successful 1 if fails Run Time Support Functions 9 11 read Syntax for C Syntax for C Description Return Value Syntax for C Syntax for C Description Return Value Read Characters From Buffer include lt stdio h gt include lt file h gt int read int file_descriptor char buffer unsigned count include lt cstdio gt include lt file h gt int std read int file_descriptor char buffer unsigned count The read function reads the number of characters specified by count to the buffer from the device or file associated with file_descriptor Lj The file_descriptor is the stream number assigned by the low level routines that is associated with the
468. yntax for C Syntax for C Defined in Description strcmp sitrcoll Find First Occurrence of a Character include lt string h gt char strchr const char string int c include lt cstring gt char std strchr const char string int c strchr c in rts src The strchr function finds the first occurrence of c in string If strchr finds the character it returns a pointer to the character otherwise it returns a null pointer 0 char a When zz comes home the search is on for zs char b char the z 2 b strchr a the 2z j After this example b points to the first z in zz String Compare include lt string h gt int stremp const char string1 register const char string2 int strcoll const char string1 const char string2 include lt cstring gt int std stremp const char string1 register const char string2 int std strcoll const char string1 const char string2 strcmp c and strcoll c in rts src The strcmp and strcoll functions compare string2 with string1 The functions are equivalent both functions are supported to provide compatibility with ISO C The functions return one of the following values lt 0 if string1 is less than string2 0 if string1 is equal to string2 gt 0_ if string1 is greater than string2 Run Time Support Functions 9 93 strcpy Example Syntax for C Syntax for C Defined in Description Example 9
469. you want the compiler to ignore strict ISO violations rather than emit a warning as occurs in normal ISO mode or an error message as occurs in strict ISO mode In relaxed ISO mode the compiler accepts extensions to the ISO C standard even when they conflict with ISO C 7 10 3 Enabling Embedded C Mode pe Option 7 38 The compiler supports the compilation of embedded C In this mode some features of C are removed that are of less value or too expensive to support in an embedded system Embedded C omits these C features Templates Exception handling Run time type information The new cast syntax The keyword mutable Multiple inheritance Virtual inheritance O O O O O C L Under the standard definition of embedded C namespaces and using declarations are not supported The C6000 compiler nevertheless allows these features under embedded C because the C runtime support library makes use of them Furthermore these features impose no runtime penalty Chapter 8 Run Time Environment This chapter describes the TMS320C6000 C C run time environment To ensure successful execution of C C programs it is critical that all run time code maintain this environment It is also important to follow the guidelines in this chapter if you write assembly language functions that interface with C C code Topic 6 1 Memory Modell lt ssssss 515 cjenienc stasis cslamernse cla ateaiee sane selec 8 2 Object Represe

Download Pdf Manuals

image

Related Search

Related Contents

Samsung B5310 Korisničko uputstvo  Tenma 72-7210 Manual  Voir le programme des activités pour chaque école.  ZENITH SERIES - Graham Field  CPS-V38098-3  Manuale d`installazione  DELL OptiPlex 9010  Pharmaceutical Edition v5.04  Important: Caution:  Originalbetriebsanleitung Original Operating Instructions  

Copyright © All rights reserved.
Failed to retrieve file