W4.5
C/C++ Compiler and Library Manual
for TigerSHARC
Revision 3.0, April 2006
®
Processors
Analog Devices, Inc.
One Technology Way
Norwood, Mass. 02062-9106
Part Number
82-000336-03
a
Copyright Information
©2006 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, 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
CONTENTS
PREFACE
Purpose of This Manual ............................................................ xxxvii
Intended Audience .................................................................... xxxvii
Manual Contents Description .................................................. xxxviii
What’s New in This Manual ..................................................... xxxviii
Technical or Customer Support .................................................. xxxix
Supported Processors ....................................................................... xl
Product Information ....................................................................... xl
MyAnalog.com .......................................................................... xl
Processor Product Information .................................................. xli
Related Documents ................................................................. xlii
Online Technical Documentation ........................................... xliii
Accessing Documentation From VisualDSP++ .................... xliii
Accessing Documentation From Windows ........................... xliv
Accessing Documentation From the Web ............................. xliv
Printed Manuals ....................................................................... xlv
VisualDSP++ Documentation Set ......................................... xlv
VisualDSP++ 4.5 C/C++ Compiler and Library Manual iii
for TigerSHARC Processors
CONTENTS
Hardware Tools Manuals ..................................................... xlv
Processor Manuals ............................................................... xlv
Data Sheets ......................................................................... xlv
Notation Conventions ................................................................. xlvii
COMPILER
C/C++ Compiler Overview ........................................................... 1-3
Compiler Command-Line Interface .............................................. 1-5
Running the Compiler ............................................................ 1-6
Compiler Command-Line Switches ....................................... 1-11
C/C++ Compiler Switch Summaries .................................. 1-11
C/C++ Mode Selection Switch Descriptions ...................... 1-22
-c89 ............................................................................. 1-22
-c++ ............................................................................. 1-22
C/C++ Compiler Common Switch Descriptions ................ 1-23
sourcefile ...................................................................... 1-23
-@ filename .................................................................. 1-23
-A name [(<tokens>)] .................................................... 1-23
-add-debug-libpaths ...................................................... 1-25
-align-branch-lines ........................................................ 1-25
-allow-macs-to-extend-saturation .................................. 1-25
-alttok .......................................................................... 1-25
-always-inline ............................................................... 1-26
-annotate-loop-instr ...................................................... 1-27
-auto-attrs .................................................................... 1-27
iv VisualDSP++ 4.5 C/C++ Compiler and Library Manual
for TigerSHARC Processors
CONTENTS
-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
-Dmacro[=definition] .................................................... 1-29
-debug-types ................................................................. 1-30
-default-branch-{np|p} ................................................... 1-30
-double-size-any ............................................................ 1-31
-double-size-{32 | 64} .................................................... 1-31
-dry .............................................................................. 1-32
-dryrun ......................................................................... 1-32
-E ................................................................................. 1-33
-ED .............................................................................. 1-33
-EE ............................................................................... 1-33
-enum-is-int .................................................................. 1-34
-extra-keywords ............................................................. 1-34
-file-attr name[=value] ................................................... 1-34
-flags-{asm|compiler|lib|link|mem} switch [,switch2 [,...]] 1-35
-force-circbuf ................................................................ 1-35
-fp-associative ............................................................... 1-35
VisualDSP++ 4.5 C/C++ Compiler and Library Manual v
for TigerSHARC Processors
CONTENTS
-fp-div-lib ..................................................................... 1-36
-full-version .................................................................. 1-36
-g ................................................................................. 1-36
-glite ............................................................................ 1-37
-H ................................................................................ 1-37
-HH ............................................................................. 1-37
-h[elp] .......................................................................... 1-37
-I- ................................................................................ 1-38
-I directory [{,|;} directory...] ......................................... 1-38
-implicit-pointers .......................................................... 1-39
-include filename .......................................................... 1-40
-ipa .............................................................................. 1-40
-L directory [{,|;} directory...] ........................................ 1-40
-l library ....................................................................... 1-40
-M ............................................................................... 1-41
-MD ............................................................................ 1-41
-MM ............................................................................ 1-41
-Mo filename ................................................................ 1-42
-Mt name ..................................................................... 1-42
-MQ ............................................................................ 1-42
-map filename .............................................................. 1-42
-mem ........................................................................... 1-42
-multiline ..................................................................... 1-43
-never-inline ................................................................. 1-43
vi VisualDSP++ 4.5 C/C++ Compiler and Library Manual
for TigerSHARC Processors
CONTENTS
-no-align-branch-lines ................................................... 1-43
-no-alttok ..................................................................... 1-43
-no-annotate ................................................................. 1-43
-no-annotate-loop-instr ................................................. 1-44
-no-auto-attrs ................................................................ 1-44
-no-bss .......................................................................... 1-44
-no-builtin .................................................................... 1-45
-no-circbuf .................................................................... 1-45
-no-const-strings ........................................................... 1-45
-no-defs ........................................................................ 1-45
-no-extra-keywords ........................................................ 1-46
-no-fp-associative .......................................................... 1-46
-no-fp-minmax ............................................................. 1-46
-no-mem ....................................................................... 1-47
-no-multiline ................................................................ 1-47
-no-saturation ............................................................... 1-47
-no-std-ass .................................................................... 1-47
-no-std-def .................................................................... 1-47
-no-std-inc .................................................................... 1-48
-no-std-lib .................................................................... 1-48
-no-threads ................................................................... 1-48
-O ................................................................................ 1-48
-O[0|1] ......................................................................... 1-49
-Oa ............................................................................... 1-49
VisualDSP++ 4.5 C/C++ Compiler and Library Manual vii
for TigerSHARC Processors
CONTENTS
-Og .............................................................................. 1-49
-Os ............................................................................... 1-50
-Ov num ...................................................................... 1-50
-o filename ................................................................... 1-52
-overlay ........................................................................ 1-52
-P ................................................................................. 1-52
-PP ............................................................................... 1-53
-path-{ asm | compiler | lib | link | mem } directory ........ 1-53
-path-install directory ................................................... 1-53
-path-output directory .................................................. 1-53
-path-temp directory ..................................................... 1-53
-pch ............................................................................. 1-54
-pchdir directory ........................................................... 1-54
-pedantic ...................................................................... 1-54
-pedantic-errors ............................................................ 1-54
-pgo-session session-id .................................................. 1-55
-pguide ......................................................................... 1-56
-pplist filename ............................................................. 1-56
-proc processor ............................................................. 1-57
-progress-rep-func ......................................................... 1-57
-progress-rep-gen-opt .................................................... 1-58
-progress-rep-mc-opt ..................................................... 1-58
-R directory [{:|,}directory …] ....................................... 1-58
-R- ............................................................................... 1-59
viii VisualDSP++ 4.5 C/C++ Compiler and Library Manual
for TigerSHARC Processors
CONTENTS
-S ................................................................................. 1-59
-s .................................................................................. 1-59
-save-temps ................................................................... 1-59
-section id=section_name[,id=section_name...] .............. 1-60
-show ............................................................................ 1-61
-si-revision version ........................................................ 1-61
-signed-bitfield .............................................................. 1-62
-signed-char .................................................................. 1-62
-structs-do-not-overlap .................................................. 1-62
-syntax-only .................................................................. 1-63
-sysdefs ......................................................................... 1-63
-T filename ................................................................... 1-64
-threads ........................................................................ 1-64
-time ............................................................................ 1-65
-Umacro ....................................................................... 1-65
-unsigned-bitfield .......................................................... 1-65
-unsigned-char .............................................................. 1-66
-v .................................................................................. 1-66
-verbose ........................................................................ 1-66
-version ......................................................................... 1-66
-W {error|remark|suppress|warn} number ....................... 1-67
-Werror-limit number ................................................... 1-67
-Werror-warnings .......................................................... 1-67
-Wremarks .................................................................... 1-67
VisualDSP++ 4.5 C/C++ Compiler and Library Manual ix
for TigerSHARC Processors
CONTENTS
C++ Mode Compiler Switch Descriptions ......................... 1-71
-Wterse ......................................................................... 1-68
-w ................................................................................ 1-68
-warn-protos ................................................................. 1-68
-workaround <workaround>[,<workaround>]* .............. 1-68
-write-files .................................................................... 1-69
-write-opts .................................................................... 1-69
-xref <filename> ............................................................ 1-69
-anach .......................................................................... 1-71
-check-init-order ........................................................... 1-72
-eh ............................................................................... 1-73
-full-dependency-inclusion ............................................ 1-73
-ignore-std .................................................................... 1-75
-no-anach ..................................................................... 1-75
-no-demangle ............................................................... 1-75
-no-eh .......................................................................... 1-75
-no-implicit-inclusion ................................................... 1-75
-no-rtti ......................................................................... 1-75
-rtti .............................................................................. 1-76
Data Types and Data Type Sizes ............................................ 1-77
Integer Data Types ........................................................... 1-78
Floating-Point Data Types ................................................ 1-78
Data Type Alignment ............................................................ 1-79
Environment Variables Used by the Compiler ........................ 1-80
x VisualDSP++ 4.5 C/C++ Compiler and Library Manual
for TigerSHARC Processors
CONTENTS
Optimization Control ............................................................ 1-81
Interprocedural Analysis .................................................... 1-84
Interaction with Libraries .............................................. 1-85
C/C++ Compiler Language Extensions ........................................ 1-87
Byte-Addressing Mode ........................................................... 1-91
sizeof() Operator Types and Sizes ....................................... 1-91
Pointers ............................................................................ 1-92
Alignment of Objects ........................................................ 1-92
Initializations .................................................................... 1-93
Pragmas Used in Byte-Addressing Mode ............................ 1-93
Performance Issues ............................................................ 1-93
Libraries Used in Byte-Addressing Mode ............................ 1-94
Include Files ..................................................................... 1-95
Function Inlining .................................................................. 1-95
Inline Assembly Language Support Keyword (asm) ............... 1-100
Assembly Construct Template ......................................... 1-102
ASM() Construct Syntax: ............................................ 1-102
ASM() Construct Syntax Rules .................................... 1-103
ASM() Construct Template Example ........................... 1-104
Assembly Construct Operand Description ....................... 1-105
Assembly Constructs With Multiple Instructions ............. 1-110
Assembly Construct Reordering and Optimization ........... 1-111
Assembly Constructs With Input and Output Operands .. 1-112
Assembly Constructs and Flow Control ........................... 1-113
VisualDSP++ 4.5 C/C++ Compiler and Library Manual xi
for TigerSHARC Processors
CONTENTS
Guidelines on the Use of asm() Statements ...................... 1-113
64-Bit Integer Support (long long) ...................................... 1-114
Quad-Word Support ........................................................... 1-115
Memory Support Keywords (pm dm) .................................. 1-115
Memory Keyword Rules .................................................. 1-115
__regclass Construct ........................................................... 1-117
Bank Type Qualifiers ........................................................... 1-118
Placement Support Keyword (section) ................................. 1-119
Placement of Compiler-Generated Code and Data ............... 1-120
Boolean Type Support Keywords ......................................... 1-121
Pointer Class Support Keyword (restrict) ............................. 1-121
Variable-Length Array Support ............................................ 1-122
Non-Constant Aggregate Initializer Support ........................ 1-124
Indexed Initializer Support .................................................. 1-124
Compiler Built-In Functions ............................................... 1-126
Using the builtins.h Header File ...................................... 1-127
Optimization Guidance Built-in Functions ..................... 1-129
16-Bit Data Types .......................................................... 1-131
Packed 16-bit Integer Support Using C ....................... 1-132
Constructors (int2x16 values) ..................................... 1-132
Extractors and Expanders (int2x16 values) ................... 1-133
Arithmetic Operators .................................................. 1-133
Bitwise Operators (int2x16 values) .............................. 1-134
Comparison Operators (int2x16 values) ...................... 1-135
xii VisualDSP++ 4.5 C/C++ Compiler and Library Manual
for TigerSHARC Processors
CONTENTS
Sideways Sum (int2x16 values) .................................... 1-135
Constructors (int4x16 values) ...................................... 1-136
Extractors (2x16 from a 4x16 value) ............................ 1-137
Arithmetic Operators (int4x16 values) ......................... 1-138
Sideways Sum (int4x16 values) .................................... 1-139
32-Bit Data Types ........................................................... 1-140
Constructors (int2x32 values) ...................................... 1-140
Extractors (int2x32 values) .......................................... 1-141
Circular Buffer Built-In Functions ................................... 1-142
Circular Buffer Increment of an Index ......................... 1-142
Circular Buffer Increment of a Pointer ......................... 1-142
Math Intrinsics ............................................................... 1-143
RECIPS ...................................................................... 1-144
RSQRTS .................................................................... 1-145
Instructions Generated by Built-in Functions ................... 1-145
Data Alignment Buffer (DAB) Built-in Functions ............ 1-161
Circular Buffer Data Alignment Buffer (DAB) Built-in Functions
1-162
Communications Logic Unit Operations ......................... 1-164
TMAX, TMAX_ADD, TMAX_SUB, MAX_ADD, MAX_SUB
1-165
PERMUTE ................................................................. 1-170
ACS ............................................................................ 1-171
DESPREAD ............................................................... 1-174
XCORRS .................................................................... 1-176
VisualDSP++ 4.5 C/C++ Compiler and Library Manual xiii
for TigerSHARC Processors
CONTENTS
Pragmas .............................................................................. 1-179
Data Alignment Pragmas ................................................ 1-181
#pragma align num ..................................................... 1-182
#pragma alignment_region (alignopt) .......................... 1-183
Interrupt Handler Pragmas ............................................. 1-185
Loop Optimization Pragmas ........................................... 1-187
#pragma all_aligned .................................................... 1-188
#pragma different_banks ............................................. 1-188
#pragma loop_count(min, max, modulo) .................... 1-188
#pragma loop_unroll N .............................................. 1-189
#pragma no_alias ........................................................ 1-191
#pragma no_vectorization ........................................... 1-192
#pragma vector_for ..................................................... 1-192
Function Side-Effect Pragmas ......................................... 1-193
#pragma alloc ............................................................. 1-193
#pragma const ............................................................ 1-194
#pragma noreturn ....................................................... 1-194
#pragma pure ............................................................. 1-194
#pragma regs_clobbered string .................................... 1-195
#pragma regs_clobbered_call string ............................. 1-199
#pragma overlay ......................................................... 1-202
#pragma result_alignment (n) ..................................... 1-203
General Optimization Pragmas ....................................... 1-203
Inline Control Pragmas ................................................... 1-204
xiv VisualDSP++ 4.5 C/C++ Compiler and Library Manual
for TigerSHARC Processors
CONTENTS
#pragma always_inline ................................................ 1-205
#pragma never_inline .................................................. 1-206
Linking Control Pragmas ................................................ 1-206
#pragma linkage_name identifier ................................. 1-206
#pragma core ............................................................. 1-207
#pragma section/#pragma default_section .................... 1-212
#pragma file_attr (name[=value] [, name[=value] [...]]) 1-214
#pragma weak_entry .................................................. 1-215
Class Conversion Optimization Pragmas .......................... 1-216
#pragma param_never_null param_name [ ... ] ............ 1-216
#pragma suppress_null_check ...................................... 1-217
Template Instantiation Pragmas ....................................... 1-219
#pragma instantiate instance ........................................ 1-220
#pragma do_not_instantiate instance ........................... 1-220
#pragma can_instantiate instance ................................. 1-220
Header File Control Pragmas ........................................... 1-221
#pragma hdrstop ......................................................... 1-221
#pragma no_implicit_inclusion ................................... 1-222
#pragma no_pch ......................................................... 1-223
#pragma once ............................................................. 1-223
#pragma system_header ............................................... 1-223
Diagnostic Control Pragmas ............................................ 1-223
Modifying the Severity of Specific Diagnostics ............. 1-224
Modifying the Behavior of an Entire Class of Diagnostics 1-225
VisualDSP++ 4.5 C/C++ Compiler and Library Manual xv
for TigerSHARC Processors
CONTENTS
Saving or Restoring the Current Behavior of All Diagnostics ..
1-225
Memory Bank Pragmas ................................................... 1-226
#pragma code_bank(bankname) .................................. 1-227
#pragma data_bank(bankname) .................................. 1-228
#pragma stack_bank(bankname) ................................. 1-229
#pragma bank_memory_kind(bankname, kind) ........... 1-230
#pragma bank_read_cycles(bankname, cycles) ............. 1-231
#pragma bank_write_cycles(bankname, cycles) ............ 1-231
#pragma bank_optimal_width(bankname, width) ........ 1-232
Increments and Decrements ................................................ 1-233
C++ Style Comments .......................................................... 1-233
C++ Fractional Type Support .............................................. 1-234
Format of Fractional Literals ........................................... 1-234
Conversions Involving Fractional Values .......................... 1-235
Fractional Arithmetic Operations .................................... 1-235
Mixed-Mode Operations ................................................. 1-236
GCC Compatibility Extensions ........................................... 1-237
Statement Expressions .................................................... 1-237
Type Reference Support Keyword (typeof) ...................... 1-238
GCC Generalized Lvalues ............................................... 1-239
Conditional Expressions With Missing Operands ............ 1-240
Hexadecimal Floating-Point Numbers ............................. 1-240
Zero-Length Arrays ........................................................ 1-241
Variable Argument Macros .............................................. 1-241
xvi VisualDSP++ 4.5 C/C++ Compiler and Library Manual
for TigerSHARC Processors
CONTENTS
Line Breaks in String Literals ........................................... 1-242
Arithmetic on Pointers to Void and Pointers to Functions 1-242
Cast to Union ................................................................. 1-242
Ranges in Case Labels ..................................................... 1-242
Declarations Mixed With Code ....................................... 1-243
Escape Character Constant .............................................. 1-243
Alignment Inquiry Keyword (__alignof__) ...................... 1-243
(asm) Keyword for Specifying Names in Generated Assembler 1-244
Function, Variable and Type Attribute Keyword (__attribute__)
1-244
Unnamed struct/union fields within struct/unions ........... 1-245
Preprocessor-Generated Warnings ........................................ 1-245
Preprocessor Features ................................................................ 1-246
Predefined Preprocessor Macros ........................................... 1-246
Writing Macros ................................................................... 1-249
C/C++ Run-Time Model and Environment ............................... 1-252
Stack Frame Overview ......................................................... 1-253
Stack Frame Description ...................................................... 1-255
General System-Wide Specifications ................................ 1-257
At a procedure call, the following must be true: ............ 1-258
Argument Passage ........................................................... 1-259
Return Values ................................................................. 1-260
Procedure Call and Return .............................................. 1-261
To Call a Procedure: .................................................... 1-261
On Entry: ................................................................... 1-261
VisualDSP++ 4.5 C/C++ Compiler and Library Manual xvii
for TigerSHARC Processors
CONTENTS
To Return from a Procedure: ....................................... 1-262
Code Sequences .............................................................. 1-263
Support for argv/argc .......................................................... 1-264
Allocation of Memory for Stacks and Heaps in LDFs ........... 1-265
Example of Heap/Stack Memory Allocation .................... 1-265
Using Multiple Heaps ......................................................... 1-266
Heap Identifiers .............................................................. 1-267
Initializing the Heap ....................................................... 1-268
Using Alternate Heaps with the Standard Interface .......... 1-268
Using the Alternate Heap Interface ................................. 1-269
C++ Run-time Support for the Alternate Heap Interface 1-270
Using the Heap_Install Interface ..................................... 1-271
Miscellaneous Information .................................................. 1-273
Register Classification ......................................................... 1-273
Callee Preserved Registers (“Preserved”) .......................... 1-273
Caller Save Registers (“Scratch”) ...................................... 1-274
ADSP-TS101 and ADSP-TS20x Processor Registers ........ 1-274
C/C++ and Assembly Language Interface .................................. 1-280
Calling Assembly Subroutines From C/C++ Programs .......... 1-280
Calling C/C++ Functions From Assembly Programs ............. 1-283
Using Mixed C/C++ and Assembly Naming Conventions 1-284
C++ Programming Examples ............................................... 1-286
Using Fract Type Support ............................................... 1-286
Using Complex Number Support .................................... 1-287
xviii VisualDSP++ 4.5 C/C++ Compiler and Library Manual
for TigerSHARC Processors
CONTENTS
Compiler C++ Template Support ............................................... 1-289
Template Instantiation ......................................................... 1-289
Identifying Un-instantiated Templates ................................. 1-291
File Attributes ........................................................................... 1-293
Automatically-applied Attributes .......................................... 1-293
Default LDF Placement ....................................................... 1-295
Sections versus Attributes .................................................... 1-295
Granularity ..................................................................... 1-296
“Hard” versus “soft” ........................................................ 1-296
Number of values ............................................................ 1-297
Using attributes ................................................................... 1-297
Example ......................................................................... 1-298
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
Using Profile-Guided Optimization With a Simulator ...... 2-9
VisualDSP++ 4.5 C/C++ Compiler and Library Manual xix
for TigerSHARC Processors
CONTENTS
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-11
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-15
Getting the Most From IPA ................................................... 2-16
Initialize Constants Statically ............................................ 2-17
Quad-Word-Aligning Your Data ....................................... 2-18
Using __builtin_aligned ................................................... 2-18
Avoiding Aliases ............................................................... 2-20
Indexed Arrays Versus Pointers .............................................. 2-22
Trying Pointer and Indexed Styles ..................................... 2-23
Function Inlining .................................................................. 2-23
Using Inline asm Statements .................................................. 2-24
Memory Usage ...................................................................... 2-25
Putting Arrays into Different Memory Sections ................. 2-25
Using the Bank Qualifier .................................................. 2-28
Improving Conditional Code ...................................................... 2-28
Loop Guidelines ......................................................................... 2-29
Keeping Loops Short ............................................................. 2-29
Avoiding Unrolling Loops ..................................................... 2-30
xx VisualDSP++ 4.5 C/C++ Compiler and Library Manual
for TigerSHARC Processors
CONTENTS
Avoiding Loop-Carried Dependencies .................................... 2-30
Avoiding Loop Rotation by Hand .......................................... 2-31
Avoiding Array Writes in Loops ............................................. 2-33
Inner Loops Versus Outer Loops ............................................ 2-33
Avoiding Conditional Code in Loops ..................................... 2-34
Avoiding Placing Function Calls in Loops .............................. 2-35
Avoiding Non-Unit Strides ................................................... 2-35
Loop Control ........................................................................ 2-36
Using the Restrict Qualifier ................................................... 2-37
Using the Const Qualifier ...................................................... 2-38
Avoiding Long Latencies ........................................................ 2-38
Using Built-In Functions in Code Optimization .......................... 2-40
Using Fractional Data ............................................................ 2-40
System Support Built-in Functions ......................................... 2-41
Using Circular Buffers ........................................................... 2-42
Smaller Applications: Optimizing for Code Size ........................... 2-44
Using Pragmas for Optimization .................................................. 2-46
Function Pragmas .................................................................. 2-46
#pragma const .................................................................. 2-46
#pragma pure .................................................................... 2-47
#pragma regs_clobbered .................................................... 2-47
#pragma optimize_{off|for_speed|for_space} ...................... 2-49
Loop Optimization Pragmas .................................................. 2-49
#pragma loop_count ......................................................... 2-49
VisualDSP++ 4.5 C/C++ Compiler and Library Manual xxi
for TigerSHARC Processors
CONTENTS
#pragma no_vectorization ................................................. 2-50
#pragma vector_for ........................................................... 2-50
#pragma all_aligned .......................................................... 2-51
#pragma different_banks .................................................. 2-53
#pragma no_alias .............................................................. 2-53
Useful Optimization Switches ..................................................... 2-54
How Loop Optimization Works .................................................. 2-55
Terminology ......................................................................... 2-55
Clobbered ........................................................................ 2-55
Live .................................................................................. 2-56
Spill ................................................................................. 2-56
Scheduling ....................................................................... 2-56
Loop kernel ...................................................................... 2-56
Loop prolog ..................................................................... 2-57
Loop epilog ...................................................................... 2-57
Loop invariant .................................................................. 2-57
Hoisting ........................................................................... 2-57
Sinking ............................................................................ 2-58
Loop Optimization Concepts ................................................ 2-58
Software pipelining ........................................................... 2-59
Loop Rotation .................................................................. 2-59
Loop Vectorization ........................................................... 2-62
Modulo Scheduling .......................................................... 2-64
Variable expansion ........................................................ 2-66
xxii VisualDSP++ 4.5 C/C++ Compiler and Library Manual
for TigerSHARC Processors
CONTENTS
A Worked Example ................................................................ 2-69
Assembly Optimizer Annotations ................................................ 2-72
Global Information ............................................................... 2-74
Procedure Statistics ................................................................ 2-75
Loop Identification ................................................................ 2-79
Loop Identification Annotations ........................................ 2-80
File Position ...................................................................... 2-84
Vectorization ......................................................................... 2-85
Unroll and Jam ................................................................. 2-87
Loop Flattening ................................................................ 2-89
Vectorization Annotations ................................................. 2-90
Modulo Scheduling ............................................................... 2-92
Warnings, Failure Messages and Advice ................................ 2-100
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
Linking Library Functions ....................................................... 3-5
Working With Library Source Code ......................................... 3-8
Working With Library Header Files ......................................... 3-9
assert.h ............................................................................. 3-11
ctype.h ............................................................................. 3-11
cycle_count.h .................................................................... 3-11
cycles.h ............................................................................. 3-12
VisualDSP++ 4.5 C/C++ Compiler and Library Manual xxiii
for TigerSHARC Processors
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-15
math.h ............................................................................. 3-15
setjmp.h ........................................................................... 3-16
signal.h ............................................................................ 3-16
stdarg.h ............................................................................ 3-17
stddef.h ............................................................................ 3-17
stdio.h .............................................................................. 3-17
stdlib.h ............................................................................. 3-20
string.h ............................................................................ 3-20
time.h .............................................................................. 3-21
DSP Header Files .................................................................. 3-22
complex.h – Basic Complex Arithmetic Functions ............. 3-23
filter.h – DSP Filters and Transformations ......................... 3-24
libsim.h – Simulator Services ............................................ 3-25
matrix.h – Matrix Functions ............................................. 3-26
stats.h – Statistical Functions ............................................ 3-27
vector.h – Vector Functions ............................................... 3-28
window.h – Window Generators ....................................... 3-29
xxiv VisualDSP++ 4.5 C/C++ Compiler and Library Manual
for TigerSHARC Processors
Calling Library Functions from an ISR .................................. 3-31
Abridged C++ Library Support .............................................. 3-32
Embedded C++ Library Header Files ................................. 3-32
complex ........................................................................ 3-32
exception ...................................................................... 3-33
fract .............................................................................. 3-33
fstream .......................................................................... 3-33
iomanip ........................................................................ 3-33
ios ................................................................................ 3-33
iosfwd ........................................................................... 3-34
iostream ........................................................................ 3-34
istream .......................................................................... 3-34
new .............................................................................. 3-34
ostream ......................................................................... 3-34
sstream ......................................................................... 3-34
stdexcept ....................................................................... 3-34
streambuf ...................................................................... 3-35
string ............................................................................ 3-35
strstream ....................................................................... 3-35
C++ Header Files for C Library Facilities ........................... 3-35
Embedded Standard Template Library Header Files ........... 3-36
algorithm ...................................................................... 3-36
deque ............................................................................ 3-37
functional ..................................................................... 3-37
VisualDSP++ 3.0 C/C++ Compiler and Library Manual for TigerSHARC DSPs xxv
hash_map ..................................................................... 3-37
hash_set ....................................................................... 3-37
iterator ......................................................................... 3-37
list ................................................................................ 3-37
map .............................................................................. 3-37
memory ........................................................................ 3-37
numeric ........................................................................ 3-37
queue ........................................................................... 3-38
set ................................................................................ 3-38
stack ............................................................................. 3-38
utility ........................................................................... 3-38
vector ........................................................................... 3-38
fstream.h ...................................................................... 3-38
iomanip.h ..................................................................... 3-38
iostream.h .................................................................... 3-38
new.h ........................................................................... 3-39
Using the Thread-Safe C/C++ Run-Time Libraries with VDK 3-39
Measuring Cycle Counts ....................................................... 3-39
Basic Cycle Counting Facility ............................................ 3-40
Cycle Counting Facility with Statistics .............................. 3-41
Using time.h to Measure Cycle Counts .............................. 3-44
Determining the Processor Clock Rate .............................. 3-46
Considerations When Measuring Cycle Counts ................. 3-47
File I/O Support ................................................................... 3-49
xxvi VisualDSP++ 4.5 C/C++ Compiler and Library Manual
for TigerSHARC Processors
Extending I/O Support To New Devices ............................ 3-50
DevEntry Structure ....................................................... 3-50
Registering New Devices ............................................... 3-55
Pre-Registering Devices ................................................. 3-56
Default Device .............................................................. 3-57
Remove and Rename Functions ..................................... 3-58
Default Device Driver Interface ......................................... 3-58
Data Packing For Primitive I/O ..................................... 3-60
Data Structure for Primitive I/O .................................... 3-60
Documented Library Functions ................................................... 3-65
Run-Time Library Reference ....................................................... 3-69
a_compress ................................................................................. 3-70
a_expand .................................................................................... 3-71
abs .............................................................................................. 3-72
acos ............................................................................................ 3-73
addbitrev .................................................................................... 3-74
alog ............................................................................................ 3-75
alog10 ........................................................................................ 3-77
arg .............................................................................................. 3-79
asctime ....................................................................................... 3-80
asin ............................................................................................. 3-82
atan ............................................................................................ 3-83
atan2 .......................................................................................... 3-84
atof ............................................................................................. 3-85
VisualDSP++ 3.0 C/C++ Compiler and Library Manual for TigerSHARC DSPs xxvii
atoi ............................................................................................ 3-87
atol ............................................................................................ 3-88
atold .......................................................................................... 3-89
atoll ........................................................................................... 3-91
autocoh ...................................................................................... 3-92
autocorr ..................................................................................... 3-93
avg ............................................................................................. 3-94
bsearch ....................................................................................... 3-95
cabs ............................................................................................ 3-97
cadd ........................................................................................... 3-98
cartesian ..................................................................................... 3-99
cdiv .......................................................................................... 3-101
ceil ........................................................................................... 3-102
cexp ......................................................................................... 3-103
cfft ........................................................................................... 3-104
cfft_mag ................................................................................... 3-107
cfft2d ....................................................................................... 3-109
cfftf .......................................................................................... 3-111
clearerr ..................................................................................... 3-113
clip .......................................................................................... 3-114
clock ........................................................................................ 3-115
cmatmadd ................................................................................ 3-117
cmatmmlt ................................................................................ 3-119
cmatmsub ................................................................................ 3-121
xxviii VisualDSP++ 4.5 C/C++ Compiler and Library Manual
for TigerSHARC Processors
cmatsadd .................................................................................. 3-123
cmatsmlt ................................................................................... 3-124
cmatssub ................................................................................... 3-126
cmlt .......................................................................................... 3-128
conj .......................................................................................... 3-129
convolve ................................................................................... 3-130
conv2d ..................................................................................... 3-132
copysign ................................................................................... 3-134
cos ............................................................................................ 3-135
cosh .......................................................................................... 3-136
cot ............................................................................................ 3-137
count_ones ............................................................................... 3-138
crosscoh .................................................................................... 3-139
crosscorr ................................................................................... 3-140
csub .......................................................................................... 3-141
ctime ........................................................................................ 3-142
cvecdot ..................................................................................... 3-143
cvecsadd ................................................................................... 3-144
cvecsmlt .................................................................................... 3-145
cvecssub .................................................................................... 3-146
cvecvadd ................................................................................... 3-147
cvecvmlt ................................................................................... 3-148
cvecvsub ................................................................................... 3-149
difftime .................................................................................... 3-150
VisualDSP++ 3.0 C/C++ Compiler and Library Manual for TigerSHARC DSPs xxix
div ........................................................................................... 3-152
exp ........................................................................................... 3-153
__emuclk ................................................................................. 3-154
fabs .......................................................................................... 3-155
favg .......................................................................................... 3-156
fclip ......................................................................................... 3-157
fclose ........................................................................................ 3-158
feof .......................................................................................... 3-159
ferror ........................................................................................ 3-160
fir ............................................................................................ 3-161
fir_decima ................................................................................ 3-163
fir_interp .................................................................................. 3-166
fflush ....................................................................................... 3-172
fgetc ......................................................................................... 3-173
fgetpos ..................................................................................... 3-174
fgets ......................................................................................... 3-176
floor ......................................................................................... 3-178
fmax ......................................................................................... 3-179
fmin ......................................................................................... 3-180
fmod ........................................................................................ 3-181
fopen ....................................................................................... 3-182
fprintf ...................................................................................... 3-184
fputc ........................................................................................ 3-190
fputs ........................................................................................ 3-191
xxx VisualDSP++ 4.5 C/C++ Compiler and Library Manual
for TigerSHARC Processors