SPRUIG8K January   2018  â€“ March 2025

 

  1.   1
  2.   Read This First
    1.     About This Manual
    2.     Notational Conventions
    3.     Related Documentation
    4.     Related Documentation From Texas Instruments
    5.     Trademarks
  3. Introduction to the Software Development Tools
    1. 1.1 Software Development Tools Overview
    2. 1.2 Compiler Interface
    3. 1.3 ANSI/ISO Standard
    4. 1.4 Output Files
  4. Getting Started with the Code Generation Tools
    1. 2.1 How Code Composer Studio Projects Use the Compiler
    2. 2.2 Compiling from the Command Line
  5. Using the C/C++ Compiler
    1. 3.1  About the Compiler
    2. 3.2  Invoking the C/C++ Compiler
    3. 3.3  Changing the Compiler's Behavior with Options
      1. 3.3.1  Linker Options
      2. 3.3.2  Frequently Used Options
      3. 3.3.3  Miscellaneous Useful Options
      4. 3.3.4  Run-Time Model Options
      5. 3.3.5  Selecting Target CPU Version (--silicon_version Option)
      6. 3.3.6  Symbolic Debugging and Profiling Options
      7. 3.3.7  Specifying Filenames
      8. 3.3.8  Changing How the Compiler Interprets Filenames
      9. 3.3.9  Changing How the Compiler Processes C Files
      10. 3.3.10 Changing How the Compiler Interprets and Names Extensions
      11. 3.3.11 Specifying Directories
    4. 3.4  Controlling the Compiler Through Environment Variables
      1. 3.4.1 Setting Default Compiler Options (C7X_C_OPTION)
      2. 3.4.2 Naming One or More Alternate Directories (C7X_C_DIR)
    5. 3.5  Controlling the Preprocessor
      1. 3.5.1  Predefined Macro Names
      2. 3.5.2  The Search Path for #include Files
        1. 3.5.2.1 Adding a Directory to the #include File Search Path (--include_path Option)
      3. 3.5.3  Support for the #warning and #warn Directives
      4. 3.5.4  Generating a Preprocessed Listing File (--preproc_only Option)
      5. 3.5.5  Continuing Compilation After Preprocessing (--preproc_with_compile Option)
      6. 3.5.6  Generating a Preprocessed Listing File with Comments (--preproc_with_comment Option)
      7. 3.5.7  Generating Preprocessed Listing with Line-Control Details (--preproc_with_line Option)
      8. 3.5.8  Generating Preprocessed Output for a Make Utility (--preproc_dependency Option)
      9. 3.5.9  Generating a List of Files Included with #include (--preproc_includes Option)
      10. 3.5.10 Generating a List of Macros in a File (--preproc_macros Option)
    6. 3.6  Passing Arguments to main()
    7. 3.7  Understanding Diagnostic Messages
      1. 3.7.1 Controlling Diagnostic Messages
      2. 3.7.2 How You Can Use Diagnostic Suppression Options
    8. 3.8  Other Messages
    9. 3.9  Generating a Raw Listing File (--gen_preprocessor_listing Option)
    10. 3.10 Using Inline Function Expansion
      1. 3.10.1 Inlining Intrinsic Operators
      2. 3.10.2 Inlining Restrictions
      3. 3.10.3 Unguarded Definition-Controlled Inlining
        1. 3.10.3.1 Using the Inline Keyword
      4. 3.10.4 Guarded Inlining and the _INLINE Preprocessor Symbol
        1. 3.10.4.1 Header File string.h
        2. 3.10.4.2 Library Definition File
    11. 3.11 Using Interlist
    12. 3.12 About the Application Binary Interface
    13. 3.13 Enabling Entry Hook and Exit Hook Functions
  6. Optimizing Your Code
    1. 4.1  Invoking Optimization
    2. 4.2  Controlling Code Size Versus Speed
    3. 4.3  Performing File-Level Optimization (--opt_level=3 option)
      1. 4.3.1 Creating an Optimization Information File (--gen_opt_info Option)
    4. 4.4  Program-Level Optimization (--program_level_compile and --opt_level=3 options)
      1. 4.4.1 Controlling Program-Level Optimization (--call_assumptions Option)
    5. 4.5  Automatic Inline Expansion (--auto_inline Option)
    6. 4.6  Link-Time Optimization (--opt_level=4 Option)
      1. 4.6.1 Option Handling
      2. 4.6.2 Incompatible Types
    7. 4.7  Optimizing Software Pipelining
      1. 4.7.1 Turn Off Software Pipelining (--disable_software_pipeline Option)
      2. 4.7.2 Software Pipelining Information
        1. 4.7.2.1 Software Pipelining Information
        2. 4.7.2.2 Software Pipelining Information Terms
        3. 4.7.2.3 Loop Disqualified for Software Pipelining Messages
        4. 4.7.2.4 Pipeline Failure Messages
        5. 4.7.2.5 Register Usage Table Generated by the --debug_software_pipeline Option
      3. 4.7.3 Collapsing Prologs and Epilogs for Improved Performance and Code Size
        1. 4.7.3.1 Speculative Execution
    8. 4.8  Redundant Loops
    9. 4.9  Indicating Whether Certain Aliasing Techniques Are Used
      1. 4.9.1 Use the --aliased_variables Option When Certain Aliases are Used
    10. 4.10 Prevent Reordering of Associative Floating-Point Operations
    11. 4.11 Using Performance Advice to Optimize Code
      1. 4.11.1 Advice #35000: Use restrict to improve loop performance
    12. 4.12 Using the Interlist Feature With Optimization
    13. 4.13 Debugging and Profiling Optimized Code
      1. 4.13.1 Profiling Optimized Code
    14. 4.14 What Kind of Optimization Is Being Performed?
      1. 4.14.1  Cost-Based Register Allocation
      2. 4.14.2  Alias Disambiguation
      3. 4.14.3  Branch Optimizations and Control-Flow Simplification
      4. 4.14.4  Data Flow Optimizations
      5. 4.14.5  Expression Simplification
      6. 4.14.6  Inline Expansion of Functions
      7. 4.14.7  Function Symbol Aliasing
      8. 4.14.8  Induction Variables and Strength Reduction
      9. 4.14.9  Loop-Invariant Code Motion
      10. 4.14.10 Loop Rotation
      11. 4.14.11 Loop Collapsing and Loop Coalescing
      12. 4.14.12 Unroll-and-jam
      13. 4.14.13 Vectorization (SIMD)
      14. 4.14.14 Instruction Scheduling
      15. 4.14.15 Register Variables
      16. 4.14.16 Register Tracking/Targeting
      17. 4.14.17 Software Pipelining
    15. 4.15 Streaming Engine and Streaming Address Generator
      1. 4.15.1 Streaming Engine Overview
      2. 4.15.2 Theory of Operation for Streaming Engines and Streaming Address Generators
      3. 4.15.3 Streaming Address Generator Overview
      4. 4.15.4 Advantages of Using Streaming Engines and Streaming Address Generators
      5. 4.15.5 Interface for Streaming Engine and Streaming Address Generator
      6. 4.15.6 Parameter Template Configuration
      7. 4.15.7 Using the Streaming Engine
        1. 4.15.7.1 Hard-Coded Intrinsic Operands with the Streaming Engine
      8. 4.15.8 Using the Streaming Address Generator
        1. 4.15.8.1 Vector Predication for Streaming Address Generators
        2. 4.15.8.2 Predicated vs. Unpredicated Streaming Address Stores and Loads
      9. 4.15.9 Automatic Use of Streaming Engine and Streaming Address Generator (--auto_stream Option)
        1. 4.15.9.1 Correctness of Automatic Use of SE and SA
        2. 4.15.9.2 Tuning Automatic Use of SE and SA
    16. 4.16 Nested Loop Controller (NLC)
      1. 4.16.1 Obstacles That May Inhibit Use of NLC
  7. C/C++ Language Implementation
    1. 5.1  Characteristics of C7000 C
      1. 5.1.1 Implementation-Defined Behavior
    2. 5.2  Characteristics of C7000 C++
    3. 5.3  Data Types
      1. 5.3.1 Size of Enum Types
      2. 5.3.2 Vector Data Types
    4. 5.4  File Encodings and Character Sets
    5. 5.5  Keywords
      1. 5.5.1 The complex Keyword
      2. 5.5.2 The const Keyword
      3. 5.5.3 The __cregister Keyword
        1. 5.5.3.1 Define and Use Control Registers
        2. 5.5.3.2 Evaluating Flags in the Flag Status Register (FSR) After Floating Point Operations
      4. 5.5.4 The restrict Keyword
      5. 5.5.5 The volatile Keyword
    6. 5.6  C++ Exception Handling
    7. 5.7  Register Variables and Parameters
    8. 5.8  Pragma Directives
      1. 5.8.1  The CALLS Pragma
      2. 5.8.2  The CLINK Pragma
      3. 5.8.3  The COALESCE_LOOP Pragma
      4. 5.8.4  The CODE_ALIGN Pragma
      5. 5.8.5  The CODE_SECTION Pragma
      6. 5.8.6  The DATA_ALIGN Pragma
      7. 5.8.7  The DATA_MEM_BANK Pragma
        1. 5.8.7.1 Using the DATA_MEM_BANK Pragma
      8. 5.8.8  The DATA_SECTION Pragma
        1. 5.8.8.1 Using the DATA_SECTION Pragma C Source File
        2. 5.8.8.2 Using the DATA_SECTION Pragma C++ Source File
      9. 5.8.9  The Diagnostic Message Pragmas
      10. 5.8.10 The FORCEINLINE Pragma
      11. 5.8.11 The FORCEINLINE_RECURSIVE Pragma
      12. 5.8.12 The FUNC_ALWAYS_INLINE Pragma
      13. 5.8.13 The FUNC_CANNOT_INLINE Pragma
      14. 5.8.14 The FUNC_EXT_CALLED Pragma
      15. 5.8.15 The FUNC_IS_PURE Pragma
      16. 5.8.16 The FUNC_IS_SYSTEM Pragma
      17. 5.8.17 The FUNC_NEVER_RETURNS Pragma
      18. 5.8.18 The FUNC_NO_GLOBAL_ASG Pragma
      19. 5.8.19 The FUNC_NO_IND_ASG Pragma
      20. 5.8.20 The FUNCTION_OPTIONS Pragma
      21. 5.8.21 The INTERRUPT Pragma
      22. 5.8.22 The LOCATION Pragma
      23. 5.8.23 The MUST_ITERATE Pragma
        1. 5.8.23.1 The MUST_ITERATE Pragma Syntax
        2. 5.8.23.2 Using MUST_ITERATE to Expand Compiler Knowledge of Loops
      24. 5.8.24 The NOINIT and PERSISTENT Pragmas
      25. 5.8.25 The NOINLINE Pragma
      26. 5.8.26 The NO_COALESCE_LOOP Pragma
      27. 5.8.27 The NO_HOOKS Pragma
      28. 5.8.28 The once Pragma
      29. 5.8.29 The pack Pragma
      30. 5.8.30 The PROB_ITERATE Pragma
      31. 5.8.31 The RETAIN Pragma
      32. 5.8.32 The SET_CODE_SECTION and SET_DATA_SECTION Pragmas
      33. 5.8.33 The STRUCT_ALIGN Pragma
      34. 5.8.34 The UNROLL Pragma
      35. 5.8.35 The WEAK Pragma
    9. 5.9  The _Pragma Operator
    10. 5.10 Application Binary Interface
    11. 5.11 Object File Symbol Naming Conventions (Linknames)
    12. 5.12 Changing the ANSI/ISO C/C++ Language Mode
      1. 5.12.1 C99 Support (--c99)
      2. 5.12.2 C11 Support (--c11)
      3. 5.12.3 Strict ANSI Mode and Relaxed ANSI Mode (--strict_ansi and --relaxed_ansi)
    13. 5.13 GNU and Clang Language Extensions
      1. 5.13.1 Extensions
      2. 5.13.2 Function Attributes
      3. 5.13.3 For Loop Attributes
      4. 5.13.4 Variable Attributes
      5. 5.13.5 Type Attributes
      6. 5.13.6 Built-In Functions
    14. 5.14 Operations and Functions for Vector Data Types
      1. 5.14.1 Vector Literals and Concatenation
      2. 5.14.2 Unary and Binary Operators for Vectors
        1. 5.14.2.1 Semantics of Vector Pointers
      3. 5.14.3 Ternary Operators for Vectors (?:)
      4. 5.14.4 Swizzle Operators for Vectors
      5. 5.14.5 Unsupported Vector Comparison Operators
      6. 5.14.6 Conversion Functions for Vectors
      7. 5.14.7 Re-Interpretation Functions for Vectors
      8. 5.14.8 Vector Predicate Type
        1. 5.14.8.1 Constructing a Vector Predicate Type
        2. 5.14.8.2 Using a Vector Predicate Type
        3. 5.14.8.3 Boolean Vector Types
    15. 5.15 C7000 Intrinsics
      1. 5.15.1 High-Level Overloaded Intrinsics
      2. 5.15.2 Intrinsics Defined for Special Load and Store Instructions
      3. 5.15.3 Direct-Mapped Intrinsics
      4. 5.15.4 Lookup Table and Histogram Intrinsics
      5. 5.15.5 Matrix-Multiply Accelerator (MMA) Intrinsics
      6. 5.15.6 Legacy Intrinsics
    16. 5.16 C7000 Scalable Vector Programming
  8. Run-Time Environment
    1. 6.1 Memory
      1. 6.1.1 Sections
      2. 6.1.2 C/C++ System Stack
      3. 6.1.3 Dynamic Memory Allocation
    2. 6.2 Object Representation
      1. 6.2.1 Data Type Storage
        1. 6.2.1.1 char and short Data Types (signed and unsigned)
        2. 6.2.1.2 enum, int, and long Data Types (signed and unsigned)
        3. 6.2.1.3 long Data Types (signed and unsigned)
        4. 6.2.1.4 float Data Type
        5. 6.2.1.5 double and long double Data Types
        6. 6.2.1.6 Pointer to Data Member Types
        7. 6.2.1.7 Pointer to Member Function Types
        8. 6.2.1.8 Structures and Arrays
      2. 6.2.2 Bit Fields
      3. 6.2.3 Character String Constants
    3. 6.3 Register Conventions
    4. 6.4 Function Structure and Calling Conventions
      1. 6.4.1 How a Function Makes a Call
      2. 6.4.2 How a Called Function Responds
      3. 6.4.3 Accessing Arguments and Local Variables
    5. 6.5 Accessing Linker Symbols in C and C++
    6. 6.6 Run-Time-Support Arithmetic Routines
    7. 6.7 System Initialization
      1. 6.7.1 Boot Hook Functions for System Pre-Initialization
      2. 6.7.2 Automatic Initialization of Variables
        1. 6.7.2.1 Zero Initializing Variables
        2. 6.7.2.2 Direct Initialization
        3. 6.7.2.3 Autoinitialization of Variables at Run Time
        4. 6.7.2.4 Autoinitialization Tables
          1. 6.7.2.4.1 Length Followed by Data Format
          2. 6.7.2.4.2 Zero Initialization Format
          3. 6.7.2.4.3 Run Length Encoded (RLE) Format
          4. 6.7.2.4.4 Lempel-Ziv-Storer-Szymanski Compression (LZSS) Format
        5. 6.7.2.5 Initialization of Variables at Load Time
        6. 6.7.2.6 Global Constructors
  9. Using Run-Time-Support Functions and Building Libraries
    1. 7.1 C and C++ Run-Time Support Libraries
      1. 7.1.1 Linking Code With the Object Library
      2. 7.1.2 Header Files
      3. 7.1.3 Modifying a Library Function
      4. 7.1.4 Support for String Handling
      5. 7.1.5 Minimal Support for Internationalization
      6. 7.1.6 Support for Time and Clock Functions
      7. 7.1.7 Allowable Number of Open Files
      8. 7.1.8 Library Naming Conventions
    2. 7.2 The C I/O Functions
      1. 7.2.1 High-Level I/O Functions
        1. 7.2.1.1 Formatting and the Format Conversion Buffer
      2. 7.2.2 Overview of Low-Level I/O Implementation
        1.       open
        2.       close
        3.       read
        4.       write
        5.       lseek
        6.       unlink
        7.       rename
      3. 7.2.3 Device-Driver Level I/O Functions
        1.       DEV_open
        2.       DEV_close
        3.       DEV_read
        4.       DEV_write
        5.       DEV_lseek
        6.       DEV_unlink
        7.       DEV_rename
      4. 7.2.4 Adding a User-Defined Device Driver for C I/O
        1. 7.2.4.1 Mapping Default Streams to Device
      5. 7.2.5 The device Prefix
        1.       add_device
        2.       292
        3. 7.2.5.1 Program for C I/O Device
    3. 7.3 Handling Reentrancy (_register_lock() and _register_unlock() Functions)
    4. 7.4 Library-Build Process
      1. 7.4.1 Required Non-Texas Instruments Software
      2. 7.4.2 Using the Library-Build Process
        1. 7.4.2.1 Automatic Standard Library Rebuilding by the Linker
        2. 7.4.2.2 Invoking mklib Manually
          1. 7.4.2.2.1 Building Standard Libraries
          2. 7.4.2.2.2 Shared or Read-Only Library Directory
          3. 7.4.2.2.3 Building Libraries With Custom Options
          4. 7.4.2.2.4 The mklib Program Option Summary
      3. 7.4.3 Extending mklib
        1. 7.4.3.1 Underlying Mechanism
        2. 7.4.3.2 Libraries From Other Vendors
  10. Introduction to Object Modules
    1. 8.1 Object File Format Specifications
    2. 8.2 Executable Object Files
    3. 8.3 Introduction to Sections
      1. 8.3.1 Special Section Names
    4. 8.4 How the Linker Handles Sections
      1. 8.4.1 Combining Input Sections
      2. 8.4.2 Placing Sections
    5. 8.5 Symbols
      1. 8.5.1 Local Symbols
      2. 8.5.2 Weak Symbols
    6. 8.6 Loading a Program
  11. Program Loading and Running
    1. 9.1 Loading
    2. 9.2 Entry Point
    3. 9.3 Run-Time Initialization
      1. 9.3.1 The _c_int00 Function
      2. 9.3.2 RAM Model vs. ROM Model
        1. 9.3.2.1 Autoinitializing Variables at Run Time (--rom_model)
        2. 9.3.2.2 Initializing Variables at Load Time (--ram_model)
        3. 9.3.2.3 The --rom_model and --ram_model Linker Options
      3. 9.3.3 About Linker-Generated Copy Tables
        1. 9.3.3.1 BINIT
        2. 9.3.3.2 CINIT
    4. 9.4 Arguments to main
    5. 9.5 Run-Time Relocation
    6. 9.6 Additional Information
  12. 10Archiver Description
    1. 10.1 Archiver Overview
    2. 10.2 The Archiver's Role in the Software Development Flow
    3. 10.3 Invoking the Archiver
    4. 10.4 Archiver Examples
    5. 10.5 Library Information Archiver Description
      1. 10.5.1 Invoking the Library Information Archiver
      2. 10.5.2 Library Information Archiver Example
      3. 10.5.3 Listing the Contents of an Index Library
      4. 10.5.4 Requirements
  13. 11Linking C/C++ Code
    1. 11.1 Invoking the Linker Through the Compiler (-z Option)
      1. 11.1.1 Invoking the Linker Separately
      2. 11.1.2 Invoking the Linker as Part of the Compile Step
      3. 11.1.3 Disabling the Linker (--compile_only Compiler Option)
    2. 11.2 Linker Code Optimizations
      1. 11.2.1 Conditional Linking
      2. 11.2.2 Generating Function Subsections (--gen_func_subsections Compiler Option)
      3. 11.2.3 Generating Aggregate Data Subsections (--gen_data_subsections Compiler Option)
    3. 11.3 Controlling the Linking Process
      1. 11.3.1 Including the Run-Time-Support Library
        1. 11.3.1.1 Automatic Run-Time-Support Library Selection
          1. 11.3.1.1.1 Using the --issue_remarks Option
        2. 11.3.1.2 Manual Run-Time-Support Library Selection
        3. 11.3.1.3 Library Order for Searching for Symbols
      2. 11.3.2 Run-Time Initialization
      3. 11.3.3 Global Object Constructors
      4. 11.3.4 Specifying the Type of Global Variable Initialization
      5. 11.3.5 Specifying Where to Allocate Sections in Memory
      6. 11.3.6 A Sample Linker Command File
  14. 12Linker Description
    1. 12.1  Linker Overview
    2. 12.2  The Linker's Role in the Software Development Flow
    3. 12.3  Invoking the Linker
    4. 12.4  Linker Options
      1. 12.4.1  Wildcards in File, Section, and Symbol Patterns
      2. 12.4.2  Specifying C/C++ Symbols with Linker Options
      3. 12.4.3  Relocation Capabilities (--absolute_exe and --relocatable Options)
        1. 12.4.3.1 Producing an Absolute Output Module (--absolute_exe option)
        2. 12.4.3.2 Producing a Relocatable Output Module (--relocatable option)
      4. 12.4.4  Allocate Memory for Use by the Loader to Pass Arguments (--arg_size Option)
      5. 12.4.5  Compression (--cinit_compression and --copy_compression Option)
      6. 12.4.6  Compress DWARF Information (--compress_dwarf Option)
      7. 12.4.7  Control Linker Diagnostics
      8. 12.4.8  Automatic Library Selection (--disable_auto_rts Option)
      9. 12.4.9  Do Not Remove Unused Sections (--unused_section_elimination Option)
      10. 12.4.10 Linker Command File Preprocessing (--disable_pp, --define and --undefine Options)
      11. 12.4.11 Define an Entry Point (--entry_point Option)
      12. 12.4.12 Set Default Fill Value (--fill_value Option)
      13. 12.4.13 Define Heap Size (--heap_size Option)
      14. 12.4.14 Hiding Symbols
      15. 12.4.15 Alter the Library Search Algorithm (--library, --search_path, and C7X_C_DIR )
        1. 12.4.15.1 Name an Alternate Library Directory (--search_path Option)
        2. 12.4.15.2 Name an Alternate Library Directory ( C7X_C_DIR Environment Variable)
        3. 12.4.15.3 Exhaustively Read and Search Libraries (--reread_libs and --priority Options)
      16. 12.4.16 Change Symbol Localization
        1. 12.4.16.1 Make All Global Symbols Static (--make_static Option)
      17. 12.4.17 Create a Map File (--map_file Option)
      18. 12.4.18 Manage Map File Contents (--mapfile_contents Option)
      19. 12.4.19 Disable Name Demangling (--no_demangle)
      20. 12.4.20 Merging of Symbolic Debugging Information
      21. 12.4.21 Strip Symbolic Information (--no_symtable Option)
      22. 12.4.22 Name an Output Module (--output_file Option)
      23. 12.4.23 Prioritizing Function Placement (--preferred_order Option)
      24. 12.4.24 C Language Options (--ram_model and --rom_model Options)
      25. 12.4.25 Retain Discarded Sections (--retain Option)
      26. 12.4.26 Scan All Libraries for Duplicate Symbol Definitions (--scan_libraries)
      27. 12.4.27 Define Stack Size (--stack_size Option)
      28. 12.4.28 Mapping of Symbols (--symbol_map Option)
      29. 12.4.29 Generate Far Call Trampolines (--trampolines Option)
        1. 12.4.29.1 Advantages and Disadvantages of Using Trampolines
        2. 12.4.29.2 Minimizing the Number of Trampolines Required (--minimize_trampolines Option)
        3. 12.4.29.3 Carrying Trampolines From Load Space to Run Space
      30. 12.4.30 Introduce an Unresolved Symbol (--undef_sym Option)
      31. 12.4.31 Display a Message When an Undefined Output Section Is Created (--warn_sections)
      32. 12.4.32 Generate XML Link Information File (--xml_link_info Option)
      33. 12.4.33 Zero Initialization (--zero_init Option)
    5. 12.5  Linker Command Files
      1. 12.5.1  Reserved Names in Linker Command Files
      2. 12.5.2  Constants in Linker Command Files
      3. 12.5.3  Accessing Files and Libraries from a Linker Command File
      4. 12.5.4  The MEMORY Directive
        1. 12.5.4.1 Default Memory Model
        2. 12.5.4.2 MEMORY Directive Syntax
        3. 12.5.4.3 Expressions and Address Operators
      5. 12.5.5  The SECTIONS Directive
        1. 12.5.5.1 SECTIONS Directive Syntax
        2. 12.5.5.2 Section Allocation and Placement
          1. 12.5.5.2.1 Binding
          2. 12.5.5.2.2 Named Memory
          3. 12.5.5.2.3 Controlling Placement Using The HIGH Location Specifier
            1. 12.5.5.2.3.1 Linker Placement With the HIGH Specifier
            2.         426
            3. 12.5.5.2.3.2 Linker Placement Without HIGH Specifier
          4. 12.5.5.2.4 Alignment and Blocking
          5. 12.5.5.2.5 Alignment With Padding
        3. 12.5.5.3 Specifying Input Sections
          1. 12.5.5.3.1 The Most Common Method of Specifying Section Contents
          2.        432
        4. 12.5.5.4 Using Multi-Level Subsections
        5. 12.5.5.5 Specifying Library or Archive Members as Input to Output Sections
          1. 12.5.5.5.1 Archive Members to Output Sections
          2.        436
        6. 12.5.5.6 Allocation Using Multiple Memory Ranges
        7. 12.5.5.7 Automatic Splitting of Output Sections Among Non-Contiguous Memory Ranges
      6. 12.5.6  Placing a Section at Different Load and Run Addresses
        1. 12.5.6.1 Specifying Load and Run Addresses
        2.       441
      7. 12.5.7  Using GROUP and UNION Statements
        1. 12.5.7.1 Grouping Output Sections Together
        2. 12.5.7.2 Overlaying Sections With the UNION Statement
        3. 12.5.7.3 Using Memory for Multiple Purposes
        4. 12.5.7.4 Nesting UNIONs and GROUPs
        5. 12.5.7.5 Checking the Consistency of Allocators
        6. 12.5.7.6 Naming UNIONs and GROUPs
      8. 12.5.8  Special Section Types (DSECT, COPY, NOLOAD, and NOINIT)
      9. 12.5.9  Assigning Symbols at Link Time
        1. 12.5.9.1 Syntax of Assignment Statements
        2. 12.5.9.2 Assigning the SPC to a Symbol
        3. 12.5.9.3 Assignment Expressions
        4. 12.5.9.4 Symbols Automatically Defined by the Linker
        5. 12.5.9.5 Assigning Exact Start, End, and Size Values of a Section to a Symbol
        6. 12.5.9.6 Why the Dot Operator Does Not Always Work
        7. 12.5.9.7 Address and Dimension Operators
          1. 12.5.9.7.1 Input Items
          2. 12.5.9.7.2 Output Section
          3. 12.5.9.7.3 GROUPs
          4. 12.5.9.7.4 UNIONs
        8. 12.5.9.8 LAST Operator
      10. 12.5.10 Creating and Filling Holes
        1. 12.5.10.1 Initialized and Uninitialized Sections
        2. 12.5.10.2 Creating Holes
        3. 12.5.10.3 Filling Holes
        4. 12.5.10.4 Explicit Initialization of Uninitialized Sections
    6. 12.6  Linker Symbols
      1. 12.6.1 Linker-Defined Functions and Arrays
      2. 12.6.2 Linker-Defined Integer Values
      3. 12.6.3 Linker-Defined Addresses
      4. 12.6.4 More About the _symval Operator
      5. 12.6.5 Using _symval, PC-Relative Addressing, and Far Data
      6. 12.6.6 Weak Symbols
        1. 12.6.6.1 Weak Symbol References
        2. 12.6.6.2 Weak Symbol Definitions
      7. 12.6.7 Resolving Symbols with Object Libraries
    7. 12.7  Default Placement Algorithm
      1. 12.7.1 How the Allocation Algorithm Creates Output Sections
      2. 12.7.2 Reducing Memory Fragmentation
    8. 12.8  Using Linker-Generated Copy Tables
      1. 12.8.1 Using Copy Tables for Boot Loading
      2. 12.8.2 Using Built-in Link Operators in Copy Tables
      3. 12.8.3 Overlay Management Example
      4. 12.8.4 Generating Copy Tables With the table() Operator
        1. 12.8.4.1 The table() Operator
        2. 12.8.4.2 Boot-Time Copy Tables
        3. 12.8.4.3 Using the table() Operator to Manage Object Components
        4. 12.8.4.4 Linker-Generated Copy Table Sections and Symbols
        5. 12.8.4.5 Splitting Object Components and Overlay Management
      5. 12.8.5 Compression
        1. 12.8.5.1 Compressed Copy Table Format
        2. 12.8.5.2 Compressed Section Representation in the Object File
        3. 12.8.5.3 Compressed Data Layout
        4. 12.8.5.4 Run-Time Decompression
        5. 12.8.5.5 Compression Algorithms
        6.       497
      6. 12.8.6 Copy Table Contents
      7. 12.8.7 General Purpose Copy Routine
    9. 12.9  Partial (Incremental) Linking
    10. 12.10 Linking C/C++ Code
      1. 12.10.1 Run-Time Initialization
      2. 12.10.2 Object Libraries and Run-Time Support
      3. 12.10.3 Setting the Size of the Stack and Heap Sections
      4. 12.10.4 Initializing and AutoInitialzing Variables at Run Time
      5. 12.10.5 Constraints Due to CMMU Configuration
    11. 12.11 Linker Example
  15. 13Object File Utilities
    1. 13.1 Invoking the Object File Display Utility
    2. 13.2 Invoking the Disassembler
    3. 13.3 Invoking the Name Utility
    4. 13.4 Invoking the Strip Utility
  16. 14C++ Name Demangler
    1. 14.1 Invoking the C++ Name Demangler
    2. 14.2 Sample Usage of the C++ Name Demangler
  17.   A XML Link Information File Description
    1.     A.1 XML Information File Element Types
    2.     A.2 Document Elements
      1.      A.2.1 Header Elements
      2.      A.2.2 Input File List
      3.      A.2.3 Object Component List
      4.      A.2.4 Logical Group List
      5.      A.2.5 Placement Map
      6.      A.2.6 Far Call Trampoline List
      7.      A.2.7 Symbol Table
  18.   B Unsupported Tools and Features
    1.     B.1 List of Unsupported Tools and Features
  19.   C Glossary
    1.     529
  20.   D Revision History

