W5.0
C/C++ Compiler and Library Manual
for TigerSHARC
Revision 4.1, August 2008
®
Processors
Analog Devices, Inc.
One Technology Way
Norwood, Mass. 02062-9106
Part Number
82-000336-03
a
Copyright Information
© 2008 Analog Devices, Inc., ALL RIGHTS RESERVED. This document
may not be reproduced in any form without prior, express written consent
from Analog Devices, Inc.
Printed in the USA.
Disclaimer
Analog Devices, Inc. reserves the right to change this product without
prior notice. Information furnished by Analog Devices is believed to be
accurate and reliable. However, no responsibility is assumed by Analog
Devices for its use; nor for any infringement of patents or other rights of
third parties which may result from its use. No license is granted by implication or otherwise under the patent rights of Analog Devices, Inc.
Trademark and Service Mark Notice
The Analog Devices logo, icon bar and logo, the CROSSCORE logo,
VisualDSP++, SHARC, TigerSHARC, and EZ-KIT Lite are registered
trademarks of Analog Devices, Inc.
All other brand and product names are trademarks or service marks of
their respective owners.
CONTENTS
PREFACE
Purpose of This Manual ............................................................. xxxix
Intended Audience ..................................................................... xxxix
Manual Contents Description ......................................................... xl
What’s New in This Manual ............................................................ xl
Technical or Customer Support ....................................................... xl
Supported Processors ...................................................................... xli
Product Information ...................................................................... xli
Analog Devices Web Site .......................................................... xli
VisualDSP++ Online Documentation ...................................... xlii
Technical Library CD ............................................................. xliii
Notation Conventions ................................................................... xliv
COMPILER
C/C++ Compiler Overview ........................................................... 1-3
Compiler Command-Line Interface ............................................... 1-5
Running the Compiler ............................................................. 1-6
Compiler Command-Line Switches ........................................ 1-10
VisualDSP++ 5.0 C/C++ Compiler and Library Manual iii
for TigerSHARC Processors
CONTENTS
C/C++ Compiler Switch Summaries .................................. 1-10
C/C++ Mode Selection Switch Descriptions ...................... 1-22
C/C++ Compiler Common Switch Descriptions ................ 1-23
-c89 ............................................................................. 1-22
-c++ ............................................................................. 1-22
sourcefile ...................................................................... 1-23
-@ filename .................................................................. 1-23
-A name [(<tokens>)] .................................................... 1-23
-add-debug-libpaths ...................................................... 1-24
-align-branch-lines ........................................................ 1-25
-allow-macs-to-extend-saturation .................................. 1-25
-alttok .......................................................................... 1-25
-always-inline ............................................................... 1-26
-annotate ...................................................................... 1-26
-annotate-loop-instr ...................................................... 1-27
-auto-attrs .................................................................... 1-27
-bss .............................................................................. 1-27
-build-lib ...................................................................... 1-27
-C ................................................................................ 1-27
-c ................................................................................. 1-28
-char-size-any ............................................................... 1-28
-char-size-{8|32} ........................................................... 1-28
-const-read-write .......................................................... 1-29
-const-strings ................................................................ 1-29
iv VisualDSP++ 5.0 C/C++ Compiler and Library Manual
for TigerSHARC Processors
CONTENTS
-Dmacro[=definition] .................................................... 1-29
-debug-types ................................................................. 1-30
-default-branch-{np|p} ................................................... 1-30
-double-size-any ............................................................ 1-30
-double-size-{32 | 64} .................................................... 1-31
-dry .............................................................................. 1-32
-dryrun ......................................................................... 1-32
-E ................................................................................. 1-32
-ED .............................................................................. 1-32
-EE ............................................................................... 1-33
-enum-is-int .................................................................. 1-33
-extra-keywords ............................................................. 1-33
-file-attr name[=value] ................................................... 1-34
-flags-{asm|compiler|lib|link|mem} switch [,switch2 [,...]] 1-34
-force-circbuf ................................................................ 1-34
-fp-associative ............................................................... 1-35
-fp-div-lib ..................................................................... 1-35
-full-version .................................................................. 1-35
-g .................................................................................. 1-35
-glite ............................................................................. 1-36
-H ................................................................................ 1-36
-HH ............................................................................. 1-37
-h[elp] .......................................................................... 1-37
-I- ................................................................................. 1-37
VisualDSP++ 5.0 C/C++ Compiler and Library Manual v
for TigerSHARC Processors
CONTENTS
-I directory [{,|;} directory...] ......................................... 1-38
-implicit-pointers .......................................................... 1-38
-include filename .......................................................... 1-39
-ipa .............................................................................. 1-39
-L directory [{,|;} directory...] ........................................ 1-39
-l library ....................................................................... 1-40
-list-workarounds .......................................................... 1-40
-M ............................................................................... 1-41
-MD ............................................................................ 1-41
-MM ............................................................................ 1-41
-Mo filename ................................................................ 1-41
-Mt name ..................................................................... 1-41
-map filename .............................................................. 1-41
-mem ........................................................................... 1-42
-multiline ..................................................................... 1-42
-never-inline ................................................................. 1-42
-no-align-branch-lines ................................................... 1-42
-no-alttok ..................................................................... 1-42
-no-annotate ................................................................. 1-43
-no-annotate-loop-instr ................................................. 1-43
-no-auto-attrs ............................................................... 1-43
-no-bss ......................................................................... 1-43
-no-builtin ................................................................... 1-44
-no-circbuf ................................................................... 1-44
vi VisualDSP++ 5.0 C/C++ Compiler and Library Manual
for TigerSHARC Processors
CONTENTS
-no-const-strings ........................................................... 1-44
-no-defs ........................................................................ 1-44
-no-extra-keywords ........................................................ 1-45
-no-fp-associative .......................................................... 1-45
-no-fp-minmax ............................................................. 1-45
-no-mem ....................................................................... 1-46
-no-multiline ................................................................ 1-46
-no-progress-rep-timeout ............................................... 1-46
-no-saturation ............................................................... 1-46
-no-std-ass .................................................................... 1-47
-no-std-def .................................................................... 1-47
-no-std-inc .................................................................... 1-47
-no-std-lib .................................................................... 1-47
-no-threads ................................................................... 1-47
-no-workaround workaround_id[,workaround_id …] .... 1-48
-O ................................................................................ 1-48
-O[0|1] ......................................................................... 1-48
-Oa ............................................................................... 1-48
-Og ............................................................................... 1-49
-Os ............................................................................... 1-49
-Ov num ....................................................................... 1-49
-o filename .................................................................... 1-51
-overlay ......................................................................... 1-51
-P ................................................................................. 1-52
VisualDSP++ 5.0 C/C++ Compiler and Library Manual vii
for TigerSHARC Processors
CONTENTS
-PP ............................................................................... 1-52
-path-{ asm | compiler | lib | link } pathname ................. 1-52
-path-install directory ................................................... 1-52
-path-output directory .................................................. 1-53
-path-temp directory ..................................................... 1-53
-pch ............................................................................. 1-53
-pchdir directory ........................................................... 1-53
-pgo-session session-id .................................................. 1-53
-pguide ......................................................................... 1-54
-pplist filename ............................................................. 1-54
-proc processor ............................................................. 1-55
-progress-rep-func ......................................................... 1-56
-progress-rep-gen-opt .................................................... 1-56
-progress-rep-mc-opt ..................................................... 1-56
-progress-rep-timeout .................................................... 1-56
-progress-rep-timeout-secs secs ...................................... 1-57
-R directory [{:|,}directory …] ....................................... 1-57
-R- ............................................................................... 1-57
-S ................................................................................. 1-57
-s .................................................................................. 1-58
-save-temps ................................................................... 1-58
-section id=section_name[,id=section_name...] .............. 1-58
-show ........................................................................... 1-59
-si-revision version ........................................................ 1-59
viii VisualDSP++ 5.0 C/C++ Compiler and Library Manual
for TigerSHARC Processors
CONTENTS
-signed-bitfield .............................................................. 1-60
-signed-char .................................................................. 1-60
-structs-do-not-overlap .................................................. 1-60
-syntax-only .................................................................. 1-61
-sysdefs ......................................................................... 1-61
-T filename ................................................................... 1-62
-threads ........................................................................ 1-62
-time ............................................................................ 1-62
-Umacro ....................................................................... 1-63
-unsigned-bitfield .......................................................... 1-63
-unsigned-char .............................................................. 1-64
-v .................................................................................. 1-64
-verbose ........................................................................ 1-64
-version ......................................................................... 1-64
-W {error|remark|suppress|warn} number ....................... 1-64
-Werror-limit number ................................................... 1-65
-Werror-warnings .......................................................... 1-65
-Wremarks .................................................................... 1-65
-Wterse ......................................................................... 1-65
-w ................................................................................. 1-66
-warn-protos ................................................................. 1-66
-workaround workaround_id[,workaround_id]* ............. 1-66
-write-files .................................................................... 1-67
-write-opts .................................................................... 1-67
VisualDSP++ 5.0 C/C++ Compiler and Library Manual ix
for TigerSHARC Processors
CONTENTS
C++ Mode Compiler Switch Descriptions ......................... 1-68
-xref <filename> ............................................................ 1-67
-anach .......................................................................... 1-68
-check-init-order ........................................................... 1-69
-eh ............................................................................... 1-70
-full-dependency-inclusion ............................................ 1-70
-ignore-std .................................................................... 1-71
-no-anach ..................................................................... 1-71
-no-eh .......................................................................... 1-71
-no-implicit-inclusion ................................................... 1-71
-no-rtti ......................................................................... 1-72
-no-std-templates .......................................................... 1-72
-rtti .............................................................................. 1-72
-std-templates ............................................................... 1-72
Data Types and Data Type Sizes ............................................ 1-73
Integer Data Types ........................................................... 1-74
Floating-Point Data Types ................................................ 1-74
Data Type Alignment ............................................................ 1-75
Environment Variables Used by the Compiler ........................ 1-76
Optimization Control ........................................................... 1-77
Optimization Levels ......................................................... 1-78
Interprocedural Analysis ................................................... 1-80
Interaction with Libraries .............................................. 1-81
Controlling Silicon Revision and Anomaly Workarounds within the
Compiler ........................................................................... 1-82
x VisualDSP++ 5.0 C/C++ Compiler and Library Manual
for TigerSHARC Processors
CONTENTS
Using the -si-revision Switch ............................................ 1-83
Using the -workaround Switch .......................................... 1-84
Using the -no-workaround Switch ..................................... 1-87
Interactions Between the Silicon Revision and Workaround Switches
1-87
C/C++ Compiler Language Extensions ........................................ 1-89
Byte-Addressing Mode ........................................................... 1-93
sizeof() Operator Types and Sizes ....................................... 1-93
Pointers ............................................................................ 1-94
Alignment of Objects ........................................................ 1-94
Initializations .................................................................... 1-95
Pragmas Used in Byte-Addressing Mode ............................ 1-95
Performance Issues ............................................................ 1-95
Libraries Used in Byte-Addressing Mode ............................ 1-96
Include Files ..................................................................... 1-97
Function Inlining .................................................................. 1-97
Inlining and Optimization .............................................. 1-100
Inlining and Out-of-Line Copies ..................................... 1-100
Inlining and Global asm Statements ................................ 1-101
Inlining and Sections ...................................................... 1-101
Inline Assembly Language Support Keyword (asm) ............... 1-102
asm() Construct Syntax ................................................... 1-104
asm() Construct Syntax Rules ...................................... 1-106
asm() Construct Template Example ............................. 1-107
Assembly Construct Operand Description ....................... 1-108
VisualDSP++ 5.0 C/C++ Compiler and Library Manual xi
for TigerSHARC Processors
CONTENTS
Assembly Constructs With Multiple Instructions ............. 1-115
Assembly Construct Reordering and Optimization .......... 1-116
Assembly Constructs With Input and Output Operands .. 1-116
Assembly Constructs and Flow Control ........................... 1-117
Guidelines on the Use of asm() Statements ...................... 1-118
64-Bit Integer Support (long long) ...................................... 1-118
Quad-Word Support ........................................................... 1-119
Memory Support Keywords (pm dm) .................................. 1-119
Memory Keyword Rules .................................................. 1-120
__regclass Construct ........................................................... 1-122
Bank Type Qualifiers ........................................................... 1-123
Placement Support Keyword (section) ................................. 1-124
Placement of Compiler-Generated Code and Data ............... 1-125
Boolean Type Support Keywords ......................................... 1-126
Pointer Class Support Keyword (restrict) ............................. 1-126
Variable-Length Array Support ............................................ 1-127
Long Identifiers .................................................................. 1-129
Non-Constant Aggregate Initializer Support ........................ 1-129
Indexed Initializer Support .................................................. 1-129
Compiler Built-In Functions ............................................... 1-132
Using the builtins.h Header File ...................................... 1-133
Optimization Guidance Built-in Functions ..................... 1-134
16-Bit Data Types .......................................................... 1-137
Packed 16-bit Integer Support Using C ....................... 1-139
xii VisualDSP++ 5.0 C/C++ Compiler and Library Manual
for TigerSHARC Processors
CONTENTS
Constructors (int2x16 values) ...................................... 1-139
Extractors and Expanders (int2x16 values) ................... 1-139
Arithmetic Operators (int2x16 values) ......................... 1-140
Bitwise Operators (int2x16 values) .............................. 1-140
Comparison Operators (int2x16 values) ....................... 1-141
Sideways Sum (int2x16 values) .................................... 1-142
Constructors (int4x16 values) ...................................... 1-143
Extractors (2x16 from a 4x16 value) ............................ 1-143
Arithmetic Operators (int4x16 values) ......................... 1-145
Sideways Sum (int4x16 values) .................................... 1-145
32-Bit Data Types ........................................................... 1-147
Constructors (int2x32 values) ...................................... 1-147
Extractors (int2x32 values) .......................................... 1-147
Circular Buffer Built-In Functions ................................... 1-148
Circular Buffer Increment of an Index ......................... 1-148
Circular Buffer Increment of a Pointer ......................... 1-148
Math Intrinsics ............................................................... 1-149
RECIPS ...................................................................... 1-150
RSQRTS .................................................................... 1-151
Instructions Generated by Built-in Functions ................... 1-151
Addition and Subtraction ............................................ 1-152
Conversion: ................................................................ 1-155
Miscellaneous ALU Instructions .................................. 1-156
Shifter Instructions ..................................................... 1-158
VisualDSP++ 5.0 C/C++ Compiler and Library Manual xiii
for TigerSHARC Processors
CONTENTS
Data Alignment Buffer (DAB) Built-in Functions ............ 1-167
Circular Buffer Data Alignment Buffer (DAB) Built-in Functions
1-169
Communications Logic Unit Operations ......................... 1-171
Bit Manipulation Instructions ..................................... 1-159
Multiplier Instructions ................................................ 1-161
Floating-Point Operations ........................................... 1-164
Miscellaneous ............................................................. 1-165
Memory Allocation ..................................................... 1-165
Composition and Decomposition ................................ 1-165
System Register Access ................................................ 1-166
TMAX, TMAX_ADD, TMAX_SUB, MAX_ADD, MAX_SUB
1-171
PERMUTE ................................................................ 1-177
ACS ........................................................................... 1-178
DESPREAD ............................................................... 1-182
XCORRS ................................................................... 1-184
Pragmas .............................................................................. 1-187
Data Alignment Pragmas ................................................ 1-188
#pragma align num ..................................................... 1-189
#pragma alignment_region (alignopt) .......................... 1-191
Interrupt Handler Pragmas ............................................. 1-192
Loop Optimization Pragmas ........................................... 1-195
#pragma all_aligned .................................................... 1-195
#pragma different_banks ............................................. 1-196
xiv VisualDSP++ 5.0 C/C++ Compiler and Library Manual
for TigerSHARC Processors
CONTENTS
#pragma loop_count(min, max, modulo) ..................... 1-196
#pragma loop_unroll N ............................................... 1-196
#pragma no_alias ........................................................ 1-198
#pragma no_vectorization ........................................... 1-199
#pragma vector_for ..................................................... 1-199
Function Side-Effect Pragmas .......................................... 1-200
#pragma alloc .............................................................. 1-200
#pragma const ............................................................. 1-201
#pragma noreturn ....................................................... 1-201
#pragma pgo_ignore .................................................... 1-202
#pragma pure .............................................................. 1-202
#pragma regs_clobbered string ..................................... 1-203
#pragma regs_clobbered_call string .............................. 1-207
#pragma overlay .......................................................... 1-210
#pragma result_alignment (n) ...................................... 1-211
General Optimization Pragmas ........................................ 1-211
Inline Control Pragmas ................................................... 1-212
#pragma always_inline ................................................ 1-212
#pragma never_inline .................................................. 1-213
Linking Control Pragmas ................................................ 1-214
#pragma linkage_name identifier ................................. 1-214
#pragma core ............................................................. 1-214
#pragma section/#pragma default_section .................... 1-219
#pragma file_attr (name[=value] [, name[=value] [...]]) 1-222
VisualDSP++ 5.0 C/C++ Compiler and Library Manual xv
for TigerSHARC Processors
CONTENTS
Class Conversion Optimization Pragmas ......................... 1-223
Template Instantiation Pragmas ...................................... 1-226
Header File Control Pragmas .......................................... 1-228
#pragma separate_mem_segments ( var1, var2 ) ........... 1-222
#pragma weak_entry .................................................. 1-223
#pragma param_never_null param_name [ ... ] ............ 1-223
#pragma suppress_null_check ..................................... 1-225
#pragma instantiate instance ....................................... 1-227
#pragma do_not_instantiate instance .......................... 1-227
#pragma can_instantiate instance ................................ 1-228
#pragma hdrstop ........................................................ 1-228
#pragma no_implicit_inclusion ................................... 1-229
#pragma no_pch ......................................................... 1-230
#pragma once ............................................................. 1-230
#pragma system_header .............................................. 1-231
Diagnostic Control Pragmas ........................................... 1-231
Modifying the Severity of Specific Diagnostics ............. 1-231
Modifying the Behavior of an Entire Class of Diagnostics 1-232
Saving or Restoring the Current Behavior of All Diagnostics ..
1-232
Memory Bank Pragmas ................................................... 1-234
#pragma code_bank(bankname) .................................. 1-234
#pragma data_bank(bankname) .................................. 1-235
#pragma stack_bank(bankname) ................................. 1-236
#pragma bank_memory_kind(bankname, kind) ........... 1-237
xvi VisualDSP++ 5.0 C/C++ Compiler and Library Manual
for TigerSHARC Processors
CONTENTS
#pragma bank_read_cycles(bankname, cycles) .............. 1-238
#pragma bank_write_cycles(bankname, cycles) ............. 1-238
#pragma bank_optimal_width(bankname, width) ........ 1-239
Increments and Decrements ................................................. 1-240
C++ Style Comments ........................................................... 1-240
C++ Fractional Type Support ............................................... 1-241
Format of Fractional Literals ........................................... 1-241
Conversions Involving Fractional Values .......................... 1-242
Fractional Arithmetic Operations .................................... 1-242
Mixed-Mode Operations ................................................. 1-243
GCC Compatibility Extensions ........................................... 1-244
Statement Expressions ..................................................... 1-244
Type Reference Support Keyword (typeof) ....................... 1-245
GCC Generalized Lvalues ............................................... 1-246
Conditional Expressions With Missing Operands ............. 1-247
Hexadecimal Floating-Point Numbers ............................. 1-247
Zero-Length Arrays ......................................................... 1-248
Variable Argument Macros .............................................. 1-248
Line Breaks in String Literals ........................................... 1-249
Arithmetic on Pointers to Void and Pointers to Functions 1-249
Cast to Union ................................................................. 1-249
Ranges in Case Labels ..................................................... 1-249
Declarations Mixed With Code ....................................... 1-250
Escape Character Constant .............................................. 1-250
VisualDSP++ 5.0 C/C++ Compiler and Library Manual xvii
for TigerSHARC Processors
CONTENTS
Alignment Inquiry Keyword (__alignof__) ...................... 1-250
(asm) Keyword for Specifying Names in Generated Assembler 1-251
Function, Variable and Type Attribute Keyword (__attribute__)
1-251
Unnamed struct/union fields within struct/unions ........... 1-252
Preprocessor-Generated Warnings ........................................ 1-252
Migrating .ldf Files From Previous VisualDSP++ Installations 1-252
C++ Support Tables (ctor, gdt) ........................................ 1-253
Preprocessor Features ................................................................ 1-255
Predefined Preprocessor Macros ........................................... 1-255
Writing Macros ................................................................... 1-258
Compound Macros ......................................................... 1-258
C/C++ Run-Time Model and Environment ............................... 1-261
Stack Frame Overview ......................................................... 1-262
Stack Frame Description ..................................................... 1-264
General System-Wide Specifications ................................ 1-266
At a procedure call, the following must be true: ........... 1-267
Argument Passage ........................................................... 1-268
Passing a C++ Class Instance ........................................... 1-269
Return Values ................................................................. 1-270
Procedure Call and Return .............................................. 1-271
To Call a Procedure: ................................................... 1-271
On Entry: ................................................................... 1-272
To Return from a Procedure: ....................................... 1-273
Code Sequences .............................................................. 1-273
xviii VisualDSP++ 5.0 C/C++ Compiler and Library Manual
for TigerSHARC Processors
CONTENTS
Constructors and Destructors of Global Class Instances ........ 1-274
Constructors, Destructors and Memory Placement .......... 1-276
Support for argv/argc ........................................................... 1-277
Allocation of Memory for Stacks and Heaps in LDFs ............ 1-278
Example of Heap/Stack Memory Allocation ..................... 1-278
Using Multiple Heaps .......................................................... 1-280
Heap Identifiers .............................................................. 1-280
Initializing the Heap ....................................................... 1-281
Using Alternate Heaps with the Standard Interface ........... 1-281
Allocating C++ STL Objects to a Non-Default Heap ....... 1-282
Using the Alternate Heap Interface .................................. 1-285
C++ Run-Time Support for the Alternate Heap Interface 1-286
Using the Heap_Install Interface ..................................... 1-287
Miscellaneous Information ................................................... 1-289
Register Classification .......................................................... 1-289
Callee Preserved Registers (“Preserved”) ........................... 1-289
Dedicated Registers ......................................................... 1-290
Caller Save Registers (“Scratch”) ...................................... 1-290
ADSP-TS101 and ADSP-TS20x Processor Registers ........ 1-290
C/C++ and Assembly Language Interface ................................... 1-298
Calling Assembly Subroutines From C/C++ Programs .......... 1-298
Calling C/C++ Functions From Assembly Programs ............. 1-301
Using Mixed C/C++ and Assembly Naming Conventions . 1-302
C++ Programming Examples ................................................ 1-304
VisualDSP++ 5.0 C/C++ Compiler and Library Manual xix
for TigerSHARC Processors
CONTENTS
Using Fract Type Support ............................................... 1-305
Using Complex Number Support .................................... 1-306
Compiler C++ Template Support .............................................. 1-308
Template Instantiation ........................................................ 1-308
Identifying Un-instantiated Templates ................................. 1-310
File Attributes .......................................................................... 1-312
Automatically-Applied Attributes ........................................ 1-313
Default LDF Placement ...................................................... 1-313
Sections versus Attributes .................................................... 1-315
Granularity ..................................................................... 1-315
“Hard” versus “Soft” ....................................................... 1-316
Number of Values ........................................................... 1-316
Using Attributes .................................................................. 1-317
Example ......................................................................... 1-317
ACHIEVING OPTIMAL PERFORMANCE FROM C/C++
SOURCE CODE
General Guidelines ....................................................................... 2-3
How the Compiler Can Help .................................................. 2-4
Using the Compiler Optimizer ............................................ 2-4
Using Compiler Diagnostics ............................................... 2-5
Warnings and Remarks ................................................... 2-5
Source and Assembly Annotations ................................... 2-7
Using the Statistical Profiler ............................................... 2-7
Using Profile-Guided Optimization .................................... 2-8
xx VisualDSP++ 5.0 C/C++ Compiler and Library Manual
for TigerSHARC Processors
CONTENTS
Using Profile-Guided Optimization With a Simulator ...... 2-9
Using Profile-Guided Optimization With Non-Simulatable
Applications ............................................................... 2-10
Profile-Guided Optimization and Multiple Source Uses . 2-11
Profile-Guided Optimization and the -Ov Switch .......... 2-12
When to Use Profile-Guided Optimization .................... 2-12
Using Interprocedural Optimization .................................. 2-12
Data Types ............................................................................ 2-13
Avoiding Emulated Arithmetic .......................................... 2-14
Using Sub-Word Types with Caution ................................. 2-16
Getting the Most From IPA ................................................... 2-17
Initialize Constants Statically ............................................. 2-17
Quad-Word-Aligning Your Data ........................................ 2-19
Using __builtin_aligned .................................................... 2-20
Avoiding Aliases ................................................................ 2-21
Indexed Arrays Versus Pointers ............................................... 2-23
Trying Pointer and Indexed Styles ...................................... 2-24
Function Inlining .................................................................. 2-24
Using Inline asm Statements .................................................. 2-25
Memory Usage ...................................................................... 2-26
Putting Arrays into Different Memory Sections .................. 2-26
Using the Bank Qualifier ................................................... 2-29
Improving Conditional Code ...................................................... 2-30
Loop Guidelines ......................................................................... 2-31
Keeping Loops Short ............................................................. 2-32
VisualDSP++ 5.0 C/C++ Compiler and Library Manual xxi
for TigerSHARC Processors
CONTENTS
Avoiding Unrolling Loops ..................................................... 2-32
Avoiding Loop-Carried Dependencies .................................... 2-33
Avoiding Loop Rotation by Hand .......................................... 2-34
Avoiding Array Writes in Loops ............................................. 2-35
Inner Loops Versus Outer Loops ........................................... 2-35
Avoiding Conditional Code in Loops ..................................... 2-36
Avoiding Placing Function Calls in Loops .............................. 2-37
Avoiding Non-Unit Strides ................................................... 2-37
Loop Control ........................................................................ 2-38
Using the Restrict Qualifier ................................................... 2-39
Avoiding Long Latencies ....................................................... 2-40
Using Built-In Functions in Code Optimization .......................... 2-41
Using Fractional Data ........................................................... 2-41
System Support Built-in Functions ........................................ 2-42
Using Circular Buffers ........................................................... 2-43
Smaller Applications: Optimizing for Code Size .......................... 2-45
Using Pragmas for Optimization ................................................. 2-47
Function Pragmas ................................................................. 2-47
#pragma const .................................................................. 2-47
#pragma pure ................................................................... 2-48
#pragma regs_clobbered .................................................... 2-48
#pragma optimize_{off|for_speed|for_space} ...................... 2-50
Loop Optimization Pragmas .................................................. 2-50
#pragma loop_count ......................................................... 2-50
xxii VisualDSP++ 5.0 C/C++ Compiler and Library Manual
for TigerSHARC Processors
CONTENTS
#pragma no_vectorization ................................................. 2-51
#pragma vector_for ........................................................... 2-51
#pragma all_aligned .......................................................... 2-52
#pragma different_banks ................................................... 2-53
#pragma no_alias .............................................................. 2-54
Useful Optimization Switches ...................................................... 2-55
How Loop Optimization Works .................................................. 2-56
Terminology .......................................................................... 2-56
Clobbered Register ............................................................ 2-56
Live Register ..................................................................... 2-57
Spill .................................................................................. 2-57
Scheduling ........................................................................ 2-57
Loop Kernel ...................................................................... 2-58
Loop Prolog ...................................................................... 2-58
Loop Epilog ...................................................................... 2-58
Loop Invariant .................................................................. 2-58
Hoisting ........................................................................... 2-59
Sinking ............................................................................. 2-59
Loop Optimization Concepts ................................................. 2-59
Software Pipelining ........................................................... 2-60
Loop Rotation .................................................................. 2-60
Loop Vectorization ............................................................ 2-63
Modulo Scheduling ........................................................... 2-65
Initiation Interval (II) and the kernel ............................. 2-66
VisualDSP++ 5.0 C/C++ Compiler and Library Manual xxiii
for TigerSHARC Processors
CONTENTS
Minimum Initiation Interval Due to Resources (Res MII) 2-69
Minimum Initiation Interval Due to Recurrences (Rec MII) 2-70
Stage Count (SC) ......................................................... 2-71
Variable Expansion and MVE unroll ............................. 2-72
Trip Count ................................................................... 2-77
A Worked Example ............................................................... 2-78
Assembly Optimizer Annotations ................................................ 2-81
Global Information ............................................................... 2-82
Procedure Statistics ............................................................... 2-82
Instruction Annotations ........................................................ 2-86
Loop Identification ............................................................... 2-87
Loop Identification Annotations ....................................... 2-87
File Position ..................................................................... 2-91
Vectorization Information ..................................................... 2-93
Unroll and Jam ................................................................. 2-94
Loop Flattening ................................................................ 2-97
Vectorization Annotations ................................................. 2-98
Modulo Scheduling Information ......................................... 2-100
Annotations for Modulo Scheduled Instructions .............. 2-101
Warnings, Failure Messages and Advice ................................ 2-107
C/C++ RUN-TIME LIBRARY
C and C++ Run-Time Libraries Guide .......................................... 3-3
Calling Library Functions ........................................................ 3-4
Using Compiler’s Built-In C Library Functions ........................ 3-4
xxiv VisualDSP++ 5.0 C/C++ Compiler and Library Manual
for TigerSHARC Processors
CONTENTS
Linking Library Functions ....................................................... 3-5
Working With Library Source Code ......................................... 3-8
Working With Library Header Files ......................................... 3-9
adi_types.h ....................................................................... 3-11
assert.h ............................................................................. 3-11
ctype.h ............................................................................. 3-11
cycle_count.h .................................................................... 3-12
cycles.h ............................................................................. 3-12
device.h ............................................................................ 3-12
device_int.h ...................................................................... 3-12
errno.h ............................................................................. 3-13
float.h ............................................................................... 3-13
iso646.h ........................................................................... 3-14
limits.h ............................................................................. 3-14
locale.h ............................................................................. 3-14
math.h .............................................................................. 3-15
setjmp.h ............................................................................ 3-16
signal.h ............................................................................. 3-16
stdarg.h ............................................................................ 3-17
stdbool.h .......................................................................... 3-17
stddef.h ............................................................................ 3-17
stdint.h ............................................................................. 3-17
stdio.h .............................................................................. 3-20
stdlib.h ............................................................................. 3-23
VisualDSP++ 5.0 C/C++ Compiler and Library Manual xxv
for TigerSHARC Processors
CONTENTS
string.h ............................................................................ 3-24
time.h .............................................................................. 3-24
DSP Header Files .................................................................. 3-26
complex.h – Basic Complex Arithmetic Functions ............. 3-26
filter.h – DSP Filters and Transformations ......................... 3-27
libsim.h – Simulator Services ............................................ 3-28
matrix.h – Matrix Functions ............................................. 3-29
stats.h – Statistical Functions ............................................ 3-31
vector.h – Vector Functions ............................................... 3-31
window.h – Window Generators ....................................... 3-32
Calling Library Functions from an ISR .................................. 3-33
Using the Libraries in a Multi-Threaded Environment ........... 3-34
Abridged C++ Library Support .............................................. 3-35
Embedded C++ Library Header Files ................................. 3-36
complex ........................................................................ 3-36
exception ...................................................................... 3-37
fract ............................................................................. 3-37
fstream ......................................................................... 3-37
iomanip ........................................................................ 3-37
ios ................................................................................ 3-37
iosfwd .......................................................................... 3-37
iostream ....................................................................... 3-37
istream ......................................................................... 3-38
new .............................................................................. 3-38
xxvi VisualDSP++ 5.0 C/C++ Compiler and Library Manual
for TigerSHARC Processors
CONTENTS
ostream ......................................................................... 3-38
sstream ......................................................................... 3-38
stdexcept ....................................................................... 3-38
streambuf ...................................................................... 3-38
string ............................................................................ 3-38
strstream ....................................................................... 3-39
C++ Header Files for C Library Facilities ........................... 3-39
Embedded Standard Template Library Header Files ........... 3-40
algorithm ...................................................................... 3-40
deque ............................................................................ 3-40
functional ..................................................................... 3-40
hash_map ..................................................................... 3-40
hash_set ........................................................................ 3-40
iterator ......................................................................... 3-41
list ................................................................................ 3-41
map .............................................................................. 3-41
memory ........................................................................ 3-41
numeric ........................................................................ 3-41
queue ............................................................................ 3-41
set ................................................................................ 3-41
stack ............................................................................. 3-41
utility ........................................................................... 3-41
vector ........................................................................... 3-41
fstream.h ....................................................................... 3-42
VisualDSP++ 5.0 C/C++ Compiler and Library Manual xxvii
for TigerSHARC Processors
CONTENTS
iomanip.h ..................................................................... 3-42
iostream.h .................................................................... 3-42
new.h ........................................................................... 3-42
Using the Thread-Safe C/C++ Run-Time Libraries with VDK 3-42
Measuring Cycle Counts ....................................................... 3-42
Basic Cycle Counting Facility ............................................ 3-43
Cycle Counting Facility with Statistics .............................. 3-45
Using time.h to Measure Cycle Counts .............................. 3-48
Determining the Processor Clock Rate .............................. 3-49
Considerations When Measuring Cycle Counts ................. 3-50
File I/O Support ................................................................... 3-52
Extending I/O Support To New Devices ........................... 3-53
DevEntry Structure ....................................................... 3-54
Registering New Devices ............................................... 3-59
Pre-Registering Devices ................................................. 3-59
Default Device ............................................................. 3-61
Remove and Rename Functions ..................................... 3-62
Default Device Driver Interface ........................................ 3-62
Data Packing For Primitive I/O ..................................... 3-63
Data Structure for Primitive I/O ................................... 3-64
Documented Library Functions .................................................. 3-67
Undocumented Library Functions ............................................... 3-71
Run-Time Library Reference ....................................................... 3-73
a_compress ................................................................................. 3-74
xxviii VisualDSP++ 5.0 C/C++ Compiler and Library Manual
for TigerSHARC Processors
CONTENTS
a_expand .................................................................................... 3-75
abs .............................................................................................. 3-76
acos ............................................................................................ 3-77
addbitrev .................................................................................... 3-78
alog ............................................................................................ 3-79
alog10 ........................................................................................ 3-80
arg .............................................................................................. 3-81
asctime ....................................................................................... 3-82
asin ............................................................................................. 3-84
atan ............................................................................................ 3-85
atan2 .......................................................................................... 3-86
atof ............................................................................................. 3-87
atoi ............................................................................................. 3-89
atol ............................................................................................. 3-90
atold ........................................................................................... 3-91
atoll ............................................................................................ 3-93
autocoh ...................................................................................... 3-94
autocorr ...................................................................................... 3-95
avg ............................................................................................. 3-96
bsearch ....................................................................................... 3-97
cabs ............................................................................................ 3-99
cadd ......................................................................................... 3-100
cartesian ................................................................................... 3-101
cdiv .......................................................................................... 3-102
VisualDSP++ 5.0 C/C++ Compiler and Library Manual xxix
for TigerSHARC Processors
CONTENTS
ceil ........................................................................................... 3-103
cexp ......................................................................................... 3-104
cfft ........................................................................................... 3-105
cfft_mag ................................................................................... 3-108
cfft2d ....................................................................................... 3-110
cfftf .......................................................................................... 3-112
clearerr ..................................................................................... 3-114
clip .......................................................................................... 3-115
clock ........................................................................................ 3-116
cmatmadd ................................................................................ 3-117
cmatmmlt ................................................................................ 3-118
cmatmsub ................................................................................ 3-119
cmatsadd .................................................................................. 3-120
cmatsmlt .................................................................................. 3-121
cmatssub .................................................................................. 3-122
cmlt ......................................................................................... 3-123
conj .......................................................................................... 3-124
convolve ................................................................................... 3-125
conv2d ..................................................................................... 3-126
copysign ................................................................................... 3-127
cos ........................................................................................... 3-128
cosh ......................................................................................... 3-129
cot ........................................................................................... 3-130
count_ones ............................................................................... 3-131
xxx VisualDSP++ 5.0 C/C++ Compiler and Library Manual
for TigerSHARC Processors