Tms320c6000-Optimizing Compiler Users Guide
Tms320c6000-Optimizing Compiler Users Guide
IMPORTANT NOTICE Texas Instruments and its subsidiaries (TI) reserve the right to make changes to their products or to discontinue any product or service without notice, and advise customers to obtain the latest version of relevant information to verify, before placing orders, that information being relied on is current and complete. All products are sold subject to the terms and conditions of sale supplied at the time of order acknowledgment, including those pertaining to warranty, patent infringement, and limitation of liability. TI warrants performance of its products to the specifications applicable at the time of sale in accordance with TIs standard warranty. Testing and other quality control techniques are utilized to the extent TI deems necessary to support this warranty. Specific testing of all parameters of each device is not necessarily performed, except those mandated by government requirements. Customers are responsible for their applications using TI components. In order to minimize risks associated with the customers applications, adequate design and operating safeguards must be provided by the customer to minimize inherent or procedural hazards. TI assumes no liability for applications assistance or customer product design. TI does not warrant or represent that any license, either express or implied, is granted under any patent right, copyright, mask work right, or other intellectual property right of TI covering or relating to any combination, machine, or process in which such products or services might be or are used. TIs publication of information regarding any third partys products or services does not constitute TIs approval, license, warranty or endorsement thereof. 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. Representation or reproduction of this information with alteration voids all warranties provided for an associated TI product or service, is an unfair and deceptive business practice, and TI is not responsible nor liable for any such use. Resale of TIs products or services with statements different from or beyond the parameters stated by TI for that products or service voids all express and any implied warranties for the associated TI product or service, is an unfair and deceptive business practice, and TI is not responsible nor liable for any such use. Also see: Standard Terms and Conditions of Sale for Semiconductor Products. www.ti.com/sc/docs/stdterms.htm
Mailing Address: Texas Instruments Post Office Box 655303 Dallas, Texas 75265
Preface
Compiler Assembly optimizer Standalone simulator Library-build utility C++ name demangling utility
The TMS320C6000 C/C++ compiler accepts C++ as well as American National Standards Institute (ANSI) standard C source code and produces assembly language source code for the TMS320C6000 device. This user s guide discusses the characteristics of the C/C++ compiler. It assumes that you already know how to write C/C++ programs. The C Programming Language (second edition), by Brian W. Kernighan and Dennis M. Ritchie, describes C based on the ANSI C standard. You can use the Kernighan and Ritchie (hereafter referred to as K&R) book as a supplement to this manual. References to K&R C (as opposed to ANSI C) in this manual refer to the C language as defined in the first edition of Kernighan and Ritchies 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.
iii
Notational Conventions
Notational Conventions
This document uses the following conventions:
- 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 <stdio.h> main() { printf(hello, world\n); } - In syntax descriptions, the instruction, command, or directive is in a bold-
face 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: 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}
- 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: lnk6x {c | cr} filenames [o name.out] l libraryname
iv
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
You can use the following books to supplement this user s guide: American National Standard for Information SystemsProgramming Language C X3.159-1989, American National Standards Institute (ANSI standard for C) Working Paper for Draft Proposed International Standard for Information SystemsProgramming Language C++ X3J16/WG21, 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 Programming in C, Steve G. Kochan, Hayden Book Company Programming Embedded Systems in C and C++, by Michael Barr, Andy Oram (Editor), published by OReilly & Associates; ISBN: 1565923545, February 1999 The C Programming Language (second edition), by Brian W. Kernighan and Dennis M. Ritchie, published by Prentice-Hall, Englewood Cliffs, New Jersey, 1988 The Annotated C++ Reference Manual, Margaret A. Ellis and Bjame Stroustrup, published by Addison-Wesley Publishing Company, Reading, Massachusetts, 1990 The C++ Programming Language (second edition), Bjame Stroustrup, published by Addison-Wesley Publishing Company, Reading, Massachusetts, 1990
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.
vi
Contents
Contents
1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-1 Provides an overview of the TMS320C6000 software development tools, specifically the optimizing C compiler. 1.1 1.2 Software Development Tools Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C/C++ Compiler Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.2.1 C/C++ Language Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.2.2 Output Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.2.3 Compiler Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.2.4 Compiler Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.2.5 Utilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2 1-5 1-5 1-6 1-6 1-7 1-7
Using the C/C++ Compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-1 Describes how to operate the C/C++ compiler and the shell program. Contains instructions for invoking the shell program, which compiles, assembles, and links a C/C++ source file. Discusses the interlist utility, options, and compiler errors. 2.1 2.2 2.3 About the Shell Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2 Invoking the C/C++ Compiler Shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4 Changing the Compiler s Behavior With Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-6 2.3.1 Frequently Used Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-15 2.3.2 Specifying Filenames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-18 2.3.3 Changing How the Shell Program Interprets Filenames (fa, fc, fg, fl, fo, and fp Options) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-19 2.3.4 Changing How the Shell Program Interprets and Names Extensions (ea, ec, el, eo, and ep Options) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-20 2.3.5 Specifying Directories (fb, ff, fr, fs, and ft Options) . . . . . . . . . . . . . . . . . 2-21 2.3.6 Options That Control the Assembler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-22 Setting Default Shell Options (C_OPTION and C_C6X_OPTION) . . . . . . . . . . . . . . . . 2-23 Controlling the Preprocessor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-24 2.5.1 Predefined Macro Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-24 2.5.2 The Search Path for #include Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-25 2.5.3 Generating a Preprocessed Listing File (ppo Option) . . . . . . . . . . . . . . . . . . . 2-27 2.5.4 Continuing Compilation After Preprocessing (ppa Option) . . . . . . . . . . . . . . . 2-27 2.5.5 Generating a Preprocessed Listing File With Comments (ppc Option) . . . . 2-28 2.5.6 Generating a Preprocessed Listing File With Line-Control Information (ppl Option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-28 2.5.7 Generating Preprocessed Output for a Make Utility (ppd Option) . . . . . . . . . 2-28 2.5.8 Generating a List of Files Included With the #include Directive (ppi Option) 2-28
vii
2.4 2.5
Contents
2.6
Understanding Diagnostic Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.6.1 Controlling Diagnostics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.6.2 How You Can Use Diagnostic Suppression Options . . . . . . . . . . . . . . . . . . . . . Other Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Generating Cross-Reference Listing Information (px Option) . . . . . . . . . . . . . . . . . . . Generating a Raw Listing File (pl Option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using Inline Function Expansion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.10.1 Inlining Intrinsic Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.10.2 Automatic Inlining . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.10.3 Unguarded Definition-Controlled Inlining . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.10.4 Guarded Inlining and the _INLINE Preprocessor Symbol . . . . . . . . . . . . . . . . 2.10.5 Inlining Restrictions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Interrupt Flexibility Options (mi Option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Linking C6400 Code With C6200/C6700/Older C6400 Object Code . . . . . . . . . . . . . . Using the Interlist Utility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2-29 2-31 2-32 2-33 2-33 2-34 2-36 2-36 2-36 2-37 2-38 2-40 2-41 2-42 2-43
Optimizing Your Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-1 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 3.2 Invoking Optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2 Optimizing Software Pipelining . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-4 3.2.1 Turn Off Software Pipelining (mu Option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-5 3.2.2 Software Pipelining Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-5 3.2.3 Collapsing Prologs and Epilogs for Improved Performance and Code Size . 3-13 3.2.4 Selecting Target CPU Version (mv Option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-15 Redundant Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-16 Reducing Code Size (ms Option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-17 Performing File-Level Optimization ( o3 Option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-18 3.5.1 Controlling File-Level Optimization (oln Option) . . . . . . . . . . . . . . . . . . . . . . . . 3-18 3.5.2 Creating an Optimization Information File (onn Option) . . . . . . . . . . . . . . . . . 3-19 Performing Program-Level Optimization (pm and o3 Options) . . . . . . . . . . . . . . . . . 3-20 3.6.1 Controlling Program-Level Optimization (opn Option) . . . . . . . . . . . . . . . . . . 3-21 3.6.2 Optimization Considerations When Mixing C/C++ and Assembly . . . . . . . . . . 3-22 Indicating Whether Certain Aliasing Techniques Are Used . . . . . . . . . . . . . . . . . . . . . . . 3-25 3.7.1 Use the ma Option When Certain Aliases are Used . . . . . . . . . . . . . . . . . . . . 3-25 3.7.2 Use the mt Option to Indicate That These Techniques Are Not Used . . . . . 3-26 3.7.3 Using the mt Option With the Assembly Optimizer . . . . . . . . . . . . . . . . . . . . . 3-27 Prevent Reordering of Associative Floating-Point Operations . . . . . . . . . . . . . . . . . . . . 3-28 Use Caution With asm Statements in Optimized Code . . . . . . . . . . . . . . . . . . . . . . . . . . 3-28 Automatic Inline Expansion (oi Option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-29 Using the Interlist Utility With the Optimizer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-30
3.6
3.7
Contents
3.12
3.13
Debugging and Profiling Optimized Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.12.1 Debugging Optimized Code (g, gw, and o Options) . . . . . . . . . . . . . . . . . . 3.12.2 Profiling Optimized Code (gp and o Options) . . . . . . . . . . . . . . . . . . . . . . . . . What Kind of Optimization Is Being Performed? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.13.1 Cost-Based Register Allocation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.13.2 Alias Disambiguation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.13.3 Branch Optimizations and Control-Flow Simplification . . . . . . . . . . . . . . . . . . . 3.13.4 Data Flow Optimizations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.13.5 Expression Simplification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.13.6 Inline Expansion of Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.13.7 Induction Variables and Strength Reduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.13.8 Loop-Invariant Code Motion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.13.9 Loop Rotation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.13.10 Register Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.13.11 Register Tracking/Targeting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.13.12 Software Pipelining . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3-33 3-33 3-34 3-35 3-36 3-38 3-38 3-41 3-41 3-42 3-43 3-44 3-44 3-44 3-44 3-45
Using the Assembly Optimizer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-1 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 4.2 4.3 Code Development Flow to Increase Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2 About the Assembly Optimizer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-4 What You Need to Know to Write Linear Assembly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-4 4.3.1 Linear Assembly Source Statement Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-6 4.3.2 Functional Unit Specification for Linear Assembly . . . . . . . . . . . . . . . . . . . . . . . . 4-8 4.3.3 Using Linear Assembly Source Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-14 Assembly Optimizer Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-16 Avoiding Memory Bank Conflicts With the Assembly Optimizer . . . . . . . . . . . . . . . . . . 4-34 4.5.1 Preventing Memory Bank Conflicts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-35 4.5.2 A Dot Product Example That Avoids Memory Bank Conflicts . . . . . . . . . . . . . 4-38 4.5.3 Memory Bank Conflicts for Indexed Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-42 4.5.4 Memory Bank Conflict Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-43 Memory Alias Disambiguation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-44 4.6.1 How the Assembly Optimizer Handles Memory References (Default) . . . . . . 4-44 4.6.2 Using the mt Option to Handle Memory References . . . . . . . . . . . . . . . . . . . . 4-44 4.6.3 Using the .no_mdep Directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-44 4.6.4 Using the .mdep Directive to Identify Specific Memory Dependences . . . . . . 4-45 4.6.5 Memory Alias Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-47
4.4 4.5
4.6
Contents
ix
Contents
Linking C/C++ Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-1 Describes how to link using a stand-alone program or with the compiler shell and how to meet the special requirements of linking C code. 5.1 5.2 5.3 5.4 5.5 Invoking the Linker as an Individual Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2 Invoking the Linker With the Compiler Shell (z Option) . . . . . . . . . . . . . . . . . . . . . . . . . . 5-4 Disabling the Linker (c Shell Option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-5 Linker Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-6 Controlling the Linking Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-8 5.5.1 Linking With Run-Time-Support Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-8 5.5.2 Run-Time Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-9 5.5.3 Global Variable Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-10 5.5.4 Specifying the Type of Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-10 5.5.5 Specifying Where to Allocate Sections in Memory . . . . . . . . . . . . . . . . . . . . . . 5-11 5.5.6 A Sample Linker Command File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-13 5.5.7 Using Function Subsections (mo Shell Option) . . . . . . . . . . . . . . . . . . . . . . . . 5-14
Using the Stand-Alone Simulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-1 Describes how to invoke the stand-alone simulator and provides an example. 6.1 6.2 6.3 6.4 6.5 Invoking the Stand-Alone Simulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Stand-Alone Simulator Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using the Profiling Capability of the Stand-Alone Simulator . . . . . . . . . . . . . . . . . . . . . . . Selecting Silicon Revision to Simulate (rev Option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Stand-Alone Simulator Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-2 6-4 6-6 6-8 6-9
TMS320C6000 C/C++ Language Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-1 Discusses the specific characteristics of the TMS320C6000 C/C++ compiler as they relate to the ANSI C specification. 7.1 Characteristics of TMS320C6000 C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-2 7.1.1 Identifiers and Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-2 7.1.2 Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-3 7.1.3 Conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-3 7.1.4 Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-3 7.1.5 Declarations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-4 7.1.6 Preprocessor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-4 Characteristics of TMS320C6000 C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-5 Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-6 Keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-7 7.4.1 The const Keyword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-7 7.4.2 The cregister Keyword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-8 7.4.3 The interrupt Keyword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-10 7.4.4 The near and far Keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-11 7.4.5 The restrict Keyword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-14 7.4.6 The volatile Keyword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-15
Contents
Register Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The asm Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Pragma Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.7.1 The CODE_SECTION Pragma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.7.2 The DATA_ALIGN Pragma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.7.3 The DATA_MEM_BANK Pragma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.7.4 The DATA_SECTION Pragma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.7.5 The FUNC_CANNOT_INLINE Pragma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.7.6 The FUNC_EXT_CALLED Pragma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.7.7 The FUNC_INTERRUPT_THRESHOLD Pragma . . . . . . . . . . . . . . . . . . . . . . . 7.7.8 The FUNC_IS_PURE Pragma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.7.9 The FUNC_IS_SYSTEM Pragma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.7.10 The FUNC_NEVER_RETURNS Pragma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.7.11 The FUNC_NO_GLOBAL_ASG Pragma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.7.12 The FUNC_NO_IND_ASG Pragma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.7.13 The INTERRUPT Pragma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.7.14 The MUST_ITERATE Pragma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.7.15 The NMI_INTERRUPT Pragma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.7.16 The PROB_ITERATE Pragma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.7.17 The STRUCT_ALIGN Pragma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.7.18 The UNROLL Pragma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Generating Linknames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Initializing Static and Global Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Changing the ANSI C language Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.10.1 Compatibility With K&R C (pk Option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.10.2 Enabling Strict ANSI Mode and Relaxed ANSI Mode (ps and pr Options) 7.10.3 Enabling Embedded C++ Mode (pe Option) . . . . . . . . . . . . . . . . . . . . . . . . . . .
7-16 7-17 7-18 7-19 7-20 7-20 7-22 7-23 7-23 7-24 7-25 7-25 7-26 7-26 7-27 7-27 7-28 7-29 7-29 7-30 7-31 7-32 7-33 7-34 7-34 7-36 7-36
Run-Time Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-1 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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-2 8.1.1 Sections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-3 8.1.2 C/C++ System Stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-4 8.1.3 Dynamic Memory Allocation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-5 8.1.4 Initialization of Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-6 8.1.5 Memory Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-6 8.1.6 Position Independent Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-7 Object Representation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-8 8.2.1 Data Type Storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-8 8.2.2 Bit Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-14 8.2.3 Character String Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-15 Register Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-16
Contents xi
8.2
8.3
Contents
8.4
8.5
8.6
8.7 8.8
Function Structure and Calling Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.4.1 How a Function Makes a Call . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.4.2 How a Called Function Responds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.4.3 Accessing Arguments and Local Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Interfacing C and C++ With Assembly Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.5.4 Using MUST_ITERATE and _nassert to Enable SIMD and Expand Compiler Knowledge of Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.5.5 SAT Bit Side Effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.5.6 Using Inline Assembly Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.5.7 Accessing Assembly Language Variables From C/C++ . . . . . . . . . . . . . . . . . . Interrupt Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.6.1 Saving Registers During Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.6.2 Using C/C++ Interrupt Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.6.3 Using Assembly Language Interrupt Routines . . . . . . . . . . . . . . . . . . . . . . . . . . Run-Time-Support Arithmetic Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . System Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.8.1 Automatic Initialization of Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.8.2 Global Constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.8.3 Initialization Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.8.4 Autoinitialization of Variables at Run Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.8.5 Initialization of Variables at Load Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
8-18 8-18 8-19 8-21 8-22 8-22 8-25 8-35 8-35 8-37 8-38 8-39 8-41 8-41 8-41 8-42 8-43 8-45 8-46 8-46 8-47 8-50 8-51
Run-Time-Support Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-1 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-ANSI run-time-support functions. 9.1 Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-2 9.1.1 Linking Code With the Object Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-2 9.1.2 Modifying a Library Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-3 9.1.3 Building a Library With Different Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-3 The C I/O Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-4 9.2.1 Overview of Low-Level I/O Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-5 9.2.2 Adding a Device for C I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-11 Header Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-13 9.3.1 Diagnostic Messages (assert.h/cassert) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-14 9.3.2 Character-Typing and Conversion (ctype.h/cctype) . . . . . . . . . . . . . . . . . . . . . . 9-14 9.3.3 Error Reporting (errno.h/cerrno ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-15 9.3.4 Low-Level Input/Output Functions (file.h ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-15 9.3.5 Fast Macros/Static Inline Functions (gsm.h ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-15 9.3.6 Limits (float.h/cfloat and limits.h/climits) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-16
9.2
9.3
xii
Contents
9.4 9.5
9.3.7 Function Calls as near or far (linkage.h) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.3.8 Floating-Point Math (math.h/cmath ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.3.9 Nonlocal Jumps (setjmp.h/csetjmp) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.3.10 Variable Arguments (stdarg.h/cstdarg ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.3.11 Standard Definitions (sttdef.h/cstddef ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.3.12 Input/Output Functions (stdio.h/cstdio) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.3.13 General Utilities (stdlib.h/cstdlib ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.3.14 String Functions (string.h/cstring ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.3.15 Time Functions (time.h/ctime ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.3.16 Exception Handling (exception and stdexcept) . . . . . . . . . . . . . . . . . . . . . . . . . 9.3.17 Dynamic Memory Management (new) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.3.18 Run-Time Type Information (typeinfo) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Summary of Run-Time-Support Functions and Macros . . . . . . . . . . . . . . . . . . . . . . . . . Description of Run-Time-Support Functions and Macros . . . . . . . . . . . . . . . . . . . . . . . .
9-18 9-18 9-19 9-19 9-20 9-20 9-21 9-22 9-22 9-24 9-24 9-24 9-25 9-37
10 Library-Build Utility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-1 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 10.2 10.3 10.4 Standard Run-Time-Support Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Invoking the Library-Build Utility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Library-Build Utility Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Options Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-2 10-3 10-4 10-5
11 C++ Name Demangler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-1 Describes the C++ name demangler and tells you how to invoke and use it. 11.1 11.2 11.3 A Invoking the C++ Name Demangler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-2 C++ Name Demangler Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-2 Sample Usage of the C++ Name Demangler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-3
Contents
xiii
Contents
Figures
11 21 31 32 41 42 81 82 83 84 85 86 87 88 89 810 91 92 TMS320C6000 Software Development Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2 The Shell Program Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-3 Compiling a C/C++ Program With the Optimizer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2 Software-Pipelined Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-4 4-Bank Interleaved Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-34 4-Bank Interleaved Memory With Two Memory Spaces . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-35 Char and Short Data Storage Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-9 32-Bit Data Storage Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-10 40-Bit Data Storage Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-11 Double-Precision Floating-Point Data Storage Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-12 Bit Field Packing in Big-Endian and Little-Endian Formats . . . . . . . . . . . . . . . . . . . . . . . . . 8-14 Register Argument Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-19 Format of Initialization Records in the .cinit Section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-47 Format of Initialization Records in the .pinit Section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-49 Autoinitialization at Run Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-50 Initialization at Load Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-51 Interaction of Data Structures in I/O Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-5 The First Three Streams in the Stream Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-6
xiv
Contents
Tables
21 22 23 24 31 32 33 34 35 41 51 71 72 81 82 83 84 91 92 93 101 Shell Options Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-7 Predefined Macro Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-24 Raw Listing File Identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-34 Raw Listing File Diagnostic Identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-35 Options That You Can Use With o3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-18 Selecting a Level for the ol Option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-18 Selecting a Level for the on Option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-19 Selecting a Level for the op Option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-21 Special Considerations When Using the op Option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-22 Assembly Optimizer Directives Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-16 Sections Created by the Compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-11 TMS320C6000 C/C++ Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-6 Valid Control Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-8 Data Representation in Registers and Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-8 Register Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-17 TMS320C6000 C/C++ Compiler Intrinsics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-25 Summary of Run-Time-Support Arithmetic Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-43 Macros That Supply Integer Type Range Limits (limits.h/climits) . . . . . . . . . . . . . . . . . . . . 9-16 Macros That Supply Floating-Point Range Limits (float.h/cfloat) . . . . . . . . . . . . . . . . . . . . 9-17 Summary of Run-Time-Support Functions and Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-26 Summary of Options and Their Effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-5
Contents
xv
Contents
Examples
21 22 23 31 32 33 34 35 36 37 38 41 42 43 44 45 46 47 48 49 410 411 412 413 414 415 416 417 51 61 62 63 64 71 72
xvi
Using the inline keyword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-37 How the Run-Time-Support Library Uses the _INLINE Preprocessor Symbol . . . . . . . . . 2-39 An Interlisted Assembly Language File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-44 Software Pipelining Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-6 The Function From Example 23 Compiled With the o2 and os Options . . . . . . . . . . . 3-31 The Function From Example 23 Compiled With the o2, os, and ss Options . . . . . . 3-32 Strength Reduction, Induction Variable Elimination, Register Variables, and Software Pipelining . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-36 Control-Flow Simplification and Copy Propagation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-39 Data Flow Optimizations and Expression Simplification . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-42 Inline Function Expansion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-43 Register Tracking/Targeting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-45 C Code for Computing a Dot Product . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-9 Linear Assembly Code for Computing a Dot Product . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-10 Software-Pipeline Kernel for Computing a Dot Product With Example 42 . . . . . . . . . . . 4-11 Software Pipeline Information for Example 42 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-12 Code From Example 42 With Functional Unit Specifiers Added . . . . . . . . . . . . . . . . . . . 4-13 Software-Pipeline Kernel for Computing a Dot Product With Example 45 . . . . . . . . . . . 4-14 Lmac Function Code Showing Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-15 Load and Store Instructions That Specify Memory Bank Information . . . . . . . . . . . . . . . . 4-37 C Code for Dot Product . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-38 Linear Assembly for Dot Product . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-39 Dot Product Software-Pipelined Kernel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-39 Dot Product From Example 410 Unrolled to Prevent Memory Bank Conflicts . . . . . . . . 4-40 Unrolled Dot Product Kernel From Example 411 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-41 Using .mptr for Indexed Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-42 Annotating a Memory Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-45 Software Pipeline Using .mdep ld1, st1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-46 Software Pipeline Using .mdep st1, ld1 and .mdep ld1, st1 . . . . . . . . . . . . . . . . . . . . . . . . 4-46 Sample Linker Command File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-13 Sample Stand-Alone Simulator Banners . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-3 Profiling Dot Product Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-6 C Code With Clock Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-9 Stand-Alone Simulator Results After Compiling and Linking Example 63 . . . . . . . . . . . . 6-9 Define and Use Control Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-9 Use of the restrict type qualifier with pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-14
Contents
73 74 75 76 81 82 83 84 85 86 111 112
Use of the restrict type qualifier with arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using the CODE_SECTION Pragma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using the DATA_MEM_BANK Pragma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using the DATA_SECTION Pragma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Calling an Assembly Language Function From C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using the _lo and _hi Intrinsics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Accessing an Assembly Language Variable From C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Accessing an Assembly Language Constant From C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . AMR and SAT Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Initialization Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Name Mangling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Result After Running the C++ Name Demangler Utility . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7-14 7-19 7-21 7-22 8-24 8-35 8-39 8-40 8-42 8-48 11-3 11-5
Contents
xvii
Contents
Notes
Case Sensitivity in Filename Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-18 No Default Extension for Source Files is Assume . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-18 Specifying Path Information in Angle Brackets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-27 Function Inlining Can Greatly Increase Code Size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-36 RTS Library Files Are Not Built With mi Option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-41 Do Not Lower the Optimization Level to Control Code Size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3 The on Option Applies to the Assembly Optimizer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3 Software Pipelining Can Significantly Increase Code Size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-5 More Details on Software Pipelining Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-5 Turning Off Redundant Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-15 Turning Off Redundant Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-17 Disabling Code-Size Optimizations or Reducing the Optimization Level . . . . . . . . . . . . . . . . . . . . 3-17 Do Not Lower the Optimization Level to Control Code Size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-18 o3 Optimization and Inlining . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-29 Inlining and Code Size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-29 Impact on Performance and Code Size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-30 The g or gw Option Causes Performance and Code Size Degradations . . . . . . . . . . . . . . . . . . 3-33 Profile Points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-34 Finer Grained Profiling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-34 Do Not Use Scheduled Assembly Code as Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-5 Reserving Registers A4 and A5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-30 Memory Dependency Exception . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-44 Memory Dependence/Bank Conflict . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-47 The _c_int00 Symbol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-9 Defining Global Variables in Assembly Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-12 Avoid Disrupting the C/C++ Environment With asm Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-17 The Linker Defines the Memory Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-2 Use Only Code in Program Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-3 Stack Overflow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-5 Intrinsic Instructions in C versus Assembly Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-25 C++ Syntax for _nassert . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-36 Using the asm Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-38 Initializing Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-46 Use Unique Function Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-11 Writing Your Own Clock Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-23 Writing Your Own Clock Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-50 No Previously Allocated Objects Are Available After minit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-75 The time Function Is Target-System Specific . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-103
xviii
Chapter 1
Introduction
The TMS320C6000 is supported by 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
1.1 1.2
Page
Software Development Tools Overview . . . . . . . . . . . . . . . . . . . . . . . . . 1-2 C/C++ Compiler Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5
Introduction
1-1
1.1
C/C++ compiler
Linear assembly
Archiver
Assembler source
Assembly optimizer
Assemblyoptimized file
Archiver
Library-build utility
Linker
Run-Timesupport library
Debugging tools
EPROM programmer
Cross-reference lister
TMS320C6000
1-2
The following list describes the tools that are shown in Figure 11:
- The 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 Chapter 4, 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 shell program, an optimizer, and an interlist utility are parts of the compiler:
J
The shell program enables you to compile, assemble, and link source modules in one step. If any input file has a .sa extension, the shell program invokes the assembly optimizer. The optimizer modifies code to improve the efficiency of C programs. The interlist utility interweaves C/C++ source statements with assembly language output.
J J
See Chapter 2, Using the C/C++ Compiler, for information about how to invoke the C/C++ compiler, the optimizer, and the interlist utility using the shell 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 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 Chapter 5, 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
- You can use the library-build utility to build your own customized run-
time-support library (see Chapter 10, Library-Build Utility). Standard runtime-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:
J J
For little-endian C and C++ coderts6200.lib, rts6400.lib, and rts6700.lib For big-endian C and C++ coderts6200e.lib, rts6400e.lib, and rts6700e.lib
The run-time-support libraries contain the ANSI 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 Chapter 8, Run-Time Environment.
- The hex conversion utility converts a COFF object file into TI-Tagged,
ASCII-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:
J J
For information about these debugging tools, see the TMS320C6000 Code Composer Studio Tutorial and the Code Composer Studio User s Guide.
1-4
1.2
1.2.1
The C6000 C/C++ compiler fully conforms to the ANSI C standard as defined by the ANSI specification and described in the second edition of Kernighan and Ritchies The C Programming Language (K&R). The ANSI C standard includes extensions to C that provide maximum portability and increased capability.
- C++
The C6000 C/C++ compiler supports C++ as defined by the ISO/IEC 148821998 standard with certain exceptions. For more information, see section 7.2, Characteristics of TMS320C6000 C++, on page 7-5.
- ANSI-standard run-time support
The compiler tools come with a complete run-time library. All library functions conform to the ANSI 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 ANSI C subset as well as those components necessary for language support. For more information, see Chapter 8, Run-Time Environment.
Introduction
1-5
1.2.2
Output Files
The following features pertain to output files created by the compiler:
- 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 systems 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.
- Code to initialize data into ROM
For stand-alone embedded applications, the compiler enables you to link all code and initialization data into ROM, allowing C/C++ code to run from reset.
1.2.3
Compiler Interface
The following features pertain to interfacing with the compiler:
- Compiler shell program
The compiler tools include a shell 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 Shell Program, on page 2-2.
- Flexible assembly language interface
The compiler has straightforward calling conventions, so you can write assembly and C functions that call each other. For more information, see Chapter 8, Run-Time Environment.
1-6
1.2.4
Compiler Operation
The following features pertain to the operation of the compiler:
- 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-24.
- 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.
1.2.5
Utilities
The following features pertain to the compiler utilities:
- Source interlist utility
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 Utility, on page 2-43.
- Library-build utility
The library-build utility (mk6x) lets you custom-build object libraries from source for any combination of 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 utility
The C++ name demangler (dem6x) is a debugging aid that converts mangled names found in the output of the compiler tools (such as assembly files and linker error messages) back to their original name as declared in C++ source. For more information, see Chapter 11, C++ Name Demangler.
Introduction 1-7
1-8
Chapter 2
Topic
2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9
Page
About the Shell Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2 Invoking the C/C++ Compiler Shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4 Changing the Compiler s Behavior With Options . . . . . . . . . . . . . . . . 2-6 Setting Default Shell Options (C_OPTION and C6X_C_OPTION) . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-23 Controlling the Preprocessor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-24 Understanding Diagnostic Messages . . . . . . . . . . . . . . . . . . . . . . . . . . 2-29 Other Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-33 Generating Cross-Reference Listing Information (px Option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-33 Generating a Raw Listing File (pl Option) . . . . . . . . . . . . . . . . . . . . . 2-34
2.10 Using Inline Function Expansion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-36 2.11 Interrupt Flexibility Options (min Option) . . . . . . . . . . . . . . . . . . . . . 2-41 2.12 Linking C6400 Code With C6200/C6700/Older C6400 Object Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-42 2.13 Using the Interlist Utility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-43
2-1
2.1
accepts C or C++ source code and produces C6000 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 2.3.2, Specifying Filenames, for more information.
- The assembler generates a COFF object file. - The linker links your files to create an executable object file. The linker is
optional with the shell. You can compile and assemble various files with the shell and link them later. See Chapter 5, Linking C/C++ Code, for information about linking the files in a separate step. By default, the shell compiles and assembles files; however, you can also link the files using the z shell option. Figure 21 illustrates the path the shell takes with and without using the linker.
2-2
Assembler source
Assembler
Linker
For a complete description of the assembler and the linker, see the TMS320C6000 Assembly Language Tools User s Guide.
2-3
The z option and its associated information (linker options and object files) must follow all filenames and compiler options on the command line. You can specify all other options (except linker options) and filenames in any order on the command line. 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 suppress progress messages (q), you enter:
cl6x q symtab.c file.c seek.asm find.sa
As cl6x encounters each source file, it prints the C/C++ filenames in square brackets ( [ ] ), assembly language filenames in angle brackets ( < > ), and linear assembly files in braces ( { } ). This example uses the q option to suppress the additional progress information that cl6x produces. Entering this command produces these messages:
[symtab.c] [file.c] <seek.asm> {find.sa}
2-4
The normal progress information consists of a banner for each compiler pass and the names of functions as they are processed. The example below shows the output from compiling a single file (symtab) without the q option:
% cl6x symtab.c [symtab.c] TMS320C6x ANSI C/C++ Compiler Version xx Copyright (c) 19962000 Texas Instruments Incorporated symtab.c ==> symtab TMS320C6x ANSI C/C++ Codegen Version xx Copyright (c) 19962000 Texas Instruments Incorporated symtab.c: ==> symtab TMS320C6x COFF Assembler Version xx Copyright (c) 19962000 Texas Instruments Incorporated PASS 1 PASS 2 No Errors, No Warnings
2-5
sgq is equivalent to s g q.
- Two-letter pair options that have the same first letter can be combined. For
space before the parameter. For example, the option to undefine a name can be expressed as u name or uname. However, a required numeric parameter must be placed immediately after the option (no space between the option and parameter).
- An option with an optional parameter must be specified with the parameter
immediately after the option. That is, no space is between the option and parameter. For example, the option to specify the maximum amount of optimization must be expressed as o3, not o 3.
- Files and options except the z option can occur in any order. The z op-
tion must follow all other compiler options and precede any linker options. You can define default options for the shell 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 Shell Options (C_OPTION and C6X_C_OPTION), on page 2-23. Table 21 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, enter cl6x with no parameters on the command line.
2-6
idirectory k n q qq s
ss uname z
2-7
(c) Options that specify files Option fafilename Effect Identifies filename as an assembly source file regardless of its extension. By default, the compiler and assembler treat .asm files as assembly source files. Identifies filename as a C source file regardless of its extension. By default, the compiler treats .c files as C source files. Processes a C filename as a C++ file. Identifies filename as a linear assembly source file regardless of its extension. By default, the compiler and assembly optimizer treat .sa files as linear assembly source files. Identifies filename as an object code file regardless of its extension. By default, the compiler and linker treat .obj files as object code files. Identifies filename as a C++ file, regardless of its extension. By default, the compiler treats .C, .cpp, .cc and .cxx files as a C++ files. Page 2-19
fcfilename
2-19
fgfilename flfilename
2-19 2-19
fofilename
2-19
fpfilename
2-19
2-8
(e) Options that are machine-specific Option ma mb Effect Indicates that a specific aliasing technique is used Compiles C6400 code compatible with array alignment restrictions of version 4.0 tools or C6200/C6700 object code Prevents reordering of associative floatingpoint 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, and ml2, and ml3) Turns on function subsections Make calls to run-time-support functions near (mr0) or far (mr1) Controls code size on four levels (ms0, ms1, ms2, and ms3) Allows the compiler to make certain assumptions about aliasing and loops Turns off software pipelining Selects target version Page 3-25 2-42
3-28 2-16 3-13 2-41 2-16 5-14 7-12 3-17 3-26, 4-44 3-5 3-15
2-9
(g) Parser options that control preprocessing Option ppa ppc Effect Continues 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 Page 2-27 2-28
ppd
2-28
ppi
2-28
ppl
2-28
ppo
2-27
2-10
pden pdf pdr pds num pdse num pdsr num pdsw num pdv pdw
2-11
op1
3-21
op2
3-21
op3
3-21
os
3-30
The machine-specific ma, mhn, min, msn, and mt options, see Table 21(e), also effect optimization.
2-12
2-13
2-14
2.3.1
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.3, Disabling the Linker (c Shell Option), on page 5-5. Predefines the constant 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. Generates symbolic debugging directives that are used by the C/C++ source-level debugger and enables assembly source debugging in the assembler. 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.1, Debugging Optimized Code (g and o Options), on page 3-33). However, the g option disables many optimizations, because they disrupt the debugger.
dname[=def]
2-15
gw
Generates symbolic debugging directives that are used by the C/C++ sourcelevel debugger and enables assembly source debugging in the assembler. When gw is used, the compiler generates DWARF debugging information. DWARF is a richer debugging information format, and can handle complex C++ constructs that the COFF debugging information format cannot. You can use the g or gw option with the o option to maximize the amount of optimization that is compatible with debugging (see Debugging Optimized Code). However, the g and gw options disable many optimizations, because they disrupt the debugger.
idirectory
Adds directory to the list of directories that the compiler searches for #include files. You can use this option a maximum of 32 times to define several directories; be sure to separate i options with spaces. 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 i Option, on page 2-26. Retains the assembly language output from the compiler or assembly optimizer. Normally, the shell 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):
-
me mln
ml0 defaults aggregate data (structs and arrays) to far ml1 defaults all function calls to far ml2 defaults all aggregate data and calls to far 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 $1024 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 page 7-11, and section 8.1.5, Memory Models, on page 8-6, for more information.
2-16
mv n
Selects the target CPU version (For more information about the mv option, see page 3-15.) 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. Suppresses all output except error messages Invokes the interlist utility, which interweaves optimizer comments or C/C++ source with assembly source. If the optimizer is invoked (on option), optimizer comments are interlisted with the assembly 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. Invokes the interlist utility, 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 utility with the optimizer by combining the os and ss options. For more information, see section 2.13, Using the Interlist Utility, on page 2-43.The ss option can have a negative performance and/or code size impact. Undefines the predefined constant name. This option overrides any d options for the specified constant. 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 as an Individual Program, on page 5-2.
q qq s
ss
uname z
2-17
2.3.2
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 shell uses filename extensions to determine the file type.
Extension .c .C .cpp, .cxx, .cc .sa .asm, .abs, or .s* (extension begins with s) .obj File Type C source Depends on operating system C++ source Linear assembly Assembly source Object
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 shell interprets individual filenames, see section 2.3.3 on page 2-19. For information about how you can alter the way that the shell interprets and names the extensions of assembly source and object files, see section 2.3.5 on page 2-21. 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.
2-18
2.3.3
Changing How the Shell Program Interprets Filenames (fa, fc, fg, fl, fo, and fp Options)
You can use options to change how the shell interprets your filenames. If the extensions that you use are different from those recognized by the shell, 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 fcfilename flfilename fofilename fpfilename for an assembly language source file for a C source file for a linear assembly file for an object file for a C++ source file
For example, if you have a C source file called file.s 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.2, Specifying Filenames, on page 2-18, for more information about filename extension conventions.
2-19
2.3.4
Changing How the Shell Program Interprets and Names Extensions (ea, ec, el, eo, and ep Options)
You can use options to change how the shell 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: ea[.] new extension ec[.] new extension el[.] new extension eo[.] new extension ep[.] new extension for an assembly language file for a C source file for a linear assembly source file for an object file for a C++ source file
The following example assembles the file fit.rrr and creates an object file named fit.o:
cl6x 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:
cl6x earrr eoo fit.rrr
2-20
2.3.5
ffdirectory
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 directorys pathname on the command line after the ff option:
cl6x ff d:\listing
frdirectory
Specifies a directory for object files. To specify an object file directory, type the directorys pathname on the command line after the fr option:
cl6x fr d:\object
fsdirectory
Specifies a directory for assembly files. To specify an assembly file directory, type the directorys pathname on the command line after the fs option:
cl6x fs d:\assembly
ftdirectory
Specifies a directory for temporary intermediate files. To specify a temporary directory, type the directorys pathname on the command line after the ft option:
cl6x ft c:\temp
2-21
2.3.6
ac
adname
ahcfilename
ahifilename
al as
auname ax
For more information about assembler options, see the TMS320C6000 Assembly Language Tools User s Guide.
2-22
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=qs z
In the following examples, each time you run the compiler shell, 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 shell command line. If you have set z in the environment variable and want to compile only, use the c option of the shell. These additional examples assume C_OPTION is set as shown above:
cl6x cl6x cl6x cl6x *c c *.c *.c z lnk.cmd c *.c z lnk.cmd ; ; ; ; ; compiles and links only compiles compiles and links using a command file only compiles (c overrides z)
For more information about shell options, see section 2.3, Changing the Compiler s Behavior With Options, on page 2-6. For more information about linker options, see section 5.4, Linker Options, on page 5-6.
Using the C/C++ Compiler 2-23
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
Description Always defined Defined if target is 6200 Defined if target is 6400 Defined if target is 6700 Defined if little-endian mode is selected (the me option is not used); otherwise, it is undefined Defined if big-endian mode is selected (the me option is used); otherwise, it is undefined Defined if large-model mode is selected (the ml option is used); otherwise, it is undefined Set to the largemodel specified by mln; otherwise, it is undefined. Defined if small-model mode is selected (the ml option is not used); otherwise, it is undefined
2-24
_ _STDC_ _
You can use the names listed in Table 22 in the same manner as any other defined name. For example,
printf ( %s %s , _ _TIME_ _ , _ _DATE_ _);
2.5.2
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. 2) Directories named with the i option 3) Directories set with the C_DIR or C6X_C_DIR environment variable
Using the C/C++ Compiler 2-25
- If you enclose the filename in angle brackets (< >), the compiler searches
for the file in the following directories in this order: 1) Directories named with the i option 2) Directories set with the C_DIR or C6X_C_DIR environment variable 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) The i option names an alternate directory that contains #include files. The format of the i option is: i directory1 [i directory2 ...] You can use up to 32 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 Windows /6xtools/files/alt.h c:\6xtools\files\alt.h
The table below shows how to invoke the compiler. Select the command for your operating system:
Operating System UNIX Windows Enter cl6x i/6xtools/files source.c cl6x ic:\6xtools\files source.c
2-26
Note: Specifying Path Information in Angle Brackets If you specify the path information in angle brackets, 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:
setenv C_DIR /usr/include;/usr/ucb
2.5.3
2.5.4
2.5.5
2.5.6
2.5.7
2.5.8
Generating a List of Files Included With the #include Directive (ppi Option)
The ppi option performs preprocessing 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.
2-28
2.6
diagnostic message The text that describes the problem Diagnostic messages have an associated severity, as follows:
- A fatal error indicates a problem of such severity that the compilation can-
not 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.
- An error indicates a violation of the syntax or semantic rules of the C/C++
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 shell 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 shell 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-29
Long messages are wrapped to additional lines, when necessary. You can use a command-line option (pden) to request that the diagnostics 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 diagnostic identifier includes the suffix D (for discretionary); otherwise, no suffix is present. For example:
Test_name.c, line 7: error #64D: declaration does not declare anything struct {}; ^ Test_name.c, line 9: error #77: this declaration has no storage class or type specifier xxxxx; ^
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) f(1.5); ^
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 x; ^ 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-30
2.6.1
Controlling Diagnostics
The C/C++ compiler provides diagnostic options that allow you to modify how the parser interprets your code. These options control diagnostics: pdel 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 diagnostics 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-29 for more information. pdf pdr pds num 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.
pden
pdse num 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 separate compile. Then use pdse num to recategorize the diagnostic as an error. You can alter the severity of discretionary diagnostics only. pdsrnum 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 num to recategorize the diagnostic as a warning. You can alter the severity of discretionary diagnostics only.
pdsw num
2-31
pdv
Provides verbose diagnostics that display the original source with line-wrap and indicate the position of the error in the source line Suppresses warning diagnostics (errors are still issued)
pdw
2.6.2
If you invoke the compiler with the q option, this is the result:
err.c, line 9: warning: statement is unreachable err.c, 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:
[err.c] err.c, line 9: warning #111D: statement is unreachable err.c, line 12: warning #111D: 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.
2-32
Other Messages / Generating Understanding Cross-Reference Diagnostic Listing Messages Information / Other (px Messages Option)
The source file The line number in the source file The column number in the source file
2-33
ment 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 23.
2-34
Diagnostic raw listing information is displayed in the following format: S filename line number column number diagnostic S filename line number column number diagnostic One of the identifiers in Table 24 that indicates the severity of the diagnostic The source file The line number in the source file The column number in the source file 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-29.
2-35
the surrounding code. There are several types of inline function expansion:
- Inlining with intrinsic operators (intrinsics are always inlined) - Automatic inlining - Definition-controlled inlining with the unguarded inline keyword - 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 for 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.
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.
2-37
tive, nonstatic, externally-linked version of the function. Conditionally preprocess these two prototypes with the _INLINE preprocessor symbol, as shown in Example 22.
- Create an identical version of the function definition in a .c or .cpp file, as
shown in Example 22. In Example 22 there are two definitions of the strlen function. The first, in the header file, is an inline definition. This definition is enabled 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 strlens prototype.
2-38
Example 22. How the Run-Time-Support Library Uses the _INLINE Preprocessor Symbol
(a) string.h /*****************************************************************************/ /* string.h vx.xx */ /* Copyright (c) 19931999 Texas Instruments Incorporated */ /* Excerpted ... */ /*****************************************************************************/ #ifdef _INLINE #define _IDECL static inline #else #define _IDECL extern _CODE_ACCESS #endif _IDECL size_t #ifdef _INLINE /****************************************************************************/ /* strlen */ /****************************************************************************/ 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 strlen(const char *_string);
(b) strlen.c /****************************************************************************/ /* strlen */ /****************************************************************************/ #undef _INLINE #include <string.h> { _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; }
2-39
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)
2-40
2-41
4.0 tools.
- Linking new C6400 code with code already compiled with any version of
the tools) for the C6200 or C6700 family. Solutions (pick one):
- Recompile the entire application with the mv6400 switch. This solution,
2-42
The ss option prevents the shell from deleting the interlisted assembly language output file. The output assembly file, function.asm, is assembled normally. When you invoke the interlist utility without the optimizer, the interlist utility 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 23 shows a typical interlisted assembly file.
2-43
For more information about using the interlist utility with the optimizer, see section 3.11, Using the Interlist Utility With the Optimizer, on page 3-30.
2-44
Chapter 3
Topic
3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9
Page
Invoking Optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2 Optimizing Software Pipelining . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-4 Redundant Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-16 Reducing Code Size (ms Option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-17 Performing File-Level Optimization (o3 Option) . . . . . . . . . . . . . . . . 3-18 Performing Program-Level Optimization (pm and o3 Options) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-20 Indicating Whether Certain Aliasing Techniques Are Used . . . . . . . 3-25 Prevent Reordering of Associative Floating-Point Operations . . . 3-28 Use Caution With asm Statements in Optimized Code . . . . . . . . . . . 3-28
3.10 Automatic Inline Expansion (oi Option) . . . . . . . . . . . . . . . . . . . . . . . 3-29 3.11 Using the Interlist Utility With the Optimizer . . . . . . . . . . . . . . . . . . . . 3-30 3.12 Debugging and Profiling Optimized Code . . . . . . . . . . . . . . . . . . . . . . 3-33 3.13 What Kind of Optimization Is Being Performed? . . . . . . . . . . . . . . . . 3-35
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. The high-level optimizer runs as a separate pass between the parser and the code generator. Figure 31 illustrates the execution flow of the compiler with the stand-alone optimizer and code generator.
.if file
.opt file
.asm file
The easiest way to invoke optimization is to use the cl6x shell 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.
- o0 J J J J J J - o1
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
Performs local copy/constant propagation Removes unused assignments Eliminates local common expressions
3-2
Invoking Optimization
- o2
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.
- o3
Removes all functions that are never called Simplifies functions with return values that are never used Inlines calls to small functions Reorders function declarations so that the attributes of called functions are known when the caller is optimized 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, Using the o3 Option, on page 3-18 for more information. In addition to these optimizations, there are some optimizations that are performed regardless of the optimization level. These optimizations cannot be turned off. Note: Do Not Lower the Optimization Level to Control Code Size When trying to reduce code size, do not lower the level of optimization. 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. 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-3
The assembly optimizer also software pipelines loops. For more information about the assembly optimizer, see Chapter 4. For more information about software-pipelining, see the TMS320C6000 Programmer s Guide.
3-4
3.2.1
3.2.2
3-5
1 3 4
;* Searching for software pipeline schedule at ... ;* ii = 5 Register is live too long ;* ii = 6 Did not find schedule ;* ii = 7 Schedule found with 3 iterations in parallel ;* done ;* ;* Epilog not entirely removed ;* Collapsed epilog stages : 1 ;* ;* Prolog not removed ;* Collapsed prolog stages : 0 ;* ;* Minimum required memory pad : 2 bytes ;* ;* Minimum safe trip count : 2 ;* ;**
3-6
The terms defined below appear in the software pipelining information. For more information on each term, see the TMS320C6000 Programmer s Guide.
- Loop unroll factor. The number of times the loop was unrolled specifi-
cally 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 maximum 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
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 itera-
tion interval. For example, if four instructions require a .D unit, they require at least two cycles to execute (4 instructions/2 parallel .D units).
- Unpartitioned resource bound. The best possible resource bound val-
ues before the instructions in the loop are partitioned to a particular side.
- Partitioned resource bound (*). The resource bound values after the
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:
J J
.L units is the total number of instructions that require .L units. .S units is the total number of instructions that require .S units.
Optimizing Your Code 3-7
J J J J J J J J
.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
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 .LSD) = 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-13, for more information.
3-8
3.2.2.1
Loop Disqualified for Software Pipelining Messages The following messages appear if the loop is completely disqualified for software pipelining:
- Bad loop structure. This error is very rare and can stem from the follow-
ing:
J J J
An asm statement inserted in the C code innerloop 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 pipelining 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-14.
- Cannot identify trip counter. The loop trip counter could not be identified
3-9
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:
- Address increment is too large. An address register s offset must be ad-
justed because the offset is out of range of the C6000s offset addressing mode. You must minimize address register offsets.
- Cannot allocate machine registers. A software pipeline schedule was
found, but it cannot allocate machine registers for the schedule. You must simplify the loop. 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/Bside) Max Regs Live : 20/14 Max Condo Regs Live : 2/1
J
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. 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. 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.
- Cycle count too high Not profitable. With the schedule that the com-
piler found for the loop, it is more efficient to use a non-software-pipelined version.
- 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.
- Iterations in parallel > 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 must enable redundant loops or communicate the trip information.
- 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.
3-10
- 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| > |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
mum 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 Cant adjust trip count. The loop trip
counter has a use in the loop other than as a loop trip counter.
3-11
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:
- 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.
- 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 will be executed.
- Uneven resources. If the number of resources to do a particular opera-
tion 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.
- 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.
- There are memory bank conflicts. In cases where the compiler gener-
ates 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 .mptr directive to control memory banks.
- T address paths are resource bound. T address paths defined the num-
ber 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 is often possible to reduce the number of accesses by performing word accesses (LDW/STW) for any short accesses being performed.
3-12
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 redundant loop. The remainder is due to the prolog and epilog. The prolog and epilog of a software-pipelined loop consists of up to p1 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 mhn 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 after 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. 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 supressed. Both these values can be found in the comment block preceding a software pipelined loop.
Optimizing Your Code 3-13
;* .... ;*
: 1
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 as well. 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 softwarepipelined loop is also provided in the comment block for that loop.
;* 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:
- Required memory pad for this loop - The minimum value of n needed to achieve this software pipeline schedule
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.
3-14
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) or the MUST_ITERATE pragma (see section 7.7.14 on page 7-28.) Note: Turning Off Redundant Loops Specifying any ms option turns off redundant loops.
3.2.4
3-15
Redundant Loops
A 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 loops 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 */ { for (i=0; i < N; i++) /* i is the trip counter */ }
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 comparison would be used to determine which version should be executed:
foo(N) { if (N < 3) { for (i=0; i < } else } for (i=0; i < } } foo(50); /* Execute foo(2); /* Execute 3-16
N; i++)
/* Unpipelined version */
N; i++)
/* Pipelined version
*/
*/
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) or the use of the MUST_ITERATE pragma (see section 7.7.14 on page 7-28). Note: Turning Off Redundant Loops Specifying any ms option turns off redundant loops.
3-17
Note: Do Not Lower the Optimization Level to Control Code Size When 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.
3.5.1
3-18
3.5.2
on1 on2
3-19
piler replaces the argument with the value and passes the value instead of the argument.
- If a return value of a function is never used, the compiler deletes the return
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, selecting any type of program-level optimization causes pmm (instead of pm) to appear in the Options field of the Build Options dialog box on the Compiler tab, Basic Category. Using pmm is required to specify any type of program-level optimization in Code Composer Studio. 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 filespecific 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 programlevel 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.
3-20
3.6.1
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 35 lists the combinations of op levels and conditions that cause the compiler to revert to other op levels.
3-21
In some situations when you use pm and o3, 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. In Code Composer Studio, selecting any type of program-level optimization causes pmm (instead of pm) to appear in the Options field of the Build Options dialog box on the Compiler tab, Basic category.Using pmm is required to specify any type of program-level optimization in Code Composer Studio.
3.6.2
3-22
In general, you achieve the best results through judicious use of the FUNC_EXT_CALLED pragma in combination with pm o3 and op1 or op2. If any of the following situations apply to your application, use the suggested solution: Situation Your application consists of C/C++ source code that calls assembly 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++ variables. 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. Situation Your application consists of C/C++ source code that calls assembly 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:
J J
Solution
Solution
Compile with pm o3 op1. 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 3-21 for information about the opn option.
3-23
Situation
Your application consists of C/C++ source code and assembly 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:
J
Solution
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. If you do not, the compiler might remove the entry-point functions that are not preceded by the FUNC_EXT_CALL pragma. Compile with pm o3 op3. Because you do not use the FUNC_EXT_CALL pragma, you must use the op3 option, 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 options, the compiler removes the C functions that the assembly functions call. Use the FUNC_EXT_CALLED pragma to keep these functions.
3-24
3.7.1
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 = f(&x); *p = 5; *glob_ptr = 10; h(x); } int *f(int *arg) { glob_ptr = arg; return arg; }
Optimizing Your Code 3-25
3.7.2
Use the mt Option to Indicate That These Techniques Are Not Used
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.
- The mt option indicates that your code does not use the aliasing tech-
nique 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.
- 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 to the general aliasing rule for these types given in section 3.3 of the ANSI specification is ignored. If you have code similar to the following example, do not use the mt option:
{ long l; char *p = (char *) &l; p[2] = 5; }
- 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(&a, &a) f(&a+42, &a+j) } f(int *ptr1, int *ptr2) { ... } /* Bad */ /* Also Bad */
3-26
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 f(5, 4); /* 4 is a negative index */ return f(0, 96); /* 96 exceeds 20 as an index */ return f(4, 16); /* This one is OK */ } int f(int i, int 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).
- The mt option indicates that loop-invariant counter increments and
decrements of loop counters are non-zero. Loop invariant means a value of an expression doesnt 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
3-27
3-28
abled.
- 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 optimizer 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 inlines 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 optimizer inlines very small functions. . Note: o3 Optimization and Inlining In order to turn on automatic inlining, you must use the o3 option. The o3 option turns on other optimizations. If you desire the o3 optimizations, but not automatic inlining, use oi0 with the o3 option.
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.
3-29
ments.
- The ss and os options together interlist the optimizer comments and the
original C/C++ source with the assembly code. When you use the os option with the optimizer, the interlist utility does not run as a separate pass. Instead, the optimizer inserts comments into the code, indicating how the optimizer 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 utility can affect optimized code because it might prevent some optimization from crossing C/C++ statement boundaries. Optimization makes normal source interlisting impractical, because the optimizer extensively rearranges your program. Therefore, when you use the os option, the optimizer writes reconstructed C/C++ statements. Example 32 shows the function from Example 23 on page 2-44 compiled with the optimizer (o2) and the os option. Note that the assembly file contains optimizer 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.
3-30
Example 32. The Function From Example 23 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 MVKL .S1 .S2 SL1+0,A0 RL0,B3
STW .D2 A0,*+SP(4) || MVKH .S2 RL0,B3 RL0: ; 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 the optimizer, the optimizer inserts its comments and the interlist utility runs between the code generator and the assembler, merging the original C/C++ source into the assembly file. Example 33 shows the function from Example 23 on page 2-44 compiled with the optimizer (o2) and the ss and os options. Note that the assembly file contains optimizer comments and C source interlisted with assembly code.
3-31
Example 33. The Function From Example 23 Compiled With the o2, os, and ss Options
_main: ;** 5 printf(Hello, world\n); ;** 6 return 0; STW .D2 B3,*SP(12) ; ; 5 | printf(Hello, world\n); ; B .S1 _printf NOP 2 MVKL .S1 SL1+0,A0 MVKH .S1 SL1+0,A0 || MVKL .S2 RL0,B3 STW .D2 A0,*+SP(4) || MVKH .S2 RL0,B3 RL0: ; CALL OCCURS ; ; 6 | return 0; ; ZERO .L1 A4 LDW .D2 *++SP(12),B3 NOP 4 B .S2 B3 NOP 5 ; BRANCH OCCURS
3-32
3-33
Note: Finer Grained Profiling If you need to profile code at a finer grain that the function level in Code Composer Studio, you can use the g or gw option instead of the gp option, although this is not recommended. You might see a significant performance degradation because the compiler cannot use all optimizations with g. It is recommended that outside of Code Composer Studio, you use the clock( ) function.
3-34
3-35
Example 34. Strength Reduction, Induction Variable Elimination, Register Variables, and Software Pipelining
(a) C source int a[10]; main() { int i; for (i=0; i<10; i++) a[i] = 0; }
3-36
Example 34. Strength Reduction, Induction Variable Elimination, Register Variables and Software Pipelining (Continued)
(b) Compiler output FP .set DP .set SP .set ; A15 B14 B15
_main: ;*** MVK .S1 _a,A0 MVKH .S1 _a,A0 MV .L2X A0,B4 || ZERO .L1 A3 || ZERO .D2 B5 || MVK .S2 2,B0 ; |7| ;*** L2: ; PIPED LOOP PROLOG [ B0] B .S1 L3 ; |7| [ B0] B .S1 L3 ;@ |7| [ B0] B .S1 L3 ;@@ |7| [ B0] || [ B0] B SUB .S1 .L2 L3 B0,2,B0 ;@@@ |7| ;@@@@ |7|
ADD .S2 8,B4,B4 ; |8| || [ B0] B .S1 L3 ;@@@@ |7| || [ B0] SUB .L2 B0,2,B0 ;@@@@@ |7| ;*** L3: ; PIPED LOOP KERNEL STW .D1T1 A3,*A0++(8) ; |8| || STW .D2T2 B5,*B4(4) ; |8| || ADD .S2 8,B4,B4 ;@ |8| || [ B0] B .S1 L3 ;@@@@@ |7| || [ B0] SUB .L2 B0,2,B0 ;@@@@@@ |7| ;*** L4: ; PIPED LOOP EPILOG ;*** B .S2 B3 ; |9| NOP 5 ; BRANCH OCCURS ; |9| .global _a .bss _a,40,4
3-37
3-38
= ALPHA;
0) ? 0) ? 0) ?
3-39
;****************************************************************************** ;* FUNCTION NAME: _fsm * ;* * ;* Regs Modified : B0,B4 * ;* Regs Used : B0,B3,B4 * ;* Local Frame Size : 0 Args + 0 Auto + 0 Save = 0 byte * ;****************************************************************************** _fsm: ;** * ;** * L2: LDW .D2T2 *B4++,B0 ; |8| ;** * L3: NOP 4 [ B0] B .S1 L7 ; |8| NOP 4 [ B0] LDW .D2T2 *B4++,B0 ; |10| ; BRANCH OCCURS ; |8| ;** * LDW .D2T2 *B4++,B0 ; |9| NOP 4 [ B0] B .S1 L3 ; |9| NOP 4 [ B0] LDW .D2T2 *B4++,B0 ; |8| ; BRANCH OCCURS ; |9| ;** * L5: LDW .D2T2 *B4++,B0 ; |10| ;** * L6: ;** * L7: NOP 4 [!B0] B .S1 L6 ; |10| NOP 4 [!B0] LDW .D2T2 *B4++,B0 ; |10| ; BRANCH OCCURS ; |10| ;** * B .S2 B3 ; |12| NOP 5 ; BRANCH OCCURS ; |12|
3-40
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 35 on page 3-39 and Example 36 on page 3-42).
- Common subexpression elimination
When two or more expressions produce the same value, the compiler computes the value once, saves it, and reuses it.
- 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 optimizer removes these dead assignments (see Example 36).
3-41
_simplify: B .S2 B3 NOP 2 MPY .M1 5,A4,A0 NOP 1 EXT .S1 A0,24,24,A4 ; BRANCH OCCURS
3-42
_main: ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>ENTERING ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<LEAVING ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>ENTERING ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<LEAVING B .S2 B3 NOP 4 MVK .S1 12,A4 ; BRANCH OCCURS
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 38 on page 3-45).
3-44
_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 .bss .global .bss _x _x,4,4 _y _y,4,4
3-45
3-46
Chapter 4
Topic
4.1 4.2 4.3 4.4 4.5 4.6
Page
Code Development Flow to Increase Performance . . . . . . . . . . . . . . . 4-2 About the Assembly Optimizer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-4 What You Need to Know to Write Linear Assembly . . . . . . . . . . . . . . . 4-4 Assembly Optimizer Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-16
4-1
Efficient enough? No
Yes
Complete
Yes
Complete
Write linear assembly Phase 3: Write linear assembly Assembly optimize Profile No
4-2
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.3, Using the Profiling Capability of the Stand-Alone Simulator, on page 6-6) to identify any inefficient areas in your C/C++ code. To improve the performance of your code, proceed to phase 2.
- Phase 2: refine your C/C++ code
In phase 2, use the intrinsics and shell 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.
- 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 linear assembly code, you might want to add more details to your code, such as which functional unit to use. 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.
4-3
About About the the Assembly Assembly Optimizer Optimizer / What You Need to Know to Write Linear Assembly
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 shell program (cl6x). The assembly optimizer is automatically invoked by the shell 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 shell program, see section 2.1, on page 2-2.
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-16.
4-4
The following shell options affect the behavior of the assembly optimizer:
Option el fl k mhn min msn mt mu mvn n on q Effect Page
Changes the default extension for assembly optimizer source 2-20 files Changes how assembly optimizer source files are identified 2-19 Keeps the assembly language (.asm) file Allows speculative execution Specifies an interrupt threshold value 2-16 3-13 2-41
Controls code size on four levels (ms0, ms1, ms2, and 3-17 ms3) Presumes no memory aliasing Turns off software pipelining Select target version Compiles or assembly optimizes only (does not assemble) Increases level of optimization (o0, o1, o2, and o3) Suppresses progress messages 3-27 3-5 3-15 2-17 3-2 2-17
- TMS320C6000 instructions
When you are writing your linear assembly, your code does not need to indicate the following:
J J J
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 specify which unit should be used. 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 like 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.
4-5
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 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. See section 4.3.2 for information on specifying the functional unit.
- Source comments
The assembly optimizer attaches the comments on instructions from the input linear assembly to the output file. It attaches @ characters to the comments to specify what iteration of the loop an instruction is on in the software pipeline. See section 4.3.3, Using Linear Assembly Source Comments, on page 4-14 for an illustration of the use of source comments and the resulting assembly optimizer output.
4.3.1
label [:]
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 A0 for C6400 only, A1, A2, B0, B1, B2, or symbolic. The mnemonic is a machine-instruction (such as ADDK, MVKH, B) or assembly optimizer directive (such as .proc, .trip) The unit specifier enables you to specify the functional unit.
[register]
mnemonic
unit specifier
4-6
operand list
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.
comment
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:
- 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 inter-
preted as blanks. You must separate the operand list from the preceding field with a blank.
- 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.
- If you set up a conditional instruction, the register must be surrounded by
square brackets.
- 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-7
4.3.2
There are several ways to use the unit specifier field in linear assembly:
- 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 LDW .D1T2 .D1T2 *A3[A4], B3 *src, dst
- You can specify only the functional type (for example, .M), and the
4-8
If you do not specify the functional unit, the assembly optimizer selects the functional unit based on the mnemonic field. For more information on functional units, including which machine-instruction mnemonics require which functional type, see the TMS320C6000 CPU and Instruction Set Reference Guide. The following examples show how specifying functional units can be helpful in the linear assembly code. Example 41 is refined C code for computing a dot product.
4-9
Example 42 is a hand-coded linear assembly program that computes a dot product; compare this to Example 41, which illustrates C code.
4-10
The assembly optimizer generates the software-pipeline kernel shown in Example 43 for the hand-coded program in Example 42.
Example 43. Software-Pipeline Kernel for Computing a Dot Product With Example 42
loop: ; PIPED LOOP KERNEL MV .L2X A0,B9 ; Define a twin register [ B0] B .S1 loop ; @|31| if (!0) goto loop MV .L1X B1,A7 ; @Define a twin register [ A2] LDW .D2T2 *B6++(8),B8 ; @@|23| load a[23] [ A2] LDW .D1T1 *A6++(8),A4 ; @@|24| load b[23]
|| || || ||
[ A2] SUB .S1 A2,4,A2 ; || ADD .L1X B7,A0,A0 ; |27| sum1 += (a[0] * b[0]) + || ADD .L2 B9,B8,B7 ; |20| sum0 += (a[0] * b[0]) + || MPYH .M2X A4,B1,B8 ; @|19| a[1] * b[1] || MPY .M1 A4,A7,A0 ; @|18| a[0] * b[0] || [ A1] LDW .D2T2 *B5++(8),B1 ; @@@|17| load b[01] [ B2] SUB .L2 B2,1,B2 ; || [ A1] SUB .L1 A1,4,A1 ; || [!B2] ADD .S1 A0,A3,A3 ; |28| (a[1] * a[1]) || [!B2] ADD .D2 B7,B4,B4 ; |21| (a[1] * a[1]) || MPY .M2X B8,A4,B7 ; @|25| a[2] * b[2] || MPYH .M1X B8,A4,A0 ; @|26| a[3] * b[3] || [ B0] ADD .S2 0xfffffffc,B0,B0 ; @@|30| cnt = 4 || [ A1] LDW .D1T1 *A5++(8),A4 ; @@@|16| load a[01]
The kernel displayed in Example 43 is not the best possible kernel to use. This kernel cannot be scheduled in two cycles because the cross path (indicated by the X appended to the functional unit specifier) is repeated too many times. The assembly optimizer automatically embeds a comment in the scheduled assembly indicating this, so that you do not have to analyze the output by hand. Example 44 shows the cross paths in the software pipeline information generated by the assembly optimizer.
4-11
There are only two cross paths in the C6000. This limits the C6000 to one source read from each data paths opposite register file per cycle. The compiler must select a side for each instruction; this is called partitioning. In Example 43, the compiler partitioned two ADD instructions to sides requiring cross paths before the multiply instructions that needed the cross paths were partitioned.
4-12
You can partition enough instructions by hand to force optimal partitioning by using functional unit specifiers. If you use functional unit specifiers to force the MPYs to the sides you want them to be on, the compiler has more information about where the subsequent ADDs should go (rather, more information about where the symbolic registers involved must go). Example 45 shows the assembly code after functional unit specifiers are added.
Example 45. Code From Example 42 With Functional Unit Specifiers Added
_dotp: .cproc .reg .reg .reg ADD ADD MVK ZERO ZERO loop: .trip 25 LDW LDW MPY MPYH ADD ADD LDW LDW MPY MPYH ADD ADD [cnt] SUB [cnt] B ADD .return .endproc *a_0++[2], valA *b_0++[2], valB valA, valB, prod1 valA, valB, prod2 prod1, prod2, tmp tmp, sum0, sum0 *a_4++[2], valA *b_4++[2], valB valA, valB, prod3 valA, valB, prod4 prod3, prod4, tmp tmp, sum1, sum1 cnt, 4, cnt loop sum0, sum1, sum sum ; ; ; ; ; ; ; ; ; ; ; ; load load a[0] a[1] sum0 a[0 1] b[0 1] * b[0] * b[1] += (a[0] * b[0]) + (a[1] * a[1]) a[2 3] b[2 3] * b[2] * b[3] += (a[0] * b[0]) + (a[1] * a[1]) a_0, b_0 a_4, b_4, cnt, tmp prod1, prod2, prod3, prod4 valA, valB, sum0, sum1, sum 4, a_0, a_4 4, b_0, b_4 100, sum0 sum1 cnt
.M1 .M1
.M2 .M2
4-13
Example 46. Software-Pipeline Kernel for Computing a Dot Product With Example 45
loop: ; PIPED LOOP KERNEL [ B2] SUB .L2 B2,4,B2 ; || ADD .L1 A4,A3,A3 ; |20| sum0 += (a[0] * b[0]) + || ADD .S2 B8,B4,B4 ; |28| (a[1] * a[1]) || MPYH .M1X B9,A8,A3 ; @|19| a[1] * b[1] || [ B0] B .S1 loop ; @@|31| if (!0) goto loop || MPY .M2X A5,B1,B7 ; @@|25| a[2] * b[2] || [ B2] LDW .D2T2 *B5++(8),B9 ; @@@@|16| load a[01] || [ B2] LDW .D1T1 *A7++(8),A8 ; @@@@|17| load b[01] [ A1] SUB .L1 A1,4,A1 ; || ADD .S1 A3,A0,A0 ; |21| (a[1] * a[1]) || ADD .S2 B7,B8,B8 ; @|27| sum1 += (a[0] * b[0]) + || MPY .M1X B9,A8,A4 ; @@|18| a[0] * b[0] || MPYH .M2X A5,B1,B8 ; @@|26| a[3] * b[3] || [ B0] ADD .L2 0xfffffffc,B0,B0 ; @@@|30| cnt = 4 || [ A1] LDW .D1T1 *A6++(8),A5 ; @@@@@|23| load a[23] || [ A1] LDW .D2T2 *B6++(8),B1 ; @@@@@|24| load b[23]
4.3.3
4-14
Example 47 shows code for a function called Lmac that contains comments.
[i] [i]
4-15
.call [ret_reg =] func_name (arg1, arg2) Calls a function label .cproc [variable1 [, variable2 , ] ] .endproc .endproc [register1 [, register2 , ] ] .mdep [symbol1], [symbol2] Start a C/C++ callable procedure End a C/C++ callable procedure End a procedure Indicates a memory dependence
.mptr {register| symbol}, base [+ offset] Avoid memory bank [, stride] conflicts .no_mdep label .proc [register1 [, register2 , ] ] .reg variable1 [, variable2 ,] .return [argument] .reserve [register1 [, register2 , ] ] label .trip min No memory aliases in the function Start a procedure Declare variables Return value to procedure Reserve register use Specify trip count value
4-16
Calls a Function
.call
Syntax
.call
Description
Use the .call directive to call a function. Optionally, you may 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-16, and section 8.4, Function Structure and Calling Conventions, on page 8-18. 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. The name of the function to call, or the name of the symbolic/ machine register for indirect 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 .def 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 page 7-32 for more information. (Optional) Symbolic/machine registers passed as an argument. The arguments are passed in this order and may not be a constant, memory reference, or other expression.
func_name
arguments
You can use the cl6x mln option to indicate whether a call is near or far. If the mln option is set to 0 or if no level is specified (default), the call is near. If the mln 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(op1)
4-17
.call
Calls a Function
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)(op1, op2) ; indirect call .reg driver .call driver(op1, op2)
Here are other valid examples that use the .call syntax.
.call fir(x, h, y) .call minimal( ) .call sum = vecsum(a, b) .call hi:lo = _atol(string) ; void function ; no arguments ; returns an int ; 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 overide 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:
.global .global .sect string1: string2: .bss .text _main: .cproc .reg .call _main _puts, _rand, _ltoa .const .string The random value returned is , 0 .string , 10, 0 ; 10 == newline charbuf, 20
MVKL string1, bufptr ; load address of string1 MVKH string1, bufptr .call _puts(bufptr) ; print out string1 MV random_value, ran_val_lo SHR ran_val_lo, 31, ran_val_hi ; sign extend random value .call _ltoa(ran_val_hi:ran_val_lo, bufptr) ; convert it to a string .call _puts(bufptr) ; print out the random value MVKL string2, bufptr ; load address of string2 MVKH string2, bufptr .call _puts(bufptr) ; print out a newline .endproc 4-18
cproc/.endproc
Syntax
label
Description
Use the .cproc/.endproc directive pair to delimit a section of your code that 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. 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:
- 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.
- If the compiler cannot allocate machine registers to symbolic register
names specifed with the .reg directive (see page 4-28) 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. For more information, see section 8.3, Register Conventions, on page 8-16 and section 8.4, Function Structure and Calling Conventions, on page 8-18. Please see the .proc directive on page 4-27 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:
- 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.
Using the Assembly Optimizer 4-19
.cproc/.endproc
optimizer ensures that either the symbolic name is allocated to the appropriate argument passing register or the argument passing register is copied to the register allocated for the symbolic 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 arg1
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.
- 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:
_fcn: .cproc arg1, ... .return res ... .endproc arg2hi:arg2lo, arg3, B6, arg5, B9:B8
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 , Generating Linknames, on page , and section 8.5, Interfacing C/C++ with Assembly Language, on page 8-22, for 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 live 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 generated in a .cproc region. See page 4-31 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 page 4-27 for a list of instruction types that cannot be used in .cproc regions.
4-20
.cproc/.endproc
Example
_if_then: .cproc .reg MVK ZERO LOOP: AND [cond] MVK CMPEQ LDH [if] ADD [!if] SUB SHL [cntr] ADD [cntr] B .S2X .S2 .L2 .D1 .L1 .D1 .S1 .L2 .S1
; ; ; ; ; ; ; ; ;
cond = codeword & mask !(!(cond)) (theta == !(!(cond))) a[i] sum += a[i] sum = a[i] mask = mask << 1 decrement counter for LOOP
4-21
.mdep
Syntax Description
.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 directive pair. Example Here is an example in which .mdep is used to indicate a dependence between two memory references.
.mdep ld1, st1 LDW *p1++ {ld1}, inp1 ;name memory reference ld1 ;other code ... STW outp2, *p2++ {st1} ;name memory reference st1
4-22
.mptr
Syntax Description
.mptr
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-34. Following are descriptions of the .mptr directive parameters: register|symbol base offset stride The name of the register or the symbol used to name a specific memory reference. A symbol that associates related memory accesses The offset in bytes from the starting base symbol. The offset is an optional parameter and defaults to 0. The register loop increment in bytes. The stride is an 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
4-23
.endproc
4-24
.no_mdep
Syntax Description
.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_mdep is used.
fn: .cproc dst, src, cnt .no_mdep ;no memory aliasing in this function ... .endproc
Example
4-25
.proc/.endproc
Define a Procedure
Syntax
label
.proc
.endproc Description
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. 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 .proc directive, it is assumed that all of the registers referenced in the procedure are live in. 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.
Example
Here is a block move example in which .proc and .endproc are used:
move .proc A4, B4, B0 .no_mdep
loop: LDW *B4++, A1 MV A1, B1 STW B1, *A4++ ADD 4, B0, B0 [B0] B loop .endproc
4-26
Define a Procedure
.proc/.endproc
The following types of instructions are not allowed in .proc or .cproc (see page 4-19 and 4-26) regions:
- 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 <= 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 .endproc outside:
<= illegal
4-27
.reg
Declare Variables
Syntax Description
.reg variable1 [, variable2 ,] 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. Objects of type long, double, or long double are allocated into an even/odd register pair and are always referenced as a register pair (for example, A1:A0). A symbolic register that is used as a register in a register pair must be defined as a register pair with the .reg directive. For example:
.reg ahi:alo ADD a0,ahi:alo,ahi:alo
Example 1
This example uses the same code as the block move example on page 4-26 but the .reg directive is used:
move .cproc dst, src, cnt .reg tmp1, tmp2 loop: LDW MV STW ADD [cnt] B *src++, tmp1 tmp1, tmp2 tmp2, *dst++ 4, cnt, cnt loop
.endproc
Notice how this example differs from the .proc example on page 4-26: symbolic registers declared with .reg are allocated as machine registers. Example 2 The code in the following example is invalid, because you cannot use a variable defined by the .reg directive with the .proc directive:
move .proc dst, src, cnt .reg dst, src, cnt ; WRONG: You cannot use a ; variable with .proc
4-28
Declare Variables
.reg
Example 3
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 MV *A4++, tmp tmp, B5
4-29
Syntax Description
.reserve [register1 [, register2 , ] ] 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 .reg .... ADD .... .endproc a7 tmp1 a6, b4, a7
Note: Reserving Registers A4 and A5 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. Example 1 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 tmp1, tmp2, tmp3, tmp4, tmp5 .reserve a10, a11, a12, a13, b10, b11, b12, b13 ..... .endproc a4
Example 2
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 symbol tmp:
.cproc ... .reserve a1,a2,b0,b1,b2 .reg tmp .... [tmp] .... .... .endproc
4-30
.return
Syntax Description
.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 8-18). The optional argument can have the folowing meanings:
- Zero arguments implies a .cproc region that has no return value, similar
return value, or a 64-bit type double for C6700, similar to a long 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. It is 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:
Example
This example uses a symbolic register name, tmp, and a machine-register, A5, as .return arguments:
.cproc ... .reg tmp ... .return tmp <= legal symbolic name ... .return a5 <= legal actual name
4-31
.trip
Syntax Description
label
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 descriptions of the .trip directive parameters: label minimum value maximum value factor The label represents the beginning of the loop. This is a required parameter. The minimum number of times that the loop can iterate. This is a required parameter. The default is 1. The maximum number of times that the loop can iterate. The maximum value is an optional parameter. 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 allows 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-41 for more information.
4-32
.trip
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. Example 1 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 .trip 16, 48, 8 ldh *ptr_a++, ai ldh *ptr_b++, bi mpy weight, ai, prod shr prod, 15, scaled_prod add scaled_prod, bi, ci sth ci, *ptr_c++ sub cnt, 1, cnt b loop .endproc
loop:
[cnt] [cnt]
4-33
8N
8N + 1
8N + 2 8N + 3 Bank 1
8N + 4 8N + 5 Bank 2
8N + 6 8N + 7 Bank 3
Bank 0
For devices that have more than one memory space (Figure 42), 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.
4-34
8N
8N + 1
8N + 2 8N + 3 Bank 1 8M + 2 8M + 3
8N + 4 8N + 5 Bank 2 8M + 4 8M + 5
8N + 6 8N + 7 Bank 3 8M + 6 8M + 7
Bank 0
Bank 1
Bank 2
Bank 3
4.5.1
4-35
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], val1 LDW *a_4++[4], val2 .mptr dptr,D+0,8 LDH LDH LDH LDH *dptr++, *dptr++, *dptr++, *dptr++, d0 d1 d2 d3 ; ; ; ; base=D, base=D, base=D, base=D, offset=0, offset=2, offset=4, offset=6, stride=8 stride=8 stride=8 stride=8 ; base=a, offset=0, stride=16 ; base=a, offset=4, stride=16
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-23 for information about the .mptr directive.
4-36
Example 48 shows loads and stores extracted from a loop that is being software pipelined.
Example 48. Load and Store Instructions That Specify Memory Bank Information
.mptr .mptr .mptr .mptr .mptr .mptr LDW LDW LDW LDW LDW LDW LDW LDW STH STH Ain,IN,16 Bin,IN4,16 Aco,COEF,16 Bco,COEF+4,16 Aout,optr+0,4 Bout,optr+2,4 .D1 .D2 .D1 .D2 .D2 .D1 .D2 .D1 .D1 .D2 *Ain[2],Ain12 *Bin[2],Bin23 *Ain[2],Ain34 *Bin[2],Bin56 *Bco++[2],Bco12 *Aco++[2],Aco23 *Bco++[2],Bin34 *Aco++[2],Ain56 Assum,*Aout++[2] Bssum,*Bout++[2] ; ; ; ; ; ; ; ; IN(ki) & IN(ki2) IN(ki4) IN(ki6) COEF(i) & COEF(i+2) COEF(i+4) COEF(i+6) IN(ki+1) & IN(ki1) & IN(ki3) & IN(ki5) COEF(i+1) & COEF(i+3) & COEF(i+5) & COEF(i+7)
4-37
4.5.2
word boundaries.
- 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 || MVK LDW || LDW 0, A0 8, B0 *A0, A1 *B0, B1
No bank conflict:
MVK || MVK LDW || LDW 0, A0 4, B0 *A0, A1 *B0, B1
4-38
.trip 50 LDW *a++,val1 LDW *b++,val2 MPY val1,val2,prod1 MPYH val1,val2,prod2 ADD prod1,sum0,sum0 ADD prod2,sum1,sum1 1,i,i loop
* b[0] * b[1]
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[01] cannot conflict with a[23] and that b[01] cannot conflict with b[23]. Example 412 shows the unrolled loop kernel.
Using the Assembly Optimizer 4-39
Example 412. Dot Product From Example 410 Unrolled to Prevent Memory Bank Conflicts
_dotp2: .cproc .reg .reg ADD ADD MVK ZERO ZERO .mptr .mptr .mptr .mptr loop: a_0, b_0 a_4, b_4, sum0, sum1, i val1, val2, prod1, prod2 4,A4,a_4 4,B4,b_4 25,i ; i = 100/4 sum0 ; multiply result = 0 sum1 ; multiply result = 0 a_0,a+0,8 a_4,a+4,8 b_0,b+0,8 b_4,b+4,8
.trip 50 LDW *a_0++[2],val1 LDW *b_0++[2],val2 MPY val1,val2,prod1 MPYH val1,val2,prod2 ADD prod1,sum0,sum0 ADD prod2,sum1,sum1 LDW LDW MPY MPYH ADD ADD *a_4++[2],val1 *b_4++[2],val2 val1,val2,prod1 val1,val2,prod2 prod1,sum0,sum0 prod2,sum1,sum1 1,i,i loop
; ; ; ; ; ; ; ; ; ; ; ;
load load a[0] a[1] sum0 sum1 load load a[2] a[3] sum0 sum1
a[01] b[01] * b[0] * b[1] += a[0] += a[1] a[2 3] b[2 3] * b[2] * b[3] += a[2] += a[3]
bankx banky
* b[2] * b[3]
4-40
The goal is to find a software pipeline in which the following instructions are in parallel:
LDW *a0++[2],val1 ; load a[01] || LDW *a2++[2],val2 ; load a[23] LDW *b0++[2],val1 ; load b[01] || LDW *b2++[2],val2 ; load b[23] bankx bankx+2 banky banky+2
ADD || ADD || MPY || MPYH || [ B0] B || LDW || LDW ADD || ADD || MPY || MPYH || [ B0] ADD || LDW || LDW
Without the .mptr directives in Example 412, the loads of a[01] and b[01] are scheduled in parallel, and the loads of a[23] and b[23] 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 413 can never have a memory bank conflict. In Example 410, 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 always be a memory bank conflict. However, it would find a schedule for a 2-cycle loop kernel.
4-41
4.5.3
4-42
4.5.4
B C
A B C
4-43
4.6.1
4.6.2
4.6.3
4-44
4.6.4
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.
The directive to indicate a specific memory dependence in the previous example is as follows:
.mdep ld1, st1
This means that whenever ld1 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 ld1 reference 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 ld1 to st1. The opposite, from st1 to ld1, is not implied. In terms of the software pipeline, while every ld1 must occur before every st1, it is still legal to schedule the ld1 from iteration n+1 before the st1 from interation n.
4-45
Example 416 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.
If that schedule does not work because the iteration n st1 might write a value the iteration n+1 ld1 should read, then you must note a dependence relationship from st1 to ld1.
.mdep st1, ld1
Both directives together force the software pipeline shown in Example 417.
Example 417. Software Pipeline Using .mdep st1, ld1 and .mdep ld1, st1
iteration n LDW { ld1 } ... STW { st1 } LDW { ld1 } ... STW { st1 } iteration n+1
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 case, you need to note the dependence relation in both directions, and you need to use both directives.
.mdep .mdep
4-46
4.6.5
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, src, cnt .reg tmp .no_mdep .mdep r1, r2 LDW STW *src{r1}, tmp cnt, *dst{r2}
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, src, cnt .reg tmp .no_mdep .mdep r2, r1 100 *src++{r1}, tmp tmp, *dst++{r2} cnt, 1, cnt LOOP
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 impact on the instruction schedule than a bank conflict. It is best to keep these two topics separate.
4-47
4-48
Chapter 5
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-timesupport 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
5.1 5.2 5.3 5.4 5.5
Page
Invoking the Linker as an Individual Program . . . . . . . . . . . . . . . . . . . 5-2 Invoking the Linker With the Compiler Shell (z Option) . . . . . . . . . . 5-4 Disabling the Linker (c Shell Option) . . . . . . . . . . . . . . . . . . . . . . . . . . 5-5 Linker Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-6 Controlling the Linking Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-8
5-1
filenames
options
o name.out l libraryname
lnk.cmd
5-2
When you specify a library as linker input, the linker includes and links only those library members that resolve undefined references. For example, you can link a C/C++ program consisting of modules prog1, prog2, and prog3 (the output file is named prog.out), enter:
lnk6x c prog1 prog2 prog3 o prog.out l rts6200.lib
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 more information, see the TMS320C6000 Assembly Language Tools User s Guide.
5-3
command line or be specified with the C_OPTION or C6X_C_OPTION environment variable. All arguments that follow z on the command line are passed on to the linker. These arguments can be linker command files, additional object files, linker options, or libraries. For example, to compile and link all the .c files in a directory, enter:
cl6x sq *.c z c.cmd o prog.out l rts6200.lib
First, all of the files in the current directory that have a .c extension are compiled using the s (interlist C/C++ and assembly code) and q (run in quiet mode) options. Second, the linker links the resulting object files by using the c.cmd command file. The o option names the output file, and the l option names the run-time-support library. 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 C6X_C_OPTION environment variable from the C_OPTION or
5-4
5-5
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 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 a relocatable, executable object module Disables merge of symbolic debugging information Autoinitializes variables at run-time. See section 8.8.4 on page 8-51, for more information. Initializes variables at load time. See section 8.8.5 on page 8-52, 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 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 eight 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 libraryname is an archive library name and must follow operating system conventions.
i directory
l libraryname
5-6
Linker Options
m filename
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.
Enables function subsections
mo n
Ignores all fill specifications in memory directives. Use this option in the development stage of a project to avoid generating large .out files, which can result from using memory directive fill specifications. 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) Retains relocation entries in the output module Strips 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. Places the unresolved external symbol symbol into the output modules symbol table Displays a message when an undefined output section is created Forces rereading of libraries. Resolves back references
o filename
q r s stack size
u symbol w x
For more information on linker options, see the Linker Description chapter in the TMS320C6000 Assembly Language Tools User s Guide.
5-7
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.
5.5.1
5-8
5.5.2
Run-Time Initialization
You must link all C/C++ programs with an object module called boot.obj. 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 rts6200e.lib rts6400.lib rts6400e.lib rts6700.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 2) Processes the run-time initialization table and autoinitializes global variables (when using the c option) 3) Calls all global constructors 4) Calls main 5) Calls exit when main returns The run-time-support object libraries contain boot.obj. You can:
- Use the archiver to extract boot.obj from the library and then link the mod-
ule 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) Chapter 9 describes additional run-time-support functions that are included in the library. These functions include ANSI C standard run-time support. Note: The _c_int00 Symbol One important function contained in the run-time support library is _c_int00. The symbol _c_int00 is the starting point in boot.obj; if you use the c or cr linker option, _c_int00 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.
5-9
5.5.3
5.5.4
section 8.8.5, Initialization of Variables at Load time, on page 8-52). 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.2, Invoking the Linker With the Compiler Shell, on page 5-4). The following list outlines the linking conventions used with c or cr:
- 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_int00 is automatically referenced, ensuring that boot.obj is automatically linked in from the run-time-support library.
- 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.
5-10
- When using initializing at load time (the cr linker option), the following
occur:
J
The linker sets the symbol cinit to 1. This indicates that the initialization tables are not in memory, so no initialization is performed at runtime. 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.
- 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.5.5
(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)
5-11
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-3 for 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-12
5.5.6
To link the program, use the following syntax: lnk6x object_file(s) o outfile m mapfile lnk.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.
l = 00400h /* reset & interrupt vectors */ l = 0FC00h /* intended for initialization */ l = 10000h /* .bss, .sysmem, .stack, .cinit */
> > > > > > > > > > >
VECS PMEM BMEM BMEM BMEM BMEM BMEM BMEM BMEM BMEM BMEM
5-13
5.5.7
5-14
5-15
Chapter 6
Topic
6.1 6.2 6.3 6.4 6.5
Page
Invoking the Stand-Alone Simulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-2 Stand-Alone Simulator Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-4 Using the Profiling Capability of the Stand-Alone Simulator . . . . . . 6-6 Selecting Silicon Revision to Simulate (rev Option) . . . . . . . . . . . . . 6-8 Stand-Alone Simulator Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-9
6-1
filename.out
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 61 provides two instances of the banner.
6-2
6-3
d[d]
f value
6-4
r xxx
Relocates all sections by xxx bytes during the load. For more information on relocation, see the linker chaper 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.4, Selecting Silicon Revision to Simulate (rev Option), on page 6-8 for more information. Sets timeout to xxx seconds. The stand-alone simulator aborts if no I/O event occurs for xxx seconds. I/O events include system calls. Pauses after each internal I/O error. Does not pause for EOF
rev value
t xxx
6-5
Example 62 runs three different versions of the dot product routines and prints out the result of each routine.
load6x q g t.out val = 11480 val = 11480 val = 11480 <t.vaa> Program Name: Start Address: Stop Address: Run Cycles: Profile Cycles: BP Hits: /c6xcode/t.out 0000554c main, at line 32, /c6xcode/t.c 000073a0 exit 10543 10543 18
*************************************************************************** Area Name Count Inclusive Incl Max Exclusive ExclMax CF dot_prod1() 1 60 60 60 60 CF dot_prod2() 1 55 55 55 55 CF dot_prod3() 1 35 35 35 35 CF main() 1 10537 10537 134 134
6-6
*************************************************************************** Area Name Count CF dot_prod1() 1 25% ===================================== CF dot_prod2() 1 25% ===================================== CF dot_prod3() 1 25% ===================================== CF main() 1 25% ===================================== *************************************************************************** Area Name Inclusive CF main() 10537 99% ===================================== CF dot_prod1() 60 <1% CF dot_prod2() 55 <1% CF dot_prod3() 35 <1% *************************************************************************** Area Name InclMax CF main() 10537 99% ===================================== CF dot_prod1() 60 <1% CF dot_prod2() 55 <1% CF dot_prod3() 35 <1% *************************************************************************** Area Name Exclusive CF main() 134 1% ===================================== CF dot_prod1() 60 <1% ================ CF dot_prod2() 55 <1% =============== CF dot_prod3() 35 <1% ========= *************************************************************************** Area Name ExclMax CF main() 134 1% ===================================== CF dot_prod1() 60 <1% ================ CF dot_prod2() 55 <1% =============== CF dot_prod3() 35 <1% ========= *************************************************************************** Area Name Address CF dot_prod1() 000052c0 CF dot_prod2() 000053a4 CF dot_prod3() 00005444 CF main() 0000554c
6-7
||
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 42 on page 4-35. If the -q option is not used, the load6x banner lists the selected silicon revision.
6-8
To compile and link the code in Example 63, enter the following text on the command line. The z option invokes the linker, l linker option names a linker command file, and the o linker option names the output file.
cl6x clock.c z l lnk60.cmd o clock.out
To run the stand-alone simulator on the resulting executable COFF file, enter:
load6x clock.out
Example 64. Stand-Alone Simulator Results After Compiling and Linking Example 63
TMS320C6x Standalone Simulator Version x.xx Copyright (c) 19892000 Texas Instruments Incorporated Interrupt to abort . . . Hello, world Time = 3338 cycles NORMAL COMPLETION: 11692 cycles
6-9
6-10
Chapter 7
The TMS320C6000 C/C++ compiler supports the C/C++ language standard that was developed by a committee of the American National Standards Institute (ANSI) to standardize the C programming language. The C++ language supported by the C6000 is defined by the ISO/IEC 148821998 standard with certain exceptions.
Topic
7.1 7.2 7.3 7.4 7.5 7.6 7.7 7.8 7.9
Page
Characteristics of TMS320C6000 C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-2 Characteristics of TMS320C6000 C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-5 Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-6 Keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-7 Register Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-16 The asm Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-17 Pragma Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-18 Generating Linknames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-32 Initializing Static and Global Variables . . . . . . . . . . . . . . . . . . . . . . . . . 7-33
7-1
Characteristics of TMS320C6000 C
7.1.1
uppercase and lowercase characters are distinct for identifiers. These characteristics apply to all identifiers, internal and external. (ANSI 3.1.2, K&R A2.3)
- The source (host) and execution (target) character sets are assumed to
values up to 32 bits.
7-2
Characteristics of TMS320C6000 C
7.1.2
Data Types
- For information about the representation of data types, see section 7.3 on
page 7-6.
- The type size_t, which is the result of the sizeof operator, is unsigned int.
7.1.3
Conversions
- Float-to-integer conversions truncate toward 0.
7.1.4
Expressions
- When two signed integers are divided and either is negative, the quo-
tient 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 = = 1, 10 / 3 = = 3 10 % 3 = = 1
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.
7-3
Characteristics of TMS320C6000 C
7.1.5
Declarations
- 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. (ANSI 3.5.1, K&R A2.1)
- Structure members 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-14. (ANSI 3.5.2.1, K&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.
7.1.6
Preprocessor
- The preprocessor ignores any unsupported # pragma directive.
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
- These C++ headers are the only C++ standard library header files in-
cluded:
J J
<new> <typeinfo>
- 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 en-
one class to a pointer to member of a another class if the classes are unrelated.
- Twophase name binding in templates, as described in [tesp.res] and
7-5
Data Types
7-6
Keywords
7.4 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
ample, 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.)
- If the 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 = &x; const int * q = &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};
7-7
Keywords
7.4.2
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.
7-8
Keywords
To use the control registers in Table 72, 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 register, 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 71 for an example that declares and uses control registers.
extern cregister volatile unsigned int FADCR; extern cregister volatile unsigned int FAUCR; extern cregister volatile unsigned int FMCR; main() { printf(AMR = %x\n, AMR); }
7-9
Keywords
7.4.3
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 ANSI mode (using the ps shell option).
7-10
Keywords
7.4.4
7.4.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 MVKH LDW _address,a1 _address,a1 *a1,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 get compiler 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. If you use the DATA_SECTION pragma, the object is indicated as a far variable, and this cannot be overridden. 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.
TMS320C6000 C/C++ Language Implementation 7-11
Keywords
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) and you want to reference that variable in C code, you must declar 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 PCrelative branch instruction.
B _func
far keyword
The compiler is told by the user that the call is not within 1 M word.
MVKL MVKH B _func,a1 _func,a1 a1
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) The mrn option controls how run-time-support functions are called: mr0 mr1 Run-time-support data and calls are near Run-time-support data and calls are far
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-12
Keywords
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 mln option generates large-memory model code on four levels (ml0, ml1, ml2, and ml3): ml/ml0 ml1 ml2 ml3 Aggregate data (structs/arrays) default to far All calls default to far All aggregate data and calls default to far 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 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 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 mln 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.
7-13
Keywords
7.4.5
Example 73 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.
7-14
Keywords
7.4.6
In this example, *ctrl is a loop-invariant expression, 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.
7-15
Register Variables
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.
- 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 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-16.
7-16
The inserted code must be a legal assembly language statement. Like all assembly language statements, the line of code inside 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. 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 optimizer cannot remove asm statements, it can significantly rearrange the code order near them and cause undesired results.
7-17
Pragma Directives
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
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.
7-18
Pragma Directives
7.7.1
7-19
Pragma Directives
7.7.2
7.7.3
C6400 C6700
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 symbols type size. This is useful if you need to align data in a particular way to avoid memory bank conflicts in your handcoded 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 amount as padding is used to align data onto the correct bank. For C6200, the code in Example 75 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 0 or 8. 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 4 or c.
7-21
Pragma Directives
7.7.4
7-22
Pragma Directives
7.7.5
7.7.6
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
7-24
Pragma Directives
7.7.8
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
7-25
Pragma Directives
7-26
Pragma Directives
7-27
Pragma Directives
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). 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-28
Pragma Directives
7-29
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 */
Any use of STRUCT_ALIGN with a basic type (int, short, float) or a variable results in an error.
7-30
Pragma Directives
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.
TMS320C6000 C/C++ Language Implementation 7-31
Generating Linknames
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
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.
7-32
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.
7-33
Normal ANSI mode K&R C mode Relaxed ANSI mode Strict ANSI mode
The default is normal ANSI mode. Under normal ANSI mode, most ANSI violations are emitted as errors. Strict ANSI violations (those idioms and allowances commonly accepted by C/C++ compilers, although violations with a strict interpretation of ANSI), however, are emitted as warnings. Language extensions, even those that conflict with ANSI C, are enabled. For C++ code, ANSI mode designates the latest supported working paper. K&R C mode does not apply to C++ code.
The specific differences between the ANSI version of C and the K&R version of C are as follows:
- The integral promotion rules have changed regarding promoting an
unsigned type to a wider signed type. Under K&R C, the result type was an unsigned version of the wider type; under ANSI, 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 (u < i) ... /* SIGNED comparison, unless pk used */ - ANSI prohibits combining two pointers to different types in an operation.
In most K&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 */
definitions. In a single module, multiple definitions of this form are fused together into a single definition. Under K&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 used, OK if not */
Under ANSI, the result of these two definitions is a single definition for the object a. For most K&R compilers, this sequence is illegal, because int a is defined twice.
- ANSI prohibits, but K&R allows objects with external linkage to be
redeclared as static:
extern int a; static int a; /* illegal unless pk used */
7-35
- ANSI 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; };
- K&R syntax allows a trailing comma in enumerator lists: enum { a, b, c, }; /* illegal unless pk used */
- K&R syntax allows trailing tokens on preprocessor directives: #endif NAME /* illegal unless pk used */
7.10.2 Enabling Strict ANSI Mode and Relaxed ANSI Mode (ps and pr Options)
Use the ps option when you want to compile under strict ANSI mode. In this mode, error messages are provided when non-ANSI 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 you want the compiler to ignore strict ANSI violations rather than emit a warning (as occurs in normal ANSI mode) or an error message (as occurs in strict ANSI mode). In relaxed ANSI mode, the compiler accepts extensions to the ANSI C standard, even when they conflict with ANSI C.
Templates Exception handling Run-time type information The new cast syntax The keyword mutable Multiple inheritance Virtual inheritance
Under the standard definition of embedded C++, namespaces and usingdeclarations 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.
7-36
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
8.1 8.2 8.3 8.4 8.5 8.6 8.7 8.8
Page
Memory Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-2 Object Representation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-8 Register Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-16 Function Structure and Calling Conventions . . . . . . . . . . . . . . . . . . . 8-18 Interfacing C and C++ With Assembly Language . . . . . . . . . . . . . . . . 8-22 Interrupt Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-41 Run-Time-Support Arithmetic Routines . . . . . . . . . . . . . . . . . . . . . . . . 8-43 System Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-45
Run-Time Environment
8-1
Memory Model
8-2
Memory Model
8.1.1
Sections
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:
- Initialized sections contain data or executable code. The C/C++ compil-
The .cinit section contains tables for initializing variables and constants. 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). The .switch section contains jump tables for large switch statements. The .text section contains all the executable code.
J J
gram can use this space at run-time to create and store variables. The compiler creates the following uninitialized sections:
J
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 can 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. The .far section reserves space for global and static variables that are declared far. The .stack section allocates memory for the system stack. This memory passes arguments to functions and allocates local variables. 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.
J J J
Note: Use Only Code in Program Memory With the exception of .text, the initialized and uninitialized sections cannot be allocated into internal program memory.
Run-Time Environment
8-3
Memory Model
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 7-22).
8.1.2
Save function return addresses Allocate local variables Pass arguments to functions Save temporary results
The run-time stack grows from the high addresses to the low addresses. The compiler 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.4, Linker Options, on page 5-6. 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 using the stack pointer, see section 8.3, Register Conventions, on page 8-16; for more information about the stack, see section 8.4, Function Structure and Calling Conventions, on page 8-18.)
8-4
Memory Model
Note: Stack Overflow 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.
8.1.3
Run-Time Environment
8-5
Memory Model
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 runtime. 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-45.
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.
- The small memory model, which is the default, requires that the entire
.bss section fit within 32K bytes (32 768 bytes) of memory. This means that the total space for all static and global data in 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 .bss (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 stored in .bss, it must first load the objects 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 A0 register, then loads the B0 register using a pointer to A0:
MVKL MVKH LDW _x, A0 _x, A0 *A0, B0
To use the large memory model, invoke the compiler with the mln option. For more information on the mln 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
All near direct accesses are relative to the DP. 2) Near indirect memory access
MVK (_a $bss),A0 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 8-47.)
Run-Time Environment
8-7
Object Representation
8.2.1
array
8-8
Object Representation
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 07 of a register (see Figure 81). Objects defined as short or unsigned short are stored in memory as two bytes and are loaded to and stored from bits 015 of a register (see Figure 81). 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 815 of the register and moving the second byte of memory to bits 07. 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 07 of the register and moving the second byte of memory to bits 815.
LS 0 LS 0 LS 0 LS 0
S S S S S S S S S S S S S S S S S S S S S S S S S I I I I I I I
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 U U U U U U U U 7
S S S S S S S S S S S S S S S S S I I I I I I I I I I I I I I I
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 U U U U U U U U U U U U U U U U 31
MS = most significant LS = least significant
15
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 82). Objects of these types are loaded to and stored from bits 032 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 2431 of the register, moving the second byte of memory to bits 1623, moving the third byte to bits 815, and moving the fourth byte to bits 07. 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 07 of the register, moving the second byte to bits 815, moving the third byte to bits 1623, and moving the fourth byte to bits 2431.
LS 0 LS
I
S E E E E E E E E M M M M M M M M M M M M M M M M M M M M M M M
23
31 MS
0 LS 0
E = exponent I = signed integer MS = most significant LS = least significant
U U U U U U U U U U U U U U U U U U U U U U U U U U U U U U U U
31
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 83) 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.
Run-Time Environment
8-11
Object Representation
8.2.1.4
double and long double Data Types Double and long double data types are stored in an odd/even pair of registers (see Figure 84) 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 of 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.
31
20
0 LS
Even register
M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M
31
Legend: S = sign M = mantissa E = exponent MS = most significant LS = least significant
8.2.1.5
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 struture contains an int, unsigned int, or float, a multiple of 4 bytes of storage is reserved in memory. Members of structures are stored in the same manner as if they were individual objects. Arrays are aligned on a boundary required by their element type. Elements of arrays are stored in the same manner as if they were individual objects.
8-12
Object Representation
8.2.1.6
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.7
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 (*f) (); long 0; } };
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.
Run-Time Environment
8-13
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 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 85). Figure 85 illustrates bit field packing, using the following bit field definitions:
struct{ int A:7 int B:10 int C:3 int D:2 int E:9 }x;
A0 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.
A A A A A A A B B B B B B B B B B C C C D D E E E E E E E E E X 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 2 1 0 1 0 8 7 6 5 4 3 2 1 0 X MS LS
Little-endian register
Little-endian memory
Legend:
B A A A A A A A B B B B B B B B E E D D C C C B X E E E E E E E 0 6 5 4 3 2 1 0 8 7 6 5 4 3 2 1 1 0 1 0 2 1 0 9 X 8 7 6 5 4 3 2
8-14
Object Representation
8.2.3
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-45.
- In an expression. For example:
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 0 byte is included. For example, the following lines define the string abc, and the terminating 0 byte (the label SL5 points to the string):
SL5: .sect .const .string abc,0
String labels have the form SLn, where n is a number assigned by the compiler to make the label unique. The number begins at 0 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 a[1] = x; /* Incorrect! */
Run-Time Environment
8-15
Register Conventions
8-16
Register Conventions
Register A0 A1 A2 A3 A4 A5
Register B0 B1 B2 B3 B4 B5
Special Uses Return register (address to return to) Argument 2 Argument 2 with B4 for doubles and longs Argument 4 Argument 4 with B6 for doubles and longs Argument 6 Argument 6 with B8 for doubles and longs Argument 8 Argument 8 with B10 for doubles and longs Argument 10 Argument 10 with B12 for doubles and longs Data page pointer (DP) Stack pointer (SP)
Parent Parent Parent Parent Child Child Child Child Child Child
Parent Parent Parent Parent Child Child Child Child Child Child
Run-Time Environment
8-17
8.4.1
8-18
A4 A4 A4
A4 A4 A4
B4 B4 B5:B4
A6
int *c, struct A d, float e, int f, int g);
A6 A6
B6 B7:B6
A8
B8
A10
/* NOTE: The following function has a variable number of arguments */ int vararg(int a, int b, int c, int d, ...);
A4 A3
A4
B4
int y);
A6
stack
...
struct A func4(
A4 2) The calling function must save registers A0 to A9 and B0 to B9 (and A16 to A31 and B16 to B31 for C6400), if their values are needed after the call, by pushing the values onto the stack. 3) The caller (parent) calls the function (child). 4) 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 of the function and deallocates the space at the end of the function.
8.4.2
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. 2) 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. 3) If 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. 4) 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). 5) The called function executes the code for the function. 6) 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 or long double 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 block 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(&s, x). The function f then copies the return structure directly into s, performing the assignment automatically. 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.
8-20
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
Run-Time Environment
8-21
8.5.1
must follow the register conventions outlined in section 8.3, Register Conventions, on page 8-16.
- 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 informa-
8-22
- When you call a C/C++ function from assembly language, load the desig-
nated 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 8-18. 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++ declara-
tions. Integers and 32-bit floating-point (float) values are returned in A4. Doubles and long doubles 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 or modules, the identifier should not begin with an underscore (_). See section 7.8, Generating Linknames, on page 7-32, 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 assembler. 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 .ref or .global. This creates an undeclared external reference that the linker resolves.
Run-Time Environment
8-23
Example 81 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.
In the C++ program in Example 81, the extern declaration of asmfunc is optional 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.
8-24
8.5.2
The intrinsics listed in Table 83 correspond to the indicated C6000 assembly language instructions. See the TMS320C6000 CPU and Instruction Set Reference Guide for more information. Note: Intrinsic Instructions in C versus Assembly Language In some instances, an intrinsics 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.
int _add4(int src1, int src2); ushort & _amem2(void *ptr); uint & _amem4(void *ptr);
Instructions not specified with a device apply to all C6000 devices. 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-25
unsigned _bitr(unsigned src); uint _clr(uint src2, uint csta, uint cstb);
BITR CLR
C6400
CLR
CMPEQ2
Instructions not specified with a device apply to all C6000 devices. 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-26
CMPGT2
C6400
CMPGTU4
C6400
DEAL
C6400
int _dotp2(int src1, int src2); double _ldotp2(int src1, int src2);
DOTP2 LDOTP2
C6400
DOTPNRSU2
C6400
DOTPRSU2
C6400
Instructions not specified with a device apply to all C6000 devices. 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-27
DPINT
C6700
long _dtol(double src); int _ext(int src2, uint csta, uint cstb);
EXT
EXTU
EXTU
ABSDP ABSSP
Instructions not specified with a device apply to all C6000 devices. 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-28
double _ltod(long src); int _max2 (int src1, int src2); unsigned _maxu4(unsigned src1, unsigned src2); int _min2(int src1, int src2); unsigned _minu4(unsigned src1, unsigned src2); ushort & _mem2(void * ptr); uint & _mem4(void * ptr);
Instructions not specified with a device apply to all C6000 devices. 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-29
Instructions not specified with a device apply to all C6000 devices. 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-30
double _mpyid (int src1, int src2); double _mpysu4 (int src1, unsigned src2); double _mpyu4 (unsigned src1, unsigned src2);
6700 C6400
MVD
C6400
void _nassert(int);
uint _norm(int src2); uint _lnorm(long src2); unsigned _pack2 (unsigned src1, unsigned src2); unsigned _packh2 (unsigned src1, unsigned src2); unsigned _packh4 (unsigned src1, unsigned src2); unsigned _packl4 (unsigned src1, unsigned src2); unsigned _packhl2 (unsigned src1, unsigned src2); unsigned _packlh2 (unsigned src1, unsigned src2);
Packs alternate bytes into return value. Can pack high or low bytes.
C6400
Instructions not specified with a device apply to all C6000 devices. 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-31
SADDU4
C6400
int _sat(long src2); uint _set(uint src2, uint csta, uint cstb);
SAT SET
SET
SHFL
Instructions not specified with a device apply to all C6000 devices. 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
C6400
int _smpy (int src1, int sr2); int _smpyh (int src1, int sr2); int _smpyhl (int src1, int sr2); int _smpylh (int src1, int sr2); double _smpy2 (int src1, int sr2);
Performs 16-bit multiplication between pairs of signed packed 16-bit values, with an additional 1 bit leftshift and saturate into a double result. Two signed 32-bit values are saturated to 16-bit values and packed into the return value Four signed 16-bit values are saturated to 8-bit values and packed into the return value Converts 32-bit float to 32-bit signed integer, using the rounding mode set by the CSR register Shifts src2 left by the contents of src1, saturates the result to 32 bits, and returns the result Shifts src2 to the left/right src1 bits. Saturates the result if the shifted value is greater than MAX_INT or less than MIN_INT. Subtracts src2 from src1, saturates the result, and returns the result
C6400
SPACK2
C6400
SPACKU4
C6400
SPINT
C6700
SSHL
int _sshvl (int src2, int src1); int _sshvr (int src2, int src1);
SSHVL SSHVR
C6400
int _ssub (int src1, int src2); long _lssub (int src1, long src2);
SSUB
Instructions not specified with a device apply to all C6000 devices. 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
int _sub4 (int src1, int src2); int _subabs4 (int src1, int src2);
SUB4 SUBABS4
SWAP4 UNPKHU4
C6400 C6400
UNPKLU4
C6400
XPND2
C6400
XPND4
C6400
Instructions not specified with a device apply to all C6000 devices. 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-34
8.5.3
8.5.4
Using MUST_ITERATE and _nassert to Enable SIMD and Expand Compiler Knowledge of Loops
Through the use of MUST_TERATE 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 < 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 < 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.
Run-Time Environment 8-35
The TMS320C6000 Programmer s Guide states that one of the ways to refine C/C++ code is to use word accesses to operate on 16-bit data stored in the high and low parts of a 32-bit register. Examples using casts to int pointers are shown with the use of intrinsics to use certain instructions like _mpyh. This can be automated by using the _nassert( ); intrinsic to specify that 16-bit short arrays are aligned on a 32-bit (word) boundary. The following two examples generate the same assembly code:
- Example 1
int dot_product(short *x, short *y, short z) { int *w_x = (int *)x; int *w_y = (int *)y; int sum1 = 0, sum2 = 0, i; for (i = 0; i < z/2; i++) { sum1 += _mpy(w_x[i], w_y[i]); sum2 += _mpyh(w_x[i], w_y[i]); } return (sum1 + sum2); }
- Example 2
int dot_product(short *x, short *y, short z) { int sum = 0, i; _nassert (((int)(x) & 0x3) == 0); _nassert (((int)(y) & 0x3) == 0); #pragma MUST_ITERATE(20, , 4); for (i = 0; i < z; i++) sum += x[i] * y[i]; return sum; }
Note: C++ Syntax for _nassert In C++ code, _nassert is part of the standard namespace. Thus, the correct syntax is std::_nassert().
8-36
8.5.5
The SAT bit is maintained by the code that disables interrupts around software pipelined loops. Saturated instructions cannot be speculatively executed.
3) If an interrupt service routine modifies the SAT bit, then the routine should be written to save and restore the CSR.
Run-Time Environment
8-37
8.5.6
Note: Using the asm Statement Keep the following in mind when using the asm statement:
- Be extremely careful not to disrupt the C/C++ environment. The compiler
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.
- Do not use the asm statement to insert assembler directives that change
(debug) option. The C environments debug information and the assembly macro expansion are not compatible.
8-38
8.5.7
8.5.7.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 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 83 shows how you can access a variable defined in .bss.
_var2 .usect mysect,4,4 ; Define the variable .global _var2 ; Declare it as external
Run-Time Environment
8-39
8.5.7.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 which 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 & (address of) operator to get the value. In other words, if x is an assembly language constant, its value in C/C++ is &x. You can use casts and #defines to ease the use of these symbols in your program, as in Example 84.
for (i=0; i<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 symbols value as stored in the symbol table, the symbols declared type is unimportant. In Example 84, int is used. You can reference linker-defined symbols in a similar manner.
8-40
Interrupt Handling
8.6.1
8.6.2
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 pragma or the interrupt keyword. For more information, see section 7.7.13, The INTERRUPT Pragma, on page 7-27, and 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.
Run-Time Environment 8-41
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.
If you need to save/restore the SAT 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
8-42
Run-Time Environment
8-43
8-44
System Initialization
Run-Time Environment
8-45
System Initialization
8.8.1
8.8.2
Global Constructors
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.
8-46
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 87 shows the format of the .cinit section and the initialization records.
Initialization record n
tion data. If the the size is negative, then the data is DP address patch data (described below).
- The second field contains the starting address of the area within the .bss
tialize the variable. Each variable that must be autoinitialized has an initialization record in the .cinit section. If the first field is negative, then the record represents a list of addresses that need to be patched by adding the value of the data page pointer (DP). This is only required for autoinitialized pointers to near data. The DP address patch autoinitialization record has the following fields:
- A negative size in bytes of the list of addresses - A list of addresses to be patched
Each variable that is autoinitialized with the address of a near variable will be in the DP address patch list. Example 86 (a) shows initialized global variables defined in C. Example 86 (b) shows the corresponding initialization table. The .cinit:c is a subsection in the .cinit section that contains all scalar data. The subsection is handeled as one record during initialization, which minimizes the overall size of the .cinit section.
Run-Time Environment 8-47
System Initialization
; _i @ 0
_i:
.sect .text .global _i .usect .bss:c,2,2 .sect .align .field .cinit:c 4 _x$bss,32
; _p @ 0
_p:
.sect .text .global _p .usect .bss:c,4,4 .sect .align .field .field .field .field .field .field .field .set .cinit 8 IR_1,32 _a+0,32 0x1,32 0x2,32 0x3,32 0x4,32 0x5,32 20
; ; ; ; ;
@ @ @ @ @
0 32 64 96 128
IR_1:
8-48
System Initialization
(b) Initialized information for variables defined in (a) (Continued) ;****************************************************************************** ;* MARK THE END OF THE SCALAR INIT RECORD IN CINIT:C * ;****************************************************************************** CIR: .sect .cinit:c ;****************************************************************************** ;* ADDRESS RELOCATIONS SCALARS * ;****************************************************************************** .sect .cinit:c .align 8 .field 4,32 .align 4 .field _p,32
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.
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-49
System Initialization
8.8.4
.cinit section
cinit Loader
8-50
System Initialization
8.8.5
.cinit section
Loader
.bss section
Run-Time Environment
8-51
8-52
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 ANSI C standard defines a set of run-time-support functions that perform these tasks. The TMS320C6000 C/C++ compiler implements the complete ANSI standard library except for those facilities that handle exception conditions and locale issues (properties that depend on local language, nationality, or culture). Using the ANSI standard library ensures a consistent set of functions that provide for greater portability. In addition to the ANSI-specified functions, the TMS320C6000 run-time-support library includes routines that give you processor-specific commands and direct 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 9.2 9.3 9.4 9.5
Page
Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-2 The C I/O Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-4 Header Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-13 Summary of Run-Time-Support Functions and Macros . . . . . . . . . . 9-25 Description of Run-Time-Support Functions and Macros . . . . . . . . 9-37
9-1
Libraries
9.1 Libraries
The following libraries are included with the TMS320C6000 C/C++ compiler:
- rts6200.lib, rts6400.lib, and rts6700.librun-time-support object libraries
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:
-
ANSI 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
You 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
9-2
Libraries
9.1.2
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:
cl6x options atoi.c strcpy.c ar6x r rts6200.lib atoi.obj strcpy.obj ;recompile ;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
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
Issuing the following shell command compiles, links, and creates the file main.out from the C6200 run-time-support little-endian library:
cl6x main.c z heap 400 l rts6200.lib o main.out
being output to your hosts stdout window. With properly written device drivers, the library also offers facilities to perform I/O on a user-specified device. Note: 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 5-6).
9-4
9.2.1
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
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 specifications for writing device-level routines to interface with the lowlevel 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.
9-6
lseek Close File or Device For I/O #include <stdio.h> #include <file.h>
int close(int file_descriptor); Syntax for C++
close
Syntax for C
Description
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.
Return Value
lseek
Syntax for C
Description
The lseek 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.
- The file_descriptor is the stream number assigned by the low-level rou-
tines that the device-level driver must associate with the opened file or device.
- The offset indicates the relative offset from the origin in characters. - The origin is used to indicate which of the base locations the offset is mea-
sured 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
Run-Time-Support Functions 9-7
open
Return Value The return function is one of the following: # new value of the file-position indicator if successful EOF if not successful
open
Syntax for C
Description
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 informa-
tion.
- The flags are attributes that specify how the device or file is manipulated.
These parameters can be ignored in some cases, depending on how data is interpreted by the device. Note, however, that 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.
- The mode is required but ignored.
Return Value
The function returns one of the following values: # <0 stream number assigned by the low-level routines that the device-level driver associates with the opened file or device if successful if not successful
9-8
read
Syntax for C
Description
The read function reads the number of characters specified by count to the buffer from the device or file associated with file_descriptor.
- The file_descriptor is the stream number assigned by the low-level rou-
placed.
- The count is the number of characters to read from the device or file.
Return Value
The function returns one of the following values: 0 # 1 if EOF was encountered before the read was complete number of characters read in every other instance if not successful
rename
Syntax for C
Description
Return Value
The function returns one of the following values: 0 if successful Non-0 if not successful
Run-Time-Support Functions 9-9
unlink
Syntax for C
Description
The unlink function deletes the file specified by path. The path is the filename of the file to be opened, including path information.
Return Value
The function returns one of the following values: 0 1 if successful if not successful
write
Syntax for C
Description
The write function writes the number of characters specified by count from the buffer to the device or file associated with file_descriptor.
- The file_descriptor is the stream number assigned by the low-level rou-
placed.
- The count is the number of characters to write to the device or file.
Return Value
The function returns one of the following values: # 1 number of characters written if successful if not successful
9-10
9.2.2
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-40.
9-11
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 <stdio.h> /****************************************************************************/ /* Declarations of the userdefined device drivers */ /****************************************************************************/ 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 long 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_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-12
Header Files
These are the header files that declare the ANSI C run-time-support functions: assert.h ctype.h errno.h file.h limits.h math.h setjmp.h stdarg.h stddef.h stdio.h stdlib.h string.h time.h
In addition to the ANSI C header files, the following C++ header files are included: cassert cctype cerrno cfloat climits cmath cmathf cmathl csetjmp cstdarg cstddef cstdio cstdlib cstring ctime exception new rtti.h stdexcept typeinfo
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 is declared by the ctype.h header. Before you can use the isdigit function, you must first include ctype.h:
#include <ctype.h> . . . 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-14 through 9.3.15, Time Functions (time.h/ctime ), on page 9-22 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-25 lists the functions that these headers declare.
9-13
Header Files
9.3.1
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.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 optimizer that the expression declared with assert is true. This gives a hint to the optimizer 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-35. The assert function is listed in Table 93 (a) on page 9-26.
9.3.2
9-14
Header Files
The ctype.h/cctype header also contains 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 93 (b) page 9-26.
9.3.3
EDOM for domain errors (invalid parameter) ERANGE for range errors (invalid result) ENOENT for path errors (path does not exist) 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
9.3.5
9-15
Header Files
9.3.6
Table 91. Macros That Supply Integer Type Range Limits (limits.h/climits)
Macro CHAR_BIT SCHAR_MIN SCHAR_MAX UCHAR_MAX CHAR_MIN CHAR_MAX SHRT_MIN SHRT_MAX USHRT_MAX INT_MIN INT_MAX UINT_MAX LONG_MIN LONG_MAX ULONG_MAX
Note:
Value 8 128 127 255 SCHAR_MIN SCHAR_MAX 32 768 32 767 65 535 (INT_MAX 1) 2 147 483 647 4 294 967 295 (LONG_MAX 1) 549 755 813 887 1 099 511 627 775
Description Number of bits in type char Minimum value for a signed char Maximum value for a signed char Maximum value for an unsigned char Minimum value for a char Maximum value for a char Minimum value for a short int Maximum value for a short int Maximum value for an unsigned short int Minimum value for an int Maximum value for an int Maximum value for an unsigned int Minimum value for a long int Maximum value for a long int Maximum value for an unsigned long int
Negative values in this table are defined as expressions in the actual header file so that their type is correct.
9-16
Header Files
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-17
Header Files
9.3.7
9.3.8
9-18
Header Files
9.3.9
environment. The nonlocal jmp macro and function are listed in Table 93 (d) on page 9-30.
when the number and type of arguments can vary each time a function is called.
- 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 93 (e) page 9-30.
9-19
Header Files
size_t. The result is the value of an offset in bytes to a structure member (identifier) from the beginning of its structure (type). These types and macros are used by several of the run time-support functions.
within a file
- FILE, a structure type to record all the information necessary to control a
name in characters
- L_tmpnam, a macro that expands to the longest filename string that
Header Files
respectively The input/output functions are listed in Table 93 (f) on page 9-30.
function
- ldiv_t, a structure type that is the type of the value returned by the ldiv
conversion representations
functions
that
convert
strings
to
numeric
- Searching and sorting functions that search and sort arrays - Sequence-generation
functions that generate a pseudo-random sequence and choose a starting point for a sequence
abnormally
- Integer-arithmetic that is not provided as a standard part of the C language
The general utility functions are listed in Table 93 (g) on page 9-33.
9-21
Header Files
Move or copy entire strings or portions of strings Concatenate strings Compare strings Search strings for characters or other strings Find the length of a string
In C, all character strings are terminated with a 0 (null) character. The string functions named strxxx 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 93 (h) on page 9-34.
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.
- As a structure of type struct tm. This structure contains members for ex-
pressing time as a combination of years, months, days, hours, minutes, and seconds. A time represented like this is called broken-down time. The structure has the following members.
int int int int int int int int int tm_sec; tm_min; tm_hour; tm_mday; tm_mon; tm_year; tm_wday; tm_yday; tm_isdst; /* /* /* /* /* /* /* /* /* seconds after the minute (059) */ minutes after the hour (059) */ hours after midnight (023) */ day of the month (131) */ months since January (011) */ years since 1900 (0 and up) */ days since Saturday (06) */ days since January 1 (0365) */ daylight savings time flag */
9-22
Header Files
A time, whether represented as a time_t or a struct tm, can be expressed from different points of reference:
- Calendar time represents the current Gregorian date and time. - Local time is the calendar time expressed for a specific time zone.
The time functions and macros are listed in Table 93 (i) on page 9-36. 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 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. 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 tickscan be divided by CLOCKS_PER_SEC to produce a value in seconds.
9-23
Header Files
9-24
9-25
(b) Character typing and conversion functions (ctype.h/cctype) Function int isalnum(int c); int isalpha(int c); int isascii(int c); int iscntrl(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); Description Page
Tests c to see if it is an alphanumeric-ASCII 9-67 character Tests c to see if it is an alphabetic-ASCII character 9-67 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 9-67 9-67 9-67
Tests c to see if it is any printing character except a 9-67 space Tests c to see if it is a lowercase alphabetic ASCII 9-67 charcter Tests c to see if it is a printable ASCII character 9-67 (including a space) Tests c to see if it is an ASCII punctuation character 9-67 Tests c to see if it is an ASCII space bar, tab 9-67 (horizontal or vertical), carriage return, form feed, or new line character Tests c to see if it is an uppercase ASCII alphabetic 9-67 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 Converts c to uppercase if it is lowercase 9-67 9-104 9-104 9-104
int isupper(int c); int isxdigit(int c); char toascii(int c); char tolower(int char c); char toupper(int char c);
Note:
Functions in ctype.h/cctype are expanded inline except when the pi option is used.
9-26
(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 atan2f(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 Returns the hyperbolic arc cosine of x Returns the arc cotangent of x Returns the arc cotangent of x/y Returns the arc cotangent of x/y Returns the arc cotangent of x Returns the hyperbolic arc cotangent of x Returns the hyperbolic arc cotangent of x Returns the arc sine of x Returns the arc sine of x Returns the hyperbolic arc sine of x Returns the hyperbolic arc sine of x 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 Returns the hyperbolic arc tangent of x Page 9-38 9-38 9-38 9-38 9-39 9-39 9-39 9-39 9-40 9-40 9-43 9-43 9-44 9-44 9-45 9-45 9-45 9-45 9-46 9-46
Returns the smallest integer x; expands inline 9-49 except when pi is used Returns the smallest integer x; expands inline 9-49 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 9-51 9-51 9-51 9-51 9-52
Enhanced math function. See section 9.3.8 on page 9-18 for information on accessing this function.
9-27
(c) Floating-point math functions (math.h/cmath) Function float cotf(float x); double coth(double x); float cothf(float x); double exp(double x); double exp10(double x); float exp10f(float x); double exp2(double x); float exp2f(float x); float expf(float x); double fabs(double x); float fabsf(float x); double floor(double x); float floorf(float x); double fmod(double x, double y); float fmodf(float x, float y); double frexp(double value, int *exp); float frexpf(float value, int *exp); double ldexp(double x, int exp); float ldexpf(float x, int exp); double log(double x); double log10(double x); float log10f(float x); double log2(double x); float log2f(float x); float logf(float x); Description Returns the cotangent of x Returns the hyperbolic cotangent of x Returns the hyperbolic cotangent of x Returns ex Returns 10.0x Returns 10.0x Returns 2.0x Returns 2.0x Returns ex Returns the absolute value of x Returns the absolute value of x Page 9-52 9-52 9-52 9-55 9-56 9-55 9-56 9-56 9-55 9-57 9-57
Returns the largest integer x; expands inline 9-59 except when pi is used Returns the largest integer x; expands inline 9-59 except when pi is used Returns the exact floating-point remainder of x/y Returns the exact floating-point remainder of x/y 9-60 9-60
Returns f and exp such that .5 v |f| t 1 and value 9-63 is equal to f 2exp Returns f and exp such that .5 v |f| t 1 and value 9-63 is equal to f 2exp Returns x 2exp Returns x 2exp Returns the natural logarithm of x Returns the base-10 logarithm of x Returns the base-10 logarithm of x Returns the base-2 logarithm of x Returns the base-2 logarithm of x Returns the natural logarithm of x 9-69 9-69 9-70 9-70 9-70 9-70 9-70 9-70
Enhanced math function. See section 9.3.8 on page 9-18 for information on accessing this function.
9-28
(c) Floating-point math functions (math.h/cmath) 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 9-77 fraction Breaks value into a signed integer and a signed 9-77 fraction Returns xy Returns xy Returns xi Returns xi Returns x rounded to the nearest integer Returns x rounded to the nearest integer Returns the reciprocal square root of x Returns the reciprocal square root of x 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 Returns x truncated toward 0 9-78 9-78 9-78 9-78 9-83 9-83 9-84 9-84 9-87 9-87 9-87 9-87 9-88 9-88 9-102 9-102 9-102 9-102 9-105 9-105
Enhanced math function. See section 9.3.8 on page 9-18 for information on accessing this function.
9-29
(d) Nonlocal jumps macro and function (setjmp.h/csetjmp) Function or Macro int setjmp(jmp_buf env); void longjmp(jmp_buf env, int _val); Description Page
Saves calling environment for use by longjmp; this 9-85 is a macro Uses jmp_buf argument to restore a previously 9-85 saved environment
(e) Variable argument macros (stdarg.h/cstdarg) Macro type va_arg(va_list, type); void va_end(va_list); void va_start(va_list, parmN); Description Page
Accesses the next argument of type type in a 9-106 variable-argument list Resets the calling mechanism after using va_arg 9-106
(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); Description Adds a device record to the device table Page 9-40
Clears the EOF and error indicators for the stream 9-50 that _fp points to Flushes the stream that _fp points to and closes 9-57 the file associated with that stream Tests the EOF indicator for the stream that _fp 9-57 points to Tests the error indicator for the stream that _fp 9-58 points to Flushes the I/O buffer for the stream that _fp 9-58 points to Reads the next character in the stream that 9-58 _fp points to Stores the object that pos points to to the current 9-58 value of the file position indicator for the stream that _fp points to Reads the next _size minus 1 characters from the 9-59 stream that _fp points to into array _ptr
9-30
(f) C I/O functions (stdio.h/cstdio) Function 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); Description Page
Opens the file that _fname points to; _mode points 9-60 to a string describing how to open the file Writes to the stream that _fp points to 9-61
Writes a single character, _c, to the stream that _fp 9-61 points to Writes the string pointed to by _ptr to the stream 9-61 pointed to by _fp Reads from the stream pointed to by _fp and 9-62 stores the input to the array pointed to by _ptr Opens the file that _fname points to using the 9-63 stream that _fp points to; _mode points to a string describing how to open the file Reads formatted input from the stream that _fp 9-64 points to Sets the file position indicator for the stream that 9-64 _fp points to Sets the file position indicator for the stream that 9-64 _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 indica- 9-65 tor for the stream that _fp points to Writes a block of data from the memory pointed to 9-65 by _ptr to the stream that _fp points to Reads the next character in the stream that 9-65 _fp points to A macro that calls fgetc() and supplies stdin as the 9-66 argument Performs the same function as fgets() using stdin 9-66 as the input stream Maps the error number in _s to a string and prints 9-77 the error message Performs the same function as fprintf but uses 9-79 stdout as its output stream A macro that performs like fputc() 9-79
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); int putchar(int _x);
A macro that calls fputc() and uses stdout as the 9-79 output stream
9-31
(f) C I/O functions (stdio.h/cstdio) Function int puts(const char *_ptr); int remove(const char *_file); int rename(const char *_old_name, const char *_new_name); void rewind(register FILE *_fp); int scanf(const char *_fmt, ...); void setbuf(register FILE *_fp, char *_buf); Description Writes the string pointed to by _ptr to stdout Page 9-80
Causes the file with the name pointed to by _file to 9-82 be no longer available by that name Causes the file with the name pointed to by 9-82 _old_name to be known by the name pointed to by _new_name Sets the file position indicator for the stream 9-83 pointed to by _fp to the beginning of the file Performs the same function as fscanf() but reads 9-84 input from stdin Returns no value. setbuf() is a restricted version of 9-84 setvbuf() and defines and associates a buffer with a stream Defines and associates a buffer with a stream 9-86
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(int _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);
Performs the same function as fprintf() but writes 9-88 to the array that _string points to Performs the same function as fscanf() but reads 9-88 from the string that _str points to Creates a temporary file 9-103
Generates a string that is a valid filename (that is, 9-103 the filename is not already being used) Pushes the character specified by _c back into the 9-105 input stream pointed to by _fp Performs the same function as fprintf() but re- 9-107 places the argument list with _ap Performs the same function as printf() but replaces 9-107 the argument list with _ap Performs the same function as sprintf() but re- 9-108 places the argument list with _ap
9-32
(g) General functions (stdlib.h/cstdlib) Function void abort(void); int abs(int i); int atexit(void (*fun)(void)); double atof(const char *st); int atoi(register const char *st); long atol(register const char *st); void *bsearch(register const void *key, register 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(register int numer, register int denom); void exit(int status); void free(void *packet); char *getenv(const char *_string) long labs(long i); ldiv_t ldiv(register long numer, register long denom); int ltoa(long val, char *buffer); void *malloc(size_t size); void *memalign(size_t alignment, size_t size); void minit(void); void qsort(void *base, size_t nmemb, size_t size, int (*compar) ()); Description Terminates a program abnormally Returns the absolute value of val; expands inline Page 9-37 9-37
Registers the function pointed to by fun, called 9-46 without arguments at program termination Converts a string to a floating-point value; expands 9-47 inline except when pi is used Converts a string to an integer 9-47
Converts a string to a long integer value; expands 9-47 inline except when pi is used Searches through an array of nmemb objects for 9-48 the object that key points to
Allocates and clears memory for num objects, 9-49 each of size bytes Divides numer by denom producing a quotient and 9-54 a remainder Terminates a program normally 9-55
Deallocates memory space allocated by malloc, 9-62 calloc, or realloc Returns the environment information for the vari- 9-66 able associated with _string Returns the absolute value of i; expands inline Divides numer by denom Converts val to the equivalent string Allocates memory for an object of size bytes 9-37 9-54 9-71 9-72
Allocates memory for an object of size bytes 9-72 aligned to an alignment byte boundary Resets all the memory previously allocated by 9-75 malloc, calloc, or realloc Sorts an array of nmemb members; base points to 9-80 the first member of the unsorted array, and size specifies the size of each member
9-33
(g) General functions (stdlib.h/cstdlib) Function int rand(void); void *realloc(void *packet, size_t size); void srand(unsigned int seed); double strtod(const char *st, char **endptr); long strtol(const char *st, char **endptr, int base); unsigned long strtoul(const char *st, char **endptr, int base); Description Page
Returns a sequence of pseudorandom integers in 9-81 the range 0 to RAND_MAX Changes the size of an allocated memory space Resets the random number generator Converts a string to a floating-point value Converts a string to a long integer Converts a string to an unsigned long integer 9-81 9-81 9-100 9-100 9-100
(h) String functions (string.h/cstring) Function void *memchr(const void *cs, int c, size_t n); int memcmp(const void *cs, const void *ct, size_t n); void *memcpy(void *s1, const void *s2, register size_t n); void *memmove(void *s1, const void *s2, size_t n); void *memset(void *mem, register int ch, register size_t length); char *strcat(char *string1, const char *string2); char *strchr(const char *string, int c); int strcmp(register const char *string1, register const char *s2); Description Page
Finds the first occurrence of c in the first n charac- 9-73 ters of cs; expands inline except when pi is used Compares the first n characters of cs to ct; ex- 9-73 pands inline except when pi is used Copies n characters from s1 to s2 Moves n characters from s1 to s2 9-74 9-74
Copies the value of ch into the first length charac- 9-74 ters of mem; expands inline except when pi is used Appends string2 to the end of string1 Finds the first occurrence of character c in s; expands inline if x is used 9-89 9-90
Compares strings and returns one of the following 9-90 values: < 0 if string1 is less than string2; 0 if string1 is equal to string2; > 0 if string1 is greater than string2. Expands inline if x is used. Compares strings and returns one of the following 9-90 values: <0 if string1 is less than string2; 0 if string1 is equal to string2; >0 if string1 is greater than string2. Copies string src into dest; expands inline except 9-91 when pi is used
9-34
(h) String functions (string.h/cstring)(Continued) Function size_t strcspn(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 *strrchr(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); Description Page
Returns the length of the initial segment of string 9-92 that is made up entirely of characters that are not in chs Maps the error number in errno to an error mes- 9-92 sage string Returns the length of a string Appends up to n characters from src to dest 9-94 9-95
Compares up to n characters in two strings; ex- 9-96 pands inline except when pi is used Copies up to n characters from src to dest; ex- 9-97 pands inline except when pi is used Locates the first occurrence in string of any char- 9-98 acter from chs Finds the last occurrence of character c in string; 9-98 expands inline except when pi is used Returns the length of the initial segment of string, 9-99 which is entirely made up of characters from chs Finds the first occurrence of string2 in string1 9-99
Breaks str1 into a series of tokens, each delimited 9-101 by a character from str2 Transforms n characters from from, to to 9-101
9-35
(i)
Time-support functions (time.h/ctime) Description Converts a time to a string Determines the processor time used Converts calendar time to local time Page 9-43 9-50 9-53
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); struct tm *localtime(const time_t *timer); time_t mktime(register struct tm *tptr); size_t strftime(char *out, size_t maxsize, const char *format, const struct tm *time); time_t time(time_t *timer);
Returns the difference between two calendar 9-53 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 9-67 9-69 9-76 9-93 9-103
9-36
abs/labs
abort
Syntax for C
Abort
#include <stdlib.h> void abort(void);
abs/labs
Syntax for C
Absolute Value
#include <stdlib.h> int abs(int i); long labs(long i);
Defined in Description
abs.c in rts.src The C/C++ compiler supports two functions that return the absolute value of an integer:
- The abs function returns the absolute value of an integer i. - The labs function returns the absolute value of a long i. Run-Time-Support Functions 9-37
acos/acosf
Syntax for C
Example
acosh/acoshf
Syntax for C
#define _TI_ENHANCED_MATH_H 1 #include <cmath> double std::acosh(double x); float std::acoshf(float x);
Defined in Description
acosh.c and acoshf.c in rts.src The acosh and acoshf functions return the hyperbolic arc cosine of a floatingpoint argument x, which must be in the range [1, infinity]. The return value is w 0.0.
9-38
acot/acotf
Syntax for C
Example
acot2/acot2f
Syntax for C
#define _TI_ENHANCED_MATH_H 1 #include <cmath> double std::acot2(double x, double y); float std::acot2f(float x, float y);
Defined in Description
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 [, ] radians.
Run-Time-Support Functions 9-39
acoth/acothf
Syntax for C
add_device
Syntax for C
#include <cstdio> int std::add_device(char *name, unsigned flags, int (*dopen)(), int (*dclose)(), int (*dread)(), int (*dwrite)(), fpos_t (*dlseek)(), int (*dunlink)(), int (*drename)());
9-40
add_device
Defined in Description 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 function 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.
- The name is a character string denoting the device name. - 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.
- The dopen, dclose, dread, dwrite, dlseek, dunlink, 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. Return Value The function returns one of the following values: 0 1 if successful if fails
Run-Time-Support Functions
9-41
add_device
Example This example does the following:
#include <stdio.h> /****************************************************************************/ /* Declarations of the userdefined device drivers */ /****************************************************************************/ 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_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); }
Adds the device mydevice to the device table Opens a file named test on that device and associate it with the file *fid Writes the string Hello, world into the file Closes the file
9-42
asctime
Syntax for C
The function returns a pointer to the converted string. For more information about the functions and types that the time.h header declares and defines, see section 9.3.15, Time Functions (time.h ), on page 9-22.
asin/asinf
Syntax for C
Arc Sine
#include <math.h> double asin(double x); float asinf(float x);
Defined in Description
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]. The return value is an angle in the range [/2, /2] radians.
double realval, radians; realval = 1.0; radians = asin(realval);
Example
/* asin returns
/2
*/
Run-Time-Support Functions
9-43
asinh/asinhf
Syntax for C
assert
Syntax for C
Defined in Description
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
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 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.
9-44
atan2/atan2f
Example 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
Defined in Description
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 [/2, /2] radians.
double realval, radians;
Example
/* radians = 0.0 */
atan2/atan2f
Syntax for C
#include <cmath> double std::atan2(double y, double x); float std::atan2f(float y, float x);
Defined in Description
atan2.c and atan2f.c in rts.src 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.
Run-Time-Support Functions 9-45
atanh/atanhf
Both arguments cannot be 0. The return value is an angle in the range [, ] radians. Example
double rvalu = 0.0, rvalv = 1.0, radians;
/* radians = 0.0 */
atanh/atanhf
Syntax for C
#define _TI_ENHANCED_MATH_H 1 #include <cmath> double std::atanh(double y, double x); float std::atanhf(float x);
Defined in Description
atanh.c and atanhf.c in rts.src The atanh and atanhf functions return the hyperbolic arc tangent of a floatingpoint argument x. The return value is in the range [1.0, 1.0].
atexit
Syntax for C
Defined in Description
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 order of their registration.
9-46
atof/atoi/atol
Syntax for C
points to the string; the string must have the following format: [space] [sign] digits [.digits] [e|E [sign] integer]
- 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
- 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 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 represent the integer portion of the number. 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-47
bsearch
Syntax for C
The cmp function compares the objects that ptr1 and ptr2 point to and returns one of the following values: t0 0 u0 Example if *ptr1 is less than *ptr2 if *ptr1 is equal to *ptr2 if *ptr1 is greater than *ptr2
int list[10] = { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }; int intcmp(const void *ptr1, const void *ptr2) { return *(int*)ptr1 *(int*)ptr2; }
9-48
calloc
Syntax for C
ceil/ceilf
Syntax for C
Ceiling
#include <math.h> double ceil(double x); float 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 answer = ceilf(3.1415); answer = ceilf(3.5); /* answer = 4.0 */ /* answer = 3.0 */
Run-Time-Support Functions
9-49
clearerr
Syntax for C
clock
Syntax for C
Processor Time
#include <time.h> clock_t clock(void);
Defined in Description
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]. 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. For more information about the functions and types that the time.h header declares and defines, see section 9.3.15, Time Functions (time.h ), on page 9-22.
9-50
cosh/coshf Cosine
#include <math.h> double cos(double x); float cosf(float x); Syntax for C++ #include <cmath> double std::cos(double x); float std::cosf(float x); Defined in Description 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 */
cos/cosf
Syntax for C
Example
cosh/coshf
Syntax for C
Hyperbolic Cosine
#include <math.h> double cosh(double x); float coshf(float x);
Defined in Description
cosh.c and coshf.c in rts.src The cosh and coshf functions 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 + ex) / 2, but are computationally faster and more accurate.
double x, y; x = 0.0; y = cosh(x); /* return value = 1.0 */
Example
Run-Time-Support Functions
9-51
cot/cotf
Syntax for C
coth/cothf
Syntax for C
Hyperbolic Cotangent
#define _TI_ENHANCED_MATH_H 1 #include <math.h> double coth(double x); float cothf(float x);
#define _TI_ENHANCED_MATH_H 1 #include <cmath> double std::coth(double x); float std::cothf(float x);
Defined in Description
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 w 1.0.
9-52
ctime
Syntax for C
The function returns the pointer returned by the asctime function. For more information about the functions and types that the time.h header declares and defines, see section 9.3.15, Time Functions (time.h ), on page 9-22.
difftime
Syntax for C
Time Difference
#include <time.h> double difftime(time_t time1, time_t time0);
Defined in Description
difftime.c in rts.src The difftime function calculates the difference between two calendar times, time1 minus time0. The return value expresses seconds. For more information about the functions and types that the time.h header declares and defines, see section 9.3.15, Time Functions (time.h ), on page 9-22.
Run-Time-Support Functions
9-53
div/ldiv Division
#include <stdlib.h> div_t div(register int numer, register int denom); ldiv_t ldiv(register long numer, register long denom); Syntax for C++ #include <cstdlib> div_t std::div(register int numer, register int denom); ldiv_t std::ldiv(register long numer, register long denom); Defined in Description div.c in rts.src Two 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.
- The div function performs integer division. The input arguments are inte-
div/ldiv
Syntax for C
gers; 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; int rem; } div_t;
/* quotient /* remainder
*/ */
- The ldiv function performs long integer division. The input arguments are
long integers; the function returns the quotient and the remainder in a structure of type ldiv_t. The structure is defined as follows:
typedef struct { long int quot; long int rem; } ldiv_t;
/* quotient /* remainder
*/ */
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.
9-54
exit
Syntax for C
exp/expf
Syntax for C
Exponential
#include <math.h> double exp(double x); float expf(float x);
Defined in Description
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;
Example
x = 2.0; y = exp(x);
exp10/exp10f Exponential
#define _TI_ENHANCED_MATH_H 1 #include <math.h> double exp10(double x); float exp10f(float x); Syntax for C++ #define _TI_ENHANCED_MATH_H 1 #include <cmath> double std::exp10(double x); float std::exp10f(float x); Defined in Description exp10.c and exp10f.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.
exp10/exp10f
Syntax for C
exp2/exp2f
Syntax for C
Exponential
#define _TI_ENHANCED_MATH_H 1 #include <math.h> double exp2(double x); float exp2f(float x);
#define _TI_ENHANCED_MATH_H 1 #include <cmath> double std::exp2(double x); float std::exp2f(float x);
Defined in Description
exp2.c and exp2f.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.
9-56
fabs/fabsf
Syntax for C
x = 57.5; y = fabs(x);
fclose
Syntax for C
Close File
#include <stdio.h> int fclose(FILE *_fp);
Defined in Description
fclose.c in rts.src The fclose function flushes the stream that _fp points to and closes the file associated with that stream.
feof
Syntax for C
Defined in Description
feof.c in rts.src The feof function tests the EOF indicator for the stream pointed to by _fp.
Run-Time-Support Functions 9-57
ferror
Syntax for C
fflush
Syntax for C
Defined in Description
fflush.c in rts.src The fflush function flushes the I/O buffer for the stream pointed to by _fp.
fgetc
Syntax for C
Defined in Description
fgetc.c in rts.src The fgetc function reads the next character in the stream pointed to by _fp.
fgetpos
Syntax for C
Store Object
#include <stdio.h> int fgetpos(FILE *_fp, fpos_t *pos);
Defined in Description
fgetpos.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.
9-58
fgets
Syntax for C
floor/floorf
Syntax for C
Floor
#include <math.h> double floor(double x); float floorf(float x);
Defined in Description
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;
Example
Run-Time-Support Functions
9-59
fmod/fmodf
Syntax for C
fopen
Syntax for C
Open File
#include <stdio.h> FILE *fopen(const char *_fname, const char *_mode);
Defined in Description
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.
9-60
fprintf
Syntax for C
fputc
Syntax for C
Write Character
#include <stdio.h> int fputc(int _c, register FILE *_fp);
Defined in Description
fputc.c in rts.src The fputc function writes a character to the stream pointed to by _fp.
fputs
Syntax for C
Write String
#include <stdio.h> int fputs(const char *_ptr, register FILE *_fp);
Defined in Description
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-61
fread
Syntax for C
free
Syntax for C
Deallocate Memory
#include <stdlib.h> void free(void *packet);
Defined in Description
memory.c in rts.src The free function deallocates memory space (pointed to by packet) that 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); free(x); /* /* allocate 10 bytes free 10 bytes */ */
Example
9-62
freopen
Syntax for C
frexp/frexpf
Syntax for C
#include <cmath> double std::frexp(double value, int *exp); float std::frexpf(float value, int *exp);
Defined in Description
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 v |f| t 1.0 and value ++ f 2exp. 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;
Example
Run-Time-Support Functions
9-63
fscanf
Syntax for C
fseek
Syntax for C
#include <cstdio> int std::fseek(register FILE *_fp, long _offset, int _ptrname);
Defined in Description
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.
fsetpos
Syntax for C
Defined in Description
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 value from fgetpos() on the same stream.
9-64
ftell
Syntax for C
fwrite
Syntax for C
#include <cstdio> size_t std::fwrite(const void *_ptr, size_t _size, size_t _count, register FILE *_fp);
Defined in Description
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.
getc
Syntax for C
Defined in Description
fgetc.c in rts.src The getc function reads the next character in the file pointed to by _fp.
Run-Time-Support Functions 9-65
getchar
Syntax for C
getenv
Syntax for C
Defined in Description
trgdrv.c in rts.src The getenv function returns the environment information for the variable associated with _string.
gets
Syntax for C
Defined in Description
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 _ptr. Use the function fgets( ) instead of gets when possible.
9-66
gmtime
Syntax for C
isxxx
Syntax for C
Character Typing
#include <ctype.h> int isalnum(int c); int isalpha(int c); int isascii(int c); int iscntrl(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);
Syntax for C
#include <cctype> int std::isalnum(int c); int std::isalpha(int c); int std::isascii(int c); int std::iscntrl(int c); int std::isdigit(int c); int std::isgraph(int c); int std::islower(int c); int std::isprint(int c); int std::ispunct(int c); int std::isspace(int c); int std::isupper(int c); int std::isxdigit(int c);
Defined in
isxxx
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 isalpha isascii iscntrl isdigit isgraph islower isprint ispunct isspace isupper isxdigit Identifies alphanumeric ASCII characters (tests for any character for which isalpha or isdigit is true) Identifies alphabetic ASCII characters (tests for any character for which islower or isupper is true) Identifies ASCII characters (any character 0127) Identifies control characters (ASCII characters 031 and 127) Identifies numeric characters between 0 and 9 (inclusive) Identifies any nonspace character Identifies lowercase alphabetic ASCII characters Identifies printable ASCII characters, including spaces (ASCII characters 32126) Identifies ASCII punctuation characters Identifies ASCII tab (horizontal or vertical), space bar, carriage return, form feed, and new line characters Identifies uppercase ASCII alphabetic characters Identifies hexadecimal digits (09, af, AF)
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-68
labs
ldexp/ldexpf
Syntax for C
Multiply by a Power of 2
#include <math.h> double ldexp(double x, int exp); float ldexpf(float x, int exp);
#include <cmath> double std::ldexp(double x, int exp); float std::ldexpf(float x, int exp);
Defined in Description
ldexp.c and ldexpf.c in rts.src The ldexp and ldexpf functions multiply a floating-point number x by 2exp and return (x 2)exp. The exp can be a negative or a positive value. A range error occurs if the result is too large.
double result;
Example
ldiv
localtime
Syntax for C
Local Time
#include <time.h> struct tm *localtime(const time_t *timer);
Defined in Description
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 header declares and defines, see section 9.3.15, Time Functions (time.h ), on page 9-22.
Run-Time-Support Functions 9-69
log/logf
Syntax for C
Example
x = 2.718282; y = logf(x);
/* y = approx 1.0 */
log10/log10f
Syntax for C
Common Logarithm
#include <math.h> double log10(double x); float log10f(float x);
Defined in Description
log10.c and log10f.c in rts.src The 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;
Example
x = 10.0; y = log10f(x);
9-70
/* y = approx 1.0 */
log2/log2f
Syntax for C
Example
x = 2.0; y = log2f(x);
/* y = approx 1.0 */
longjmp
ltoa
Syntax for C
Defined in Description
ltoa.c in rts.src The ltoa function is a nonstandard (non-ANSI) 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 ltoa function returns the number of characters placed in the buffer.
Run-Time-Support Functions 9-71
malloc
Syntax for C
memalign
Syntax for C
Align Heap
#include <stdlib.h> void *memalign(size_t alignment, size_t _size);
Defined in Description
memory.c in rts.src The memalign function performs like the ANSI 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.
9-72
memchr
Syntax for C
memcmp
Syntax for C
Memory Compare
#include <string.h> int memcmp(const void *cs, const void *ct, size_t n);
#include <cstring> int std::memcmp(const void *cs, const void *ct, size_t n);
Defined in Description
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: t0 0 u0 if *cs is less than *ct if *cs is equal to *ct if *cs is greater than *ct
The memcmp function is similar to strncmp, except that the objects that memcmp compares can contain values of 0.
Run-Time-Support Functions 9-73
memcpy
Syntax for C
memmove
Syntax for C
#include <cstring> void *std::memmove(void *s1, const void *s2, size_t n);
Defined in Description
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.
memset
Syntax for C
#include <cstring> void *std::memset(void *mem, register int ch, register size_t length);
Defined in Description
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.
9-74
minit
Syntax for C
Run-Time-Support Functions
9-75
mktime
Syntax for C
mktime(&time_str); /* After calling this function, time_str.tm_wday */ /* contains the day of the week for July 4, 2001 */
9-76
modf/modff
Syntax for C
Example
value = 10.125; fpart = modf(value, &ipart); /* After execution, ipart contains 10.0, */ /* and fpart contains .125. */
perror
Syntax for C
Syntax for C
Defined in Description
perror.c in rts.src The perror function maps the error number in _s to a string and prints the error message.
Run-Time-Support Functions
9-77
pow/powf
Syntax for C
Example
powi/powif
Syntax for C
#define _TI_ENHANCED_MATH_H 1 #include <cmath> double std::powi(double x, int y); float std::powif(float x, int y);
Defined in Description
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 and i 0, or if x is negative and i is not an integer. A range error occurs if the result is too large to represent.
9-78
printf
Syntax for C
putc
Syntax for C
Write Character
#include <stdio.h> int putc(int _x, FILE *_fp);
Defined in Description
fputc.c in rts.src The putc function writes a character to the stream pointed to by _fp.
putchar
Syntax for C
Defined in Description
fputc.c in rts.src The putchar function writes a character to the standard output device.
Run-Time-Support Functions 9-79
puts
Syntax for C
qsort
Syntax for C
Array Sort
#include <stdlib.h> void qsort(void *base, size_t nmemb, size_t size, int (*compar) ());
#include <cstdlib> void std::qsort(void *base, size_t nmemb, size_t size, int (*compar) ());
Defined in Description
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 *ptr1, const void *ptr2)
The cmp function compares the objects that ptr1 and ptr2 point to and returns one of the following values: t0 0 u0 Example if *ptr1 is less than *ptr2 if *ptr1 is equal to *ptr2 if *ptr1 is greater than *ptr2
int list[10] = { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }; int intcmp(const void *ptr1, const void *ptr2) { return *(int*)ptr1 *(int*)ptr2; }
9-80
rand/srand
Syntax for C
0 RAND_MAX.
- 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. 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.
realloc
Syntax for C
Defined in Description
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.
- If packet is 0, realloc behaves like malloc. - If packet points to unallocated space, realloc takes no action and re-
turns 0.
- If the space cannot be allocated, the original memory space is not
remove
- If size = = 0 and packet is not null, realloc frees the space that
packet points to. If the entire object must be 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.3, Dynamic Memory Allocation, on page 8-5.
remove
Syntax for C
Remove File
#include <stdlib.h> int remove(const char *_file);
Defined in Description
remove.c in rts.src The remove function makes the file pointed to by _file no longer available by that name.
rename
Syntax for C
Rename File
#include <stdlib.h> int rename(const char *old_name, const char *new_name);
Defined in Description
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.
9-82
rewind
Syntax for C
round/roundf
Syntax for C
#define _TI_ENHANCED_MATH_H 1 #include <cmath> double round(double x); float roundf(float x);
Defined in Description
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, u, v, r, s, o, p;
Example
/* y = 3
*/
/* v = 5 */
/* s = 4 */
/* p = 6.0 */
Run-Time-Support Functions 9-83
rsqrt/rsqrtf
Syntax for C
scanf
Syntax for C
Defined in Description
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.
setbuf
Syntax for C
Defined in Description
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.
9-84
setjmp/longjmp
Syntax for C
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.
- 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.
Run-Time-Support Functions
9-85
setvbuf
Example These functions are typically used to effect an immediate return from a deeply nested function call:
#include <setjmp.h> 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); . . . }
setvbuf
Syntax for C
#include <cstdlib> int std::setvbuf(register FILE *_fp, register char *_buf, register int _type, register size_t _size);
Defined in Description
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 _IOLBF _IONBF Full buffering occurs Line buffering occurs No buffering occurs
9-86
sinh/sinhf Sine
#include <math.h> double sin(double x); float sinf(float x); Syntax for C++ #include <cmath> double std::sin(double x); float std::sinf(float x); Defined in Description 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 */
sin/sinf
Syntax for C
Example
sinh/sinhf
Syntax for C
Hyperbolic Sine
#include <math.h> double sinh(double x); float sinhf(float x);
Defined in Description
sinh.c and sinhf.c in rts.src The sinh and sinhf functions return the hyperbolic sine of a floating-point number x. A range error occurs if the magnitude of the argument is too large. These functions are equivalent to (ex ex) / 2, but are computationally faster and more accurate.
double x, y;
Example
x = 0.0; y = sinh(x);
/* y = 0.0 */
Run-Time-Support Functions 9-87
sprintf
Syntax for C
sqrt/sqrtf
Syntax for C
Square Root
#include <math.h> double sqrt(double x); float sqrtf(float x);
sqrt.c and sqrtf.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;
x = 100.0; y = sqrt(x);
srand sscanf
Syntax for C
#include <cstdlib> int std::sscanf(const char *_str, const char *_fmt, ...);
Defined in Description
sscanf.c in rts.src The sscanf function reads from the string pointed to by str. The string pointed to by _format describes how to read the stream.
9-88
strcat
Syntax for C
Example
Run-Time-Support Functions
9-89
strchr
Syntax for C
Example
b = strchr(a,the_z);
strcmp/strcoll
Syntax for C
String Compare
#include <string.h> int strcmp(const char *string1, register const char *string2); int strcoll(const char *string1, const char *string2);
#include <cstring> int std::strcmp(const char *string1, register const char *string2); int std::strcoll(const char *string1, const char *string2);
Defined in Description
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 ANSI C. The functions return one of the following values: t0 0 u0 if *string1 is less than *string2 if *string1 is equal to *string2 if *string1 is greater than *string2
9-90
strcpy
Example
char *stra = why ask why; char *strb = just do it; char *strc = why ask why;
if (strcmp(stra, strb) > 0) { /* statements here execute } if (strcoll(stra, strc) == 0) { /* statements here execute also }
*/
*/
strcpy
Syntax for C
String Copy
#include <string.h> char *strcpy(register char *dest, register const char *src);
#include <cstring> char *std::strcpy(register char *dest, register const char *src);
Defined in Description
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 functions 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 a[] = The quick black fox; char b[] = jumps over ; /* a > The quick black fox\0 /* b > jumps over \0 strcpy(a,b); /* a > jumps over \0 /* b > jumps over \0 */ */ */ */
Example
Run-Time-Support Functions
9-91
strcspn
Syntax for C
Example
/* length = 0 */ /* length = 9 */
strerror
Syntax for C
String Error
#include <string.h> char *strerror(int errno);
Defined in Description
strerror.c in rts.src The strerror function returns the string string error. This function is supplied to provide ANSI compatibility.
9-92
strftime
Syntax for C
Run-Time-Support Functions
9-93
strlen
Character %y %Y %Z
Expands to The year without century as a decimal number (0099) The year with century as a decimal number 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 header declares and defines, see section 9.3.15, Time Functions (time.h), on page 9-22.
strlen
Syntax for C
Defined in Description
strlen.c in rts.src The strlen function returns the length of string. 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 *strc = abcdefg; size_t length;
Example
9-94
strncat
Syntax for C
Example
Run-Time-Support Functions
9-95
strncmp
Syntax for C
char *stra = why ask why; char *strb = just do it; char *strc = why not?; size_t size = 4;
if (strcmp(stra, strb, size) > 0) { /* statements here execute } if (strcomp(stra, strc, size) == 0) { /* statements here execute also }
*/
*/
9-96
strncpy
Syntax for C
Example
strncpy (stra,strb,length ); /* /* /* /* stra> strb> strc> strd> he is the one mother warned you of\0 he is\0 I am the one father warned you of\0 oops\0 */; */; */; */;
strncpy (stra,strc,length ); /* /* /* /* stra> strb> strc> strd> I am the one mother warned you of\0 he is\0 I am the one father warned you of\0 oops\0 */; */; */; */;
strncpy (stra,strd,length ); /* /* /* /* stra> strb> strc> strd> oops\0 he is\0 I am the one father warned you of\0 oops\0
Run-Time-Support Functions
strpbrk
Syntax for C
Example
a = strpbrk (stra,strb);
strrchr
Syntax for C
Defined in Description
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, the search is on for zs; char *b; char the_z = z;
Example
After this example, *b points to the z in zs near the end of the string.
9-98
strspn
Syntax for C
Example
/* length = 3 */ /* length = 0 */
strstr
Syntax for C
#include <cstring> char *std::strstr(register const char *string1, const char *string2);
Defined in Description
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?; char *strb = what; char *ptr;
Example
ptr = strstr(stra,strb);
The pointer *ptr now points to the w in what in the first string.
Run-Time-Support Functions 9-99
strtod/strtol/ strtoul
Syntax for C
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.
- 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]
- 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] 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 digits 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.
9-100
strtok
Syntax for C
Example
strxfrm
Syntax for C
Convert Characters
#include <string.h> size_t strxfrm(register char *to, register const char *from, register size_t n);
#include <cstring> size_t std::strxfrm(register char *to, register const char *from, register size_t n);
Defined in Description
strxfrm.c in rts.src The strxfrm function converts n characters pointed to by from into the n characters pointed to by to .
Run-Time-Support Functions
9-101
tan/tanf Tangent
#include <math.h> double tan(double x); float tanf(float x); Syntax for C++ #include <cmath> double std::tan(double x); float std::tanf(float x); Defined in Description 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;
tan/tanf
Syntax for C
Example
x = 3.1415927/4.0; y = tan(x);
/* y = approx 1.0 */
tanh/tanhf
Syntax for C
Hyperbolic Tangent
#include <math.h> double tanh(double x); float tanhf(float x);
Defined in Description
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;
Example
x = 0.0; y = tanh(x);
9-102
tmpnam Time
#include <time.h> time_t time(time_t *timer); Syntax for C++ #include <ctime> time_t std::time(time_t *timer); Defined in Description time.c in rts.src The time function determines the current calendar time, represented in seconds. If the calendar time 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 header declares and defines, see section 9.3.15, Time Functions (time.h), on page 9-22. Note: The time Function Is Target-System Specific The time function is target-system specific, so you must write your own time function.
time
Syntax for C
tmpfile
Syntax for C
Defined in Description
tmpnam
Syntax for C
Defined in Description
tmpnam.c in rts.src The tmpnam function generates a string that is a valid filename.
Run-Time-Support Functions 9-103
toascii
Syntax for C
tolower/toupper
Syntax for C
Convert Case
#include <ctype.h> char tolower(int c); char toupper(int c);
Defined in Description
tolower.c and toupper.c in rts.src Two functions convert the case of a single alphabetic character c into uppercase or lowercase:
- The tolower function converts an uppercase argument to lowercase. If c
already in uppercase, toupper returns it unchanged. The functions have macro equivalents named _tolower and _toupper.
9-104
trunc/truncf
Syntax for C
Example
/* y = 2 */
/* v = 5 */
ungetc
Syntax for C
Defined in Description
ungetc.c in rts.src The ungetc function writes the character _c to the stream pointed to by _fp.
Run-Time-Support Functions
9-105
va_arg/va_end/ va_start
Syntax for C
#include <stdarg.h> typedef char *va_list; type va_arg(va_list, _type); void va_end(va_list); void va_start(va_list, parmN);
#include <cstdarg> 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);
Defined in Description
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.
- 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 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.
9-106
vprintf
Example
int
printf (char *fmt...) va_list ap; va_start(ap, fmt); . . . i = va_arg(ap, int); s = va_arg(ap, char *); l = va_arg(ap, long); . . . va_end(ap);
/* Get next arg, an integer */ /* Get next arg, a string */ /* Get next arg, a long */
/* Reset
*/
vfprintf
Syntax for C
Write to Stream
#include <stdlib.h> int vfprintf(FILE *_fp, const char *_format, va_list _ap);
#include <cstdlib> int std::vfprintf(FILE *_fp, const char *_format, va_list _ap);
Defined in Description
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.
vprintf
Syntax for C
Defined in Description
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.
Run-Time-Support Functions 9-107
vsprintf
Syntax for C
9-108
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 10.2 Invoking the Library-Build Utility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-3 10.3 Library-Build Utility Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-4 10.4 Options Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-5
Library-Build Utility
10-1
Comment base, C6200 base, C6200, big endian base, C6400 base, C6400, big endian base, C6700 base, C6700, big endian
10-2
src_arch
lobj.lib
The mk6x utility runs the shell 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
q u
10-4
Options Summary
(b) Options that are machine-specific Option ma mb Effect Assumes aliased variables Compiles C6400 code compatible with array alignment restrictions of version 4.0 tools or C6200/C6700 object code 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 ml3) Turns on function subsections Makes calls to run-time-support functions near (mr0) or far (mr1) 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 Page 3-25 2-42
2-16 3-13 2-41 2-16 5-14 2-16 3-17 3-26 3-5 3-15
Library-Build Utility
10-5
Options Summary
(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 are still issued) Page 2-31 2-32 2-32
(e) Options that control the optimization level Option o0 o1 o2 (or o) o3 Effect Compiles with register optimization Compiles with o0 optimization + local optimization Compiles with o1 optimization + global optimization Compiles with o2 optimization + file optimization. Note that mk6x automatically sets oI0 and op0. Page 3-2 3-2 3-3 3-3
(f) Option that controls the assembler Option as Effect Keeps labels as symbols Page 2-22
(g) Options that change the default file extensions Option ea[.]new extension eo[.]new extension Effect Sets default extension for assembly files Sets default extension for object files Page 2-20 2-20
10-6
Chapter 11
Topic
Page
11.1 Invoking the C+= Name Demangler . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-2 11.2 C++ Name Demangler Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-2 11.3 Sample Usage of the C++ Name Demangler . . . . . . . . . . . . . . . . . . . . 11-3
11-1
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
11-3
Executing the C++ name demangler utility demangles all names that it believes to be mangled. If you enter:
% dem6x foo.asm
the result is shown in Example 112. Notice that the linknames of foo( ) and compute( ) are demangled.
11-4
Example 112. Result After Running the C++ Name Demangler Utility
;*********************************************************** ;* FUNCTION DEF: foo(short, int *) * ;*********************************************************** foo(short, int *): LDW .D2T2 *+DP(_last_err$1),B0 MVK .S1 (_last_err$1$bss),A0 NOP 3 [ B0] B .S1 L1 STW .D2T2 B10,*SP(8) STW .D2T2 B3,*+SP(4) || MVKL .S2 RL0,B3 MVKH .S2 RL0,B3 || MV .D2 B4,B10 || ADD .L2X DP,A0,B4 || ZERO .L1 A0 [ B0] LDW .D2T2 *+SP(4),B3 NOP 1 ; BRANCH OCCURS B .S2 compute(int,int *) NOP 5 RL0: ; CALL OCCURS LDW .D2T2 *+DP(_last_err$1),B0 || MV .L1 A4,A0 LDW .D2T2 *+SP(4),B3 NOP 1 L1: NOP 3 B .S2 B3 || STW .D2T2 B0,*B10 LDW .D2T2 *++SP(8),B10 MV .L1 A0,A4 NOP 3 ; BRANCH OCCURS
11-5
11-6
Glossary
Appendix AppendixA A
Glossary
A
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 optimization, because any indirect reference could refer to any other object. allocation: A process in which the linker calculates the final memory addresses of output sections. American National Standards Institute(ANSI): An organization that establishes 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, directives, and macro definitions. The assembler substitutes absolute operation 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 shell program, cl6x, when one of the input files has a .sa extension. assignment statement: A statement that initializes a variable with a value.
Glossary A-1
Glossary
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. 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.
B
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 determined 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/C++ compiler: A software program that translates C source statements into assembly language source statements. 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 files for the linker or hex conversion utility. comment: A source statement (or portion of a source statement) that documents or improves readability of a source file. Comments are not compiled, assembled, or linked; they have no effect on the object file. common object file format(COFF): A system of object files configure according to a standard developed by AT&T. These files are relocatable in memory space.
A-2
Glossary
constant:
cross-reference listing: An output file created by the assembler that lists the symbols it defined, what line they were defined on, which lines referenced them, and their final values.
D
.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 functions 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 variables at run time. This is accomplished by defining a large memory pool (heap) and using the functions to allocate memory from the heap.
E
emulator: A hardware development TMS320C6000 operation. system that duplicates the
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. 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.
Glossary A-3
Glossary
F
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.
G
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.
H
hex conversion utility: A utility that converts COFF object files into one of several standard ASCII hexadecimal formats, suitable for loading into an EPROM programmer.
I
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. interlist utility: A utility that inserts as comments your original C/C++ source statements into the assembly language output from the assembler. The C/C++ statements are inserted next to the equivalent assembly instructions.
A-4
Glossary
K
kernel: The body of a software-pipelined loop between the pipelined-loop prolog and the pipelined-loop epilog. K&R C: Kernighan and Ritchie C, the de facto standard as defined in the first edition of The C Programming Language (K&R). Most K&R C programs written for earlier, non-ANSI C compilers should correctly compile and run without modification.
L
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 statements, their line numbers, and their effects on the section program counter (SPC). 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 numbered addresses. Endian ordering is hardware-specific and is determined 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 module into system memory. loop unrolling: An optimization that expands small loops so that each iteration of the loop appears in your code. Although loop unrolling increases code size, it can improve the efficiency of your code.
Glossary A-5
Glossary
M
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.
O
object file: An assembled or linked file that contains machine-language object code. object library: An archive library made up of individual object files. 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 assembly 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.
A-6
Glossary
P
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 software-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 performed with program-level optimization that are rarely applied during filelevel 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.
R
redundant loops: Two versions of the same loop, where one is a softwarepipelined 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 symbols 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.
Glossary A-7
Glossary
run-time-support functions: Standard ANSI 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.
S
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 sections starting address, contains the sections size, etc. shell program: A utility that lets you compile, assemble, and optionally link in one step. The shell runs one or more source modules through the compiler (including the parser, optimizer, and code generator), the assembler, and the linker. 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 performs integrated preprocessing, which includes parsing of instructions. stand-alone simulator: A software tool that loads and runs an executable COFF .out file. When used with the C I/O libraries, the standalone simulator 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.
A-8
Glossary
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 software tool to retain symbolic information that can be used by a debugging tool such as a simulator or an emulator.
T
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 initialized 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.
U
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, regardless of its actual sign.
V
variable: A symbol representing a quantity that can assume any of a set of values.
Glossary
A-9
A-10
Index
Index
; in linear assembly source 4-14 #include directive generating list of files included 2-28 @ shell option 2-15 * in linear assembly source 4-14 >> symbol 2-33 al shell option 2-22 alias disambiguation defined A-1 described 3-38 aliasing defined A-1 aliasing techniques 3-25 to 3-27 assigning the address to a global variable 3-25 indicating certain techniques are not used 3-26 to 3-27 returning the address from a function 3-25 align help function 9-72 allocate memory allocate and clear memory function 9-49 allocate memory function 9-72 sections 5-11 allocation defined A-1 alt.h pathname 2-26 ANSI C compatibility with K&R C 7-34 TMS320C6000 C differences from 7-2 defined A-1 standard overview 1-5 ar linker option 5-6 arc cosine functions 9-38 cotangent cartesian functions 9-39 hyperbolic functions 9-40 polar functions 9-39 sine functions 9-43 tangent cartesian functions 9-45 hyperbolic functions 9-46 polar functions 9-45 archive library defined A-1 linking 5-8
A
a linker option 5-6 aa shell option 2-22 abort function 9-37 .abs extension 2-18 abs function 9-37 absolute listing, creating 2-22 absolute value abs/labs functions 9-37 fabs function 9-57 fabsf function 9-57 ac shell option 2-22 acos function 9-38 acosf function 9-38 acosh function 9-38 acoshf function 9-38 acot function 9-39 acot2 function 9-39 acot2f function 9-39 acotf function 9-39 acoth function 9-40 acothf function 9-40 ad shell option 2-22 add_device function 9-40 ahc shell option 2-22 ahi shell option 2-22
Index-1
Index
archiver defined A-1 described 1-3 arguments accessing 8-21 arithmetic operations 8-43 array search function 9-48 sort function 9-80 as shell option 2-22 ASCII string conversion functions 9-47 asctime function 9-43 asin function 9-43 asinf function 9-43 asinh function 9-44 asinhf function 9-44 .asm extension 2-18 asm statement described 7-17 in optimized code 3-28 using 8-38 assembler controlling with compiler shell 2-22 defined A-1 described 1-3 options summary 2-13 assembly language accessing constants 8-40 global variables 8-39 variables 8-39 calling with intrinsics 8-25 code interfacing 8-22 embedding 7-17 including 8-38 interlisting with C code 2-43 interrupt routines 8-42 module interfacing 8-22 retaining output 2-16 assembly listing file creation 2-22 assembly optimizer defined A-1 described 1-3 invoking 4-4 using 4-1 to 4-16 assembly source debugging 2-15 assert function 9-44 Index-2
assert.h header described 9-14 summary of functions 9-26 assignment statement defined A-1 atan function 9-45 atan2 function 9-45 atan2f function 9-45 atanf function 9-45 atanh function 9-46 atanhf function 9-46 atexit function 9-46 atof function 9-47 atoi function 9-47 atol function 9-47 au shell option 2-22 autoinitialization at runtime defined A-2 described 8-50 defined A-2 initialization tables 8-47 of variables 8-6, 8-46 types of 5-10 ax shell option 2-22
B
b option linker 2-14, 5-6 standalone simulator 6-4 banner suppressing 2-17 base-10 logarithm 9-70 base-2 logarithm 9-71 big endian defined A-2 producing 2-16 _BIG_ENDIAN macro 2-24 bit fields 7-4 allocating 8-14 size and type 7-36 block copy functions nonoverlapping memory 9-74 overlapping memory 9-74 defined A-2 memory allocation 5-11 boot.obj 5-8, 5-10
Index
branch optimizations 3-38 bsearch function 9-48 .bss section allocating in memory 5-11 defined A-2 described 8-3 buffer define and associate function specification function 9-84 BUFSIZE macro 9-20 byte defined A-2
9-86
C
.C extension 2-18 .c extension 2-18 c library-build utility option 10-4 c option how shell and linker options differ 5-5 linker 5-2, 5-10 shell 2-15 C++ language characteristics 7-5 C++ name demangler described 1-7, 11-1 example 11-3 to 11-5 invoking 11-2 options 11-2 C/C++ compiler defined A-2 described 1-3 C/C++ language accessing assembler constants 8-40 accessing assembler global variables 8-39 accessing assembler variables 8-39 characteristics 7-2 to 7-4 const keyword 7-7 constants 7-2 to 7-4 conversions 7-3 to 7-4 cregister keyword 7-8 data types 7-3 to 7-4 declarations 7-4 expressions 7-3 to 7-4 far keyword 7-11 to 7-13 identifiers 7-2 to 7-4 interlisting with assembly 2-43 interrupt keyword 7-10 near keyword 7-11 to 7-13
C/C++ language (continued) placing assembler statements in 8-38 pragmas 7-4 pragma directives 7-18 to 7-31 restrict keyword 7-14 volatile keyword 7-15 C_C6X_OPTION 2-23 C_DIR environment variable 2-25, 2-27 C6X_C_DIR environment variable 2-25, 2-27 _c_int00 described 5-10 C_OPTION 2-23 calendar time ctime function 9-53 described 9-23 difftime function 9-53 mktime function 9-76 time function 9-103 calling conventions accessing arguments and local variables 8-21 how a called function responds 8-19 to 8-21 how a function makes a call 8-18 to 8-19 register usage 8-17 calloc function 9-75 described 9-49 dynamic memory allocation 8-5 reversing 9-62 cassert header described 9-14 summary of functions 9-26 cctype header described 9-14 summary of functions 9-26 ceil function 9-49 ceilf function 9-49 ceiling functions 9-49 cerrno header 9-15 cfloat header 9-16 to 9-17 character conversion functions a number of characters 9-101 described 9-14 summary of 9-26 escape sequences in 7-35 find function 9-90 matching functions strpbrk 9-98 strrchr 9-98 strspn 9-99
Index-3
Index
character (continued) read functions multiple characters 9-59 single character 9-58 string constants 8-15 type testing function 9-67 unmatching function 9-92 character sets 7-2 .cinit section allocating in memory 5-11 assembly module use of 8-23 described 8-3 use during autoinitialization 5-10 cl6x command 2-4 clear EOF functions 9-50 clearerr function 9-50 clearerrf function 9-50 climits header 9-16 to 9-17 CLK_TCK macro 9-22 clock function 9-50 clock_t data type 9-22 CLOCKS_PER_SEC macro described 9-23 usage 9-50 close file function 9-57 close I/O function 9-7 cmath header described 9-18 summary of functions 9-27 to 9-29 code generator defined A-2 code size reducing 3-5, 3-17 _CODE_ACCESS macro 9-18 CODE_SECTION pragma 7-19 COFF defined A-2 collapsing epilogs 3-13 speculative execution 3-13 collapsing prologs 3-13 speculative execution 3-13 command file appending to command line 2-15 defined A-2 linker 5-13 comments defined A-2 in linear assembly source code 4-14 linear assembly 4-6 Index-4
compare strings functions any number of characters in entire string 9-90 compatibility with K&R C 7-34
compiler described 2-1 to 2-44 diagnostic messages 2-29 to 2-32 optimizer 3-2 to 3-3 options conventions 2-6 summary 2-7 to 2-22 overview 1-5 to 1-8 sections 5-11 compiling after preprocessing 2-27
compiling C code compile only 2-17 overview, commands, and options with the optimizer 3-2 to 3-3 concatenate strings functions any number of characters 9-95 entire string 9-89 const keyword 7-7 5-11
2-2 to 2-3
constant accessing assembler constants from C 8-40 C language 7-2 character strings 8-15 defined A-3 escape sequences in character constants 7-35 string 7-35 control registers accessing from C/C++, 7-8 control-flow simplification 3-38 2-31 to 2-32
controlling diagnostic messages conventions function calls 8-18 notational, iv register 8-16 conversions 7-3 C language 7-3 described 9-14
Index
convert case function 9-104 long integer to ASCII 9-71 string to number 9-47 time to string function 9-43 to ASCII function 9-104 copy file using ahc shell option copy string function cos function cosf function cosh function coshf function cosine functions cot function 9-52 9-51 9-51 9-51 9-51 9-51 3-36 9-91 2-22
ctime header described 9-22 summary of functions ctype.h header described 9-14 summary of functions
9-36
9-26
D
d option shell 2-15 standalone simulator 6-4 data flow optimizations 3-41 data object representation 8-8 data page pointer (DP) 7-11 data section defined A-3 data types C language 7-3 clock_t 9-22 div_t 9-21 FILE 9-20 fpos_t 9-20 how stored in memory 8-8 jmp_buf 9-19 ldiv_t 9-21 list of 7-6 ptrdiff_t 9-20 size_t 9-20 storage 8-8 struct_tm 9-22 time_t 9-22 va_list 9-19 _DATA_ACCESS macro 9-18 DATA_ALIGN pragma 7-20 DATA_MEM_BANK pragma 7-20 DATA_SECTION pragma 7-22 _ _DATE_ _ macro 2-25 daylight savings time 9-22 deallocate memory function 9-62 debugging generating directives 2-15 optimized code 3-33 declarations in C language 7-4 development flow diagram 1-2 device adding 9-11 functions 9-40 diagnostic identifiers in raw listing file
cost-based register allocation optimization cotangent hyperbolic functions 9-52 polar functions 9-52 cotf function coth function cothf function 9-52 9-52 9-52 5-2, 5-10 7-8
cross-reference listing defined A-3 generating with assembler 2-22 generating with compiler shell 2-33 cross-reference utility 1-4 csetjmp header described 9-19 summary of functions and macros cstdarg header described 9-19 summary of macros
9-30
9-30
cstdio header described 9-20 to 9-21 summary of functions 9-30 to 9-32 cstdlib header described 9-21 summary of functions cstring header described 9-22 summary of functions ctime function 9-53
9-33
9-34
2-35
Index-5
Index
diagnostic messages assert function 9-44 controlling 2-31 described 9-14 description 2-29 to 2-30 errors 2-29 fatal errors 2-29 format 2-29 generating 2-31 to 2-32 other messages 2-33 remarks 2-29 suppressing 2-31 to 2-32 warnings 2-29 difftime function 9-53 direct call defined A-3 directives assembly optimizer 4-16 defined A-3 directories alternate for include files 2-26 for include files 2-16, 2-26 specifying 2-21 div function 9-54 div_t data type 9-21 division 7-3 division functions 9-54 documentation v, vi DP (data page pointer) 7-11 duplicate value in memory function 9-74 DWARF debugging information 2-16 dynamic memory allocation defined A-3 described 8-5
E
e linker option 5-6 ea shell option 2-20 ec shell option 2-20 EDOM macro 9-15 EFPOS macro 9-15 el shell option 2-20 embedded C++ mode 7-36 emulator defined A-3 .endproc directive 4-26 ENOENT macro 9-15 Index-6
entry point defined A-3 environment information function 9-66 environment variable C_DIR 2-25, 2-27 C6X_C_DIR 2-25, 2-27 defined A-3 eo shell option 2-20 EOF macro 9-20 ep shell option 2-20 epilog defined A-3 epilog collapsing 3-13 speculative execution 3-13 EPROM programmer 1-4 ERANGE macro 9-15 errno.h header 9-15 error errno.h header file 9-15 indicators functions 9-50 mapping function 9-77 message macro 9-26 messages See also diagnostic messages handling with options 2-32 preprocessor 2-24 escape sequences 7-2, 7-35 exception handling 9-24 exception include file 9-24 executable module defined A-3 exit functions abort function 9-37 atexit 9-46 exit function 9-55 exp function 9-55 exp10 function 9-56 exp10f function 9-56 exp2 function 9-56 exp2f function 9-56 expf function 9-55 exponential math functions described 9-18 exp function 9-55 exp10 function 9-56 exp10f function 9-56 exp2 function 9-56 exp2f function 9-56 expf function 9-55
Index
expression C language 7-3 defined A-3 simplification 3-41 extensions abs 2-18 asm 2-18 C 2-18 c 2-18 cc 2-18 cpp 2-18 cxx 2-18 nfo 3-19 obj 2-18 s 2-18 sa 2-18, 4-4 specifying 2-20 external declarations 7-35 A-3 external symbol defined
file copy 2-22 include 2-22 removal function 9-82 rename function 9-82 FILE data type 9-20 _ _FILE_ _ macro 2-25 file.h header 9-15 file-level optimization 3-18 defined A-4 filename extension specification 2-19 generate function 9-103 specifying 2-18 FILENAME_MAX macro 9-20 find first occurrence of byte function 9-73 fl shell option 2-19 float.h header 9-16 to 9-17 floating-point math functions 9-18 remainder functions 9-60 summary of functions 9-27 to 9-29 floor function 9-59 floorf function 9-59 flush I/O buffer function 9-58 fmod function 9-60 fmodf function 9-60 fo shell option 2-19 fopen function 9-60 FOPEN_MAX macro 9-20 fpos_t data type 9-20 fprintf function 9-61 fputc function 9-61 fputs function 9-61 fr shell option 2-21 fraction and exponent functions 9-63 fread function 9-62 free function 9-62 freopen function 9-63 frexp function 9-63 frexpf function 9-63 fs shell option 2-21 fscanf function 9-64 fseek function 9-64 fsetpos function 9-64
F
f linker option fa shell option fabs function fabsf function far keyword 5-6 2-19 9-57 7-11 5-11 9-57
.far section allocating in memory described 8-3 _FAR_RTS macro fatal error 2-29 2-21 2-19 9-57 9-57 9-58 2-21 9-58 9-58 9-58 9-59 fb shell option fc shell option fclose function feof function ferror function ff shell option fflush function fgetc function fgets function fgetpos function 9-18
Index-7
Index
ft shell option
2-21
ftell function 9-65 FUNC_CANNOT_INLINE pragma 7-23 FUNC_EXT_CALLED pragma described 7-23 use with pm option 3-22 FUNC_INTERRUPT_THRESHOLD pragma FUNC_IS_PURE pragma 7-25 FUNC_IS_SYSTEM pragma 7-25 FUNC_NEVER_RETURNS pragma 7-26 FUNC_NO_GLOBAL_ASG pragma 7-26 FUNC_NO_IND_ASG pragma 7-27 function alphabetic reference 9-37 call bypassing normal calls 9-19 conventions 8-18 to 8-21 using the stack 8-4 general utility 9-21, 9-33 inline expansion 2-36 to 2-40 inlining defined A-4 prototype effects of pk option 7-34 responsibilities of called function 8-19 responsibilities of calling function 8-18 structure 8-18 fwrite function 9-65
7-24
global variables accessing assembler variables from C autoinitialization 8-46 initializing 7-33 reserved space 8-3 gmtime function 9-67 gp shell option 3-34 Greenwich mean time function 9-67 Gregorian time 9-22 gsm.h header 9-15 gw shell option 2-16
8-39
H
h library-build utility option 10-4, 11-2 h option linker 5-6 standalone simulator 6-4 header files assert.h header 9-14 cassert header 9-14 cctype header 9-14 cerrno header 9-15 cfloat header 9-16 to 9-17 climits header 9-16 to 9-17 cmath header 9-18 csetjmp header 9-19 cstdarg header 9-19 cstdio header 9-20 to 9-21 cstdlib header 9-21 cstring header 9-22 ctime header 9-22 to 9-23 ctype.h header 9-14 errno.h header 9-15 file.h header 9-15 float.h header 9-16 to 9-17 gsm.h header 9-15 limits.h header 9-16 to 9-17 linkage.h header 9-18 list of 9-13 math.h header 9-18 new header 9-24 setjmp.h header 9-19 stdarg.h header 9-19 stddef.h header 9-20 stdio.h header 9-20 to 9-21 stdlib.h header 9-21 string.h header 9-22 time.h header 9-22 to 9-23 typeinfo header 9-24
G
g option linker 5-6 shell 2-15 general-purpose registers 32-bit data 8-9, 8-10, 8-11 double-precision floating-point data halfword 8-9 generating linknames 7-32 generating list of #include files 2-28 get file-position function 9-65 getc function 9-65 getchar function 9-66 getenv function 9-66 gets function 9-66 global symbol defined A-4 Index-8
8-12
Index
heap align function 9-72 described 8-5 reserved space 8-3 heap linker option 5-6 with malloc 9-72 heap size function 9-81 hex conversion utility defined A-4 described 1-4 HUGE_VAL macro 9-18 hyperbolic math functions described 9-18 hyperbolic arc cosine functions 9-38 hyperbolic arc cotangent functions 9-40 hyperbolic arc sine functions 9-44 hyperbolic arc tangent functions 9-46 hyperbolic cosine functions 9-51 hyperbolic cotangent functions 9-52 hyperbolic sine functions 9-87 hyperbolic tangent functions 9-102
#include files adding a directory to be searched specifying a search path 2-25 using ahi shell option 2-22 preprocessor directive 2-25 indirect call defined A-4
2-16
initialization at load time defined A-4 described 8-51 of variables 7-33 at load time 8-6 at runtime 8-6 types 5-10 initialization tables 8-47 5-11
I
i option linker 5-6 shell 2-16, 2-26 I/O adding a device 9-11 described 9-4 functions close 9-7 flush buffer 9-58 lseek 9-7 open 9-8 read 9-9 rename 9-9 unlink 9-10 write 9-10 implementation overview 9-5 low-level definitions 9-15 summary of functions 9-30 to 9-32 _IDECL macro 9-18 7-2 7-2 to 7-4 identifiers in C language
inline assembly language 8-38 declaring functions as 2-38 definition-controlled 2-38 disabling 2-37 inline keyword _INLINE macro 2-38 2-25 2-38
inlining automatic expansion 3-29 function expansion 2-36 unguarded definition-controlled intrinsic operators 2-36 restrictions 2-40
2-37
input file changing default extensions 2-20 changing interpretation of filenames default extensions 2-18 extensions summary 2-8 summary of options 2-8 input/output definitions integer division 9-54 A-4 9-15
2-19
implementation-defined behavior
8-22 to 8-40
Index-9
Index
interlist utility defined A-4 described 1-3 invoking 2-17 invoking with shell program 2-43 used with the optimizer 3-30 interrupt flexibility options 2-41 handling described 8-41 saving registers 7-10 interrupt keyword 7-10 INTERRUPT pragma 7-27 intrinsics inlining operators 2-36 using to call assembly language statements 8-25 inverse tangent of y/x 9-45 invoking C++ name demangler 11-2 library-build utility 10-3 linker 5-2 shell program 2-4 standalone simulator 6-2 isalnum function 9-67 isalpha function 9-67 isascii function 9-67 iscntrl function 9-67 isdigit function 9-67 isgraph function 9-67 islower function 9-67 isprint function 9-67 ispunch function 9-67 isspace function 9-67 isupper function 9-67 isxdigit function 9-67 isxxx function 9-14
K
k shell option 2-16 k library-build utility option 10-4, 11-2 K&R compatibility with ANSI C 7-34 related document, vi K&R C defined A-5 kernel defined A-5 described 3-4 keyword const 7-7 cregister 7-8 far 7-11 to 7-13 inline 2-38 interrupt 7-10 near 7-11 to 7-13 restrict 7-14 volatile 7-15
L
l option library-build utility 10-3 linker 5-2, 5-8 L_tmpnam macro 9-20 label case sensitivity 2-22 defined A-5 retaining 2-22 labs function 9-37 large memory model 2-16, 8-6 _LARGE_MODEL macro 2-24 _LARGE_MODEL_OPTION macro 2-24 ldexp function 9-69 ldiv function 9-54 ldiv_t data type 9-21 libraries run-time support 9-2 to 9-3 library-build utility 10-1 to 10-6 compiler and assembler options 10-5 to 10-6 described 1-4 optional object library 10-3 options 10-4 to 10-6 limits floating-point types 9-17 integer types 9-16
J
j linker option 5-6 jmp_buf data type 9-19 jump function 9-30 jump macro 9-30 jumps (nonlocal) functions Index-10
9-85
Index
limits.h header 9-16 to 9-17 _ _LINE_ _ macro 2-25 linear assembly defined A-5 described 4-1 source comments 4-6 specifying functional units 4-6 writing 4-4 to 4-15 linkage.h header 9-18 linker command file 5-13 controlling 5-8 defined A-5 described 1-3 disabling 5-5 invoking 2-17 invoking individually 5-2 options 5-6 to 5-7 summary of options 2-14 suppressing 2-15 linking C/C++ code 5-1 to 5-14 individually 5-2 object library 9-2 with run-time-support libraries 5-8 with the shell program 5-4 linking C6400 code with C6200/C6700/Older C6400 object code 2-42 linknames generated by the compiler 7-32 listing file creating cross-reference 2-22 defined A-5 generating with preprocessor 2-34 little endian changing to big 2-16 defined A-5 _LITTLE_ENDIAN macro 2-24 lnk6x 5-2 load6x 6-2 loader defined A-5 using with linker 7-33 local time convert broken-down time to local time 9-76 convert calendar to local time 9-53 described 9-23 local variables accessing 8-21
localtime function 9-69 log function 9-70 log10 function 9-70 log10f function 9-70 log2 function 9-71 log2f function 9-71 logf function 9-70 longjmp function 9-19, 9-85 loop rotation optimization 3-44 loop unrolling defined A-5 loop-invariant optimizations 3-44 loops expand compiler knowledge with _nassert optimization 3-43 redundant 3-16 software pipelining 3-4 to 3-15 low-level I/O functions 9-15 lseek I/O function 9-7 ltoa function 9-71
8-35
M
m linker option 5-7 ma shell option 3-25 macro defined A-6 macro call defined A-6 macro defined definition A-6 macro defined expansion A-6 macros _CODE_ACCESS 9-18 _DATA_ACCESS 9-18 _FAR_RTS 9-18 _IDECL 9-18 alphabetic reference 9-37 BUFSIZ 9-20 CLOCKS_PER_SEC 9-23 EOF 9-20 expansions 2-24 to 2-25 FILENAME_MAX 9-20 FOPEN_MAX 9-20 HUGE_VAL 9-18 L_tmpnam 9-20 NASSERT 9-14 NDEBUG 9-14 NULL 9-20 offsetof 9-20 predefined names 2-24 to 2-25
Index-11
Index
macros (continued) SEEK_CUR 9-21 SEEK_END 9-21 SEEK_SET 9-21 setjmp 9-19 stden 9-21 stdin 9-21 stdout 9-21 TMP_MAX 9-21 malloc function 9-75 allocating memory 9-72 dynamic memory allocation reversing 9-62 map file defined A-6 math.h header described 9-18 summary of functions mb shell option .mdep 4-45 me shell option memalign function memchr function memcmp function memcpy function memmove function 2-16 9-72 9-73 9-73 9-74 9-74 4-44 2-42
8-5
9-27 to 9-29
memory model (continued) sections 8-3 small memory model 8-6 stack 8-4 variable initialization 8-6 memory pool malloc function 9-72 reserved space 8-3 memory reference annotating 4-45 default handling by assembly optimizer memset function 9-74 mh shell option 3-14 mi shell option 2-41 minit function 9-75 mk6x 10-3, 11-2 mktime function 9-76 ml shell option 2-16 modf function 9-77 modff function 9-77 modulus 7-3 mr shell option 7-12 ms shell option 3-17 mt shell option 3-26 to 3-27 with assembly optimizer 3-27, 4-44 multibyte characters 7-2 multiply by power of 2 function 9-69 MUST_ITERATE pragma 7-28
4-44
memory bank scheme (interleaved) 4-34 four-bank memory 4-34 with two memory spaces 4-35 memory banks 4-34 9-73 4-44, 4-45 memory compare function memory dependence exceptions 4-44
N
n option linker 5-7 shell 2-17 _nassert intrinsic 8-35 NASSERT macro 9-14 natural logarithm functions 9-70 NDEBUG macro 9-14, 9-44 near keyword 7-11 near position-independent data 8-7 new header 9-24 new_handler type 9-24 .nfo extension 3-19 NMI_INTERRUPT pragma 7-29 .no_mdep 4-44 nonlocal jump function 9-30
memory management functions calloc 9-49 free 9-62 malloc function 9-72 minit 9-75 realloc function 9-81 memory map defined A-6 memory model described 8-2 dynamic memory allocation large memory model 8-6 Index-12
8-5
Index
nonlocal jump functions and macros described 9-85 summary of 9-30 notational conventions iv NULL macro 9-20
O
o option linker 5-7 shell 3-2 standalone simulator 6-4 .obj extension 2-18 object file defined A-6 object library defined A-6 linking code with 9-2 offsetof macro 9-20 oi shell option 3-29 ol shell option 3-18 on shell option 3-19 op shell option 3-21 to 3-23 open file function 9-60, 9-63 open I/O function 9-8 operand defined A-6 optimizations alias disambiguation 3-38 branch 3-38 control-flow simplification 3-38 controlling the level of 3-21 cost based register allocation 3-36 data flow 3-41 expression simplification 3-41 file-level defined A-4 described 3-18 induction variables 3-43 information file options 3-19 inline expansion 3-42 levels 3-2 list of 3-35 to 3-46 loop rotation 3-44 loop-invariant code motion 3-44 program-level defined A-7 described 3-20 register targeting 3-44 register tracking 3-44
optimizations (continued) register variables 3-44 strength reduction 3-43 optimized code debugging 3-33 profiling 3-33 optimizer defined A-6 described 1-3 invoking with shell options 3-2 summary of options 2-12 options assembler 2-22 C++ name demangler 11-2 compiler shell summary 2-7 conventions 2-6 defined A-6 diagnostics 2-11, 2-31 library-build utility 10-4 to 10-6 linker 5-6 to 5-7 preprocessor 2-10, 2-27 to 2-28 standalone simulator 6-4 output file options summary 2-9 module defined A-6 overview of files 1-6 section defined A-6 suppression 2-17
P
packed data optimization concerns parser defined A-7 summary of options 2-10 partitioning defined A-7 pdel shell option 2-31 pden shell option 2-31 pdr shell option 2-31 pds shell option 2-31 pdse shell option 2-31 pdsr shell option 2-31 pdsw shell option 2-31 pdv shell option 2-32 pdw shell option 2-32 pe shell option 7-36 perror function 9-77 pi shell option 2-37 2-42
Index-13
Index
pipelined-loop epilog defined A-7 described 3-4 pipelined-loop prolog defined A-7 described 3-4 pk parser option 7-34, 7-36 placing run-time-support off-chip controlling function calls 7-12 pm shell option pop defined A-7 9-83 8-7 3-20 7-35 pointer combinations
position file indicator function position-independent data pow function powf function powi function powif function 9-78 9-78 9-78 9-78 9-78 2-27 2-28 2-28 2-28 2-28 2-27 7-36 A-7 7-4 power functions
ppa shell option ppc shell option ppd shell option ppi shell option ppl shell option ppo shell option pr shell option pragma defined
#pragma directive
pragma directives 7-18 to 7-31 CODE_SECTION 7-19 DATA_ALIGN 7-20 DATA_MEM_BANK 7-20 DATA_SECTION 7-22 FUNC_CANNOT_INLINE 7-23 FUNC_EXT_CALLED 7-23 FUNC_INTERRUPT_THRESHOLD FUNC_IS_PURE 7-25 FUNC_IS_SYSTEM 7-25 FUNC_NEVER_RETURNS 7-26 FUNC_NO_GLOBAL_ASG 7-26 FUNC_NO_IND_ASG 7-27 INTERRUPT 7-27 MUST_ITERATE 7-28 NMI_INTERRUPT 7-29 PROB_ITERATE 7-29 Index-14
7-24
pragma directives (continued) STRUCT_ALIGN 7-30 UNROLL 7-31 predefined names ad shell option 2-22 undefining with au shell option 2-22 preinitialized variables global and static 7-33 preprocessed listing file generating raw information 2-34 generating with #line directives 2-28 generating with comments 2-28 preprocessor controlling 2-24 to 2-28 defined A-7 directives in C language 7-4 error messages 2-24 _INLINE symbol 2-38 options 2-27 to 2-28 predefining constant names for 2-15 symbols 2-25 prevent reordering of associative floatingpoint operations 3-28 printf function 9-79 PROB_ITERATE pragma 7-29 .proc directive 4-26 processor time function 9-50 profiling optimized code 3-34 program termination functions abort function 9-37 atexit function 9-46 exit function 9-55 program-level optimization controlling 3-21 defined A-7 performing 3-20 progress information suppressing 2-17 prolog defined A-7 prolog collapsing 3-13 speculative execution 3-13 ps shell option 7-36 pseudorandom integer generation functions 9-81 ptrdiff_t 7-3 ptrdiff_t data type 9-20 push defined A-7 putc function 9-79 putchar function 9-79 puts function 9-80
Index
px shell option
2-33
Q
q library-build utility option 10-4 q option linker 5-7 shell 2-17 standalone simulator 6-4 qq shell option 2-17 qsort function 9-80
R
r option linker 5-7 standalone simulator 6-5 raise to a power functions 9-78 rand function 9-81 RAND_MAX macro 9-21 random integer functions 9-81 raw listing file generating with pl option 2-34 identifiers 2-34 read character functions multiple characters 9-59 next character function 9-65, 9-66 single character 9-58 stream functions from standard input 9-84 from string to array 9-62 string 9-64, 9-88 read function 9-66 read I/O function 9-9 realloc function 8-5, 9-75 change heap size 9-81 reversing 9-62 reciprocal square root functions 9-84 reducing code size 3-17 redundant loops defined A-7 described 3-16 .reg directive 4-28 register storage class 7-4
register variables compiling 7-16 conventions 8-16 optimizations 3-44 to 3-46 registers accessing control registers from C/C++, 7-8 allocation 8-16 conventions 8-16 to 8-17 live-in 4-26 live-out 4-26 saving during interrupts 7-10 use in interrupts 8-41 related documentation v, vi relaxed ANSI mode 7-36 relocation defined A-7 remarks 2-29 remove function 9-82 removing epilogs aggressively 3-14 rename function 9-82 rename I/O function 9-9 restrict keyword 7-14 rewind function 9-83 round function 9-83 roundf function 9-83 rounding functions 9-83 rsqrt function 9-84 rsqrtf function 9-84 run-time environment defined A-7 function call conventions 8-18 to 8-21 interfacing C with assembly language 8-22 to 8-40 interrupt handling described 8-41 saving registers 7-10 introduction 8-1 memory model during autoinitialization 8-6 dynamic memory allocation 8-5 sections 8-3 register conventions 8-16 to 8-17 stack 8-4 system initialization 8-45 to 8-52 run-time-support functions defined A-8 introduction 9-1 summary 9-25 to 9-36
Index-15
Index
run-time-support (continued) libraries defined A-8 described 1-4, 9-2 library-build utility 10-1 linking C code 5-2, 5-8 library function inline expansion 3-42 macros summary 9-25 to 9-36 run-time initialization of variables 8-6
S
.s extension 2-18 s option linker 5-7 shell 2-17, 2-43 .sa extension 2-18 SAT bit side effects 8-37 saving registers during interrupts 7-10 scanf function 9-84 searches 9-48 section allocating memory 5-11 .bss 8-3 .cinit 8-3 .const 8-3 defined A-8 described 8-3 .far 8-3 initialized 8-3 .stack 8-3 .switch 8-3 .sysmem 8-3 .text 8-3 uninitialized 8-3 section header defined A-8 sections created by the compiler 5-11 SEEK_CUR macro 9-21 SEEK_END macro 9-21 SEEK_SET macro 9-21 set file-position functions fseek function 9-64 fsetpos function 9-64 set_new_handler function 9-24 setbuf function 9-84 setjmp macro 9-19, 9-85 Index-16
setjmp.h header described 9-19 summary of functions and macros 9-30 setvbuf function 9-86 shell program defined A-8 described 1-3 diagnostic options 2-31 to 2-32 frequently used options 2-15 to 2-18 invoking 2-4 options assembler 2-13 compiler 2-7 input file extension 2-8 input files 2-8 linker 2-14 optimizer 2-12 output files 2-9 parser 2-10 type-checking 2-9 overview 2-2 preprocessor options 2-27 to 2-28 shift 7-3 signed integer and fraction functions 9-77 SIMD using _nassert to enable 8-35 sin function 9-87 sine functions 9-87 sinf function 9-87 sinh function 9-87 sinhf function 9-87 size_t 7-3 size_t data type 9-20 small memory model 8-6 _SMALL_MODEL macro 2-24 software development tools overview 1-2 to 1-4 software pipelining assembly optimizer code 4-4 C code 3-4 defined A-8 description 3-4 to 3-15 disabling 3-5 information 3-5 sort array function 9-80 source file defined A-8 extensions 2-19 specifying functional units in linear assembly 4-6
Index
sprintf function 9-88 sqrt function 9-88 sqrtf function 9-88 square root functions 9-88 srand function 9-81 ss shell option 2-17, 3-30 sscanf function 9-88 stack pointer 8-4 reserved space 8-3 .stack section allocating in memory 5-11 described 8-3 __STACK_SIZE, using 8-4 standalone preprocessor defined A-8 standalone simulator 6-1 to 6-12 defined A-8 invoking 6-2 options 6-4 static variable defined A-8 initializing 7-33 stdarg.h header described 9-19 summary of macros 9-30 _ _STDC_ _ macro 2-25 stddef.h header 9-20 stden macro 9-21 stdexcept include file 9-24 stdin macro 9-21 stdio.h header described 9-20 to 9-21 summary of functions 9-30 to 9-32 stdlib.h header described 9-21 summary of functions 9-33 stdout macro 9-21 storage class defined A-8 store object function 9-58 strcat function 9-89 strchr function 9-90 strcmp function 9-90 strcoll function 9-90 strcpy function 9-91 strcspn function 9-92 strength reduction optimization 3-43
string functions 9-22, 9-34 break into tokens 9-101 compare any number of characters entire string 9-90 conversion 9-100 copy 9-97 length 9-94 matching 9-99 string error 9-92 string.h header described 9-22 summary of functions strlen function strncat function strncmp function strncpy function strpbrk function strrchr function strspn function strstr function strtod function strtok function strtol function strtoul function 9-94 9-95 9-96 9-97 9-98 9-98 9-99 9-99 9-100 9-101 9-100 9-100 7-30 9-22 7-4
9-96
9-34
STRUCT_ALIGN pragma struct_tm data type structure defined structure members strxfrm function STYP_CPY flag A-8 9-101 5-11
suppressing diagnostic messages .switch section allocating in memory described 8-3 symbol defined A-9 2-22 symbol table creating labels defined A-9 5-11
2-31 to 2-32
Index-17
Index
symbolic cross-reference 2-22 debugging defined A-9 generating directives 2-15 symbols assembler-defined 2-22 case sensitivity 2-22 undefining assembler-defined symbols .sysmem section allocating in memory 5-11 described 8-3 _SYSMEM_SIZE 8-5 system initialization described 8-45 initialization tables 8-47 system stack 8-4
2-22
T
t standalone simulator option 6-5 tan function 9-102 tanf function 9-102 tangent functions 9-102 tanh function 9-102 tanhf function 9-102 target system defined A-9 temporary file creation function 9-103 test an expression function 9-44 test EOF function 9-57 test error function 9-58 .text section allocating in memory 5-11 defined A-9 described 8-3 _TI_ENHANCED_MATH_H symbol 9-18 time function 9-103 time functions asctime function 9-43 clock function 9-50 ctime function 9-53 described 9-22 difftime function 9-53 gmtime function 9-67 localtime 9-69 mktime 9-76 strftime function 9-93 Index-18
time functions (continued) summary of 9-36 time function 9-103 _ _TIME_ _ macro 2-25 time.h header described 9-22 to 9-23 summary of functions 9-36 time_t data type 9-22 TMP_MAX macro 9-21 tmpfile function 9-103 tmpnam function 9-103 _TMS320C6200 macro 2-24 _TMS320C6400 macro 2-24 _TMS320C6700 macro 2-24 _TMS320C6X macro 2-24 toascii function 9-104 tokens 9-101 tolower function 9-104 toupper function 9-104 trigonometric math function 9-18 trigraph sequence defined A-9 trip count defined A-9 described 3-16 .trip directive 4-32 trunc function 9-105 truncate functions 9-105 truncf function 9-105 type_info structure 9-24 typeinfo header 9-24
U
u library-build utility option 10-4, 11-2 u option linker 5-7 shell 2-17 undefining a constant 2-17 ungetc function 9-105 unguarded definition-controlled inlining 2-37 uninitialized sections allocating in memory 5-11 defined A-9 list 8-3 unlink I/O function 9-10 UNROLL pragma 7-31
Index
W
w linker option 5-7 warning messages 2-29 wildcards use 2-18 write block of data function write functions fprintf 9-61 fputc 9-61 fputs 9-61 printf 9-79 putc 9-79 putchar 9-79 puts 9-80 sprintf 9-88 ungetc 9-105 vfprintf 9-107 vprintf 9-107 vsprintf 9-108 write I/O function 9-10
V
v library-build utility option va_arg macro va_end macro va_list data type va_start macro 9-19, 9-106 9-19, 9-106 9-19 9-19, 9-106 10-4, 11-2
9-65
variable argument macros described 9-19 summary of 9-30 variable-argument macros, usage 9-106 8-39 variables accessing assembler variables from C accessing local variables 8-21 autoinitialization 8-46 compiling register variables 7-16 defined A-9 initializing global 7-33 static 7-33 vfprintf function volatile keyword vprintf function vsprintf function 9-107 7-15 9-107 9-108
X
x linker option 5-7
Z
z option overriding 5-5 shell 2-4, 2-17, 5-4 standalone simulator 6-5
Index-19
Index-20