Semantics of Vector Pointers

Vector data object: If you use the unary & operator to take the address of a vector data object, the result is a pointer. Unlike taking the address of an array, taking the address of a vector gives you a pointer representing the whole vector, not a pointer to an individual element.

For example, given an object vec of type int4, the expression &vec has type int4 *.

int4 vec;
randomize(&vec); /* OK */

To access the elements of a pointer vector object, use swizzle operators instead of trying to cast the pointer as some other pointer type. See Section 5.14.4.

void randomize(int4 *vecp)
{
    for([..]) (*vecp).s[i] = rand();
}

Complex data object: Similarly, if you use the unary & operator to take the address of a complex scalar object, the result is a pointer. This pointer represents the entire complex scalar object, not an individual component.

cfloat cplx;
foo(&cplx); /* OK */

Vector data element: You can use the unary & operator to take the address of an indexing-style swizzle (for example, &x.s[1] or x.s[j]). The address is a pointer to that element, with the expected semantics. However, you cannot use the unary & operator to take the address of a non-indexing-style swizzle, such as s1, s1(), or r().

Types with the const qualifier: You can declare vector types and complex types with the const type qualifier. The semantics are the same as for non-vector types. Using the unary & operator to take the address of a const vector object gives a pointer to a const-qualified vector type.

