C/C++ Compiler Manual
for SHARC
Revision 1.5, January 2011
®
Processors
Part Number
82-001963-02
Analog Devices, Inc.
One Technology Way
Norwood, Mass. 02062-9106
Copyright Information
© 2011 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, SHARC, and VisualDSP++ 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 ............................................................. xxxi
Intended Audience ..................................................................... xxxi
Manual Contents ...................................................................... xxxii
What’s New in This Manual ...................................................... xxxii
Technical or Customer Support ................................................ xxxiii
Supported Processors ................................................................ xxxiv
Product Information ................................................................ xxxiv
Analog Devices Web Site .................................................... xxxiv
VisualDSP++ Online Documentation ................................. xxxv
Technical Library CD ......................................................... xxxvi
EngineerZone ..................................................................... xxxvi
Social Networking Web Sites ............................................. xxxvii
Notation Conventions ............................................................. xxxvii
VisualDSP++ 5.0 C/C++ Compiler Manual iii
for SHARC Processors
Contents
COMPILER
C/C++ Compiler Overview ........................................................... 1-3
Compiler Command-Line Interface .............................................. 1-5
Running the Compiler ............................................................ 1-6
Compiler Command-Line Switches ......................................... 1-7
C/C++ Compiler Switch Summaries .................................... 1-7
C/C++ Mode Selection Switch Descriptions ...................... 1-20
-c89 ............................................................................. 1-20
-c99 ............................................................................. 1-20
-c++ ............................................................................. 1-20
C/C++ Compiler Common Switch Descriptions ................ 1-21
sourcefile ...................................................................... 1-21
-@ filename .................................................................. 1-21
-A name[tokens] ........................................................... 1-21
-add-debug-libpaths ...................................................... 1-22
-aligned-stack ............................................................... 1-23
-alttok ......................................................................... 1-23
-always-inline ............................................................... 1-24
-annotate ...................................................................... 1-24
-annotate-loop-instr ...................................................... 1-24
-auto-attrs .................................................................... 1-25
-build-lib ...................................................................... 1-25
-C ................................................................................ 1-25
-c ................................................................................. 1-25
iv VisualDSP++ 5.0 C/C++ Compiler Manual
for SHARC Processors
Contents
-compatible-pm-dm ...................................................... 1-25
-const-read-write ........................................................... 1-25
-const-strings ................................................................ 1-26
-D ................................................................................ 1-26
-debug-types ................................................................. 1-26
-double-size[-32|-64] ..................................................... 1-27
-double-size-any ............................................................ 1-28
-dry .............................................................................. 1-28
-dryrun ......................................................................... 1-28
-E ................................................................................. 1-29
-ED .............................................................................. 1-29
-EE ............................................................................... 1-29
-eh ................................................................................ 1-29
-enum-is-int .................................................................. 1-30
-extra-keywords ............................................................. 1-30
-file-attr
name[=value] .................................................. 1-31
-flags ............................................................................. 1-31
-float-to-int ................................................................... 1-32
-force-circbuf ................................................................ 1-32
-fp-associative ............................................................... 1-32
-full-version .................................................................. 1-32
-fx-contract ................................................................... 1-33
-fx-rounding-mode-biased ............................................. 1-33
-fx-rounding-mode-truncation ....................................... 1-33
VisualDSP++ 5.0 C/C++ Compiler Manual v
for SHARC Processors
Contents
-fx-rounding-mode-unbiased ......................................... 1-33
-g ................................................................................. 1-33
-glite ........................................................................... 1-34
-H ............................................................................... 1-34
-HH ............................................................................. 1-35
-h[elp] .......................................................................... 1-35
-I ................................................................................ 1-35
-I- ................................................................................ 1-36
-i .................................................................................. 1-36
-implicit-pointers .......................................................... 1-36
-include ....................................................................... 1-37
-ipa .............................................................................. 1-37
-L ................................................................................ 1-38
-l ................................................................................. 1-38
-list-workarounds .......................................................... 1-39
-M ............................................................................... 1-39
-MD ............................................................................ 1-39
-MM ............................................................................ 1-39
-Mo .............................................................................. 1-40
-Mt .............................................................................. 1-40
-map ............................................................................ 1-40
-mem ........................................................................... 1-40
-multiline ..................................................................... 1-40
-never-inline ................................................................. 1-41
vi VisualDSP++ 5.0 C/C++ Compiler Manual
for SHARC Processors
Contents
-no-aligned-stack ........................................................... 1-41
-no-alttok ..................................................................... 1-41
-no-annotate ................................................................. 1-41
-no-annotate-loop-instr ................................................. 1-42
-no-auto-attrs ................................................................ 1-42
-no-builtin .................................................................... 1-42
-no-circbuf .................................................................... 1-43
-no-const-strings ........................................................... 1-43
-no-db .......................................................................... 1-43
-no-defs ........................................................................ 1-43
-no-eh ........................................................................... 1-43
-no-extra-keywords ........................................................ 1-44
-no-fp-associative .......................................................... 1-44
-no-fx-contract .............................................................. 1-44
-no-mem ....................................................................... 1-45
-no-multiline ................................................................ 1-45
-no-progress-rep-timeout ............................................... 1-45
-no-sat-associative ......................................................... 1-45
-no-saturation ............................................................... 1-46
-no-shift-to-add ............................................................ 1-46
-no-simd ....................................................................... 1-46
-no-std-ass .................................................................... 1-47
-no-std-def .................................................................... 1-47
-no-std-inc .................................................................... 1-47
VisualDSP++ 5.0 C/C++ Compiler Manual vii
for SHARC Processors
Contents
-no-std-lib .................................................................... 1-47
-no-threads ................................................................... 1-47
-no-workaround ........................................................... 1-48
-normal-word-code ....................................................... 1-48
-nwc ............................................................................. 1-48
-O[0|1] ........................................................................ 1-48
-Oa .............................................................................. 1-49
-Og .............................................................................. 1-49
-Os ............................................................................... 1-49
-Ov .............................................................................. 1-49
-o ................................................................................ 1-51
-overlay ........................................................................ 1-52
-overlay-clobbers .......................................................... 1-52
-P ................................................................................. 1-53
-PP ............................................................................... 1-53
-path-{ asm | compiler | lib | link } ............................... 1-53
-path-install ................................................................. 1-53
-path-output ................................................................ 1-54
-path-temp .................................................................. 1-54
-pch ............................................................................. 1-54
-pchdir ........................................................................ 1-54
-pgo-session ................................................................. 1-54
-pguide ......................................................................... 1-55
-pplist ......................................................................... 1-55
viii VisualDSP++ 5.0 C/C++ Compiler Manual
for SHARC Processors
Contents
-proc processor .............................................................. 1-56
-progress-rep-func ......................................................... 1-57
-progress-rep-opt ........................................................... 1-57
-progress-rep-timeout .................................................... 1-57
-progress-rep-timeout-secs secs ...................................... 1-57
-R ................................................................................. 1-57
-R- ............................................................................... 1-58
-reserve ......................................................................... 1-58
-restrict-hardware-loops ................................................. 1-59
-S ................................................................................. 1-59
-s .................................................................................. 1-59
-sat-associative .............................................................. 1-59
-save-temps ................................................................... 1-59
-section ......................................................................... 1-60
-short-word-code ........................................................... 1-61
-show ............................................................................ 1-61
-si-revision .................................................................... 1-61
-signed-bitfield .............................................................. 1-62
-structs-do-not-overlap .................................................. 1-62
-swc .............................................................................. 1-63
-syntax-only .................................................................. 1-63
-sysdefs ......................................................................... 1-63
-T ................................................................................ 1-63
-threads ........................................................................ 1-64
VisualDSP++ 5.0 C/C++ Compiler Manual ix
for SHARC Processors
Contents
-time ............................................................................ 1-64
-U ............................................................................... 1-64
-unsigned-bitfield ......................................................... 1-65
-v ................................................................................. 1-65
-verbose ........................................................................ 1-66
-version ........................................................................ 1-66
-W ............................................................................... 1-66
-Werror-limit number ................................................... 1-67
-Werror-warnings ......................................................... 1-67
-Wremarks .................................................................... 1-67
-Wterse ......................................................................... 1-67
-w ................................................................................ 1-67
-warn-protos ................................................................. 1-68
-workaround ................................................................. 1-68
-write-files .................................................................... 1-68
-write-opts .................................................................... 1-69
-xref
filename .............................................................. 1-69
C Mode (MISRA) Compiler Switch Descriptions .............. 1-70
-misra ........................................................................... 1-70
-misra-linkdir ............................................................... 1-70
-misra-no-cross-module ................................................ 1-70
-misra-no-runtime ........................................................ 1-71
-misra-strict .................................................................. 1-71
-misra-suppress-advisory ............................................... 1-71
x VisualDSP++ 5.0 C/C++ Compiler Manual
for SHARC Processors
Contents
-misra-testing ................................................................ 1-71
-Wmis_suppress ............................................................ 1-71
-Wmis_warn ................................................................. 1-72
C++ Mode Compiler Switch Descriptions .......................... 1-72
-anach ........................................................................... 1-72
-check-init-order ........................................................... 1-73
-extern-inline ................................................................ 1-74
-friend-injection ............................................................ 1-74
-full-dependency-inclusion ............................................ 1-74
-ignore-std .................................................................... 1-75
-no-anach ..................................................................... 1-75
-no-extern-inline ........................................................... 1-75
-no-friend-injection ....................................................... 1-76
-no-implicit-inclusion ................................................... 1-76
-no-rtti ......................................................................... 1-76
-no-std-templates .......................................................... 1-76
-rtti .............................................................................. 1-76
-std-templates ............................................................... 1-77
Environment Variables Used by the Compiler ........................ 1-77
Data Type and Data Type Sizes .............................................. 1-78
Integer Data Types ............................................................ 1-80
Floating-Point Data Types ................................................. 1-80
VisualDSP++ 5.0 C/C++ Compiler Manual xi
for SHARC Processors
Contents
Optimization Control ........................................................... 1-81
Optimization Levels ......................................................... 1-81
Interprocedural Analysis ................................................... 1-84
Interaction With Libraries ............................................. 1-85
Controlling Silicon Revision and Anomaly Workarounds
Within the Compiler .......................................................... 1-86
Using the -si-revision Switch ............................................. 1-87
Using the -workaround Switch .......................................... 1-88
Using the -no-workaround Switch ..................................... 1-89
Interactions Between the Silicon Revision and
Workaround Switches .................................................... 1-89
Using Native Fixed-Point Types .................................................. 1-90
Fixed-Point Type Support ...................................................... 1-90
Native Fixed-Point Types ....................................................... 1-91
Native Fixed-Point Constants ................................................ 1-92
A Motivating Example .......................................................... 1-93
Fixed-Point Arithmetic Semantics .......................................... 1-94
Data Type Conversions and Fixed-Point Types ....................... 1-94
Bit-Pattern Conversion Functions: bitsfx and fxbits ................ 1-96
Arithmetic Operators for Fixed-Point Types ........................... 1-97
FX_CONTRACT ................................................................. 1-99
Rounding Behavior ............................................................. 1-101
xii VisualDSP++ 5.0 C/C++ Compiler Manual
for SHARC Processors
Contents
Arithmetic Library Functions ............................................... 1-103
divifx .............................................................................. 1-104
idivfx .............................................................................. 1-105
fxdivi .............................................................................. 1-106
mulifx ............................................................................. 1-107
absfx ............................................................................... 1-108
roundfx .......................................................................... 1-108
countlsfx ......................................................................... 1-109
strtofxfx .......................................................................... 1-109
Fixed-Point I/O Conversion Specifiers ................................. 1-109
Setting the Rounding Mode ................................................. 1-111
Language Standards Compliance ............................................... 1-113
C Mode .............................................................................. 1-113
C++ Mode ........................................................................... 1-114
MISRA-C Compiler ................................................................. 1-115
MISRA-C Compiler Overview ............................................. 1-115
MISRA-C Compliance ........................................................ 1-116
Using the Compiler to Achieve Compliance ..................... 1-117
Rules Descriptions ............................................................... 1-120
C/C++ Compiler Language Extensions ...................................... 1-128
Function Inlining ................................................................ 1-133
Inlining and Optimization .............................................. 1-136
Inlining and Out-of-Line Copies ..................................... 1-136
VisualDSP++ 5.0 C/C++ Compiler Manual xiii
for SHARC Processors
Contents
Inlining and Global asm Statements ................................ 1-137
Inlining and Sections ...................................................... 1-137
Variable Argument Macros .................................................. 1-138
Restricted Pointers .............................................................. 1-138
Variable-Length Array Support ............................................ 1-139
Non-Constant Initializer Support ........................................ 1-141
Designated Initializers ......................................................... 1-142
Hexadecimal Floating-Point Numbers ................................. 1-144
Declarations Mixed With Code ........................................... 1-145
Compound Literals ............................................................. 1-146
C++ Style Comments .......................................................... 1-147
Enumeration Constants That Are Not int Type .................... 1-147
Boolean Type Support Keywords (bool, true, false) .............. 1-147
The fract Native Fixed-Point Type ....................................... 1-148
Inline Assembly Language Support Keyword (asm) .............. 1-148
asm() Construct Syntax ................................................... 1-150
asm() Construct Syntax Rules ..................................... 1-152
asm() Construct Template Example ............................. 1-153
Assembly Construct Operand Description ....................... 1-154
Using long long Types in asm Constraints ....................... 1-160
Assembly Constructs With Multiple Instructions ............. 1-161
Assembly Construct Reordering and Optimization .......... 1-162
Assembly Constructs With Input and Output
Operands ..................................................................... 1-163
Assembly Constructs With Compile-Time Constants ...... 1-164
xiv VisualDSP++ 5.0 C/C++ Compiler Manual
for SHARC Processors
Contents
Assembly Constructs and Flow Control ........................... 1-165
Guidelines on the Use of asm() Statements ...................... 1-165
Dual Memory Support Keywords (pm dm) .......................... 1-166
Memory Keywords and Assignments/
Type Conversions ......................................................... 1-169
Memory Keywords and Function Declarations/
Pointers ....................................................................... 1-170
Memory Keywords and Function Arguments ................... 1-171
Memory Keywords and Macros ....................................... 1-172
Bank Type Qualifiers ........................................................... 1-173
Placement Support Keyword (section) .................................. 1-174
Placement of Compiler-Generated Code and Data ............... 1-175
Long Identifiers ................................................................... 1-176
Preprocessor Generated Warnings ........................................ 1-176
Compiler Built-In Functions ................................................ 1-177
Access to System Registers .............................................. 1-177
Circular Buffer Built-In Functions ................................... 1-180
Circular Buffer Increment of an Index ......................... 1-181
Circular Buffer Increment of a Pointer ......................... 1-181
Compiler Performance Built-In Functions ....................... 1-182
Expected Behavior ....................................................... 1-182
Known Values ............................................................. 1-184
Fractional Built-In Functions .......................................... 1-185
Miscellaneous Built-In Function ...................................... 1-187
VisualDSP++ 5.0 C/C++ Compiler Manual xv
for SHARC Processors
Contents
Pragmas .............................................................................. 1-187
Data Alignment Pragmas ................................................ 1-189
#pragma align num ..................................................... 1-189
#pragma alignment_region (alignopt) .......................... 1-191
#pragma pack (alignopt ) .............................................. 1-192
#pragma pad (alignopt) ............................................... 1-193
Interrupt Handler Pragmas ............................................. 1-193
#pragma implicit_push_sts_handler ............................ 1-194
#pragma interrupt ...................................................... 1-194
#pragma interrupt_complete_nesting .......................... 1-195
#pragma interrupt_complete ....................................... 1-196
#pragma save_restore_40_bits ..................................... 1-196
#pragma save_restore_simd_40_bits
(SIMD SHARCs Only) ............................................ 1-197
Interrupt Pragmas and the Interrupt Vector Table ........ 1-197
Loop Optimization Pragmas ........................................... 1-198
#pragma SIMD_for .................................................... 1-199
#pragma all_aligned .................................................... 1-199
#pragma no_vectorization ........................................... 1-199
#pragma loop_count (min, max, modulo) .................... 1-200
#pragma loop_unroll N .............................................. 1-200
#pragma no_alias ........................................................ 1-203
#pragma vector_for .................................................... 1-203
xvi VisualDSP++ 5.0 C/C++ Compiler Manual
for SHARC Processors
Contents
General Optimization Pragmas ........................................ 1-204
Function Side-Effect Pragmas .......................................... 1-205
#pragma alloc .............................................................. 1-206
#pragma const ............................................................. 1-206
#pragma misra_func(arg) ............................................. 1-207
#pragma noreturn ....................................................... 1-207
#pragma pgo_ignore .................................................... 1-207
#pragma pure .............................................................. 1-208
#pragma regs_clobbered string .................................... 1-209
#pragma regs_clobbered_call string .............................. 1-213
#pragma overlay .......................................................... 1-217
#pragma result_alignment (n ) ...................................... 1-217
Class Conversion Optimization Pragmas .......................... 1-218
#pragma param_never_null param_name [ ... ] ............ 1-218
#pragma suppress_null_check ...................................... 1-219
Template Instantiation Pragmas ...................................... 1-221
#pragma instantiate instance ........................................ 1-222
#pragma do_not_instantiate instance ........................... 1-223
#pragma can_instantiate instance ................................. 1-223
Header File Control Pragmas ........................................... 1-223
#pragma hdrstop ......................................................... 1-223
#pragma no_implicit_inclusion ................................... 1-224
#pragma no_pch ......................................................... 1-225
VisualDSP++ 5.0 C/C++ Compiler Manual xvii
for SHARC Processors
Contents
Fixed-Point Arithmetic Pragmas ...................................... 1-226
Inline Control Pragmas ................................................... 1-229
#pragma once ............................................................. 1-226
#pragma system_header .............................................. 1-226
#pragma FX_CONTRACT {ON|OFF} ....................... 1-227
#pragma FX_ROUNDING_MODE
{TRUNCATION|BIASED|UNBIASED} ................. 1-227
#pragma STDC FX_FULL_PRECISION
{ON|OFF|DEFAULT} ............................................. 1-228
#pragma STDC FX_FRACT_OVERFLOW
{SAT|DEFAULT} ..................................................... 1-228
#pragma always_inline ................................................ 1-229
#pragma inline ........................................................... 1-230
#pragma never_inline ................................................. 1-230
Linking Control Pragmas ................................................ 1-231
#pragma linkage_name identifier ................................. 1-231
#pragma core .............................................................. 1-231
#pragma retain_name ................................................ 1-236
#pragma section/#pragma default_section ................... 1-238
#pragma file_attr(“name[=value]”
[, “name[=value]” [...]]) ............................................ 1-242
#pragma weak_entry .................................................. 1-243
xviii VisualDSP++ 5.0 C/C++ Compiler Manual
for SHARC Processors
Contents
Diagnostic Control Pragmas ............................................ 1-243
Modifying the Severity of Specific Diagnostics ............. 1-244
Modifying the Behavior of an Entire Class of
Diagnostics .............................................................. 1-245
Saving or Restoring the Current Behavior of All
Diagnostics .............................................................. 1-245
Memory Bank Pragmas ................................................... 1-246
#pragma code_bank(bankname ) ................................... 1-247
#pragma data_bank(bankname) ................................... 1-247
#pragma stack_bank(bankname ) .................................. 1-248
#pragma bank_memory_kind(bankname, kind ) ............ 1-250
#pragma bank_read_cycles(bankname, cycles ) ............... 1-250
#pragma bank_write_cycles(bankname, cycles ) .............. 1-251
#pragma bank_optimal_width(bankname, width ) ......... 1-252
Code Generation Pragmas ............................................... 1-253
#pragma avoid_anomaly_45 {on | off} ......................... 1-253
#pragma no_db_return ................................................ 1-253
Exceptions Table Pragma ................................................. 1-254
#pragma generate_exceptions_tables ............................ 1-254
GCC Compatibility Extensions ........................................... 1-256
Statement Expressions ..................................................... 1-256
Type Reference Support Keyword (Typeof) ...................... 1-258
GCC Generalized Lvalues ............................................... 1-259
Conditional Expressions with Missing Operands .............. 1-259
Zero-Length Arrays ......................................................... 1-260
VisualDSP++ 5.0 C/C++ Compiler Manual xix
for SHARC Processors
Contents
GCC Variable Argument Macros ..................................... 1-260
Line Breaks in String Literals .......................................... 1-260
Arithmetic on Pointers to Void and Pointers to
Cast to Union ................................................................. 1-261
Ranges in Case Labels ..................................................... 1-261
Escape Character Constant ............................................. 1-261
Alignment Inquiry Keyword (__alignof__) ...................... 1-261
Keyword for Specifying Names in Generated
Function, Variable and Type Attribute Keyword
Unnamed struct/union Fields Within struct/unions ......... 1-263
Functions .................................................................... 1-261
Assembler (asm) ........................................................... 1-262
(__attribute__) ............................................................ 1-263
C++ Fractional Type Support .............................................. 1-264
Format of Fractional Literals ........................................... 1-264
Conversions Involving Fractional Values .......................... 1-265
Fractional Arithmetic Operations .................................... 1-265
Mixed Mode Operations ................................................. 1-266
Saturated Arithmetic ........................................................... 1-266
Support for 40-bit Arithmetic ............................................. 1-267
Using 40-bit Arithmetic in Compiled Code ..................... 1-268
Run-Time Library Functions That Use 40-bit
Arithmetic ................................................................... 1-269
Interrupt Support ........................................................... 1-270
xx VisualDSP++ 5.0 C/C++ Compiler Manual
for SHARC Processors
Contents
SIMD Support .................................................................... 1-271
A Brief Introduction to SIMD Mode ............................... 1-271
What the Compiler Can Do Automatically ...................... 1-272
What Prevents the Compiler From Automatically
Exploiting SIMD Mode ................................................ 1-273
How to Help the Compiler Exploit SIMD Mode ............. 1-274
How to Prevent SIMD Code Generation ......................... 1-275
Accessing External Memory on ADSP-2126x and
ADSP-2136x Processors .................................................... 1-275
Link-Time Checking of Data Placement .......................... 1-275
Inline Functions for External Memory Access .................. 1-276
Support for Interrupts ......................................................... 1-276
Interrupt Dispatchers ...................................................... 1-277
Interrupts and Circular Buffering .................................... 1-281
Avoiding Self-Modifying Code ........................................ 1-281
Interrupt Nesting Restrictions on ADSP-211xx/212xx/
213xx/214xx Processors ................................................ 1-282
Restriction on Use of Super-Fast Dispatcher on
ADSP-2106x Processors ............................................... 1-282
Restrictions on Using Normal and Circular Buffer
Interrupt Dispatchers on ADSP-2136x Processors ......... 1-284
Migrating .ldf Files From Previous VisualDSP++
Installations ...................................................................... 1-284
C++ Support Tables (ctor, gdt) ........................................ 1-285
ADSP-21375 Memory Map ............................................ 1-287
VisualDSP++ 5.0 C/C++ Compiler Manual xxi
for SHARC Processors
Contents
C++ Run-Time Libraries Rationalization ......................... 1-288
Fixed-Point I/O Support ................................................. 1-288
Preprocessor Features ................................................................ 1-289
Predefined Preprocessor Macros ........................................... 1-290
Writing Macros ................................................................... 1-297
Compound Macros ......................................................... 1-297
C/C++ Run-Time Model and Environment ............................... 1-300
C/C++ Run-Time Environment ........................................... 1-300
Memory Usage ............................................................... 1-302
Program Memory Code Storage .................................. 1-304
Data Memory Data Storage ......................................... 1-305
Program Memory Data Storage ................................... 1-305
Run-Time Stack Storage ............................................. 1-306
Run-Time Heap Storage ............................................ 1-306
Initialization Data Storage ......................................... 1-307
Run-Time Header Storage ........................................... 1-308
Memory Allocation for Stack and Heap on ADSP-2106x,
ADSP-2116x, and ADSP-2126x Processors .................. 1-310
Example of Heap/Stack Memory Allocation ................ 1-311
Measuring the Performance of the Compiler .................... 1-312
Constructors and Destructors of Global Class Instances ....... 1-313
Constructors, Destructors and Memory Placement .......... 1-314
Support for argv/argc .......................................................... 1-315
xxii VisualDSP++ 5.0 C/C++ Compiler Manual
for SHARC Processors
Contents
Using Multiple Heaps .......................................................... 1-316
Declaring a Heap ............................................................ 1-317
Heap Identifiers .............................................................. 1-319
Allocating C++ STL Objects to a Non-Default Heap ....... 1-319
Using Alternate Heaps With the Standard Interface ......... 1-322
Using the Alternate Heap Interface .................................. 1-323
C++ Run-Time Support for the Alternate Heap
Interface ................................................................... 1-324
Example C Programs ....................................................... 1-325
Compiler Registers ............................................................. 1-327
Miscellaneous Information About Registers ..................... 1-327
User Registers ................................................................. 1-328
Call Preserved Registers ................................................... 1-329
Scratch Registers ............................................................. 1-330
Stack Registers ................................................................ 1-331
Alternate Registers ......................................................... 1-331
Managing the Stack ......................................................... 1-332
Transferring Function Arguments and Return Value ......... 1-338
Passing a C++ Class Instance ........................................... 1-341
Using Data Storage Formats ............................................ 1-341
fract Data Representation ................................................ 1-344
Using the Run-Time Header ........................................... 1-346
VisualDSP++ 5.0 C/C++ Compiler Manual xxiii
for SHARC Processors
Contents
C/C++ and Assembly Interface .................................................. 1-347
Calling Assembly Subroutines From C/C++ Programs .......... 1-347
Calling C/C++ Functions From Assembly Programs ............. 1-350
Using Mixed C/C++ and Assembly Support Macros ......... 1-353
entry .......................................................................... 1-353
exit ............................................................................. 1-353
leaf_entry ................................................................... 1-354
leaf_exit ..................................................................... 1-354
ccall(x) ....................................................................... 1-354
reads(x) ...................................................................... 1-354
puts=x ........................................................................ 1-354
gets(x) ........................................................................ 1-354
alter(x) ....................................................................... 1-355
save_reg ...................................................................... 1-355
restore_reg .................................................................. 1-355
Using Mixed C/C++ and Assembly Naming
Conventions ................................................................ 1-357
Implementing C++ Member Functions in Assembly
Language ..................................................................... 1-359
Writing C/C++ Callable SIMD Subroutines .................... 1-361
C++ Programming Examples ............................................... 1-362
Using Fract Support ........................................................ 1-363
Using Complex Support ................................................. 1-364
xxiv VisualDSP++ 5.0 C/C++ Compiler Manual
for SHARC Processors
Contents
Mixed C/C++/Assembly Programming Examples .................. 1-365
Using Inline Assembly (Add) ........................................... 1-367
Using Macros to Manage the Stack .................................. 1-367
Using Scratch Registers (Dot Product) ............................. 1-369
Using Void Functions (Delay) ......................................... 1-370
Using the Stack for Arguments (Add 5) ........................... 1-372
Using Registers for Arguments and Return (Add 2) .......... 1-373
Using Non-Leaf Routines That Make Calls (RMS) .......... 1-374
Using Call Preserved Registers (Pass Array) ...................... 1-376
Exceptions Tables in Assembly Routines ............................... 1-378
Compiler C++ Template Support ............................................... 1-381
Template Instantiation ......................................................... 1-381
Implicit Instantiation ...................................................... 1-382
Exported Templates ......................................................... 1-383
Generated Template Files ................................................ 1-384
Identifying Un-Instantiated Templates ............................. 1-385
File Attributes ........................................................................... 1-387
Automatically-Applied Attributes ......................................... 1-388
Content Attributes .......................................................... 1-389
FuncName Attributes ...................................................... 1-389
Encoding Attributes ........................................................ 1-390
Default LDF Placement ....................................................... 1-390
VisualDSP++ 5.0 C/C++ Compiler Manual xxv
for SHARC Processors
Contents
Sections Versus Attributes ................................................... 1-391
Granularity ..................................................................... 1-391
“Hard” Versus “Soft” ...................................................... 1-392
Number of Values ........................................................... 1-392
Using Attributes .................................................................. 1-393
Example 1 ...................................................................... 1-393
Example 2 ...................................................................... 1-395
ACHIEVING OPTIMAL PERFORMANCE FROM C/C++
SOURCE CODE
General Guidelines ....................................................................... 2-2
How the Compiler Can Help .................................................. 2-3
Using the Compiler Optimizer ............................................ 2-4
Using Compiler Diagnostics ............................................... 2-4
Warnings and Remarks ................................................... 2-5
Assembly Annotations ..................................................... 2-7
Using the Statistical Profiler ................................................ 2-7
Using Profile-Guided Optimization .................................... 2-8
Using Profile-Guided Optimization With a Simulator ..... 2-8
Using Profile-Guided Optimization With
Non-Simulatable Applications .................................... 2-10
Profile-Guided Optimization and Multiple
Source Uses ............................................................... 2-10
Profile-Guided Optimization and the -Ov Switch .......... 2-11
xxvi VisualDSP++ 5.0 C/C++ Compiler Manual
for SHARC Processors
Contents
Profile-Guided Optimization and Multiple PGO
Data Sets .................................................................... 2-11
When to Use Profile-Guided Optimization .................... 2-12
Using Interprocedural Optimization .................................. 2-12
Data Types ............................................................................ 2-13
Avoiding Emulated Arithmetic .......................................... 2-14
Getting the Most From IPA ................................................... 2-15
Initialize Constants Statically ............................................. 2-16
Dual Word-Aligning Your Data ......................................... 2-17
Using __builtin_aligned .................................................... 2-18
Avoiding Aliases ................................................................ 2-20
Indexed Arrays Versus Pointers ............................................... 2-22
Trying Pointer and Indexed Styles ...................................... 2-23
Using Function Inlining ....................................................... 2-23
Using Inline asm Statements .................................................. 2-24
Memory Usage ...................................................................... 2-25
Improving Conditional Code ...................................................... 2-27
Loop Guidelines ......................................................................... 2-28
Keeping Loops Short ............................................................. 2-28
Avoiding Unrolling Loops ...................................................... 2-29
Avoiding Loop-Carried Dependencies .................................... 2-29
Avoiding Loop Rotation by Hand .......................................... 2-30
Avoiding Complex Array Indexing ......................................... 2-32
Inner Loops vs. Outer Loops .................................................. 2-32
Avoiding Conditional Code in Loops ..................................... 2-33
VisualDSP++ 5.0 C/C++ Compiler Manual xxvii
for SHARC Processors
Contents
Avoiding Placing Function Calls in Loops .............................. 2-34
Avoiding Non-Unit Strides .................................................... 2-34
Loop Control ........................................................................ 2-35
Using the Restrict Qualifier ................................................... 2-36
Avoiding Long Latencies ....................................................... 2-37
Using Built-In Functions in Code Optimization .......................... 2-38
Using System Support Built-In Functions .............................. 2-38
Using Circular Buffers ........................................................... 2-40
Smaller Applications: Optimizing for Code Size .......................... 2-42
Using Pragmas for Optimization ................................................. 2-43
Function Pragmas ................................................................. 2-44
#pragma alloc ................................................................... 2-44
#pragma const .................................................................. 2-45
#pragma pure ................................................................... 2-45
#pragma result_alignment ................................................. 2-45
#pragma regs_clobbered .................................................... 2-46
#pragma optimize_
{off|for_speed|for_space|as_cmd_line} ............................ 2-48
Loop Optimization Pragmas .................................................. 2-49
#pragma loop_count ......................................................... 2-49
#pragma no_vectorization ................................................. 2-50
#pragma vector_for ........................................................... 2-50
#pragma SIMD_for .......................................................... 2-51
#pragma all_aligned .......................................................... 2-51
#pragma no_alias .............................................................. 2-52
xxviii VisualDSP++ 5.0 C/C++ Compiler Manual
for SHARC Processors
Contents
Useful Optimization Switches ...................................................... 2-53
How Loop Optimization Works .................................................. 2-54
Terminology .......................................................................... 2-54
Clobbered Register ............................................................ 2-54
Live Register ..................................................................... 2-55
Spill .................................................................................. 2-55
Scheduling ........................................................................ 2-55
Loop Kernel ...................................................................... 2-56
Loop Prolog ...................................................................... 2-56
Loop Epilog ...................................................................... 2-56
Loop Invariant .................................................................. 2-56
Hoisting ........................................................................... 2-57
Sinking ............................................................................. 2-57
Loop Optimization Concepts ................................................. 2-57
Software Pipelining ........................................................... 2-58
Loop Rotation .................................................................. 2-59
Loop Vectorization ............................................................ 2-61
Modulo Scheduling ........................................................... 2-63
Initiation Interval (II) and the Kernel ............................ 2-65
Minimum Initiation Interval Due to Resources
(Res MII) ................................................................... 2-68
Minimum Initiation Interval Due to Recurrences
(Rec MII) ................................................................... 2-68
Stage Count (SC) .......................................................... 2-69
VisualDSP++ 5.0 C/C++ Compiler Manual xxix
for SHARC Processors
Variable Expansion and MVE Unroll ............................. 2-71
Trip Count ................................................................... 2-76
A Worked Example ............................................................... 2-77
Assembly Optimizer Annotations ................................................ 2-80
Global Information ............................................................... 2-81
Procedure Statistics ............................................................... 2-83
Instruction Annotations ........................................................ 2-88
Loop Identification ............................................................... 2-88
Loop Identification Annotations ....................................... 2-89
File Position ..................................................................... 2-93
Vectorization ......................................................................... 2-96
Loop Flattening ................................................................ 2-97
Vectorization Annotations ................................................. 2-99
Modulo Scheduling Information ......................................... 2-101
Annotations for Modulo Scheduled Instructions .............. 2-101
Warnings, Failure Messages and Advice ................................ 2-107
Analyzing Your Application ....................................................... 2-111
Stack Overflow Detection ................................................... 2-111
The Stack Overflow Detection Facility ............................ 2-113
INDEX
xxx VisualDSP++ 5.0 C/C++ Compiler Manual
for SHARC Processors