W4.0
C/C++ Compiler and Library Manual
for SHARC
Revision 5.0, January 2005
®
Processors
Analog Devices, Inc.
One Technology Way
Norwood, Mass. 02062-9106
Part Number
82-001963-01
a
Copyright Information
©2005 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, and EZ-KIT Lite are registered trademarks of Analog Devices,
Inc.
All other brand and product names are trademarks or service marks of
their respective owners.
CONTENTS
PREFACE
Purpose of This Manual ............................................................... xxxi
Intended Audience ....................................................................... xxxi
Manual Contents ........................................................................ xxxii
What’s New in This Manual ....................................................... xxxiii
Technical or Customer Support .................................................. xxxiii
Supported Processors .................................................................. xxxiv
Product Information .................................................................. xxxiv
MyAnalog.com ..................................................................... xxxiv
Processor Product Information ............................................... xxxv
Related Documents .............................................................. xxxvi
Online Technical Documentation ........................................ xxxvii
Accessing Documentation From VisualDSP++ ................. xxxvii
Accessing Documentation From Windows ...................... xxxviii
Accessing Documentation From the Web ........................ xxxviii
Printed Manuals ................................................................... xxxix
VisualDSP++ Documentation Set ..................................... xxxix
Hardware Tools Manuals .................................................. xxxix
Processor Manuals ............................................................ xxxix
VisualDSP++ 4.0 C/C++ Compiler and Library Manual iii
for SHARC Processors
CONTENTS
Data Sheets ...................................................................... xxxix
Notation Conventions ..................................................................... xl
COMPILER
C/C++ Compiler Overview ........................................................... 1-2
Compiler Command-Line Interface .............................................. 1-4
Running the Compiler ............................................................ 1-5
Specifying Compiler Options in VisualDSP++ ......................... 1-9
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
-aligned-stack ............................................................... 1-24
-alttok .......................................................................... 1-24
-annotate-loop-instr ...................................................... 1-25
-bss .............................................................................. 1-25
-build-lib ...................................................................... 1-25
-C ................................................................................ 1-25
-c ................................................................................. 1-26
-compatible-pm-dm ...................................................... 1-26
iv VisualDSP++ 4.0 C/C++ Compiler and Library Manual
for SHARC Processors
CONTENTS
-const-read-write ........................................................... 1-26
-Dmacro[=definition] .................................................... 1-26
-debug-types ................................................................. 1-26
-default-linkage[-asm | -C | -C++] .................................. 1-27
-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
-extra-keywords ............................................................. 1-29
-flags-{asm|compiler|lib|link|mem} switch [,switch2 [,...]] 1-29
-float-to-int ................................................................... 1-30
-force-circbuf ................................................................ 1-30
-fp-associative ............................................................... 1-30
-full-version .................................................................. 1-30
-g .................................................................................. 1-31
-H ................................................................................ 1-31
-HH ............................................................................. 1-31
-h[elp] .......................................................................... 1-32
-I directory [{,|;} directory...] ......................................... 1-32
-I- ................................................................................. 1-32
-i .................................................................................. 1-33
VisualDSP++ 4.0 C/C++ Compiler and Library Manual v
for SHARC Processors
CONTENTS
-include filename .......................................................... 1-33
-ipa .............................................................................. 1-33
-L directory[{;|,}directory…] ......................................... 1-34
-l library ....................................................................... 1-34
-M ............................................................................... 1-35
-MD ............................................................................ 1-35
-MM ............................................................................ 1-35
-Mo _filename_ ............................................................ 1-35
-Mt filename ................................................................ 1-35
-MQ ............................................................................ 1-36
-map filename .............................................................. 1-36
-mem ........................................................................... 1-36
-multiline ..................................................................... 1-36
-no-aligned-stack .......................................................... 1-36
-no-alttok ..................................................................... 1-36
-no-annotate ................................................................. 1-37
-no-annotate-loop-instr ................................................. 1-37
-no-bss ......................................................................... 1-37
-no-builtin ................................................................... 1-37
-no-circbuf ................................................................... 1-38
-no-db .......................................................................... 1-38
-no-defs ........................................................................ 1-38
-no-extra-keywords ....................................................... 1-38
-no-fp-associative .......................................................... 1-38
vi VisualDSP++ 4.0 C/C++ Compiler and Library Manual
for SHARC Processors
CONTENTS
-no-mem ....................................................................... 1-39
-no-multiline ................................................................ 1-39
-no-saturation ............................................................... 1-39
-no-simd ....................................................................... 1-39
-no-std-ass .................................................................... 1-39
-no-std-def .................................................................... 1-40
-no-std-inc .................................................................... 1-40
-no-std-lib .................................................................... 1-40
-no-threads ................................................................... 1-40
-O[0|1] ......................................................................... 1-40
-Oa ............................................................................... 1-41
-Og ............................................................................... 1-41
-Os ............................................................................... 1-41
-Ov num ....................................................................... 1-41
-o filename .................................................................... 1-42
-P ................................................................................. 1-42
-PP ............................................................................... 1-42
-path-{ asm | compiler | lib | link | mem } directory ........ 1-42
-path-install directory .................................................... 1-42
-path-output directory ................................................... 1-43
-path-temp directory ..................................................... 1-43
-pch .............................................................................. 1-43
-pchdir directory ........................................................... 1-43
-pedantic ...................................................................... 1-43
VisualDSP++ 4.0 C/C++ Compiler and Library Manual vii
for SHARC Processors
CONTENTS
-pedantic-errors ............................................................ 1-44
-pguide ......................................................................... 1-44
-pplist filename ............................................................. 1-44
-proc processor ............................................................. 1-45
-progress-rep-func ......................................................... 1-45
-progress-rep-gen-opt .................................................... 1-45
-progress-rep-mc-opt ..................................................... 1-46
-R directory[{:|,}directory …] ........................................ 1-46
-R- ............................................................................... 1-47
-reserve register[, register …] ......................................... 1-47
-restrict-hardware-loops <maximum> ............................ 1-47
-S ................................................................................. 1-47
-s .................................................................................. 1-48
-save-temps ................................................................... 1-48
-section <id>=<section_name>[,<id>=section_name>] ... 1-48
-show ........................................................................... 1-48
-si-revision version ........................................................ 1-49
-signed-bitfield ............................................................. 1-50
-signed-char .................................................................. 1-50
-structs-do-not-overlap ................................................. 1-51
-switch-pm ................................................................... 1-51
-syntax-only .................................................................. 1-51
-sysdefs ......................................................................... 1-52
-T filename .................................................................. 1-52
viii VisualDSP++ 4.0 C/C++ Compiler and Library Manual
for SHARC Processors
CONTENTS
-threads ........................................................................ 1-52
-time ............................................................................ 1-53
-Umacro ....................................................................... 1-53
-unsigned-bitfield .......................................................... 1-53
-unsigned-char .............................................................. 1-54
-v .................................................................................. 1-54
-verbose ........................................................................ 1-54
-version ......................................................................... 1-54
-W[error|remark|suppress|warn] number[,number ...] ..... 1-55
-Wdriver-limit number .................................................. 1-55
-Werror-limit number ................................................... 1-55
-Wremarks .................................................................... 1-55
-Wterse ......................................................................... 1-55
-w ................................................................................. 1-56
-warn-protos ................................................................. 1-56
-workaround <workaround>[,<workaround>]* ............... 1-56
-write-files .................................................................... 1-56
-write-opts .................................................................... 1-57
-xref <filename> ............................................................ 1-57
C++ Mode Compiler Switch Descriptions .......................... 1-58
-anach ........................................................................... 1-58
-eh ................................................................................ 1-59
-no-anach ..................................................................... 1-60
-no-demangle ................................................................ 1-60
VisualDSP++ 4.0 C/C++ Compiler and Library Manual ix
for SHARC Processors
CONTENTS
-no-eh .......................................................................... 1-60
-no-implicit-inclusion ................................................... 1-60
-no-rtti ......................................................................... 1-60
-rtti .............................................................................. 1-61
Data Type and Data Type Sizes .............................................. 1-61
Integer Data Types ........................................................... 1-62
Floating-Point Data Types ................................................ 1-62
Environment Variables Used by the Compiler ........................ 1-63
Optimization Control ........................................................... 1-64
Interprocedural Analysis ................................................... 1-67
Interaction with Libraries .............................................. 1-68
C/C++ Compiler Language Extensions ........................................ 1-70
Inline Function Support Keyword (inline) ............................. 1-74
Inline Assembly Language Support Keyword (asm) ................ 1-75
Assembly Construct Template ........................................... 1-77
asm() Construct Syntax Rules ....................................... 1-78
asm() Construct Template Example ............................... 1-79
Assembly Construct Operand Description ......................... 1-80
Assembly Constructs With Multiple Instructions ............... 1-86
Assembly Construct Reordering and Optimization ............ 1-87
Assembly Constructs With Input and Output Operands .... 1-87
Assembly Constructs and Flow Control ............................. 1-88
Guildelines on the Use of asm() Statements ....................... 1-89
Dual Memory Support Keywords (pm dm) ............................ 1-90
x VisualDSP++ 4.0 C/C++ Compiler and Library Manual
for SHARC Processors
CONTENTS
Memory Keywords and Assignments/Type Conversions ...... 1-92
Memory Keywords and Function Declarations/Pointers ..... 1-93
Memory Keywords and Function Arguments ..................... 1-93
Memory Keywords and Macros ......................................... 1-94
Placement Support Keyword (section) .................................... 1-95
Placement of Compiler-Generated Data ................................. 1-95
Boolean Type Support Keywords (bool, true, false) ................. 1-96
Pointer Class Support Keyword (restrict) ................................ 1-96
Variable-Length Array Support .............................................. 1-97
Non-Constant Initializer Support .......................................... 1-99
Indexed Initializer Support .................................................... 1-99
Aggregate Constructor Expression Support ........................... 1-101
Preprocessor Generated Warnings ........................................ 1-102
C++ Style Comments ........................................................... 1-102
Compiler Built-In Functions ................................................ 1-102
Access to System Registers ............................................... 1-103
Circular Buffer Built-In Functions ................................... 1-107
Circular Buffer Increment of an Index ......................... 1-107
Circular Buffer Increment of a Pointer ......................... 1-107
Compiler Performance Built-in Functions ........................ 1-108
Pragmas .............................................................................. 1-110
Data Alignment Pragmas ................................................. 1-111
#pragma align num ..................................................... 1-112
#pragma alignment_region (alignopt) .......................... 1-113
VisualDSP++ 4.0 C/C++ Compiler and Library Manual xi
for SHARC Processors
CONTENTS
Interrupt Handler Pragma ............................................... 1-115
Loop Optimization Pragmas ........................................... 1-116
General Optimization Pragmas ....................................... 1-119
Function Side-Effect Pragmas ......................................... 1-120
#pragma pack (alignopt) ............................................. 1-114
#pragma pad (alignopt) ............................................... 1-114
#pragma SIMD_for .................................................... 1-116
#pragma all_aligned .................................................... 1-117
#pragma no_vectorization ........................................... 1-117
#pragma loop_count(min, max, modulo) .................... 1-117
#pragma no_alias ........................................................ 1-118
#pragma vector_for ..................................................... 1-118
#pragma alloc ............................................................. 1-121
#pragma const ............................................................ 1-121
#pragma noreturn ....................................................... 1-122
#pragma pure ............................................................. 1-122
#pragma regs_clobbered string .................................... 1-123
#pragma result_alignment (n) ..................................... 1-127
Template Instantiation Pragmas ...................................... 1-127
#pragma instantiate instance ....................................... 1-128
#pragma do_not_instantiate instance .......................... 1-128
#pragma can_instantiate instance ................................ 1-129
Header File Control Pragmas .......................................... 1-129
#pragma hdrstop ........................................................ 1-129
xii VisualDSP++ 4.0 C/C++ Compiler and Library Manual
for SHARC Processors
CONTENTS
#pragma no_implicit_inclusion ................................... 1-130
#pragma no_pch ......................................................... 1-131
#pragma once ............................................................. 1-131
#pragma system_header ............................................... 1-132
Linking Control Pragmas ................................................ 1-132
#pragma linkage_name identifier ................................. 1-132
#pragma retain_name .................................................. 1-132
#pragma section/#pragma default_section .................... 1-133
#pragma weak_entry .................................................. 1-135
Diagnostic Control Pragmas ............................................ 1-135
Modifying the Severity of Specific Diagnostics ............. 1-135
Modifying the Behavior of an Entire Class of Diagnostics 1-136
Saving or Restoring the Current Behavior of All Diagnostics ..
1-137
Code Generation Pragmas ............................................... 1-138
GCC Compatibility Extensions ........................................... 1-138
Statement Expressions ..................................................... 1-138
Type Reference Support Keyword (Typeof) ...................... 1-140
GCC Generalized Lvalues ............................................... 1-141
Conditional Expressions with Missing Operands .............. 1-141
Hexadecimal Floating-Point Numbers ............................. 1-142
Zero-Length Arrays ......................................................... 1-142
Variable Argument Macros .............................................. 1-143
Line Breaks in String Literals ........................................... 1-143
Arithmetic on Pointers to Void and Pointers to Functions 1-143
VisualDSP++ 4.0 C/C++ Compiler and Library Manual xiii
for SHARC Processors
CONTENTS
Cast to Union ................................................................. 1-144
Ranges in Case Labels ..................................................... 1-144
Declarations Mixed With Code ....................................... 1-144
Escape Character Constant ............................................. 1-145
Alignment Inquiry Keyword (__alignof__) ...................... 1-145
Keyword for Specifying Names in Generated Assembler (asm) 1-145
Function, Variable and Type Attribute Keyword (__attribute__)
1-146
C++ Fractional Type Support .............................................. 1-146
Format of Fractional Literals ........................................... 1-147
Conversions Involving Fractional Values .......................... 1-147
Fractional Arithmetic Operations .................................... 1-148
Mixed Mode Operations ................................................. 1-148
Saturated Arithmetic ........................................................... 1-149
SIMD Support .................................................................... 1-150
Using SIMD Mode with Multichannel Data .................... 1-151
Using SIMD Mode with Single-Channel Data ................. 1-152
Restrictions to Using SIMD ............................................ 1-154
SIMD_for Pragma Syntax ............................................... 1-155
Compiler Constraints on Using SIMD C/C++ ................ 1-157
Impact of Anomaly #40 on SIMD ................................... 1-158
Performance When Using SIMD C/C++ ......................... 1-159
Examples Using SIMD C ................................................ 1-160
Using SIMD C (Problem Cases—Data Increments) ..... 1-160
Using SIMD C (Problem Cases—Data Alignment) ...... 1-162
xiv VisualDSP++ 4.0 C/C++ Compiler and Library Manual
for SHARC Processors
CONTENTS
Preprocessor Features ................................................................ 1-165
Predefined Preprocessor Macros ........................................... 1-166
__2106x__ ..................................................................... 1-166
__2116x__ ..................................................................... 1-166
__2126x__ ..................................................................... 1-166
__2136x__ ..................................................................... 1-166
__ADSP21000__ ............................................................ 1-166
__ADSP21020__ ............................................................ 1-167
__ADSP21060__ ............................................................ 1-167
__ADSP21061__ ............................................................ 1-167
__ADSP21062__ ............................................................ 1-167
__ADSP21065L__ .......................................................... 1-167
__ADSP21160__ ............................................................ 1-167
__ADSP21161__ ............................................................ 1-167
__ADSP21261__ ............................................................ 1-168
__ADSP21262__ ............................................................ 1-168
__ADSP21266__ ............................................................ 1-168
__ADSP21267__ ............................................................ 1-168
__ADSP21363__ ............................................................ 1-168
__ADSP21364__ ............................................................ 1-168
__ADSP21365__ ............................................................ 1-168
__ADSP21366__ ............................................................ 1-169
__ADSP21367__ ............................................................ 1-169
__ADSP21368__ ............................................................ 1-169
VisualDSP++ 4.0 C/C++ Compiler and Library Manual xv
for SHARC Processors
CONTENTS
__ADSP21369__ ........................................................... 1-169
__ANALOG_EXTENSIONS__ ..................................... 1-169
__cplusplus .................................................................... 1-169
__DATE__ .................................................................... 1-169
__DOUBLES_ARE_FLOATS__ .................................... 1-170
__ECC__ ....................................................................... 1-170
__EDG__ ...................................................................... 1-170
__EDG_VERSION__ .................................................... 1-170
__FILE__ ....................................................................... 1-170
__LINE__ ...................................................................... 1-170
_NO_LONGLONG ...................................................... 1-170
__NO_BUILTIN ........................................................... 1-171
__SIGNED_CHARS__ .................................................. 1-171
__SIMDSHARC__ ........................................................ 1-171
__STDC__ .................................................................... 1-171
__STDC_VERSION__ .................................................. 1-171
__TIME__ ..................................................................... 1-171
__VERSION__ .............................................................. 1-171
__VERSIONNUM__ ..................................................... 1-172
__WORKAROUNDS_ENABLED ................................. 1-172
Writing Macros ................................................................... 1-172
C/C++ Run-Time Model and Environment ............................... 1-175
C/C++ Run-Time Environment ........................................... 1-175
Memory Usage ............................................................... 1-177
xvi VisualDSP++ 4.0 C/C++ Compiler and Library Manual
for SHARC Processors
CONTENTS
Measuring the Performance of C Compiler ...................... 1-183
Support for argv/argc ........................................................... 1-185
Using Multiple Heaps .......................................................... 1-185
Declaring a Heap ............................................................ 1-186
Heap Identifiers .............................................................. 1-189
Using Alternate Heaps with the Standard Interface ........... 1-189
Using the Alternate Heap Interface .................................. 1-190
Example C Programs ....................................................... 1-191
Compiler Registers .............................................................. 1-192
Miscellaneous Information About Registers ..................... 1-193
User Registers ................................................................. 1-193
Call Preserved Registers ................................................... 1-194
Scratch Registers ............................................................. 1-195
Stack Registers ................................................................ 1-196
Alternate Registers .......................................................... 1-196
Managing the Stack ......................................................... 1-197
Transferring Function Arguments and Return Value ......... 1-202
Using Data Storage Formats ............................................ 1-205
Using the Run-Time Header ........................................... 1-208
C/C++ and Assembly Interface .................................................. 1-209
Calling Assembly Subroutines from C/C++ Programs ........... 1-209
Calling C/C++ Functions from Assembly Programs .............. 1-211
Using Mixed C/C++ and Assembly Support Macros ......... 1-214
entry ........................................................................... 1-214
VisualDSP++ 4.0 C/C++ Compiler and Library Manual xvii
for SHARC Processors
CONTENTS
Using Mixed C/C++ and Assembly Naming Conventions 1-218
Implementing C++ Member Functions in Assembly Language 1-220
exit ............................................................................. 1-214
leaf_entry ................................................................... 1-215
leaf_exit ..................................................................... 1-215
ccall(x) ....................................................................... 1-215
reads(x) ...................................................................... 1-215
puts=x ........................................................................ 1-215
gets(x) ........................................................................ 1-215
alter(x) ....................................................................... 1-216
save_reg ...................................................................... 1-216
restore_reg .................................................................. 1-216
Writing C/C++ Callable SIMD Subroutines .................... 1-222
C++ Programming Examples ............................................... 1-223
Using Fract Support ........................................................ 1-223
Using Complex Support ................................................. 1-224
Mixed C/C++/Assembly Programming Examples ................. 1-226
Using Inline Assembly (Add) .......................................... 1-227
Using Macros to Manage the Stack .................................. 1-228
Using Scratch Registers (Dot Product) ............................ 1-229
Using Void Functions (Delay) ......................................... 1-231
Using the Stack for Arguments and Return (Add 5) ......... 1-232
Using Registers for Arguments and Return (Add 2) ......... 1-233
Using Non-Leaf Routines That Make Calls (RMS) .......... 1-234
xviii VisualDSP++ 4.0 C/C++ Compiler and Library Manual
for SHARC Processors
CONTENTS
Using Call Preserved Registers (Pass Array) ...................... 1-236
Compiler C++ Template Support ............................................... 1-238
Template Instantiation ......................................................... 1-238
Identifying Uninstantiated Templates ................................... 1-239
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 the Statistical Profiler ............................................... 2-5
Using Profile-Guided Optimization ..................................... 2-6
Using Interprocedural Optimization .................................... 2-7
Data Types .............................................................................. 2-8
Avoiding Emulated Arithmetic ............................................ 2-9
Getting the Most From IPA ................................................... 2-10
Initialize Constants Statically ............................................. 2-10
Dual Word-Aligning Your Data ......................................... 2-11
Using __builtin_aligned .................................................... 2-12
Avoiding Aliases ................................................................ 2-13
Indexed Arrays Versus Pointers ............................................... 2-15
Trying Pointer and Indexed Styles ...................................... 2-16
Function Inlining .................................................................. 2-16
Using Inline asm Statements .................................................. 2-18
Memory Usage ...................................................................... 2-19
VisualDSP++ 4.0 C/C++ Compiler and Library Manual xix
for SHARC Processors
CONTENTS
Improving Conditional Code ...................................................... 2-21
Loop Guidelines ......................................................................... 2-22
Keeping Loops Short ............................................................. 2-22
Avoiding Unrolling Loops ..................................................... 2-22
Avoiding Loop-Carried Dependencies .................................... 2-23
Avoiding Loop Rotation by Hand .......................................... 2-24
Avoiding Array Writes in Loops ............................................. 2-25
Inner Loops vs. Outer Loops ................................................ 2-26
Avoiding Conditional Code in Loops ..................................... 2-26
Avoiding Placing Function Calls in Loops .............................. 2-27
Avoiding Non-Unit Strides ................................................... 2-27
Loop Control ........................................................................ 2-28
Using the Restrict Qualifier ................................................... 2-29
Using the Const Qualifier ..................................................... 2-30
Avoiding Long Latencies ....................................................... 2-31
Using Built-In Functions in Code Optimization .......................... 2-32
System Support Built-In Functions ........................................ 2-32
Using Circular Buffers ........................................................... 2-33
Smaller Applications: Optimizing for Code Size .......................... 2-36
Using Pragmas for Optimization ................................................. 2-38
Function Pragmas ................................................................. 2-38
#pragma alloc ................................................................... 2-38
#pragma const .................................................................. 2-39
#pragma pure ................................................................... 2-39
xx VisualDSP++ 4.0 C/C++ Compiler and Library Manual
for SHARC Processors
CONTENTS
#pragma result_alignment ................................................. 2-40
#pragma regs_clobbered .................................................... 2-40
#pragma optimize_{off|for_speed|for_space|as_cmd_line} .. 2-42
Loop Optimization Pragmas .................................................. 2-43
#pragma loop_count ......................................................... 2-43
#pragma no_vectorization ................................................. 2-43
#pragma vector_for ........................................................... 2-44
#pragma SIMD_for .......................................................... 2-45
#pragma all_aligned .......................................................... 2-45
#pragma no_alias .............................................................. 2-46
Useful Optimization Switches ...................................................... 2-47
Example: How the Optimizer Works ........................................... 2-48
Assembly Optimizer Annotations ................................................ 2-51
Procedure Statistics ................................................................ 2-52
Loop Identification ................................................................ 2-54
Loop Identification Annotations ........................................ 2-55
File Position ...................................................................... 2-58
Vectorization ......................................................................... 2-60
Loop Flattening ................................................................ 2-61
Vectorization Annotations ................................................. 2-62
Modulo Scheduling ............................................................... 2-65
C/C++ RUN-TIME LIBRARY
C and C++ Run-Time Libraries Guide ........................................... 3-3
Calling Library Functions ........................................................ 3-3
VisualDSP++ 4.0 C/C++ Compiler and Library Manual xxi
for SHARC Processors
CONTENTS
Linking Library Functions ....................................................... 3-4
Working with Library Header Files ........................................ 3-12
assert.h ............................................................................. 3-13
ctype.h ............................................................................. 3-13
cycle_count.h ................................................................... 3-13
cycles.h ............................................................................ 3-13
device.h ............................................................................ 3-14
device_int.h ...................................................................... 3-14
errno.h ............................................................................. 3-14
float.h .............................................................................. 3-15
iso646.h ........................................................................... 3-15
limits.h ............................................................................ 3-16
locale.h ............................................................................ 3-16
math.h ............................................................................. 3-16
setjmp.h ........................................................................... 3-18
signal.h ............................................................................ 3-18
Interrupt Dispatchers .................................................... 3-18
Interrupts and Circular Buffering .................................. 3-21
Avoiding Self-Modifying Code ...................................... 3-21
Interrupt Nesting Restrictions on ADSP-2116x/2126x/2136x
Processors .................................................................. 3-22
Restriction on Use of Super-Fast Dispatcher on ADSP-2106x
Processors .................................................................. 3-22
stdarg.h ............................................................................ 3-23
stddef.h ............................................................................ 3-23
xxii VisualDSP++ 4.0 C/C++ Compiler and Library Manual
for SHARC Processors
CONTENTS
stdio.h .............................................................................. 3-24
stdlib.h ............................................................................. 3-26
string.h ............................................................................. 3-27
time.h ............................................................................... 3-27
Calling Library Functions from an ISR .................................. 3-29
Using Compiler Built-In C Library Functions ........................ 3-30
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
VisualDSP++ 4.0 C/C++ Compiler and Library Manual xxiii
for SHARC Processors
CONTENTS
C++ Header Files for C Library Facilities ........................... 3-35
Embedded Standard Template Library Header Files ........... 3-37
algorithm ..................................................................... 3-37
deque ........................................................................... 3-37
functional ..................................................................... 3-37
hash_map ..................................................................... 3-37
hash_set ....................................................................... 3-37
iterator ......................................................................... 3-37
list ................................................................................ 3-37
map .............................................................................. 3-38
memory ........................................................................ 3-38
numeric ........................................................................ 3-38
queue ........................................................................... 3-38
set ................................................................................ 3-38
stack ............................................................................. 3-38
utility ........................................................................... 3-38
vector ........................................................................... 3-38
fstream.h ...................................................................... 3-39
iomanip.h ..................................................................... 3-39
iostream.h .................................................................... 3-39
new.h ........................................................................... 3-39
Using the Thread-Safe C/C++ Run-Time Libraries with VDK 3-39
Measuring Cycle Counts ....................................................... 3-40
Basic Cycle Counting Facility ............................................ 3-40
xxiv VisualDSP++ 4.0 C/C++ Compiler and Library Manual
for SHARC Processors
CONTENTS
Cycle Counting Facility with Statistics ............................... 3-42
Using time.h to Measure Cycle Counts .............................. 3-45
Determining the Processor Clock Rate ............................... 3-47
Considerations When Measuring Cycle Counts .................. 3-47
File I/O Support .................................................................... 3-49
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-59
Data Structure for Primitive I/O .................................... 3-60
C Run-Time Library Reference .................................................... 3-64
abort .......................................................................................... 3-65
abs .............................................................................................. 3-66
acos ............................................................................................ 3-67
asctime ....................................................................................... 3-68
asin ............................................................................................. 3-70
atan ............................................................................................ 3-71
atan2 .......................................................................................... 3-72
atexit .......................................................................................... 3-73
atof ............................................................................................. 3-74
VisualDSP++ 4.0 C/C++ Compiler and Library Manual xxv
for SHARC Processors
CONTENTS
atoi ............................................................................................ 3-77
atol ............................................................................................ 3-78
atold .......................................................................................... 3-79
avg ............................................................................................. 3-82
bsearch ....................................................................................... 3-83
calloc ......................................................................................... 3-85
ceil ............................................................................................. 3-86
circindex .................................................................................... 3-87
circptr ........................................................................................ 3-89
clear_interrupt ............................................................................ 3-92
clip .......................................................................................... 3-101
clock ........................................................................................ 3-102
cos ........................................................................................... 3-103
cosh ......................................................................................... 3-104
count_ones ............................................................................... 3-105
ctime ........................................................................................ 3-106
difftime .................................................................................... 3-107
div ........................................................................................... 3-108
exit ........................................................................................... 3-109
exp ........................................................................................... 3-110
fabs .......................................................................................... 3-111
floor ......................................................................................... 3-112
fmod ........................................................................................ 3-113
free .......................................................................................... 3-114
xxvi VisualDSP++ 4.0 C/C++ Compiler and Library Manual
for SHARC Processors
CONTENTS
frexp ......................................................................................... 3-115
getenv ....................................................................................... 3-116
gmtime ..................................................................................... 3-117
heap_calloc ............................................................................... 3-118
heap_free .................................................................................. 3-120
heap_install .............................................................................. 3-122
heap_lookup_name ................................................................... 3-125
heap_malloc ............................................................................. 3-127
heap_realloc .............................................................................. 3-129
interrupt ................................................................................... 3-132
isalnum ..................................................................................... 3-134
isalpha ...................................................................................... 3-135
iscntrl ....................................................................................... 3-136
isdigit ....................................................................................... 3-137
isgraph ...................................................................................... 3-138
isinf .......................................................................................... 3-139
islower ...................................................................................... 3-141
isnan ......................................................................................... 3-142
isprint ....................................................................................... 3-144
ispunct ..................................................................................... 3-145
isspace ...................................................................................... 3-146
isupper ..................................................................................... 3-147
isxdigit ...................................................................................... 3-148
labs ........................................................................................... 3-149
VisualDSP++ 4.0 C/C++ Compiler and Library Manual xxvii
for SHARC Processors
CONTENTS
lavg .......................................................................................... 3-150
lclip ......................................................................................... 3-151
lcount_ones .............................................................................. 3-152
ldexp ........................................................................................ 3-153
ldiv .......................................................................................... 3-154
lmax ......................................................................................... 3-155
lmin ......................................................................................... 3-156
localeconv ................................................................................ 3-157
localtime .................................................................................. 3-160
log ........................................................................................... 3-162
log10 ........................................................................................ 3-163
longjmp ................................................................................... 3-164
malloc ...................................................................................... 3-166
max .......................................................................................... 3-167
memchr .................................................................................... 3-168
memcmp .................................................................................. 3-169
memcpy ................................................................................... 3-170
memmove ................................................................................ 3-171
memset .................................................................................... 3-172
min .......................................................................................... 3-173
mktime .................................................................................... 3-174
modf ........................................................................................ 3-176
pow .......................................................................................... 3-177
qsort ........................................................................................ 3-178
xxviii VisualDSP++ 4.0 C/C++ Compiler and Library Manual
for SHARC Processors
CONTENTS
raise .......................................................................................... 3-180
rand .......................................................................................... 3-181
realloc ....................................................................................... 3-182
setjmp ...................................................................................... 3-184
setlocale .................................................................................... 3-185
set_alloc_type ........................................................................... 3-186
signal ........................................................................................ 3-188
sin ............................................................................................ 3-190
sinh .......................................................................................... 3-191
sqrt ........................................................................................... 3-192
srand ........................................................................................ 3-193
strcat ........................................................................................ 3-194
strchr ........................................................................................ 3-195
strcmp ...................................................................................... 3-196
strcoll ....................................................................................... 3-197
strcpy ....................................................................................... 3-198
strcspn ...................................................................................... 3-199
strerror ..................................................................................... 3-200
strftime ..................................................................................... 3-201
strlen ........................................................................................ 3-205
strncat ...................................................................................... 3-206
strncmp .................................................................................... 3-207
strncpy ..................................................................................... 3-208
strpbrk ...................................................................................... 3-209
VisualDSP++ 4.0 C/C++ Compiler and Library Manual xxix
for SHARC Processors
CONTENTS
strrchr ...................................................................................... 3-210
strspn ....................................................................................... 3-211
strstr ........................................................................................ 3-212
strtod ....................................................................................... 3-213
strtold ...................................................................................... 3-216
strtok ....................................................................................... 3-219
strtol ........................................................................................ 3-221
strtoul ...................................................................................... 3-223
strxfrm ..................................................................................... 3-225
system ...................................................................................... 3-227
tan ........................................................................................... 3-228
tanh ......................................................................................... 3-229
time ......................................................................................... 3-230
tolower ..................................................................................... 3-231
toupper .................................................................................... 3-232
va_arg ...................................................................................... 3-233
va_end ..................................................................................... 3-235
va_start .................................................................................... 3-236
DSP LIBRARY FOR ADSP-2106X AND ADSP-21020
PROCESSORS
DSP Run-Time Library Guide ...................................................... 4-2
Calling DSP Library Functions ................................................ 4-2
Linking DSP Library Functions ............................................... 4-3
Working With Library Source Code ........................................ 4-3
xxx VisualDSP++ 4.0 C/C++ Compiler and Library Manual
for SHARC Processors