Types with the volatile qualifier: You can declare vector types and complex types with the volatile type qualifier. The semantics are the same as for non-vector types. Using the unary & operator to take the address of a volatile vector object gives a pointer to a volatile-qualified vector type.

When optimizing access to any volatile object, the compiler must preserve the number and relative order in which accesses occur at runtime. If possible, the compiler accesses a volatile vector object whole-vector-at-a-time, not element-by-element. If that is not possible (for instance, because a vector is larger than a single vector register), the compiler can split the volatile access into smaller chunks, and the order in which these smaller chunks are accessed is unspecified.

Consider these loops. The first loop is the original, and the second loop is the vectorized version:


volatile int *p = array;                    /* original loop */
for ([..])
    *p++ = [..]                             /* process one int at a time in sequence */

volatile int8 *p8 = (volatile int8 *)array; /* vectorized loop */
for ([..])
    *p8++ = [..]                            /* process 8 int at a time in parallel */

The first loop in this example accesses one array element at a time in sequence. The second loop accesses 8 ints in parallel. Because the second loop changes the relative order of accesses, the compiler is not allowed to automatically convert the first loop to the second. You can manually make a change from one style of access to the other if that change is warranted.

Pointers with the restrict qualifier: You can add the restrict qualifier to a pointer to a vector type if the pointer follows the usual rules for the restrict keyword. Simply stated, the pointer to the vector must be the only way that the vector the pointer points to is accessed.

Correspondence between vectors and arrays: The most effective use of vectors is to process a large array of data with vectors that are as large as possible. Because vectors and arrays are so similar, you can easily use vector pointers to access large arrays. For example:

int array[N];
int8 vec = *(int8 *)array; /* vector to access first 8 ints in array */

One important use of vectors is to access an array by casting the address of the array (or a pointer) as a pointer-to-vector type. That pointer can then be used to load or store multiple elements of the array in parallel. Suppose you have the following example:

void dotp(int x[N], int y[N], int z[restrict])
{
    /* original */
    for (int i=0;i<N;i++)
    {
        /* process the data one int at a time */
        *z++ = *x++ + *y++;
    }
}

The compiler can automatically transform this simple example because the restrict keyword tells the compiler that the z input parameter does not overlap with either x or y.

void dotp(int x[N], int y[N], int z[restrict])
{
    int8 *xp = (int8 *)x;
    int8 *yp = (int8 *)y;
    int8 *zp = (int8 *)z;
    for (int i=0;i<N/8;i++)
    {
        /* process the data 8 ints at a time */
        *zp++ = *xp++ + *yp++;
    }
}
Note: When using a pointer to a vector to read from a non-complex array, match the element type of the vector to the element type of the non-complex array. For example, if an array type is const int array[N], make the vector a const with int elements, like const int8.

Using a pointer-to-vector to access an array is safe because elements of both arrays and vectors are stored and aligned the same way when stored in memory. In memory, a vector's first element (s0) is stored at the lowest address in memory, regardless of endian mode. The individual bytes of each element are stored according to the endianness mode. The first element of the array is then assigned to the vector's first element (s0).

When using C++, you can use similar code to process multiple elements of a std::vector or std::array in parallel using the data() member:

void dotp(std::vector<int> x, std::vector<int> y, std::vector<int> z)
{
    int8 *xp = (int8 *)x.data();
    int8 *yp = (int8 *)y.data();
    int8 *zp = (int8 *)z.data();
    for (int i=0;i<N/8;i++)
    {
        /* process the data 8 ints at a time */
        *zp++ = *xp++ + *yp++;
    }
}

void dotp(std::array<int> x, std::array<int> y, std::array<int> z)
{
    int8 *xp = (int8 *)x.data();
    int8 *yp = (int8 *)y.data();
    int8 *zp = (int8 *)z.data();
    for (int i=0;i<N/8;i++)
    {
        /* process the data 8 ints at a time */
        *zp++ = *xp++ + *yp++;
    }
}

Accessing a complex type as a vector: The imaginary and real components of complex vector objects and complex scalar objects are stored differently depending on whether the object is in memory or in registers.

Complex scalar objects are stored in memory with the real component at the lowest address. Complex vector objects are stored in memory as a sequence of complex scalar values, with the real component of s0 at the lowest address, followed by the imaginary component of s0, and so on.

Complex scalar objects are stored in registers with the imaginary component in the least significant bit, followed by the real component. Complex vector objects are stored as a sequence of complex scalar values, with imaginary component of s0 at the LSB, followed by real component of s0, and so on. This register layout is required by CPU instructions that operate on complex values (for example, VCMPYSP).

As a result of the reversal in the order in which the components are stored, the compiler must swap the complex real and imaginary components when loading from memory to a register and vice versa.

In memory, complex scalar objects are stored with the real component at the lowest address. In registers, the imaginary component is stored starting at the least significant bit. Figure 5-1 Memory and Register Layout of Complex Components

The compiler normally handles swapping the order of complex components. When you access a complex scalar or complex vector object through a pointer, the pointer must have the correct type.

You can access a non-complex array as a complex scalar:

float value[2];
cfloat x = *(cfloat *)&value;

You can access a complex scalar as a vector of length two with the same element type as the complex components:

cchar value;
char2 x = *(char2 *)&cchar;

You can access an array of non-complex scalars as a complex vector as long as the complex values are stored in the non-complex scalar array with the real component first, then the imaginary component. You can use either a 1- or 2-dimensional array, as convenient.

float value[2][] = { { r, i }, { r, i } ... };
cfloat4 x = *(cfloat4 *)&value;

float value[] = { r, i, r, i, ... };
cfloat4 x = *(cfloat4 *)&value;

You can access any complex vector as a vector of twice the length with the same element type as the complex components:

cchar4 value;
char8 x = *(char8 *)&value;

When loading a complex scalar or complex vector from a non-complex type, the compiler handles the necessary component swapping for you.

Note: When using a pointer to complex to read from a non-complex array, make the element type of the complex object match the element type of the non-complex array. For example, if your array is of type const int coefficients[2][N], make the vector a const with int elements (for example, const cint8). If you do not stick to this type, undesirable behavior can occur due to automatic swapping of complex components.

A frequent use case for complex values in C code is to represent them as two-dimensional array of the component values, like so:

float coefficients[2][4] =
{ { real, imag }, { real, imag },
  { real, imag }, { real, imag }, };

/* access part of the coefficient array as a vector */
output = input * *(cfloat4 *)coefficients;

You can also initialize a complex vector from an array of C99 complex values, because the layout of a C99 complex object and a TI complex object are the same:

float _Complex coefficients[4] =
{ real + imag * _Complex_I, real + imag * _Complex_I,
  real + imag * _Complex_I, real + imag * _Complex_I, };

/* access part of the coefficient array as a vector */
output = input * *(cfloat4 *)coefficients;

Mismatched vector/array sizes: You can use vector operations even if an array has an element count that is not an even multiple of the vector element count by using predicated loads and stores for the last iteration of the loop. As a result, the last iteration of the loop loads and stores only part of the vector, and thus only the remaining part of the array.

#include <stddef.h>
#include <c7x.h>

void dotp(int x[], int y[], int z[restrict], size_t n)
{
    int8 *xp = (int8 *)x;
    int8 *yp = (int8 *)y;
    int8 *zp = (int8 *)z;
    for (int i=0;i<n/8;i++)
        *zp++ = *xp++ * *yp++;
    unsigned leftover = n%8;
    if (leftover)
    {
        vpred mask = __mask_char(leftover);
        __vstore_pred(mask, zp, __vload_pred(mask, xp) * __vload_pred(mask, yp));
    }
}