Home
VisualDSP++ 3.5 C/C++ Compiler and Library
Contents
1. Description Prototype Complex void cvecsadd const complex_double a complex_double b Vector Scalar complex_double c int n Addition void cvecsaddf const complex_float a complex_float b complex_float c int n void cvecsadd_frl6 const complex_fractl6 a complex_fractl6 b complex_fractl6 c int n Complex void cvecssub const complex_double a complex_double b Vector Scalar complex_double c int n Subtraction void cvecssubf const complex_float a complex_float b complex_float c int n void cvecssub_frl6 const complex_fractl6 a complex_fractl6 b complex_fractl6 c int n Complex void cvecsmlt const complex_double a complex_double b Vector Scalar complex_double c int n Multiplication void cvecsmItf const complex_float a complex_float b complex_float c int n void cvecsmlt_frl6 const complex_fractl6 a complex_fractl6 b complex_fract1l6 c int n Complex void cvecvadd const complex_double a Vector Vector const complex_double b complex_double c int n Addition void cvecvaddf const complex_float a const complex_float b complex_float c J int n void cvecvadd_frl6 const complex_fractl6 a const complex_fractl6 b J complex_fractl6 c int n Complex void cvecvsub const complex_double a Vector Vector const complex_double b complex_doub
2. clearerr fclose feof ferror fflush fgetc fgetpos fgets fprintf fputc fputs fopen fread freopen fscanf fseek fsetpos ftell fwrite getc getchar gets perror putc putchar puts remove rename rewind scanf setbuf setvbuf sprintf sscanf ungetc vfprintf vprintf vsprintf Table 3 11 Documented Library Functions in stdlib h Header File abort abs atexit atof atoi atol bsearch calloc div exit free labs 3 24 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Table 3 11 Documented Library Functions in stdlib h Header File C C Run Time Library Idiv malloc qsort rand realloc srand strtod strtodf strtol strtoul Table 3 12 Documented Library Functions in string h Header File memchr memcmp memcpy memcpy_from_shared memcpy_to_shared memmove memset strncat strchr strcmp strcoll strcpy strcspn strerror strlen strncat strncmp strncpy strpbrk strrchr strspn strstr strtok strxfrm Table 3 13 Documented Library Functions in sysreg h Header File disable_interrupts enable_interrupts external_memory_read external_memory_write io_space_read i0_space_write mode_change sysreg_read sysreg_write VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs 3 25 C Run Time Library Reference C Run Time Library Reference The C run time library is a collection
3. Register Description Notes PX scratch SB scratch SE scratch SI scratch SR1 0 scratch double word return SR2 scratch Table 1 15 List of DAG1 Registers Register Description 10 scratch I1 scratch 12 preserved 13 preserved 0 preserved 1 scratch 2 preserved 3 scratch LO 3 not used must be zero BO 3 not used DMPG1 preserved 1 164 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Table 1 16 List of DAG2 Registers Register Description 14 Dedicated SP 15 Dedicated FP 16 scratch 17 preserved M4 preserved M5 dedicated 1 M6 scratch M7 scratch L4 7 not used must be zero B4 7 not used DMPG2 dedicated must not change Table 1 17 Miscellaneous Registers Register Description ASTAT scratch CCODE preserved 0x8 ALU result sign default in C C code CNTR scratch CNTL scratch JPG scratch MASK scratch RPTL scratch LPSTACKA scratch Compiler VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs 1 165 C C Run Time Model and Environment Table 1 17 Miscellaneous Registers Cont d LPSTACKP scratch MSTAT scratch STACKA scratch STACKP scratch STACKA scratch File O Support The VisualDSP environment provides access to file
4. Header Description cassert Enforces assertions during function executions cctype Classifies characters VisualDSP 3 5 C C Compiler and Library Manual 3 19 for ADSP 219x DSPs C and C Run Time Library Guide Table 3 4 C Header Files for C Library Facilities Contd Header Description cerrno Tests error codes reported by library functions cfloat Tests floating point type properties climits Tests integer type properties clocale Adapts to different cultural conventions cmath Provides common mathematical operations cset jmp Executes non local goto statements csignal Controls various exceptional conditions cstdarg Accesses a variable number of arguments cstddef Defines several useful data types and macros cstdio Performs input and output cstdlib Performs a variety of operations cstring Manipulates several kinds of strings Embedded Standard Template Library Header Files Templates and the associated header files are not part of the embedded C standard but they are supported by the cc219x compiler in C mode The embedded standard template library headers are algorithm The algorithm header defines numerous common operations on sequences deque The deque header defines a deque template container 3 20 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library functional The func
5. Symbolic Name Equivalent and amp amp and_eq amp bitand amp bitor comp not not_eq l or or_eq xor A xor_eq As The symbolic names have the same name as the C keywords that are accepted by the compiler when the alttok switch see on page 1 23 is specified limits h The limits h header file contains definitions of maximum and minimum values for each C data type other than floating point VisualDSP 3 5 C C Compiler and Library Manual 3 11 for ADSP 219x DSPs C and C Run Time Library Guide locale h The locale h header file contains definitions for expressing numeric monetary time and other data math h This category includes the floating point mathematical functions of the C run time library The mathematical functions are ANSI standard The math h header file contains prototypes for functions used to calculate mathematical properties of single precision floating type variables On the ADSP 219x processors double and float are both single precision float ing point types Additionally some functions support a 16 bit fractional data type The math h file also defines the macro HUGE_VAL HUGE_VAL evaluates to the maximum positive value that the type double can support The macros EDOM and ERANGE defined in errno h are used by math h functions to indicate domain and range errors Some of the functions in this header file exist as both integer and floating point T
6. The use of any letter not listed in Table 1 9 results in unspecified behavior The compiler does not check the validity of the code by using the constraint letter For example if your assembly template contains axl dm 0 m3 and the address you want to load from is in the variable p the compiler needs to know that it should put p in a DAG1 I reg ister 10 13 before it generates your instruction You convey this information to cc219x by specifying the operand w p where w is the constraint letter for DAG1 I registers To assign registers to the operands the compiler must also be told which operands in an assembly language instruction are inputs which are out puts and which outputs may not overlap inputs The compiler is told this in three ways e The output operand list appears as the first argument after the assembly language template The list is separated from the assembly language template with a colon The input operands are separated from the output operands with a colon and always follow the out put operands 1 68 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler e The operand constraints describe which registers are modified by an assembly language instruction The in constraint indicates that the operand is an output all output operand constraints must use e The compiler may allocate an output operand in the same register as an unrelated input opera
7. Example dFinclude lt stdlib h gt double x x atof 5 5 PE x 5 5 RT VisualDSP 3 5 C C Compiler and Library Manual 3 35 for ADSP 219x DSPs C Run Time Library Reference See Also atoi atol strtod 3 36 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library atoi convert string to integer Synopsis include lt stdlib h gt int atoi const char nptr Description The atoi function converts a character string to an integer value The character string to be converted is pointed to by the input pointer nptr The function clears any leading characters for which isspace would return true Conversion begins at the first digit with an optional preceding sign and terminates at the first non digit Error Conditions The atoi function returns a zero if no conversion can be made Example include lt stdlib h gt int i 7 atoi 5 7 S 5 See Also atol atof strtod strtol strtoul VisualDSP 3 5 C C Compiler and Library Manual 3 37 for ADSP 219x DSPs C Run Time Library Reference atol convert string to long integer Synopsis include lt stdlib h gt long atol const char nptr Description The atol function converts a character string to a long integer value The character string to be converted is pointed to by the input pointer nptr The function clears any leading characters for which isspace would return true Conversion begin
8. Good explicit use of circular buffer via ___builtin_circindex or int p b for i 0 j 0 1 lt 1000 it n sum a i p p __builtin_circptr p n b 20 Good explicit use of circular buffer via ___builtin_circptr For more information see Compiler Built In Functions on page 1 94 2 28 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Achieving Optimal Performance from C C Source Code Smaller Applications Optimizing for Code Size The same ethos for producing fast code also applies to producing small code You should present the algorithm in a way that gives the optimizer excellent visibility of the operations and data and hence the greatest free dom to safely manipulate the code to produce small applications Once the program is presented in this way the optimization strategy will depend on the code size constraint that the program must obey The first step should be to optimize the application for full performance using 0 or ipa switches If this obeys the code size constraints then no more need be done The optimize for space switch 0s on page 1 37 which may be used in conjunction with IPA will perform every performance enhancing trans formation except those that increase code size In addition the e linker switch flags link e if used from the compiler command line may be helpful on page 1 27 This performs section elimination in the linker to re
9. fourth quadrant 3 27 7 a sin_frl6 0x8000 0x0 0x8000 0 return sin_frl6 0x8000 x 4 See Also asin COS VisualDSP 3 5 C C Compiler and Library Manual 3 117 for ADSP 219x DSPs C Run Time Library Reference sinh hyperbolic sine Synopsis d Finclude lt math h gt double sinh double x float sinhf float x Description The sinh function returns the hyperbolic sine of the argument x Error Conditions The sinh function returns the IEEE constant Inf if the argument is out side the domain Example d Finclude lt math h gt double x y y sinh x See Also cosh 3 118 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library sqrt square root Synopsis dFinclude lt math h gt double sqrt double x float saqrtf float x fractl6o sqrt_frl6 fractl6 x Description The sqrt function returns the positive square root of the argument Error Conditions The sqrt function returns a zero for a negative input Example d Finclude lt math h gt double y y sqrt 2 0 IR y LATA ees See Also rsqrt VisualDSP 3 5 C C Compiler and Library Manual 3 119 for ADSP 219x DSPs C Run Time Library Reference srand random number seed Synopsis d Finclude lt stdlib h gt void srand unsigned int seed Description The srand function is used to set the seed value for the rand function A particular seed
10. The size of the input array in the output array out and the temporary working buffer t is n where n represents the number of points in the FFT The function does not impose any special memory alignment require ments on the arrays However benefits in run time performance will be realized if the output array is allocated on an address boundary that is multiple of twice the FFT size If the input data can be overwritten then optimum memory usage can be achieved by specifying the input array as either the output array or as the temporary array provided that the mem ory size of the input array is at least 2 n Specifying the input array as the temporary array will also result in increased run time performance 4 96 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs DSP Run Time Library The twiddle table is passed in the argument w which must contain at least 34n twiddle factors The function twidfftrad4_fri6 may be used to ini tialize the array If the twiddle table contains more factors than needed for a particular call on rfftrad4_fri6 then the stride factor has to be set appropriately otherwise it should be one The argument scale_method controls how the function should scale the output to avoid overflow If no scaling is selected by setting scale_method to zero then the input signal should be sufficiently conditioned to avoid overflow The block_exponent argument will be set to zero The function will perfo
11. static int fail 0 main test int isnan double union double d float f unsigned long l u ifdef _ DOUBLES_ARE_FLOATS__ u l 0xFF800000L if isnan u d 0 fail u 1 OxFF800001L if isnan u d 0 fail u 1 0x7F800000L if isnan u d 0 fail VisualDSP 3 5 C C Compiler and Library Manual 3 79 for ADSP 219x DSPs C Run Time Library Reference u 1 0x7F800001L dfendif test int isnanf f 0xFF800000L 0xFF800001L 0x7F800000L 0x7F800001L U U U U pri else pri See Also isinf pri if isnan u d 0 fail oat if isnanf u f 0 fail if isnanf u f 0 fail if isnanf u f 0 fail t if isnanf u f 0 fail nt pass fail message if fail 0 ntf Test passed n ntf Test failed d n fail 3 80 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library isprint detect printable character Synopsis include lt ctype h gt int isprint int c Description The isprint function determines if the argument is a printable character 0x20 0x7E If the argument is not a printable character isprint returns a zero If the argument is a printable character isprint returns a non zero value Error Conditions The isprint function does not return any error conditions Example include lt ctype h gt int ch for ch 0 ch lt Ox
12. 1 76 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler Assembly Constructs and Macros One way to use asm constructs is to encapsulate them in macros that look like functions For example the following shows macros that contain asm constructs This code defines a macro abs_macro which uses the inline asm instruction to perform an assembly language abs operation of variable x_var putting the result in result_var tdefine abs_macro result x asm 0 abs 41 c result c x pseudo code result abs x main int result_var 0 int x_var 10 abs_macro result_var 10 IE OF FY abs_macro result_var X_var Assembly Constructs and Flow Control It is inadvisable to place flow control operations within an asm construct that leaves the asm construct such as calling a procedure or perform ing a jump to another piece of code that is not within the asm construct itself Such operations are invisible to the compiler and may violate assumptions made by the compiler For example the compiler is careful to adhere to the calling conventions for preserved registers when making a procedure call If an asm construct calls a procedure the asm construct must also ensure that all conven tions are obeyed or the called procedure may corrupt the state used by the function containing the asm construct VisualDSP 3 5 C C Compiler and Library Manual 1 77 for
13. Always defines __FDG__ as 1 This signifies that an Edison Design Group front end is being used _EDG_VERSION__ Always defines __EDG_VERSION__ as an integral value representing the version of the compiler s front end FILE_ The preprocessor expands this macro into the current input file name as a string constant The string matches the name of the file specified on the cc219x command line or in a preprocessor Hinclude command ANSI standard Jt ANGUAGE_C Always defines _LANGUAGE_C as 1 when compiling C or C source LINE__ The preprocessor expands the __LINE__ macro into the current input line number as a decimal integer constant ANSI standard NO_BUILTIN Defines __NO_BUILTIN as 1 when you compile with the no builtin command line switch _N O_LONG_LONG Always defines _NO_LONG_LONG as 1 for C and C source This definition signifies no support is present for the long long int type 1 148 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler Table 1 12 Predefined Macro Listing Contd Macro Function SIGNED_CHARS Defines __SIGNED_CHARS__ as 1 unless you compile with the unsigned char command line switch __STDC__ Defines __STDC__ as 1 STDC_VERSION Defines __STDC_VERSION__ as 199409L __TIME__ The preprocessor expands this macro into the current time as a string constant The t
14. Fractional literals are written with the r suffix to avoid certain precision loss Literals without an r are of the type double and are implicitly con verted to fract as needed Conversions Involving Fractional Values The following notes apply to type conversion operations e Conversion between a fractional value and a floating value is sup ported The conversion to the floating point type may result in some precision loss e Conversion between a fractional value and an integer value is sup ported The conversion is not recommended because the only common values are 0 and 1 VisualDSP 3 5 C C Compiler and Library Manual 1 91 for ADSP 219x DSPs C C Compiler Language Extensions Fractional Arithmetic Operations The following notes summarize information about fractional arithmetic operators supported by the cc219x compiler Standard arithmetic operations on two fract items include addi tion subtraction and multiplication Assignment operations include and Shift operations include left and right shifts A left shift is imple mented as a logical shift and a right shift is an arithmetic shift Shifting left by a negative amount is not recommended Comparison operations are supported between two fract items Mixed mode arithmetic has a preference for fract For more infor mation about the mixed mode arithmetic see on page 1 92 Multiplication of a fractional and an integer produces
15. The functions described by this header assume that input array arguments are constant their contents will not change during the course of the rou tine In particular this means the input arguments do not overlap with any output argument Table 4 7 Vector Functions Description Prototype Real void vecsadd const double a double b double c Vector Scalar int n Addition void vecsaddf const float af J float b float c J int n void vecsadd_frl6 const fractl6 a J fractl6 b fractl6 c J int n Real void vecssub const double a double b double c Vector Scalar int n Subtraction void vecssubf const float a J float b float c int n void vecssub_frl6 const fractl6 a J fractl6 b fractl6 c J int n Real void vecsmlt const double a double b double c Vector Scalar int n Multiplication void vecsmltf const float a float b float c J int n void vecsmlt_frl6 const fractl6 a J fractl6 b fractl6 c L J int n VisualDSP 3 5 C C Compiler and Library Manual 4 17 for ADSP 219x DSPs DSP Run Time Library Guide Table 4 7 Vector Functions Cont d Description Prototype Real void vecvadd const double a const double b Vector Vector double c int n Addition void vecvaddf const float a J const float b J float c int n void vecvadd_frl
16. ie Probably not intended syntax else Preprocessing of IDL Files Every VisualDSP Interface Definition Language VIDL specification is analyzed by the C language preprocessor prior to syntax analysis For more information refer to the VisualDSP Component Software Engi neering User s Guide The include directive is used to control the inclusion of additional VIDL source text from a secondary input file that is named in the direc tive Two available forms of include are shown in Figure 1 2 VisualDSP 3 5 C C Compiler and Library Manual 1 151 for ADSP 219x DSPs Preprocessor Features VIDL file name VIDL file name Figure 1 2 INCLUDE Syntax Diagram The file identified by the file name is located by searching a list of directo ries When the name is delimited by quote characters the search begins in the directory containing the primary input file then proceeds with the list of directories specified by the 1 command line switch When the name is delimited by angle bracket characters the search proceeds directly with the directories specified by 1 If the file is not located within any direc tory on the search list the search may be continued in one or more platform dependent system directories 1 152 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler C C Run Time Model and Environment This section provides a full description of the ADSP 219x
17. interrupt raise signal 3 44 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library cos cosine Synopsis include lt math h gt double cos double float cosf float fractl6 cos_frl6 fractl6 Description The cos function returns the cosine of the argument The input is inter preted as radians the output is in the range 1 1 The cos_fri6 function inputs a fractional value in the range 1 0 1 0 corresponding to 7 2 1 2 The domain represents half a cycle which can be used to derive a full cycle if required see Notes below The result in radians is in the range 1 0 1 0 Error Conditions The cos function does not return an error condition Example d Finclude lt math h gt double y y cos 3 14159 PRS 21000 7 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs 3 45 C Run Time Library Reference Notes The domain of the cos_fr16 function is restricted to the fractional range 0x8000 0x7 fff which corresponds to half a period from 1 2 to 7 2 It is possible however to derive the full period using the following proper ties of the function cosine 0 mT 2 cosine T 3 2 T cosine 2 0 cosine T 2 T The function below uses these properties to calculate the full period from 0 to 2m of the cosine function using an input domain of 0 0x7fff d Finclude lt math h gt fractl6 cos2pi
18. ACH is no longer supported If you re link using your Release 6 1 object files or object libraries you must cre ate a Linker Description File for each object or object library before using the new Linker The remainder of this section describes these and other known differences between VisualDSP Releases 6 1 and VisualDSP 3 5 It also provides assistance when possible for making these required changes A 2 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler Legacy Support C C Compiler and Run Time Library The new cc219x compiler provided in VisualDSP 3 5 does not support some switches and extensions that were available in the g21 compiler As a result the compiler supports a set of new rules for the run time environ ment This section lists the extensions and switches that have been removed replaced or whose function works differently than in Release 6 1 For further details about the cc219x compiler see Chapter 1 Compiler Segment Placement Support Keyword Changed to Section The segment placement keyword has changed to section The section construct now precedes the variable declaration and its argu ment is a string For example section my_sec int myvar For more information about the section construct see Placement Support Keyword section on page 1 83 G21 Compatibility Call The cc219x compiler provides a special G21 compatibility call that en
19. Compiler and Library Manual 3 87 for ADSP 219x DSPs C Run Time Library Reference Idiv long division Synopsis include lt stdlib h gt ldiv_t Idiv long int numer long int denom Description The 1div function divides numer by denom and returns a structure of type ldiv_t The type 1div_t is defined as typedef struct long int quot long int rem k ldivit where quot is the quotient of the division and rem is the remainder such that if result is of type 1div_t then result quot denom result rem numer Error Conditions If denom is zero the behavior of the 1div function is undefined Example d Finclude lt stdlib h gt ldiv_t result result ldiv 7 2 result quot 3 result rem 1 See Also div fmod 3 88 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library log natural logarithm Synopsis d Finclude lt math h gt double log double float logf float Description The log function computes the natural base e logarithm of its input Error Conditions The 10g function returns a zero and sets errno to EDOM if the input value is negative Example d Finclude lt math h gt double y y log 1 0 y 0 0 See Also alog exp log10 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs 3 89 C Run Time Library Reference log10 base 10 logarithm Synopsis d Finclude lt math h gt
20. Description The strlen function returns the length of the null terminated string pointed to by s1 not including the terminating null character Error Conditions The strlen function does not return an error condition Example include lt string h gt size_t len len strlen SOMEFUN jen 7 See Also No references to this function 3 128 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library strncat concatenate characters from one string to another Synopsis d Finclude lt string h gt char strncat char sl const char s2 size_t n Description The strncat function appends a copy of up to n characters in the null ter minated string pointed to by s2 to the end of the null terminated string pointed to by s1 It returns a pointer to the new s1 string The behavior of strncat is undefined if the two strings overlap The new s1 string is terminated with a null 0 Error Conditions The strncat function does not return an error condition Example d Finclude lt string h gt char stringl 50 ptr stringl 0 0 strncat stringl MOREFUN 4 stringl equals MORE See Also strcat VisualDSP 3 5 C C Compiler and Library Manual 3 129 for ADSP 219x DSPs C Run Time Library Reference strncmp compare characters in strings Synopsis include lt string h gt int strncemp const char s1 const char s2 size_t n
21. Domain Re a Im a lt 3 4 x 1038 for cabsf cabs Re a Im a lt 1 0 for cabs_fr16 Note The minimum input value for both real and imaginary parts can be less than 1 256 for cabs_fr16 but the result may have bit error of 2 to 3 bits 4 30 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs DSP Run Time Library cadd complex addition Synopsis include lt complex h gt complex_float caddf complex_float a complex_float b complex_double cadd complex_double a complex_double b complex_fractl6 cadd_frl6 complex_fractl6 a complex_fractl6 b Description This function computes the complex addition of two complex inputs a and b and returns the result Algorithm Re c Re a Re b Im c Im a Im b Domain 3 4 x 108 to 3 4 x 1078 for caddf cadd 1 0 to 1 0 for cadd_fr16 VisualDSP 3 5 C C Compiler and Library Manual 4 3 for ADSP 219x DSPs DSP Run Time Library Reference cartesian convert Cartesian to polar notation Synopsis include lt complex h gt float cartesianf complex_float a float phase double cartesian complex_double a double phase fractl6 cartesian_frl6 complex_fractl6 a fract1l6 phase Description This function transforms a complex number from Cartesian notation to polar notation The Cartesian number is represented by the argument a that the function converts into a corresponding magnitude which
22. Error Conditions The isxdigit function does not return any error conditions Example include lt ctype h gt int ch for ch 0 ch lt Ox7f ch printf 04x ch printf 2s isxdigit ch hexadecimal putchar n See Also isalnum isdigit VisualDSP 3 5 C C Compiler and Library Manual 3 85 for ADSP 219x DSPs C Run Time Library Reference labs long integer absolute value Synopsis include lt stdlib h gt long int labs long int j Description The labs function returns the absolute value of its integer input Error Conditions The labs function does not return an error condition Example d Finclude lt stdlib h gt long int j j labs 285128 j 285128 See Also abs fabs 3 86 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library Idexp multiply by power of 2 Synopsis dFinclude lt math h gt double ldexp double x int n float Idexpf float x int n Description The 1dexp function returns the value of the floating point input multi plied by 2 raised to the power of n It adds the value of the second argument n to the exponent of the first argument x Error Conditions If the result overflows 1dexp returns a NaN If the result underflows ldexp returns a zero Example d Finclude lt math h gt double y y Idexp 0 5 2 y 2 0 See Also exp pow VisualDSP 3 5 C C
23. VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library C and C Run Time Library Guide The C and C run time libraries contain routines that you can call from your source program This section describes how to use the libraries and provides information on the following topics e Calling Library Functions on page 3 4 e Using the Compiler s Built In C Library Functions on page 3 5 e Linking Library Functions on page 3 6 e Working With Library Header Files on page 3 8 e Abridged C Library Support on page 3 16 For information on the C library s contents see Documented Library Functions on page 3 23 For information on the Abridged C library s contents see Abridged C Library Support on page 3 16 and on line Help VisualDSP 3 5 C C Compiler and Library Manual 3 3 for ADSP 219x DSPs C and C Run Time Library Guide Calling Library Functions To use a C C library function call the function by name and give the appropriate arguments The name and arguments for each function appear on the function s reference page The reference pages appear in the Doc umented Library Functions on page 3 23 and in the C Run Time Library topic of the on line Help Like other functions you use library functions should be declared Decla rations are supplied in header files For more information about the header files see Working With
24. W SUN DSF 73 5 C C Compiler and Library Manual for ADSP 219x Processors Analog Devices Inc One Technology Way Norwood Mass 02062 9106 Revision 4 1 October 2003 Part Number 82 000390 03 ANALOG DEVICES Copyright Information 2003 Analog Devices Inc ALL RIGHTS RESERVED This docu ment 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 impli cation or otherwise under the patent rights of Analog Devices Inc Trademark and Service Mark Notice The Analog Devices logo VisualDSP the VisualDSP logo 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 enti esheets eared ease deena AUR PUNO sariren oueade merase eenas Plone Contents esha pede nctnscscarecepaenacradcimedexrernciasdaanaunes Whats New Dk 1s Manual noice ctaescshereimnrnceeadnaseseietnncecenmauiaewee Technical or Customer SUpport iacasecdacd cxeattacerea stents
25. assembly code Intended Audience The primary audience for this manual is DSP programmers who are famil iar with Analog Devices DSPs This manual assumes that the audience has a working knowledge of the ADSP 219x DSPs architecture and instruc tion set and the C C programming languages Programmers who are unfamiliar with ADSP 219x DSPs can use this manual but they should supplement it with other texts such as the appropriate hardware reference and instruction set reference that provide information about your ADSP 219x DSP architecture and instructions VisualDSP 3 5 C C Compiler and Library Manual Xxix for ADSP 219x DSPs Manual Contents Description Manual Contents Description This manual contains e Chapter 1 Compiler Provides information on compiler options language extensions and C C assembly interfacing e Chapter 2 Achieving Optimal Performance from C C Source Code Shows how to optimize compiler operation e Chapter 3 C C Run Time Library Shows how to use library functions and provides a complete C C library function reference e Chapter 4 DSP Run Time Library Shows how to use DSP library functions and provides a complete DSP library function reference e Appendix A Compiler Legacy Support Describes support for legacy code that was developed with previous releases of the development tools What s New in this Manual This edition of the VisualDSP 3
26. on page 1 39 path install directory The path install installation location switch directs the compiler to use the specified directory as the location for all compilation tools instead of the default path This is useful when working with multiple versions of the tool set You can selectively override this switch with the path tool switch path output directory The path output non temporary files location switch directs the com piler to place output files in the specified directory path temp directory The path temp temporary files location switch directs the compiler to place temporary files in the specified directory VisualDSP 3 5 C C Compiler and Library Manual 1 39 for ADSP 219x DSPs Compiler Command Line Interface pch The pch precompiled header switch directs the compiler to automati cally generate and use precompiled header files A precompiled output header has a pch extension attached to the source file name By default all precompiled headers are stored in a directory called PCHRepository Precompiled header files can significantly speed compilation pre compiled headers tend to occupy more disk space pchdir directory The pchdir locate PCHRepository switch specifies the location of an alternative PCHRepository directory for storing and invocation of precom piled header files If the directory does not exist the compiler creates it Note that o output does not influence the
27. parm2 return parm1 else return parm2 signof parml Domain Full range for various input parameter types 4 44 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs DSP Run Time Library cmlt complex multiply Synopsis d Finclude lt complex h gt complex_float cmltf complex_float a complex_float b complex_double cmlt complex_double a complex_double b complex_fractl6 cmlt_frl6 complex_fractl6 a complex_fractl6 b Description This function computes the complex multiplication of two complex inputs a and b and returns the result Algorithm Re c Re a Re b Im a Im b Im c Re a Im b Im a Re b Domain 3 4 x 10 8 to 3 4 x 10 8 for cmitf cmit 1 0 to 1 0 for cmlt_fr16 VisualDSP 3 5 C C Compiler and Library Manual 4 45 for ADSP 219x DSPs DSP Run Time Library Reference conj complex conjugate Synopsis include lt complex h gt complex_float conjf complex_float a complex_float b complex_double conj complex_double a complex_double b complex_fractl6 conj_frl6 complex_fractl6 a complex_fractl6 b Description This function conjugates the complex input a and returns the result Algorithm Re c Re a Im c Im a Domain 3 4 x 10 to 3 4 x 1038 for conjf conj 1 0 to 1 0 for conj_frl6 4 46 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs DSP Run Time Library convolve
28. 3 110 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library setjmp define a run time label Synopsis include lt setjmp h gt int setjmp jmp_buf env Description The set jmp function saves the calling environment in the jmp_buf argu ment The effect of the call is to declare a run time label that can be jumped to via a subsequent call to longjmp When set jmp is called it immediately returns with a result of zero to indi cate that the environment has been saved in the jmp_buf argument If at some later point 1ongjmp is called with the same jmp_buf argument longjmp will restore the environment from the argument The execution will then resume at the statement immediately following the correspond ing call to set jmp The effect is as if the call to set jmp has returned for a second time but this time the function will return a non zero result The effect of calling 1ongjmp will be undefined if the function that called setjmp has returned in the interim Error Conditions The setjmp function does not return an error condition Example See code example for longjmp on page 3 91 See Also longjmp VisualDSP 3 5 C C Compiler and Library Manual 3 111 for ADSP 219x DSPs C Run Time Library Reference signal define signal handling Synopsis d Finclude lt signal h gt void signal int sig void func int int void signalf int sig void func
29. 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler Table 1 4 C C Compiler Common Switches Cont d Switch Name Description syntax only on page 1 45 Checks the source code for compiler syntax errors but does not write any output sysdefs on page 1 45 Defines the system definition macros T filename on page 1 46 Uses the specified the Linker Description File as control input for linking threads on page 1 46 Specifies that the build and link should be thread safe time on page 1 47 Umacro on page 1 47 Displays the elapsed time as part of the output informa tion on each part of the compilation process Undefines macro s unsigned bitfield on page 1 47 Makes the default type for bitfield unsigned unsigned char on page 1 48 Makes the default type for char unsigned v on page 1 48 Displays both the version and command line information for all compilation tools as they process each file version amp verbose on page 1 48 verbose on page 1 48 val global lt name list gt Adds global names Displays command line information for all compilation tools as they process each file version on page 1 49 Displays version information for all compilation tools as they process each file W error remark suppress warn number on page 1 49 Overrides the default severity of t
30. 3 5 C C Compiler and Library Manual 1 47 for ADSP 219x DSPs Compiler Command Line Interface Field signed bitfield unsigned bitfield Why x a 2 1 0 3 Plain field x b 0 1 0 1 One bit X C 2 1 2 1 Explicit signed xd 0 3 0 3 Explicit unsigned See also the signed bitfields switch on page 1 45 unsigned char V The unsigned char make char unsigned switch directs the compiler to make the default type for char unsigned The compiler also undefines the SIGNED_CHARS__ preprocessor macro The v version and verbose switch directs the compiler to display both the version and command line information for all the compilation tools as they process each file val global lt name list gt The val global add global names switch directs the compiler that the names given by lt name list gt are present in all globally defined variables The list is separated by double colons In C these names are encoded as enclosing namespace or classes In C the names are prefixed and separated by underscores _ The compiler will issue an error on any globally defined variable in the current source module s not using lt name list gt This switch is used to define VCSE components verbose The verbose display command line switch directs the compiler to dis play command line information for all the compilation tools as they process each file 1 48 VisualDSP 3 5 C C C
31. A a DS A i Dya Xm Y B bd Dp B Dpi By D where m 0 1 2 n 1 Domain 1 0 to 1 0 4 84 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs DSP Run Time Library max maximum Synopsis d Finclude lt math h gt int max int parml int parm2 long int Imax long int parml long int parm2 float fmaxf float parml float parm2 double fmax double parml double parm2 fractl6 max_frl6 fractl6 parml fractl6 parm2 Description This function returns the larger of its two arguments Algorithm if parml gt parm2 return parml1 else return parm2 Domain Full range for type of parameters VisualDSP 3 5 C C Compiler and Library Manual 4 85 for ADSP 219x DSPs DSP Run Time Library Reference mean mean Synopsis d Finclude lt stats h gt fractl6 mean_frl6 a n const fractl6 aL int n float meanf a n const float al int n Description JR Input vector a a Number of input samples Input vector a Number of input samples This function computes the mean of the input elements contained within input vector a and returns the result Algorithm 1 n 1 c gt a N j 0 Domain 3 4 x 1038 to 3 4 x 1038 1 0 to 1 0 for meanf for mean_fr16 4 86 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs DSP Run Time Library min minimum Synopsis d Finclude lt m
32. Additional conventions which apply only to specific chapters may appear throughout this document Example Description Close command Text in bold style indicates the location of an item within the File menu VisualDSP environment s menu system For example the Close command appears on the File menu this that Alternative required items in syntax descriptions appear within curly brackets and separated by vertical bars read the example as this or that this that Optional items in syntax descriptions appear within brackets and sepa rated by vertical bars read the example as an optional this or that this Optional item lists in syntax descriptions appear within brackets delimited by commas and terminated with an ellipsis read the example as an optional comma separated list of this SECTION Commands directives keywords and feature names are in text with letter gothic font filename Non keyword placeholders appear in text with italic style format VisualDSP 3 5 C C Compiler and Library Manual xxxvii for ADSP 219x DSPs Notation Conventions Example Description A note providing information of special interest or identifying a related topic In the online version of this book the word Note appears instead of this symbol A caution providing information about critical design or program ming issues that influence operation of a product In the online
33. Description The strncmp function lexicographically compares up to n characters of the null terminated strings pointed to by s1 and s2 It returns a positive value if the s1 string is greater than the s2 string a negative value if the s2 string is greater than the s1 string and a zero if the strings are the same Error Conditions The strncmp function does not return an error condition Example include lt string h gt char ptrl ptrl TESTI if strncmp ptrl TEST 4 0 printf s starts with TEST n ptrl See Also memecmp strcmp 3 130 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library strncpy copy characters from one string to another Synopsis d Finclude lt string h gt char strncpy char sl const char s2 size_t n Description The strncpy function copies up to n characters of the null terminated string pointed to by s2 into the space pointed to by s1 If the last character copied from s2 is not a null the result does not end with a null The behavior of strncpy is undefined when the two objects overlap The strncpy function returns the new s1 If the s2 string contains fewer than n characters the s1 string is padded with the null character until all n characters have been written Error Conditions The strncpy function does not return an error condition Example d Finclude lt string h gt char stringl1 50 strncpy stringl MO
34. Oxa Bl base register sysreg_B2 Oxb B2 base register sysreg_B3 Oxc B3 base register sysreg_B4 Oxd B4 base register sysreg_B5 Oxe B5 base register sysreg_B6 Oxf B6 base register sysreg_B 0x10 B7 base register sysreg_SYSCTL 0x11 SYSCTL register sysreg_CACTL 0x12 Cache Control register 1 96 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler The sysreg parameter can also be any 8 bit value used to represent a sys tem control register since each variant of the ADSP 219x DSPs may have a differing System Control Register set The compiler does not validate the sysreg parameter instead it relies on the assembler to fault erroneous values An example use of sysreg_read to get the value of IMASK might be include lt sysreg h gt int read_imask int value sysreg_read sysreg_IMASK return value An example use of sysreg_write to set the value of IMASK might be include lt sysreg h gt void write_imask int val8bit sysreg_write sysreg_IMASK val8bit I O Space Read or Write The inclusion of sysreg h allows the use of functions that will generate efficient inline instructions to implement read and write of values from and to I O space addresses The prototypes for these functions are as defined in sysreg h void io_space_write const unsigned int const unsigned int int io_space_read const unsigned int addr
35. The threads enable thread safe build specifies that the build and link should be thread safe The macro _ADI_THREADS is defined to one 1 It is used for conditional compilation by the preprocessor and by the default Linker Description Files to link with thread safe libraries This switch is only likely to be used by applications involving the VisualDSP Kernel VDK 1 46 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler time The time time the compiler switch directs the compiler to display the elapsed time as part of the output information on each part of the compi lation process Umacro The U undefine macro switch lets you undefine macros If you specify a macro name it will be undefined The compiler processes all D define macro switches on the command line before any U undefine macro switches You can invoke this switch by selecting the Undefines field in the VisualDSP Project Options dialog box Compile tab Preprocessor category unsigned bitfield The unsigned bitfield make plain bitfields unsigned switch directs the compiler to make bitfields which have not been declared with an explicit signed or unsigned keyword to be unsigned This switch does not effect plain one bit bitfields which are always unsigned For example given the declaration struct int a 2 int b 1 Signed int c 2 unsigned int d 2 Xx the bitfield values are VisualDSP
36. Values and Meanings Sig Value Definition SIG_PWRDWN power down interrupt SIG_STACKINT PC LOOP or COUNTER overflow on push or on pop when empty SIG_KERNEL kernel interrupt SIG_INT4 user assignable SIG_INTS5 user assignable SIG_INT6 user assignable SIG_INT7 user assignable SIG_INT8 user assignable SIG_INT9 user assignable SIG_INT10 user assignable SIG_INT11 user assignable SIG_INT12 user assignable SIG_INT13 user assignable VisualDSP 3 5 C C Compiler and Library Manual 3 107 for ADSP 219x DSPs C Run Time Library Reference Table 3 16 Raise Function Signals Values and Meanings Contd Sig Value Definition SIGABRT software interrupt SIGILL software interrupt SIGINT software interrupt SIGSEGV software interrupt SIGTERM software interrupt SIGFPE software interrupt Interrupts are not nested by the default start up file Error Conditions The raise function returns a zero if successful a non zero value if it fails Example d Finclude lt signal h gt raise SIGABRT See Also interrupt signal 3 108 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library rand random number generator Synopsis d include lt stdlib h gt int rand void Description The rand function returns a pseudo random integer value in the range 15 0 2 1 For this function t
37. eter to I O memory space at the address passed as the first parameter This function is implemented as a compiler built in If the address param eter is a constant literal value the compiler will emit a Type 34 instruction that will be inlined at the point of io_space_write use For non literal addresses the compiler will call a library compiler support routine to per form the required write The inclusion of the sysreg h include file is mandatory when using io_space_write Error Conditions The io_space_write function does not return raise or set any error conditions Example include lt sysreg h gt int addr OxA int val OxA main int vl io_space_write OxA val inline instruction will be generated VisualDSP 3 5 C C Compiler and Library Manual 3 69 for ADSP 219x DSPs C Run Time Library Reference int v2 io_space_write addr OxFF support routine will be called af See Also disable_interrupts enable_interrupts io_space_read mode_change sysreg_read sysreg_write 3 70 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library isalnum detect alphanumeric character Synopsis include lt ctype h gt int isalnum int c Description The isalnum function determines if the argument is an alphanumeric character A Z a z or 0 9 If the argument is not alphanumeric isalnum returns a zero If the argument is alphanumeric isalnum r
38. for ADSP 219x DSPs C C Run Time Library Example d Finclude lt sysreg h gt main sysreg_write sysreg_IMASK 0x1 See Also disable_interrupts enable_interrupts io_space_read io_space_write mode_change sysreg_read VisualDSP 3 5 C C Compiler and Library Manual 3 153 for ADSP 219x DSPs C Run Time Library Reference tan tangent Synopsis include lt math h gt double tan double x float tanf float x fractl6 tan_frl6 fractl6 x Description The tan function returns the tangent of the argument x The input in radians must be in the range 9099 9099 The tan_fr16 function is only defined for input values between 7 4 0x9B78 and 7 4 0x6488 The input argument is in radians Output values range from 0x8000 to 0x7FFF The library function returns 0 for any input argument that is outside the defined domain Error Conditions The tan function returns zero if the input argument is outside the defined domain Example d Finclude lt math h gt double y y tan 3 14159 4 0 y 1 0 See Also atan atan2 3 154 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library tanh hyperbolic tangent Synopsis d Finclude lt math h gt double tanh double x float tanhf float x Description The tanh function returns the hyperbolic tangent of the argument x Error Conditions The tanh function does not return an erro
39. for ADSP 219x DSPs C Run Time Library Reference va_arg get next argument in variable length list of arguments Synopsis include lt stdarg h gt void va_arg va_list ap type Description The va_arg macro is used to walk through the variable length list of argu ments to a function After starting to process a variable length list of arguments with va_start call va_arg with the same va_list variable to extract arguments from the list Each call to va_arg returns a new argument from the list Substitute a type name corresponding to the type of the next argument for the type parameter in each call to va_arg After processing the list call va_end The header file stdarg h defines a pointer type called va_list that is used to access the list of variable arguments The function calling va_arg is responsible for determining the number and types of arguments in the list It needs this information to determine how many times to call va_arg and what to pass for the type parameter each time There are several common ways for a function to determine this type of information The standard C printf function reads its first argument looking for sequences to determine the number and types of its extra arguments In the example below all of the arguments are of the same type char and a termination value NULL is used to indicate the end of the argument list Other methods are also possible If a call to va_arg is made after all a
40. fractl6 extract_h fract32 This function returns the 16 most significant bits if the 32 bit fract parameter provided Extract low least significant 16 bits fractl6 extract_1l fract32 This function returns the 16 least significant bits of the 32 bit fract parameter provided Multiply and accumulate with rounding fractl6 mac_r fract32 fractl6 fractl6 This function performs an L_mac operation using the three parameters P P 8 P provided The result is the rounded 16 most significant bits of the 32 bit results from the L_mac operation Multiply and subtract with rounding fractl6o msu_r fract32 fractl6 fractl6 This function performs an L_msu operation using the three parameters P P 8 P provided The result is the rounded 16 most significant bits of the 32 bit result from the L_msu operation Short multiply fractl6 mult fract16 fractl6 1 112 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler This function returns the 16 bit result of the fractional multiplication of the input parameters The result is saturated Multiply with rounding fractl6o mult_r fractl6 fractl6 This function performs a 16 bit multiply with rounding of the result of the fractional multiplication of the two input parameters Short negate fractl6 negate fractl6 This function returns the 16 bit result of the negation of the input param eter If the input is 0x8000 saturation occurs and
41. fractl6 shr fractl6 fractl6 This function arithmetically shifts the first parameter right by second parameter bits with sign extension If second parameter is negative the operation shifts left Shift right with rounding fractl6 shr_r fractl6 fractl6 This function performs a shift to the right as per the shr operation with additional rounding and saturation of the result Short subtract fractl6 sub fractl6 fractl6 1 114 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler This function returns the 16 bit result of the subtraction of the two parameters Saturation occurs with the result being set to 0x7fff for over flow and 0x8000 for underflow Long absolute fract32 L_abs fract32 This function returns the 32 bit absolute value of the input parameter In cases where the input is equal to 0x80000000 saturation occurs and 0x7fffffff is returned Long add fract32 L_add fract32 fract32 This function returns the 32 bit saturated result of the addition of the two input parameters Long add with carry fract32 L_add_c fract32 fract32 This function performs 32 bit addition of the two input parameters Uses the Carry flag as additional input when using the ETSI flag variables 16 bit variable gt most significant bits least significant bits zeroed fract32 L_deposit_h fract16 This function deposits the 16 bit parameter into the 16 most significant bits of the 32 bit r
42. is of type integer and uses K amp R promotion rules instead of ANSI promo tion rules The run time model defines some registers as scratch registers and others as preserved or dedicated registers Scratch registers can be used within the assembly language program without worrying about their previous con tents If more room is needed or an existing code is used and you wish to use the preserved registers you must save their contents and then restore those contents before returning Do not use the dedicated or stack registers for other than their intended purpose the compiler libraries debugger and interrupt routines depend on having a stack available as defined by those registers The compiler also assumes the machine state does not change during exe cution of the assembly language subroutine Do not change any machine modes for example certain registers may be used to indicate circular buffering when those register val ues are nonzero The compiler prefaces the name of any external entry point with an underscore Therefore declare your assembly language subroutine s name with a leading underscore If you re using the function from assembly pro 1 170 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler grams as well you might want your function s name to be just as you write it Then you ll also need to tell the C C compiler that it s an asm func tion by placing extern asm ar
43. length of the window required is specified by the parameter N and the stride parameter a is used to space the window values within the output vector w The length of the output vector should therefore be N a This window is also known as the Cosine window a N 1 where n 0 1 2 N 1 Algorithm wn 0 5 0 5 co Domain a gt 0 N gt 0 4 68 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs DSP Run Time Library gen_harris generate harris window Synopsis d Finclude lt window h gt void gen_harris_frl6 w a N fractl6 wll Window vector int a Address stride in samples for window vector int N Length of window vector Description This function generates a vector containing the Harris window The length of the window required is specified by the parameter N and the stride parameter a is used to space the window values within the output vector w The length of the output vector should therefore be N a This window is also known as the Blackman Harris window Algorithm 2mm w n 0 35875 0 48829 co 0 141284 003 amt 26 Ginecol S7 N 1 N I where n 0 1 2 N 1 Domain a gt 0 N gt 0 VisualDSP 3 5 C C Compiler and Library Manual 4 69 for ADSP 219x DSPs DSP Run Time Library Reference gen_kaiser generate kaiser window Synopsis d Finclude lt window h gt void gen_kaiser_frl6 w beta a N fractl6 wl
44. on page 1 40 pedantic Issues compiler warnings for any constructs that are not on page 1 40 ISO ANSI standard C C compliant pedantic errors Issues compiler errors for any constructs that are not on page 1 40 ISO ANSI standard C C compliant pplist filename Outputs a raw preprocessed listing to the specified file on page 1 41 proc identifier Specifies that the compiler should produce code suitable on page 1 41 for the specified DSP R directory Appends directory to the standard search path for source on page 1 42 files R Removes all directories from the standard search path for on page 1 43 source files reserve lt regl gt reg2 Reserves the 12 13 and MO registers from compiler use on page 1 43 Note Reserving registers can have a detrimental effect on the compilers optimization capabilities xS Stops compilation before running the assembler on page 1 43 s Removes debugging information from the output execut on page 1 43 able file when linking save temps Saves intermediate compiler temporary files on page 1 44 show Displays the driver command line information on page 1 44 si revision version Specifies a silicon revision of the specified processor on page 1 44 signed bitfield Makes the default type for int bitfields signed on page 1 45 signed char Makes the default type for char signed on page 1 45 1 18 VisualDSP
45. qualified parameters and return types Library Support for Far Pointers All standard library functions that normally have pointer parameters cur rently only support near pointer parameters Passing a far pointer parameter to a standard library function will cause the far pointer to be truncated The compiler will generate a warning when this occurs assum ing the correct standard include file has been included before the call to the library Legacy Support Previous releases of VisualDSP only supported external memory through compiler intrinsics which had to be passed the full address to be loaded or stored These intrinsics are still supported although superseded in terms of functionality and flexibility by use of far qualified types The inclusion of sysreg h allows the use of functions that will generate inline instructions to implement read and write of values from and to external memory The prototypes of the functions are defined in sysreg h int external_memory_read int DMPG_val int addr void external_memory_write int DMPG_val int addr int val 1 102 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler int __builtin_external_vol_memory_read int volatile void addr void __builtin_external_vol_memory_write int volatile void addr int The DMPG_val parameter is the value of the upper 8 bits of the 24 bit external memory address The addr parameter is a pointer to t
46. void free void ptr Description The free function deallocates a pointer previously allocated to a range of memory by calloc or malloc to the free memory heap If the pointer was not previously allocated by calloc malloc or realloc the behavior is undefined The free function returns the allocated memory to the heap from which it was allocated Error Conditions The free function does not return an error condition Example include lt stdlib h gt char ptr ptr malloc 10 Allocate 10 words from heap free ptr Return space to free heap See Also calloc malloc realloc VisualDSP 3 5 C C Compiler and Library Manual 3 61 for ADSP 219x DSPs C Run Time Library Reference frexp separate fraction and exponent Synopsis include lt math h gt double frexp double f int expptr float frexpf float f int expptr Description The frexp function separates a floating point input into a normalized fraction and a base 2 exponent The function returns the first argument as a fraction in the interval 2 1 and stores a power of 2 in the integer pointed to by the second argument If the input is zero then the fraction and exponent will both be set to zero Error Conditions The frexp function does not return an error condition Example d Finclude lt math h gt double y int exponent y frexp 2 0 amp exponent y 0 5 exponent 2 See Also modf 3 62 VisualDSP
47. 0 i1 lt 1000 i sum ali b i 20 Good the compiler knows that b is accessed as a circular buffer Clearly the access to array b is a circular buffer When optimization is enabled the compiler will produce a hardware circular buffer instruction for this access Consider the slightly more complicated example for i 0 i1 lt 1000 it n sum a i b i 20 VisualDSP 3 5 C C Compiler and Library Manual 2 27 for ADSP 219x DSPs Using Built In Functions in Code Optimization Bad may not be able to use circular buffer to access b In this case the compiler does not know if n is positive and less than 20 If it is then the access may be correctly implemented as a hardware circular buffer On the other hand if it is greater than 20 a circular buffer incre ment may not yield the same results as the C code The programmer has two options here One is to compile with the force circbuf switch on page 1 27 This tells the compiler that any access of the form a i n should be considered as a circular buffer Before using this switch you should check that this assumption is valid for your application The preferred option however is to use builtins to perform the circular buffering Two are provided for this purpose To make it clear to the com piler that a circular buffer should be used you may write either for i1 0 j 0 i1 lt 1000 it n sum a i bj j __builtin_circindex j n 20
48. 0x7fff is returned Long normalize fractl6 norm_ fract16 This function returns the number of left shifts required to normalize the input variable for positive values on the interval with minimum of 0x40000000 and maximum of 0x7fffffff and for negative values on the interval with minimum of 0x80000000 and maximum of 0xc0000000 Short normalize fractl6 norm_s fractl6 This function returns the number of left shifts required to normalize the input 16 bit variable for positive values on the interval with minimum of 0x4000 and maximum of 0x7fff and for negative values on the interval with minimum of 0x8000 and maximum of 0xc000 Round fractl6 round fract32 VisualDSP 3 5 C C Compiler and Library Manual 1 113 for ADSP 219x DSPs C C Compiler Language Extensions This function rounds the lower 16 bits of the 32 bit input parameter into the most significant 16 bits with saturation The resulting bits are shifted right by 16 Saturate fractl6 saturate fract32 This function returns the 16 most significant bits of the input parameter If the input parameter is greater than 0x7fff 0x7fff is returned If the input parameter is less than 0x8000 0x8000 is returned Short shift left fractl6o shl fractl6 fractl6 This function arithmetically shifts the first parameter left by second parameter bits The empty bits are zero filled If second parameter is nega tive the operation shifts right Short shift right
49. 12345 _asmfunc end global _asmfunc type _asmfunc STT_FUNC For a more complicated function you might find it useful to fol low the general run time model and use the run time stack for local storage etc A simple C program passed through the com piler will provide a good template to build on Alternatively you may find it just as convenient to use local static storage for temporaries Calling C C Functions from Assembly Programs You may want to call a C C callable library and other functions from within an assembly language program As discussed in Calling Assembly Subroutines from C C Programs on page 1 170 you may want to cre ate a test function to do this in C C and then use the code generated by the compiler as a reference when creating your assembly language program and the argument setup Using volatile global variables may help clarify the essential code in your test function 1 172 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler The run time model defines some registers as scratch registers and others as preserved or dedicated The contents of the scratch registers may be changed without warning by the called C C function If the assembly language program needs the contents of any of those registers you must save their contents before the call to the C C function and then restore those contents after returning from the call Do not use the dedicated register
50. 2 13 2 30 inline asm statements 2 14 inline assembly language support keyword asm 1 63 construct I O operands 1 75 template 1 64 template operands 1 68 with multiple instructions 1 74 construct template 1 64 constructs optimization 1 75 macros containing asm 1 77 inline code avoiding 2 30 inline function support keyword inline 1 60 1 62 inlining automatic 2 13 function 2 13 inner loop 2 19 instantiation template functions 1 134 interfacing C C and assembly See mixed C C assembly programming interprocedural analysis IPA 1 30 2 6 interrupt disable 1 98 enable 1 98 pragma 1 123 pragmas 1 122 table 1 154 interrupt define interrupt handling function 3 63 I 16 VisualDSP 3 0 C C Compiler and Library Manual for ADSP 219x DSPs INDEX interruptf function 3 63 Interrupts see clear_interrupt interruptf interrupts signal raise functions io_space_read read I O space function 3 67 io_space_write write I O space function 3 69 ipa interprocedural analysis compiler switch 1 30 1 58 2 6 isalnum detect alphanumeric character function 3 71 isalpha detect alphabetic character function 3 72 iscntrl detect control character function 3 73 isdigit detect decimal digit function 3 74 isgraph detect printable character function 3 75 isinf test for infinity function 3 76 islower detect lowercase character function 3 78 isnan test for NAN function 3 79 iso646 h Boo
51. 3 5 globvar global variable 2 22 GNU C compiler 1 138 graphical character test see isgraph function H H list headers compiler switch 1 28 handler interrupt 1 155 isignal 1 155 hardware call stack 1 35 call stack overflow 1 157 defect workarounds 1 50 interrupt 1 154 header file 1 136 ETSI 1 111 header file control pragmas 1 136 header files 1 149 4 4 C run time library 3 83 15 def2192 12 h 3 10 def219x h 3 10 errno h 3 10 float h 3 10 iso646 h 3 11 limits h 3 11 locale h 3 12 math h 3 12 setjmp h 3 13 signal h 3 13 stdarg h 3 13 stddef h 3 13 stdio h 3 13 stdlib h 3 15 string h 3 15 sysreg h 3 15 C access to C facilities cassert 3 19 cctype 3 19 cerrno 3 20 cfloat 3 20 climits 3 20 clocale 3 20 cmath 3 20 csetjmp 3 20 csignal 3 20 cstdarg 3 20 cstddef 3 20 cstdio 3 20 cstdlib 3 20 cstring 3 20 assert h 3 9 DSP 4 4 ctype h 3 9 complex h 4 4 4 6 def2191 h 3 10 filter h 4 6 I 14 VisualDSP 3 0 C C Compiler and Library Manual for ADSP 219x DSPs INDEX math h 4 10 matrix h 4 12 4 15 stats h 4 16 vector h 4 17 4 20 window h 4 20 Embedded C Library complex 3 16 embedded C library exception 3 17 fract 3 17 fstream 3 17 iomanip 3 17 ios 3 17 iosfwd 3 17 iostream 3 18 istream 3 18 new 3 18 ostream 3 18 sstream 3 18 stdexcept 3 18 streambuf 3 18 string 3 19 strstream 3 19 Embedded Standard Template Library 3 20 3 22 embedded standard template li
52. 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library interrupt define interrupt handling Synopsis d Finclude lt signal h gt void interrupt int sig void func int int void interruptf int sig void func int int void interrupts int sig void func int int Description These functions are Analog Devices extensions to the ANSI standard The interrupt function determines how a signal received during program execution is handled The interrupt function executes the function pointed to by func at every interrupt sig the signal function executes the function only once The different variants of the interrupt functions differentiate between handler dispatching functions The variants will be appropriate for some applications and provide improved efficiency The default interrupt function dispatcher saves and restores all scratch registers and modes on the data stack around a call to the handler func when servicing an inter rupt This dispatcher will pass the interrupt ID for example S1G_PWRODWN to the handler as its parameter The interruptf interrupt dispatcher is similar to interrupt except that it switches between primary and secondary register sets to save and restore registers instead of using the data stack The interruptf function cannot be used in applications where nested interrupts are enabled This interrupt dispatcher will pass the interrupt ID to the handler a
53. 32 bit fractional data type 1 31 format having a range of 1 0 1 0 This is defined in the C C language as typedef long fract32 ETSI Header File The following are summary descriptions of the functions provided by the ETSI library as defined in the header file ETSI_fract_arith h Short absolute fractl6 abs_s fractl6 This function returns the 16 bit value that is the absolute value of the input parameter Where the input is 0x8000 saturation occurs and 0x7 fff is returned Short add fractl6 add fractl6 fractl6 This function returns the 16 bit result of addition of the two fract16 input parameters Saturation occurs with the result being set to 0x7 fff for overflow and 0x8000 for underflow Short division fractl6 div_s fractl6 fractl6 This function returns the 16 bit result of the fractional integer division of f1 by f2 f1 and f2 must both be positive fractional values with f2 greater than f1 Long division fractl6 div_l fract32 fractl6 VisualDSP 3 5 C C Compiler and Library Manual 1 111 for ADSP 219x DSPs C C Compiler Language Extensions This function produces a result which is the fractional integer division of the first parameter by the second Both inputs must be positive and the least significant word of the second parameter must be greater or equal to the first the result is positive leading bit equal to 0 and truncated to 16 bits Extract high most significant 16 bits
54. 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library must be declared using the pragma interrupt directive see on page 1 122 The altregisters directive see on page 1 122 may be used in conjunction with the interrupt pragma in the definition of the handler This dispatcher will not pass the interrupt ID to the handler The sig argument must be one of the signals listed in highest to lowest priority of interrupts in Table 3 17 Table 3 17 Signal Function Signals Values and Meanings Sig Value Definition SIG_PWRDWN power down interrupt SIG_STACKINT PC LOOP or COUNTER overflow on push or on pop when empty SIG_KERNEL kernel interrupt SIG_INT4 user assignable SIG_INT5 user assignable SIG_INT6 user assignable SIG_INT7 user assignable SIG_INTS user assignable SIG_INT9 user assignable SIG_INT10 user assignable SIG_INT11 user assignable SIG_INT12 user assignable SIG_INT13 user assignable SIGABRT software interrupt SIGILL software interrupt SIGINT software interrupt SIGSEGV software interrupt SIGTERM software interrupt SIGFPE software interrupt VisualDSP 3 5 C C Compiler and Library Manual 3 113 for ADSP 219x DSPs C Run Time Library Reference The signal function causes the receipt of the signal number sig to be handled in one of the following ways e SIG_DFL The default action is taken e SIG_IGN The signal
55. 5 C C Compiler and Library Manual for ADSP 219x DSPs documents support for all ADSP 219x processors Refer to VisualDSP 3 5 Product Bulletin for 16 Bit Processors for infor mation on all new and updated features and other release information XXX VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Preface Technical or Customer Support You can reach DSP Tools Support in the following ways e Visit the DSP Development Tools website at www analog com technology dsp developmentTools index html e Email questions to dsptools support analog com e Phone questions to 1 800 ANALOGD e Contact your ADI local sales office or authorized distributor e Send questions by mail to Analog Devices Inc One Technology Way P O Box 9106 Norwood MA 02062 9106 USA Supported Processors The name ADSP 219x refers to a family of Analog Devices 16 bit fixed point processors VisualDSP currently supports the following ADSP 219x processors ADSP 2191 DSP ADSP 2192 12 DSP ADSP 2195 DSP ADSP 2196 DSP ADSP 21990 DSP ADSP 21991 DSP and ADSP 21992 DSP VisualDSP 3 5 C C Compiler and Library Manual xxxi for ADSP 219x DSPs Product Information Product Information You can obtain product information from the Analog Devices website from the product CD ROM or from the printed publications manuals Analog Devices is online at www analog com Our website provides infor mation about a broad range o
56. After this step the new frame is officially in place 5 Continue saving registers and then executing the procedure A leaf procedure which does not require much stack space might choose to omit steps 1 and 2 operating without its own stack frame On the ADSP 219x DSPs the 32 words of protected space beyond the SP can be used for temporary storage To Return from a Procedure l Eo MaRe EE S If the hardware PC stack is not used the return address must be loaded from the stack and restored Restore miscellaneous saved registers Place the return value in the correct register if not there already Restore FP for the previous frame Reset SP to remove the frame for procedure Return to the caller 1 160 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler Miscellaneous Information This section contains a number of miscellaneous aspects of the design that may be helpful in understanding stack functionality e Procedures without prototypes can be called successfully provided the argument types correspond properly Prototypes are always good programming practice Programs that call library subroutines should always include header files e There is no special interface for calling system library functions They use the standard calling convention Register Classification This section describes all of the ADSP 219x processor registers Registers are listed in order of preferre
57. C Compiler and Library Manual for ADSP 219x DSPs 3 27 C Run Time Library Reference abs absolute value Synopsis d Finclude lt stdlib h gt int abs int j Description The abs function returns the absolute value of its int input The abs function is implemented through a built in The built in causes the com piler to emit an inline instruction to perform the required function at the point where abs is called abs INT_MIN returns INT_MIN Error Conditions The abs function does not return an error condition Example include lt stdlib h gt int i i abs 5 i 5 See Also fabs labs 3 28 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library acos arc cosine Synopsis include lt math h gt double acos double x float acosf float x fractl6 acos_frl6 fractl6 x Description The acos function returns the arc cosine of the argument The input must be in the range 1 1 The output in radians is in the range 0 7 The acos_fr16 function is only defined for input values between 0 and 0 9 0x7333 The input argument is in radians Output values range from acos 0 2 m 0x7FFF to acos 0 9 2 m 0x24C1 Error Conditions The acos function returns a zero if the input is not in the defined range Example d Finclude lt math h gt double y y acos 0 0 y n 2 See Also COS VisualDSP 3 5 C C Comp
58. C compiled functions or func tions from the C run time library Failure to revert to the default modes may cause applications to fail when running Table 1 13 MSTAT Register Modes Mode Description State SEC_REG Secondary Data Registers disabled BIT_REV Bit reversed address output disabled AR_SAT ALU saturation mode disabled M_MODE MAC result mode Integer Mode 16 0 format SEC_DAG Secondary DAG registers disabled 1 162 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler Complete List of Registers The following tables describe all of the registers for the ADSP 219x DSPs e Table 1 14 lists the data register s file registers e Table 1 15 lists the DAG1 registers e Table 1 16 lists the DAG2 registers e Table 1 17 lists miscellaneous registers You must always specify all parts of the SR and MR register groups For example either MR1 or SRO is valid but either SR or MR by itself is not valid Table 1 14 List of Data Register File Registers Register Description Notes AXO scratch AX1 scratch single word return AYO scratch AY1 scratch AR scratch AF scratch X0 scratch X1 scratch YO scratch Y1 scratch R1 0 scratch R2 scratch VisualDSP 3 5 C C Compiler and Library Manual 1 163 for ADSP 219x DSPs C C Run Time Model and Environment Table 1 14 List of Data Register File Registers Cont d
59. C keyword extensions no defs The no defs disable defaults switch directs the preprocessor not to define any default preprocessor macros include directories library direc tories libraries or run time headers no extra keywords The no extra keywords disable short form keywords switch directs the compiler not to recognize the Analog Devices keyword extensions that might affect conformance to ISO ANSI programs These extensions include keywords such as pm and dm which may be used as identifiers in conforming programs The alternate keywords that are prefixed with two leading underscores such as __pm and __dm continue to work The extra keywords switch on page 1 26 can be used to explicitly request support for the additional keywords no fp associative The no fp associative switch directs the compiler not to treat floating point multiplication and addition as associative 1 34 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler no_hardware_pc_stack The no_hardware_pc_stack switch directs the compiler to produce code to avoid the possibility of overflowing the hardware call stack This is done by popping from the hardware PC stack the return address at the start of each function and storing this value on the software data stack to be pushed back on the hardware stack just before returning from the function no mem The no mem switch causes the compiler to not invo
60. Compiler Language Extensions on page 1 59 Compiler options are set in the VisualDSP Integrated Development and Debug Environment IDDE from the Compile page of the Project Options dialog box see Specifying Compiler Options in VisualDSP on page 1 11 The selections control how the compiler processes your source files letting you select features that include the language dialect error reporting and debugger output For more information on the VisualDSP environment see the VisualDSP 3 5 Users Guide for ADSP 21xx DSPs and online Help VisualDSP 3 5 C C Compiler and Library Manual 1 3 for ADSP 219x DSPs C C Compiler Overview Standard Conformance Analog C compilers conform to the ISO IEC 998 1990 C standard and the ISO IEC 14882 1998 C standard in C mode with a small num ber of currently unsupported features or areas of divergence Unsupported features are Runtime type information RTTI for C is not supported Exceptions for C is not supported ANSI features that require operating system support are generally not supported This includes time h functionality in C The cc219x compiler does not provide comprehensive support of NaN s overflow and underflow conditions in their compiler sup port floating point routines Areas of divergence from Standard The double type is defined in terms of a single precision 32 bit floats not double precision 64 bit floats The cc219x compil
61. DSP run time model and run time environment The run time model which applies to compiler generated code includes descriptions of the layout of the stack data access and call entry sequence The C C run time environment includes the conventions that C C routines must follow to run on ADSP 219x DSPs Assembly routines linked to C C routines must fol low these conventions ADI recommends that assembly programmers maintain stack conventions This section contains e Using the Run Time Header on page 1 154 e Interrupt Table and Interface on page 1 154 e Stack Frame on page 1 155 e Stack Frame Description on page 1 157 e Miscellaneous Information on page 1 161 e Register Classification on page 1 161 e File I O Support on page 1 166 VisualDSP 3 5 C C Compiler and Library Manual 1 153 for ADSP 219x DSPs C C Run Time Model and Environment Using the Run Time Header The run time header is an assembly language procedure that initializes the processor and sets up processor features to support the C run time envi ronment The default run time header source code for the ADSP 219x processors is in the 219x_hdr asm file This run time header performs the following operations e Initializes the C run time environment e Calls your main routine e Calls exit routine defined in the C run time library Jibc d1b if main returns e Defines system halt instruction called from exit rout
62. DSPs C and C Run Time Library Guide If all the objects supplied to the driver have been built as C but are referencing a C object which is in a library the standard C libraries are not searched and the linker may issue an error concern ing unresolved symbol s This can be avoided by using the flags link switch see on page 1 27 which ensures that that the C libraries are linked from the default LDF files For example flags link MD__cplusplus 1 Note that this problem will only occur if the C object is in a library If it is in an object file the compiler will recognize it as a C object and link with the C libraries Working With Library Header Files When you use a library function in your program you should also include the function s header file with the include preprocessor command The header file for each function is identified in the Synopsis section of the function s reference page Header files contain function prototypes The compiler uses these prototypes to check that each function is called with the correct arguments A list of the header files that are supplied with this release of the cc219x compiler appears in Table 3 2 You should use a C standard text to aug ment the information supplied in this chapter Table 3 2 C Run Time Library Header Files Header Purpose Standard assert h Diagnostics ANSI ctype h Character Handling ANSI def2191 h Memory M
63. DSPs DSP Run Time Library arg get phase of a complex number Synopsis d Finclude lt complex h gt float argf complex_float a double arg complex_double a fractl6 arg_frl6 complex_fractl6 a Description This function computes the phase associated with a Cartesian number rep resented by the complex argument a and returns the result Refer to the description of the polar_fr16 function which explains how a phase represented as a fractional number is interpreted in polar notation see polar on page 4 91 Algorithm e c atan Re a Domain 3 4 x 1038 to 3 4 x 10 8 forargf arg 1 0 to 1 0 for arg_fr16 Note Im a Re a lt 1 for arg_fr16 VisualDSP 3 5 C C Compiler and Library Manual 4 27 for ADSP 219x DSPs DSP Run Time Library Reference autocoh autocoherence Synopsis dFinclude lt stats h gt void autocohf a n m c const float aL Input vector a int n Input samples KI int m Lag count XY float cl Output vector c void autocoh_frl6 a n m c const fractl6 a Input vector a int n Input samples int m Lag count AC fractl6 cL Output vector c Description This function computes the autocoherence of the input elements con tained within input vector a and stores the result to output vector c Algorithm n k 1 1 ce 2 6 8 ax 2 where k 0 1 m 1 and a is the mean value of i
64. E E 1 23 ANALY E E E E E 1 24 A oha A Nr iiner Deere NE mee SSE rTnIEEr Derren smi ae ree 1 24 WE iin e O ee eae een 1 24 eee E EE E E 1 24 Dmacrol definition 2cescccccssazscndcvendendieduaceakedea ednnvaskeds 1 24 iv VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs CONTENTS GREG Ne efile is spin serenienecertectmerntiominenieradwmaoess 1 25 default linkage asm CCH scaascisvcrssessessaresvarsntiantendvars 1 25 AY aar N SE 1 25 T eE R 1 26 E E E A E EE E N T 1 26 HAD E EE EE E E EE E E E E 1 26 A E rE N 1 26 OETA REPRE E E E AEAN A 1 26 flags asm compiler lib link mem switch switch2 1 27 AOrCECIO DUI serenana eni a R 1 27 AA E a eateeeueeasuelae 1 27 E EENE 1 27 P NOINE EEI ATE 1 28 og Meer errr cre citer ervey ey rene ier srr et tye Orr ter ier pereet ery enter rer rny cr 1 28 CENT E A E E E A E E E A 1 28 Whe E AEE NE ETE O AEA EEE EE SE ATN 1 29 ONE E AA N A NON AEA AO AE 1 29 T directory LF dieeta ennnenaana 1 29 A E E A AE EANN 1 30 anclude filename aiticincildisdeisiicminieaninibremaininiotnd 1 30 AIDE E tatiana E T E lidaneuaane 1 30 Jump dal Ona es 1 31 eee Lhi det aa 1 31 A DIAE gerger iar S 1 31 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs CONTENTS T EAN E NE oat A E 1 32 E E E E E T T E E A 1 32 a E R E EIE AE AE S EE A A E EET 1 32 sMo Menane oe ot acts a Sout peau ein RR 1 32 CE TRIE sutstantiwlisalnceatdeisaukn
65. Iterator types iter and sum These extensions created loop expressions that were used as a shorthand for working with arrays Assigning variables to specific registers asm This extension was used to declare a variable and specify a machine register in which to store it If you use any of these extensions in your C source code revise that source A 4 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler Legacy Support Compiler Switch Modifications The switches listed in Table A 1 have been removed or their actions have been modified If you use any of these switches to compile your C C code remove or replace the switch before recompiling the code with the new cc219x compiler Table A 1 C C Compiler Obsolete and Replaced Switches Release 6 1 Switch Operation under Release 6 1 Change for VisualDSP 3 5 a Specify Architecture File Replaced with T lt Linker Description File gt in linker command line Subsumed in VisualDSP build process dD dM and dN Output the results of prepro cessing and or list of defines Removed deps Instruct driver to rebuild only components of a target that have changed Removed Fno lt high med low gt Disable specified optimiza Removed tion level Optimization controlled with 0 switches fcond mismatch Allow conditional expression Removed mismatch finl
66. Library Manual 3 101 for ADSP 219x DSPs C Run Time Library Reference The inclusion of the sysreg h include file is mandatory when using mode_change Error Conditions The mode_change function does not return raise or set any error conditions Example d Finclude lt sysreg h gt main enable TIMER and disable AR saturation mode_change __MODE_ENA_TIMER MODE_DIS_AR_SAT See Also disable_interrupts enable_interrupts io_space_read io_space_write sysreg_read sysreg_write 3 102 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs modf separate integral and fractional parts Synopsis d Finclude lt math h gt C C Run Time Library double modf double f double fraction float modff float f float fraction Description The modf function separates the first argument into integral and fractional portions The fractional portion is returned and the integral portion is stored in the object pointed to by the second argument The integral and fractional portions have the same sign as the input Error Conditions The modf function does not return an error condition Example d Finclude lt math h gt double y n y modf 12 345 amp n See Also frexp fy 0 345 n 12 0 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs 3 103 C Run Time Library Reference pow raise to a power Synopsis include lt math h gt do
67. Pointer to filter state structure The function uses the following structure to maintain the state of the filter typedef struct fractl6 xhg Filter coefficients fractl6 d Start of delay line Xf Practle p Read Write pointer int k Number of coefficients int 1 Interpolation decimation index fir_state_frl6 Description The fir_decima_fri6 function performs an FIR based decimation filter It generates the filtered decimated response of the input data x and stores the result in the output vector y The number of input samples is specified by the argument n and the size of the output vector should be n 1 where is the decimation index The function maintains the filter state in the structured variable s which must be declared and initialized before calling the function The macro fir_init in the filter h header file is available to initialize the structure and is defined as VisualDSP 3 5 C C Compiler and Library Manual 4 59 for ADSP 219x DSPs DSP Run Time Library Reference define fir_init state coeffs delay ncoeffs index state h coeffs state d delay state p delay state k ncoeffs state 1 index The characteristics of the filter are dependent upon the number of filter coefficients and their values and on the decimation index supplied by the calling program A pointer to the coefficients should be stored in s gt h and s gt
68. Switches in Table 1 5 on page 1 20 A brief description of each switch follows the tables beginning on on page 1 21 1 12 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler Table 1 3 C or C Mode Selection Switches Switch Name Description c89 on page 1 21 Supports programs that conform to the ISO IEC 9899 1990 standard c on page 1 21 Supports ANSI ISO standard C with Analog Devices extensions Table 1 4 C C Compiler Common Switches Switch Name Description sourcefile on page 1 21 Specifies file to be compiled filename on page 1 22 A name tokens on page 1 22 Reads command line input from the file Asserts the specified name as a predicate alttok on page 1 23 Allows alternative keywords and sequences in sources bss on page 1 24 Causes the compiler to put global zero initialized data into a separate BSS style section build lib on page 1 24 Directs the librarian to build a library file aC on page 1 24 Retains preprocessor comments in the output file active only with the E or P switch Cc on page 1 24 Compiles and or assembles only does not link const read write on page 1 24 Specifies that data accessed via a pointer to const data may be modified elsewhere Dmacrol definition on page 1 24 Defines a macro debug
69. The revision can be specified as none or a number of the form described by regular expression 0 9 0 91 1 3 for example 1 123 The com piler defines a macro __SILICON_REVISION__ to a value specific to each silicon revision For unknown revisions the compiler will generate a warning and default to the latest known revision The parameter version represents a silicon revision of the processor specified by the proc switch on page 1 41 The none revision disables support for silicon errata For example cc219x proc ADSP 2191 si revision 0 1 In the absence of silicon revision the compiler selects the greatest silicon revision it knows about if any 1 44 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler A compiler will pass along the appropriate si revision switch setting when invoking another VisualDSP tool for example when the com piler driver invokes assembler and linker signed bitfield The signed bitfield make plain bitfields signed switch directs the compiler to make bitfields which have not been declared with an explicit signed or unsigned keyword to be signed This switch does not effect plain one bit bitfields which are always unsigned This is the default mode See also the unsigned bitfield switch on page 1 47 signed char The signed char make char signed switch directs the compiler to make the default type for char signed The c
70. These functions are described in io_space_read on page 3 67 and io_space_write on page 3 69 respectively VisualDSP 3 5 C C Compiler and Library Manual 1 97 for ADSP 219x DSPs C C Compiler Language Extensions An example use of io_space_read to read from address zero might be Finclude lt sysreg h gt int read_io_zero int value jo_space_read 0 return value An example use of io_space_write to write to address zero might be include lt sysreg h gt void write_io_zero int val jio_space_write 0 val Interrupt Control The inclusion of sysreg h allows the use of functions that generate the instructions to enable and disable interrupts The prototypes for these functions are as defined in sysreg h void enable_interrupts void void disable_interrupts void The following code provides an example of the use of enable_interrupts and disable_interrupts to disable and enable interrupts around a call to printf Finclude lt sysreg h gt d Finclude lt stdio h gt void interrupt_safe_iprint int val disable_interrupts printf d n val enable_interrupts 1 98 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler Mode Control The inclusion of sysreg h allows the use of a function that generates the instructions to enable and disable a series of modes using the zero latency mode control instructions The prototype for this function is
71. Under dynamic scaling the function will inspect the intermediate results and will only scale to avoid overflow Dynamic scaling therefore mini mizes loss of precision but at the possible cost of slightly reduced performance The block_exponent argument will be set to a value between 0 which indicates that no scaling was performed and 10g2 n as if static scaling was performed Algorithm N 1 X k xo yi n 0 When the sequence length n equals power of four the cfftrad4 algo rithm is also available Domain Input sequence length n must be a power of two and at least 16 VisualDSP 3 5 C C Compiler and Library Manual 4 37 for ADSP 219x DSPs DSP Run Time Library Reference cfftrad4 N point complex input FFT Synopsis include lt filter h gt void cfftrad4_frl6 in tL out wl wst n block_exponent scale_method const complex_fractl6 in input sequence S complex_fract16 t temporary working buffer z complex_fract16 out output sequence J const complex_fract16 wl twiddle sequence int wst twiddle factor stride asi int n number of FFT points zI int block_exponent block exponent of output data int scale method scaling method desired O none l static 2 dynamic Description This function transforms the time domain complex input signal sequence to the frequency domain by using the radix 4 Fast Fourier Transform The cfftrad4_fri16 function will
72. ___1ib_prog_term which is defined in the run time startup file Error Conditions The exit function does not return an error condition Example include lt stdlib h gt exit EXIT_SUCCESS See Also abort atexit 3 52 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs exp exponential Synopsis d Finclude lt math h gt double exp double float expf float Description C C Run Time Library The exp function computes the exponential value e to the power of its argument The argument must be in the range 87 9 88 6 Error Conditions The exp function returns the value HUGE_VAL and stores the value ERANGE in errno when there is an overflow error In the case of underflow the exp function returns a zero Example d Finclude lt math h gt double y y exp 1 0 y 2 71828 See Also alog log pow VisualDSP 3 5 C C Compiler and Library Manual 3 53 for ADSP 219x DSPs C Run Time Library Reference external_memory_read read from external memory Synopsis include lt sysreg h gt void external_memory_read int void Description The external_memory_read function causes the compiler to emit instruc tions to read from external memory at the address passed as two parameters and set the value read from that address as a return value The first parameter is the value of the top eight bits of the 24 bit external memory address to read The second paramet
73. a Domain x 9099 9099 for cotf cot 4 52 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs DSP Run Time Library countones count one bits in word Synopsis d Finclude lt math h gt int countones int parm int lcountones long parm Description This function counts the number of one bits in parm Algorithm j return X bit j of parm j where N is the number of bits in parm VisualDSP 3 5 C C Compiler and Library Manual 4 53 for ADSP 219x DSPs DSP Run Time Library Reference crosscoh cross coherence Synopsis include lt stats h gt void crosscohf a b n m c const float al Input vector a const float bl Input vector b int n Number of input samples int m Lag count or float cl Output vector c y void crosscoh_frl6 a n m c const fractl6 al Input vector a ay const fractl6 b Input vector b int n Number of input samples int m Lag count fractl6 cl Output vector c zy Description This function computes the cross coherence of the input elements con tained within input vector a and input vector b and stores the result to output vector c Algorithm c 8 a 0 ju b where k 0 1 m 1 a is the mean value of input vector a and b is the mean value of input vector b Domain 3 4 x 1038 to 3 4 x 10 8 for crosscohf 1 0 to 1 0 for crosscoh_frl6 4 54 VisualDSP 3
74. a base for conversion Error Conditions The strtol function returns a zero if no conversion can be made and the invalid string is stored in the object pointed to by endptr If the correct value results in an overflow positive or negative as appropriate LONG_MAX is returned If the correct value results in an underflow LONG_MIN is returned ERANGE is stored in errno in the case of either overflow or underflow 3 142 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library Example include lt stdlib h gt i tdefine base 10 char rem long int i i strtol 2345 5 amp rem base 7 2345 rem 5 See Also atoi atol strtoul VisualDSP 3 5 C C Compiler and Library Manual 3 143 for ADSP 219x DSPs C Run Time Library Reference strtoul convert string to unsigned long integer Synopsis d Finclude lt stdlib h gt unsigned long int strtoul const char nptr char endptr int base Description The strtoul function returns as an unsigned long int the value repre sented by the string nptr If endptr is not a null pointer strtoul stores a pointer to the unconverted remainder in endptr The strtoul function breaks down the input into three sections e white space as determined by isspace e initial characters e unrecognized characters including a terminating null character The initial characters may comprise an optional sign character 0x or 0X whe
75. ain nii ai e anii 3 96 mere pr Kon baed senro OE 3 97 a A oe 3 98 MNO aroa ENE 3 99 Loi Sn EE A A E P E e E E eV nyen CRT On Se 3 100 made GENOE aorar a a R AE 3 101 WOOO AIE EA A A A A E A AE EA N EA T 3 103 DON rara NA 3 104 REE crer E 3 105 BE a E E E ame 3 107 TE EAE AE 3 109 a U E AEE A E N IA PE A eas E TAR 3 110 A a E E Tern ter rarer E E E E E T nertry 3 111 DISA E E E E T 3 112 E E E eee 3 116 BSN EEE EEE EA I A ANE EA EA AA A 3 118 I A E EE E E eee ee eee 3 119 O ETE EE EAT ASE EE E E EE E A EE 3 120 A E E E T E E E E EE N N T 3 121 Te e E tee eee 3 122 xxii VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs ua i E E E E E EE 3 123 NICO EAA N EEA EE E E 3 124 SE A E A SCAT ET SE TEO RTE Ore 3 125 I ieee eee 3 126 WERROIOE unstated gene ea eed 3 127 CORO ceria se eee ees 3 128 POC piorar 3 129 PINON decease T E 3 130 CLE 5 gna ei reel ene ec ene or ner eee est Seyi moe pen ren errno ery Re ener 3 131 6 EE AEON T L E AOE NE E EE E T A 3 132 RTA cosain e ada benchaddab anon 3 133 SEPS coccinea 3 134 a E A E A E A EEN TAA A AE A E E S 3 135 O eaa wine aul cue 3 136 CL ae ee eRe OEE EYE RTD EE RED E E CRETC ER TER Efe amr RUT E A PRET ETE TEE 3 138 I a are cays oe N E 3 140 a E E E E N E E E E N 3 142 aa A EA EE EE aan eee 3 144 S ai ete eieuiesae er aiesaeee ewes 3 146 PEE TG E A A AA A 3 148 a STEP E EE E E A E A 3 151 i a EEE ENE AEE IE VRE AEE EAE AE E A EEE E EA ERT 3 154 PUY E E E E
76. an integer result or a fractional result The program context determines which variant is generated following the conversion algorithm of C When the compiler does not have enough context it generates an ambiguous operator message For example error more than one operator matches these operands If this error occurs cast the result of the multiply to the desired type Mixed Mode Operations Most operations supported for fractional values are supported for mixed fractional float or fractional double arithmetic expressions At run time a floating point value is converted to a fractional value and the operation is completed using fractional arithmetic 1 92 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler The assignment operations such as are the exception to the rule The logic of an assignment operation is defined by the type of a variable posi tioned on the left side of the expression Floating point operations require an explicit cast of a fractional value to the desired floating type Saturated Arithmetic The cc219x compiler supports saturated arithmetic for fractional data in the saturated arithmetic mode Whenever a calculation results in a bigger value than the fract data type represents the result is truncated wrapped around An overflow flag is set to warn the program that the value has exceeded its limits To prevent the overflow and to get the result as the
77. and data types for performing input and output Applications that use the facilities of this header file should link with the I O library 1ibio d1b in the same way as linking with the C run time library 1ibc d1b The library is thread safe but it is not interrupt safe and should not therefore be called either directly or indirectly from an interrupt service routine VisualDSP 3 5 C C Compiler and Library Manual 3 13 for ADSP 219x DSPs C and C Run Time Library Guide The implementation of the stdio h routines is based on a simple interface with a device driver that provides a set of low level primitives for open close read write and seek operations By default these operations are provided by the VisualDSP simulator and EZ KIT Lite systems How ever alternative device drivers may be registered see Extending I O Support To New Devices on page 1 166 that can then be used through the stdio h functions The following restrictions apply to this software release e Functions tmpfile and tmpnam are not available e Functions rename and remove are only supported under the default device driver supplied by the VisualDSP simulator and EZ kits and they only operate on the host file system e Positioning within a file that has been opened as a text stream is only supported if the lines within the file are terminated by the character sequence r n When using the default device driver all I O operations are channel
78. arguments The names and arguments for each function appear on the function s reference page The names and arguments for each function appear in the section ETSI Header File on page 1 111 Like other functions you use ETSI functions should be declared Declara tions are supplied in the header file ETSI_fract_arith h which must be included in any source files where ETSI functions are called The function names are C function names If you call C run time library functions from an assembly language program you must use the assembly version of the 1 108 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler function name prefix an underscore on the name For more information on naming conventions see the section C C and Assembly Language Interface on page 1 169 Several of the ETSI routines are provided with carry and overflow check ing Where overflow or carry occurs the global variables Carry and Overflow will be set It is your responsibility to reset these variables in between operations The Carry and Overflow variables are represented by integers and are prototyped in the 1ibetsi h system header file With the ETSI functions provided by Analog Devices this can be switched off by compiling with __NO_ETSI_FLAGS defined in the compiler command line In fact this is the default for the ADSP 219x DSP implementation If the user wishes to keep track of these flags for debugging purposes th
79. arrays in Program Memory pm The compiler issues an error if an attempt is made to use a variable length array in pm As an example if you were to implement a routine for computation of a product of three matrices you need to allocate a temporary matrix of the same size as input matrices Declaring automatic variable size matrix is much easier then explicitly allocating it in a heap The expression declares an array with a size that is computed at run time The length of the array is computed on entry to the block and saved in case sizeof is applied to the array For multidimensional arrays the boundaries are also saved for address computation After leaving the block all the space allocated for the array and size information will be deallocated For example the following program prints 40 not 50 include lt stdio h gt void foo int main foo 40 1 86 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler void foo int n char cin n 50 printf d sizeof c Non Constant Aggregate Initializer Support The compiler includes extended support for aggregate initializers The compiler does not require the elements of an aggregate initializer for an automatic variable to be constant expressions The following example shows an initializer with elements that vary at run time void initializer float a float b float the_array 2 a b a b All automatic
80. as defined in sysreg h void mode_change const int _mode_spec The _mode_spec parameter is a bitmask of mode definitions defined in sysreg h These definitions are ODE_ENA_AV_LATCH 0x1 ODE_ENA_AR_SAT 0x2 ODE_ENA_M_MODE 0x4 __MODE_ENA_TIMER 0x8 ODE_DIS_AV_LATCH 0x100 ODE_DIS_AR_SAT 0x200 ODE_DIS_M_MODE 0x400 ODE_DIS_INT 0x1000 Near and Far Type Qualifiers The ADSP 219x processors can have external memory which will not by default for reasons of efficiency be addressable in 16 bits from C C source The compiler provides an extension to support access to external memory which allows use of external memory in C applications without degrading performance when accessing internal memory This extension is enabled using a C type qualifiers far and near Declarations This extension is enabled using a far and near type qualifier in C C variable declarations The following are example uses of the far and near type qualifiers VisualDSP 3 5 C C Compiler and Library Manual 1 99 for ADSP 219x DSPs C C Compiler Language Extensions nt near near nnl declares nnl to be a pointer which resides in near memory and points to a near memory integer nt nn2 declares nn2 to be a pointer which resides in near memory and points to a near memory integer far near nfl declares nfl to be a pointer which resides in near memory and po
81. benefiting from such enhancements Note that the default setting or debug mode within the VisualDSP IDDE is for non optimized compilation in order to assist programmers in diagnosing problems with their initial coding The optimizer is enabled in VisualDSP by checking the Enable optimization checkbox under the Project Options gt Compile tab This adds the 0 enable optimization switch on page 1 37 to the compiler invocation A release build from within VisualDSP will automatically enable optimization 2 4 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Achieving Optimal Performance from C C Source Code Using the Statistical Profiler Tuning an application begins with an understanding of which areas of the application are most frequently executed and therefore where improve ments would provide the largest gains The statistical profiling feature provided in VisualDSP is an excellent means for finding these areas More details about how to use it may be found in the VisualDSP 3 5 User s Guide The particular advantage of statistical profiling is that it is completely unobtrusive Other forms of profiling insert instrumentation into the code perturbing the original optimization code size and register alloca tion to some degree The best methodology is usually to compile with both optimization and debug information generation enabled In this way you can obtain a pro file of the
82. cfft function 4 36 N point complex input FFT cfftrad4 function 4 38 N point inverse FFT ifft function 4 77 N point inverse FFT ifftrad4 function 4 79 N point real input FFT rfft function 4 94 N point real input FFT rfftrad4 function 4 96 near type qualifiers 1 99 near pointers 1 99 size 1 100 new devices I O support 1 166 next argument in variable list 3 158 no_hardware_pc_stack compiler switch 1 35 no alttok disable alternative tokens compiler switch 1 33 no anach disable C anachronisms compiler switch 1 53 no bss compiler switch 1 33 no builtin no builtin functions compiler switch 1 34 no circbuf no circular buffer compiler switch 1 34 no def disable definitions compiler switch 1 34 no demangle disable demangler compiler switch 1 53 no extra keywords disable short form keywords compiler switch 1 34 no fp associative compiler switch 1 34 no mem not invoking memory initializer compiler switch 1 35 non constant initializer support compiler 1 87 non unit stride avoiding 2 21 norm normalization 4 90 no std ass disable standard assertions compiler switch 1 35 no std def disable standard definitions compiler switch 1 35 no std inc disable standard include search compiler switch 1 35 1 20 VisualDSP 3 0 C C Compiler and Library Manual for ADSP 219x DSPs INDEX no std lib disable standard library search compiler switch 1 36 nothre
83. cnsenemrenseastecs Supported Processors sorisiorsurrinkoreniurinti iiinn Product Information mossero AOAN E Aa a EA E A EAE AA D A E DSP Piste eae hommes Related Documents acssesories Online Technical Documentation sesessrrrerrrererrerrcersiessseeras From Visti Se ccces si tcudcacinssnsh cendiedecancenamnonsntsiassvndunenss Fror Wo Oe sat iecincs ces shnapeipahid pian a Pn the We eee eee eae Prinred Mantab wee ieee VisualDSP Documentation Set wiocessccisietesaicarseasrcaraiesd Hardware Manuals ssrisereunernienanur a Pa E A TA VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs iii CONTENTS Contictine DSP Publications cicercinacersneniectceenrememenierieonese xxxvii Notanon eee oer eee ee XXXVIl COMPILER gt Compiler Overbeek oe eee 1 2 tS ssrssirsnsrsn isson n A 1 4 Compiler Command Line Interface 6 o cicccsciscwriacmeststimosecsnaions 1 6 Tete ee ihe Canpiler soricei 1 7 Specifying Compiler Options in VisualDSP wee 1 11 Compiler Command Line Switches scence 1 12 ChCe Compiler Switch Sunmaries cciassecarcsacessaneceesciesnses 1 12 C C Mode Selection Switch Descriptions 00 sees 1 21 MEAT dacepis E A E E E E A A E ae 1 21 SHIGE E ARNE 1 21 C C Compiler Common Switch Descriptions 1 21 TN nancies 1 21 ELE a E E wane nee enti E E E aetrem 1 22 A namel tokens scicicanersdaceucoiedcandesertaneanaatad commeyerhinsonasaae 1 22 E a E 1 23 e EEI EE E E E A EEEE A EE
84. const fractl6 cinl int clenl const fractl6 cin2 int clen2 fractl6 cout 2 D Convolution void conv2d_frl6 const fractl6 cinl int crowl int ccoll const fractl6 cin2 int crow2 int ccol2 fractl6 cout 2 D Convolution 3x3 Matrix void conv2d3x3_frl16 const fractl6 cin int crowl int ccoll const fractl6 cin2 3 3 fractl6 cout Compression Expansion A law Compression void a_compress const short inl short outL int n VisualDSP 3 5 C C Compiler and Library Manual 4 9 for ADSP 219x DSPs DSP Run Time Library Guide Table 4 3 Transformation Functions Cont d Description Prototype A law Expansion void a_expand const short inl short outL int n p law Compression void mu_compress const short inl short outL int n p law Expansion void mu_expand const char inl short out int n math h Math Functions The standard math functions have been augmented by implementations for the float data type and in some cases for the fract16 data type Table 4 4 provides a summary of the functions defined by the math h header file Descriptions of these functions are given under the name of the double version in the C Run Time Library Reference on page 3 26 This header also provides prototypes for a number of additional math functions clip copysign max min and an integer function countones These
85. convolution Synopsis include lt filter h gt void convolve_frl6 cinl clenl cin2 clen2 cout const fractl6 cinl pointer to input sequence 1 int clenl length of the input sequence 1 const fractl6 cin2 pointer to input sequence 2 int clen2 length of the input sequence 2 float cout pointer to output sequence Description This function convolves two sequences pointed to by cinl and cin2 If cinl points to the sequence whose length is clen1 and cin2 points to the sequence whose length is clen2 then resulting sequence pointed to by cout has length clenl clen2 1 Algorithm Convolution between two sequences cinl and cin2 is described as clen2 1 cout n ZN cinI n k clen2 1 e cin 2 clen2 1 k for n 0 to clen1 clen2 2 Values for cin1 j are considered to be zero for j lt Oor j gt clen1 1 VisualDSP 3 5 C C Compiler and Library Manual 4 47 for ADSP 219x DSPs DSP Run Time Library Reference Example Here is an example of a convolution where cin1 is of length 4 and cin2 is of length 3 If we represent cinl as A and cin2 as B the elements of the output vector are ALO B O AL1 BLO ALOJ B AL2 BLO AL1I B ALOI BL2 AL3 BLO AL2 B A 1 B 2 3 B A 2 B 2 A 3 B 2 Domain 1 0 to 1 0 4 48 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs conv2d 2 D con
86. declarations It applies to the variable or field declaration that immediately follows the pragma Use of this pragma causes the compiler to generate the next vari able or field declaration aligned on a boundary specified by num The align pragma is useful for declaring arrays that need to be on a circu lar boundary Such arrays might be required to make use of a bit reversal sorting algorithm that is implemented using the ADSP 219x processor s DAG bit reversal mode pragma align 256 int arr 128 pragma pad alignopt The pragma pad alignopt may be applied to struct definitions It applies to struct definitions that follow until the default alignment is restored by omitting a ignopt for example by pragma pad with empty parentheses This pragma is effectively a shorthand for placing pragma align before every field within the struct definition VisualDSP 3 5 C C Compiler and Library Manual 1 121 for ADSP 219x DSPs C C Compiler Language Extensions The following example shows how to use pragma pad pragma pad 4 struct int i int j pS Alec pragma pad Interrupt Handler Pragmas The interrupt pragma s include interrupt and altregisters pragmas pragma interrupt The interrupt pragma may be used before a function declaration or defi nition It applies to the function declaration or definition that immediately follows the pragma Use of this pragma causes the compiler to generate the fun
87. does not recognize them Function Pragmas Function pragmas include pragma const pragma pure pragma alloc pragma result_alignment pragma regs_clobbered and pragma optimize_ off for_speed for_space as_cmd_line pragma const The pragma const pragma asserts to the compiler that a function does not have any side effects such as modifying global variables or data buffers and the result returned is only a function of the parameter values The pragma may be applied to a function prototype or definition It helps the compiler since two calls to the function with identical parameters will always yield the same result This way calls to pragma const functions may be hoisted out of loops if their parameters are loop independent VisualDSP 3 5 C C Compiler and Library Manual 2 31 for ADSP 219x DSPs Pragmas pragma pure Like pragma const this pragma asserts to the compiler that a function does not have any side effects such as modifying global variables or data buffers However the result returned may be a function of both the parameter values and any global variables The pragma may be applied to a function prototype or definition Two calls to the function with identical parameters will always yield the same result provided that no global vari ables have been modified between the calls Hence calls to pragma pure functions may be hoisted out of loops if their parameters are loop inde pendent and no global varia
88. enables Procedural Optimizations 0 Refer to Oa on page 1 37 Ov num on page 1 38 and O on page 1 37 for more information e Interprocedural optimizations IPA The compiler performs advanced aggressive optimization over the whole program in addition to the per file optimizations in proce dural optimization IPA is enabled using the ipa switch and additionally enables Procedural Optimizations 0 See ipa on page 1 30 and O on page 1 37 for more information Interprocedural Analysis The compiler has an optimization capability called nterprocedural Analysis IPA that allows the compiler to optimize across translation units instead of within individual translation units This capability allows the compiler to see all of the source files used in a final link at compilation time and to use that information while optimizing VisualDSP 3 5 C C Compiler and Library Manual 1 57 for ADSP 219x DSPs Compiler Command Line Interface Interprocedural analysis is enabled by selecting the Interprocedural analy sis option on the Compiler tab accessed via the VisualDSP Project Options dialog box or by specifying the ipa command line switch on page 1 30 The ipa switch automatically enables the 0 switch to turn on optimization Use of the ipa switch causes additional files to be generated along with the object file produced by the compiler These files have ipa and opa filename extensio
89. file through the listed stages to produce a DXE file see file names in Table 1 2 on page 1 10 Table 1 3 on page 1 13 lists the switches that select the language dialect Although many switches are generic between C and C some of them are valid in C mode only A summary of the generic C C compiler switches appears in Table 1 4 on page 1 13 A summary of the C spe cific compiler switches appears in Table 1 5 on page 1 20 The summaries are followed by descriptions of each switch When developing a DSP project you may find it useful to modify the compiler s default options settings The way you set the com piler s options depends on the environment used to run the DSP development software See Specifying Compiler Options in Visu alDSP on page 1 11 for more information 1 6 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler Running the Compiler Use the following general syntax for the cc219x command line cc219x switch switch sourcefile sourcefile where e switch is the name of the switch to be processed The compiler has many switches These switches select the operations and modes for the compiler and other tools Command line switches are case sensitive For example 0 is not the same as o e sourcefile is the name of the file to be preprocessed compiled assembled and or linked A file name can include the drive directory file name and file exten
90. follows the pragma is not removed even though Interpro cedural Analysis IPA sees that it is not used Use this pragma for C functions that are only called from assembler routines such as the startup code sequence invoked before main The following example shows how to use this pragma int delete_me int x return x 2 pragma retain_name int keep_me int y return yt2 int main void return 0 Since the program has no uses of either delete_me or keep_me the compiler will remove delete_me but will keep keep_me because of the pragma You do not need to specify retain_name for main VisualDSP 3 5 C C Compiler and Library Manual 1 127 for ADSP 219x DSPs C C Compiler Language Extensions For more information on IPA see Interprocedural Analysis on page 1 57 pragma weak_entry The pragma weak_entry may be used before a static variable or function declaration or definition It applies to the function or variable declaration or definition that immediately follows the pragma Use of this pragma causes the compiler to generate the function or variable definition with weak linkage The following are example uses of the pragma weak_entry directive pragma weak_entry int w_var 0 pragma weak_entry void w_func Function Side Effect Pragmas The function side effect pragmas are used before a function declaration to give the compiler additional information about the function
91. function may return the value of a restricted pointer that is local to the function and the return value may then be assigned to another restricted pointer If your program uses a restricted pointer in a way that it does not uniquely refer to storage then the behavior of the program is undefined Variable Length Array Support The compiler supports variable length automatic arrays Unlike other automatic arrays variable length ones are declared with a non constant length This means that the space is allocated when the array is declared and deallocated when the brace level is exited The compiler does not allow jumping into the brace level of the array and produces a compile time error message if this is attempted The compiler does allow breaking or jumping out of the brace level and it deallocates the array when this occurs VisualDSP 3 5 C C Compiler and Library Manual 1 85 for ADSP 219x DSPs C C Compiler Language Extensions You can use variable length arrays as function arguments as shown in the following example struct entry var_array int array_len char data Larray_len Larray_len The compiler calculates the length of an array at the time of allocation It then remembers the array length until the brace level is exited and can return it as the result of the sizeof function performed on the array Because variable length arrays must be stored on the stack it is impossible to have variable length
92. hexadecimal floating point number is sign 0x 0X hexdigs L hexdigs p P sign digits 3 34 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library A hexadecimal floating point number may start with an optional plus or minus followed by the hexadecimal prefix 0x or 0X This character sequence must be followed by one or more hexadecimal characters that optionally contain a decimal point The hexadecimal digits are followed by a binary exponent that consists of the letter p or P an optional sign and a non empty sequence of decimal digits The exponent is interpreted as a power of two that is used to scale the fraction represented by the tokens hexdigs hexdigs The first character that does not fit either form of number will stop the scan Error Conditions The atof function returns a zero if no conversion could be made If the correct value results in an overflow a positive or negative as appropriate HUGE_VAL is returned If the correct value results in an underflow 0 0 is returned The ERANGE value is stored in errno in the case of either an over flow or underflow Notes The function reference atof pdata is functionally equivalent to strtod pdata char NULL and therefore if the function returns zero it is not possible to determine whether the character string contained a valid representation of 0 0 or some invalid numerical string
93. in order to enable it to improve the code surrounding the function call These prag mas should be placed before a function declaration and apply to that function For example pragma pure long dot short short int The function side effect pragmas are alloc pure const regs_clobbered and result_alignment 1 128 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler pragma alloc The pragma alloc tells the compiler that the function behaves like the library function malloc returning a pointer to a newly allocated object An important property of these functions is that the pointer returned by the function does not point at any other object in the context of the call In the example fpragma alloc int new_buf void int vmul int a int b int out new_buf for i 0 i lt N i outLi ali bLil return out the compiler can reorder the iterations of the loop because the pragma alloc tells it that a and b cannot overlap out The GNU attribute malloc is also be supported with the same meaning pragma pure The pragma pure tells the compiler that the function does not write to any global variables and does not read or write any volatile variables Its result therefore is a function of its parameters or of global variables If any of the parameters are pointers the function may read the data they point at but it may not write it As this means t
94. incr const void base size_t buflen Both incr and buflen are specified in bytes since the operation deals in void pointers The operation is equivalent to ptr incr if ptr lt base ptr buflen else if ptr gt base buflen ptr buflen An example of this built in function is void func int array int n int incr int len int i idx 0 int ptr array scale increment and length by size of item pointed to incr sizeof ptr len sizeof ptr for i 0 i lt n i ptr incr ptr __builtin_circptr ptr incr array len VisualDSP 3 5 C C Compiler and Library Manual 1 105 for ADSP 219x DSPs C C Compiler Language Extensions ETSI Support The ETSI European Telecommunications Standards Institute support for ADSP 219x processors is a collection of functions that provides high performance implementations for operations commonly required by DSP applications These operations provided by the ETSI library libetsi d1b and compiler built in functions defined in ETSI_fract_arith h include support for fractional or fixed point arith metic The results obtained from of use of these operations have well defined overflow and saturation conditions The ETSI support operations are Analog Devices extensions to ANSI C standard The ETSI support contains functions that you can call from your source program The following topics describe how to use this suppor
95. inline int max3 int a int b int c return max a max b c A function declared inline must be defined its body must be included in every file in which the function is used The normal way to do this is to place the inline definition in a header file Usually it will also be declared static In some cases the compiler does not output object code for the function for example the address is not needed for an inline function called only from within the defining program However recursive calls and functions whose addresses are explicitly referred to by the program are compiled to assembly code The compiler only inlines functions even those declared using the inline keyword when optimizations are enabled using the 0 switches as described on page 1 37 1 62 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler Inline Assembly Language Support Keyword asm The cc219x asm construct allows you to code ADSP 219x assembly lan guage instructions within a C or C function and to pass declarations and directives through to the assembler The asm construct is useful for expressing assembly language statements that cannot be expressed easily or efficiently with C constructs The asm keyword allows you code complete assembly language instruc tions or you can specify the operands of the instruction using C expressions When specifying operands with a C expression you do not need to know
96. input operand constraint Indicates the constraint is temporary constraint Indicates the constraint is both an input and output operand 1 The use of any letter not listed in the table results in unspecified behavior The compiler does not check the validity of the code by using the constraint letter Table 1 10 Register Names for asm Constructs Clobber String Meaning AX1 AXO AY1 AYO AR AF ALU registers MX1 MXO MYI MYO MR1 MRO MAC registers MR2 ST ess SES PSR SRO oT SBP SRAT Shifter registers POr EL SOO MB OR Les DAG addressing registers MO MI M2 M3 M4 M6 M7 Modifier registers Bo B1 B2 B3 B4 B5 B6 B7 Base registers DMPG1 DMPG2 Page registers a ES eaa Ea n BLES S aaa E a LGN a E Length register PX PMD DMD bus exchange register VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs 1 73 C C Compiler Language Extensions Table 1 10 Register Names for asm Constructs Contd Clobber String Meaning astat ALU status register MSTAT MMODE SSTAT mode control register IMASK ICNTL IFC Interrupt registers CNTR STACKA STACKP Program sequencer register TJPG IOPG Paging overlay register ADSP 2190 DSP only Tee Condition code register memory Unspecified memory location s Assembly Con
97. is ignored e Function address The function pointed to by func is executed The function pointed to by func is executed once when the signal is received Handling is then returned to the default state Interrupts are not nested by the default start up file Error Conditions The signal function returns SIG_ERR and sets errno to SIG_ERR if it does not recognize the requested signal Example dFinclud e lt signal h gt void handler int sig main sig sig sig sig enable power d al SIG_PWRDWN disable power al SIG_PWRDW enable power d alf SIG_PWRDWN own in hand down interr SIG_ own in disable power down interr alf SIG_PWRDWN handler Lerrup er GN cerrup SIG_IGN Interrupt Service Routine ISR t and register ISR pt t and register ISR pt 3 114 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library See Also interrupt raise VisualDSP 3 5 C C Compiler and Library Manual 3 115 for ADSP 219x DSPs C Run Time Library Reference sin sine Synopsis include lt math h gt double sin double x float sinf float x fractl6 sin_frl6 fractl6 x Description The sin function returns the sine of the argument x The input is inter preted as a radian the output is in the range 1 1 The sin_fr16 function inputs a f
98. it returns as the function s result and a phase that is returned via the second argument phase Refer to the description of the polar_fr16 function which explains how a phase represented as a fractional number is interpreted in polar notation see polar on page 4 91 Algorithm magnitude cabs a phase arg a Domain 3 4 x 1038 to 3 4 x 1038 for cartesianf cartesian 1 0 to 1 0 for cartesian_frl6 4 32 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Example d Finclude lt complex h gt complex_float point 2 0 float phase DSP Run Time Library float mag mag cartesianf point amp phase mag 2 0 phase T VisualDSP 3 5 C C Compiler and Library Manual 4 33 for ADSP 219x DSPs DSP Run Time Library Reference cdiv complex division Synopsis include lt complex h gt complex_float cdivf complex_float a complex_float b complex_double cdiv complex_double a complex_double b complex_fractl6 cdiv_frl6 complex_fractl6 a complex_fractl6 b Description This function computes the complex division of two complex inputs a and b and returns the result Algorithm Re a Re b Im a Im b Re b Im b Re b Im a Im b Re a Re c Im c 5 gt Re b Im b Domain 3 4 x 10 8 to 3 4 x 1038 for cdivf cdiv 1 0 to 1 0 for cdiv_fr16 4 34 VisualDSP 3 5 C C Compiler and Li
99. it can verify that the circular index or pointer is always within the circular buffer range See Circular Buffer Built In Functions on page 1 103 fp associative The fp associative switch directs the compiler to treat floating point multiplication and addition as associative full version The full version display versions switch directs the compiler to dis play version information for build tools used in a compilation VisualDSP 3 5 C C Compiler and Library Manual 1 27 for ADSP 219x DSPs Compiler Command Line Interface 8 The g generate debug information switch directs the compiler to out put symbols and other information used by the debugger When the g switch is used in conjunction with the 0 enable optimiza tion switch the compiler performs standard optimizations The compiler also outputs symbols and other information to provide limited source level debugging through VisualDSP This combination of options provides line debugging and global variable debugging You can invoke this switch by selecting the Generate debug infor mation check box in the VisualDSP Project Options dialog box Compile tab General category When g and 0 are specified no debug information is available for local variables and the standard optimizations can sometimes re arrange program code in a way that inaccurate line number information may be produced For full debugging capabilities use the g switch without th
100. jump tables is data memory jump dm L directory directory The L library search directory switch directs the linker to append the directory to the search path for library files l library The 1 link library switch directs the linker to search the library for functions when linking The library name is the portion of the file name between the 1ib prefix and d1b extension For example the compiler command line switch 1c directs the linker to search in the library named c for functions This library resides in a file named libc d1b Normally you should list all object files on the command line before the 1 switch This ensures that the functions and global variables the object files refer to are loaded in the given order This option may be specified more than once libraries are searched as encountered during the left to right processing of the command line VisualDSP 3 5 C C Compiler and Library Manual 1 31 for ADSP 219x DSPs Compiler Command Line Interface M The M generate make rules only switch directs the compiler not to com pile the source file but to output a rule which is suitable for the make utility describing the dependencies of the main program file The format of the make rule output by the preprocessor is object file include file MD The MM generate make rules and compile switch directs the preprocessor to print to a file called original_filename d a rule describing
101. library and FlexLM network license manager soft ware documentation Viewing and printing the HTML files require a browser such as Internet Explorer 4 0 or higher PDF VisualDSP tools manuals in Portable Documentation Format one PDF file for each manual Viewing and printing the PDF files require a PDF reader such as Adobe Acrobat Reader 4 0 or higher If documentation is not installed on your system as part of the software installation you can add it from the VisualDSP CD ROM at any time Access the online documentation from the VisualDSP environment Windows Explorer or Analog Devices website From VisualDSP Access VisualDSP online Help from the Help menu s Contents Search and Index commands Open online Help from context sensitive user interface items toolbar buttons menu commands and windows XXXiV VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Preface From Windows In addition to any shortcuts you may have constructed there are many ways to open VisualDSP online Help or the supplementary documenta tion from Windows Help system files CHM files are located in the Help folder and PDF files are located in the Docs folder of your VisualDSP installation The Docs folder also contains the Dinkum Abridged C library and FlexLM net work license manager software documentation Using Windows Explorer e Double click any file that is part of the V
102. n fractl6 var_frl6 a const fractl6 al int n Description n Pointer to input vector a Number of input samples Pointer to input vector a Number of input samples REJ This function computes the variance of the input elements contained within input vector a and returns the result Algorithm n 1 n 1 2 2 o a O i 0 i 0 Cc Domain 3 4 x 10 8 to 3 4 x 10 8 1 0 n n 1 to 1 0 for varf for var_frl6 4 108 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs DSP Run Time Library zero_cross count zero crossings Synopsis d Finclude lt stats h gt int zero_crossf a n const float al Pointer to input vector a int n Number of input samples Kg zero_cross_frl6 a n const fractl6 al Pointer to input vector a int n Number of input samples Description This function computes the number of times that a signal crosses over the zero line and returns the result If all the input values are zero the func tion returns a zero Algorithm The actual algorithm is different from the one shown below because the algorithm needs to handle the case where an element of the array is zero However this example should give you a basic understanding if a i gt 0 amp amp a i 1 lt 0 a i lt 0 amp amp a i 1 gt 0 the number of zeros is increased by one Domain 3 4 x 103
103. new h header declares several functions that allocate and free storage 3 22 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Documented Library Functions C C Run Time Library The following tables list the library functions documented in this chapter These tables list the functions by the header file in which they are located whereas the C Run Time Library Reference on page 3 26 presents the functions in alphabetic order Table 3 5 Documented Library Functions in the ctype h Header File isalnum isalpha iscntrl isdigit isgraph islower isprint ispunct isspace isupper isxdigit tolower toupper Table 3 6 Documented Library Functions in the math h Header File acos asin atan atan2 ceil cos cosh exp fabs floor fmod frexp isinf isnan Idexp log log10 modf pow sin sinh sqrt tan tanh Table 3 7 Documented Library Functions in the set jmp h Header File longjmp setjmp VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs 3 23 Documented Library Functions Table 3 8 Documented Library Functions in the signal h Header File clear_interrupt interrupt raise signal Table 3 9 Documented Library Functions in the stdarg h Header File va_arg va_end va_start Table 3 10 Supported Library Functions in the stdio h Header File
104. normally the case for assembly lan 1 78 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler guage programming as well If you need special access to all 24 bits you should use an assembly language subroutine and work with the PX register The following listing shows examples of dual memory keyword syntax int pm abc 100 declares an array abc with 100 elements in Program Memory int dm def 100 declares an array def with 100 elements in Data Memory By int ghi 100 declares an array ghi with 100 elements in Data Memory Kf int pm pm pp declares pp to be a pointer which resides in Program Memory and points to a Program Memory integer Z int dm dm dd declares dd to be a pointer which resides in primary Data emory and points to a Data Memory integer int dd declares dd to be a pointer which resides in Data Memory and points to a Data Memory integer ef int pm dm dp declares dp to be a pointer which resides in Data Memory and points to a Program Memory integer ey int pm dp declares dp to be a pointer which resides in Data Memory and points to a Program Memory integer int dm pm pd declares pd to be a pointer which resides in pm secondary Data Memory and points to a Data Memory integer int pm pd declares pd to be a pointer which resides in Program memory and
105. obvious to you exactly why it is occurring a good way to learn about the cause is the Pipeline Viewer This can be accessed through Debug Windows gt Pipeline Viewer in the VisualDSP 3 5 IDDE By single stepping through the program you will see where the stall occurs Note that the Pipeline Viewer is only avail able within a simulator session 2 24 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Achieving Optimal Performance from C C Source Code Using Built In Functions in Code Optimization Built in functions also known as compiler intrinsics provide a method for the programmer to efficiently use low level features of the DSP hard ware while programming in C Although this section does not cover all the built in functions available for more information refer to Compiler Built In Functions on page 1 94 it presents some code examples where implementation choices are available to the programmer Fractional Data Fractional data represented as an integral type can be manipulated in two ways one way is the use of long promoted shifts and multiply constructs and the other is the use of compiler built in functions The built in func tions are recommended as they give you the most control over your data Let s consider the fractional dot product algorithm This may be written as long dot_product short a short b int i long sum 0 for i 0 i lt 100 i this line is performan
106. of functions that you can call from your C programs The information that follows applies to all of the functions in the library Notation Conventions An interval of numbers is indicated by the minimum and maximum sepa rated by a comma and enclosed in two square brackets two parentheses or one of each A square bracket indicates that the endpoint is included in the set of numbers a parenthesis indicates that the endpoint is not included Reference Format Each function in the library has a reference page These pages have the fol lowing format Name and Purpose of the function Synopsis Required header file and functional prototype Description Function specification Error Conditions How the function indicates an error Example Typical function usage See Also Related functions 3 26 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library abort abnormal program end Synopsis d include lt stdlib h gt void abort void Description The abort function causes an abnormal program termination by raising the SIGABRT signal If the SIGABRT handler returns abort calls exit to terminate the program with a failure condition Error Conditions The abort function does not return Example d Finclude lt stdlib h gt extern int errors if errors terminate program if abort errors are present See Also atexit exit VisualDSP 3 5 C
107. on function parameters Using the Const Qualifier By default the compiler assumes that the data referenced by a pointer to const type will not change Therefore another way to tell the compiler that the two arrays a and b do not overlap is to use the const keyword void copy short a const short b int i for i 0 i lt 100 i ali b i Good pointers disambiguated via const qualifier The use of const in the above example will have a similar effect on the no_alias pragma see in pragma no_alias on page 2 36 In fact the const implementation is better since it also allows the optimizer to use the fact that accesses via a and b are independent in other parts of the code not just the inner loop In C it is legal though bad programming practice to use casts to allow the data pointed to by pointers to const type to change This should be avoided since by default the compiler will generate code that assumes VisualDSP 3 5 C C Compiler and Library Manual 2 23 for ADSP 219x DSPs Loop Guidelines const data does not change If you have a program that modifies const data through a pointer you can generate standard conforming code by using the compile time flag const read write Avoiding Long Latencies All pipelined machines will introduce stall cycles when you cannot execute the current instruction until a prior instruction has exited the pipeline If a stall is seen empirically but it is not
108. optimized code while retaining function names and line number information This will give you accurate results that correspond directly to the C C source Note that the compiler optimizer may have moved code between lines You can obtain a more accurate view of your application if you build it optimized but without debug information generation You will then obtain statistics that relate directly to the assembly code The only prob lem with doing this may be in relating assembly lines to the original source Do not strip out function names when linking since keeping func tion names means you can scroll through the assembly window to instructions of interest In very complicated code you can locate the exact source lines by count ing the loops unless they are unrolled Looking at the line numbers in the assembly file use the save temps switch on page 1 44 to retain com piler generated assembly files which will have the s filename extension may also help The compiler optimizer may have moved code around so that it does not appear in the same order as in your original source VisualDSP 3 5 C C Compiler and Library Manual 2 5 for ADSP 219x DSPs General Guidelines Using Interprocedural Optimization To obtain the best performance the optimizer often requires information that can only be determined by looking outside the function that it is working on For example it helps to know what data can be referenced by pointer p
109. or makefile dependencies M MM for include files specified in double quotes include filename The include include file switch directs the preprocessor to process the specified file before processing the regular input file Any D and U options on the command line are always processed before an include file ipa The ipa interprocedural analysis switch turns on Interprocedural Anal ysis IPA in the compiler This option enables optimization across the entire program including between source files that were compiled sepa rately The ipa option should be applied to all C and C files in the 1 30 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler program For more information see Interprocedural Analysis on page 1 57 Specifying ipa also implies setting the 0 switch on page 1 37 You can invoke this switch by selecting the Interprocedural optimization check box in the VisualDSP Project Options dia log box Compile tab General category jump dm pm same The jump select jump table memory type switch directs the compiler to place jump tables in data memory jump dm program memory jump pm or the same memory section as the function to which it applies jump same Jump tables are storage that might be required to hold in memory target addresses for branch instruction used in complex IF THEN ELSE statements or switch statements The default storage memory for
110. or deleted For example define I0write val addr asm volatile si val I0 addr si si A sequence of asm volatile constructs is not guaranteed to be com pletely consecutive it may be moved across jump instructions or in other ways that are not significant to the compiler To force the compiler to keep the output consecutive use only one asm volatile construct or use the output of the asm construct in a C C statement Assembly Constructs with Input and Output Operands The assembly constructs output operands must be write only cc219x assumes that the values in these operands do not need to be preserved When the assembler instruction has an operand that is both read from and written to you must logically split its function into two separate operands one input operand and one write only output operand The connection between them is expressed by constraints that say they need to be in the same location when the instruction executes You can use the same C expression for both operands or different expres sions For example in the following statement the modi fy instruction uses sock as its read only source operand and shoe as its read write destination VisualDSP 3 5 C C Compiler and Library Manual 1 75 for ADSP 219x DSPs C C Compiler Language Extensions pseudo code modify shoe sock asm modify 40 42 w shoe 0 shoe x sock The constraint 0 for operand 1
111. passed as a parameter and set the value read from that register as a return value The input parameter for sysreg_read can be one of the symbolic variable constants of the enumerated data type SysReg defined in sysreg h or any valid 8 bit value used to represent a system control register The symbolic definitions in sysreg h are listed below General Register set sysreg_ASTA arithmetic status sysreg_SSTA shifter status sysreg_MSTA multiplier status sysreg_ICNTL interrupt control sysreg_IMASK interrupts enabled mask sysreg_IRPTL Interrupt Latch register sysreg_DMPG1 DMPG1 high address register sysreg_DMPG2 DMPG2 high address register sysreg_IOPG 10PG I O page register System Control Register set sysreg_BO BO base register sysreg_Bl B1 base register sysreg_B2 B2 base register 3 148 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library sysreg_B3 B3 base register sysreg_B4 B4 base register sysreg_B5 B5 base register sysreg_B6 B6 base register sysreg_B7 B7 base register sysreg_SYSCTL SYSCTL register Cache Control Register sysreg_CACTL CACTL register Emulation Debug Control Register sysreg_DBGCTRL DBGCTRL register Emulation Debug Status Register sysreg_DBGSTAT DBGSTAT register Cycle Counter Registers sysreg_CNTO CNTO register sysreg_CNTl CNT1 register sysreg_CNT2 CNT2 register sysreg_CNT3 CNT3 register The sysreg_read function is implemented a
112. pchdir option pedantic The pedantic ANSI standard warnings switch causes the compiler to issue warnings for any constructs found in your program that do not strictly conform to the ISO ANSI standard for C or C The compiler may not detect all noconforming constructs In par ticular the pedantic switch does not cause the compiler to issue errors when Analog Devices keyword extensions are used pedantic errors The pedantic errors ANSI C errors switch causes the compiler to issue errors instead of warnings for cases described in the pedantic switch 1 40 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler pplist filename The pplist preprocessor listing switch directs the preprocessor to out put a listing to the named file When more than one source file has been preprocessed the listing file contains information about the last file pro cessed The generated file contains raw source lines information on transitions into and out of include files and diagnostics generated by the compiler Each listing line begins with a key character that identifies its type as Character Meaning N Normal line of source X Expanded line of source S Line of source skipped by if or ifdef L Change in source position R Diagnostic message remark W Diagnostic message warning E Diagnostic message error c Diagnostic message catastrophic error proc processor The proc target
113. pigeons pcgedeca wanes 1 143 Variable Argument Macros sccancecciscsancrnionsensersricdacneisensendes 1 143 Line Breaks in String Literals sesisusnoiniorsaneserne 1 144 Arithmetic on Pointers to Void and Pointers to Functions 1 144 Cast to UNON sonnoongsrern r a e 1 144 Ranges im Case Labs ccna 1 144 Declarations mixed with Code ausrisiirisesesissrnisrisrnarsnnin 1 144 Escape Character Constant cscmenenonnsarismenii aa inin 1 145 Alignment Inquiry Keyword __alignof__ eee 1 145 Keyword for Specifying Names in Generated Assembler asm 1 145 Function Variable and Type Attribute Keyword __attribute__ 1 146 Preprocessor Features saiaisiatipiensmeioaitieeadsnainiiaainemniaaiens 1 147 Predefined Preprocessor Macros tiiccciccsstainccnniecicatacdousaansans 1 147 Feader FES scieasasoneereinie ee eines 1 149 Writing Preprocestot Macnee sississvsasennisavssnsssnnnetaveatantesseiasis 1 149 Preprocessing OF IDL Files serseri 1 151 VisualDSP 3 5 C C Compiler and Library Manual xiii for ADSP 219x DSPs CONTENTS C C Run Time Model and Environment siccssmcinessucsverienccsere 1 153 Tring ihe Run Time Fe cctgesccecersn eaneriermmersnonserannannars 1 154 Interrupt Tableand Interface oes s pica stadoscctsesteonteasseceniysteases 1 154 Ue Ee gs ieee eased 1 155 Stack Frame Description ccizanicicaresrecisiemanincacnneaiuwodes 1 157 General System Wide Specilicationg sorrsssirenitevcieiineenri 1 158 At a procedure call the following mu
114. points to a Data Memory integer Xf float pm dm pm fp the first pm means that fp is in Program Memory the following dm puts fp in Data Memory and fp itself is in Program Memory VisualDSP 3 5 C C Compiler and Library Manual 1 79 for ADSP 219x DSPs C C Compiler Language Extensions Memory space specification keywords cannot qualify type names and structure tags but you can use them in pointer declarations The follow ing listing shows examples of memory space specification keywords in typedef and struct statements Dual Memory Support Keyword typedef amp struct Examples typedef float pm PFLOATP PFLOATP defines a type which is a pointer to a a float which resides in pm a struct s int x int y int z static pm struct s mystruct 10 9 8 Note that the pm specification is not used in the structure definition The pm specification zx is used when defining the variable mystruct Xf Memory Keywords and Assignments Type Conversions Memory space specifications limit the kinds of assignments your program can make e You may make assignments between variables allocated in different memory spaces e Pointers to program memory must always point to PM Pointers to data memory must always point to DM You may not mix addresses from different memory spaces within one expression Do not attempt to explicitly cast one type of pointer to anoth
115. pure 1 129 2 32 pragma regs_clobbered 2 33 pragma regs_clobbered string 1 130 pragma result_alignment 1 134 pragma retain_name 1 127 pragma system_header 1 138 pragma vector_for 1 124 pragma weak_entry 1 128 pragrma altregisters 1 122 pragrma interrupt 1 122 tebug types compiler switch 1 25 IDL files 1 151 filename command file compiler switch 1 22 __alignof__ type name construct 1 145 __attribute__ keyword 1 146 __ builtin_aligned declaration 2 6 __ builtin _circindex function 2 28 __ builtin_circptr function 2 28 __GROUPNAME _ macro 1 46 _ HOSTNAME _ macro 1 46 _ MACHINE _ macro 1 46 __NO_BUILTIN preprocessor macro 1 34 __NO_ETSI_ FLAGS macro 1 109 _ REALNAME _ macro 1 46 __SIGNED_CHARS _ macro 1 45 VisualDSP 3 0 C C Compiler and Library Manual I 1 for ADSP 219x DSPs INDEX __ SILICON_REVISION__ macro 1 44 __ SYSTEM __ macro 1 46 __USERNAME _ macro 1 46 _ADI_THREADS macro 1 46 _primlO C function breakpoint 3 14 channeling I O operations 3 14 _primIOCB label 3 14 p law compression mu_compress function 4 88 u law expansion mu_expand function 4 89 Numerics 219x_int_tab file 1 154 2 D convolution conv2d function 4 49 2 D convolution conv2d3x3 function 4 50 A A assert compiler switch 1 22 a_compress A law compression function 4 23 a_expand A law expansion function 4 24 abend see abort function abort abnormal program end function 3 27 Abri
116. same variable or pointer To make changes of this kind easier you can use C preprocessor macros to define common memory spaces that must be coordinated The following listing shows two code segments that are equivalent after preprocessing 1 82 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler The following code segment demonstrates how you can redefine the mem ory space specifications by redefining the macros SPACE1 and SPACE2 Dual Memory Support Keywords amp Macros define SPACE1 pm itdefine SPACE2 dm char pm foo char dm char SPACE1 foo char SPACE2 char pm x char SPACE1 x char dm y char SPACE2 y x foo amp y x foo amp y PM and DM Compiler Support for Standard C Library Functions There are a number of functions defined in the standard C library that take pointer input parameter types These functions which include for example strien are implemented differently when the pointer input is to program memory PM or data memory DM The different imple mentations are called automatically by the compiler because it has specific in built knowledge about the standard C functions that require pointer parameters The support requires that the normal standard header file for example string h is included prior to use of the function requiring PM and DM variants The default library function variants are DM should the include file not be used Placement Support Key
117. sequence to the time domain by using the radix 4 Inverse Fast Fourier Transform The size of the input array in the output array out and the temporary working buffer t is n where n represents the number of points in the FFT The function does not impose any special memory alignment require ments on the arrays However benefits in run time performance will be realized if the output array is allocated on an address boundary that is multiple of twice the FFT size If the input data can be overwritten then optimum memory usage can be achieved by specifying the input array as the output array VisualDSP 3 5 C C Compiler and Library Manual 4 79 for ADSP 219x DSPs DSP Run Time Library Reference The twiddle table is passed in the argument w which must contain at least yn twiddle factors The function twidfftrad4_fri6 may be used to initial ize the array If the twiddle table contains more factors than needed for a particular call on ifftrad4_fr16 then the stride factor has to be set appropriately otherwise it should be 1 The argument scale_method controls how the function should scale the output to avoid overflow If no scaling is selected by setting scale_method to zero then the input signal should be sufficiently conditioned to avoid overflow The block_exponent argument will be set to zero The function will perform static scaling if scale_method is set to 1 For static scaling the function will scale intermediate results to
118. space for use within simple leaf functions without the overhead of establishing a stack frame Stack Frame Description This section describes the stack as shown in Figure 1 3 on page 1 156 Incoming Arguments The memory area for incoming arguments begins at the FP value 1 Argument words are mapped by ascending addresses so the sec ond argument word is mapped at FP 2 Linkage Information The return address is saved on the hardware stack by the CALL instruction In the called function the address can then be popped from the hardware stack and saved as part of the stack frame This information is used by the debugger to generate call stack debug information for source level debugging Saving the return address on the stack frame is also useful in avoiding overflowing the finite hardware call stack when using recursion for example The value stored on the stack gets pushed back on the hardware call stack before the return of the function The compiler detects recursive routines and also offers a switch to avoid overflowing the hardware call stack called no_hardware_pc_stack which might be required for highly nested software Local Variables and Temporaries Space for a register save area and local variables temporaries is allo cated on the stack by the function prologue Local variables and temporaries are typically placed first in this area so they can be VisualDSP 3 5 C C Compiler and Library Manual 1 157 for ADSP 219x D
119. string that directs the compiler to use certain groups of registers for the input and output operands Enclose the constraint string within double quotes For more information on operand constraints see Assembly Construct Operand Descrip tion on page 1 68 output operand The output operand is the name of a C or C variable that receives output from a corresponding operand in the assembly instruction input operand The input operand is a C C expression that provides an input to a corresponding operand in the assembly instruction clobber The clobber notifies the compiler that a list of registers are over written by the assembly instructions Use lowercase characters to name clobbered registers Enclose each name within double quotes and separate each quoted register name with a comma The input VisualDSP 3 5 C C Compiler and Library Manual 1 65 for ADSP 219x DSPs C C Compiler Language Extensions and output operands are guaranteed not to use any of the clobbered registers so you can read and write the clobbered registers as often as you like See Table 1 10 on page 1 73 ASM Construct Syntax Rules These rules apply to assembly construct template syntax The template is the only mandatory argument to asm All other arguments are optional An operand constraint string followed by a C C expression in parentheses describes each operand For output operands it must be possible to assign to the expr
120. the depen dencies of the main program file After preprocessing compilation proceeds normally See also the Mo switch MM The MM generate make rules and compile switch directs the preprocessor to print to stdout a rule describing the dependencies of the main program file After preprocessing compilation proceeds normally Mo filename The Mo filename preprocessor output file switch directs the compiler to use filename for the output of MD or ED switches Mt filename The Mt filename output make rule for the named source switch speci fies the name of the source file for which the compiler generates the make rule when you use the M or MM switch If the named file is not in the cur rent directory you must provide the path name in double quotation marks The new file name will override the default base doj The Mt option supports the IMPORT extension 1 32 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler MQ The MQ switch directs the compiler not to compile the source file but to output a rule In addition the MQ switch does not produce any notifica tion when input files are missing map filename The map generate a memory map switch directs the linker to output a memory map of all symbols The map file name corresponds to the filename argument For example if the filename argument is test the map file name is test xml The xm1 extension is added where n
121. to keep track of its current position within the vector Algorithm k 1 yQ i m x i j h k 1 j m k for m 0 1 1 1 j 0 where i 0 1 n 1 Domain 1 0 to 1 0 4 62 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs DSP Run Time Library gen_bartlett generate bartlett window Synopsis d Finclude lt window h gt void gen_bartlett_frl6 w a N fractl6 wll Window vector int a Address stride in samples for window vector int N Length of window vector Description This function generates a vector containing the Bartlett window The length of the window required is specified by the parameter N and the stride parameter a is used to space the window values within the output vector w The length of the output vector should therefore be N a The Bartlett window is similar to the Triangle window see gen_triangle on page 4 72 but has the following different properties e The Bartlett window always returns a window with two zeros on either end of the sequence so that for odd n the center section of an N 2 Bartlett window equals an N Triangle window e For even n the Bartlett window is still the convolution of two rect angular sequences There is no standard definition for the Triangle window for even n the slopes of the Triangle window are slightly steeper than those of the Bartlett window VisualDSP 3 5 C C Compiler and Library Manual 4 63 for ADSP 21
122. to the same array When the same data may be reachable through two pointers they are said to alias each other If IPA is enabled the compiler will look at the call sites of fn and try to determine whether a and b can ever point to the same array Even with IPA it is quite easy to create what appear to the compiler as aliases The analysis works by associating pointers with sets of variables that they may refer to at some point in the program If the sets for two pointers are found to intersect then both pointers are assumed to point to the union of the two sets 2 10 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Achieving Optimal Performance from C C Source Code If fn above were called in two places with global arrays as arguments then IPA would have the results shown below fn globl glob2 N fn globl glob2 N Good sets for a and b do not intersect a and b are not aliases fn globl glob2 N fn glob3 glob4 N Good sets for a and b do not intersect a and b are not aliases fn globl glob2 N fn glob3 globl N Bad sets intersect both a and b may access glob1 a and b may be aliases The third case arises because IPA considers the union of all calls at once rather than considering each call individually when determining whether there is a risk of aliasing If each call were considered individually IPA would have to take flow control into account and the number o
123. trol It is easy for a compiler to see that an automatic scalar whose address is not taken may be held in a register during a loop But it is not as easy when the variable is a global or a function static Therefore code such as for i 0 i lt globvar i ali 10 Bad may need to reload globvar on every iteration may not create a hardware loop if the compiler cannot be sure that the write into the array a does not change the value of the global variable The globvar must be re loaded each time around the loop before performing the exit test In this circumstance the programmer can make the compiler s job easier by writing int upper_bound globvar for i 0 i lt upper_bound i ali 10 Good easily becomes hardware loop Using the Restrict Qualifier The restrict qualifier provides one way to help the compiler resolve pointer aliasing ambiguities Accesses from distinct restricted pointers do not interfere with each other The loads and stores in the following loop for i 0 i lt 100 i ali b i 2 22 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Achieving Optimal Performance from C C Source Code Bad possible alias of arrays a and b may be disambiguated by writing int restrict p a int restrict gq for i 0 1 lt 100 i ell a E KAFE Good restrict qualifier tells compiler that memory accesses do not alias The restrict keyword is particularly useful
124. value always produces the same sequence of pseudo random numbers Error Conditions The srand function does not return an error condition Example d Finclude lt stdlib h gt srand 22 See Also rand 3 120 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library strcat concatenate strings Synopsis include lt string h gt char strcat char sl const char s2 Description The strcat function appends a copy of the null terminated string pointed to by s2 to the end of the null terminated string pointed to by s1 It returns a pointer to the new s1 string which is null terminated The behavior of strcat is undefined if the two strings overlap Error Conditions The strcat function does not return an error condition Example d Finclude lt string h gt char string1 50 stringl 0 A stringl 1 B stringl 2 0 strcat stringl CD new string is ABCD See Also strncat VisualDSP 3 5 C C Compiler and Library Manual 3 121 for ADSP 219x DSPs C Run Time Library Reference strchr find first occurrence of character in string Synopsis include lt string h gt char strchr const char sl int c Description The strchr function returns a null pointer to the first location in s1 a null terminated string that contains the character c Error Conditions The strchr function returns a null pointer if c is not part
125. value into fractl6 variables pointed to by the parameters hi and 10 The values cal culated are Hi bitl6 to bit31 of src Lo sre hi lt lt l16 gt gt 1 Fract integer division of two longs fract32 Div_32 fract32 L_num fractl6 denom_hi fractl6 denom_lo This is 32 bit fractional divide operation The result returned is the fract32 representation of L_num divided by L_denom represented by demon_hi and denom_lo L_num and L_denom must both be positive frac tional values and L_num must be less that L_denom to ensure that the result falls within the fractional range Pragmas The compiler supports a number of pragmas Pragmas are implementa tion specific directives that modify the compiler s behavior There are two types of pragma usage pragma directives and pragma operators Pragma directives have the following syntax pragma pragma directive pragma directive operands new line Pragma operators have the following syntax _Pragma string literal When processing a pragma operator the compiler effectively turns it into a pragma directive using a non string version of string literal This means that the following pragma directive VisualDSP 3 5 C C Compiler and Library Manual 1 119 for ADSP 219x DSPs C C Compiler Language Extensions pragma Jinkage_name mylinkname can also be equivalently be expressed using the following pragma operator _Pragma inkage_name mylinkname The examples in this manual
126. version of this book the word Caution appears instead of this symbol xxxviii VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler 1 COMPILER The C C compiler cc219x is part of Analog Devices development soft ware for ADSP 219x DSPs This chapter contains e C C Compiler Overview on page 1 2 Provides an overview of C C compiler for ADSP 219x DSPs e Compiler Command Line Interface on page 1 6 Describes the operation of the compiler as it processes programs including input and output files and command line switches e C C Compiler Language Extensions on page 1 59 Describes the cc219x compiler s extensions to the ISO ANSI stan dard for the C and C languages e Preprocessor Features on page 1 147 Contains information on the preprocessor and ways to modify source compilation e C C Run Time Model and Environment on page 1 153 Contains reference information about implementation of C C programs data and function calls in ADSP 219x DSPs e C C and Assembly Language Interface on page 1 169 Describes how to call an assembly language subroutine from C or C program and how to call a C or C function from within an assembly language program VisualDSP 3 5 C C Compiler and Library Manual 1 1 for ADSP 219x DSPs C C Compiler Overview C C Compiler Overview The C C compiler cc219x is designed to aid your DSP p
127. void twidfft2d_frl6 complex_fractl6 wl int n Description The twidfft2d_fr16 function generates complex twiddle factors for a 2 D FFT The size of the FFT input sequence is given by the argument n and the function writes the twiddle factors to the vector w known as the twid dle table The size of the twiddle table must be n 2 the number of points in the FFT Normally the table is only calculated once and is then passed to an FFT function as an argument A twiddle table may be used to generate several FFTs of different sizes by initializing the table for the largest FFT and then using the stride argument of the FFT function to specify the step size through the table For example to generate the largest FFT the stride would be set to 1 and to generate an FFT of half this size the stride would be set to 2 Algorithm This function takes FFT length n as an input parameter and generates the lookup table of complex twiddle coefficients The samples generated are twid_re k cod 27 n 4 106 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs DSP Run Time Library twid _im k si 77 e n where k 0 1 2 n 2 1 Domain The FFT length n must be a power of two and at least 16 VisualDSP 3 5 C C Compiler and Library Manual 4 107 for ADSP 219x DSPs DSP Run Time Library Reference var variance Synopsis d Finclude lt stats h gt Float varf a n const float al int
128. which registers or memory locations contain C variables The C compiler does not analyze code defined with the asm construct it passes this code directly to the assembler The compiler does perform sub stitutions for operands of the formats 0 through 9 However it passes everything else through to the assembler without reading or analyzing it The asm constructs are executable statements and as such may not appear before declarations within C C functions A simplified asm construct without operands takes the form of asm ENA INT The complete assembly language instruction enclosed in quotes is the argument to asm The compiler generates a label before and after inline assembly instructions when generating debug code g switch These labels are used to generate the debug line information used by the debug ger If the inline assembler inserts conditionally assembled code an undefined symbol error is likely to occur at link time If the inline assembler changes the current section and thereby causes the com piler labels to be placed in another section such as a data section instead of the default code section then the debug line informa tion will be incorrect for these lines VisualDSP 3 5 C C Compiler and Library Manual 1 63 for ADSP 219x DSPs C C Compiler Language Extensions Using asm constructs with operands requires some additional syntax The construct syntax is described in e Assem
129. will inspect the intermediate results and will only scale to avoid overflow Dynamic scaling therefore mini mizes loss of precision but at the possible cost of slightly reduced performance The block_exponent argument will be set to a value between 0 which indicates that no scaling was performed and 10g2 n as if static scaling was performed Algorithm See cfft on page 4 36 Domain Input sequence length n must be a power of two and at least 16 VisualDSP 3 5 C C Compiler and Library Manual 4 95 for ADSP 219x DSPs DSP Run Time Library Reference rfftrad4 N point real input FFT Synopsis d Finclude lt filter h gt void rfftrad4_frl6 in t out wl wst n block_exponent scale_method const fractl6 inl input output sequence complex_fractl6 tL temporary working buffer i complex_fractl6 out working buffer const complex_fractl6 wl twiddle sequence x7 int wst twiddle factor stride Ej int n number of FFT points E int block_exponent block exponent of output data int scale method scaling method desired O none l static 2 dynamic Description This function transforms the time domain real input signal sequence to the frequency domain by using the radix 4 Fast Fourier Transform The rfftrad4_fri6 function takes advantage of the fact that the imaginary part of the input equals zero which in turn eliminates half of the multipli cations in the butterfly
130. y atan 0 0 y 0 0 See Also atan2 tan VisualDSP 3 5 C C Compiler and Library Manual 3 31 for ADSP 219x DSPs C Run Time Library Reference atan2 arc tangent of quotient Synopsis include lt math h gt double atan2 double x double y float atan2f float x float y fractl6 atan2 fractl6 x fractl6 y Description The atan2 function computes the arc tangent of the input value x divided by input value y The output in radians is in the range 7 T The atan2_fr16 function uses the full range from 7 4 to 7 4 0x8000 to 0x7FFF for both input and output arguments This corre sponds to a scaling by n compared to the floating point function The input argument is in radians Error Conditions The atan2 function returns a zero if x 0 and y lt gt 0 Example d Finclude lt math h gt double a float b atan2 0 0 0 5 the error condition a 0 0 atan2f 1 0 0 0 b 1 2 o ll See Also atan tan 3 32 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library atexit register a function to call at program termination Synopsis include lt stdlib h gt int atexit void func void Description The atexit function registers a function to be called at program termina tion Functions are called once for each time they are registered in the reverse order of registration Up to 32 functions can be regis
131. your C C programs Many of these routines have been modified to provide better support for the improved performance and code compilation of cc219x For complete information on the library contents see Chapter 3 C C Run Time Library The cc219x compiler release now includes a complete documented DSP library libdsp d1b and associated include files providing efficient stan dard functions required by DSP application designers For details refer to Chapter 4 DSP Run Time Library Future cc219x compiler releases may include additional library functions refer to Chapter 3 C C Run Time Library VisualDSP 3 5 C C Compiler and Library Manual A 9 for ADSP 219x DSPs C C Compiler and Run Time Library A 10 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs INDEX Symbols pragma align num 1 121 pragma alloc 1 129 2 32 pragma can_instantiate instance 1 136 pragma const 1 130 2 31 pragma do_not_instantiate instance 1 136 pragma hdrstop 1 136 pragma instantiate instance 1 135 pragma linkage_name 1 126 pragma loop_count 2 35 pragma loop_count min max modulo 1 124 pragma no_alias 1 125 2 36 pragma no_pch 1 137 pragma once 1 138 pragma optimize_ off for_speed for_space 2 35 pragma optimize_as_cmd_line 1 126 pragma optimize_for_space 1 126 pragma optimize_for_speed 1 126 pragma optimize_off 1 125 pragma pad alignopt 1 121 pragma
132. 1 amen ee teem ER 3 21 a OE E T E ER 3 21 AeA E E E E E T 3 21 DE araea ocean serene mer Neen tune rere cne ose eee oe eae 3 21 IAD A E E A E A A 3 21 D a AN 3 21 GO E saaa S NAA 3 21 LET E E A E E E E E E 3 21 60 nee 3 22 WUE ea a A 3 22 HE opia S 3 22 I AANA 3 22 aE RA 3 22 lomapi css card oli cetionacaandtaatenulstiedenedannenaaenecannius 3 22 er LE gee eee E lest e Bere ent Ber aire ar rior eon P E ter oe 3 22 a E A Ney eae ar Het emu ney nana serene Or are 3 22 Documented Library Functions cccsnsirancessstnserecedaioucunsctarsaaiaanenpats 3 23 C Run Time Library Reference aicciietccacnerasnesmapeoimectendusentamecas 3 26 ENT eave erik Conven ong cecs a 3 26 Reicrence Forat ssamoreoiat inme ai np 3 26 E E E E E AA E E A E 3 27 VisualDSP 3 5 C C Compiler and Library Manual xix for ADSP 219x DSPs E eae ee ae ees 3 29 A aE PDR FREE DE NERPY EUICRETS Pod RPE OPT URES RENITE RTTRT ir YS EAE nErE OPO ETT EFC ED 3 30 MOR Ee ROR E A Ee ern rc A REVS E E mT Sener er ee Cm renee cr 3 31 SL E E E tery eet E E E rr ie err 3 32 ONT aria N 3 33 BO er ete aoa 3 34 An 1 a AEI AE AE ane estat A IA EN A I E 3 37 E EE AE EE E AEE E N E E E AE AE eee 3 38 E E O E EA E nae seen de A ETET 3 39 E E A A A E A E T E AE O T O E 3 41 O r E AT O 3 42 SE REIT e A E E A E E E 3 43 a E AE IAN PA N WT OER O EE A AT E AN 3 45 O ROA 3 48 E E E A A EE A E A 3 49 CY E E E E E A A AT ae eaeaeoualndaas 3 50 E e E E E EEA E D AE E 3 51
133. 1 calling assembly language subroutine 1 170 C C library functions 3 4 DSP library functions 4 2 ETSI library functions 1 108 calloc allocate and initialize memory function 3 41 cartesian Cartesian to polar function 4 32 cdiv complex division function 4 34 ceil ceiling function 3 42 cexp complex exponential function 4 35 cfft N point complex input FFT function 4 36 cfft2d NxN point 2 D complex input FFT 4 40 cfftrad4 N point complex input FFT 4 38 cfir complex FIR filter function 4 42 cfir finite impulse response filter function 4 42 character string search see strchr function character string search recursive see strrchr function circular buffer length registers 1 162 circular buffers 2 27 accessing 1 104 automatic generation 1 103 increment of index 1 104 increment of pointer 1 105 increments of index 1 104 switch setting 1 27 clear_interrupt clear a pending signal function 3 43 clip clip function 4 44 clobber string specifiers 1 71 clobbered register set 1 132 register set 1 132 registers 1 65 1 130 1 132 close operation 3 14 cmlt complex multiply function 4 45 code optimization 1 56 2 3 1 5 VisualDSP 3 0 C C Compiler and Library Manual for ADSP 219x DSPs INDEX command line interface 1 6 1 55 compiler built in C library functions 3 5 C extensions 1 60 code optimization 1 56 2 3 command line switch summaries 1 12 command line syntax 1 7 file extensio
134. 3 50 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library enable_interrupts enable interrupts Synopsis d Finclude lt sysreg h gt void enable_interrupts void Description The enable_interrupts function causes the compiler to emit an instruc tion to enable hardware interrupts The enable_interrupts function is implemented as a compiler built in The emitted instruction will be inlined at the point of enable_interrupts use The inclusion of the sysreg h include file is mandatory when using enable_interrupts The enable_interrupts function does not return a value Error Conditions The enable_interrupts function does not return raise or set any error conditions Example d Finclude lt sysreg h gt main enable_interrupts emits ENA INTS instruction inline See Also disable_interrupts io_space_read io_space_write mode_change sysreg_read sysreg_write VisualDSP 3 5 C C Compiler and Library Manual 3 51 for ADSP 219x DSPs C Run Time Library Reference exit normal program termination Synopsis d Finclude lt stdlib h gt void exit int status Description The exit function causes normal program termination The functions registered by the atexit function are called in reverse order of their regis tration and the microprocessor is put into the IDLE state The status argument is stored in register AX1 and control is passed to the label
135. 5 C C Compiler and Library Manual for ADSP 219x DSPs DSP Run Time Library The matrix functions defined in the matrix h header file are listed in Table 4 5 In most of the function prototypes a isa pointer to input matrix a b isa pointer to input matrix b b isan input scalar n is the number of rows m is the number of columns c isa pointer to output matrix c In the matrix matrix functions n and k are the dimensions of matrix a and k and m are the dimensions of matrix b The functions described by this header assume that input array arguments are constant that is their contents do not change during the course of the routine In particular this means the input arguments do not overlap with any output argument Table 4 5 Matrix Functions Description Prototype Real void matsadd const double a const double b int n int m Matrix Scalar double c Addition void matsaddf const float a const float b int n int m float c void matsadd_frl6 const fractl6 a const fractl6 b int n int m fractl6 c Real void matssub const double a const double b int n int m Matrix Scalar double c Subtraction void matssubf const float a const float b int n int m float c void matssub_frl6 const fractl6 a const fractl6 b int n int m fractl6 c VisualDSP 3 5 C C Compiler and Library Manual 4 13 for ADSP 219x DSPs DSP Run Time Librar
136. 5 C C Compiler and Library Manual for ADSP 219x DSPs DSP Run Time Library crosscorr cross correlation Synopsis d Finclude lt stats h gt void crosscorrf a b n m c const float al Input vector a xf const float b Input vector b int n Number of input samples EJ int m Lag count E float cl Pointer to output vector c void crosscorr_frl6 a b n m c const fractl6 al Input vector a f const fractl6 b Input vector b af int n Number of input samples A int m Lag count Aap fractl6 cl Pointer to output vector c Description This function computes the cross correlation of the input elements con tained within input vector a and input vector b and stores the result to output vector c Algorithm n k 1 1 CESE Say Dixy n j 0 where k 0 1 m 1 Domain 3 4 x 1038 to 3 4 x 1038 for crosscorrf 1 0 to 1 0 for crosscorr_fr16 VisualDSP 3 5 C C Compiler and Library Manual 4 55 for ADSP 219x DSPs DSP Run Time Library Reference csub complex subtraction Synopsis include lt complex h gt complex_float csubf complex_float a complex_float b complex_double csub complex_double a complex_double b complex_fractl6 csub_frl6 complex_fractl6 a complex_fractl6 b Description This function computes the complex subtraction of two complex inputs a and b and returns the result Algorithm Re c Re a Re b Im c Im
137. 5E4 abc amp rem f 2 3455E 7 rem abc strtodf 0x1 800p 9 123 amp rem f 768 0 rem 123 ll See Also atof strtol strtoul VisualDSP 3 5 C C Compiler and Library Manual 3 139 for ADSP 219x DSPs C Run Time Library Reference strtok convert string to tokens Synopsis include lt string h gt char strtok char sl const char s2 Description The strtok function returns successive tokens from the string s1 where each token is delimited by characters from s2 A call to strtok with s1 not NULL returns a pointer to the first token in s1 where a token is a consecutive sequence of characters not in s2 s1 is modified in place to insert a null character at the end of the token returned If s1 consists entirely of characters from s2 NULL is returned Subsequent calls to strtok with s1 equal to NULL will return successive tokens from the same string When the string contains no further tokens NULL is returned Each new call to strtok may use a new delimiter string even if s1 is NULL in which case the remainder of the string is tokenized using the new delimiter characters Error Conditions The strtok function returns a null pointer if there are no tokens remain ing in the string Example d Finclude lt string h gt static char str a phrase to be tested today char t tScstrtoktstry 3 t points to a z 3 140 VisualDSP 3 5 C C Compiler and Library Ma
138. 6 const fractl6 a J const fractl6 bc J fractl6 c int n Real void vecvsub const double a J const double b J Vector Vector double c int n Subtraction void vecvsubf const float a J const float b CL J float c int n void vecvsub_frl6 const fractl6 a const fractl6 b fractl6 c J int n Real void vecvmlt const double a J const double b J Vector Vector double c int n Multiplication void vecvmltf const float a const float b J float c int n void vecvmlt_frl6 const fractl6 a const fractl6 b fractl6 c J int n Maximum Value of double vecmax const double a J int n Vector Elements float vecmaxf const float a int n fractl6 vecmax_frl6 const fract 16 a int n Minimum Value of double vecmin const double a int n Vector Elements float vecminf const float a int n fractl6 vecmin_frl6 const fractl6 a J int n Index of int vecmaxloc const double a int n Maximum Value of int vecmaxlocf const float a J int n Vector Elements int vecmaxloc_frl6 const fractl6 a J int n Index of Minimum int vecminloc const double a int n Value of Vector int vecminlocf const float a int n Elements int vecminloc_frl6 const fractl6 a int n 4 18 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Table 4 7 Vector Functions Contd DSP Run Time Library
139. 7f ch printf 04x ch printf 3s isprint ch printable putchar n See Also isgraph isspace VisualDSP 3 5 C C Compiler and Library Manual 3 81 for ADSP 219x DSPs C Run Time Library Reference ispunct detect punctuation character Synopsis include lt ctype h gt int ispunct int c Description The ispunct function determines if the argument is a punctuation charac ter If the argument is not a punctuation character ispunct returns a zero If the argument is a punctuation character ispunct returns a non zero value Error Conditions The ispunct function does not return any error conditions Example dFinclude lt ctype h gt int ch for ch 0 ch lt 0x7f ch printf 04x ch printf 43s ispunct ch punctuation putchar n See Also isalnum 3 82 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library isspace detect whitespace character Synopsis include lt ctype h gt int isspace int c Description The isspace function determines if the argument is a blank whitespace character 0x09 0x0D or 0x20 This includes space form feed f new line n carriage return r horizontal tab t and vertical tab v If the argument is not a blank space character isspace returns a zero If the argument is a blank space character isspace returns a non zero value Error Cond
140. 8 Domain a gt 0 N gt 0 4 74 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs DSP Run Time Library histogram histogram Synopsis d Finclude lt stats h gt void histogramf a c max min n m const float al Pointer to input vector a int cl Pointer to output vector c float max Maximum value of the bin Ze float min Minimum value of the bin RJ int n Number of input samples S int m Number of bins Kf void histogram_frl6 a c max min n m const fractl6 al Pointer to input vector a int cl Pointer to output vector c fractl6 max Maximum value of the bin a fractl6 min Minimum value of the bin cae int n Number of input samples a int m Number of bins A Description The histogram function computes a histogram of the input vector a that contains n samples and stores the result in the output vector c The minimum and maximum value of any input sample is specified by min and max respectively These values are used by the function to calcu late the size of each bin as max min m where m is the size of the output vector c Any input value that is outside the range min max will exceed the boundaries of the output vector and will be discarded VisualDSP 3 5 C C Compiler and Library Manual 4 75 for ADSP 219x DSPs DSP Run Time Library Reference To preserve maximum performance while performing out of bounds c
141. 8 to 3 4 x 1038 for zero_crossf 1 0 to 1 0 for zero_cross_frl6 VisualDSP 3 5 C C Compiler and Library Manual 4 109 for ADSP 219x DSPs DSP Run Time Library Reference 4 110 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs A COMPILER LEGACY SUPPORT The VisualDSP environment and tools provide several types of support for legacy code that was developed with previous releases of the develop ment tools For more information on legacy code support see the VisualDSP 3 5 Linker and Utilities Manual for 16 Bit Processors and VisualDSP 3 5 Assembler and Preprocessor Manual for ADSP 218x and ADSP 219x DSPs Tools Differences VisualDSP 3 5 includes an updated C C compiler linker and debugger and a binary file format ELF Due to use of the VisualDSP Integrated Development and Debugging Environment IDDE and other enhancements VisualDSP 3 5 has significant differences from Release 6 1 that you will need to be aware of Most of these software dif ferences originated in VisualDSP 3 0 release In some cases you will need to modify your sources to use the new tools Of the new features and enhancements the following have the most impact on your existing projects e Some tools switches have changed If you use any of the modified or obsolete switches you must revise your command line scripts or batch files in order to rebuild your project e The code generation tools no longer support
142. 99 library support 1 102 size 1 100 Fast Fourier Transforms 4 6 fflush NULL 3 15 FFT function versions 4 7 file extension 1 7 1 9 names 1 22 searches 1 9 file I O support 1 166 file searching lt filename gt 1 152 files ADL 1 151 filter h header file 4 6 filters in digital signal processing 4 6 finite impulse response FIR filter 4 57 finite impulse response filter cfirc function 4 42 finite impulse response filter fir function 4 57 fir finite impulse response filter function 4 57 fir_decima FIR decimation filter function 4 59 fir_interp FIR interpolation filter function 4 61 fixed point arithmetic 1 90 flags command line input compiler switch 1 27 float representation 3 138 float h floating point header file 3 10 floating point constants hexadecimal 1 142 floating point mathematical functions 3 12 floor floor function 3 59 flow control operations 1 77 FLT ROUNDS macro 3 10 fmod floating point modulus function 3 60 I 12 VisualDSP 3 0 C C Compiler and Library Manual for ADSP 219x DSPs INDEX force circbuf circular buffer compiler switch 1 27 force circbuf switch 2 28 fp associative floating point associative compiler switch 1 27 fract 1 176 data type C mode 1 90 fract type support 1 176 fract16 data types 1 110 fract32 data types 1 110 fractional arithmetic operations 1 91 data manipulation 2 25 data support 1 90 literal format 1 91 mixed mode operations 1 92 s
143. 9x DSPs DSP Run Time Library Reference Algorithm N 1 n Malal T 2 where n 0 1 2 N 1 Domain a gt 0 N gt 0 4 64 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs DSP Run Time Library gen_blackman generate blackman window Synopsis include lt window h gt void gen_blackman_frl6 w a N fractl6 wll Window vector int a Address stride in samples for window vector int N Length of window vector Description This function generates a vector containing the Blackman window The length of the window required is specified by the parameter N and the stride parameter a is used to space the window values within the output vector w The length of the output vector should therefore be N a Algorithm w n 042 050 A 008 cof gol N 1 N 1 where n 0 1 2 N 1 Domain a gt 0 N gt 0 VisualDSP 3 5 C C Compiler and Library Manual 4 65 for ADSP 219x DSPs DSP Run Time Library Reference gen_gaussian generate gaussian window Synopsis dFinclude lt window h gt void gen_gaussian_frl6 w alpha a N fractl6 wl Window vector Xj float alpha Gaussian alpha parameter int a Address stride in samples for window vector int N Length of window vector Kif Description This function generates a vector containing the Gaussian window The length of the window required is specified by the parameter N and the
144. ADSP 219x DSPs C C Compiler Language Extensions Dual Memory Support Keywords pm dm This section describes cc219x keyword extensions to C and C that sup port the dual memory space modified Harvard architecture of the ADSP 219x processors There are two keywords used to designate mem ory space dm and pm These keywords can be used to specify the location of a static or global variable or to qualify a pointer declaration These keywords allow you to control placement of data in primary dm or secondary pm data memory No data is placed in the memory unit that holds programs The following rules apply to dual memory support keywords A memory space keyword dm or pm refers to the expression to its right You can specify a memory space for each level of pointer This cor responds to one memory space for each in the declaration The compiler uses Data Memory as the default memory space for all variables All undeclared spaces for data are Data Memory spaces The compiler always uses Program Memory as the memory space for functions Function pointers always point to Program Memory You cannot assign memory spaces to automatic variables All auto matic variables reside on the stack which is always in Data Memory Literal character strings always reside in Data Memory Although program memory on the ADSP 219x DSPs consists of 24 bit words only 16 bits of each word are used when C or C data is stored in pm This is
145. AEXE format DSP executables EXE They now generate ELF format DSP executa bles DXE and the debugger requires DSP executables to be in the VisualDSP 3 5 C C Compiler and Library Manual A 1 for ADSP 219x DSPs Tools Differences ELF DWARF 2 format As a result AEXE formatted files must be recompiled or reassembled in order to be debugged under VisualDSP 3 5 An ELF DWARF to AEXE conversion utility is available in VisualDSP 3 5 that will perform back conversion An AEXE to ELF conversion utility performs forward conversion Some assembly instructions and directives have changed from the VisualDSP 6 1 syntax but a 1egacy assembler switch has been provided to assemble files in the old syntax You may need to review diagnostic messages and revise your source code in order to reassemble your source Legacy syntax and the new syntax under VisualDSP 3 5 cannot be used together in the same source file They can be mixed together within the same project as long as they are assembled in different source files Some C compiler extensions to the ISO ANSI standard have changed If you use any of the modified or removed extensions you must revise your code in order to rebuild your project The run time model has changed If you call a VisualDSP Release 6 1 assembly language subroutine from your C C program you must revise the assembly code to comply with the new rules for the C C run time environment The Architecture File
146. CHIEVING OPTIMAL PERFORMANCE FROM C C SOURCE CODE This chapter provides guidance to help you to tune your application to achieve the best possible code from the compiler Some implementation choices are available when coding an algorithm and understanding their impact is crucial to attaining optimal performance The focus of what follows is on how to obtain maximal code performance from the compiler Most of these guidelines also apply when optimizing for minimum code size although some techniques specific to that goal are also discussed The first section looks at some general principles and how the compiler can lend the most help to your optimization effort Optimal coding styles are then considered in detail Special features such as com piler switches built in functions and pragmas are also discussed The chapter ends with a short example to demonstrate how the optimizer works Small examples are included throughout this chapter to demonstrate points being made Some show recommended coding styles others iden tify styles to be avoided or code that it may be possible to improve These are marked as Good and Bad respectively This chapter contains e General Guidelines on page 2 3 e Loop Guidelines on page 2 17 e Using Built In Functions in Code Optimization on page 2 25 e Smaller Applications Optimizing for Code Size on page 2 29 VisualDSP 3 5 C C Compiler and Library Manual 2 1 fo
147. CO cinisedaneslne enna ea 3 52 5 ET A AAE A nein nee O A E 3 53 CO memory vead scroiinnenne na nsen EN 3 54 zternal memory Write aaa Radice econ evden 3 56 1E oncaeid toes es i E anh ula nada T 3 58 DOG Ga eee eee eee 3 59 xx VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs ican nae nee 3 61 T aE PORTER EERE REPRO TCRT aU OORT REEREEEE LO EET A Ver T 3 62 EA 1 Sennen CED een nn Rim Sree GENRE Rei TT ere EAE E MOND ETE 3 63 WO SPAR POE E E a E A E AS 3 67 TE e E E E E E 3 69 ET E E E EE E E E a RT 3 71 MIE ETETE E A NEE I E A AAE AE A A 3 72 BEATIN e re Pee ere arn eat E eee pinAWRSyerne are err net 3 73 E E E E E A A ENE E E E A enone 3 74 A EE E E E E A E T E E 3 75 Ok E E E E E E E ea ce ees 3 76 BIONET sedinane a e ec rer Eeenr eer eee reever ere ere een reer 3 78 NE E aaa A E E cratered ico ea andes olen nediveealiate 3 79 LU none eben s SePnpeeE ere EE SerOREnCERED pnth oP SRrrRPEED RR err eR TURE TEERECE 3 81 EE gerr E R T 3 82 DSPACE witiaauasbleanciniacaauianaa ele iaseeicdausdnamaatinci ia kiika 3 83 KUPPET deri ceeeeenaencnis eres eseee 3 84 IGE oie 3 85 TUE EENE AEO EE ENE O AEEA 3 86 PR E EER N AN A A AANE AEE aS 3 87 Ne EE EEEE AA E E EAE EA E EE E A 3 88 a E E E E E E EE 3 89 LORIN dann a iaaaa anaes 3 90 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs xxi TOE E E A E E A E EE E 3 93 T E RR A AAA 3 94 POA a AE eee ee E T A E A E 3 95 MEMET isis ietiraen dau a
148. E P AEE E E EA 3 155 ONEI araona sian eeaiiet enema 3 156 VisualDSP 3 5 C C Compiler and Library Manual xxiii for ADSP 219x DSPs VAM cinoma mma na made 3 158 We NG E E E ghee ndecdaa nen 3 160 ie RE cctv tectn tue at onlil aectt sec sll Meanie he hath tt ace tel on baie 3 161 DSP RUN TIME LIBRARY DSP Run Time Library Guide secesassnraiera akn AS 4 2 Calling DSP Library Fonction sevscnciasisinia 4 2 Linking DSP Library Functions scicsissctivis sentences oaiasanens 4 3 Working with Library Source Code secressnoisansasicisr 4 3 DSP Pipe Filips snnsosraii usr an 4 4 complex h Basic Complex Arithmetic Functions 4 4 filter h DSP Filters and Transformations ccccsceeees 4 6 math h Math Functions cccccespartiortectacsesmaieoceeuseemes 4 10 matrix dy Matrix Functions sssieisscsercennirstinsdkist 4 12 tats bi Statistical Functions ssreceensonriecrncrnnesis 4 16 vector hk Vector FUNCIONS vce 4 17 window h Window Generators ssccinsscicsscatasavcerercascancices 4 20 DSP Run Time Library Reference conciencia 4 22 Notation ConyentiOns saeininisn rinira anani 4 22 BAILS sonaria ikp kaaii n a aka anes a A na Diaa 4 23 a P ra 4 24 E E E E E aintiamins 4 25 e anurans 4 26 UE aE TR 4 27 xxiv VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs OIE sania eae 4 29 CIDE See TET ORE NE CREATED RE OSE A DEER ESO RIV e SENT EEE A oe 4 30 Ee Re EE E AC Peep Rens eee EA Ut AE een ar
149. Initializer int alo 0 0 115 0 290 equivalent cc219x C C array initializer int al 6 2 115 4 29 You can combine this technique of naming elements with standard C C initialization of successive elements The standard and cc219x instructions below are equivalent Note that any unlabeled initial value is assigned to the next consecutive element of the structure or array Example 2 Standard amp cc219x C C Array Initializer Standard Array Initializer int a 6 0 vl v2 0 v4 0 equivalent cc219x C C array initializer that uses indexed elements int a 6 1 vl v2 4 v4 1 88 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler The following example shows how to label the array initializer elements when the indices are characters or an enum type Example 3 Array Initializer With enum Type Indices cc219x C C array initializer int whitespace 256 psan he Ct Ae Tb Vb ES MT Ee ed In a structure initializer specify the name of a field to initialize with freld name before the element value The standard C C and cc219x C C struct initializers in the example below are equivalent Example 4 Standard amp cc219x C C struct Initializer Standard struct Initializer struct point i int p struct po Equiva Labeled E struct poin struct poi nt x yis xvalue yvalu
150. J int n int m fractl6 c J Cross correlation void crosscorrf const float al J const float b J int n int m float c void crosscorr_frl6 const fractl6 al J const fractl6 bE J int n int m fractl6 c J Histogram void histogramf const float af int c float max float min int n int m void histogram_frl6 const fractl6 al J int cl J fractl6 max fractile min int n int m Mean float meanf const float al J int n fractl6 mean_fr16 const fractl6 al J int n Root Mean Square oat rmsf const float al J int n fractl6 rms_frl6 const fractl6 aL J int n Variance oat varf const float al J int n fractl6 var_frl6 const fractl6 al J int n Count Zero float zero_crossf const float a int n Crossing fractl6 zero_cross_frl6 const fractl6 al J int n 4 16 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs DSP Run Time Library vector h Vector Functions The vector h header file contains functions for operating on real and complex vectors both vector scalar and vector vector operations See complex h Basic Complex Arithmetic Functions on page 4 4 for the definition of the complex types The functions in the vector h header file are listed in Table 4 7 In the Prototype column a and b are input vectors b is an input scalar c is an output vector and n is the number of elements
151. LE E E E ET 1 53 Dars Type SES ccc ese EE Ei 1 54 iota CONTO ote eee ie eee 1 56 Dibetpie CO ATSI ysis accesscestsrratenrarecanarsioennesnamaesaneisane 1 57 C C Compiler Language Extensions scssnivcsrcsnecnsecsmnsnaaeucsancnes 1 59 Inline Function Support Keyword inline wo eee eens 1 62 Inline Assembly Language Support Keyword asm esce 1 63 Assembly Construct Template cccasceciciteninetns 1 64 ASMO Construct SPa cosirer 1 64 ASMI Construct Syntax Rules sssikonasorinsssini 1 66 ASMO Construct Template Example ssisssessisisssninses 1 67 Assembly Construct Operand Description esesssseeseeeee 1 68 Assembly Constructs with Multiple Instructions 1 74 Assembly Construct Reordering and Optimization 1 74 Assembly Constructs with Input and Output Operands 1 75 Assembly Constructs and Macros cciescessnsctssvcescrssnsinersancusaes 1 77 Assembly Constructs and Flow Control scscicsecctessnecsensaueessus 1 77 Dual Memory Support Keywords pm dm ssssecsserseeeeee 1 78 Memory Keywords and Assignments Type Conversions 1 80 Memory Keywords and Function Declarations Pointers 1 81 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs CONTENTS Memory Keywords and Function Arguments 0 00 1 82 Memoty Keywords and Macros sinicrianisnisiieissrsrasi 1 82 PM and DM Compiler Support for Standard C Library Functions 1 83 Placement Support Keyword section seceroccniiieo
152. Library Header Files on page 3 8 Function names are C C function names If you call a C or C run time library function from an assembler program you must use the assembly version of the function name e For C functions this is an underscore at the beginning of the C function name For example the C function main is referred to as _main from assembler e Functions in C modules are normally compiled with an encoded function name Function names in C contain abbreviations for the parameters to the function and also the return type As such they can become very large The compiler mangles these names to a shorter form You can instruct the C compiler to use the sin gle underscore convention from C as shown by the following example extern C int myfunc int external name is _myfunc Alternatively compile C files to assembler and see how the function has been declared in the assembly file 3 4 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library It may not be possible to call inline functions from an assembler program as the compiler may have removed the definition of the function if all calls to the function are inlined Global static variables cannot be referred to in assembly routines as their names are encrypted For more information on the naming conventions see C C and Assembly Language Interface on page 1 169 You can use el far the a
153. M Removed msmall code Optimize for size not for speed Replaced with 0s see on page 1 37 mstatic spill Use dm memory when all reg ister are used Removed nostdinc Do not search standard sys Replaced with no std inc tem directories for header see on page 1 35 files nostdlib Do not use standard system Replaced with no std lib libraries and startup files see on page 1 36 when linking runhdr Specify a particular runtime Removed header traditional cpp Support some preprocessing Removed features VisualDSP 3 5 C C Compiler and Library Manual A 7 for ADSP 219x DSPs C C Compiler and Run Time Library New and Obsolete Warnings The VisualDSP 3 5 compiler includes several new warning switches These switches control the number and type of messages reported during a given compilation They are described in Table A 2 on page A 8 Table A 2 C C Compiler New Warning Switches VisualDSP 3 5 Warning Switch Description warn protos Produce a warning when a function is called without a full prototype Wdriver limit number Set a maximum number of driver errors Werror limit number Set a maximum number of compiler errors Wramarkes Indicates that the compiler may issue remarks which are diagnostic messages even milder than warnings Wterse Enable terse warnings pedantic Causes the compiler to generat
154. Manual for ADSP 219x DSPs C C Run Time Library io_space_read read I O space Synopsis include lt sysreg h gt int io_space_read const int Description The io_space_read function returns the value read from I O memory space at the address specified by the parameter The function is implemented as a compiler built in If the input argument is a constant literal value the compiler will emit a Type 34 instruction that will be inlined at the point of io_space_read use For non literal inputs the compiler will call a library compiler support routine to perform the required read Error Conditions The io_space_read function does not return raise or set any error conditions Example include lt sysreg h gt int addr OxA main int vl io_space_read 0xA inline instruction will be generated int v2 jo_space_read addr library support routine will be called VisualDSP 3 5 C C Compiler and Library Manual 3 67 for ADSP 219x DSPs C Run Time Library Reference See Also disable_interrupts enable_interrupts io_space_write mode_change sysreg_read sysreg_write 3 68 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library io_space_write write I O space Synopsis include lt sysreg h gt void io_space_write const int address const unsigned int value Description The io_space_write function stores the value passed as the second param
155. Manual for ADSP 219x DSPs DSP Run Time Library define cfir_init state coeffs delay ncoeffs state h coeffs state d delay state p delay state k ncoeffs The characteristics of the filter passband stopband etc are dependent upon the number of complex filter coefficients and their values A pointer to the coefficients should be stored in s gt h and s gt k should be set to the number of coefficients Each filter should have its own delay line which is a vector of type complex_fract16 and whose length is equal to the number of coefficients The vector should be cleared to zero before calling the function for the first time and should not otherwise be modified by the user program The structure member s gt d should be set to the start of the delay line and the function uses s gt p to keep track of its current position within the vector Algorithm pal y k by h i x k i fork 0 1 n i 0 Domain 1 0 to 1 0 VisualDSP 3 5 C C Compiler and Library Manual 4 43 for ADSP 219x DSPs DSP Run Time Library Reference clip clip Synopsis d Finclude lt math h gt int clip int parml int parm2 long int Iclip long int parml long int parm2 float fclipf float parml float parm2 double fclip double parml double parm2 fractl6o clip_frl6 fractl6 parml fractl6 parm2 Description This function clips a value if it is too large Algorithm if parml lt
156. O AR B input yregs to MAC MY1 MYO fe results from ALU AR C result from int multiplies MRO cc Used in the clobber list to tell the ASTAT compiler that condition codes have been clobbered d input xregs to SHIFTER SI SR1 SRO MR1 MRO AXO AYO AX1 AY1 MXO MX1 MYO MY1 AR D result from shift SR1 e data registers size 16 SI AX1 AXO MX1 MXO MYO MY1 AY1 AYO MRI MRO SRI SRO AR f shift amount SE g ALU X registers AX1 AXO AR SR1 SRO MR1 MRO G ALU Y registers AY1 AYO memory Used in the clobber list to tell the compiler that the asm statement writes to memory r all registers SR1 SRO SI MY1 MX1 AY1 AX1 MYO MXO AYO AXO MR1 MRO AR IO I7 O M7 LO L7 u DAGI L registers LO L3 v DAG2 L registers L4 L7 w DAGI I registers 10 13 x DAGI M registers 0 M3 1 72 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler Table 1 9 ASM Operand Constraints Cont d Constraint Description Registers y DAG2 I registers 14 17 Z DAG2 M registers M4 M7 amp constraint Indicates that the constraint is applied to an output operand that may not overlap an input operand constraint Indicates that the constraint is applied to an output operand amp constraint Indicates the constraint is applied to an input operand that may not be overlapped with an output operand amp constraint Indicates the constraint is applied to an output operand that may not overlap an
157. P prior to the call the caller s FP is never used by the recipient VisualDSP 3 5 C C Compiler and Library Manual 1 173 for ADSP 219x DSPs C C and Assembly Language Interface Using Mixed C C and Assembly Naming Conventions It is necessary to be able to use C C symbols function names or vari able names in assembly routines and use assembly symbols in C routines This section describes how to name C C and assembly symbols and shows how to use C C and assembly symbols To name an assembly symbol that corresponds to a C C symbol add an underscore prefix to the C C symbol name when declaring the symbol in assembly For example the C C symbol main becomes the assembly symbol _main To use a C C function or variable in your assembly routine declare it as global in the C C program and import the symbol into the assembly routine by declaring the symbol with the EXTERN assembler directive The C language performs name mangling on function names it defines according to the output and input parameter types of the function If call ing into a C defined function from assembly code the EXTERN symbol will need to be the mangled C output name This is best retrieved by looking at the compiler s assembly output for the C source that defines the required function To use an assembly function or variable in your C C program declare the symbol with the GLOBAL assembler directive in the assembly routi
158. REFUN 4 MORE is copied into stringl stringl 4 0 must null terminate stringl See Also memcpy Memmove strcpy VisualDSP 3 5 C C Compiler and Library Manual 3 131 for ADSP 219x DSPs C Run Time Library Reference strpbrk find character match in two strings Synopsis include lt string h gt char strpbrk const char s1 const char s2 Description The strpbrk function returns a pointer to the first character in s1 that is also found in s2 The string pointed to by s2 is treated as a set of charac ters The order of the characters in the string is not significant Error Conditions In the event that no character in s1 matches any in s2 a null pointer is returned Example include lt string h gt char ptrl ptr2 ptr3 ptrl TESTING ptr2 SHOP ptr3 strpbrk ptrl ptr2 ptr3 points to the S in TESTING See Also strspn 3 132 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library strrchr find last occurrence of character in string Synopsis d Finclude lt string h gt char strrchr const char s1 int c Description The strrchr function returns a pointer to the last occurrence of character c in the null terminated input string s1 Error Conditions The strrchr function returns a null pointer if c is not found Example d Finclude lt string h gt char ptrl ptr2 ptrl TESTING ptr2
159. S The S stop after compilation switch directs the compiler to stop compi lation before running the assembler The compiler outputs an assembler file with a s extension You can invoke this switch by selecting the Stop after Compiler check box in the VisualDSP Project Options dialog box Compile tab General category selection s The s strip debugging information switch directs the compiler to remove debugging information symbol table and other items from the output executable file during linking VisualDSP 3 5 C C Compiler and Library Manual 1 43 for ADSP 219x DSPs Compiler Command Line Interface save temps The save temps save intermediate files switch directs the compiler to retain intermediate files generated and normally removed as part of the various compilation stages These intermediate files are placed in the path output specified output directory or the build directory if the path output switch on page 1 39 is not used See Table 1 2 on page 1 10 for a list of intermediate files show The show display command line switch directs the compiler to echo all command line arguments expanded option files switches and environ ment variables used by the compiler si revision version The si revision version silicon revision switch sets the version of the hardware which is the required target for the build It is used to enable inherent behavior relating to any errata in specific silicon revisions
160. SP 219x DSPs 219x_hdr doj Startup file set up routines and call main 3 6 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library Table 3 1 C and C Library Files Cont d 219x lib Directory Description 219x_cpp_hdr doj C startup file set up routines and call main 219x_cpp_mt_hdr doj 219x_exit doj Dummy exit object for backwards compatibility 219x_ezkit_hdr doj Startup file set up routines call main and enable use of the EZ kit monitor program 219x_cpp_ezkit_hdr doj C start up file set up routines call main and 219x_cpp_mt_ezkit_hdr doj enable use of the EZ kit monitor program ibc dlb C run time library ibcmt dlb ibc_type32aworkaround dlb ibcmt_type32aworkaround dlb ibcpp dlb C run time library ibcppmt d1lb ibcpp_type32aworkaround dlb ibcppmt_type32aworkaround dlb ibcpprt dlb C run time support library ibcpprtmt dlb ibcpprt_type32aworkaround dlb ibcpprtmt_type32aworkaround dlb ibdsp dlb DSP library ibdsp_type32aworkaround d1b ibetsi dlb ETSI run time library ibio dlb 1 O library ibiomt dlb jbio_type32aworkaround d1b ibiomt_type32aworkaround d1b ibsim dlb Simulator library support Ensure that the C library of run time routines libcpprt d1b is the last library specified on the link line VisualDSP 3 5 C C Compiler and Library Manual 3 7 for ADSP 219x
161. SPs C C Run Time Model and Environment addressed with the smallest offsets from FP The register save area is located at the farthest end of this area and can be accessed by SP relative addressing Outgoing Arguments Outgoing arguments are located at the top of the stack prior to the call Space may be pre allocated or claimed at the time of each call Free Space Space below SP is normally considered free and unprotected it is available for use in growing the stack at any time synchronously or asynchronously the latter for interrupt handling However on the ADSP 219x DSPs the 32 words past the SP are reserved as a protected temporary space for use within a procedure General System Wide Specifications Some general specifications that apply to the stacks are The stacks grow down in memory from higher to lower addresses The current frames base is addressed by the FP register The first free word in each stack is addressed by the SP register Data can be pushed onto the stack by executing an instruction like the following one for the ADSP 219x DSPs DM 14 M5 rej The return address of the caller is stored at offsets 1 and 2 from the address carried by the current FP if it is stored on the stack The linkage back to the previous stack frame is stored at offset 0 from the current FP 1 158 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler At a procedu
162. Window vector Ay float beta Kaiser beta parameter Ro int a Address stride in samples for window vector int N Length of window vector EJ Description This function generates a vector containing the Kaiser window The length of the window required is specified by the parameter N and the stride parameter a is used to space the window values within the output vector w The length of the output vector should therefore be N a The B value is specified by parameter beta Algorithm ddT I B win where n 0 1 2 N 1 N 1 2 and I B represents the zeroth order modified Bessel function of the first kind Domain a gt 0 N gt 0 B gt 0 0 4 70 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs DSP Run Time Library gen_rectangular generate rectangular window Synopsis d Finclude lt window h gt void gen_rectangular_frl6 w a N fractl6 wl Window vector int a Address stride in samples for window vector int N Length of window vector Description This function generates a vector containing the Rectangular window The length of the window required is specified by the parameter N and the stride parameter a is used to space the window values within the output vector w The length of the output vector should therefore be N a Algorithm won 1 where n 0 1 2 N 1 Domain a gt 0 N gt 0 VisualDSP 3 5 C C Compiler and L
163. _frl6 fractl6 x if x lt 0x2000 FE lt O0 255 47 first quadrant 0 7 2 Xj cos_fr16 0x0 0x7fff 0 0x7fff return cos_frl6 x 4 else if x lt Ox6000 PR RD P57 if x lt 0x4000 a second quadrant 7 2 7 a cos_frl6 Ox8000 0x0 Ox7fff 0 pe Ba if x lt 0x6000 ai third quadrant 3 21 cos_fr1i6 0x0 0x7fff 0 0x8000 return cos_frl6 0xc000 x 4 else fourth quadrant 3 27 1 KI cos_fr16 0x8000 0x0 0x8000 0 return cos_fr16 0x8000 x 4 3 46 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library See Also acos sin VisualDSP 3 5 C C Compiler and Library Manual 3 47 for ADSP 219x DSPs C Run Time Library Reference cosh hyperbolic cosine Synopsis d Finclude lt math h gt double cosh double float coshf float Description The cosh function returns the hyperbolic cosine of its argument Error Conditions The cosh function returns the IEEE constant Inf if the argument is out side the domain Example d Finclude lt math h gt double x y y cosh x See Also sinh 3 48 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library disable_interrupts disable interrupts Synopsis d Finclude lt sysreg h gt void disable_interrupts void Description The disable_interr
164. a Im b Domain 3 4 x 1038 to 3 4 x 1038 for csubf csub 1 0 to 1 0 for csub_fr16 4 56 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs DSP Run Time Library fir finite impulse response filter Synopsis include lt filter h gt void fir_frl6 x y n s const fractl6 x Input sample vector x x fractl6 yl Output sample vector y int n Number of input samples E fir_state_fr16 s Pointer to filter state structure The function uses the following structure to maintain the state of the filter typedef struct fractl6 h Filter coefficients as fractl6 d Start of delay line E fract16 p Read Write pointer ai int k Number of coefficients int 1 Interpolation decimation index EN fir_state_fr16 Description The fir_fr16 function implements a finite impulse response FIR filter The function generates the filtered response of the input data x and stores the result in the output vector y The number of input samples and the length of the output vector is specified by the argument n The function maintains the filter state in the structured variable s which must be declared and initialized before calling the function The macro fir init in the filter h header file is available to initialize the structure and is defined as VisualDSP 3 5 C C Compiler and Library Manual 4 57 for ADSP 219x DSPs DSP Run Time Library Reference define
165. a x and stores the result in the output vector y The number of input samples is specified by the argument n and the size of the output vector should be n 1 where is the interpolation index The function maintains the filter state in the structured variable s which must be declared and initialized before calling the function The macro fir_init in the filter h header file is available to initialize the structure and is defined as VisualDSP 3 5 C C Compiler and Library Manual 4 61 for ADSP 219x DSPs DSP Run Time Library Reference define fir_init state coeffs delay ncoeffs index state h coeffs state d delay state p delay state k ncoeffs state 1 index The filter characteristics are dependent upon the number of polyphase fil ter coefficients and their values and on the interpolation index supplied by the calling program A pointer to the coefficients should be stored in s gt h and s gt k should be set to the number of coefficients The interpola tion index is supplied to the function in s gt 1 Each filter should have its own delay line which is a vector of type fract16 and whose length is equal to the number of coefficients The vector should be cleared to zero before calling the function for the first time and should not otherwise be modified by the user program The structure member s gt d should be set to the start of the delay line and the function uses s gt p
166. ables use of existing libraries with the new compiler The extern 01dAsmCal1 declaration can be added to the prototype s of the functions developed under Release 6 1 Your programs will be faster smaller and more reliable after the C code is upgraded to use the new compiler This convention is similar to the C C linkage specification VisualDSP 3 5 C C Compiler and Library Manual A 3 for ADSP 219x DSPs C C Compiler and Run Time Library Support for G21 Based Options And Extensions The cc219x compiler supports most of the switches and extensions of the previous GNU based compiler release For a list of absolute or modified options see Compiler Switch Modifications on page A 5 ANSI C Extensions The following extensions are no longer supported or their functions have been modified typeof This extension was used to define the type of an expression Complex types complex creal cimag and conj These exten sions were used to define complex numbers Although you cannot write complex number literals you can have a complex type defined with real and imaginary components These types need to be managed by the programmer Support for complex types using such an approach is used in the libdsp definitions and use of vari ous complex types Compound statements within expressions This extension was used to declare variables within an expression You can achieve these results using inline functions
167. aced with operand one x The output operand is the C C variable result The letter c is the operand constraint for the variable This constrains the output to an ALU result register The compiler generates code to copy the output from the register to the variable result if necessary The in c indicates that the operand is an output The input operand is the C C variable x The letter c is the oper and constraint for the variable This constrains x to an ALU register If x is stored in different kinds of registers or in memory the com piler generates code to copy the values into an register before the asm construct uses them VisualDSP 3 5 C C Compiler and Library Manual 1 67 for ADSP 219x DSPs C C Compiler Language Extensions Assembly Construct Operand Description The second and third arguments to the asm construct describe the oper ands in the assembly language template There are several pieces of information that need to be conveyed for the compiler to know how to assign registers to operands This information is conveyed with an oper and constraint The compiler needs to know what kind of registers the assembly instructions can operate on so it can allocate the correct register type You convey this information with a letter in the operand constraint string which describes the class of allowable registers Table 1 9 on page 1 72 describes the correspondence between constraint letters and register classes
168. acter segment in one string but not the other Synopsis include lt string h gt size_t strcespn const char sl const char s2 Description The strcspn function returns the length of the initial segment of s1 which consists entirely of characters not in the string pointed to by s2 The string pointed to by s2 is treated as a set of characters The order of the characters in the string is not significant Error Conditions The strcspn function does not return an error condition Example S include lt string h gt char ptrl ptr2 size_t len ptrl Tried and Tested ptr2 aeiou len strcspn ptrl ptr2 Jen 2 See Also strlen strspn 3 126 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library strerror get string containing error message Synopsis d Finclude lt string h gt char strerror int errnum Description The strerror function returns a pointer to a string containing an error message by mapping the number in errnum to that string Error Conditions The strerror function does not return an error condition Example include lt string h gt char ptrl ptrl strerror 1 See Also No references to this function VisualDSP 3 5 C C Compiler and Library Manual 3 127 for ADSP 219x DSPs C Run Time Library Reference strlen string length Synopsis include lt string h gt size_t strlen const char s1
169. ad write data as in ANSI C The compiler s default behavior assumes that data referenced through const pointers will never change The const read write switch changes the compiler s behavior to match the ANSI C assumption which is that other non const pointers may be used to change the data at some point Dmacro definition The D define macro switch directs the compiler to define a macro If you do not include the optional definition string the compiler defines the macro as the string 1 If definition is required to be a character string 1 24 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler constant it must be surrounded by escaped double quotes Note that the compiler processes D switches on the command line before any U unde fine macro switches This switch can be invoked with the Definitions dialog field located in the VisualDSP Project Options dialog box Compile tab Preprocessor category debug types lt file h gt The debug types switch provides for building an h file directly and writing a complete set of debugging information for the header file The g option on page 1 28 need not be specified with the debug types switch because it is implied For example cc219x debug types anyHeader h The implicit g option writes debugging information for only those typedefs that are referenced in the program The debug types option provides complete debugging in
170. ads disable thread safe build compiler switch 1 36 no widen muls disable widening multiplications compiler switch 1 36 NxN point 2 D complex input FFT cfft2d function 4 40 NxN point 2 D inverse input FFT ifft2d function 4 81 NxN point 2 D real input FFT rfft2d function 4 98 O O enable optimization compiler switch 1 37 o output compiler switch 1 38 Oa automatic function inlining compiler switch 1 37 oldasmcall csp 8x compiler switch 1 38 open operation 3 14 operand constraints 1 69 optimization code 2 29 controlling 1 56 default 1 56 interprocedural analysis 1 57 option 1 30 reset 1 126 switches 2 37 optimized assembler file 1 58 optimizer 1 56 1 123 2 4 optimizing for space 1 126 for speed 1 126 2 29 optimizing asm C program constructs 1 75 Os optimize for size compiler switch 1 37 outer loop 2 19 output flushing 3 15 generated by printf 3 15 Ov num optimize for speed versus size compiler switch 1 38 P P omit line numbers compiler switch 1 38 path install installation location compiler switch 1 39 path output non temporary files location compiler switch 1 39 path temp temporary files location compiler switch 1 39 path tool tool location compiler switch 1 39 pchdir locate PCHRepository compiler switch 1 40 PCHRepository directory 1 40 pedantic ANSI standard warnings compiler switch 1 40 pedantic errors ANSI C errors compiler switch 1 40 pi
171. age 1 34 Placement support keyword section Disabled using the no extra keywords compiler switch see on page 1 34 Boolean type support keywords in C bool true false Disabled using the no extra keywords compiler switch see on page 1 34 Variable length array support Non constant aggregate initializer support Indexed initializer support Preprocessor generated warnings Support for C style comments in C programs For more information on these extensions see the C C Compiler Lan guage Extensions on page 1 59 VisualDSP 3 5 C C Compiler and Library Manual 1 5 for ADSP 219x DSPs Compiler Command Line Interface Compiler Command Line Interface This section describes how the cc219x compiler is invoked from the com mand line the various types of files used by and generated from the compiler and the switches used to tailor the compiler s operation This section contains e Running the Compiler on page 1 7 e Specifying Compiler Options in VisualDSP on page 1 11 e Compiler Command Line Switches on page 1 12 e Data Type Sizes on page 1 54 e Optimization Control on page 1 56 By default the compiler runs with Analog Extensions for C code enabled This means that the compiler processes source files written in ANSI ISO standard C language supplemented with Analog Devices extensions Table 1 1 on page 1 8 lists valid extensions By default the compiler pro cesses the input
172. age 1 53 Prevents filtering of any linker errors through the deman gler 1 20 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler C C Mode Selection Switch Descriptions The following command line switches provide C C mode selection c89 The c89 switch directs the compiler to support programs that conform to the ISO IEC 9899 1990 standard For greater conformance to the stan dard the following switches should be used alttok const read write no extra keywords and pedantic see in Table 1 4 on page 1 13 C The c C mode switch directs the compiler to assume that the source file s are written in ANSI ISO standard C with Analog Devices language extensions All the standard features of C are accepted in the default mode except exception handling and run time type identification because these impose a run time overhead that is not desirable for all embedded programs C C Compiler Common Switch Descriptions The following command line switches apply in C and C modes sourcefile The sourcefile parameter or parameters switch specifies the name of the file or files to be preprocessed compiled assembled and or linked A file name can include the drive directory file name and file extension The cc219x compiler uses the file extension to determine the operations to perform Table 1 2 on page 1 10 lists the permitted extensions and matching comp
173. al for ADSP 219x DSPs 2 37 Useful Optimization Switches 2 38 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs 3 C C RUN TIME LIBRARY The C and C run time libraries are collections of functions macros and class templates that you can call from your source programs The libraries provide a broad range of services including those that are basic to the languages such as memory allocation character and string conversions and math calculations Using the library simplifies your software develop ment by providing code for a variety of common needs This chapter contains e C and C Run Time Library Guide on page 3 3 It provides introductory information about the ANSI ISO stan dard C and C libraries It also provides information about the ANSI standard header files and built in functions that are included with this release of the cc219x compiler e Documented Library Functions on page 3 23 It tabulates the functions that are defined by ANSI standard header files e C Run Time Library Reference on page 3 26 It provides reference information about the C run time library functions included with this release of the cc219x compiler The cc219x compiler provides a broad collection of library functions including those required by the ANSI standard and functions supplied by Analog Devices that are of value in signal processing applications In addi tion to the Standard C Library this
174. alDSP 3 0 C C Compiler and Library Manual for ADSP 219x DSPs INDEX 1 33 MM generate make rules and compile 1 32 Mo processor output file 1 32 MQ 1 33 Mt output make rules 1 32 no_hardware_pc_stack 1 35 no alttok disable tokens 1 33 no bss 1 33 no builtin no built in functions 1 34 no circbuf no circular buffer 1 34 no defs disable defaults 1 34 no extra keywords disable short form keywords 1 34 no fp associative 1 34 no mem not invoking memory initializer 1 35 no std ass disable standard assertions 1 35 no std def disable standard macro definitions 1 35 no std inc disable standard include search 1 35 no std lib disable standard library search 1 36 nothreads disable thread safe build 1 36 no widen muls disable widening multiplications 1 36 O enable optimizations 1 37 o filename output file 1 38 Oa automatic function inlining 1 37 oldasmcall csp 8x 1 38 Os optimize for size 1 37 Ov num optimize for speed vs size 1 38 P omit line numbers 1 38 path tool location 1 39 path install directory installation location 1 39 path output directory non temporary files location 1 39 path temp directory temporary files location 1 39 pch precompiled header 1 40 pchdir locate PCHRepository 1 40 pedantic ANSI standard warnings 1 40 pedantic errors ANSI C errors 1 40 PP omit line numbers and compi
175. alignment 7 The pragma result_alignment n asserts that the pointer or integer returned by the function has a value that is a multiple of n This pragma is often used in conjunction with the pragma alloc of cus tom allocation functions that return pointers that are more strictly aligned than be deduced from their type Template Instantiation Pragmas The template instantiation pragmas give fine grain control over where that is in which object file the individual instances of template func tions and member functions and static members of template classes are created The creation of these instances from a template is known in C speak as instantiation As templates are a feature of C these pragmas are only allowed in c mode These pragmas take the name of an instance as a parameter as shown in Table 1 11 1 134 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Table 1 11 Instance Names Compiler Name Parameter a template class name A lt int gt a template class declaration class A lt int gt a member function name A lt int gt f a static data member name A lt int gt 1 a static data declaration int A lt int gt 1 a member function declaration void A lt int gt fint char a template function declaration char f int float If instantiation pragmas are not used the compiler will chose object files i
176. ames and arguments for each function are described in the function s reference page in the section DSP Run Time Library Reference on page 4 22 Like other functions you use library functions should be declared Decla rations are supplied in header files as described in the section Working With Library Header Files on page 3 8 The function names are C function names If you call C run time library functions from an assembly language program you must use the assembly version of the function name which is the func tion name prefixed with an underscore For more information on naming conventions see the section C C and Assembly Lan guage Interface on page 1 169 You can use the archiver described in the VisualDSP 3 5 Linker and Utilities Manual for 16 Bit Processors to build library archive files of your own functions 4 2 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs DSP Run Time Library Linking DSP Library Functions When your C C code calls a DSP run time library function the call creates a reference that the linker resolves when linking your program This requires the linker to be directed to link with the DSP run time library libdsp d1b in the 219x 1ib directory which is a subdirectory of the VisualDSP installation directory The default Linker Description File LDF will do this automatically as it specifies that 1ibdsp d1b will be included in every link If an app
177. an simple assembly function to add two integers and mask the result to fit into 8 bits _add_mask AY1 DM I4 1 AX1 DM I4 2 AYO 255 AR AX1 AY1 RTS DB AR AR AND AYO AX1 AR _add_mask end Clearly the function does not modify the majority of the scratch registers available and thus these could instead be used as call preserved registers In this way fewer spills to the stack would be needed in the caller function Using the prototype pragma regs_clobbered AX1 AYO AY1 AR ASTAT int add_mask int int Good uses regs_clobbered to increase call preserved register set VisualDSP 3 5 C C Compiler and Library Manual 2 33 for ADSP 219x DSPs Pragmas the compiler is told which registers are modified by a call to the add_mask function The registers not specified by the pragma are assumed to pre serve their values across such a call and the compiler may use these spare registers to its advantage when optimizing the call sites The pragma is also powerful when all of the source code is written in C In the above example a C implementation might be int add_mask int a int b return atb amp 255 Bad function thought to clobber entire volatile register set Since this function will not need many registers when compiled it can be defined using pragma regs_clobbered AX1 AYO AY1 AR M7 CCset int add_mask int a int b return at b amp 255 Good function co
178. analysis Initializing Constants Statically IPA will identify variables that have only one value and replace them with constants resulting in a host of benefits for the optimizer s analysis For this to happen a variable must have a single value throughout the pro gram If the variable is statically initialized to zero as all global variables are by default and is subsequently assigned some other value at another point in the program then the analysis sees two values and will not con sider the variable to have a constant value For example d Finclude lt stdio h gt int val initialized to zero void init val 3 re assigned void func printf val 4d val int main inito func Bad IPA cannot see that val is a constant is better written as include lt stdio h gt const int val 3 initialized once VisualDSP 3 5 C C Compiler and Library Manual 2 9 for ADSP 219x DSPs General Guidelines void init void func printf val d val int main init func Good IPA knows val is 3 Avoiding Aliases It may seem that the iterations may be performed in any order in the fol lowing loop void fn char aL char bE int n int 13 for i 0 i lt n i aLi DLT de Bad a and b may alias each other but a and b are both parameters and although they are declared with 1 they are in fact pointers which may point
179. and returns the coefficients in the vector w The vector w known as the twiddle table is normally calculated once and is then passed to an FFT function as a separate argument The size of the table must be at least 1 2 of n the number of points in the FFT FFTs of different sizes can be accommodated with the same twiddle table Simply allocate the table at the maximum size Each FFT has an addi tional parameter the stride of the twiddle table To use the whole table specify a stride of 1 If the FFT uses only half the points of the largest FFT the stride should be 2 this takes only every other element Algorithm This function takes FFT length n as an input parameter and generates the lookup table of complex twiddle coefficients The samples are twid_re k cod 27 n wde imidz sin 27 K n where k 0 1 2 n 2 1 4 102 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs DSP Run Time Library Domain The FFT length n must be a power of two and at least 16 VisualDSP 3 5 C C Compiler and Library Manual 4 103 for ADSP 219x DSPs DSP Run Time Library Reference twidfftrad4 generate FFT twiddle factors for radix 4 FFT Synopsis include lt filter h gt void twidfftrad4_frl6 complex_fract1l6 wl int n void twidfft_frl6 complex_fractl6 wl int n Description The twidfftrad4_fri6 function initializes a table with complex twiddle factors for a radix 4 FFT The num
180. ap Register and System Defini C Extension tions for ADSP 2191 DSPs 3 8 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library Table 3 2 C Run Time Library Header Files Cont d Header Purpose Standard def2192 12 h Memory Map Register and System Defini C Extension tions for ADSP 2192 12 DSPs def219x h Memory Map Definitions C Extension errno h Error Handling ANSI float h Floating Point ANSI iso646 h Boolean Operators ANSI limits h Limits ANSI locale h Localization ANSI math h Mathematics ANSI setjmp h Non Local Jumps ANSI signal h Signal Handling ANSI stdarg h Variable Arguments ANSI stddef h Standard Definitions ANSI stdio h Input Output ANSI stdlib h Standard Library ANSI string h String Handling ANSI sysreg h Efficient system access C Extension The following sections provide descriptions of the header files contained in the C library The header files are listed in alphabetical order assert h The assert h header file contains the assert macro ctype h The ctype h header file contains functions for character handling such as isalpha tolower etc VisualDSP 3 5 C C Compiler and Library Manual 3 9 for ADSP 219x DSPs C and C Run Time Library Guide def2191 h Memory Map Definitions The def2191 h header file contains macro definitions for the ADSP 2191 processor s system addresses and syst
181. arameters or whether a variable actually has a constant value The ipa compiler switch on page 1 30 enables interprocedural analysis IPA which can make this available When this switch is used the com piler will be called again from the link phase to recompile the program using additional information obtained during previous compilations Because it only operates at link time the effects of IPA will not be seen if you compile with the S switch on page 1 43 To see the assembly file when IPA is enabled use the save temps switch on page 1 44 and look at the s file produced after your program has been built As an alternative to IPA you can achieve many of the same benefits by adding pragma directives and other declarations such as __builtin_aligned to provide information to the compiler about how each function interacts with the rest of the program These directives are further described Using Built In Functions in Code Optimization on page 2 25 and Pragmas on page 2 31 2 6 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Achieving Optimal Performance from C C Source Code Data Types The compiler directly supports the following scalar data types Single Word Fixed Point Data Types Native Arithmetic char 16 bit signed integer unsigned char 16 bit unsigned integer short 16 bit signed integer unsigned short 16 bit unsigned integer int 16 bit signed integer unsigne
182. argument and always scales the output by n n this is equivalent to static scaling The function will also set block_exponent to log2 n Algorithm 1 n l n 1 c i j A Ee AEEA N k 0 1 0 where i 0 1 n 1 j 0 1 2 n 1 Domain Input sequence length n must be a power of two and at least 16 4 82 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs DSP Run Time Library infinite impulse response filter Synopsis include lt filter h gt void jiir_frl6 x y n s const fractl6 x Input sample vector x a fractl6 yl Output sample vector y af int n Number of input samples af jir_state_frl6 s Pointer to filter state structure The function uses the following structure to maintain the state of the filter typedef struct fractl6 c coefficients Kf fractl6 d start of delay line xj int k number of bi quad stages A iir_state_fr16 Description The iir_fr16 function implements a bi quad canonical form infinite impulse response IIR filter It generates the filtered response of the input data x and stores the result in the output vector y The number of input samples and the length of the output vector is specified by the argument n The function maintains the filter state in the structured variable s which must be declared and initialized before calling the function The macro iir init in the filter h header file is available to initialize t
183. ary part The phase argument is interpreted as radians For the polar_fri6 function the phase must be scaled by 27 and must be in the range 0x8000 0x7ff0 The value of the phase may be either pos itive or negative Positive values are interpreted as an anti clockwise motion around a circle with a radius equal to the magnitude as shown in Table 4 9 Table 4 9 Positive Phases Phase Radians 0 0 0 0 25 0x2000 T2 0 50 0x4000 T 0 75 0x6000 3 27 0 999 0x7ff0 lt 27 VisualDSP 3 5 C C Compiler and Library Manual 4 91 for ADSP 219x DSPs DSP Run Time Library Reference Table 4 10 shows how negative values for the phase argument are inter preted as a clockwise movement around a circle Table 4 10 Negative Phases Phase Radians 0 25 Oxe000 3 27 0 50 0xc000 T 0 75 0xa000 T 2 1 00 0x8000 2T Algorithm Re c r cos 0 Im c r sin where O is the phase and r is the magnitude Domain phase 9099 9099 for polarf polar magnitude 3 4 x 1038 3 4 x 1078 for polarf polar phase 1 0 0 999969 for polar_fr16 magnitude 1 0 1 0 for polar_frl6 Example include lt complex h gt dtdefine PI 3 14159265 complex_fractl6 point float phase_float 4 92 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs DSP Run Time Library fractl6 phase_fril6 fractl6 mag_frl6
184. ase i tp SA ei inl aaa rns anta a 1 43 GREER DOUIEEET TERIEE aal onena cnsiisremncinaes 1 43 a TT Rane enisandemnere can TO RS 1 43 A RE REP aM RT RSE OTT SRE OR TS PRE RPT Re er fT OTe RPA CET EAT TCR Rave RoR TUE 1 43 SEVEN arepknnoni kaka ninii i kaai 1 44 O E A 1 44 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs vii CONTENTS TOV SIA ONY roren oaar news 1 44 SE CELE ssa 1 45 EDIRNE o E 1 45 Oy a EN 1 45 E N A E EE E E N 1 45 sT PANINI sree 1 46 Si 21 a ae Onine ner eter Reet nnE FOrmetne Ree ane ant arr rer ene rename 1 46 PDE xmas 1 47 s LET eee eee One ae REECE Re Seer Freee MU ner ete ere 1 47 pee NR RUE IE RIL orco 1 47 ITA HCTIAY ic siccikes Giaassnannaitiuehehnmaieeibeatiaanbehenadiinbiand 1 48 E E EE E E ie ae ean 1 48 a SOE enamed ist srono 1 48 ee dus E ET ATSO E EATE E 1 48 es E E ONE E EE E A eer 1 49 W error remark suppress warn number e0 1 49 Wenror imit number accauscianssersciinhareiniedaareuudniouses 1 49 e E E E E 1 49 E E E E E E 1 49 T E EAN 1 50 PTOI IOS E AE A E E 1 50 workaround lt workaround gt lt workaround gt 1 50 E ATU EE E E eta sea E okaaimadbioet 1 50 AIEO DES prr arr e E E Eai 1 50 viii VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs CONTENTS RRCE TURN E E 1 51 C Mode Compiler Switch Descriptions 00 eee eee 1 52 L Fi hander EET ga eden ene 1 52 UNE pa paid erneeauinies 1 53 MUON IAI G
185. ates DWARF 2 debug information H on page 1 28 Outputs a list of header files but does not compile the source file HH on page 1 28 Outputs a list of included header files and compiles hLelp on page 1 29 Outputs a list of command line switches with brief syntax descriptions VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler Table 1 4 C C Compiler Common Switches Contd Switch Name Description I on page 1 29 Establishes the point in the include directory list at which the search for header files enclosed in angle brackets should begin I directory on page 1 29 Appends directory to the standard search path i on page 1 30 include filename on page 1 30 ipa on page 1 30 Outputs only header details or makefile dependencies for include files specified in double quotes Includes named file prior to preprocessing each source file Specifies that interprocedural analysis should be performed for optimization between translation units jump pm dm same on page 1 31 Specifies where the compiler should place jump tables in memory L directory on page 1 31 Appends the specified directory to the standard library search path when linking Jibrary on page 1 31 Searches the specified library for functions when linking on page 1 32 Generates make rules only does n
186. ath h gt int min int parml int parm2 long int Imin long int parml long int parm2 float fminf float parml float parm2 double fmin double parml double parm2 fractl6 min_frl6 fractl6 parml fractl6 parm2 Description This function returns the smaller of its two arguments Algorithm if parml lt parm2 return parml else return parm2 Domain Full range for type of parameters used VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs 4 87 DSP Run Time Library Reference mu_compress p law compression Synopsis include lt filter h gt void mu_compress in out n const short inl Input array Xj short out Output array xy int n Number of elements to be compressed Description The mu_compress function takes a vector of linear 14 bit signed speech samples and performs p law compression according to ITU recommenda tion G 711 Each sample is compressed to 8 bits and is returned in the vector pointed to by out Algorithm C k mu_law compression of A k for k 0 to n 1 Domain Content of input array 8192 to 8191 4 88 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs DSP Run Time Library mu_expand p law expansion Synopsis include lt filter h gt void mu_expand in out n const short inl Input array Xj short out Output array int n Number of elements to be expanded Description The mu_expan
187. aturated arithmetic 1 92 type conversions 1 91 free deallocate memory function 3 61 free deallocate memory functions 3 71 frexp separate fraction and exponent function 3 62 full version display versions compiler switch 1 27 function arguments 1 82 and memory keywords 1 82 function call in loop 2 21 function inlining 2 13 functions built in 1 95 C run time library 3 26 3 161 DSP 4 22 4 109 primitive I O 3 13 program control calloc 3 41 free 3 71 malloc 3 93 realloc 3 110 G g generate debug information compiler switch 1 28 GCC compatibility extensions 1 138 GCC compiler 1 138 1 140 gen_bartlett generate bartlett window function 4 63 gen_blackman generate blackman window function 4 65 gen_gaussian generate gaussian window function 4 66 gen_hamming generate hamming window function 4 67 gen_hanning generate hanning window function 4 68 gen_harris gen_harris window function 4 69 gen_kaiser generate kaiser window function 4 70 gen_rectangular generate rectangular window function 4 71 gen_triangle generate triangle window function 4 72 1 13 VisualDSP 3 0 C C Compiler and Library Manual for ADSP 219x DSPs INDEX gen_vohann generate von hann window function 4 74 general optimization pragmas 1 125 general register set 1 95 3 148 3 151 general utilities specified by C standard 3 15 get phase of a complex number arg function 4 27 global static variables
188. aveats as to what registers may or must be placed in the clobbered set On ADSP 219x processors the registers 14 15 DMPG2 MSTAT and M_MODE may not be specified in the clobbered set as the correct operation of the function call requires their value to be preserved If the user specifies them in the clobbered set a warning will be issued and they will be removed from the specified clobbered set 1 132 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler The registers AR and M7 are always clobbered If the user specifies a func tion definition with the regs_clobbered pragma which does not contain these registers a warning is issued and these registers are added to the clobbered set However if the compiler sees an external function declaration with a regs_clobbered pragma that does not contain the AR and M7 registers a warning will not be issued because an assembly function may have been written which genuinely does not modify these registers Registers from these classes D I B ASTAT CNTR PX DMPG1 STACKA STACKP IJPG IOPG SB SE may be specified in clobbered set and code will be generated to save them as necessary The L registers are required to be zero on entry and exit from a function A user may specify that a function clobbers the L registers If it is a com piler generated function then it will in fact leave the L registers as zero at the end of the function If it is an assembly f
189. baiadaueiegieb in Riieuusd 1 32 GI a ias san EDA a Pee oe ney eeeen Soret ttany cecerene aoe eer 1 33 ET rE 1 33 Se Se Oe ane E ROE E E DE oe vee eRe 1 33 SECIS pa 1 33 AARNE E E A E E A E 1 34 OEE a a pseraeaduaeieecieshnuentetenecema ee 1 34 ANGIE E EEE E ieee E ET T 1 34 APPR onise ara a 1 34 a E E N E 1 34 ia hardware pe aik oain EAEN 1 35 E e a E E E E E EEE 1 35 E E EE E A E E E EE 1 35 AONE ninn 1 35 AAI E 1 35 E E E EA N EEN E E E E 1 36 po Wwiden mulg oncinstindes secseea anda otndeusnsondsedeanneeabeasecenieaties 1 36 N E E N E E E E E 1 36 a D E PEE EETA E E E AAEE E EE 1 37 vi VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs CONTENTS AD E E E A eae 1 37 E E O E E R E E E A err Te 1 37 SA PUAN pas A a aeienaaieneamaiaaatineh 1 38 I e r R R ie 1 38 kasme EPOE ae 1 38 E E E A E henna A aoa 1 38 AT ano ane 1 38 path asm compiler def lib link mem filename 1 39 path install direct ry cath scceccrdechenseaataiaioeadeeseaesameeies 1 39 p th output directory deci scccescnsasudecciscadoiendaeccnmncnsceies 1 39 apath temp DIPERIOTY acc nicsertcarrieteiindsictleiunniiancauuia 1 39 es E ET Rene ne erty E rt E ret ment EET A E nome 1 40 ehdit rey pacare r R 1 40 TE a E eae 1 40 spEdAnTICEITOTS ajoradan andenn AR AENEA 1 40 applet DENNE sarreria EA 1 41 prog processor xciecs ciated iat ortdintienedainrudinnonaaineisa 1 41 R emcees hj directory co erreren 1 42 SU see t
190. bc amp rem dd 2 3455E 7 rem abc dd strtod 0x1 800p 9 123 amp rem dd 768 0 rem 123 ay See Also atof strtol strtoul VisualDSP 3 5 C C Compiler and Library Manual 3 137 for ADSP 219x DSPs C Run Time Library Reference strtodf convert string to float Synopsis include lt stdlib h gt float strtodf const char nptr char endptr Description The strtodf function extracts a value from the string pointed to by nptr and returns the value as a float The strtodf function expects nptr to point to a string that represents either a decimal floating point number or a hexadecimal floating point number Either form of number may be pre ceded by a sequence of whitespace characters as determined by the isspace function that the function ignores A decimal floating point number has the form sign digits E digits te E sign digits The sign token is optional and is either plus or minus and dig its are one or more decimal digits The sequence of digits may contain a decimal point The decimal digits can be followed by an exponent which consists of an introductory letter e or E and an optionally signed integer If neither an exponent part nor a decimal point appears a decimal point is assumed to follow the last digit in the string The form of a hexadecimal floating point number is sign 0x 0X Chexdigs E hexdigs p P sign digit
191. ber of points in the FFT are defined by n and the coefficients are returned in the twiddle table w The size of the twiddle table must be at least 34n the length of the FFT input sequence A table can accommodate several FFTs of different sizes by allocating the table at maximum size and then using the stride argu ment of the FFT function to specify the step size through the table If the stride is set to 1 the FFT function uses all the table if your FFT has only a quarter of the number of points of the largest FFT the stride should be 4 For efficiency the twiddle table is normally generated once during pro gram initialization and is then supplied to the FFT routine as a separate argument The twidfft_fr16 routine is provided as an alternative to the twidfftrad4_fr16 routine and performs the same function Algorithm This function takes FFT length n as an input parameter and generates the lookup table of complex twiddle coefficients 4 104 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs DSP Run Time Library The samples generated are twid_re k co 27 K n twid _im k si 7 e n where k 0 1 2 34n 1 Domain The FFT length n must be a power of four and at least 16 VisualDSP 3 5 C C Compiler and Library Manual 4 105 for ADSP 219x DSPs DSP Run Time Library Reference twidfft2d generate FFT twiddle factors for 2 D FFT Synopsis include lt filter h gt
192. bles are modified in the loop pragma alloc The pragma alloc pragma asserts that the function behaves like the malloc library function In particular it returns a pointer to new memory that cannot alias any pre existing buffers In the following code pragma alloc int new_buf void int vmul int a int b int i int out new_buf for i 0 i lt 100 i out i a i b i Good uses pragma alloc to disambiguate out from a and b the use of the pragma allows the compiler to be sure that the write into buffer out does not modify either of the two input buffers a or b and therefore the iterations of the loop may be re ordered 2 32 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Achieving Optimal Performance from C C Source Code pragma regs_clobbered The regs_clobbered pragma is a useful way to improve the performance of code that makes function calls The best use of the pragma is to increase the number of call preserved registers available across a function call There are two complementary ways in which this may be done First of all suppose that you have a function written in assembly that you wish to call from C source code The regs_clobbered pragma may be applied to the function prototype to specify which registers are clob bered by the assembly function that is which registers may have different values before and after the function call Consider for example
193. bly Construct Template on page 1 64 e Assembly Construct Operand Description on page 1 68 e Assembly Constructs with Multiple Instructions on page 1 74 e Assembly Construct Reordering and Optimization on page 1 74 e Assembly Constructs with Input and Output Operands on page 1 75 e Assembly Constructs and Macros on page 1 77 Assembly Construct Template Using asm constructs you can specify the operands of the assembly instruction using C expressions You do not need to know which registers or memory locations contain C variables ASM Construct Syntax Use the following general syntax for your asm constructs asm template Lconstraint output operand constraint output operand J L Lconstraint input operand constraint input operand clobber I The syntax elements are defined as 1 64 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler template e The template is a string containing the assembly instruction s with number indicating where the compiler should substitute the oper ands Operands are numbered in order of occurrence from left to right starting at 0 Separate multiple instructions with a semico lon then enclose the entire string within double quotes For more information on templates containing multiple instruc tions see Assembly Constructs with Multiple Instructions on page 1 74 constraint The constraint is a
194. brary algorithm 3 20 deque 3 20 fstreams h 3 22 functional 3 21 hash_map 3 21 hash_set 3 21 iomanip h 3 22 iostream h 3 22 iterator 3 21 list 3 21 map 3 21 memory 3 21 new h 3 22 numeric 3 21 queue 3 21 set 3 22 stack 3 22 utility 3 22 vector 3 22 system 1 149 user 1 149 header files standard float h 3 10 iso646 h 3 11 stdio h 1 166 3 14 help command line help compiler switch 1 29 hexadecimal digit test see isxdigit function hexadecimal floating point constants 1 142 HH list headers and compile compiler switch 1 28 histogram 4 75 I i less includes compiler switch 1 30 I start include directory compiler switch 1 29 1 35 I O 1 15 VisualDSP 3 0 C C Compiler and Library Manual for ADSP 219x DSPs INDEX file support 1 166 functions 3 13 library 3 7 3 13 new device support 1 166 primitives 1 166 3 14 redirection 1 50 space addresses 1 97 space read 1 97 space write 1 97 I O primitives 1 166 I O support for new devices 1 166 ifft N point inverse FFT function 4 77 ifft2d NxN point 2 D inverse input FFT function 4 81 ifftrad4 N point inverse FFT function 4 79 iir infinite impulse response filter function 4 83 iir_fr16 function 4 83 iir_init macro 4 83 include include file compiler switch 1 30 include directives 1 151 indexed array 2 12 indexed initializer support 1 87 induction variables 2 19 infinite impulse response IIR filter 4 83 inline keyword
195. brary Manual for ADSP 219x DSPs DSP Run Time Library cexp complex exponential Synopsis include lt complex h gt complex_float cexpf float a complex_double cexp double a Description This function computes the complex exponential of real input a and returns the result Algorithm Re c cos a Im c sin a Domain a 9099 9099 for cexpf cexp VisualDSP 3 5 C C Compiler and Library Manual 4 35 for ADSP 219x DSPs DSP Run Time Library Reference cfft N point complex input FFT Synopsis include lt filter h gt le void cfft_frl6 in tL outl wl wst n block_exponent scale_method const complex_fractl6 in input sequence xy complex_fractl6 tL temporary working buffer if complex_fractl6 out output sequence ap const complex_fractl6 wl twiddle sequence x int wst twiddle factor stride Ef int n number of FFT points K int block_exponent block exponent of output data int scale method scaling method desired O none l static 2 dynamic Description This function transforms the time domain complex input signal sequence to the frequency domain by using the radix 2 Fast Fourier Transform FFT The size of the input array in the output array out and the temporary working buffer t is n where n represents the number of points in the FFT The function does not impose any special memory alignment require ments on
196. ce known to the user Device IDs are used globally across an application The data field is a pointer for any private data the device may need it is not used by the run time libraries The function pointed to by the init field is invoked by the run time library when the device is first registered It returns a nega tive value for failure positive value for success The functions pointed to by the open close write and read fields are the functions that provide the same functionality used in the default I O device Seek is another function at the same level for those devices which support such functionality If a device does not support an operation such as seeking writing on read only devices or reading write only devices then a function pointer must still be provided the function must arrange to always return failure codes when the operation is attempted A new device can be registered with the following call int add_devtab_entry DevEntry_t entry If the device is successfully registered the init routine of the device is called with entry as its parameter add_devtab_entry returns the DevicelD of the device registered VisualDSP 3 5 C C Compiler and Library Manual 1 167 for ADSP 219x DSPs C C Run Time Model and Environment If the device is not successfully registered a negative value is returned Reasons for failure include but are not limited to e The DevicelD is the same as another device already register
197. ce critical sum long aLil bLi lt lt 1 return sum Bad uses shifts to implement fractional multiplication This presents some problems to the optimizer Normally the code gener ated here would be a multiply followed by a shift followed by an accumulation However the DSP hardware has a fractional multiply accu mulate instruction that performs all these tasks in one cycle VisualDSP 3 5 C C Compiler and Library Manual 2 25 for ADSP 219x DSPs Using Built In Functions in Code Optimization In the example code the compiler recognizes this idiom and replaces the multiply followed by shift with a fractional multiply In more complicated cases where perhaps the multiply is further separated from the shift the compiler may not detect the possibility of using a fractional multiply The recommended coding style is to use built in functions In the follow ing example a builtin is used to multiply fractional 16 bit data dFinclude lt math h gt fract32 dot_product fractl6 a fractl6 b int ji fract32 sum 0 for i 0 1 lt 100 i this line is performance critical sum __ builtin _mult_frlx32 aLli bLil return sum Good uses builtins to implement fractional multiplication Note that the fract16 and fract32 types used in the example above are merely typedefs to C integer types used by convention in standard include files The compiler does not have any in built knowledge of the
198. character c The first n characters of s1 are set to c The memset function returns a pointer to s1 Error Conditions The memset function does not return an error condition Example include lt string h gt char stringl1 50 memset stringl 0 50 set stringl to 0 See Also memcpy 3 100 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library mode_change change selected system modes Synopsis include lt sysreg h gt void mode_change const int Description The mode_change function causes the compiler to emit instructions to enable and disable a series of modes using the zero latency mode control instructions The mode_change function takes as a parameter a constant integer bitmask that the compiler converts into a series of enable and disable mode settings The sysreg h include file defines each mode bit setting value as a sym bolic variable that can be used as a parameter to mode_change These definitions are ODE_ENA_AV_LATCH 0x1 ODE_ENA_AR_SAT 0x2 ODE_ENA_M_MODE 0x4 __MODE_ENA_TIMER 0x8 __MODE_ENA_INT 0x10 ODE_DIS_AV_LATCH 0x100 ODE_DIS_AR_SAT 0x200 ODE_DIS_M_MODE 0x400 __MODE_DIS_TIMER 0x800 ODE_DIS_INT 0x1000 The mode_change function is implemented as a compiler built in and the emitted instructions will be inlined at the point of mode_change use VisualDSP 3 5 C C Compiler and
199. clude the contents of frequently_changing_data h as it is included after the hdrstop pragma Therefore the precompiled header file would not need to be regenerated each time frequently_changing_data h was modified pragma no_pch The pragma no_pch overrides the pch precomiled headers switch on page 1 40 for a particular source file It directs the compiler not to look for a pch file and not to generate one for the specified source file VisualDSP 3 5 C C Compiler and Library Manual 1 137 for ADSP 219x DSPs C C Compiler Language Extensions pragma once The pragma once which should appear at the beginning of a header file tells the compiler that the header is written in such a way that including it several times has the same effect as including it once For example pragma once ifndef FILE_H define FILE_H contents of header file dFendif In this example the pragma once is actually optional because the compiler recognizes the i fndef define f endif idiom and will not reopen a header that uses it pragma system_header The pragma system_header identifies an include file as the file supplied with VisualDSP The pragma tells the compiler that every function and variable declared in the file but not in files included in the file is the vari able or function with that name from the VDSP library The compiler will take advantage of any special knowledge it has of the behavior of th
200. code to a file with a different filename and rename the function itself Test the function before you use it in your system to verify that it is functionally correct Analog Devices only supports the run time library functions as provided DSP Header Files The DSP header files contains prototypes for all the DSP library func tions When the appropriate include preprocessor command is included in your source the compiler will use the prototypes to check that each function is called with the correct arguments The DSP header files included in this release of the cc219x compiler are e complex h Basic Complex Arithmetic Functions on page 4 4 e filter h DSP Filters and Transformations on page 4 6 e math h Math Functions on page 4 10 e matrix h Matrix Functions on page 4 12 e stats h Statistical Functions on page 4 16 e vector h Vector Functions on page 4 17 e window h Window Generators on page 4 20 complex h Basic Complex Arithmetic Functions The complex h header file contains type definitions and basic arithmetic operations for variables of type complex_float complex_double and complex_fractl6 The complex functions defined in the complex h header file are listed in Table 4 1 on page 4 5 4 4 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs DSP Run Time Library The following structures are used to represent complex numbers i
201. const complex_fractl6 b int n int m complex_fractl6 c Complex void cmatmmlt const complex_double a int n int k Matrix Matrix const complex_double b int m complex_double c Multiplication void cmatmmltf const complex_float a int n int k const complex_float b int m complex_float c void cmatmmlt_frl6 const complex_fractl6 a int n int k const complex_fractl6 b int m complex_fractl6 c Transpose void transpm const double a int n int m double c void transpmf const float a int n int m float c void transpm_frl6 const fractl6 a int n int m fractl6 c VisualDSP 3 5 C C Compiler and Library Manual 4 15 for ADSP 219x DSPs DSP Run Time Library Guide stats h Statistical Functions Table 4 6 lists the statistical functions defined in the stats h header file that are described in DSP Run Time Library Reference on page 4 22 Table 4 6 Stats Functions Description Prototype Autocoherence void autocohf const float aL int n int m float c void autocoh_frl6 const fractl6 al J int n int m fractl6 c Autocorrelation void autocorrf const float al J int n int m float c void autocorr_frl6 const fractl6 aL J int n int m fractl6 c Cross coherence void crosscohf const float al J const float b J int n int m float c void crosscoh_frl6 const fractl6 a J const fractl6 bc
202. ction code so that it may be used as a self dispatching interrupt handler The compiler arranges for the function to save its context above and beyond the usual caller preserved set of registers and to restore the con text upon exit The function will return using a return from interrupt RTI instruction pragma interrupt void field_SIG ISR code pragma altregisters The altregisters pragma may be used in conjunction to the interrupt pragma to indicate that the compiler can optimize the saving and restoring of registers through use of the secondary register sets Note the use of the altregisters pragma is not safe when nested interrupts are enabled 1 122 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler For example tpragma interrupt pragma altregisters void field_SIG ISR code Loop Optimization Pragmas Loop optimization pragmas give the compiler additional information about usage within a particular loop which allows the compiler to per form more aggressive optimization The pragmas are placed before the loop statement and apply to the statement that immediately follows which must be a for while or do statement to have effect In general it is most effective to apply loop pragmas to inner most loops since the com piler can achieve the most savings there The optimizer always attempts to vectorize loops when it is safe to do so The optimizer exploi
203. ction elimination 2 29 seek operation 3 14 segment see placement support keyword segment selecting compilation tool 1 39 set jump see longjmp setjmp functions setjmp define runtime label function 3 111 setjmp label for external linkage function 3 111 setjmp long jump function 3 111 1 24 VisualDSP 3 0 C C Compiler and Library Manual for AD shared memory object ADSP 2192 12 processor 3 98 short form keywords disabling 1 34 enabling 1 26 show display command line compiler switch 1 44 shr operation 1 114 signal define signal handling function 3 112 signal handling 3 13 signals see clear_interrupt interruptf interrupts poll_flag_in raise signal functions signed bitfield make plain bitfields signed compiler switch 1 45 signed char make char signed compiler switch 1 45 silicon revision setting 1 44 simulator library support 3 7 sin sine function 3 116 sin_fr16 function 3 116 single case range 1 144 single threaded environment 3 6 sinh hyperbolic sine function 3 118 si revision silicon revision compiler switch 1 44 sizeof operator 1 144 source code DSP run time library 4 3 sourcefile parameter on command line 1 21 sqrt square root function 3 119 srand random number seed function 3 120 stack address direction 1 156 frame 1 155 free space 1 158 incoming arguments 1 157 local variables temporaries 1 157 outgoing arguments 1 158 saving return address 1 157 standard conf
204. ctions long latencies avoiding 2 24 longjmp second return from setjmp function 3 91 loop iteration count 2 35 optimization 1 123 2 35 parallel processing 1 124 short 2 17 unrolling 2 17 vectorizing 1 123 loop control automatic variables 2 21 variables 2 21 loop exit test 2 21 loop rotation by hand 2 18 loop carried dependency 2 18 lower case see islower tolower functions lvalue GCC generalized 1 141 generalized 1 141 M M generate make rules only compiler switch 1 32 macros and asm C program constructs 1 77 EDOM 3 12 ERANGE 3 12 HUGE_VAL 3 12 multi statement 1 150 predefined 1 147 undefining 1 47 variable argument 1 143 writing 1 149 malloc allocate memory function 3 93 map generate a memory map compiler switch 1 33 mathematical functions floating point 3 12 max maximum function 4 85 1 18 VisualDSP 3 0 C C Compiler and Library Manual for ADSP 219x DSPs INDEX maximum performance 2 29 MD make and compile compiler switch 1 32 mean mean function 4 86 mean mean array function 3 111 mem invoke memory initializer compiler switch 1 33 memchr find first occurrence of character function 3 94 memcmp compare objects function 3 95 memcpy copy characters from one object to another function 3 96 memcpy_to_shared function 3 98 memmove copy characters between overlapping objects function 3 99 memory allocation 3 110 assignments 1 80 data placement in 2 15 memory s
205. d C source files Additionally the switch enables the recognition of these alternative operator keywords in C source files Keyword Equivalent and amp amp and_eq amp bitand amp bitor comp not l not_eq l or or_eq xor xor_eq To use them in C you should use include lt iso646 h gt bss The bss switch causes the compiler to place global zero initialized data into a BSS style section called bsz rather than into the normal global data section This is default mode See also the no bss switch on page 1 33 VisualDSP 3 5 C C Compiler and Library Manual 1 23 for ADSP 219x DSPs Compiler Command Line Interface build lib The build 1ib build library switch directs the compiler to use el far librarian to produce a library file d1b as the output instead of using the linker to produce an executable file dxe The o option on page 1 38 must be used to specify the name of the resulting library C The C comments switch which is only active in combination with the E EE ED P or PP switches directs the preprocessor to retain com ments in its output C The c compile only switch directs the compiler to compile and or assemble the source files but stop before linking The output is an object file doj for each source file const read write The const read write switch directs the compiler to specify that con stants may be accessed as re
206. d allocation by the compiler Callee Preserved Registers Preserved Registers 12 13 17 M0 M2 and M4 are preserved A subroutine which uses any of these registers must save preserve it and restore it Dedicated Registers Certain registers have dedicated purposes and will not be used for other things Compiled code and libraries expect the dedicated registers to be correct Caller Save Registers Scratch All registers not preserved or dedicated are scratch A subroutine may use a scratch register without having to save it VisualDSP 3 5 C C Compiler and Library Manual 1 161 for ADSP 219x DSPs C C Run Time Model and Environment Circular Buffer Length Registers Registers LO through L7 are the circular buffer length registers The com piler assumes that these registers contain zero which disables circular buffering They must be set to zero when compiled code is executing to avoid incorrect behavior There is no restriction on the value of an L regis ter when the corresponding I register has been reserved from compiler use See reserve register register on page 1 43 for information on reserving registers Mode Status MSTAT Register The C runtime initializes the MSTAT register as part of the run time header code The compiler and run time libraries assume to be running in these preset modes If you change any of the modes listed in Table 1 13 ensure that they are reverted before calling C
207. d function inputs a vector of 8 bit compressed speech sam ples and expands them according to ITU recommendation G 711 Each input value is expanded to a linear 14 bit signed sample in accordance with the p law definition and is returned in the vector pointed to out Algorithm C k mu_law expansion of A k for k 0 to n 1 Domain Content of input array 0 to 255 VisualDSP 3 5 C C Compiler and Library Manual 4 89 for ADSP 219x DSPs DSP Run Time Library Reference norm normalization Synopsis include lt complex h gt complex_float normf complex_float a complex_double norm complex_double a Description This function normalizes the complex input a and returns the result Algorithm z Re a Reto JRe a Im a Im a I oe Re a Im a Domain 3 4 x 1038 to 3 4 x 1038 for normf 4 90 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs DSP Run Time Library polar construct from polar coordinates Synopsis include lt complex h gt complex_float polarf float magnitude float phase complex_double polar double magnitude double phase complex_fractl6 polar_frl6 fractl6 magnitude fractl6 phase Description This function transforms the polar coordinate specified by the arguments magnitude and phase into a Cartesian coordinate and returns the result as a complex number in which the x axis is represented by the real part and the y axis by the imagin
208. d int 16 bit unsigned integer Double Word Fixed Point Data Types Emulated Arithmetic long 32 bit signed integer unsigned long 32 bit unsigned integer Floating Point Data Types Emulated Arithmetic double 32 bit float float 32 bit float Fractional data types are represented using the integer types Manipula tion of these is best done by use of built in functions described in System Support Built In Functions on page 2 26 VisualDSP 3 5 C C Compiler and Library Manual 2 7 for ADSP 219x DSPs General Guidelines Avoiding Emulated Arithmetic Arithmetic operations for some types are implemented by library func tions because the DSP hardware does not directly support these types Consequently operations for these types are far slower than native opera tions sometimes by a factor of a hundred and also produce larger code These types are marked as Emulated Arithmetic in Data Types on page 2 7 The hardware does not provide direct support for division so division and modulus operations are almost always multi cycle operations even on integral type inputs If the compiler has to issue a full division operation it will usually need to generate a call to a library function One notable sit uation in which a library call is avoided is for integer division when the divisor is a compile time constant and is a power of two In that case the compiler generates a
209. data but there are three aspects of the result that are normally treated differently 1 MSB extraction Multiplication is a widening operation thus mul tiplying a 16 bit value by another 16 bit value produces a 32 bit result If a 16 bit integer result is required then this is taken to be the least significant 16 bits of the result and the upper 16 bits are regarded as overflow For a fractional operation the upper 16 bits would represent a 16 bit result and the lower 16 bits would be regarded as an underflow 2 Duplicate sign bit elimination Following a multiplication of two 16 bit values the nature of the representation results in two sign bits in the result For normal integer arithmetic this causes no problem but for fractional arithmetic a shift left by one is required to normalize the result 3 Saturation If we perform an arithmetic operation that would cause us to overflow it can be useful to return the maximum appropri ately signed number that can be represented in the result register The alternatives which include firing an interrupt saying the result is undefined and is some other number usually look less attractive to DSP programmers These fractional operations can often be done at no extra cost to normal integer operations on DSPs using special instructions or modes of operation VisualDSP 3 5 C C Compiler and Library Manual 1 107 for ADSP 219x DSPs C C Compiler Language Extensions The C pr
210. decimate in frequency by the radix 4 FFT algorithm The size of the input array in the output array out and the temporary working buffer t is n where n represents the number of points in the FFT The function does not impose any special memory alignment require ments on the arrays However benefits in run time performance will be realized if the output array is allocated on an address boundary that is a multiple of twice the FFT size If the input data can be overwritten then optimum memory usage can be achieved by specifying the input array as either the output array or as the temporary array Specifying the input array as the temporary array will also result in increased run time performance 4 38 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs DSP Run Time Library The twiddle table is passed in the argument w which must contain at least 34n twiddle coefficients The function twidfftrad4_fr16 may be used to initialize the array If the twiddle table contains more coefficients than needed for a particular call on cfftrad4_fr16 then the stride factor has to be set appropriately otherwise it should be one The argument scale_method controls how the function should scale the output to avoid overflow If no scaling is selected by setting scale_method to zero then the input signal should be sufficiently conditioned to avoid overflow The block_exponent argument will be set to zero The function will perform sta
211. depends on the source input files and the compiler options used Source files contain the C C program to be processed by the compiler The cc219x compiler supports the ANSI ISO standard definitions of the C and C languages For information on the C language standard see 1 2 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler any of the many reference texts on the C language Analog Devices recom mends the Bjarne Stroustrup text The C Programming Language from Addison Wesley Longman Publishing Co ISBN 0201889544 1997 as a reference text for the C programming language The cc219x compiler supports the proposed Embedded C Standard The Embedded C Standard defines a subset of the full ISO IEC 14882 1998 C language standard The proposal excludes features that can detract from compiler performance in embedded systems such as exception handling and run time type identification In addition to the embedded C standard features cc219x supports the proposed standard definition templates and all other features of the full C standard except for the exception handling and run time type identifications The additional supported features provide extra functionality without degrad ing the compiler performance The cc219x compiler supports a set of C C language extensions These extensions support hardware features of the ADSP 219x DSPs For infor mation on these extensions see C C
212. dged C Library overview 3 2 support 3 16 abs absolute value function 3 28 acos arc cosine function 3 29 acos_fr16 function 3 29 activation record 1 155 ADSP 2192 12 processor shared memory object 3 98 ageregate constructor expression support 1 89 alias avoiding 2 10 align num pragma 1 121 alignment inquiry keyword 1 145 allocate memory see calloc free malloc realloc functions alphanumeric character test see isalnum function altregisters pragma 1 122 alttok alternative tokens C mode compiler switch 1 23 anach enable C anachronisms compiler switch 1 52 anachronisms default C mode 1 52 disabling in C mode 1 53 ANSI standard 3 1 compiler 1 26 ANSI ISO standard C 1 21 anti log base 10 function 4 26 anti log function 4 25 arg get phase of complex number function 4 27 arithmetic saturated 1 93 array variable length 1 85 1 143 2 VisualDSP 3 0 C C Compiler and Library Manual for ADSP 219x DSPs INDEX array length 1 86 array search binary see bsearch function arrays zero length 1 143 ASCII string see atof atoi atol functions asin arc sine function 3 30 asin_fr16 function 3 30 asm compiler keyword 1 60 keyword for specifying names in generated assembler 1 145 statement 1 144 2 14 asm compiler keyword see also Inline assembly language support keyword asm asm construct reordering 1 75 constructs flow control 1 77 operand constraints 1 71 assembly constr
213. digits A hexadecimal floating point number may start with an optional plus or minus followed by the hexadecimal prefix 0x or 0X This character sequence must be followed by one or more hexadecimal characters that optionally contain a decimal point 3 136 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library The hexadecimal digits are followed by a binary exponent that consists of the letter p or P an optional sign and a non empty sequence of decimal digits The exponent is interpreted as a power of two that is used to scale the fraction represented by the tokens hexdigs hexdigs The first character that does not fit either form of number will stop the scan If endptr is not NULL a pointer to the character that stopped the scan is stored at the location pointed to by endptr If no conversion can be performed the value of nptr is stored at the location pointed to by endptr Error Conditions The strtod function returns a zero if no conversion can be made and a pointer to the invalid string is stored in the object pointed to by endptr If the correct value results in an overflow a positive or negative as appropri ate HUGE_VAL is returned If the correct value results in an underflow 0 is returned The ERANGE value is stored in errno in the case of either an over flow or underflow Example include lt stdlib h gt char re double dd dd strtod 2345 5E4 a
214. double logl0 double float logl0f float Description The 10g10 function returns the base 10 logarithm of its input Error Conditions The 10g10 function indicates a domain error sets errno to EDOM and returns a zero if the input is negative Example include lt math h gt double y y 1og10 100 0 y 2 0 See Also alog10 log pow 3 90 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library longjmp second return from set jmp Synopsis include lt setjmp h gt void longjmp jmp_buf env int return_val Description The longjmp function causes the program to execute a second return from the place where set jmp env was called with the same jmp_buf argument The longjmp function takes as its arguments a jump buffer that contains the context at the time of the original call to set jmp It also takes an inte ger return_val which set jmp returns if return_val is non zero Otherwise set jmp returns a 1 If env was not initialized through a previous call to set jmp or the function that called set jmp has since returned the behavior is undefined Also automatic variables that are local to the original function calling set jmp that do not have volatile qualified type and that have changed their value prior to the longjmp call have indeterminate value Error Conditions The longjmp function does not return an error condition Example include lt s
215. dynamic scaling the function will inspect the intermediate results and will only scale to avoid overflow Dynamic scaling therefore mini mizes loss of precision but at the possible cost of slightly reduced performance The block_exponent argument will be set to a value between 0 which indicates that no scaling was performed and 10g2 n as if static scaling was performed Algorithm roe i S xa k 0 The implementation uses core FFT functions To get the inverse effect it first swaps the real and imaginary parts of the input performs the direct radix 2 transformation and finally swaps the real and imaginary parts of the output Domain Input sequence length n must be a power of two and at least 16 4 78 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs DSP Run Time Library ifftrad4 N point inverse FFT Synopsis include lt filter h gt void ifftrad4_frl6 in tl out wl wst n block_exponent scale_method const complex_fractl6 in input sequence cai complex_fractl6 tl temporary working buffer x complex_fractl6 out output sequence const complex_fractl6 wl twiddle sequence oh int wst twiddle factor stride aif int n number of FFT points K int block_exponent block exponent of output data int scale method scaling method desired O none l static 2 dynamic Xi Description This function transforms the frequency domain complex input signal
216. e ent cc219x C C struct Initializer With ements nt x ysts i nt p y yvalue x xvalue Aggregate Constructor Expression Support Extended initializer support in cc219x C C includes support for aggre gate constructor expressions These expressions enable you to assign values to large structure types without requiring each element s value to be indi vidually assigned The following example shows an ISO ANSI standard struct usage fol lowed by equivalent cc219x code that has been simplified using an constructor expression VisualDSP 3 5 C C Compiler and Library Manual 1 89 for ADSP 219x DSPs C C Compiler Language Extensions Standard struct amp cc219x C C Constructor struct Standard struct struct foo int a char bL2 struct foo make_foo int x char s struct foo temp temp a xX temp b 0 s 0 if ESTON 0 temp b 1 s 1 else temp b 1 0 return temp Equivalent cc219x C C constructor struct struct foo make_foo int x char s return struct foo x s 0 s 0 s 1 0 Fractional Type Support While in C mode the cc219x compiler supports fractional fixed point arithmetic that provides a way of computing with non integral values within the confines of the fixed point representation The representation on which the fractional support is based is that of a 16 bit integral type In this releas
217. e 0 switch H The H list headers switch directs the compiler to output only a list of the files included by the preprocessor via the include directive without compiling The o switch on page 1 38 may be used to specify the redi rection of the list to a file HH The HH list headers and compile switch directs the compiler to print to the standard output file stream a list of the files included by the preproces sor via the include directive After preprocessing compilation proceeds normally 1 28 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler h elp The help command line help switch directs the compiler to output a list of command line switches with a brief syntax description J The 1 start include directory list switch establishes the point in the include directory list at which the search for header files enclosed in angle brackets should begin Normally for header files enclosed in double quotes the compiler searches in the directory containing the current input file then the compiler reverts back to looking in the directories specified with the I switch and then in the standard include directory For header files in angle brackets the compiler performs the latter two searches only It is possible to replace the initial search within the directory containing the current input file by placing the 1 switch at the point on the com mand line where the search fo
218. e I directory switch on page 1 29 and L directory switch on page 1 31 When you provide an input or output file name as an optional parameter use the following guidelines e Use a file name include the file extension with either an unambig uous relative path or an absolute path A file name with an absolute path includes the drive directory file name and file extension Enclose long file names within straight quotes for example long file name c The cc219x compiler uses the file extension conven tions listed in Table 1 2 to determine the input file type e Verify that the compiler is using the correct file If you do not pro vide the complete file path as part of the parameter or add additional search directories cc219x looks for input in the current directory Using the verbose output switches for the preprocessor compiler assembler and linker causes each of these tools to echo the name of each file as it is processed VisualDSP 3 5 C C Compiler and Library Manual 1 9 for ADSP 219x DSPs Compiler Command Line Interface Table 1 2 Input and Output Files Input File File Extension Description Extension ae C C source file CC CPPp CXX C source file wh Header file referenced by a Finclude statement pch C pre compiled header file onl Preprocessed C C source created when preprocess only E compiler switch is specified ipa opa Interprocedural ana
219. e address as any store to out Therefore a i or bli is never an alias for out il Using the no_alias pragma can lead to better code because it allows the loads and stores to be reordered and any number of iterations to be per formed concurrently thus providing better software pipelining by the optimizer General Optimization Pragmas There are three pragmas which can change the optimization level while a given module is being compiled These pragmas must be used at global scope immediately prior to a function definition The pragmas do not just apply to the immediately following function they remain in effect until the end of the compilation or until superceded by a following optimize_ pragma The pragmas are e pragma optimize_off This pragma turns off the optimizer if it was enabled This pragma has no effect if IPA is enabled VisualDSP 3 5 C C Compiler and Library Manual 1 125 for ADSP 219x DSPs C C Compiler Language Extensions pragma optimize_for_space This pragma turns the optimizer back on if it was disabled or sets focus to give reduced code size a higher priority than high perfor mance where these conflict pragma optimize_for_speed This pragma turns the optimizer back on if it was disabled or sets focus to give high performance a higher priority than reduced code size where these conflict pragma optimize_as_cmd_line This pragma resets the optimization settings to be those specified
220. e information that must be preserved and restored e arguments passed to the current procedure In addition if this is not a leaf procedure if it is going to call other proce dures its stack frame also contains outgoing linkage and parameter space e space for the arguments to the called procedure e space for the callee to save basic linkage information Figure 1 3 provides a general overview of the stack Note that the stack grows downward on the page Because the stacks grow towards smaller addresses higher addresses are found in the upwards direction Stack Frame Description on page 1 157 Incoming Arguments Linkage lt FP Information Linkage Information and Temporaries Save Area for caller info Outgoing Arguments Free Space lt sp Figure 1 3 ADSP 219x DSP Stack The stack resides in primary Data Memory DM It is controlled by a pair of pointers a Stack Pointer SP which identifies the boundary of the in use portion of the stack space and a Frame Pointer FP which pro vides stable addressing to the current frame 1 156 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler For increased efficiency the ADSP 219x DSP run time model assumes 32 words past the stack pointer are available for use within a leaf function functions that make no calls and are protected from changes by an inter rupt handler This provides easy access to temporary
221. e library GCC Compatibility Extensions The compiler provides compatibility with the C dialect accepted by ver sion 3 2 of the GNU C Compiler Many of these features are available in the C99 ANSI Standard A brief description of the extensions is included in this section For more information refer to the following web address http gcc gnu org onlinedocs gcc 3 2 1 gcc C Extensions html C 20Extensions 1 138 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler Statement Expressions A statement expression is a compound statement enclosed in parentheses A compound statement itself is enclosed in braces so this construct is enclosed in parentheses brace pairs The value computed by a statement expression is the value of the last statement which should be an expression statement The statement expres sion may be used where expressions of its result type may be used But they are not allowed in constant expressions Statement expressions are useful in the definition of macros as they allow the declaration of variables local to the macro In the following example define min a b d short __x a __y b __res ifea Dy RES SaaS else _ res _xX res int use_min return min foo thing 2 The foo and thing statements get called once each because they are assigned to the variables __x and __y which are local to the statement expression that
222. e of the compiler there is no underlying C support for 32 bit fractional arithmetic The ADSP 219x processors provide hardware sup port for the 16 bit fractional arithmetic Fractional values are declared with the fract data type Ensure that your program includes the fract header file fract is a C class that supports a set of standard arithmetic operators used in arithmetic expressions Frac tional values are represented as signed values in a range of 1 1 witha 1 90 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler binary point immediately after the sign bit Other value ranges are obtained by scaling or shifting In addition to the arithmetic assignment and shift operations fract provides several type conversion operations For more information about supported fractional arithmetic operators see Fractional Arithmetic Operations on page 1 92 For sample programs demonstrating the use of the fract type see Listing 1 1 on page 1 177 Listing 1 2 on page 1 178 and Listing 1 3 on page 1 178 The current release of the software does not provide for automatic scaling of fractional values Format of Fractional Literals Fractional literals use the floating point representation with an r suffix to distinguish them from floating point literals for example 0 5r The cc219x compiler validates fractional literal values at run time to ensure they reside within the valid range of values
223. e richness of expression available in C Examples of features that may degrade performance are virtual functions or using classes to implement basic data types This section contains e How the Compiler Can Help on page 2 4 e Data Types on page 2 7 e Getting the Most from IPA on page 2 9 VisualDSP 3 5 C C Compiler and Library Manual 2 3 for ADSP 219x DSPs General Guidelines e Indexed Arrays vs Pointers on page 2 12 e Function Inlining on page 2 13 e Using Inline asm Statements on page 2 14 e Memory Usage on page 2 15 How the Compiler Can Help The compiler provides many facilities designed to help the programmer Using the Compiler Optimizer There is a vast difference in performance between code compiled opti mized and code compiled non optimized In some cases optimized code can run ten or twenty times faster Optimization should always be used when measuring performance or shipping code as product The optimizer in the C C compiler is designed to generate efficient code from source that has been written in a straightforward manner The basic strategy for tuning a program is to present the algorithm in a way that gives the optimizer excellent visibility of the operations and data and hence the greatest freedom to safely manipulate the code Future releases of the compiler will continue to enhance the optimizer and expressing algorithms simply will provide the best chance of
224. e sj int n number of FFT points a int block_exponent block exponent of output data Kif int scale method scaling method desired O none l static 2 dynamic Description This function computes a two dimensional Inverse Fast Fourier Trans form of the complex input matrix a n n and stores the result to the complex output matrix c n n The size of the input array in the output array out and the temporary working buffer t is n n where n represents the number of points in the FFT The function does not impose any special memory alignment requirements on the arrays However benefits in run time performance will be realized if the output array is allocated on an address boundary that is multiple of twice the FFT size If the input data can be overwritten then optimum memory usage can be achieved by specifying the input array as the output array VisualDSP 3 5 C C Compiler and Library Manual 4 81 for ADSP 219x DSPs DSP Run Time Library Reference The twiddle table is passed in the argument w which must contain at least n 2 twiddle factors The function twidfft2d_fr16 may be used to initial ize the array If the twiddle table contains more factors than needed for a particular call on if ft2d_fr16 then the stride factor has to be set appro priately otherwise it should be 1 The arguments block_exponent and scale_method have been added for future expansion However the current version of the function ignores the
225. e source code The amount of auto inlining the compiler performs is controlled using the 0v optimize for speed versus size switch on page 1 38 Therefore use of 0v100 indicates that as many functions as possible will be auto inlined whereas 0v0 prevents any function from being auto inlined Specifying 0a also implies the use of 0 When remarks are enabled the compiler will produce a remark to indicate each function that is inlined Os The 0s optimize for size switch directs the compiler to produce code that is optimized for size This is achieved by performing all optimizations except those that increase code size The optimizations not performed include loop unrolling some delay slot filling and jump avoidance The compiler also uses a function to save and restore preserved registers for a function instead of generating the more cycle efficient inline default versions VisualDSP 3 5 C C Compiler and Library Manual 1 37 for ADSP 219x DSPs Compiler Command Line Interface Ov num The Ov num optimize for speed versus size switch directs the compiler to produce code that is optimized for speed versus size The num should be an integer between 0 purely size and 100 purely speed o filename The o output file switch directs the compiler to use filename for the name of the final output file oldasmcall csp 8x The oldasmcall csp 8x switch changes the operation of the OldAsmCall linkage specifi
226. e source code for functions and macros in the ETSI library is provided with your VisualDSP software By default the installation program copies the source code to a subdirectory of the directory where the run time libraries are kept named 219x 1ib src libetsi_src Each func tion is kept in a separate file The file name is the name of the function with the extension asm If you do not intend to modify any of the func tions you can delete this directory and its contents to conserve disk space The source code is provided so you can customize specific functions for your own needs To modify these files you need proficiency in ADSP 219x assembly lan guage and an understanding of the run time environment as explained in C C and Assembly Language Interface on page 1 169 Before you make any modifications to the source code copy the source code to a file with a different file name and rename the function itself Test the function before you use it in your system to verify that it is func tionally correct Analog Devices only supports the run time library functions as provided ETSI Support for Data Types ETSI functions support fract16 and fract32 data types as follows e fract16 is a 16 bit fractional data type 1 15 format having a range of 1 0 1 0 This is defined in the C C language as typedef short fractl6 1 110 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler e fract32 is a
227. e transformed string into the string pointed to by s1 The resultant string will include the terminating null character The function returns the length of the transformed string not including the terminating null character If n is zero and s1 is set to the null pointer then strxfrm will return the number of characters required for the transformed string Overlapping strings are not supported The transformation is such that strcmp will return the same result for two transformed strings as strcol would for the same original strings However because only the C locale is defined in the ADSP 219x DSP environment the strxfrm function is similar to the strncpy function except that the null character is always appended at the end of the output string Error Conditions The strxfrm function does not return an error condition Example include lt string h gt char stringl1 50 3 146 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library strxfrm stringl SOMEFUN 49 SOMEFUN is copied into stringl See Also strcmp strcoll strncpy VisualDSP 3 5 C C Compiler and Library Manual 3 147 for ADSP 219x DSPs C Run Time Library Reference sysreg read read from non memory mapped register Synopsis include lt sysreg h gt int sysreg_read const int Description The sysreg_read function causes the compiler to emit instructions to read the non memory mapped register
228. e warnings for any con structs in a C or C source file that does not conform to the ANSI standard W lt error remark suppress warn gt lt num gt num Overrides the severity of specific compilation diagnos tic messages where num is the number representing the message to override The Release 6 1 warning switches that are no longer supported are listed in Table A 3 on page A 8 Table A 3 C Compiler Obsolete Warning Switches Wall Wformat Wswitch Wchar subsripts Wimplictit Wtrigraphs Wcomment Wparentheses Wuninitialized Werror Wreturn type Wunused A 8 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler Legacy Support See Compiler Command Line Switches on page 1 12 for further infor mation on the compiler s switch set Run Time Model The cc219x compiler in VisualDSP 3 5 produces code that is not fully compatible with the Release 6 1 run time model VisualDSP 3 5 has significant changes in the registers and stack usage These changes are especially important if you call an assembly language subroutine from a C C program or a C C function from an assembly language pro gram For more information about the VisualDSP 3 5 run time model see C C Run Time Model and Environment on page 1 153 C C Run Time Library This release includes a set of documented ANSI standard routines that you can call from
229. ecessary mem The mem invoke memory initializer switch causes the compiler to invoke the Memory Initializer tool after linking the executable The MemInit tool can be controlled through the f1ags mem switch on page 1 27 no alttok The no alttok disable alternative tokens switch directs the compiler to not accept alternative operator keywords and digraph sequences in the source files This is the default mode For more information see the alttok switch on page 1 23 no bss The no bss switch causes the compiler to keep zero initialized and non zero initialized data in the same data section rather than separating zero initialized data into a different BSS style section See also the bss switch on page 1 23 VisualDSP 3 5 C C Compiler and Library Manual 1 33 for ADSP 219x DSPs Compiler Command Line Interface no builtin The no builtin no builtin functions switch directs the compiler to rec ognize only built in functions that begin with two underscores __ Note that this switch influences many functions This switch also predefines the __NO_BUILTIN preprocessor macro For more information on built in func tions see Compiler Built In Functions on page 1 94 no circbuf The no circbuf no circular buffer switch directs the compiler not to define any default preprocessor macros include directories library direc tories libraries or run time headers It also disables the Analog Devices C
230. ection Definition in the LDF file can place this section in RAM or ROM assembler generated code imacros Process macro file Removed MD and MMD Output rules for the make Removed utility used with E mboot page Specify boot page Removed The ADSP 219x processors do not support paging mdmdata Specify target architecture file Removed mpmdata segments You can control placement of mdcode object file segments using the SECTIONS command in the LDF file mlistm Merge C code with Removed VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler Legacy Support Table A 1 C C Compiler Obsolete and Replaced Switches Cont d Release 6 1Switch Operation under Release 6 1 Change for VisualDSP 3 5 mno doloops Do not generate loop struc tures in assembled code Removed The compiler only generates do loop control structures when it is safe to do so and the compiler is generating optimized code 0 Os Interrupt handling routines should save and restore the loop stack if they are to use the same construct to avoid overflowing the loop stacks module mno inits Do not initialize variables in Removed assembled code mpjump Place the jump table in pm Removed memory mreserved Instructs the compiler not to Replaced with reserve use specified registers see on page 1 43 mrom Make the module a RO
231. ed e There are no more spaces left in the device registry table e The DeviceID is less than zero e Some of the function pointers are NULL e The device s init routine returned a failure result Once a device is registered it can be made the default device using the following function void set_default_io_device int The user passes the DeviceID There is a corresponding function for retrieving the current default device int get_default_io_device void The default device is used by fopen when a file is first opened The fopen function passes the open request to the open function of the device indicated by get_default_io_device The device file identifier dfid returned by the open function is private to the device other devices may simultaneously have other files open which use the same iden tifier An open file is uniquely identified by the combination of DeviceID and dfid The fopen function records the DeviceID and dfid in the global open file table and allocates its own internal fid to this combination All future operations on the file reads writes seeks and close use this fid to retrieve the Device D and thus direct the request to the appropriate device s primitive functions passing the dfid along with other parameters Once a file has been opened by fopen the current value of get_default_io_device is irrelevant to that file 1 168 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219
232. ed through the C function _prim10 The assembly label has two under scores __priml10 The _prim10 function accepts no arguments Instead it examines the I O control block at label _primI0CB Without external intervention by a host environment the _prim10 routine simply returns which indicates failure of the request When the host environment is providing I O support the host places a breakpoint at the start of _prim10 Upon entry to _prim10 the data for the request will reside in a control block at the label _prim1ocB The host arranges to intercept control when it enters the _primI0 routine and after servicing the request returns control to the calling routine See File I O Support on page 1 166 for more information 3 14 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library At program termination the host environment will close down any physi cal connection between the application and an opened file However the T O library will not implicitly close any opened streams to avoid an unnec essary overheads particularly with respect to memory occupancy Therefore unless explicit action is taken by an application any unflushed output may be lost Any output generated by printf is always flushed but output generated by other library functions such as putchar fwrite fprintf will not be automatically flushed Applications should therefore arrange to close down any streams t
233. ed with a leading double underscore __ Unless the no extra keywords command line switch is used the compiler defines the shorter forms of the keyword extension that omits the leading underscores See extra keywords on page 1 26 for more information This section describes only the shorter forms of the keyword extensions but in most cases you can use either form in your code For example all references to the inline keyword in this text appear without the leading double underscores but you can use inline or __inline interchangeably in your code You might need to use the longer forms such as __inline exclusively if you are porting a program that uses the extra Analog Devices keywords as identifiers For example a program might declare local variables such as pm or dm In this case you should use the no extra keywords switch and if you need to declare a function as inline or allocate variables to memory spaces you can use __inline or __pm __dm respectively Table 1 7 provides a list and a brief description of keyword extensions Table 1 8 provides a list and a brief description of operational extensions Both tables direct you to sections of this chapter that document each extension in more detail Table 1 7 Keyword Extensions Keyword extensions Description inline function Directs the compiler to integrate the function code into the code of the callers For more information see Inline Function Support Key
234. edefined Preprocessor Macros The cc219x compiler defines a number of macros to produce information about the compiler source file and options specified These macros can be tested using the ifdef and related directives to support your pro gram s needs Similar tailoring is done in the system header files Macros such as __DATE__ can be useful to incorporate in text strings The operator with a macro body is useful in converting such symbols into text constructs Table 1 12 describes the predefined preprocessor macros VisualDSP 3 5 C C Compiler and Library Manual 1 147 for ADSP 219x DSPs Preprocessor Features Table 1 12 Predefined Macro Listing Macro Function __ADSP21XX__ Always defines __ADSP21XX__ and __ADSP219X__as 1 ADSP2191__ Defines __ADSP2191__ as 1 when you compile with the proc ADSP 2191 command line switch ADSP2192_12__ Defines __ADSP2192_12__ as 1 when you compile with the proc ADSP 2192 12 command line switch DOUBLES_ARE_FLOATS ECC EDG__ __ANALOG_EXTENSIONS__ Defines ___ANALOG_EXTENSIONS__ as 1 unless you compile with pedantic or pedantic errors __cplusplus Defines __cplusplus as 199711L when compiling in C mode DATE__ The preprocessor expands this macro into the current date as a string constant The date string constant takes the form mm dd yyyy ANSI standard Always defines __DOUBLES_ARE_FLOATS__as 1 Always defines __ECC__as 1
235. ee calloc free malloc memcmp memcpy memset memmove memchar realloc functions memory initializer 1 33 1 35 1 39 memory keywords 1 80 and function arguments 1 82 and function declarations pointers 1 81 and macros 1 82 memset set range of memory to a character function 3 100 min minimum function 4 87 minimum code size 2 29 missing operands in conditional expressions 1 142 mixed C assembly programming asm constructs 1 64 mixed C assembly naming conventions 1 174 mixed C assembly programming asm constructs 1 63 1 64 1 68 1 74 1 75 1 77 mixed C C assembly programming 1 153 mixed C C assembly reference 1 172 MM generate make rules and compile compiler switch 1 32 Mo processor output file compiler switch 1 32 mode control instructions 1 99 mode_change change selected system modes function 3 101 modf separate integral and fractional parts function 3 103 move memory range see memmove function MQ compiler switch 1 33 MSTAT mode status register 1 162 Mt filename output make rule compiler switch 1 32 mu_compress 1 law compression function 4 88 1 19 VisualDSP 3 0 C C Compiler and Library Manual for ADSP 219x DSPs INDEX mu_expand p law expansion function 4 89 multidimensional arrays 1 86 multi line asm C program constructs 1 74 multiple instructions constructs with 1 74 multi statement macros 1 150 multi threaded environment 3 6 N N point complex input FFT
236. em register bits These symbolic names can be used in programs to access specific system registers and sys tem register bits in the ADSP 2191 DSP def2192 12 h Memory Map Definitions The def2192 12 h header file contains macro definitions for the ADSP 2191 12 processor s system addresses and system register bits These symbolic names can be used in programs to access specific system registers and system register bits in the ADSP 2191 12 DSP def219x h Memory Map Definitions The def219x h header file contains macro definitions for a ADSP 219x processor s system addresses and system register bits These symbolic names can be used in programs to access specific system registers and sys tem register bits in ADSP 219x DSPs errno h The errno h header file provides access to errno This facility is not in general supported by the rest of the library float h The float h file defines the format of floating point data types The FLT_ROUNDS macro defined in the header file is set to the C run time environment definition of the rounding mode for float variables which is round towards nearest 3 10 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library iso646 h The is0646 h header file defines symbolic names for certain C operators the symbolic names and their associated value are shown in Table 3 3 Table 3 3 Symbolic Names Defined in iso646 h
237. emonstrates its use appears under C Programming Examples on page 1 176 fstream The fstream header defines the filebuf ifstream and ofstream classes for external file manipulations iomanip The iomanip header declares several iostream manipulators Each manip ulator accepts a single argument ios The ios header defines several classes and functions for basic iostream manipulations Most of the iostream header files include ios iosfwd The iosfwd header declares forward references to various iostream tem plate classes defined in other standard headers VisualDSP 3 5 C C Compiler and Library Manual 3 17 for ADSP 219x DSPs C and C Run Time Library Guide iostream The iostream header declares most of the iostream objects used for the standard stream manipulations istream The istream header defines the istream class for iostream extractions Most of the iostream header files include istream new The new header declares several classes and functions for memory alloca tions and deallocations ostream The ostream header defines the ostream class for iostream insertions sstream The sstream header defines the stringbuf istringstream and ostringstream classes for various string object manipulations stdexcept The stdexcept header defines a variety of classes for exception reporting streambuf The streambuf header defines the streambuf classes for basic operations of the io
238. en eee 4 31 Cartesian paorutaiia nikt a a a eek 4 32 lt 0 RE AA EA NAA A AE E E erat AEA EE E ae 4 34 CERI r a N 4 35 GE areren ae ER 4 36 EE EAE ee Oe R N 4 38 GL sce ere N A ERARA 4 40 GT ainchicks wha inen as etd abet dechiceneibet alanine ehenneaanl 4 42 Pll ET E A E ee eee 4 44 2 sg Cee EE Be OE Peep E Ree Re Pe ri OE 4 45 CO eS eer a cal ea a 4 46 RINE siinne A N RRO 4 47 oe E rE eer weer eS ne ey 4 49 CONTLOIRS ETT A E A E EENE AE E 4 50 COREE aroia rari i 4 51 A E E EAE E E E E A T NE 4 52 COMA Erorr IEO 4 53 ESITO Sane ne ee N E A RN 4 54 EL neem RCE A E 4 55 SN AA E E EA P E gu A A AA AEE 4 56 E rer erie ne E A E E E E rer A 4 57 VisualDSP 3 5 C C Compiler and Library Manual XXV for ADSP 219x DSPs Pe decia orane E ERT 4 59 TE EN TE N E A N E A T 4 61 sen barile eano AE 4 63 a a E E E E A E E E 4 65 R E I E E E E T E 4 66 pen TRIAS aen N 4 67 pen Re dorsenin 4 68 a i EE E A AEA E E A E E diane 4 69 a A E E E E E E 4 70 Sen PA s area 4 71 AE T E E E E E E E E E 4 72 sen Von DANT cern N 4 74 E E E E E E E E 4 75 a E E E T AE EE A Tes 4 77 T E A N E E EE dea E E 4 79 E E A A A T T 4 81 UF r E E E E E TE E ENEN 4 83 TOOT P E E E E E E 4 85 IOGAN ee eee 4 86 LA EEA P E E A A A Rim mnaK 4 87 WUES a ERN EEA 4 88 DU ED 1 anai TRE ay CP Rr Te Rr entre nner EoVRr renner err 4 89 PO csincasiiioieianin aia nvanine 4 90 hE ae ee tee ae gE E E E oN Pear E err 4 9 xxvi VisualDSP 3 5 C C Compiler and Librar
239. ents the number of points in the FFT The function does not impose any special memory alignment require ments on the arrays However benefits in run time performance will be realized if the output array is allocated on an address boundary that is multiple of twice the FFT size If the input data can be overwritten then optimum memory usage can be achieved by specifying the input array as the output array The twiddle table is passed in the argument w which must contain at least n 2 twiddle coefficients The function twidfftrad2_fr16 may be used to initialize the array If the twiddle table contains more coefficients than needed for a particular call on ifft_fr16 then the stride factor has to be set appropriately otherwise it should be 1 VisualDSP 3 5 C C Compiler and Library Manual 4 77 for ADSP 219x DSPs DSP Run Time Library Reference The argument scale_method controls how the function should scale the output to avoid overflow If no scaling is selected by setting scale_method to zero then the input signal should be sufficiently conditioned to avoid overflow The block_exponent argument will be set to zero The function will perform static scaling if scale_method is set to 1 For static scaling the function will scale intermediate results to prevent over flow The final output will be scaled by 1 n and block_exponent will be set to log2 n If scale_method is set to 2 then the function will select dynamic scaling Under
240. er The following listings show a code segment with variables in different memory spaces being assigned and a code segment with illegal mixing of memory space assignments Legal Dual Memory Space Variable Assignment Example int pm x int dm y X y Legal code Illegal Dual Memory Space Type Cast Example 1 80 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs int pm x int dm y int dm a x y Compiler will x amp a Compiler will flag error flag error Compiler Memory Keywords and Function Declarations Pointers Functions always reside in program memory Pointers to functions always point to PM The following listing shows some example function declara tions with pointers Dual Memory Support ers Syntax Examples int y Pe int pm y es int dm y Le inta pm Fy Cp of func tion y resi pm and returns poin which resi func ter to tion y an i des i resi pm and returns poin which resi func ter to tion y an i des i resi pm and returns poin which resi func ter to tion y an 1 in des resi q q q pm and returns a poin residing poin ts to es in teger dm es in teger pm es in teger dm es in ter to a pointer in pm that an integer which resides
241. er Language Extensions Conditional Expressions with Missing Operands The middle operand of a conditional operator can be left out If the con dition is non zero true then the condition itself is the result of the expression This can be used for testing and substituting a different value when a pointer is NULL The condition is only evaluated once therefore repeated side effects can be avoided For example printf name s n lookup key calls lookup once and substitutes the string if it returns NULL This is an extension to C provided for compatibility with GCC It is not allowed in C mode Hexadecimal Floating Point Numbers C99 style hexadecimal floating point constants are accepted They have the following syntax hexadecimal floating constant 0x 0X hex significand binary exponent part floating suffix hex significand hex digits hex digits binary exponent part p P decimal digits floating suffix f 1 F Lb The hex significand is interpreted as a hexadecimal rational number the digit sequence in the exponent part is interpreted as a decimal integer The exponent indicates the power of two by which the significand is to be scaled The floating suffix has the same meaning it does for decimal float ing constants a constant with no suffix is of type double a constant with suffix F is of type float and a constant with suffix L is of type long double Hexadecimal floati
242. er between compatibility call for the ADSP 21csp01 DSP and legacy ADSP 218x DSPs oldasmcall csp is default Therefore oldasmcal1 csp makes code compatible with leg acy ADSP 21csp01 code while oldasmcal1 8x makes code compatible with legacy ADSP 218x code P The P omit line numbers switch directs the compiler to stop after the C preprocessor runs without compiling and to omit the 1 ine preprocessor directives with line number information in the output from the prepro cessor The C switch may be used in combination with the P switch PP The PP omit line numbers and compile switch directs the compiler to omit the 1 ine preprocessor directives with line number information from the preprocessor output After preprocessing compilation proceeds normally 1 38 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler path asm compiler def lib link mem filename The path tool location switch directs the compiler to use the specified component in place of the default installed version of the compilation tool The component should comprise a relative or absolute path to its location Respectively the tools are the assembler compiler driver defini tions file librarian linker or memory initializer Use this switch when you wish to override the normal version of one or more of the tools The path switch also overrides the directory specified by the path instal1 switch
243. er is the lower 16 bits of the address of the external memory to read This function is implemented as a compiler built in The emitted instruc tions will be inlined at the point of external_memory_read use The inclusion of the sysreg h include file is mandatory when using external_memory_read Error Conditions The external_memory_read function does not return raise or set any error conditions Example d Finclude lt sysreg h gt section external_memory_section static int GlobalTable 256 int main int page read_value asm 0 PAGE GlobalTable e page 3 54 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library read_value external_memory_read page amp GlobalTable 1 return read_value See Also external_memory_write disable_interrupts enable_interrupts io_space_read io_space_write mode_change sysreg_read sysreg_write VisualDSP 3 5 C C Compiler and Library Manual 3 55 for ADSP 219x DSPs C Run Time Library Reference external_memory_write write to external memory Synopsis include lt sysreg h gt void external_memory_write int void int Description The external_memory_write function causes the compiler to emit instruc tions to write to external memory at the address passed in the first two parameters with the value passed in the last parameter The first parameter is the value of the top eight bits of the 24 bit e
244. er makes use of the DSP s double word long MAC instruction results to avoid having to explicitly promote inte ger operand multiplication to long If the integer multiplication result overflows the integer type then the result is not truncated as would be the case in strict ANSI terms This behavior is disabled using the compiler s no widen muls switch on page 1 36 Normal ANSI C external linkage does not specifically require stan dard include files to be used although it is recommended In most cases Analog C compilers do require standard include files to be used This is because build configurations and optimization levels are used to select the correct and optimal implementation of the functions For example the include files may redefine standard C functions to use optimal compiler built in implementations 1 4 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler The compilers also support a number of language extensions that are essentially aids to DSP programmers and would not be defined in strict ANSI conforming implementations These extensions are usually enabled by default and in some cases can be disabled using a command line switch if required These extensions include Inline function which directs the compiler to integrate the func tion code into the code of the callers Dual memory support keywords pm dm Disabled using the no extra keywords compiler switch see on p
245. er to add the spec ified directory to the list of directories searched for source files On Windows platforms multiple source directories are given as a comma or semicolon separated list The compiler searches for the source files in the order specified on the command line The compiler searches the specified directories before reverting to the current project directory This option is position dependent on the command line that is it affects only source files that follow the option Source files whose file names begin with or or Windows equivalent and contain drive specifiers on Windows platforms are not affected by this option 1 42 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs R Compiler The R disable source path switch removes all directories from the stan dard search path for source files effectively disabling this feature This option is position dependent on the command line it only affects files following it reserve register register The reserve reserve register switch directs the compiler not to use the specified register s This guarantees that a known register or set of regis ters is available for auto buffering You can reserve the 12 13 and MO registers Separate register names with commas on the compiler command line Reserving registers seriously reduces the effectiveness of compiler optimizations and should only be done when essential
246. eral Register set sysreg_ASTA arithmetic status sysreg_SSTA shifter status sysreg_MSTA multiplier status sysreg_ICNTL interrupt control sysreg_IMASK interrupts enabled mask sysreg_IRPTL Interrupt Latch register sysreg_DMPG1 DMPG1 high address register sysreg_DMPG2 DMPG2 high address register sysreg_I0PG 10PG I O page register System Control Register set sysreg_BO BO base register sysreg_Bl B1 base register VisualDSP 3 5 C C Compiler and Library Manual 3 151 for ADSP 219x DSPs C Run Time Library Reference sysreg_B2 B2 base register sysreg_B3 B3 base register sysreg_B4 B4 base register sysreg_B5 B5 base register sysreg_B6 B6 base register sysreg_B7 B7 base register sysreg_SYSCTL SYSCTL register Cache Control Register sysreg_CACTL CACTL register Emulation Debug Control Register sysreg_DBGCTRL DBGCTRL register Emulation Debug Status Register sysreg_DBGSTAT DBGSTAT register Cycle Counter Registers sysreg_CNTO CNTO register sysreg_CNTl CNT1 register sysreg_CNT2 CNT2 register sysreg_CNT3 CNT3 register The sysreg_write function is implemented as a compiler built in The emitted instructions will be inlined at the point of sysreg_write use The inclusion of the sysreg h include file is mandatory when using sysreg_write Error Conditions The sysreg_write function does not return raise or set any error conditions 3 152 VisualDSP 3 5 C C Compiler and Library Manual
247. ered ar m7 void f void the compiler will know that only registers ar and m7 may be modified by the call to f so it may keep local variables in other registers across that call 1 130 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler The regs_clobbered pragma may also be used with a function definition or a declaration preceding a definition when it acts as a command to the compiler to generate register saves and restores on entry and exit from the function to ensure it only modifies the registers in string For example fpragma regs_clobbered ar m7 int g int a return at3 The regs_clobbered pragma may not be used in conjunction with pragma interrupt If both are specified a warning is issued and the regs_clobbered pragma is ignored To obtain best results with the pragma it is best to restrict the clobbered set to be a subset of the default scratch registers The compiler is likely to produce more efficient code this way than if the scratch set is changed to use the same number of registers but which does not make a subset of the default volatile set usually scratch When considering when to apply the regs_clobbered pragma it may be useful to look at the output of the compiler to see how many scratch regis ters were used Restricting the volatile set to these registers will produce no impact on the code produced for the function but may free up registers for the caller to allocate ac
248. ession that is the expression must be legal on the left side of an assignment statement A colon separates e The template from the first output operand e The last output operand from the first input operand e The last input operand from the clobbered registers A space must be added between adjacent colon field delimiters in order to avoid a clash with the C operator reserved global resolution A comma separates operands and registers within arguments The number of operands in arguments must match the number of operands in your template The maximum permissible number of operands is ten 0 1 2 3 4 5 6 7 8 and 9 1 66 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler The compiler cannot check whether the operands have data types that are reasonable for the instruction being executed The com piler does not parse the assembler instruction template does not interpret the template and does not verify whether the template contains valid input for the assembler ASM Construct Template Example The following example shows how to apply the asm construct template to the ADSP 219x assembly language abs instruction int x result asm 0 abs 41 c result te Gas In the previous example note the following points The template is 0 abs 1 The 0 is replaced with operand zero result the first operand The 1 is repl
249. esult The least 16 bits are zeroed 16 bit variable gt least significant bits sign extended fract32 L_deposit_l fract16 This function deposits the 16 bit parameter into the 16 least significant bits of the 32 bit result The most significant bits are set to sign extension for the input VisualDSP 3 5 C C Compiler and Library Manual 1 115 for ADSP 219x DSPs C C Compiler Language Extensions Multiply and accumulate fract32 L_mac fract32 fractl6 fractl6 This function performs a fractional multiplication of the two 16 bit parameters and returns the saturated sum of the multiplication result with the 32 bit parameter Multiply and accumulate without saturation fract32 L_macNs fract32 fractl6 fractl6 This function performs a non saturating version of the L_mac operation Multiply both the most significant bits and the least significant bits of a long by the same short fract32 L milhs fract32 fractl6 Multiply and subtract fract32 L_msu fract32 fractl6 fractl6 This function performs a fractional multiplication of the two 16 bit parameters and returns the saturated subtraction of the multiplication result with the 32 bit parameter Multiply and subtract without saturation fract32 L_msuNs fract32 fractl6 fractl6 This function performs a non saturating version of the L_msu operation Long multiply fract32 L_mult fractl6 fractl6 This function returns the 32 bit result of the fractional multip
250. etjmp h gt d Finclude lt stdio h gt d Finclude lt errno h gt d Finclude lt stdlib h gt VisualDSP 3 5 C C Compiler and Library Manual 3 91 for ADSP 219x DSPs C Run Time Library Reference jmp_buf env int res if res setjmp env 0 printf Problem d reported by func res exit EXIT_FAILURE func void func void if errno 0 See Also setymp longjmp env errno 3 92 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library malloc allocate memory Synopsis d include lt stdlib h gt void malloc size_t size Description The malloc function returns a pointer to a block of memory of length size The block of memory is uninitialized Error Conditions The malloc function returns a null pointer if it is unable to allocate the requested memory Example d Finclude lt stdlib h gt int ptr ptr int malloc 10 ptr points to an j array of length 10 See Also calloc free realloc VisualDSP 3 5 C C Compiler and Library Manual 3 93 for ADSP 219x DSPs C Run Time Library Reference memchr find first occurrence of character Synopsis include lt string h gt void memchr const void sl int c size_t n Description The memchr function compares the range of memory pointed to by s1 with the input character c and returns a pointer to the first occurrence of c A null pointer
251. eturns a non zero value Error Conditions The isalnum function does not return any error conditions Example include lt ctype h gt int ch for ch 0 ch lt Ox7f ch printf 04x ch printf 3s isalnum ch alphanumeric putchar n See Also isalpha isdigit VisualDSP 3 5 C C Compiler and Library Manual 3 71 for ADSP 219x DSPs C Run Time Library Reference isalpha detect alphabetic character Synopsis include lt ctype h gt int isalpha int c Description The isalpha function determines if the input is an alphabetic character A Z or a z If the input is not alphabetic isalpha returns a zero If the input is alphabetic isalpha returns a non zero value Error Conditions The isalpha function does not return any error conditions Example include lt ctype h gt int ch for ch 0 ch lt Ox7f ch printf 4 04x ch printf 2s isalpha ch alphabetic putchar n See Also isdigit isalnum 3 72 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library iscntrl detect control character Synopsis include lt ctype h gt int iscntri int c Description The iscntr1 function determines if the argument is a control character 0x00 Ox1F or 0x7F If the argument is not a control character iscntr1 returns a zero If the argument is a control character iscntr returns a non zer
252. ex Number Support The Mandelbrot fractal set is defined by the following iteration on com plex numbers Z Zz z cCc The c values belong to the set for which the above iteration does not diverge to infinity The canonical set is defined when z starts from zero VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs 1 177 C C and Assembly Language Interface Listing 1 2 demonstrates the Mandelbrot generator expressed in a simple algorithm using the C library complex class Listing 1 2 Mandelbrot Generator Example C code include lt complex gt int iterate complex lt double gt c complex lt double gt z int max int n for n 0 n lt max amp amp abs z lt 2 0 n ZL ZS A Aes return n max 0 n Listing 1 3 shows a C version of the inner computational function of the Mandelbrot generator extracts performance and programming penalties compared with the C version Listing 1 3 Mandelbrot Generator Example C Code int iterate double creal double cimag double zreal double zimag int max double real imag int n real zreal zreal imag zimag zimag for n 0 n lt max amp amp realt timag lt 4 0 n zimag 2 0 zreal zimag cimag zreal real imag creal real zreal zreal imag zimag zimag return n max 0 n 1 178 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs 2 A
253. ey should compile with __NO_ETSI_FLAGS set to zero This will mean that the user is using the functions in accordance with the ETSI standard but this will result in a reduced performance Using the ETSI Built In Functions Some of the ETSI functions have been implemented as part of cc219x compiler s set of built in functions For information on how to use these functions refer to Compiler Built In Functions on page 1 94 These built in implementations will be automatically defined when header file ETSI_fract_arith h is included Linking ETSI Library Functions When your C C code calls an ETSI function that is not implemented using a compiler built in the call creates a reference that the linker resolves when linking This requires the linker to be directed to link with the ETSI library 1ibetsi dib in the 219x 1ib directory which is a sub directory of the VisualDSP installation directory This is done automatically when using the default Linker Description File LDF for ADSP 219x processor targets as these specify that 1ibetsi d1b will be on each link line VisualDSP 3 5 C C Compiler and Library Manual 1 109 for ADSP 219x DSPs C C Compiler Language Extensions If not using default LDF files then either add libetsi dibto the LDF file which is being used or alternatively use the compiler s letsi switch to specify that 1ibetsi dib is to be added to the link line Working with ETSI Library Source Code Th
254. f permuta tions would make compilation time impracticably long The lack of control flow analysis can also create problems when a single pointer is used in multiple contexts For example it is better to write int p a Tit q be some use of p some use of q Good p and q do not alias than int p a some use of p VisualDSP 3 5 C C Compiler and Library Manual 2 11 for ADSP 219x DSPs General Guidelines p b some use of p Bad uses of p in different contexts may alias because the latter may cause extra apparent aliases between the two uses Indexed Arrays vs Pointers C allows a program to access data from an array in two ways either by indexing from an invariant base pointer or by incrementing a pointer These two versions of vector addition illustrate the two styles Style 1 using indexed arrays void va_ind const short a const short b short out int n intis for i 0 i lt n i outLi a i b i Style 2 using pointers void va_ptr const short a const short bl short out int n Wes Ws short pout out const short pa a pb b for i 0 i lt n i poutt pat pb Trying Pointer and Indexed Styles One might hope that the chosen style would not make any difference to the generated code but this is not always the case Sometimes one version of an algorithm will generate better optimized code than the other but it is no
255. f possible There are cases where the compiler will not be able to verify that the mem ory access is always within the bounds of the buffer The compiler is conservative in such cases and does not generate circular buffer accesses The compiler can be instructed to still generate circular buffer accesses even in such cases by specifying force circbuf on page 1 27 The compiler also provides built in functions which can explicitly gener ate circular buffer accesses subject to available hardware resources The built in functions provide circular indexing and circular pointer refer ences Both built in functions are defined in the builtins h header file Circular Buffer Increment of an Index The following operation performs a circular buffer increment of an index int __builtin_circindex int index int incr unsigned int nitems The operation is equivalent to index incr if index lt 0 index nitems else if index gt nitems index nitems An example of this built in function is void func int array int n int incr int len int i idx 0 for i 0 i lt n i 1 104 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler arrayLidx incr idx __builtin_circindex idx incr len Circular Buffer Increment of a Pointer The following operation performs a circular buffer increment of a pointer void __builtin_circptr const void ptr unsigned size_t
256. f products analog integrated circuits amplifiers converters and digital signal processors MyAnalog com MyAnalog com is a free feature of the Analog Devices website that allows customization of a webpage to display only the latest information on products you are interested in You can also choose to receive weekly email notification containing updates to the webpages that meet your interests MyAnalog com provides access to books application notes data sheets code examples and more Registration Visit www myanalog com to sign up Click Register to use MyAnalog com Registration takes about five minutes and serves as means for you to select the information you want to receive If you are already a registered user just log on Your user name is your email address DSP Product Information For information on digital signal processors visit our website at www analog com dsp which provides access to technical publications datasheets application notes product overviews and product announcements xxxii VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Preface You may also obtain additional information about Analog Devices and its products in any of the following ways e Email questions or requests for information to dsp support analog com e Fax questions or requests for information to 1 781 461 3010 North America 089 76 903 557 Europe e Access the Digital Signal Processing Division
257. fir_fr16 Response Filter const complex_fractl6 x complex_fractl6 yl int n cfir_state_frl6 s VisualDSP 3 5 C C Compiler and Library Manual 4 7 for ADSP 219x DSPs DSP Run Time Library Guide Table 4 3 Transformation Functions Description Prototype Fast Fourier Transform Generate FFT void twidfft_fr16 Twiddle Factor complex_fractl6 wl int n Generate FFT Twiddle void twidfftrad2_frl16 Factors for Radix 2 FFT complex_fractl6 wl int n Generate FFT Twiddle void twidfftrad4_fri16 Factors for Radix 4 FFT complex_fractl6 wl int n Generate FFT Twiddle void twidfft2d_frl16 Factors for 2 D FFT complex_fractl6 wl int n N Point Radix 2 void cfft_frl16 Complex Input FFT const complex_fractl6 in complex fractl6 t complex_fractl6 out const complex_fractl6 w int wst int n int block_exponent int scale_method N Point Radix 2 void rfft_frl16 Real Input FFT const fract16 in complex_fractl6 t complex_fractl6 out const complex_fractl6 w int wst int n int block_exponent int scale_method N Point Radix 2 void ifft_frl16 Inverse Input FFT const complex_fract in complex_fractl6 t complex_fractl6 out const complex_fractl6 w int wst int n int block_exponent int scale_method N Point Radix 4 void cfftrad4_frl16 Complex Input FFT const complex_fract
258. fir_init state coeffs delay ncoeffs index state h coeffs state d delay state p delay state k ncoeffs state 1 index The characteristics of the filter passband stopband and so on are depen dent upon the number of filter coefficients and their values A pointer to the coefficients should be stored in s gt h and s gt k should be set to the number of coefficients Each filter should have its own delay line which is a vector of type fract16 and whose length is equal to the number of coefficients The vector should be initially cleared to zero and should not otherwise be modified by the user program The structure member s gt d should be set to the start of the delay line and the function uses s gt p to keep track of its current position within the vector The structure member s gt 1 is not used by fir_fr16 This field is nor mally set to an interpolation decimation index before calling either the fir_interp_frl6 or fir_decima_frl6 functions Algorithm k 1 Vi S A j x i jf fori 0 n 1 j 0 Domain 1 0 to 1 0 4 58 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs DSP Run Time Library fir decima FIR decimation filter Synopsis include lt filter h gt void fir_decima_frl6 x y n s const fractl6 x Input sample vector x a fractl6 yl Output sample vector y int n Number of input samples Koi fir state fri6 s
259. float alogf float x Description The alog function calculates the natural base e anti log of its argument An anti log function performs the reverse of a 10g function and is there fore equivalent to exponentiation The input argument x must be in the range 87 9 88 6 The function will return HUGE_VAL if x is greater than the domain and it will return 0 0 if x is less than the domain Algorithm x C e Domain x 87 9 88 6 for alog alogf Example d Finclude lt math h gt double y y alog 1 0 LEN Cid VB 28350 R VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs 4 25 DSP Run Time Library Reference alog10 base 10 anti log Synopsis d Finclude lt math h gt double aloglO double x float aloglOf float x Description The alog function calculates the base 10 anti log of its argument An anti log function performs the reverse of a 10g function and is therefore equivalent to exponentiation Therefore alog10 x is equivalent to exp x log 10 0 If the argument x is greater than the domain of 38 2 38 5 the func tion will return HUGE_VAL For input values less than the domain the function will return 0 0 Algorithm oe ae log 10 0 Domain x 38 2 38 5 for alog10 alogl0f Example d Finclude lt math h gt double y y alogl0 1 0 P oy 10 0 AF 4 26 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x
260. formation for all typedefs and structs default linkage asm C C The default linkage asm assembler linkage default linkage C C linkage default linkage C C linkage switch directs the compiler to set the default linkage type C linkage is the default type in C mode and C linkage is the default type in C mode This switch can be specified in the Additional Options box located in the VisualDSP Project Options dialog box Compile tab General category dry The dry verbose dry run switch directs the compiler to display main driver actions but not to perform them VisualDSP 3 5 C C Compiler and Library Manual 1 25 for ADSP 219x DSPs Compiler Command Line Interface dryrun The dryrun terse dry run switch directs the compiler to display top level driver actions but not to perform them E The E stop after preprocessing switch directs the compiler to stop after the C C preprocessor runs without compiling The output prepro cessed source code prints to the standard output stream lt stdout gt unless the output file is specified with the o switch Note that the C switch can be used in combination with the E switch ED The ED run after preprocessing to file switch directs the compiler to write the output of the C C preprocessor to a file named original_filename i After preprocessing compilation proceeds normally EE The EE run after preprocessing switch directs t
261. function _primlO 3 14 C language extensions 1 60 aggregate assignments 1 89 asm keyword 1 63 bool keyword 1 84 C style comments 1 61 compound statements 1 86 false keyword 1 60 indexed initializers 1 88 inline keyword 1 62 non constant initializers 1 87 segment keyword 1 60 true keyword 1 60 C run time libc dlb library 3 13 library 3 7 library function summary 3 23 library header files 3 8 3 15 C type functions isalnum 3 71 iscntrl 3 73 isgraph 3 75 islower 3 76 3 78 isprint 3 81 ispunct 3 82 isspace 3 83 isupper 3 84 isxdigit 3 85 tolower 3 156 toupper 3 157 C function overload 1 102 C header files for library facilities 3 19 C mode compiler switches anach enable C anachronisms 1 52 no anach disable C anachronisms 1 53 no demangle 1 53 C programming examples 1 176 complex support 1 177 fract support 1 176 C run time library 3 7 support library 3 7 C startup file 3 7 C C mode selection switches 1 4 VisualDSP 3 0 C C Compiler and Library Manual for ADSP 219x DSPs INDEX c C mode 1 21 c89 1 21 C C run time environment See also mixed C C assembly programming library files 3 6 library overview 3 3 C C run time model 1 153 c89 compiler switch 1 21 cabs complex absolute value function 4 30 cache control register 3 149 3 152 cadd complex addition function 4 31 CALL instruction 1 157 callee preserved registers 1 161 caller save registers 1 16
262. functions are described in DSP Run Time Library Reference on page 4 22 Table 4 4 Math Library Description Prototype doub Float Anti lo e alog double x 8 alogf float x Base 10 Anti log doub Float e aloglO double x aloglOf float x double acos double x float acosf float x fractl acos_frl6 fractio x Arc Cosine 4 10 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Table 4 4 Math Library Contd DSP Run Time Library Description Prototype Arc Sine double asin double x float asinf float x fractl6 asin_frl6 fractl6 x Arc Tangent double atan float x float atanf float x fFractle atan_fr16 fractl6 x Arc Tangent of double atan2 double x double y Quotient float atan2f float x float y fractl6 atan2_frl6 fractl6 x fractl6 y Ceiling double ceil double x float ceilf float x Cosine double cos double x float cosf float x fractl6 cos_frl6 fractl6 x Hyperbolic Cosine double cosh double x float coshf float x Cotangent double cot double x float cotf float x Exponential double exp double x Float expf float x Floor double floor double x float floorf float x Floating Point double fmod double x double y Remainder float fmodf float x float y Get Mantissa and double frex
263. gate conj function 4 46 complex multiply cmlt function 4 45 complex number support 1 177 complex subtraction csub function 4 56 compound statements within expressions 1 86 conditional code in loops 2 20 conditional expressions with missing operands 1 142 conj complex conjugate function 4 46 const keyword 2 23 qualifier 2 23 const pointers 1 24 const read write compiler switch 1 24 const read write flag 2 24 1 8 VisualDSP 3 0 C C Compiler and Library Manual for ADSP 219x DSPs INDEX construct from polar coordinates polar function 4 91 construct operand assembly 1 68 constructs flow control 1 77 operand description 1 71 reordering and optimization 1 74 with input and output operands 1 75 with multiple instructions 1 74 control character test see iscntrl function controlling optimization 1 56 conv2d 2 D convolution function 4 49 conv2d3x3 2 D convolution function 4 50 conversions far and near pointers 1 101 convert characters see tolower toupper functions convert strings see atof atoi atol strtok strtol strtoul functions convolution 4 6 convolve convolution function 4 47 copysign copysign function 4 51 cos cosine function 3 45 cos_fr16 function 3 45 cosh hyperbolic cosine function 3 48 cot cotangent function 4 52 count zero crossing zero_cross function 4 109 countones count one bits in word function 4 53 crosscoh cross coherence function 4 54 cro
264. gisters of the ADSP 219x processors The code produced this way is better suited to the processor and therefore more efficient However this optimization can generate overflow results which are not consistent in some cases and may differ from expected results depending on the optimizations enabled and the way that the source is written The inconsistency and differences are seen if an overflow and truncation of the integer operands would normally occur When the optimization is applied there is no truncation When the opti mization is disabled the result of overflow will be truncated to integer size before being stored in the long result nothreads The nothreads disable thread safe build switch specifies that all com piled code and libraries used in the build need not be thread safe This is the default setting when the threads enable thread safe build switch is not used 1 36 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler The 0 enable optimizations switch directs the compiler to produce code that is optimized for performance Optimizations are not enabled by default for the cc219x compiler You can invoke this switch by selecting the Enable optimization check box in the VisualDSP Project Options dialog box Compile tab General category Oa The 0a automatic function inlining switch enables the inline expansion of C C functions which are not necessarily declared inline in th
265. hat they open Note that the function reference fflush NULL will flush the buffers of all opened streams stdlib h The stdlib h header file contains general utilities specified by the C stan dard These include some integer math functions such as abs div and rand general string to numeric conversions memory allocation functions such as malloc and free and termination functions such as exit This header file also contains prototypes for miscellaneous functions such as bsearch and qsort string h The string h header file contains string handling functions including strcpy and memcpy sysreg h The sysreg h header file defines a set of functions that provide efficient system access to registers modes and addresses not normally accessible from C source See Compiler Built In Functions on page 1 94 for more information on these functions VisualDSP 3 5 C C Compiler and Library Manual 3 15 for ADSP 219x DSPs C and C Run Time Library Guide Abridged C Library Support When in C mode the cc219x compiler can call a large number of func tions from the Abridged Library a conforming subset of the C library The Abridged Library has two major components embedded C library EC and embedded standard template library ESTL The embedded C library is a conforming implementation of the Embedded C library as specified by the Embedded C Technical Committee This section lists and briefly describe
266. he compiler to write the output of the C C preprocessor to standard output After preprocess ing compilation proceeds normally extra keywords The extra keywords enable short form keywords switch directs the compiler to recognize the Analog Devices keyword extensions to ISO ANSI standard C and C This recognition includes keywords such as pm and dm without leading underscores which could affect conforming ISO ANSI C and C programs This is the default mode The no extra keywords switch on page 1 34 can be used to disallow sup port for the additional keywords Table 1 7 on page 1 60 provides a list and a brief description of keyword extensions 1 26 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler flags asm compiler lib link mem switch switch2 The flags command line input switch directs the compiler to pass command line switches to the other build tools These tools are Option Tool flags asm Assembler flags compiler Compiler flags lib Library Builder flags link Linker flags mem Memory Initializer force circbuf The force circbuf circular buffer switch instructs the compiler to make use of circular buffer facilities even if the compiler cannot verify that the circular index or pointer is always within the range of the buffer Without this switch the compiler s default behavior is to be conservative and not use circular buffers unless
267. he external memory The val parameter to external_memory_write is the value to be written to external memory The variants where addr is a volatile pointer should be used when the accessed memory is changed by interrupts of peripherals in a way that may not be visible to the compiler For example include lt sysreg h gt section external_memory_section static int GlobalTable 256 int main int page read_value value_to_write 0 asm 0 PAGE GlobalTable e page external_memory_write page amp GlobalTable 0 value_to_write read_value external_memory_read page amp GlobalTable 1 return read_value Circular Buffer Built In Functions The C C compiler provides the following built in functions for using the ADSP 219x processor s circular buffer mechanisms You should include the builtins h file before using these functions Failure to do so leads to unresolved symbols at link time Automatic Circular Buffer Generation If optimization is enabled the compiler will automatically attempt to use circular buffer mechanisms where appropriate For example void func int array int n int incr VisualDSP 3 5 C C Compiler and Library Manual 1 103 for ADSP 219x DSPs C C Compiler Language Extensions int is for i 0 i lt n i array i 10 incr The compiler will recognize that the arrayli 10 expression is a cir cular reference and will use a circular buffer i
268. he floating point functions typically have an f prefix Make sure you are using the correct one The C language provides for implicit type conversion so the fol lowing sequence produces surprising results with no warnings float x y y abs x The value in x is truncated to an integer prior to calculating the absolute value then reconverted to floating point for the assign ment toy 3 12 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library setjmp h The setjmp h header file contains setjmp and longjmp for non local jumps signal h The signal h header file provides function prototypes for the standard ANSI signal h routines and also for several ADSP 219x DSP s extensions such as interrupt and clear_interrupt The signal handling functions process conditions hardware signals that can occur during program execution They determine the way that your C program responds to these signals The functions are designed to process such signals as external interrupts and timer interrupts stdarg h The stdarg h header file contains definitions needed for functions that accept a variable number of arguments Programs that call such functions must include a prototype for the functions referenced stddef h The stddef h header file contains a few common definitions useful for portable programs such as size_t stdio h The stdio h header file defines a set of functions macros
269. he function call will have the same effect every time it is called between assignments to global variables the compiler need not generate the code for every call Therefore in this example pragma pure long sdot short short int long tendots short a short b int n VisualDSP 3 5 C C Compiler and Library Manual 1 129 for ADSP 219x DSPs C C Compiler Language Extensions int i long s 0 for isset 1 lt lt 10s FFT s sdot a b n call can get hoisted out of loop return s the compiler can replace the ten calls to sdot with a single call made before the loop pragma const The pragma const is a more restrictive form of the pure pragma It tells the compiler that the function does not read from global variables as well as not writing to them or reading or writing volatile variables The result of the function is therefore a function of its parameters If any of the parameters are pointers the function may not even read the data they point at pragma regs_clobbered string The pragma regs_clobbered string may be used with a function decla ration or definition to specify which registers are modified or clobbered by that function The string contains a list of registers and is case insensitive When used with an external function declaration this pragma acts as an assertion telling the compiler something it would not be able to discover for itself In the example pragma regs_clobb
270. he inline keyword to inline code for functions that are used a number of times especially if they not very small functions The 0s switch does not have any effect on the use of the inline keyword It does however prevent automatic inlining using the 0a switch from increas ing the code size Macro functions can also cause code expansion and should be used with care 2 30 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Achieving Optimal Performance from C C Source Code Pragmas Pragmas can assist optimization by allowing the programmer to make assertions or suggestions to the compiler This section looks at how they can be used to finely tune source code Refer to Pragmas on page 1 119 for full details of how each pragma works the emphasis here will be in considering under what circumstances they are useful during the optimi zation process In most cases the pragmas serve to give the compiler information which it is unable to deduce for itself It must be emphasized that the programmer is responsible for making sure that the information given by the pragma is valid in the context in which it is used Use of a pragma to assert that a function or loop has a quality that it does not in fact have is likely to result in incorrect code and hence a malfunctioning application An advantage of the use of pragmas is that they allow code to remain por table since they will normally be ignored by a compiler that
271. he measure of randomness is its periodicity the num ber of values it is likely to generate before repeating a pattern The output of the pseudo random number generator has a period in the order of 2 Error Conditions The rand function does not return an error condition Example include lt stdlib h gt int i i rand See Also srand VisualDSP 3 5 C C Compiler and Library Manual 3 109 for ADSP 219x DSPs C Run Time Library Reference realloc change memory allocation Synopsis include lt stdlib h gt void realloc void ptr size_t size Description The realloc function changes the memory allocation of the object pointed to by ptr to size Initial values for the new object are taken from those in the object pointed to by ptr If the size of the new object is greater than the size of the object pointed to by ptr then the values in the newly allocated section are undefined If ptr is a non null pointer that was not allocated with malloc or calloc the behavior is undefined If ptr is a null pointer realloc imitates malloc If size is zero and ptr is not a null pointer real loc imitates free Error Conditions If memory cannot be allocated ptr remains unchanged and realloc returns a null pointer Example d Finclude lt stdlib h gt int ptrsg ptr int malloc 10 intervening code ptr int realloc ptr 20 the size is now 20 See Also calloc free malloc
272. he specified diagnostic messages errors remarks or warnings Werror limit number on page 1 49 Stops compiling after reaching the specified number of errors VisualDSP 3 5 C C Compiler and Library Manual 1 19 for ADSP 219x DSPs Compiler Command Line Interface Table 1 4 C C Compiler Common Switches Cont d Switch Name Description Wremarks on page 1 49 Indicates that the compiler may issue remarks which are diagnostic messages even milder than warnings Wterse on page 1 49 Issues only the briefest form of compiler warnings errors and remarks W on page 1 50 Does not display compiler warning messages warn protos on page 1 50 Produces a warning when a function is called without a prototype workaround lt workaround gt lt workaround gt on page 1 50 Enables code generator workaround for specific hardware defects write files on page 1 50 Enables compiler I O redirection write opts on page 1 50 Passes the user options but not input filenames via a tem porary file xref filename on page 1 51 Outputs cross reference information to the specified file Table 1 5 C Mode Compiler Switches Switch Name Description anach on page 1 52 Enables C anachronisms The default mode no anach on page 1 53 Disables C anachronisms no demangle on p
273. he structure and is defined as define iir_init state coeffs delay stages state c coeffs state d delay state k stages VisualDSP 3 5 C C Compiler and Library Manual 4 83 for ADSP 219x DSPs DSP Run Time Library Reference The characteristics of the filter are dependent upon filter coefficients and the number of stages Each stage has five coefficients which must be stored in the order B2 B1 BO A2 Al The value of A0 is implied to be 1 0 and A1 and A2 should be scaled accordingly This requires that the value of the AO coefficient is greater than both A1 and A2 for all the stages A pointer to the coefficients should be stored in s gt c and s gt k should be set to the num ber of stages The iir_fri6 function is implemented using a direct form II algo rithm When importing coefficients from a filter design tool that employs a transposed direct form II the Al and A2 coefficients have to be negated For example if a filter design tool returns A 1 0 0 2 0 9 then the A coefficients have to be modified to A 1 0 0 2 0 9 Each filter should have its own delay line which is a vector of type fract16 and whose length is equal to twice the number of stages The vector should be initially cleared to zero and should not otherwise be modified by the user program The structure member s gt d should be set to the start of the delay line Algorithm H z B Bz Bz Sime Par Pee where D
274. hecking the histogram_fr16 function allocates a tempo rary work area on the stack The work area is allocated with m 2 elements and the stack may therefore overflow if the number of bins is sufficiently large The size of the stack may be adjusted by making appropriate changes to the LDF file Algorithm Each input value is adjusted by min multiplied by 1 binsize and is rounded The appropriate bin in the output vector is then incremented Domain 3 4 x 10 8 to 3 4 x 10 8 for histogramf 1 0 to 1 0 for histogram_fr16 4 76 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs DSP Run Time Library ifft N point inverse FFT Synopsis include lt filter h gt void ifft_fr1l6 in tl out wl wst n block_exponent scale_method const complex_fractl6 in input sequence xJ complex_fractl6 t temporary working buffer x7 complex_fract16 out output sequence ai const complex_fract16 w twiddle sequence int wst twiddle factor stride Ko int n number of FFT points Z int block_exponent block exponent of output data int scale method scaling method desired O none l static 2 dynamic Description This function transforms the frequency domain complex input signal sequence to the time domain by using the radix 2 Fast Fourier Transform The size of the input array in the output array out and the temporary working buffer t is n where n repres
275. hod desired O none l static 2 dynamic K Description This function computes a two dimensional Fast Fourier Transform of the real input matrix a n n and stores the result to the complex output matrix c n n The size of the input array in the output array out and the temporary working buffer t is n n where n represents the number of points in the FFT The function does not impose any special memory alignment requirements on the arrays However benefits in run time performance will be realized if the output array is allocated on an address boundary that is a multiple of twice the FFT size The twiddle table is passed in the argument w which must contain at least n 2 twiddle coefficients The function twidfft2d_fr16 may be used to ini tialize the array If the twiddle table contains more coefficients than needed for a particular call on rf ft2d_fr16 then the stride factor has to be set appropriately otherwise it should be one 4 98 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs DSP Run Time Library The arguments block_exponent and scale_method have been added for future expansion However the current version of the function ignores the argument and always scales the output by n n this is equivalent to static scaling The function will also set block_exponent to log2 n Algorithm n n 1 di D ak re 9 9 k 0 1 0 where i 0 1 n 1 j 0 1 2 n 1 Domain Input sequence length n mu
276. iangle void gen_triangle_frl6 fractl6 wl J int a int _n Window Generate Vonhann void gen_vonhann_frl6 fractl6 _wl int a int n Window VisualDSP 3 5 C C Compiler and Library Manual 4 2 DSP Run Time Library Reference DSP Run Time Library Reference This section provides descriptions of the DSP run time library functions Notation Conventions An interval of numbers is indicated by the minimum and maximum sepa rated by a comma and enclosed in two square brackets two parentheses or one of each A square bracket indicates that the endpoint is included in the set of numbers a parenthesis indicates that the endpoint is not included The reference pages for the library functions use the following format Name and purpose of the function Synopsis Required header file and functional prototype When the functionality is provided for several data types for example float double or fract16 several prototypes are given Description Function specification Algorithm High level mathematical representation of the function Domain Range of values supported by the function Notes Other miscellaneous notations For some functions the interface is presented using the K amp R style for ease of documentation An ANSI C prototype is provided in the header file 4 22 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs DSP Run Time Library a_compress A law co
277. ias ccs iecraccsreismnrasantesinnnans 1 126 pragma linkage name identifier sesicsiccascresrerccoersesss 1 126 NS I o a E E 1 127 pragma weak Enty ooronsnenninraasniaraio radins 1 128 Function Side Effece Pragmas cscsnicearrennniecerini 1 128 PAPA NIE allot spunroarngin 1 129 Fpragma PUTE csncrosnoriinnorasknaknahasiaininain ieii 1 129 e a AS E A E T 1 130 pragma regs CODED string ssirminosesucasinenises 1 130 pragma result_aligiment n siiciscisicasccnccrasterescsinns 1 134 Template Instantiation Pragmas cvscsccnssrcracearverssveeniennee 1 134 pragma instantiate TSIEN sarsissosersrriiisirii 1 135 pragma do_not_instantiate instance cc ceceseeeeeeeees 1 136 pragma can instantiate INSTANCE cesresiisesienenssrai 1 136 Header File Control Pragmas svimeriririsiviicniusivisrcririssis 1 136 Fpragma hdrstop scnorossnrinnniaroinin akiona 1 136 Fpp ma Do peers a E 1 137 xii VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs CONTENTS PEALE GOS ccieenmeivencamertentuneitentacraneinentanenmeroeimeier 1 138 T prigma sr icn DIRET incnicncsmaronmsienmesnanansisans 1 138 GCC Compatibility Extensions ade secs nscale niesmeedeteceens 1 138 Seerne nt IOI OI aeina A 1 139 Type Reference Support Keyword Typeof eesecccccceeees 1 140 GCC Generalized CWE cciexeneeieeeeenes 1 141 Conditional Expressions with Missing Operands 1 142 Hexadecimal Floating Point Numbers susasiscnsiessinessivaine 1 142 Zero Me PS
278. iative buffers m Additional Output I Save temporary files I Generate preprocessed file Additional options Cancel Figure 1 1 Project Options Compile Property Page There are four sub pages you can access General Preprocessor Proces sor and Warning Most project options have a corresponding compiler command line switch described in Compiler Command Line Switches VisualDSP 3 5 C C Compiler and Library Manual 1 11 for ADSP 219x DSPs Compiler Command Line Interface on page 1 12 The Additional options field in each sub page is used to enter the appropriate file names and options that do not have correspond ing controls on the Compile tab but are available as compiler switches Use the VisualDSP context sensitive online Help to get information on compiler options you can specify in VisualDSP Compiler Command Line Switches This section describes the command line switches you can use when com piling It contains a set of tables that provide a brief description of each switch These tables are organized by type of a switch Following these tables are sections that provide fuller descriptions of each switch C C Compiler Switch Summaries This section contains a set of tables that summarize generic and specific switches options e C or C Mode Selection Switches in Table 1 3 on page 1 13 e C C Compiler Common Switches in Table 1 4 on page 1 13 e C Mode Compiler
279. ibrary Manual 4 7 for ADSP 219x DSPs DSP Run Time Library Reference gen_triangle generate triangle window Synopsis include lt window h gt void gen_triangle_frl6 w a N fractl6 wl Window vector int a Address stride in samples for window vector int N Length of window vector Description This function generates a vector containing the Triangle window The length of the window required is specified by the parameter N and the stride parameter a is used to space the window values within the output vector w Refer to the Bartlett window on page 4 63 regarding the relationship between it and the Triangle window Algorithm For even n the following equation applies 2n 1 n lt N 2 GE E gt N 2 7 where n 0 1 2 N 1 4 72 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs DSP Run Time Library For odd n the following equation applies n lt N 2 te ENE e N 1 where n 0 1 2 N 1 Domain a gt 0 N gt 0 VisualDSP 3 5 C C Compiler and Library Manual 4 73 for ADSP 219x DSPs DSP Run Time Library Reference gen_vonhann generate von hann window Synopsis d Finclude lt window h gt void gen_vonhann_frl6 w a N fractl6 wll Window vector int a Address stride in samples for window vector int N Length of window vector Description This function is identical to gen_hanning window on page 4 6
280. ified file When more than one source file has been compiled the listing contains information about the last file processed For each reference to a symbol in the source pro gram a line of the form symbol id name ref code filename line number column number is written to the named file The symbol id represents a unique decimal number for the symbol and ref code is one of the following characters Character Meaning D Definition Declaration Modification Address taken Used Changed used and modified Any other type of reference m acze Error unknown type of reference VisualDSP 3 5 C C Compiler and Library Manual 1 51 for ADSP 219x DSPs Compiler Command Line Interface C Mode Compiler Switch Descriptions The following switches apply only to C anach The anach enable C anachronisms directs the compiler to accept some language features that are prohibited by the C standard but still in common use This is the default mode Use the no anach switch for greater standard compliance The following anachronisms are accepted in the default C mode Overload is allowed in function declarations It is accepted and ignored Definitions are not required for static data members that can be initialized using default initialization The anachronism does not apply to static data members of template classes they must always be defined The number of elements in an array may be specified in an arra
281. iler and Library Manual 3 29 for ADSP 219x DSPs C Run Time Library Reference asin arc sine Synopsis include lt math h gt double asin double x float asinf float x fractl6 asin_frl6 fractl6 x Description The asin function returns the arc sine of the argument The input must be in the range 1 1 The output in radians is in the range 1 2 to 7 2 The asin_fr16 function is only defined for input values between 0 9 0x8ccd and 0 9 0x7333 The input argument is in radians Output values range from asin 0 9 2 m 0xa4C1 to asin 0 9 2 m 0x5B3F Error Conditions The asin function returns a zero if the input is not in the defined range Example d Finclude lt math h gt double y y asin 1 0 y nl2 See Also sin 3 30 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library atan arc tangent Synopsis include lt math h gt double atan double x float atanf float x fractl6 atan_frl6 fractl6 x Description The atan function returns the arc tangent of the argument The output in radians is in the range 7 2 to 11 2 The atan_fr16 function covers the output range from 17 4 input value 0x8000 output value 0x9878 to 1 4 input value 0x7FFF output value 0x6488 The input argument is in radians Error Conditions The atan function does not return an error condition Example d Finclude lt math h gt double y
282. iler operations VisualDSP 3 5 C C Compiler and Library Manual 1 21 for ADSP 219x DSPs Compiler Command Line Interface filename The filename command file switch directs the compiler to read com mand line input from filename The specified filename must contain driver options but may also contain source filenames and environment variables It can be used to store frequently used options as well as to read from a file list A name tokens The A assert switch directs the compiler to assert name as a predicate with the specified tokens This has the same effect as the fassert prepro cessor directive The following assertions are predefined system embedded machine adsp219x cpu adsp219x compiler cc219x The A name value switch is equivalent to including fassert name value in your source file and both may be tested in a preprocessor condition in the following manner if tname value do something else do something else endif For example the default assertions may be tested as if machine adsp219x do something endif 1 22 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler The parentheses in the assertion should be quoted when using the A switch to prevent misinterpretation No quotes are needed for a ifassert directive in a source file alttok The alttok alternative tokens switch directs the compiler to allow digraph sequences in C an
283. illegal 1 82 E E stop after preprocessing compiler switch 1 26 ED run after preprocessing to file compiler switch 1 26 EE run after preprocessing compiler switch 1 26 elfar archive library 1 2 1 24 Embedded C Library header files 3 16 3 19 Embedded Standard Template Library 3 2 header files 3 20 3 22 emulated arithmetic avoiding 2 8 emulation debug control register 3 149 3 152 emulation debug status register 3 149 3 152 enable_interrupts enable interrupts function 3 51 end see atexit exit functions escape character 1 145 ETSI 1 106 built in functions 1 109 calling library functions 1 108 I 10 VisualDSP 3 0 C C Compiler and Library Manual for ADSP 219x DSPs INDEX compiler built in functions 1 106 function linking 1 109 header file 1 111 library 1 106 library functions 1 111 library source code 1 110 run time library 3 7 support 1 106 ETSI library functions 16 bit variable least significant bits 1 115 16 bit variable most significant bits 1 115 compose long 1 118 extract high 1 112 extract long from two shorts 1 119 extract low 1 112 fract integer division of two longs 1 119 long absolute 1 115 long add 1 115 long add with carry 1 115 long division 1 111 long multiply 1 116 long negate 1 116 long normalize 1 113 long saturation 1 117 long shift left 1 117 long shift right 1 117 long shift right with rounding 1 117 long subtract 1 118 long s
284. ime string constant takes the form hh mm ss ANSI standard _VERSION__ Defines __VERSION__ as a string constant giving the version num ber of the compiler used to compile this module Header Files A header file contains C or C declarations and macro definitions Use the include preprocessor directive to access header files for your pro gram Header file names have an h extension There are two main categories of header files e System header files declare the interfaces to the libraries supplied with the ADSP 219x product Include them in your program for the definitions and declarations you need to access Use angle brackets to indicate a system header file Hinclude lt file gt e User header files contain declarations for interfaces between the source files of your program Use double quotes to indicate a user header file include file Writing Preprocessor Macros A macro is a name of a block of text that the preprocessor substitutes Use the define preprocessor command to create a macro definition When a macro definition has arguments the block of text the preprocessor substi tutes can vary with each new set of arguments VisualDSP 3 5 C C Compiler and Library Manual 1 149 for ADSP 219x DSPs Preprocessor Features Multi statement Macros Whenever possible use inline functions rather than multi statement mac ros If multi statement macros are necessary define such macros to allow inv
285. in the subdirectory 219x lib of your VisualDSP installation Several library files are built twice once for single threaded environments and once for multi threaded environments The multi threaded versions have a mt suffix Another variant for some of the libraries is also pro vided that avoids a hardware anomaly involving instruction type 32a these libraries have a _type32aworkaround suffix When you call a run time library function the call creates a reference that the linker resolves One way to direct the linker to the library s location is to use the default Linker Description File ADSP 21 lt your_target gt 1df If you are not using the default LDF file then either add the appro priate library libraries to the LDF file used for your project or use the compiler s 1 switch I library on page 1 31 to specify the library to be added to the link line For example the switches 1c 1etsi will add the C library libc dlb and the ETSI support library 1ibetsi dib to the list of libraries to be searched by the linker For more information on the LDF file see the VisualDSP 3 5 Linker and Utilities Manual for 16 Bit Processors Table 3 1 briefly describes the ADSP 219x DSP library functions Table 3 1 C and C Library Files 219x lib Directory Description 2192 12_int_tab doj Default interrupt vector code for ADSP 2192 12 DSP 219x_int_tab doj Default interrupt vector code for AD
286. in dm xy xI x Bi X K F K xy ef xy Sh xf Ff X xf eyword Function Declaration With Point VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs 1 81 C C Compiler Language Extensions Memory Keywords and Function Arguments The compiler checks calls to prototyped functions for memory space spec ifications consistent with the function prototype The following example shows sample code that cc219x flags as inconsistent use of memory spaces between a function prototype and a call to the function Illegal Dual Memory Support Keywords amp Calls To Prototyped Functions extern int foo int pm declare function foo which expects a pointer to an int residing in pm as its argument and which returns an int af int x define int x in dm ah foo amp x call function foo aif using pm pointer location of x as the E argument cc219x FLAGS AS AN ERROR this is an inconsistency between the function s if declared memory space argument and function aif call memory space argument xf Memory Keywords and Macros Using macros when making memory space specification for variables or pointers can make your code easier to maintain If you must change the definition of a variable or pointer moving it to another memory space declarations that depend on the definition may need to be changed to ensure consistency between different declarations of the
287. in the Project Options dialog box in the VisualDSP environment For example the following command line cc219x c source cpp proc ADSP 2191 runs cc219x with c Specifies that the following source file is written in ANSI ISO standard C extended with the Analog Devices keywords source cpp Specifies the source file for your program proc ADSP 2191 Specifies that the compiler should produce code suitable for the ADSP 2191 DSP Using Fract Type Support Listing 1 1 on page 1 177 demonstrates the compiler support for the fract type and associated arithmetic operators such as and The dot product algorithm is expressed using the standard arithmetic operators The code demonstrates how two variable length arrays are initialized with fractional literals 1 176 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler For more information abut the fractional data type and arithmetic see Fractional Type Support on page 1 90 Listing 1 1 Example Code Using Fract Data Type C code Finclude lt fract gt define N 20 fract XIN Afery e aye ya D a a ya S a ya brs Rol S Ee US a A o ES AE E a SP ya OPES fract y N 0 1r 2r 3r 4r 5r 6r 7r 8r 9r 10r 1r SOP cP E E L E Oy aT Py Or 5 O13 fract fdot int N fract x fract y int j fract s s 0 for j 0 j lt N j s x j yljl return s int main void fdot N x y Using Compl
288. ine Interrupt Table and Interface The interrupt table is an assembly language set of functions defined in named sections These sections get placed appropriately in the Linker Description File LDF to be executed at interrupt vector addresses The default code for the ADSP 219x DSP s interrupt table is defined in 219x_int_tab asm The default interrupt table uses the following external symbols _lib_int_table Static table holding interrupt information defined in the C run time library __lib_int_determiner An interrupt dispatcher defined in the C run time library ___esystem_start C run time initialization defined in the run time header The 219x_int_tab file contains a section of code for each hardware inter rupt The LDF file places these code sections in the correct interrupt vector slots for each interrupt 1 154 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler If an interrupt occurs program execution begins at the interrupt vector addresses Program execution causes a jump to __1ib_int_determiner in the default vector code If __lib_int_determiner finds by inspecting __lib_int_table a handler set for the interrupt it will call the handler __lib_int_determiner saves and restores all scratch registers around the handler call The function __1ib_int_determiner terminates by executing a return from interrupt RTI instruction which restores program execu tion to the point at which the interr
289. ine functions Force function inlining Removed fkeep inline funtions Force keeping of inlined Removed functions fno asm Don t recognize asm as a Replaced with keyword no extra keywords see on page 1 34 fno builtin Don t recognize builtin functions Replaced with no builtin see on page 1 34 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs A 5 C C Compiler and Run Time Library Table A 1 C C Compiler Obsolete and Replaced Switches Cont d Release 6 1Switch Operation under Release 6 1 Change for VisualDSP 3 5 fsigned bitfields funsigned bitfields Control whether bit field is signed or unsigned Removed Bit field is signed or unsigned based on the sign of the type defi nition declaring the bitfield fno signed bitfields fno unsigned bit fields Negative form of the fsigned bitfield and funsigned bitfield Removed Bit field is signed or unsigned based on the sign of the type defi nition declaring the bitfield fsigned char funsigned char Specify whether to default to signed or unsigned char type Replaced with signed char and unsigned char fsyntax only Check syntax only no out put Replaced with syntax only see on page 1 45 fwritable strings Store string constants in the writable data segment Removed String constants are placed in the seg_datal s
290. ing Array Writes in Loops Other dependencies can be caused by writes to array elements In the fol lowing loop the optimizer cannot determine whether the load from a reads a value defined on a previous iteration or one that will be overwrit ten in a subsequent iteration for C100 i ons PE alij bli alclill Bad has array dependency The optimizer can resolve access patterns where the addresses are expres sions that vary by a fixed amount on each iteration These are known as induction variables for i 0 i lt n i aLit4 bli a i Good uses induction variables Inner Loops vs Outer Loops Tip Inner loops should iterate more than outer loops The optimizer focuses on improving the performance of inner loops because this is where most programs spend the majority of their time It is considered a good trade off for an optimization to slow down the code before and after a loop if it is going to make the loop body run faster Therefore try to make sure that your algorithm also spends most of its VisualDSP 3 5 C C Compiler and Library Manual 2 19 for ADSP 219x DSPs Loop Guidelines time in the inner loop otherwise it may actually be made to run slower by optimization If you have nested loops where the outer loop runs many times and the inner loop a small number of times it may be possible to rewrite the loops so that the outer loop has the fewer iterations Avoiding Conditional Code in L
291. inn 2 22 Using the Const Qualia sax ciccnscnarnenventececinntinmnendecernioennans 2 23 Avoiding Long Laten ies snorcrconereerneorennn inondat 2 24 Using Built In Functions in Code Optimization 00 0 2 25 Pisa TO checnccieica niece 2 25 System Support Built In Functions osrsrorirsarisrars arisini 2 26 Uine Te Dulles srsrsiinreead 2 27 Smaller Applications Optimizing for Code Size eseese 2 29 Pranita sinclar 2 31 Pucci PAG NAS sorecenrerererorninire arenor TATR 2 31 PPLA COMET iid ce aie ie 231 Fpragima PATE siseccescsnsisercovavnrveansdsevcaseearverncane ninin Erann 2 32 a L E E A E E 2 32 Fprapmia reps clobbered ronnen 2 33 pragma optimize_ off for_speed for_space as_cmd_line 2 35 Looe Optimization Pramas siiceccssrcinidedaanssieasenae 2 35 xvi VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs CONTENTS fpr ma loop ROUGE lt pocptecccsreenidintereimerninnteneonioss 2 35 A ELE E E T 2 36 Useful Oprmizaton Swirches sisrinssiinii eneinio e 2 37 C C RUN TIME LIBRARY Cand Cr Ron Time Library Guide sanassa 3 3 Calang Library Peer ine seriosas eens enews 3 4 Using the Compiler s Built In C Library Functions 0 3 5 Linking Library Functions icicceiscicianennicmsuieieneienmacians 3 6 Working With Library Header Files scrcccsmnenranieiisons 3 8 a A ci A ieee E E E E E A ET 3 9 S e ee ea 3 9 def2191 h Memory Map Definitions sssssscscereereeree 3 10 def2192 12 h Memory Map Definit
292. int int void signals int sig void func int int Description These functions are Analog Devices extensions to the ANSI standard The signal function determines how a signal received during program execution is handled The signa functions cause a single execution the function pointed to by func the interrupt functions cause the function to be executed for every interrupt The different variants of the signal functions differentiate between han dler dispatching functions The variants will be appropriate for some applications and provide improved efficiency The default signal func tion dispatcher saves and restores all scratch registers and modes on the data stack around a call to the handler func when servicing an interrupt This dispatcher will pass the interrupt ID for example SIG_PWRDWN to the handler as its parameter The signalf interrupt dispatcher is similar to interrupt except that it switches between primary and secondary register sets to save and restore registers instead of using the data stack The signalf function cannot be used in applications where nested interrupts are enabled This interrupt dispatcher will pass the interrupt ID to the handler as its parameter The signals interrupt dispatcher saves and restores only the smallest number of registers and modes required to determine if a handler has been registered and to call that handler The handler passed as input to signals 3 112 VisualDSP 3
293. ints to a far memory integer int far nf2 declares nf2 to be a pointer which resides in near memory and points to a far memory integer section some_far_section inte tar far ffa declares ff to be a pointer which resides in far memory and points to a far memory integer The near qualifier is a default and may be omitted when declaring types for variable which will normally reside in internal memory The compiler will treat accesses to near qualified variable types exactly as if the near qualifier had not been used The far qualifier will normally be used in conjunction with the section placement specifier on static or global scope variables Use of far with automatic declarations will result in a compiler warning indication that the far qualifier is unnecessary The compiler will issue an error if both near and far are used in a conflicting way Sizes of Far and Near Qualified Types The size of a far pointer is 32 bits the actual address width required 24 bits cannot be stored on the data stack The size of near qualified data is as normal given that near will be ignored The sizeof operator will return 1 for near pointers and 2 for far pointers For example include lt assert h gt 1 100 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler section s
294. ion Overloading scasicsisiseiniiiusisinneuacunicns 1 102 Library Sapport for Far Pointers lt iessererisescomuteracees 1 102 Legacy Support cictcniedaiene eee 1 102 Circular Batter Built in Functions seissnnniiaan 1 103 Automatic Circular Buffer Generation eessssecceeeccee 1 103 Circular Buffer Increment of an Index sucrinrisirisrens 1 104 Circular Buiter Increment of a Pointer ssicrsineriaraw 1 105 ETSI SUPPO vaeioeeni eee eee 1 106 EISI Sit Ce sas ecaccernisic csieeiierenraireeens 1 106 Calling ETSI Library Fonctions ccaprsrsicntivennasvineecian 1 108 Using the ETSI Built In Functions ruscccsninecissnnsa 1 109 Linline ETSI Library Functions pcicascsscevarteortereeenternaenods 1 109 Working with ETSI Library Source Code ssniiisssniisiras 1 110 EES Support for Data Tyee cncsgesaisarnieta en 1 110 ET Feidr PE aan 1 111 FUORI rnani 1 113 Data Alignment PAAR cevsicssraienai iao 1 121 PRN aliet MUM gcrann 1 121 pragma pad aligno pt nenssnioririncnrinbinicninine 1 121 Interrupt Handler Petar scerorneresnienenanmii 1 122 VisualDSP 3 5 C C Compiler and Library Manual xi for ADSP 219x DSPs CONTENTS PN INE aar 1 122 eee ee sconce ena 1 122 Loop Oprimizanon Prapiias seineniiiaceiun ei 1 123 pragma loop_count min max modulo ssesseseseeeess 1 124 Fpragma vector for baicadinticsinchenciesnieiaiiadaeclearanntaimncis 1 124 Fore ma No alai renerien 1 125 General Optimization Piagmas sssnccuuiercmimneminn 1 125 Liking Control Pragm
295. ions eee 3 10 def219x h Memory Map Definitions eee eeeseeeeeeeees 3 10 COIR sccamicisiheioentindeniewonenet 3 10 POOR PEE tons ieee eae deena 3 10 TOAD suoraa 3 11 TATE Sd E E S A EE A E ET 3 11 ie EE VE EAE TE ES eee 3 12 mahh sip iets ca netcaliensce lata aa i licens oan R ba 3 12 OP tN onan does eee 3 13 eT nen 3 13 Ct Giana eae 3 13 seddel SMR Cee Ree EOE EE Ea RPC RTOS ORC TEM Rar RTOS EE REC SRT RTT EETERRE aN 3 13 VisualDSP 3 5 C C Compiler and Library Manual xvii for ADSP 219x DSPs CONTENTS BOO A A E nian E 3 13 E E E A AE T EE T E E 3 15 ALL p AE 3 15 a Sec ia ere 3 15 Abridged C Library SUpport cisinaiantnaiscimcsoicesmuicinanises 3 16 Embedded C Library Header Files sscnccsescicscneronercixsenniers 3 16 SO oie ees 3 16 CG EEE E E E A N A 3 17 E e EpES ETT EP PRN VRE Ra yea Oe reer eee Moree ee 3 17 PI tc ces se E E cease eave eu EA PO E E 3 17 OMARI boae aR 3 17 EEA A E E E ener EE E rn 3 17 DEI aar eadeseaemneeeaendtes 3 17 TC e E E 3 18 T E EE E E E E EEE E A E E A et 3 18 E E E eres 3 18 r E E E E E N 3 18 EE a E E E E E 3 18 E E hee ea 3 18 SCRE eE AAO 3 18 SEEE ia EEA 3 19 SA a R rae Peete SATE OVEyT errs rE FER 3 19 C Header Files for C Library Facilities scciiiccarsrossoinsssoncas 3 19 Embedded Standard Template Library Header Files 3 20 xviii VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Ci alone 3 20 DAE GRE sierran N tee 3 2
296. is identical to the strcmp function The function returns a positive value if the s1 string is greater than the s2 string a negative value if the s2 string is greater than the s1 string and a zero if the strings are the same Error Conditions The strcol1 function does not return an error condition Example include lt string h gt char stringl 50 string2 50 if strcoll stringl string2 printf s is different than 4s n stringl string2 See Also strrchr strncmp 3 124 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library strcpy copy from one string to another Synopsis d Finclude lt string h gt void strcpy char sl const char s2 Description The strcpy function copies the null terminated string pointed to by s2 into the space pointed to by s1 Memory allocated for s1 must be large enough to hold s2 plus one space for the null character 0 The behav ior of strcpy is undefined if the two objects overlap or if s1 is not large enough The strcpy function returns the new s1 Error Conditions The strcpy function does not return an error condition Example d Finclude lt string h gt char stringl1 50 strcepy stringl SOMEFUN SOMEFUN is copied into stringl See Also memcpy memmove strncpy VisualDSP 3 5 C C Compiler and Library Manual 3 125 for ADSP 219x DSPs C Run Time Library Reference strcspn length of char
297. is returned if c does not occur in the first n characters Error Conditions The memchr function does not return an error condition Example include lt string h gt char ptr ptr memchr TESTING E 7 ptr points to the E in TESTING See Also strchr strrchr 3 94 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library memcmp compare objects Synopsis d Finclude lt string h gt int memcmp const void sl const void s2 size_t n Description The memcmp function compares the first n characters of the objects pointed to by s1 and s2 It returns a positive value if the s1 object is lexically greater than the s2 object a negative value if the s2 object is lexically greater than the s1 object and a zero if the objects are the same Error Conditions The memcmp function does not return an error condition Example d Finclude lt string h gt char stringl ABC char string2 BCD int result result memcmp stringl string2 3 result lt 0 See Also strcmp strcoll strncmp VisualDSP 3 5 C C Compiler and Library Manual 3 95 for ADSP 219x DSPs C Run Time Library Reference memcpy copy characters from one object to another Synopsis include lt string h gt void memcpy void sl const void s2 size_t n Description The memcpy function copies n characters from the object pointed to by s2 into the object poin
298. isinff u f 0 fail u 1 Ox7F800001L if isinff u f 0 failt print pass fail message if fail 0 printf Test passed n else printf Test failed 4d n fail See Also isnan VisualDSP 3 5 C C Compiler and Library Manual 3 77 for ADSP 219x DSPs C Run Time Library Reference islower detect lowercase character Synopsis include lt ctype h gt int islower int c Description The islower function determines if the argument is a lowercase character a z If the argument is not lowercase is lower returns a zero If the argu ment is lowercase islower returns a non zero value Error Conditions The islower function does not return any error conditions Example include lt ctype h gt int ch for ch 0 ch lt Ox7f ch printf 04x ch printf 2s islower ch lowercase putchar n See Also isalpha isupper 3 78 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library isnan test for not a number NAN Synopsis d Finclude lt math h gt int isnanf float x int isnan double x Description The isnan function returns a zero if the argument is not set to an IEEE NaN Not a Number otherwise the function will return a non zero value Error Conditions The isnan function does not return or set any error conditions Example d Finclude lt stdio h gt dFinclude lt math h gt
299. isualDSP documenta tion set e Double click the vdsp help chm file which is the master Help sys tem to access all the other CHM files Using the Windows Start Button e Access the VisualDSP online Help by clicking the Start button and choosing Programs Analog Devices VisualDSP and VisualDSP Documentation e Access the PDF files by clicking the Start button and choosing Programs Analog Devices VisualDSP Documentation for Printing and the name of the book From the Web To download the tools manuals point your browser at http www analog com technology dsp developmentTools gen_purpose html Select a processor family and book title Download archive Z1P files one for each manual Use any archive management software such as WinZip to decompress downloaded files VisualDSP 3 5 C C Compiler and Library Manual XXXV for ADSP 219x DSPs Product Information Printed Manuals For general questions regarding literature ordering call the Literature Center at 1 800 ANALOGD 1 800 262 5643 and follow the prompts VisualDSP Documentation Set VisualDSP manuals may be purchased through Analog Devices Cus tomer Service at 1 781 329 4700 ask for a Customer Service representative The manuals can be purchased only as a kit For additional information call 1 603 883 2430 If you do not have an account with Analog Devices you will be referred to Analog Devices distributors To get information on ou
300. itions The isspace function does not return any error conditions Example include lt ctype h gt int ch for ch 0 ch lt Ox7f ch printf 04x ch printf 2s isspace ch space putchar n See Also iscntrl isgraph VisualDSP 3 5 C C Compiler and Library Manual 3 83 for ADSP 219x DSPs C Run Time Library Reference isupper detect uppercase character Synopsis include lt ctype h gt int isupper int c Description The isupper function determines if the argument is an uppercase charac ter A Z If the argument is not an uppercase character isupper returns a zero If the argument is an uppercase character isupper returns a non zero value Error Conditions The isupper function does not return any error conditions Example dFinclude lt ctype h gt int ch for ch 0 ch lt 0x7f ch printf 04x ch printf 2s isupper ch uppercase putchar n See Also isalpha islower 3 84 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library isxdigit detect hexadecimal digit Synopsis dFinclude lt ctype h gt int isxdigit int c Description The isxdigit function determines if the argument is a hexadecimal digit character A F a f or 0 9 If the argument is not a hexadecimal digit isxdigit returns a zero If the argument is a hexadecimal digit isxdigit returns a non zero value
301. k should be set to the number of coefficients The decimation index is supplied to the function in s gt 1 Each filter should have its own delay line which is a vector of type fract16 and whose length is equal to the number of coefficients The vector should be initially cleared to zero and should not otherwise be modified by the user program The structure member s gt d should be set to the start of the delay line and the function uses s gt p to keep track of its current position within the vector Algorithm WD DMG 1 fy Ak 1 where i 0 1 n I 1 Domain 1 0 to 1 0 4 60 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs DSP Run Time Library fir_interp FIR interpolation filter Synopsis include lt filter h gt void fir_interp_frl6 x y n s const fractl6 x Input sample vector x ard fractl6 yl Output sample vector y a int n Number of input samples a fir _state_frl6 s Pointer to filter state structure The function uses the following structure to maintain the state of the filter typedef struct fractl6 h Filter coefficients Xf fractl6 d Start of delay line fractl6 p Read Write pointer af int k Number of coefficients X int 1 Interpolation decimation index fir_state_frl6 Description The fir_interp_fr16 function performs an FIR based interpolation filter It generates the interpolated filtered response of the input dat
302. ke the Memory Initial izer tool after linking the executable This is the default setting See also mem on page 1 33 no std ass The no std ass disable standard assertions switch prevents the com piler from defining the standard assertions See the A switch on page 1 22 for the list of standard assertions no std def The no std def disable standard macro definitions prevents the com piler from defining any default preprocessor macro definitions no std inc The no std inc disable standard include search switch directs the C preprocessor to limit its search for header files to the current directory and directories specified with 1 switch You can invoke this switch by selecting the Ignore standard include paths check box in the VisualDSP Project Options dialog box Compile tab Preprocessor category VisualDSP 3 5 C C Compiler and Library Manual 1 35 for ADSP 219x DSPs Compiler Command Line Interface no std lib The no std 1ib disable standard library search switch directs the linker to limit its search for libraries to directories specified with the L switch on page 1 31 no widen muls The no widen muls disable widening multiplications switch disables the compiler optimization which it performs on multiplication operations By default the compiler attempts to optimize integer multiplication operations which are stored in a long result to utilize the double word MAC result re
303. l lt ll See Also abs labs 3 58 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library floor floor Synopsis include lt math h gt double floor double float floorf float Description The floor function returns the largest integral value that is not greater than its input Error Conditions The floor function does not return an error condition Example d Finclude lt math h gt double y y floor 1 25 yy 1 0 y floor 1 25 y 2 0 See Also ceil VisualDSP 3 5 C C Compiler and Library Manual 3 59 for ADSP 219x DSPs C Run Time Library Reference fmod floating point modulus Synopsis d Finclude lt math h gt double fmod double numer double denom float fmodf float numer float denom Description The fmod function computes the floating point remainder that results from dividing the first argument into the second argument This value is less than the second argument and has the same sign as the first argument If the second argument is equal to zero fmod returns a zero Error Conditions The fmod function does not return an error condition Example include lt math h gt double y y fmod 5 0 2 0 a L0 Ay See Also div ldiv modf 3 60 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library free deallocate memory Synopsis d Finclude lt stdlib h gt
304. l6 in complex fractl6 t complex_fractl6 out const complex_fractl6 w int wst int n int block_exponent int scale_method N Point Radix 4 void rfftrad4_frl16 Real Input FFT const fractl6 in complex_fractl6 t complex_fractl6 out const complex_fractl6 w int wst int n int block_exponent int scale_method 4 8 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs DSP Run Time Library Table 4 3 Transformation Functions Cont d Description Prototype N Point Radix 4 Inverse Input FFT void ifftrad4_frl6 const complex_fract in complex_fractl6 t complex_fractl6 out const complex_fractl6 w int wst int n int block_exponent int scale_method Nxn Point 2 D Complex Input FFT void cfft2d_frl6 const complex_fractl6 in complex fractl6 t complex_fractl6 out const complex_fractl6 w int wst int n int block_exponent int scale_method Nxn Point 2 D Real Input FFT void rfft2d_frl6 const fractl6 in complex_fractl6 t complex_fractl6 out const complex_fractl6 w int wst int n int block_exponent int scale_method Nxn Point 2 D Inverse void ifft2d_frl6 FFT const complex_fract in complex_fractl6 t complex_fractl6 out const complex_fractl6 w int wst int n int block_exponent int scale_method Convolutions Convolution void convolve_fr16
305. le 1 38 pplist file preprocessor listing 1 41 proc target processor 1 41 R disable source path 1 43 R directory add source directory 1 42 reserve reserve register 1 43 S stop after compilation 1 43 s strip debugging information 1 43 save temps save intermediate 1 7 VisualDSP 3 0 C C Compiler and Library Manual for ADSP 219x DSPs INDEX files 1 44 show display command line 1 44 signed bitfield make plain bitfields signed 1 45 signed char make char signed 1 45 si revision version silicon revision 1 44 sourcefile 1 21 syntax only only check syntax 1 45 syntax only system definitions 1 45 T linker description file 1 46 threads enable thread safe build 1 46 time time the compiler 1 47 Umacro undefine macro 1 47 unsigned bitfield make plain bitfields unsigned 1 47 unsigned char make char unsigned 1 48 v version and verbose 1 48 val global add global names 1 48 verbose display command line 1 48 version display version 1 49 w disable all warnings 1 50 W disable all warnings 1 49 warn protos prototypes warning 1 50 Werror limit maximum switches 1 49 workaround 1 50 Wremarks enable diagnostic warnings 1 49 write files enable file redirection 1 50 write opts 1 50 Wterse enable terse warnings 1 49 xref file cross reference list 1 51 compiler optimization disabling 1 36 complex conju
306. le c int n Subtraction void cvecvsubf const complex_float a const complex_float b complex_float c J int n void cvecvsub_frl6 const complex_fractl6 a const complex_fractl6 b J complex_fractl6 c J int n Complex void cvecvm const complex_double a Vector Vector const complex_double b complex_double c int n Multiplication void cvecvmltf const complex_float a const complex_float b J complex_float c J int n void cvecvmlt_frl6 const complex_fractl6 a J const complex_fractl6 b J complex_fractl6 c J int n VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs 4 19 DSP Run Time Library Guide Table 4 7 Vector Functions Cont d Description Prototype Real Vector Dot double vecdot const double a Product const double b J int n float vecdotf const float al const float b int n fractl6 vecdot_frl6 const fractl6 a const fractl6 b C int n Complex Vector Dot Product complex_double cvecdot const complex_double a const complex_double b J int n complex_float cvecdotf const complex_float a const complex_float b int n complex_fractl6 cvecdot_frl6 const complex_fractl6 a const complex_fractl6 b J complex_fractl6 c int n window h Window Generators The window h header file contains various functions to generate windows based on va
307. lean operator header file 3 11 isprint detect printable character function 3 81 ispunct detect punctuation character function 3 82 isspace detect whitespace character function 3 83 isupper detect uppercase character function 3 84 isxdigit detect hexadecimal digit function 3 85 J jump select jump table memory type compiler switch 1 31 K Kaiser window 4 70 keywords dual memory support illegal 1 82 memory 1 80 1 82 memory and macros 1 82 keywords compiler see VisualDSP compiler C C language extensions L L library search directory compiler switch 1 31 l link library compiler switch 1 31 1 36 labs long integer absolute value function 3 86 Language extensions compiler see VisualDSP compiler C C language extensions Idexp multiple by power of 2 function 3 87 Idiv division long function 3 88 leaf function 1 157 legacy support compiler A 3 1 17 VisualDSP 3 0 C C Compiler and Library Manual for ADSP 219x DSPs INDEX libc dlb library 3 13 libetsi dlb library 1 106 1 110 3 7 libetsi h system header file 1 109 libio dlb library 3 13 library format 4 22 functions listed 3 23 header files working with 3 8 line breaks in string literals 1 144 linkage type setting 1 25 linking DSP run time library functions 4 3 pragmas for 1 126 log natural logarithm function 3 89 log10 base 10 logarithm function 3 90 Long jump see longjmp setjmp fun
308. les to per form a specified action Table 1 1 File Extensions Extension Action C C cc cpp cxx Source file is compiled assembled and linked asm dsp or s Assembly language source file is assembled and linked doj Object file from previous assembly is linked If multiple files are specified each is first processed to produce an object file then all object files are presented to the linker You can stop this sequence at various points by using appropriate com piler switches or by selecting options with the VisualDSP environment These switches are F P M H S and c 1 8 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler Many of the compiler s switches take a file name as an optional parameter If you do not use the optional output name switch cc219x names the out put for you Table 1 2 on page 1 10 lists the type of files names and extensions cc219x appends to output files File extensions vary by command line switch and file type These exten sions are influenced by the program that is processing the file any search directories that you select and any path information that you include in the file name Table 1 2 indicates the searches that the preprocessor com piler assembler and linker support The compiler supports relative and absolute directory names to define file search paths For information on additional search directories see th
309. lex_float b complex_fractl6 cdiv_frl6 complex_fractl6 a complex_fractl6 b Get Phase of double arg complex_double a Complex Number float argf complex_float a fractl6 arg_frl6 complex_frl6 a Complex Conjugate complex_double conj complex_double a complex_float conjf complex_float a complex_fractl6 conj_frl6 complex_fractl6 a Convert Cartesian to double cartesian complex_double a double phase Polar Coordinates float cartesianf complex_float a float phase fractl6 cartesian_frl6 complex_fractl6 a fractl6 phase Convert Polar to complex_double polar double mag double phase Cartesian Coordinates complex_float polarf float mag float phase complex_fractl6 polar_frl6 fractl6 mag fractl6 phase Complex Exponential complex_double cexp double a complex_float cexpf float a Normalization complex_double norm complex_double a complex_float normf complex_float a filter h DSP Filters and Transformations The filter h header file contains filters used in signal processing It also includes the A law and p law companders that are used by voice band compression and expansion applications The header file also contains functions that perform key transformations used in DSPs including FFTs and convolution 4 6 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs DSP Run Time Library Various forms
310. lication of the two 16 bit parameters Long negate fract32 L_negate fract32 1 116 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler This function returns the 32 bit result of the negation of the parameter Where the input parameter is 0x80000000 saturation occurs and Ox7fffffff is returned Long saturation fract32 L sat fract32 The resultant variable is set to 0x80000000 if Carry and Overflow ETSI flags are set underflow condition else if Overflow is set the resultant is set to Ox7fffffff The default revision of the library simply returns as no checking or setting of the Overflow and Carry flags is performed Long shift left fract32 Leshl fract32 fractl6 This function arithmetically shifts the 32 bit first parameter to the left by the value given in the 16 bit second parameter The empty bits of the 32 bit result are zero filled If the second parameter is negative the shift performed is to the right with sign extended The result is saturated in cases of overflow and underflow Long shift right fract32 L shr fract32 fractl6 This function arithmetically shifts the 32 bit first parameter to the right by the value given in the 16 bit second parameter with sign extension If the shifting value is negative the source is shifted to the left The result is saturated in cases of overflow and underflow Long shift right with rounding fract32 L_shr_r fract32 fractl6 This function perf
311. lication uses a customized LDF file then either add libdsp dib to the customized LDF file or alternatively use the compiler s 1dsp switch to specify that 1ibdsp d1b is to be added to the link line Working with Library Source Code The source code for the functions in the C and DSP run time libraries is provided with your VisualDSP software By default the installation program copies the source code to a subdirectory of the directory where the run time libraries are kept named 219x lib src The directory con tains the source for the C run time library the DSP run time library the ETSI functions and for the I O run time library as well as the source for the main program start up functions If you do not intend to modify any of the run time library functions you can delete this directory and its con tents to conserve disk space The source code is provided so you can customize specific functions for your own needs Each function is kept in a separate file The file name is the name of the function with the appropriate extension for C or assem bler source To modify these files you need proficiency in ADSP 219x DSP assembly language and an understanding of the run time environ ment as explained in C C and Assembly Language Interface on page 1 169 Before you make any modifications to the source code copy VisualDSP 3 5 C C Compiler and Library Manual 4 3 for ADSP 219x DSPs DSP Run Time Library Guide the source
312. lysis files used internally by the compiler when per forming interprocedural analysis S dSp asm Assembler source file id Interface definition language files for VCSE iip ti Template instantiation files used internally by the compiler when instan tiating C templates is Preprocessed assembly source retained when save temps is specified ldf Linker Description File doj Object file to be linked d1b Library of object files to be linked as needed xm DSP system memory map file output sym DSP system symbol map file output 1 10 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler Specifying Compiler Options in VisualDSP When using the VisualDSP Integrated Development and Debug Envi ronment IDDE use the Compile tab from the Project Options dialog box to get compiler functional options as shown on Figure 1 1 Project Options 2 x Project General viDL Compile Assemble Link Load al gt Category General General r Code Generation P reprocessor Enable optimid Processor Waring _ g J pimantan SIZE V Generate debug information m Language Dialect B Pointers to const may point T Disable built in functions paa cent dee PS Ger erceptions ata Fini Non standard circular buffer I Disable keyword extensions idiom rl Do not treat FP operations E Disable hardware circular as assoc
313. macros 1 147 __ADSP2191 95 96 990__ 1 148 __ADSP2192_12__ 1 148 __ADSP21XX__ 1 148 __ANALOG_EXTENSIONS __ I 22 VisualDSP 3 0 C C Compiler and Library Manual for ADSP 219x DSPs 1 148 __cplusplus 1 148 __DOUBLES_ARE_FLOATS__ 1 148 __ECC__ 1 148 __EDG __ 1 148 __EDG_VERSION__ 1 148 __FILE_ 1 148 __LINE_ 1 148 __NO_BUILTIN 1 148 __SIGNED_CHARS ___ 1 149 __ STDC__ 1 149 __STDC_VERSION__ 1 149 __TIME_ 1 149 __VERSION__ 1 149 _LANGUAGE C 1 148 _NO_LONG_LONG 1 148 prelinker 1 58 preprocessing IDL files 1 152 preprocessor macros 1 147 primitive I O functions 3 13 printable character test see isprint function printf flushing output 3 15 printf write formatted stream output to standard out function 3 105 proc target processor compiler switch 1 41 procedural optimizations 1 56 procedure call 1 159 profile guided optimization 2 30 program control functions calloc 3 41 free 3 71 malloc 3 93 realloc 3 110 program termination 3 52 punctuation character test ispunct function 3 82 Q qsort quicksort function 3 105 qsort function 3 105 R R disable source path compiler switch 1 43 R directory add source directory compiler switch 1 42 raise raise a signal function 3 107 rand random number generator function 3 109 random number see rand srand functions 3 109 read operation 3 14 realloc change memory allocation function 3 110 real time signals see clear_interrupt interr
314. maximum representable value when processing signal data use saturated arithmetic Saturated arithmetic forces an overflowed value to become the maximum representable value The mode is set to be saturated or default with the set_saturate_mode and reset_saturate_mode functions Each arithmetic operator has its corresponding variant effected in the saturated mode For example add_sat sub_sat neg_sat Preprocessor Generated Warnings The preprocessor directive twarning causes the preprocessor to generate a warning and continue preprocessing The text on the remainder of the line that follows warning is used as the warning message VisualDSP 3 5 C C Compiler and Library Manual 1 93 for ADSP 219x DSPs C C Compiler Language Extensions C Style Comments The compiler accepts C style comments beginning with and ending at the end of the line in C programs This is essentially compatible with standard C except for the following case a b highly unusual c which a standard C compiler processes as a b c Compiler Built In Functions The compiler supports intrinsic functions that enable efficient use of hardware resources Knowledge of these functions is built into the cc219x compiler Your program uses them via normal function call syntax The compiler notices the invocation and generates one or more machine instructions just as it does for normal operators such as and Built in functions ha
315. min expands to and min can be used freely within a larger expression because it expands to an expression Labels local to a statement expression can be declared with the __label__ keyword For example d __label__ exit VisualDSP 3 5 C C Compiler and Library Manual 1 139 for ADSP 219x DSPs C C Compiler Language Extensions initis for i 0 p i i int d get p i if check d goto exit process d exit VOTS i Statement expressions are not supported in C mode i Statement expressions are an extension to C originally imple mented in the GCC compiler Analog Devices support the extension primarily to aid porting code written for that compiler When writing new code consider using inline functions which are compatible with ANSI ISO standard C and C99 and are as effi cient as macros when optimization is enabled Type Reference Support Keyword Typeof The typeof expression construct can be used as a name for the type of expression without actually knowing what that type is It is useful for making source code that is interpreted more than once such as macros or include files more generic The typeof keyword may be used where ever a typedef name is permitted such as in declarations and in casts This example define abs a typeof a __a a if _a lt 0 _a _ a a ge o shows typeof used in conjunction with a statement expression to define a generic mac
316. move unneeded data and code If the code produced with 0s and e does not meet the code size constraint some analysis of the source code will be required to try to reduce the code size further Note that loop transformations such as unrolling and software pipelining increase code size But it is these loop transformations that also give the greatest performance benefit Therefore in many cases compiling for min imum code size will produce significantly slower code than optimizing for speed The compiler provides a way to balance between the two extremes of 0 and 0s This is the sliding scale 0v num switch adjustable using the optimization slider bar under Project Options in the VisualDSP IDDE described on page 1 38 The num is a value between 0 and 100 where the lower value corresponds to minimum code size and the upper to maximum performance A value in between will try to optimize the fre VisualDSP 3 5 C C Compiler and Library Manual 2 29 for ADSP 219x DSPs Smaller Applications Optimizing for Code Size quently executed regions of code for maximum performance while keeping the infrequently executed parts as small as possible The switch is most reliable when using profile guided optimization since the execution counts of the various code regions have been measured experimentally Without PGO the execution counts are estimated based on the depth of loop nesting Tip Avoid the use of inline code Avoid using t
317. mpiled to preserve most registers to ensure that any other registers aside from AX1 AYO AY1 AR M7 and the condition codes will not be modified by the function If any other regis ters are used in the compilation of the function they will be saved and restored during the function prologue and epilogue In general it is not very helpful to specify any of the condition codes as call preserved as they are difficult to save and restore and are usually clob bered by any function Moreover it is usually of limited benefit to be able to keep them live across a function call Therefore it is better to use CCset all condition codes rather than ASTAT in the clobbered set above For more information refer to pragma regs_clobbered string on page 1 130 2 34 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Achieving Optimal Performance from C C Source Code pragma optimize_ off for_speed for_space as_cmd_line The optimize_ pragma may be used to change the optimization setting on a function by function basis In particular it may be useful to optimize functions that are rarely called for example error handling code for space using pragma optimize_for_space whereas functions critical to performance should be compiled for maximum speed pragma optimize_for_speed The pragma optimize_off is useful for debugging specific functions without increasing the size or decreasing the performance of the o
318. mpression Synopsis include lt filter h gt void a_compress in out n const short inl Input array short out Output array int n Number of elements to be compressed Description The a_compress function takes a vector of linear 13 bit signed speech samples and performs A law compression according to ITU recommenda tion G 711 Each sample is compressed to 8 bits and is returned in the vector pointed to by out Algorithm C k a law compression of A k for k 0 to n 1 Domain content of input array 4096 to 4095 VisualDSP 3 5 C C Compiler and Library Manual 4 23 for ADSP 219x DSPs DSP Run Time Library Reference a_expand A law expansion Synopsis include lt filter h gt void a_expand in out n const short in Input array Xj short out Output array int n Number of elements to be expanded Description The a_expand function inputs a vector of 8 bit compressed speech sam ples and expands them according to ITU recommendation G 711 Each input value is expanded to a linear 13 bit signed sample in accordance with the A law definition and is returned in the vector pointed to by out Algorithm C k a law expansion of A k for k 0 to n 1 Domain content of input array 0 to 255 4 24 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs DSP Run Time Library alog anti log Synopsis d Finclude lt math h gt double alog double x
319. mum compiler errors compiler switch 1 49 white space character test see isspace function workaround hardware defect 1 50 workaround compiler switch 1 50 Wremarks enable diagnostic warnings compiler switch 1 49 write operation 3 14 write files enable driver I O redirection compiler switch 1 50 write opts compiler switch 1 50 writes array element 2 19 writing preprocessor macros 1 149 Wterse enable terse warnings compiler switch 1 49 X xref cross reference list compiler switch 1 51 Z zero length arrays 1 143 zero_cross count zero crossing function 4 109 I 28 VisualDSP 3 0 C C Compiler and Library Manual for AD
320. n Time Library Table 3 15 Interrupt Function Signals Values and Meanings Cont d Sig Value Definition SIGTERM software interrupt SIGFPE software interrupt The interrupt functions cause the receipt of the signal number sig to be handled in one of the following ways e SIG DFL The default action is taken e SIG_IGN The signal is ignored e Function Address The function pointed to by func is executed The function pointed to by func is executed each time the interrupt is received The interrupt function must be called with the S1G_IGN argu ment to disable interrupt handling Interrupts are not nested by the default start up file Error Conditions The interrupt functions return SIG_ERR and set errno equal to SIG_ERR if the requested interrupt is not recognized Example include lt signal h gt void handler int sig Interrupt Service Routine ISR main enable power down interrupt and register ISR interrupt SIG_PWRDWN handler disable power down interrupt VisualDSP 3 5 C C Compiler and Library Manual 3 65 for ADSP 219x DSPs C Run Time Library Reference See Also signal terrupt SIG_PWRDWN SIG_IGN enable power down interrupt and register ISR terruptf SIG_PWRDWN handler disabl e power down interrupt terruptf SIG_PWRDWN SIG_IGN raise 3 66 VisualDSP 3 5 C C Compiler and Library
321. n base is 16 and those letters and digits which represent an integer with a radix of base The letters a z or A Z are assigned the values 10 to 35 and are permitted only when those values are less than the value of base If base is zero the base is taken from the initial characters A leading 0x indicates base 16 a leading 0 indicates base 8 For any other leading char acters base 10 is used If base is between 2 and 36 it is used as a base for conversion 3 144 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library Error Conditions The strtoul function returns a zero if no conversion can be made and a pointer to the invalid string is stored in the object pointed to by endptr If the correct value results in an overflow ULONG_MAX is returned ERANGE is stored in errno in the case of overflow Example include lt stdlib h gt define base 10 char rem unsigned long int i i strtoul 2345 5 amp rem base 7 2345 rem 5 See Also atoi atol strtol VisualDSP 3 5 C C Compiler and Library Manual 3 145 for ADSP 219x DSPs C Run Time Library Reference strxfrm transform string using LC_COLLATE Synopsis include lt string h gt size_t strxfrm char sl1 const char s2 size_t n Description The strxfrm function transforms the string pointed to by s2 using the locale specific category LC_COLLATE and copies no more than n characters of th
322. n rectan gular coordinates typedef struct float re float im complex_float typedef struct double re double im complex_double typedef struct fractl6o re fractl6o im complex_fractl6 Details of the basic complex arithmetic functions are included in DSP Run Time Library Reference on page 4 22 Table 4 1 Complex Functions Description Prototype Complex Absolute double cabs complex_double a Value float cabsf complex_float a fractl6 cabs_frl6 complex_fractl6 a Complex Addition complex_double cadd complex_double a complex_double b complex_float caddf complex_float a complex_float b complex_fractl16 cadd_frl6 complex_fractl6 a complex_fractl6 b Complex complex_double csub complex_double a complex_double b Subtraction complex_float csubf complex_float a complex_float b complex_fractl6 csub_frl6 complex_fractl6 a complex_fractl6 b VisualDSP 3 5 C C Compiler and Library Manual 4 5 for ADSP 219x DSPs DSP Run Time Library Guide Table 4 1 Complex Functions Cont d Description Prototype Complex Multiply complex_double cmlt complex_double a complex_double b complex_float cmltf complex_float a complex_float b complex_fractl16 cmlt_frl6 complex_fractl6 a complex_fractl6 b Complex Division complex_double cdiv complex_double a complex_double b complex_float cdivf complex_float a comp
323. n which to instantiate all required instances automatically during the prelinking process pragma instantiate instance The pragma instantiate instance requests the compiler to instantiate instance in the current compilation For example tpragma instantiate class Stack lt int gt will cause all static members and member functions for the int instance of a template class Stack to be instantiated whether they are required in this compilation or not The example pragma instantiate void Stack lt int gt push int will cause only the individual member function Stack lt int gt push int to be instantiated VisualDSP 3 5 C C Compiler and Library Manual 1 135 for ADSP 219x DSPs C C Compiler Language Extensions pragma do_not_instantiate instance The pragma do_not_instantiate instance directs the compiler not to instantiate instance in the current compilation For example pragma do_not_instantiate int Stack lt float gt use_count will prevent the compiler from instantiating the static data member Stack lt float gt use_count in the current compilation pragma can_instantiate instance The pragma can_instantiate instance tells the compiler that if instance is required anywhere in the program it should be instantiated in this compilation Currently this pragma forces the instantiation even if it is not required anywhere in the program Therefore it has the same effect as pragma instantia
324. nctions All these services are Analog Devices extensions to ANSI standard C These functions are in addition to the C C run time library functions that are described in Chapter 3 C C Run Time Library For more information on the algorithms on which many of DSP run time library s math functions are based see the Cody and Waite text Software Manual for the Elementary Functions from Prentice Hall 1980 This chapter contains e DSP Run Time Library Guide on page 4 2 It contains information about the library and provides a descrip tion of the DSP header files that are included with this release of the cc219x compiler e DSP Run Time Library Reference on page 4 22 It provides the complete reference for each DSP run time library function provided with this release of the cc219x compiler VisualDSP 3 5 C C Compiler and Library Manual 4 for ADSP 219x DSPs DSP Run Time Library Guide DSP Run Time Library Guide The DSP run time library contains functions that you can call from your source program This section describes how to use the library and provides information on the following topics e Calling DSP Library Functions e Linking DSP Library Functions on page 4 3 e Working with Library Source Code on page 4 3 e DSP Header Files on page 4 4 Calling DSP Library Functions To use a DSP library function call the function by name and give the appropriate arguments The n
325. nd unless the output operand has the amp constraint modifier This situation can occur because the com piler assumes that the inputs are consumed before the outputs are produced This assumption may be false if the assembler code actually consists of more than one instruction In such a case use amp for each output operand that must not overlap an input or supply an amp for the input operand Operand constraints indicate what kind of operand they describe by means of preceding symbols The possible preceding symbols are no sym bol amp and no symbol The operand is an input It must appear as part of the third argument to the asm construct The allo cated register will be loaded with the value of the C C expression before the asm template is exe cuted Its C C expression will not be modified by the asm and its value may be a constant or literal Example d e symbol The operand is an output It must appear as part of the second argument to the asm construct Once the asm template has been executed the value in the allocated register is stored into the location indi cated by its C C expression therefore the VisualDSP 3 5 C C Compiler and Library Manual 1 69 for ADSP 219x DSPs C C Compiler Language Extensions symbol symbol amp symbol expression must be one that would be valid as the left hand side of an assignment Example d The operand is b
326. ne and import the symbol by declaring the symbol as extern in the C C program Alternatively the cc219x compiler provides an asm linkage specifier used similarly to the C linkage specifier of C which when used removes the need to add an underscore prefix to the symbol that is defined in assembly Table 1 18 shows several examples of the C C and assembly interface naming conventions 1 174 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Table 1 18 C C Naming Conventions for Symbols Compiler In C C Program In Assembly Subroutine int c_var declared global extern _c_var void c_func in C code extern _c_func void cpp_func void in C source extern _cpp_func__Fv extern int asm_var global _asm_var extern void asm_func global _asm_func _asm_func extern asm void asm_func global asm_func asm_func VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs 1 175 C C and Assembly Language Interface C Programming Examples This section shows examples of the features specific to C These exam ples are e Using Fract Type Support on page 1 176 e Using Complex Number Support on page 1 177 By default the cc219x compiler runs in C mode To run the compiler in C mode use the corresponding option on the command line or select the option
327. ne breaks do not need to be escaped in any way They are replaced by the character n in the generated string This extension is not supported in C mode The extension is not compatible with many dialects of C including ANSI ISO C89 and C99 However it is useful in asm statements which are intrinsically non portable Arithmetic on Pointers to Void and Pointers to Functions Addition and subtraction is allowed on pointers to void and pointers to functions The result is as if the operands had been cast to pointers to char The sizeof operator returns one for void and function types Cast to Union A type cast can be used to create a value of a union type by casting a value of one of the unions member s types Ranges in Case Labels A consecutive range of values can be specified in a single case by separat ing the first and last values of the range with For example case 200 300 Declarations mixed with Code In C mode the compiler will accept declarations in the middle of code as in C99 and C This allows the declaration of local variables to be placed at the point where they are required Therefore the declaration can be combined with initialization of the variable 1 144 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler For example in the following function void func Key k Node p list while p amp amp p gt key k p p gt next if lp return Data d p g
328. ng constants enable the programmer to specify the exact bit pattern required for a floating point constant For example the declaration 1 142 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler float f Oxlp 126f causes f to be initialized with the value 0x800000 Hexadecimal floating constants are not supported in C mode Zero Length Arrays Arrays may be declared with zero length This is an anachronism sup ported to provide compatibility with GCC Use variable length array members instead Variable Argument Macros The final parameter in a macro declaration may be followed by to indi cate the parameter stands for a variable number of arguments For example define trace msg args fprintf stderr msg HE args can be used with differing numbers of arguments trace got here n trace i 4d n i trace x f y 4f n x y The operator has a special meaning when used in a macro definition before the parameter that expands the variable number of arguments if the parameter expands to nothing then it removes the preceding comma The variable argument macro syntax comes from GCC It is not compatible with C99 variable argument macros and is not sup ported in C mode VisualDSP 3 5 C C Compiler and Library Manual 1 143 for ADSP 219x DSPs C C Compiler Language Extensions Line Breaks in String Literals String literals may span many lines The li
329. nition preceded by a declaration has the desired effect For example extern int f int int asm func int f int a int b Function Variable and Type Attribute Keyword __attribute__ The __attribute__ keyword can be used to specify attributes of functions variables and types as in these examples void func void __attribute__ section fred int a __attribute__ aligned 8 typedef struct int al4 __attribute__ aligned 4 Q The __attribute__ keyword is supported and therefore code written for GCC can be ported All attributes accepted by GCC on 1x86 are accepted The ones that are actually interpreted by the compiler are described in the sections of this manual describing the corresponding pragmas see Pragmas on page 1 119 1 146 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler Preprocessor Features The cc219x compiler provides standard preprocessor functionality as described in any C text The following extensions to standard C are also supported end of line C style comments d warning directive For more information about these extensions refer to Preprocessor Gen erated Warnings on page 1 93 and C Style Comments on page 1 94 This section contains e Predefined Preprocessor Macros e Header Files on page 1 149 e Writing Preprocessor Macros on page 1 149 e Preprocessing of IDL Files on page 1 151 Pr
330. nline code and does not have to assume that scratch registers and condition states are modified by the call Prime candidates for inlining are small fre quently used functions because they will cause the least code size increase while giving most performance benefit VisualDSP 3 5 C C Compiler and Library Manual 2 13 for ADSP 219x DSPs General Guidelines As an example of the usage of the inline keyword the function below sums two input parameters and returns the result inline int add int a int b return atb Good use of the inline keyword Inlining has a code size to performance trade off that should be consid ered when it is used With 0a the compiler will automatically inline small functions where possible If the application has a tight upper code size limit the resulting code size expansion may be too great It is worth considering using automatic inlining in conjunction with the 0v n switch on page 1 38 to restrict inlining and other optimizations with a code size cost to parts of the application that are performance critical This will be considered in more detail later in this chapter Using Inline asm Statements The compiler allows use of inline asm statements to insert small sections of assembly into C code Tip Avoid use of inline asm statements where built in functions may be used instead The compiler does not intensively optimize code that contains inline asm statements because it has lit
331. nput matrix 1 number of rows in matrix 1 number of columns in matrix 1 pointer to input matrix 2 pointer to output matrix RY xJ E auf x This function computes the two dimensional convolution of matrix minl size mrowl x mcoll with matrix min2 size 3x3 Algorithm Two dimensional input matrix min1 is convolved with input matrix min2 placing the result in a matrix pointed to by mout 2 2 mout erJ gt gt minl c i r j min2 2 i 2 j i 0 j 0 for c 0 to mcoll1 2 and r 0 to mrow1 2 Domain 1 0 to 1 0 4 50 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs DSP Run Time Library copysign copy the sign Synopsis d Finclude lt math h gt float copysignf float parml float parm2 double copysign double parml double parm2 fractl6 copysign_frl6 fractl6 parml fractl6 parm2 Description This function copies the sign of the second argument to the first argument Algorithm return parml copysignof parm2 Domain Full range for type of parameters used VisualDSP 3 5 C C Compiler and Library Manual 4 5 for ADSP 219x DSPs DSP Run Time Library Reference cot cotangent Synopsis d Finclude lt math h gt float cotf float a double cot double a Description This function calculates the cotangent of its argument a which is mea sured in radians If a is outside of the domain the function returns 0 Algorithm c cot
332. nput vector a Domain 3 4 x 1038 to 3 4 x 1038 for autocohf 1 0 to 1 0 for autocoh_fr16 4 28 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs DSP Run Time Library autocorr autocorrelation Synopsis d Finclude lt stats h gt void autocorrf a n m c const float al Input vector a int n Number of input samples int m Lag count float cl Output vector c void autocorr_frl6 a n m c const fractl6 al Input vector a int n Number of input samples int m Lag count Fractl6 c Output vector c Description This function computes the autocorrelation of the input elements con tained within input vector a and stores the result to output vector c The autocorr function is used in digital signal processing applications such as speech analysis Algorithm n k 1 1 Ch EK b a iy j 0 where k 0 1 m 1 Domain 3 4 x 10 8 to 3 4 x 10 8 for autocorrf 1 0 to 1 0 for autocorr_frl6 VisualDSP 3 5 C C Compiler and Library Manual 4 29 for ADSP 219x DSPs DSP Run Time Library Reference cabs complex absolute value Synopsis include lt complex h gt float cabsf complex_float a double cabs complex_double a fractl6 cabs_frl6 complex_fractl6 a Description This function computes the complex absolute value of a complex input and returns the result Algorithm c JRe a Im a
333. ns 1 9 GCC compatibility 1 138 I O files 1 9 legacy support A 3 optimization switch 1 30 optimizer 2 4 overview 1 2 running 1 7 setting maximum error number 1 49 specifying functional options 1 11 compiler common switches filename command file 1 22 A assert compiler switch 1 22 alttok alternative tokens 1 23 bss 1 23 build lib 1 24 C comments 1 24 c compile only 1 24 const read write 1 24 D define macro 1 24 debug types 1 25 default linkage tool 1 25 dry verbose dry run 1 25 dryrun terse dry run 1 26 E stop after preprocessing 1 26 ED run after preprocessing to file 1 26 EE run after preprocessing 1 26 extra keywords 1 26 flags command line input 1 27 force circbuf 1 27 fp associative floating point associative operation 1 27 full version display versions 1 27 g generate debug information 1 28 H list headers 1 28 h elp command line help 1 29 HH list headers and compile 1 28 i less includes 1 30 I start include directory 1 29 I directory include search directory 1 29 include include file 1 30 ipa interprocedural analysis 1 30 jump select jump table memory type 1 31 l link library 1 31 L directory library search directory 1 31 M make rules only 1 32 map filename generate a memory map 1 33 MD generate make rules and compile 1 32 mem invoke memory initializer 1 6 Visu
334. ns and should not be deleted manually unless the associ ated object file is also deleted All of the ipa optimizations are invoked after the initial link when a spe cial program has called the prelinker re invokes the compiler to perform the new optimizations Because a file may be recompiled by the prelinker you cannot use the S option to see the final optimized assembler file when ipa is enabled Instead you must use the save temps switch so that the full com pile link cycle can be performed first Because IPA operates only during the final link the ipa switch has no benefit when compiling the source files to object format for inclusion in a library Although IPA will generate usage information for potential addi tional optimizations at the final link stage neither the usage information nor the module s source file are available when the linker includes a mod ule from a library Therefore each library module is compiled to the normal 0 optimization level The prelinker inspects object modules included from libraries and other object files which were not compiled with the ipa switch to see whether there are hidden references to the functions and variables defined in those objects which were compiled with the ipa switch and optimizes those variables and functions accordingly 1 58 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler C C Compiler Language Extensions The compiler suppor
335. nstant initializers lets you use non constants as elements of aggregate initializers for automatic variables For more information see Non Constant Aggregate Initializer Support on page 1 87 Indexed initializers Support for indexed initializers lets you specify elements of an aggregate initializer in an arbitrary order For more information see Indexed Initializer Support on page 1 87 Preprocessor generated warnings Support for generating warning messages from the preprocessor For more information see Preprocessor Generated Warnings on page 1 93 C style comments Support for C style comments in C programs For more information see C Style Comments on page 1 94 VisualDSP 3 5 C C Compiler and Library Manual 1 61 for ADSP 219x DSPs C C Compiler Language Extensions Inline Function Support Keyword inline The inline keyword directs cc219x to integrate the code for the function you declare as inline into the code of its callers Inline function support and the inline keyword is a standard feature of C the compiler pro vides it as a C extension Using this keyword eliminates the function call overhead and therefore can increase the speed of your program s execu tion Argument values that are constant and that have known values may permit simplifications at compile time The following example shows a function definition that uses the inline keyword
336. nter faces such that functions like sin can be directly called with the proper size operands Therefore float sinf float 32 bit double sin double 32 bit For full descriptions of these functions and their implementation see Chapter 4 DSP Run Time Library VisualDSP 3 5 C C Compiler and Library Manual 1 55 for ADSP 219x DSPs Compiler Command Line Interface Optimization Control The general aim of compiler optimizations is to generate correct code that executes fast and is small in size Not all optimizations are suitable for every application or possible all the time so the compiler optimizer has a number of configurations or optimization levels which can be applied when suitable Each of these levels are enabled by one or more compiler switches and VisualDSP project options or pragmas Refer Chapter 2 Achieving Optimal Performance from C C Source Code for information on how to obtain maximal code per formance from the compiler The following list identifies several optimization levels The levels are notionally ordered with least optimization listed first and most optimiza tion listed last The descriptions for each level outline the optimizations performed by the compiler and identifies any switches or pragmas required or that have direct influence on the optimization levels performed e Debug The compiler produces debug information to ensure that the object code matches the app
337. nter if the key is not found in the array VisualDSP 3 5 C C Compiler and Library Manual 3 39 for ADSP 219x DSPs C Run Time Library Reference Example d Finclude lt stdlib h gt char answer char base 50 3 answer bsearch g base 50 3 strcmp See Also qsort 3 40 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library calloc allocate and initialize memory Synopsis include lt stdlib h gt void calloc size_t nmemb size_t size Description The calloc function dynamically allocates a range of memory and initial izes all locations to zero The number of elements the first argument multiplied by the size of each element the second argument is the total memory allocated The memory may be deallocated with the free function Error Conditions The calloc function returns a null pointer if unable to allocate the requested memory Example include lt stdlib h gt int pers ptr int calloc 10 sizeof int ptr points to a zeroed array of length 10 See Also free malloc realloc VisualDSP 3 5 C C Compiler and Library Manual 3 41 for ADSP 219x DSPs C Run Time Library Reference ceil ceiling Synopsis d Finclude lt math h gt double ceil double float ceilf float Description The ceil functions return the smallest integral value that is not less than its input Error Conditions The ceil functions d
338. nual for ADSP 219x DSPs C C Run Time Library t strtok NULL t points to phrase a t strtok NULL t points to to be tested t strtok NULL t points to today t strtok NULL t NULL E See Also No references to this function VisualDSP 3 5 C C Compiler and Library Manual 3 141 for ADSP 219x DSPs C Run Time Library Reference strtol convert string to long integer Synopsis Finclude lt stdlib h gt long int strtol const char nptr char endptr int base Description The strtol function returns as a long int the value that was represented by the string nptr If endptr is not a null pointer strtol stores a pointer to the unconverted remainder in endptr The strtol function breaks down the input into three sections white space as determined by isspace initial characters and unrecognized characters including a terminating null character The initial characters may comprise an optional sign character 0x or 0X when base is 16 and those letters and digits which represent an integer with a radix of base The letters a z or A Z are assigned the values 10 to 35 and are permitted only when those values are less than the value of base If base is zero the base is taken from the initial characters A leading 0x indicates base 16 a leading 0 indicates base 8 For any other leading char acters base 10 is used If base is between 2 and 36 it is used as
339. o not return an error condition Example include lt math h gt double y y ceil 1 05 fey 2 0 f y ceilf 1 05 y 1 0 See Also floor 3 42 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library clear_interrupt clear a pending signal Synopsis d Finclude lt signal h gt int clear_interrupt int sig Description The clear_interrupt function clears the signal sig in the IRPTL register The sig argument must be one of the processor signals shown below for the ADSP 219x DSPs Table 3 14 ADSP 219x Signals Sig Value Definition SIG_PWRDWN power down interrupt SIG_STACKINT PC LOOP or COUNTER overflow on push or on pop when empty SIG_KERNEL kernel interrupt SIG_INT4 user assignable SIG_INT5 user assignable SIG_INT6 user assignable SIG_INT7 user assignable SIG_INTS user assignable SIG_INT9 user assignable SIG_INT10 user assignable SIG_INT11 user assignable SIG_INT12 user assignable SIG_INT13 user assignable VisualDSP 3 5 C C Compiler and Library Manual 3 43 for ADSP 219x DSPs C Run Time Library Reference Error Conditions The clear_interrupt function returns a 1 if the interrupt was pending a 1 if the parameter is not a valid signal or 0 is returned otherwise Example d Finclude lt signal h gt clear_interrupt SIG_PWRDWN clear the interrupt 2 latch See Also
340. o value Error Conditions The iscntr function does not return any error conditions Example include lt ctype h gt int ch for ch 0 ch lt Ox7f ch printf 04x ch printf 2s iscntrl ch control putchar n See Also isalnum isgraph VisualDSP 3 5 C C Compiler and Library Manual 3 73 for ADSP 219x DSPs C Run Time Library Reference isdigit detect decimal digit Synopsis include lt ctype h gt int isdigit int c Description The isdigit function determines if the input character is a decimal digit 0 9 If the input is not a digit isdigit returns a zero If the input is a digit isdigit returns a non zero value Error Conditions The isdigit function does not return an error condition Example include lt ctype h gt int ch for ch 0 ch lt Ox7f cht printf 04x ch printf 42s isdigit ch digit putchar n See Also isalpha isalnum isxdigit 3 74 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library isgraph detect printable character not including white space Synopsis dFinclude lt ctype h gt int isgraph int c Description The isgraph function determines if the argument is a printable character not including a white space 0x21 0x7e If the argument is not a printable character isgraph returns a zero If the argument is a printable character isgraph re
341. ocation like function calls This will make your source code easier to read and maintain The following two code segments define two versions of the macro SKIP_SPACES SKIP_SPACES regular macro define SKIP_SPACES p limit char lim limit while p lim Tt CACHE Lar Cpijrese break Ay FA SKIP_SPACES enclosed macro define SKIP_SPACES p limit do char lim limit while p lim Tt CEC PD HE ee so p break while 0 The second definition is the same as the first except that it is enclosed in a do while 0 construct Enclosing the definition within the do while 0 pair means that the macro can be invoked more like a function With the first definition sometimes you would have to follow the macro with a semi colon and sometimes you would not Whereas with the sec ond definition the do while 0 pair means that the macro is followed by a semi colon 1 150 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler With the do while 0 construct you can treat the macro as a func tion and put the semicolon after it For example SKIP_SPACES enclosed macro ends without if Ap t 0 SKIP_SPACES p lim else m This expands to if p 0 do while 0 else Without the do while 0 construct the expansion would be if p 0
342. oercions These operations may require implicit calls to library functions For more details see Data Types on page 2 7 Avoiding Non Unit Strides If you write a loop such as for i 0 i lt n i 3 some code Bad non unit stride means division may be required then in order for the compiler to turn this into a hardware loop it will need to work out the loop trip count To do so it must divide n by 3 The compiler will decide that this is worthwhile as it will speed up the loop but as discussed above division is an expensive operation Try to avoid creating loop control variables with strides of non unit magnitude Loop Control i Tip Use int types for loop control variables and array indices i Tip Use automatic variables for loop control and loop exit test For loop control variables and array indices it is always better to use signed ints rather than any other integral type The C standard requires various type promotions and standard conversions that complicate the code for the compiler optimizer Frequently the compiler is still able to VisualDSP 3 5 C C Compiler and Library Manual 2 21 for ADSP 219x DSPs Loop Guidelines deal with such code and create hardware loops and pointer induction vari ables However it does make it more difficult for the compiler to optimize and may occasionally result in under optimized code The same advice goes for using automatic local variables for loop con
343. of the FFT function are provided by the library correspond ing to radix 2 radix 4 and two dimensional FFTs The number of points is provided as an argument The twiddle table for the FFT functions is supplied as a separate argument and is normally calculated once during program initialization Library functions are provided to initialize a twiddle table A table can accommodate several FFTs of different sizes by allocating the table at maximum size and then using the stride argument of the FFT function to specify the step size through the table If the stride argument is set to 1 the FFT function will use all the table if the FFT uses only half the num ber of points of the largest the stride should be 2 The functions defined in the filter h header file are listed in Table 4 2 and Table 4 3 and are described in detail in DSP Run Time Library Ref erence on page 4 22 Table 4 2 Filter Library Description Prototype Finite Impulse void fir_frl6 Response Filter const fractl6 x fractl y int n fir_state_frl6 s Infinite Impulse void iir_frl6 Response Filter const fractl6 x fractl6 yl int n iir_state_frl6 s FIR Decimation void fir_decima_frl6 Filter const fractl6 x fractl6 yl int n fir_state_frl6 s FIR Interpolation void fir_interp_fr16 Filter const fractl6 x fractl6 yl int n fir_state_frl6 s Complex Finite Impulse void c
344. of the string Example include lt string h gt char ptrl ptr2 ptrl TESTING ptr2 strchr ptrl E ptr2 points to the E in TESTING See Also memchr strrchr 3 122 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library strcmp compare strings Synopsis d Finclude lt string h gt int strcmp const char sl const char s2 Description The strcmp function lexicographically compares the null terminated strings pointed to by s1 and s2 It returns a positive value if the s1 string is greater than the s2 string a negative value if the s2 string is greater than the s1 string and a zero if the strings are the same Error Conditions The strcmp function does not return an error condition Example d Finclude lt string h gt char string1 50 string2 50 if stremp stringl string2 o printf s is different than 4s n stringl string2 See Also memcmp strncmp VisualDSP 3 5 C C Compiler and Library Manual 3 123 for ADSP 219x DSPs C Run Time Library Reference strcoll compare strings Synopsis include lt string h gt int strcoll const char sl const char s2 Description The strcol1 function compares the string pointed to by s1 with the string pointed to by s2 The comparison is based on the locale macro LC_COLLATE Because only the C locale is defined in the ADSP 219x DSP environment the strcol1 function
345. og2 n Algorithm n 1 n 1 y f i D Dak rernenrn k 0 0 where i 0 1 n 1 j 0 1 2 n 1 Domain Input sequence length n must be a power of two and at least 16 VisualDSP 3 5 C C Compiler and Library Manual 4 4 for ADSP 219x DSPs DSP Run Time Library Reference cfir complex finite impulse response filter Synopsis include lt filter h gt void cfir_frl6 x y n s const complex_fractl6 x complex_fractl6 y int n cfir_state_frl6 s Input sample vector x Output sample vector y Number of input samples Pointer to filter state structure RN Xf af The function uses the following structure to maintain the state of the filter typedef struct int k complex_fractl6 h complex_fractl6 d complex_fractl6 p cfir_state_frl6 Description Number of coefficients Filter coefficients Start of delay line Read write pointer a Si ane xf The cfir_fr16 function implements a complex finite impulse response CFIR filter It generates the filtered response of the complex input data x and stores the result in the complex output vector y The function maintains the filter state in the structured variable s which must be declared and initialized before calling the function The macro cfir_init in the filter h header file is available to initialize the struc ture and is defined as 4 42 VisualDSP 3 5 C C Compiler and Library
346. ogramming language does not include a basic type for fractional data and rather than introduce a non standard type Analog Devices defines fractl6andfract32 in terms of appropriately sized integer data types and provides sets of basic intrinsic functions which perform the required operations These look like library function calls but are spe cially recognized by the compilers which generate short sequences or single instructions exploiting any specialized features which may be avail able on the architecture An important aspect of this is that the compiler optimizer is not inhibited in any way by the use of these intrinsics Because of the varying nature of the architectures the basic intrinsic func tions just discussed cannot be standardized across all the architectures However a set of standard functions for manipulating fractional data has been defined by the ITU International Telecommunications Union and ETSI European Telecommunications Standards Institute Referred to as the ETSI Standard Functions these have been very widely used to implement Telecommunications packages such as GSM EFR and AMR Vocoders and have become a de facto industry standard These functions have been implemented on ADSP 219x DSPs The ETSI standard is aimed at DSP processors with 16 bit inputs satu rated arithmetic and 32 bit accumulators Calling ETSI Library Functions To use an ETSI function call the function by name and give the appropri ate
347. olean type support keywords bool true false twiddle factors for radix 2 FFT 4 102 twiddle factors for radix 4 FFT 4 104 twidfft2d function 4 106 twidfftrad2 function 4 102 twidfftrad4 function 4 104 type cast 1 144 conversions 1 80 typeof keyword 1 140 U U undefine macro compiler switch 1 25 1 47 unresolved symbol 1 103 unsigned bitfield make plain bitfields unsigned compiler switch 1 47 unsigned char make char unsigned compiler switch 1 48 upper case see isupper toupper functions user header files 1 149 Vv v version and verbose compiler switch 1 48 va_arg get next argument in variable list function 3 158 va_end reset variable list pointer function 3 160 va_start set variable list pointer function 3 161 val global add global names compiler switch 1 48 var variance function 4 108 variable argument macros 1 143 variable length argument list initializing 3 161 VCSE components 1 48 verbose display command line compiler switch 1 48 version display version switch 1 49 VIDL source text 1 151 VisualDSP C C language extensions 1 59 1 60 IDDE 1 3 1 11 Kernel VDK 1 46 VisualDSP 3 0 C C Compiler and Library Manual for ADSP 219x DSPs simulator 1 166 volatile and asm C program constructs 1 75 WwW w disable all warnings compiler switch 1 50 w disable all warnings switch 1 49 warn protos prototypes warning compiler switch 1 50 Werror limit maxi
348. ome_far_section int far abc 100 int near def 100 main assert sizeof amp abc 2 amp amp sizeof amp def 1 Conversions Between Far and Near Pointers Conversions between far and near pointers are valid The compiler will truncate the Most Significant Word MSW of a far pointer when con verting a far pointer to a near pointer The conversion from a near pointer will be done by making the MSW of the output far pointer the same as that of the internal data area Care should be taken to avoid de referencing truncated far pointers as the data accessed will be in the internal memory area The compiler will gen erate a warning when it sees a conversion from a far pointer to a near pointer For example int near near_iptr int far far_iptr void trunc_far int far i near_iptr i truncate MSW leaving LSW will cause a compiler warning void extend_far int near i Kar aiptr 13 extend MSW with value of internal memory addresses VisualDSP 3 5 C C Compiler and Library Manual 1 101 for ADSP 219x DSPs C C Compiler Language Extensions Addressing Far Data The result of the address operator amp when used to generate the address of data which is declared as being in far memory will be a far pointer type C Function Overloading The compiler in C mode will allow function overloading of parame ters types for different far and near
349. ommand Line Interface W The w disable all warnings switch directs the compiler not to issue warnings You can invoke this switch by selecting the Disable all warnings and remarks check box in the VisualDSP Project Options dia log box Compile tab Warning selection warn protos The warn protos prototypes warning switch directs the compiler to produce a warning message when a function is called without a full proto type being supplied workaround lt workaround gt lt workaround gt The workaround switch enables code generator workaround for specific hardware defects Example of a valid workaround type32a anomaly write files The write files enable driver I O redirection switch directs the com piler driver to redirect the file name portions of its command line through a temporary file This technique helps with handling long file names which can make the compiler drivers command line too long for some operating systems write opts The write opts switch directs the compiler to pass the user specified options but not the input file names to the main driver via a temporary file This can be helpful if the resulting main driver command line would otherwise be too long 1 50 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler xref lt filename gt The xref cross reference list switch directs the compiler to write cross reference listing information to the spec
350. ompiler also defines the SIGNED_CHARS__ macro This is the default mode when the unsigned char make char unsigned switch is not used syntax only The syntax only only check syntax switch directs the compiler to check the source code for syntax errors and warnings No output files will be generated with this switch sysdefs The sysdefs system definitions switch directs the compiler to define several preprocessor macros describing the current user and user s system The macros are defined as character string constants and are used in func tions with null terminated string arguments VisualDSP 3 5 C C Compiler and Library Manual 1 45 for ADSP 219x DSPs Compiler Command Line Interface The following macros are defined if the system returns information for them Macro Description HOSTNAME The name of the host machine _ MACHINE The machine type of the host machine __SYSTEM__ The OS name of the host machine __USERNAME__ The current user s login name __GROUPNAME__ The current user s group name __REALNAME__ The current user s real name __MACHINE__ __GROUPNAME__ and __ REALNAME__ are not available on Windows platforms T filename The T Linker Description File switch directs that the linker when invoked will use the specified Linker Description File LDF If T is not specified a default LDF file is selected based on the processor variant threads
351. ompiler and Library Manual for ADSP 219x DSPs Compiler version The version display compiler version switch directs the compiler to display its version information W error remark suppress warn number The W number override error message switch directs the compiler to override the specified diagnostic messages errors remarks or warn ings The num argument specifies the message to override At compilation time the compiler produces a number for each specific compiler diagnostic message The D discretionary string after the diag nostic message number indicates that the diagnostic may have its severity overridden Each diagnostic message is identified by a number that is used across all compiler software releases Werror limit number The Werror limit maximum compiler errors switch lets you set a max imum number of errors for the compiler Wremarks The Wremarks enable diagnostic warnings switch directs the compiler to issue remarks which are diagnostic messages that are even milder than warnings You can invoke this switch by selecting the Enable remarks check box in the VisualDSP Project Options dialog box Compile tab Warning selection Wterse The Wterse enable terse warnings switch directs the compiler to issue the briefest form of warnings This also applies to errors and remarks VisualDSP 3 5 C C Compiler and Library Manual 1 49 for ADSP 219x DSPs Compiler C
352. on the cc219x command line when the compiler was invoked The following shows example uses of these pragmas fpragma optimize_off void non_op non optimized code pragma optimize_for_space void op_for_si code optimized for size pragma optimize_for_speed void op_for_sp code optimized for speed subsequent functions declarations optimized for speed Linking Control Pragmas Linking pragmas change how a given global function or variable is viewed during the linking stage These pragmas are linkage_name retain_name and weak_entry pragma linkage_name identifier The pragma 1inkage_name associates the identifier with the next exter nal function declaration It ensures that identifier is used as the external reference instead of following the compiler s usual conventions 1 126 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler If identifier is not a valid function name as could be used in normal func tion definitions the compiler will generate an error See also the asm keyword described on page 1 145 The following shows an example use of this pragma pragma linkage_name realfuncname void funcname void func funcname compiler will generate a call to realfuncname pragma retain_name The pragma retain_name indicates that the external function or variable declaration that
353. oops If a loop contains conditional code control flow latencies may incur large penalties if the compiler has to generate conditional jumps within the loop In some cases the compiler will be able to convert IF THEN ELSE and constructs into conditional instructions In other cases it will be able to relocate the expression evaluation outside of the loop entirely How ever for important loops linear code should be written where possible The compiler will not perform the loop transformation that interchanges conditional code and loop structures Instead of writing for i 0 i1 lt 100 i if mult_by_b suml ali bli else sumi ali cli Bad loop contains conditional code it is better to write if mult_by_b for i 0 i lt 100 i suml ali b i else for i 0 i lt 100 i suml a i c i Good two simple loops can be optimized well if this is an important loop 2 20 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Achieving Optimal Performance from C C Source Code Avoiding Placing Function Calls in Loops The compiler will not usually be able to generate a hardware loop if the loop contains a function call due to the expense of saving and restoring the context of a hardware loop In addition to obvious function calls such as printf hardware loop generation can also be prevented by operations such as division modulus and some type c
354. operation on a pre sorted array Note that e base points to the start of the array e nelem is the number of elements in the array e size is the size of each element of the array e compare is a pointer to a function that is called by qsort to com pare two elements of the array The function should return a value less than equal to or greater than zero according to whether the first argument is less than equal to or greater than the second VisualDSP 3 5 C C Compiler and Library Manual 3 105 for ADSP 219x DSPs C Run Time Library Reference Return Value The qsort function returns no value Example d Finclude lt stdlib h gt float a 10 int compare_float const void a const void b float aval float a oat bval float b f aval lt bval return 1 else if aval bval return 0 else return 1 qsort a sizeof a sizeof aL0 sizeof aL0 compare_float See Also bsearch 3 106 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library raise force a signal Synopsis d Finclude lt signal h gt int raise int sig Description The raise function sends the signal sig to the executing program The raise function forces interrupts wherever possible and simulates an inter rupt otherwise The sig argument must be one of the signals listed in priority order in Table 3 16 Table 3 16 Raise Function Signals
355. or te Compier Cin Help arron aa 2 4 Using the Compiler OpPOmiZer a ccasesciicrnennstcdenaramnvarinscnes 2 4 Using the Statistical Profiler siccccsccanccenasicadenaciaemmeness 2 5 Using Interprocedural Optimization srsisrcsiitekiaisaetiiiisas 2 6 Data TYPES sonnen ninoi 2 7 Avoiding Emulared Arithmetic srssensnserarioinan 2 8 Gering the Most irom IPA onanccccoritoncantnieubadenaues 2 9 Initializing Constants Statically ccccecisesen etalon 2 9 ENS AEOS sanasini AA NAR 2 10 Indexed Arrays vs Pointers i oesiicen sic ctncreciecrnasnoinoceseawemoese 2 12 Trying Pointer and Indexed Styles sruiuimoriiititsnriikitia 2 12 Foncion UNR asrnane e seer erat Werlr Hetty 2 13 Usine Inline asmi Staremicnts rorcriniiean 2 14 Memory sate srisrrsresrerr tiran E 2 15 Loop Gude DAES reren iE eRe ea 2 17 Eecpine Loopt SKON oreca ana 2 17 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs XV CONTENTS Avoiding Unroling Loops ccmarscnncemcncenomnmancnenaniinnentetes 2 17 Avoiding Loop Rotation by Hand sisssacaissicscinvennunviaanrscaiin 2 18 Av iding Array Writes in Loops se nsircnssaenss cacctivenandsagninsindensincs 2 19 Taner Loops ve Outer Loops css ostersonomiaaiuienreateenioese 2 19 Avoiding Conditional Code in Loops ssiriiiniisineriiinanirsi 2 20 Avoiding Placing Function Calls in Loops ssccscissserncsesesereconesere 2 21 Avoiding Non Unit Strides sraon 2 21 Loap Corral eare 2 21 Using the Restrict Qualifier srsiorrnnnsssdi ini
356. ormances 1 4 statement expression 1 139 statistical profiling 2 5 stdio functions 1 166 stdio h header file 1 166 3 13 Stop see atexit exit functions strcat concatenate strings function 3 121 strchr find first occurrence of character in string function 3 122 strcmp compare strings function 3 123 3 126 strcoll compare strings function 3 124 strcpy copy from one string to another function 3 125 strcspn length of character segment in one string but not the other function 3 126 strerror get string containing error message function 3 127 string conversion see atof atoi atol strtok strtol strxfrm functions string functions memchar 3 94 VisualDSP 3 0 C C Compiler and Library Manual for ADSP 219x DSPs memmove 3 99 strchr 3 122 strcoll 3 124 strcspn 3 126 strerror 3 127 strpbrk 3 132 strrchr 3 133 3 134 strspn 3 134 strstr 3 135 strtok 3 140 strxfrm 3 146 string literals with line breaks 1 144 strings converting to double 3 136 strlen string length function 3 128 strncat concatenate characters from one string to another function 3 129 strncmp compare characters in strings function 3 130 strncpy copy characters from one string to another function 3 131 strpbrk find character match in two strings function 3 132 strrchr find last occurrence of character in string function 3 133 strspn length of segment of characters in both strings function 3 134 strstr find string within string f
357. orms the shift right operation as per L_shr but with rounding VisualDSP 3 5 C C Compiler and Library Manual 1 117 for ADSP 219x DSPs C C Compiler Language Extensions Long subtract fract32 L sub fract32 fract32 This function returns the 32 bit saturated result of the subtraction of two 32 bit parameters first second Long subtract with carry fract32 Lisub_c fract32 fract32 This function performs 32 bit subtraction of the two input parameters Uses the Carry flag as additional input when using the ETSI flag variables Compose long fract32 L_Comp fractl6 fractl6 This function composes a fract32 type value from the given fract16 high first parameter and low second parameter components The sign is provided with the low half the result is calculated to be high lt lt 16 low lt lt 1 Multiply two longs fract32 Mpy_32 fractl6 fractl6 fractl6 fractl6 This function performs the multiplication of two fract32 type variables provided as high and low half parameters The result returned is calculated as Res L_mult hil hi2 Res L_mac Res mult hil lo2 1 Res L_mac Res mult lol hi2 1 Multiply short by a long fract32 Mpy_32_16 fractl6 fractl6 fractl6 1 118 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler Extract a long from two shorts void L_Extract fract32 src fractl6 hi fractl6 lo This function extracts low and high halves of fract32 type
358. ot compile MD on page 1 32 MM on page 1 32 Generates make rule and compiles Generates make rules and compiles Mo filename on page 1 32 Makes dependencies other than stdout This switch is used in conjunction with the ED or MD options Mt filename on page 1 32 Makes dependencies where the target is renamed as filename MQ on page 1 33 Generates make rules only does not compile No notifica tion when input files are missing map filename on page 1 33 Directs the linker to generate a memory map of all symbols VisualDSP 3 5 C C Compiler and Library Manual 1 15 for ADSP 219x DSPs Compiler Command Line Interface Table 1 4 C C Compiler Common Switches Contd Switch Name Description mem on page 1 33 Causes the compiler to invoke the Memory Initializer after linking the executable file no alttok on page 1 33 Does not allow alternative keywords and sequences in sources no bss on page 1 33 no builtin on page 1 34 no circbuf on page 1 34 Causes the compiler to group global zero initialized data into the same section as global data with non zero initializ ers Disables recognition of __builtin functions Disables the automatic generation of circular buffer code by the compiler no defs on page 1 34 Does not define any default preprocessor macros include directories libra
359. oth an input and an output It must appear as part of the second argument to the asm construct The allocated register is loaded with the C C expression value the asm template is exe cuted and then the allocated register s new value is stored back into the C C expression Therefore as with pure outputs the C C expression must be one that is valid on the left hand side of an assign ment Example d The operand is temporary It must appear as part of the third argument to the asm construct A register is allocated as working space for the duration of the asm template execution The register s initial value is undefined and the register s final value is dis carded The corresponding C C expression is not loaded into the register but must be present This expression is normally specified using a literal zero Example d This operand constraint may be applied to inputs and outputs It indicates that the register allocated to the input or output may not be one of the registers that are allocated to the outputs or inputs This operand constraint is used when one or more output registers are set while one or more inputs are still to 1 70 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler be referenced This situation sometimes occurs if the asm template contains more than one instruc tion Example amp d e symbol The operand is an input but the register s
360. ound the prototype The C C runtime determines that all function parameters are passed on the stack A good way to observe and understand how arguments are passed is to write a dummy function in C or C and compile it using the save temps command line switch see on page 1 44 The resulting com piler generated assembly file s can then be viewed The following example includes the global volatile variable assignments to indicate where the arguments can be found upon entry to asmfunc Sample file for exploring compiler interface global variables assign arguments there just so we can track which registers were used type of each variable corresponds to one of arguments int global_a float global_b int global_p the function itself int asmfunc int a float b int p int d int e do some assignments so s file will show where args are global_a a global_b b global_p p value gets loaded into the return register return 12345 VisualDSP 3 5 C C Compiler and Library Manual 1 171 for ADSP 219x DSPs C C and Assembly Language Interface When compiled with the save temps option set this produces the fol lowing code _asmfunc AX1 DM 14 2 SI DM 14 1 AXO DM I4 3 DM ADDRESS _global_b AX1 AYO DM I4 4 DMCADDRESS _global_a SI DM ADDRESS _global_b l AXO RTS DB DMCADDRESS _global_p AYO AX1
361. p double x int n Exponent float frexpf float x int n Multiply by Power of 2 double Idexp double x int n float Idexpf float x int n Natural Logarithm double log double x float logf float x VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs 4 11 DSP Run Time Library Guide Table 4 4 Math Library Contd Description Prototype Logarithm Base 10 double logl0 double x float loglOf float x Get Fraction and double modf double x double i Integer float modff float x float i Power double pow double x double y float powf float x float y Sine double sin double x float sinf float x fractl sin_frl fractl6 x Hyperbolic Sine double sinh double x float sinhf float x Square Root double sqrt double x float sqrtf float x fractl6 sqrt_frl6 fractl6 x Reciprocal of Square Root double rsqrt double x Float rsqrtf float x Tangent double tan double x float tanf float x fractl6 tan_frl6 fractl6 x Hyperbolic double tanh double x Tangent Float tanhf float x matrix h Matrix Functions The matrix h header file contains matrix functions for operating on real and complex matrices both matrix scalar and matrix matrix operations See complex h Basic Complex Arithmetic Functions on page 4 4 for definition of the complex types VisualDSP 3
362. peline viewer 2 24 I 21 VisualDSP 3 0 C C Compiler and Library Manual for ADSP 219x DSPs INDEX placement support keyword segment 1 60 1 83 pm memory keyword 1 60 1 78 PM support standard C library 1 83 pointer incrementing 2 12 input parameter types 1 83 pointer class support keyword restrict 1 60 1 84 pointers arithmetic action on 1 144 memory keywords 1 81 polar construct from polar coordinates function 4 91 pow raise to a power function 3 104 PP omit line numbers and compile compiler switch 1 38 pplist preprocessor listing compiler switch 1 41 pragmas 1 119 align num 1 121 alloc 1 129 altregisters 1 122 can_instantiate instance 1 136 const 1 130 data alignment 1 121 do_not_instantiate instance 1 136 function side effect 1 128 hdrstop 1 136 header file control 1 136 instantiate instance 1 135 interrupt 1 122 interrupt handler 1 122 linkage_name 1 126 linking 1 126 linking control 1 126 loop optimization 1 123 2 35 loop_count min max modulo 1 124 no_alias 1 125 no_pch 1 137 once 1 138 optimization level change 1 125 optimize_as_cmd_line 1 126 optimize_for_space 1 126 optimize_for_speed 1 126 optimize_off 1 125 pad alignopt 1 121 pure 1 129 regs_clobbered string 1 130 result_alignment 1 134 retain_name 1 127 system_header 1 138 template instantiation 1 134 vector_for 1 124 weak_entry 1 128 precompiled 1 136 precompiled header 1 40 precompiled header file 1 136 predefined
363. phase_float PI phase_frl6 phase_float 2 PI 32768 0 mag_frl6 0x0200 point polar_frl6 mag_frl6 phase_frl6 point re Oxfe00 point im 0x0000 VisualDSP 3 5 C C Compiler and Library Manual 4 93 for ADSP 219x DSPs DSP Run Time Library Reference rfft N point real input FFT Synopsis include lt filter h gt void rfft_frl6 inlJ tl outL wl wst n block_exponent scale_method const fractl6 inl input output sequence complex_fractl6 tL temporary working buffer complex_fractl6 out working buffer const complex_fractl6 wl twiddle sequence int wst twiddle factor stride Ej int n number of FFT points E int block_exponent block exponent of output data int scale method scaling method desired O none l static 2 dynamic ap Description This function transforms the time domain real input signal sequence to the frequency domain by using the radix 2 FFT The function takes advantage of the fact that the imaginary part of the input equals zero which in turn eliminates half of the multiplications in the butterfly The size of the input array in the output array out and the temporary working buffer t is n where n represents the number of points in the FFT The function does not impose any special memory alignment require ments on the arrays However benefits in run time performance will be realized if the output array is alloca
364. prevent over flow The final output will be scaled by 1 n and block_exponent will be set to log2 n If scale_method is set to 2 then the function will select dynamic scaling Under dynamic scaling the function will inspect the intermediate results and will only scale to avoid overflow Dynamic scaling therefore mini mizes loss of precision but at the cost of slightly reduced performance The block_exponent will be set to a value between 0 which indicates that no scaling was performed and 10g2 n if static scaling was performed Algorithm 1 N 1 x n To X kWp k 0 The implementation uses core FFT functions implemented as direct radix 4 algorithm To get the inverse effect it first swaps the real and imaginary parts of the input performs the direct radix 4 transformation and finally swaps the real and imaginary parts of the output Domain Input sequence length n must be a power of four and at least 16 4 80 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs DSP Run Time Library ifft2d NxN point 2 D inverse input FFT Synopsis include lt filter h gt void ifft2d_frl6 in t out wl wst n block_exponent scale_method const complex_float in pointer to input matrix a n n XJ complex_fractl6 t pointer to working buffer t n n complex_fractl6 out pointer to output matrix c n n const complex_fractl6 wl twiddle sequence int wst twiddle factor strid
365. processor switch specifies that the compiler should pro duce code suitable for the specified processor The processor identifiers directly supported in VisualDSP 3 5 are ADSP 2191 ADSP 21990 ADSP 21991 ADSP 21992 ADSP 2195 ADSP 2196 ADSP 2192 12 and ADSP 219x For example cc219x proc ADSP 2191 o bin pl doj pl asm VisualDSP 3 5 C C Compiler and Library Manual 1 41 for ADSP 219x DSPs Compiler Command Line Interface If no target is specified with the proc switch the system uses the ADSP 219x setting as a default If the processor identifier is unknown to the compiler it attempts to read required switches for code generation from the file lt processor gt ini The assembler searches for the ini file in the VisualDSP System folder For custom processors the compiler searches the section proc in the lt processor gt ini for key architecture The custom processor must be based on an architecture key that is one of the known processors For example proc Customxxx searches the Customxxx ini file When compiling with the proc switch the appropriate processor macro as well as ___ADSP21XX__ and __ADSP219X__ preprocessor macros are defined as 1 For example __ADSP2191__ and __ADSP219X__are 1 See also si revision version on page 1 44 for more information on silicon revision of the specified processor R directory dzrectory The R add source directory switch directs the compil
366. r ADSP 219x DSPs Pragmas on page 2 31 Useful Optimization Switches on page 2 37 2 2 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Achieving Optimal Performance from C C Source Code General Guidelines It is useful to bear in mind the following basic strategy when writing an application 1 Try to choose an algorithm that is suited to the architecture being targeted For example there may be a trade off between memory usage and algorithm complexity that may be influenced by the tar get architecture 2 Code the algorithm in a simple high level generic form Keep the target in mind especially with respect to choices of data types 3 You can then turn your attention towards code tuning For critical code sections think more carefully about the strengths of the target platform and make any non portable changes where necessary Tip Choose the language as appropriate As the programmer your first decision is to choose whether to implement your application in C or C This decision may be influenced by perfor mance considerations C code using only C features will have very similar performance to pure C source Many higher level C features for example those resolved at compile time such as namespaces overloaded functions and inheritance have no performance cost However use of some other features may degrade performance and so the performance loss must be weighed against th
367. r all types of header file should begin All include directories on the command line specified before the 1 switch will only be used in the search for header files that are enclosed in double quotes This switch removes the directory containing the current input file from the include directory list I directory directory The 1 include search directory switch directs the C C preprocessor to append the directory directories to the search path for include files This option may be specified more than once all specified directories are added to the search path VisualDSP 3 5 C C Compiler and Library Manual 1 29 for ADSP 219x DSPs Compiler Command Line Interface Include files whose names are not absolute path names and that are enclosed in when included will be searched for in the following directories in this order 1 The directory containing the current input file the primary source file or the file containing the finclude 2 Any directories specified with the I switch in the order they are listed on the command line 3 Any directories on the standard list lt VisualDSP install dir gt include If a file is included using the lt gt form this file will only be searched for by using directories defined in items 2 and 3 above 4 The i less includes switch may be used with the H HH M or MM switches to direct the compiler to only output header details H HH
368. r condition Example d Finclude lt math h gt double x y y tanh x See Also cosh sinh VisualDSP 3 5 C C Compiler and Library Manual 3 155 for ADSP 219x DSPs C Run Time Library Reference tolower convert from uppercase to lowercase Synopsis include lt ctype h gt int tolower int c Description The tolower function converts the input character to lowercase if it is uppercase otherwise it returns the character Error Conditions The tolower function does not return an error condition Example dFinclude lt ctype h gt int ch for ch 0 ch lt Ox7f ch printf 04x ch if isupper ch printf tolower 4i04x tolower ch putchar n See Also islower isupper toupper 3 156 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library toupper convert from lowercase to uppercase Synopsis dFinclude lt ctype h gt int toupper int c Description The toupper function converts the input character to uppercase if it is in lowercase otherwise it returns the character Error Conditions The toupper function does not return an error condition Example include lt ctype h gt int ch for ch 0 ch lt Ox7f ch printf 04x ch if islower ch printf toupper 04x toupper ch putchar n See Also islower isupper tolower VisualDSP 3 5 C C Compiler and Library Manual 3 157
369. r distributors log onto http www analog com salesdir continent asp Hardware Manuals Hardware reference and instruction set reference manuals can be ordered through the Literature Center or downloaded from the Analog Devices website The phone number is 1 800 ANALOGD 1 800 262 5643 The manuals can be ordered by a title or by product number located on the back cover of each manual Datasheets All datasheets can be downloaded from the Analog Devices website As a general rule any datasheet with a letter suffix L M N can be obtained from the Literature Center at 1 800 ANALOGD 1 800 262 5643 or downloaded from the website Datasheets without the suffix can be down loaded from the website only no hard copies are available You can ask for the datasheet by a part name or by product number xxxvi VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Preface If you want to have a datasheet faxed to you call the phone number for that service 1 800 446 6212 Follow the prompts and a list of datasheet code numbers will be faxed to you Call the Literature Center first to find out if requested datasheets are available Contacting DSP Publications Please send your comments and recommendation on how to improve our manuals and online Help You can contact us by sending an E mail to dsp techpubs analog com Notation Conventions The following table identifies and describes text conventions used in this manual
370. ractional value in the range 1 0 1 0 corresponding to 1 2 7 2 The domain represents half a cycle which can be used to derive a full cycle if required see Notes below The result in radians is in the range 1 0 1 0 Error Conditions The sin function does not return an error condition Example dFinclude lt math h gt double y y sin 3 14159 y 0 0 Notes The domain of the sin_fr16 function is restricted to the fractional range 0x8000 0x7fff which corresponds to half a period from 1 2 to 7 2 It is possible however to derive the full period using the following proper ties of the function 3 116 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library sine 0 1 2 sine T 3 2 T Sine m 2 0 sine T 2 T The function below uses these properties to calculate the full period from 0 to 27 of the sine function using an input domain of 0 0x7fff include lt math h gt fractl6 sin2pi_fr16 fract16 x if x lt 0x2000 lt 0 25 first quadrant 0 7 2 sin_fr16 Ox0 0x7fff 0 0x7fff return sin_frl6 x 4 else if x lt 0x6000 lt lt 0 75 if x lt 0x4000 second quadrant 2 1 sin_frl6 Ox8000 0x0 Ox7fff 0 a a if x lt 0x6000 third quadrant 3 21 x7 sin_fr16 0x0 0x7fff 0 0x8000 return sin_fr1i6 0xc000 x 4 else
371. rchiver described in the VisualDSP 3 5 Linker and Utilities Manual for 16 Bit Processors to build library archive files of your own functions Using the Compiler s Built In C Library Functions The C C compiler s built in functions are a set of functions that the compiler immediately recognizes and replaces with inline assembly code instead of a function call Typically in line assembly code is faster than an library routine and it does not incur the calling overhead To use built in functions your source must include the required standard include file For the abs functions this would require stdlib h to be included There are built in functions used to define some ANSI C math h string h and stdlib h functions There are also built in func tions to support various ANALOG extensions to the ANSI standard defined in the include file math_builtins h Not all built in functions have a library alternate definition Therefore the failure to use the required include files can result in your program build failing to link If you want to use the C run time library functions of the same name compile with the no builtin compiler switch on page 1 34 VisualDSP 3 5 C C Compiler and Library Manual 3 5 for ADSP 219x DSPs C and C Run Time Library Guide Linking Library Functions The C C run time library is organized as several libraries which are cat alogued in Table 3 1 The libraries and start up files are installed with
372. re call the following must be true e For the ADSP 219x DSPs no space beyond the SP must be in use e There must be at least one free slot on the PC stack to hold the return address At an interrupt the following must be true e Space beyond the SP must be available e For the ADSP 219x DSPs the first 32 words beyond the SP must be protected the interrupt routine should decrement the SP by 32 and then restore the original value of SP prior to return Return Values Return values always use registers Single word return values come back in register AX1 Double word return values are stored in SR1 0 with the most significant part in SR1 If the return value is larger than two words then the caller must allocate space and pass the address in as a hidden argument The register 10 is used for this purpose Procedure Call and Return To call a procedure 1 Evaluate the arguments and push them onto the stack 2 Call the procedure 3 On return remove arguments if desired VisualDSP 3 5 C C Compiler and Library Manual 1 159 for ADSP 219x DSPs C C Run Time Model and Environment On Entry 1 2 Save the old FP and set FP to current SP If no_hardware_pc_stack is specified for debugging pop the PC stack and store it on the main stack Move the SP to create space for the new frame If g is specified but no_hardware_pc_stack is not specified push the return address back onto the hardware stack
373. release of the compiler software VisualDSP 3 5 C C Compiler and Library Manual 3 1 for ADSP 219x DSPs includes the abridged C library a conforming subset of the standard C library The abridged C library includes the embedded C and embedded standard template libraries This chapter describes the standard C C library functions in the current release of the run time library Chapter 4 DSP Run Time Library describes a number of signal processing matrix and statistical functions that assist DSP code development For more information on the C standard library see The Standard C Library by P J Plauger Prentice Hall 1992 For more informa tion on the algorithms on which many of the C library s math functions are based see Cody W J and W Waite Software Man ual for the Elementary Functions Englewood Cliffs New Jersey Prentice Hall 1980 For more information on the C library por tion of the ANSI ISO Standard for C see Plauger P J Preface The Draft Standard C Library Englewood Cliffs New Jersey Prentice Hall 1994 ISBN 0131170031 The C library reference information in HTML format is included on the software distribution CD ROM To access the reference files from VisualDSP use the Help Topics command Help menu and select the Reference book icon From the Online Manuals topic you can open any of the library files You can also manually access the HTML files using a web browser
374. rguments have been processed or if va_arg is called with a type parameter that is different from the type of the next argument in the list the behavior of va_arg is undefined 3 158 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Error Conditions C C Run Time Library The va_arg macro does not return an error condition Example d Finclude lt stdarg h gt d Finclude lt string h gt include lt stdlib h gt char concat char sl int len 0 char result char s va_list ap va_start ap sl s sl while s len strlen s S va_arg ap char va_end ap result malloc len 7 if result return result result va_start ap sl s sl while s strcat result s S va_arg ap char va_end ap return result See Also va_end va_start VisualDSP 3 5 C C Compiler and Library Manual 3 159 for ADSP 219x DSPs C Run Time Library Reference va_end finish variable length argument list processing Synopsis include lt stdarg h gt void va_end va_list ap Description The va_end macro can only be used after the va_start macro has been invoked A call to va_end concludes the processing of a variable length list of arguments that was begun by va_start Error Conditions The va_end macro does not return an error condition Example See va_arg on page 3 158 See Also va_arg va_s
375. rious methodologies The functions defined in the window h header file are listed in Table 4 8 and are described in detail in DSP Run Time Library Reference on page 4 22 For all window functions a stride parameter a can be used to space the window values The window length parameter n equates to the number of elements in the window Therefore for a stride a of 2 and a length n of 10 an array of length 20 is required where every second entry is untouched Table 4 8 Window Generator Functions Description Prototype Generate Bartlett void gen_bartlett_frl6 fractl6 w J int a int n Window Generate Blackman void gen_blackman_frl16 fractl6 wl J int a int n Window Generate Gaussian void gen_gaussian_frl6 fractl6 wl float alpha int a int n Window 4 20 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs DSP Run Time Library Table 4 8 Window Generator Functions Contd for ADSP 219x DSPs Description Prototype Generate Hamming void gen_hamming_frl6 fractl6 wl J int a int n Window Generate Hanning void gen_hanning_frl6 fractl6 wl J int a int n Window Generate Harris void gen_harris_frl6 fractl6 wl J int a int n Window Generate Kaiser void gen_kaiser_frl6 fractl6 wl J float beta int a int n Window Generate Rectangular void gen_rectangular_frl6 fractl6 wl J int a int n Window Generate Tr
376. rm static scaling if scale_method is set to 1 For static scaling the function will scale intermediate results to prevent over flow The final output will be scaled by 1 n and block_exponent will be set to log2 n If scale_method is set to 2 then the function will select dynamic scaling Under dynamic scaling the function will inspect the intermediate results and will only scale to avoid overflow Dynamic scaling therefore mini mizes loss of precision but at the possible cost of slightly reduced performance The block_exponent argument will be set to a value between 0 which indicates that no scaling was performed and 10g2 n as if static scaling was performed Algorithm See cfftrad4_fr16 on page 4 38 Domain Input sequence length n must be a power of four and at least 16 VisualDSP 3 5 C C Compiler and Library Manual 4 97 for ADSP 219x DSPs DSP Run Time Library Reference rfft2d NxN point 2 D real input FFT Synopsis include lt filter h gt void rfft2d_frl6 in t out wl wst n block_exponent scale_method const fractl6 in pointer to input matrix a n n complex_fractl6 t pointer to working buffer t n n complex_fractl6 out pointer to output matrix c n n const complex_fractl6 wl twiddle sequence x int wst twiddle factor stride KJ int n number of FFT points int block_exponent block exponent of output data int scale method scaling met
377. ro with a local variable declaration 1 140 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler The argument to typeof may also be a type name Because typeof itself is a type name it may be used in another typeof type name construct This can be used to restructure the C type declaration syntax such as define pointer T typeof T define array T N typeof T N array pointer char 4 y declares y to be an array of four pointers to char i The typeof keyword is not supported in C mode i The typeof keyword is an extension to C originally implemented in the GCC compiler It should be used with caution because it is not compatible with other dialects of C or C and has not been adopted by the more recent C99 standard GCC Generalized Lvalues A cast is an 1value may appear on the left hand side of an assignment if its operand is an lvalue This is an extension to C provided for compati bility with GCC It is not allowed in C mode A comma operator is an value if its right operand is an lvalue This is an extension to C provided for compatibility with GCC It is a standard fea ture of C A conditional operator is an 1 value if its last two operands are lvalues of the same type This is an extension to C provided for compatibility with GCC It is a standard feature of C VisualDSP 3 5 C C Compiler and Library Manual 1 141 for ADSP 219x DSPs C C Compil
378. roject devel opment efforts by e Processing C and C source files producing machine level ver sions of the source code and object files e Providing relocatable code and debugging information within the object files e Providing relocatable data and program memory segments for placement by the linker in the processors memory Using C C developers can significantly decrease time to market since it gives them the ability to efficiently work with complex signal processing data types It also allows them to take advantage of specialized DSP opera tions without having to understand the underlying DSP architecture The C C compiler cc219x compiles ISO ANSI standard C and C code for the ADSP 219x DSPs Additionally Analog Devices includes within the compiler a number of C language extensions designed to assist in DSP development The cc219x compiler runs from the VisualDSP environment or from an operating system command line The C C compiler cc219x processes your C and C language source files and produces ADSP 219x DSP s assembler source files The assem bler source files are assembled by the ADSP 219x assembler easm219x The assembler creates Executable and Linkable Format ELF object files that can either be linked using the linker to create an ADSP 219x exe cutable file or included in an archive library using el far The way in which the compiler controls the assemble link and archive phases of the process
379. ropriate source code line See g on page 1 28 for more information e Default The compiler does not perform any optimizations by default when none of the compiler optimizations switches are used or enabled in VisualDSP project options Default optimizations level can be enabled using the optimize_off pragma on page 1 125 e Procedural Optimizations The compiler performs advanced aggressive optimization on each procedure in the file being compiled The optimizations can be directed to favor optimizations for speed 0 or space 0s or a factor between speed and space 0v If debugging is also 1 56 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler requested the optimization is given priority so the debugging func tionality may be limited See O on page 1 37 Os on page 1 37 and Ov num on page 1 38 Procedural optimizations for speed and space 0 and 0s can be enabled in C C source using the pragma optimize_ for_speed for_space see on page 1 125 more infor mation on optimization pragmas e Automatic Inlining The compiler automatically inlines C C functions which are not necessarily declared as inline in the source code It does this when it has determined that doing so will reduce execution time How aggressively the compiler performs automatic inlining is controlled using the 0v switch Automatic inlining is enabled using the 0a switch and additionally
380. ross the call site String Syntax A regs_clobbered string consists of a list of registers register ranges or register sets that are clobbered The list is separated by spaces commas or semicolons A register is a single register name which is the same as that which may be used in an assembly file A register range consists of start and end registers which both reside in the same register class separated by a hyphen All registers between the two inclusive are clobbered VisualDSP 3 5 C C Compiler and Library Manual 1 131 for ADSP 219x DSPs C C Compiler Language Extensions A register set is a name for a specific set of commonly clobbered registers that is predefined by the compiler The following register sets are defined Set Registers CCset ASTAT condition codes MR MRO MR2 SR SRO SR2 Blset DAG1 B registers B2set DAG2 B registers Bset Blset union B2set DAG1scratch Members of dag1 I L B and M registers that are scratch by default DAG2scratch Members of dag2 I L B and M registers that are scratch by default DAGscratch DAG Iscratch union DAG2scratch Dscratch Members of D registers that are scratch by default ALLscratch Entire default volatile set When the compiler detects an illegal string a warning is issued and the default volatile set as defined in this compiler manual is used instead Unclobberable and Must Clobber Registers There are certain c
381. ry directories libraries run time headers or keyword extensions no extra keywords on page 1 34 Does not define language extension keywords that could be valid C or C identifiers no fp associative on page 1 34 Does not treat floating point multiply and addition as an associative no_hardware_pc_stack on page 1 35 no mem on page 1 35 Uses software stack instead of default hardware stack for return PC Causes the compiler to not invoke the Memory Initializer after linking Set by default no std ass on page 1 35 Prevents the compiler from defining standard assertions no std def on page 1 35 Disables normal macro definitions also disables Analog Devices keyword extensions that do not have leading underscores __ no std inc on page 1 35 Searches for preprocessor header files only in the current directory and in directories specified with the 1 switch no std lib on page 1 36 Searches for only those linker libraries specified with the 1 switch when linking VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler Table 1 4 C C Compiler Common Switches Cont d Switch Name Description nothreads on page 1 36 Specifies that compiled code does not need to be thread safe no widen muls on page 1 36 Disable widening multiplications optimization 0 on page 1 37 Enable
382. s A hexadecimal floating point number may start with an optional plus or minus followed by the hexadecimal prefix 0x or 0X This character sequence must be followed by one or more hexadecimal characters that optionally contain a decimal point 3 138 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library The hexadecimal digits are followed by a binary exponent that consists of the letter p or P an optional sign and a non empty sequence of decimal digits The exponent is interpreted as a power of two that is used to scale the fraction represented by the tokens hexdigs hexdigs The first character that does not fit either form of number will stop the scan If endptr is not NULL a pointer to the character that stopped the scan is stored at the location pointed to by endptr If no conversion can be performed the value of nptr is stored at the location pointed to by endptr Error Conditions The strtodf function returns a zero if no conversion can be made and a pointer to the invalid string is stored in the object pointed to by endptr If the correct value results in an overflow a positive or negative as appropri ate HUGE_VAL is returned If the correct value results in an underflow 0 is returned The ERANGE value is stored in errno in the case of either an over flow or underflow Example include lt stdlib h gt char rem float f 4 l strtodf 2345
383. s FTP website at ftp ftp analog com or ftp 137 71 23 21 ftp ftp analog com Related Documents For information on product related development software see the follow ing publications VisualDSP 3 5 Getting Started Guide for 16 Bit Processors VisualDSP 3 5 Users Guide for 16 Bit Processors VisualDSP 3 5 Assembler and Preprocessor Manual for ADSP 218x and ADSP 219x DSPs VisualDSP 3 5 Linker and Utilities Manual for 16 Bit Processors VisualDSP 3 5 Loader Manual for 16 Bit Processors VisualDSP 3 5 Product Bulletin for 16 Bit Processors VisualDSP Kernel VDK Users Guide VisualDSP Component Software Engineering User s Guide Quick Installation Reference Card For hardware information refer to the processor s Hardware Reference Manual and Instruction Set Reference Manual VisualDSP 3 5 C C Compiler and Library Manual xxxiii for ADSP 219x DSPs Product Information Online Technical Documentation Online documentation comprises VisualDSP Help system and tools manuals Dinkum Abridged C library and FlexLM network license manager software documentation You can easily search across the entire VisualDSP documentation set for any topic of interest For easy print ing supplementary PDF files for the tools manuals are also provided A description of each documentation file type is as follows File Description CHM Help system files and VisualDSP tools manuals HTM or HTML Dinkum Abridged C
384. s a compiler built in and the emitted instructions will be inlined at the point of sysreg_read use The inclusion of the sysreg h include file is mandatory when using sysreg_read Error Conditions The sysreg_read function does not return raise or set any error condi tions The compiler will not validate the input instead it will rely on the assembler to fault erroneous values VisualDSP 3 5 C C Compiler and Library Manual 3 149 for ADSP 219x DSPs C Run Time Library Reference Example include lt sysreg h gt main int value sysreg_read sysreg_IMASK See Also disable_interrupts enable_interrupts io_space_read io_space_write mode_change sysreg_write 3 150 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library sysreg_write write to non memory mapped register Synopsis include lt sysreg h gt void sysreg_write const int const unsigned int Description The sysreg_write function causes the compiler to emit instructions to write the non memory mapped register which is passed as the first param eter with the value passed as the second parameter The first parameter for sysreg_write can be one of the symbolic variable constants of the enumerated data type SysReg defined in sysreg h or any valid 8 bit value used to represent a system control register The second parameter is unsigned The symbolic definitions in sysreg h are listed below Gen
385. s at the first digit with an optional preceding sign and terminates at the first non digit There is no way to determine if a zero is a valid result or an indica tor of an invalid string Error Conditions The atol function returns a zero if no conversion can be made Example d Finclude lt stdlib h gt long int i i atol 5 i 5 See Also atoi atof strtod strtol strtoul 3 38 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library bsearch perform binary search in a sorted array Synopsis Finclude lt stdlib h gt void bsearch const void key const void base size_t nelem size_t size int compare const void const void Description The bsearch function executes a binary search operation on a pre sorted array where e key is a pointer to the element to search for e base points to the start of the array e nelem is the number of elements in the array e size is the size of each element of the array e compare points to the function used to compare two elements It takes as parameters a pointer to the key and a pointer to an array element and should return a value less than equal to or greater than zero according to whether the first parameter is less than equal to or greater than the second The bsearch function returns a pointer to the first occurrence of key in the array Error Conditions The bsearch function returns a null poi
386. s for other than their intended purpose the compiler libraries debugger and interrupt routines all depend on having a stack available as defined by those registers Preserved registers can be used their contents will not be changed by call ing a C C function The function will always save and restore the contents of preserved registers if they are going to change If arguments are on the stack they are addressed via an offset from the stack pointer or frame pointer Explore how arguments are passed between an assembly language program and a function by writing a dummy func tion in C C and compiling it with the save temporary files option the save temps command line switch By examining the contents of volatile global variables in s file you can determine how the C C function passes arguments and then duplicate that argument setup pro cess in the assembly language program The stack must be set up correctly before calling a C C callable func tion If you call other functions maintaining the basic stack model also facilitates the use of the debugger The easiest way to do this is to define a C C main program to initialize the run time system maintain the stack until it is needed by the C C function being called from the assembly language program and then continue to maintain that stack until it is needed to call back into C C However make sure the dedicated regis ters are correct You do not need to set the F
387. s into different memory sections The DSP hardware can support two memory operations on a single instruction line combined with a compute instruction However two memory operations will only complete in one cycle if the two addresses are situated in different memory blocks if both access the same block then a stall will be incurred Take as an example the dot product loop below Because data is loaded from both array a and array b in every iteration of the loop it may be use ful to ensure that these arrays are located in different blocks for i 0 i lt 100 i sum a i b i VisualDSP 3 5 C C Compiler and Library Manual 2 15 for ADSP 219x DSPs General Guidelines Bad compiler assumes that two memory accesses together may give a stall This is done by using the compiler extension described in Dual Memory Support Keywords pm dm on page 1 78 Placing a pm qualifier before the type definition tells the compiler that the array is located in what is notionally called Program Memory PM The memory of a ADSP 219x DSP is in one unified address space and there is no restriction concerning in which part of memory program code or data can be placed as on previ ous generations of DSP architectures like the ADSP 218x DSPs However the default LDF files ensure that pm qualified data is placed in a different memory block than non qualified or dm qualified data thus allowing two accesses to occur simultaneously
388. s its parameter The interrupts interrupt dispatcher saves and restores only the smallest number of registers and modes required to determine if a handler has been registered and to call that handler The handler passed as input to VisualDSP 3 5 C C Compiler and Library Manual 3 63 for ADSP 219x DSPs C Run Time Library Reference interrupts must be declared using the tpragma interrupt directive see on page 1 122 The pragma altregisters directive see on page 1 122 may be used in conjunction with the interrupt pragma in the definition of the handler This dispatcher will not pass the interrupt ID to the handler The sig argument must be one of the signals listed in priority order in Table 3 15 Table 3 15 Interrupt Function Signals Values and Meanings Sig Value Definition SIG_PWRDWN power down interrupt SIG_STACKINT PC LOOP or COUNTER overflow on push or on pop when empty SIG_KERNEL kernel interrupt SIG_INT4 user assignable SIG_INT5 user assignable SIG_INT6 user assignable SIG_INT7 user assignable SIG_INTS8 user assignable SIG_INT9 user assignable SIG_INT10 user assignable SIG_INT11 user assignable SIG_INT12 user assignable SIG_INT13 user assignable SIGABRT software interrupt SIGILL software interrupt SIGINT software interrupt SIGSEGV software interrupt 3 64 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Ru
389. s on a host system using stdio functions File I O support is provided through a set of low level primitives that implement the open close read write and seek operations The stdio functions make use of these primitives to pro vide conventional C input and output facilities The source files for the I O primitives are available under the VisualDSP installation in the sub directory 219x lib src libio_src Refer to stdio h on page 3 13 for more information Extending I O Support To New Devices The I O primitives are implemented using an extensible device driver mechanism The default start up code includes a device driver that can perform I O through the VisualDSP simulator and EZ KIT Lite Other device drivers may be registered and then used through the normal stdio functions A device driver is a set of primitive functions grouped together into a DevEntry structure This structure is defined in device h struct DevEntry int DevicelID void data 1 166 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler int init struct DevEntry entry int open const char name int mode int close int fd int write int fd unsigned char buf int size int read int fd unsigned char buf int size long seek long fd long offset int whence typedef struct DevEntry DevEntry typedef struct DevEntry DevEntry_t The Device ID field is a unique identifier for the devi
390. s optimizations 0a on page 1 37 Enables automatic function inlining Os on page 1 37 0v num on page 1 38 Optimizes for code size Controls speed vs size optimizations o filename on page 1 38 Specifies the output file name oldasmcall csp 8x on page 1 38 Switches the operation of the 01dAsmCa11 linkage speci fier P on page 1 38 Preprocesses but does not compile the source file Omits line numbers in the preprocessor output PP on page 1 38 Similar to P but does not halt compilation after prepro cessing path asm compiler def lib link mem filename on page 1 39 Uses the specified directory as the location of the specified compilation tool assembler compiler library builder or linker path install directory on page 1 39 Uses the specified directory as the location for all compilation tool path output directory on page 1 39 Specifies the location of non temporary files path temp directory on page 1 39 Specifies the location of temporary files pch on page 1 40 Generates and uses precompiled header files pch VisualDSP 3 5 C C Compiler and Library Manual 1 17 for ADSP 219x DSPs Compiler Command Line Interface Table 1 4 C C Compiler Common Switches Cont d Switch Name Description pchdir directory Specifies the location of PCHRepository
391. s the following components of the Abridged Library e Embedded C Library Header Files on page 3 16 e C Header Files for C Library Facilities on page 3 19 e Embedded Standard Template Library Header Files on page 3 20 For more information on the Abridged Library see online Help Embedded C Library Header Files The following sections provide a brief description of the header files in the embedded C library complex The complex header file defines a template class complex and a set of asso ciated arithmetic operators Predefined types include complex_float and complex_long_double This implementation does not support the full set of complex operations as specified by the C standard In particular it does not support either the transcendental functions or the I O operators lt lt and gt gt 3 16 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library The complex header and the C library header file complex h refer to two different and incompatible implementations of the complex data type exception The exception header defines the exception and bad_exception classes and several functions for exception handling fract The fract header defines the fract data type which supports fractional arithmetic assignment and type conversion operations The header file is fully described under Fractional Type Support on page 1 90 and an example that d
392. says that it must occupy the same loca tion as operand 0 A digit in an operand constraint is allowed only in an input operand and it must refer to an output operand Only a digit in the constraint can guarantee that one operand is in the same place as another operand Just because a variable for example shoe in the code that follows is used for more than one operand does not guar antee that the operands are in the same place in the generated assembler code Do NOT try to control placement with operand names use the digit The following code might NOT work asm modify 40 42 w shoe w shoe x sock In some cases operands 0 and 1 could be stored in different registers due to reloading or optimizations Be aware that asm does not support input operands that are used as both read operands and write operands The example below shows a dangerous use of such an operand In this example my_variable is modified during the asm operation The compiler only knows that the output result_asm has changed Subsequent use of my_variable after the asm instruction may yield incorrect results since those values may have been modified during the asm instruction and may not have been restored int result_asm int my_variable NOT recommended pseudo code result_asm dm my_variable 3 asm operation changes value of my_variable asm 40 DM 41 3 e result_asm w my_variable
393. se types and treats them exactly as the integer types that they are typedefed to System Support Built In Functions Built in functions are also provided to perform low level system manage ment in particular for the manipulation of system registers defined in sysreg h It is usually better to use these built in functions rather than inline asm statements The built in functions cause the compiler to gener ate efficient inline instructions and their use often results in better optimization of the surrounding code at the point where they are used Using builtins will also usually result in improved code readability For more information on built in functions supported by the compiler refer to Compiler Built In Functions on page 1 94 2 26 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Achieving Optimal Performance from C C Source Code Examples of the two styles are int read_io int jiopg_val int ret_val IOPG 1 0 10 0x20 e ret_val e iopg_val IOPG return ret_val Bad uses inline asm statement Finclude lt sysreg h gt ifdefine ADDR 0x20 int read_io int iopg_val sysreg_write sysreg_IOPG iopg_val return sysreg_read reg_CYCLES Good uses sysreg h This example reads and returns the CYCLES register Using Circular Buffers Circular buffers are often extremely useful in DSP code They can be used in several ways Consider the C code for i
394. shift instruction Even then a few fix up instructions are needed after the shift if the types are signed If you have a signed divi sion by a power of two consider whether you can change it to unsigned in order to obtain a single instruction operation When the compiler has to generate a call to a library function for one of these arithmetic operators that are not supported by the hardware perfor mance will suffer not only because the operation will take multiple cycles but also because the effectiveness of the compiler optimizer will be reduced For example such an operation in a loop can prevent the compiler from making use of efficient zero overhead hardware loop instructions Also calling the library to perform the required operation can change values held in scratch registers before the call so the compiler will have to gener ate more stores and loads from the data stack to keep values required after the call returns Emulated arithmetic operators should therefore be avoided where possible especially in loops 2 8 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Achieving Optimal Performance from C C Source Code Getting the Most from IPA Interprocedural analysis IPA is designed to try to propagate information about the program to parts of the optimizer that can use it This section looks at what information is useful and how to structure your code to make this information easily accessible to the
395. sion The compiler supports both Win32 and POSIX style paths using either forward or back slashes as the directory delim iter It also supports UNC path names starting with two slashes and a network name The cc219x compiler uses the file extension to determine what the file contains and what operations to perform upon it Table 1 2 on page 1 10 lists the allowed extensions For example the following command line cc219x proc ADSP 2191 0 Wremarks o program dxe source c runs cc219x with the following switches proc ADSP 2191 Specifies the processor 0 Specifies optimization for the compiler Wremarks Selects extra diagnostic remarks in addition to warning and error messages o program dxe Selects a name for the compiled linked output VisualDSP 3 5 C C Compiler and Library Manual 1 7 for ADSP 219x DSPs Compiler Command Line Interface source c Specifies the C language source file to be compiled The following example command line cc219x proc ADSP 2191 c source cpp runs cc219x with c Specifies that all of the source files are written in C source cpp Specifies the C language source file for your program The normal function of cc219x is to invoke the compiler assembler and linker as required to produce an executable object file The precise opera tion is determined by the extensions of the input filenames and by various switches In normal operation the compiler uses the following extension fi
396. srads 1 83 Boolean Type Support Keywords bool true false 1 84 Pointer Class Support Keyword restrict prurssrossinirisnani 1 84 Variable Length Array BOPPOTC wicenssiencevonicnsuasenandedidnisecesincsaes 1 85 Non Constant Aggregate Initializer Support eee 1 87 Indexed Tnaviialiver SUpport Jatesvessecscacsocissauaiusseitastarainssceaunscs 1 87 Aggregate Constructor Expression SUpport cscsscssossiiennsessevens 1 89 Froctiona ee CuDPOTE arashi doen AA 1 90 Pormatol Practional Literals ecscsatcesscrcizatiereendcomesrenioimetes 1 91 Conversions Involving Fractional Values osusscnesssisssa 1 91 Fractional Arithmetic Operations sis icsccissauieuiesecisiaereessaus 1 92 Mixed Mode Operations cits caiusensisanciclepieaiuneesauracaiumiaass 1 92 Saturated ATIE NE aer S 1 93 Preprocessor Generated Warnings icadcnsiscvieserncanaseancssaniavtavaines 1 93 O24 Se CODES eron n S 1 94 Compiler Built In Functions ssismieeisuinirininsnenai niinen 1 94 Recess tO System Kep OTOS ocala 1 95 LAS Space Read or Woite sriakercolsruinasire akitin 1 97 AE e E E A AE A 1 98 Modo Canol sosenanssrsnedii arn 1 99 Near and Far Type Sea conscience 1 99 x VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs CONTENTS DAO ccc eee eee 1 99 Sizes of Far and Near Qualified Types sronconinisrorss 1 100 Conversions Between Far and Near Pointers 0004 1 101 Addressing Far Dala 2 62 sao easadn ce naimeseamnenaseuns 1 102 Cr Poncr
397. sscorr cross correlation function 4 55 csub complex subtraction function 4 56 custom processors 1 42 cycle counter registers 3 149 3 152 D D define macro compiler switch 1 24 1 47 DAGI registers 1 164 DAG72 registers 1 165 data register 1 163 scalar type 2 7 data alignment pragmas 1 121 data types double word 1 55 deallocate memory see free function debugging information 1 43 declarations mixed with code 1 144 dedicated registers 1 161 default target processor 1 42 default linkage asm assembler link compiler switch 1 25 1 9 VisualDSP 3 0 C C Compiler and Library Manual for ADSP 219x DSPs INDEX default linkage C compiler switch 1 25 default linkage C compiler switch 1 25 Defines 1 148 device driver 1 166 identifiers 1 166 DeviceID field 1 167 disabling compiler optimization on multiplcation 1 36 div division function 3 50 div division int function 3 71 division see div ldiv functions dm memory keyword 1 60 DM support standard C library 1 83 DMPG_val parameter 1 103 double representation 3 136 word data types 1 55 dry verbose dry run compiler switch 1 25 dryrun terse dry run compiler switch 1 26 DSP functions 4 22 4 109 header files 4 4 library 3 7 library function calls 4 2 run time library functions 4 22 DSP run time library function linking 4 3 guide 4 2 source code 4 3 dual memory support pm dm 1 83 dual memory support keywords pm dm 1 60 1 78
398. st be a power of two and at least 16 VisualDSP 3 5 C C Compiler and Library Manual 4 99 for ADSP 219x DSPs DSP Run Time Library Reference rms root mean square Synopsis d Finclude lt stats h gt float rmsf a n const float al Pointer to input vector a int n Number of input samples ay fractl6 rms_frl6 a n const fractl6 al Pointer to input vector a int n Number of input samples aa Description This function computes the root mean square of the input elements con tained within input vector a and returns the result Algorithm C Domain 3 4 x 1038 to 3 4 x 10 8 for rmsf 1 0 to 1 0 for rms_fr16 4 100 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs DSP Run Time Library rsqrt reciprocal square root Synopsis d Finclude lt math h gt float rsqrtf float a double rsqrt double a Description This function calculates the reciprocal of the square root of the number a If a is negative the function returns 0 Algorithm c 1 4 Domain 0 0 to 3 4 x 1038 for rsqrtf VisualDSP 3 5 C C Compiler and Library Manual 4 101 for ADSP 219x DSPs DSP Run Time Library Reference twidfftrad2 generate FFT twiddle factors for radix 2 FFT Synopsis include lt filter h gt void twidfftrad2_frl6 complex_fractl6 wl int n Description This function calculates complex twiddle coefficients for a radix 2 FFT with n points
399. st be true 1 159 At an interrupt the following must be true 0 0 1 159 ie VANES ste nR R 1 159 Procedure Call and Retur sec cecsercasenscccessadesaencayeyseeniewanece 1 159 Oa Ent auoe aa i 1 160 To Return irom a Procedure a acnesesencnnncates 1 160 Miscellaneous TAMRON caserccsscnnieemiiicsceencioeens 1 161 Rezistor ee siso S 1 161 Callee Preserved Registers Preserved sccisccsarceacnicesancedee 1 161 Dedicated Recitas oe nevexieceemoceecumeodesanies 1 161 Caller Save Registers Scratch sstissimsancansrentinticsimiabaranns 1 161 Circ lar Bitter Length Registers scnscssicvincessonnciesseniecrnttenne 1 162 Mode Status MS TAT Register scciscscicvsircasvencinsivercansinnns 1 162 Complete List Ok eS as saceneconsiaancesursaarrssonsiaancienneronts 1 163 File PO GONE ioe ote aed tn 1 166 Extending I O Support To New Devices scccesercnicrsieenserces 1 166 C C and Assembly Language Interface siiicssessenssiesctnesceanons 1 169 Calling Assembly Subroutines from C C Programs 1 170 xiv VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs CONTENTS Calling C C Functions from Assembly Programs 1 172 Using Mixed C C and Assembly Naming Conventions 1 174 Cre Programming Examples serrera 1 176 tiime Fracr Type SUPPO ccrann A 1 176 Using Complex Number Suppart sinisisisinsssrinresatn 1 177 ACHIEVING OPTIMAL PERFORMANCE FROM C C SOURCE CODE Cetera ACES pna R 2 3 H
400. stream classes Most of the iostream header files include streambuf 3 18 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library string The string header defines the string template and various supporting classes and functions for string manipulations Objects of the string type should not be confused with the null terminated C strings strstream The strstream header defines the strstreambuf istrstream and ostream classes for iostream manipulations on allocated extended and freed character sequences C Header Files for C Library Facilities For each C standard library header there is a corresponding standard C header If the name of a C standard library header file is foo h then the name of the equivalent C header file will be cfoo For example the C header file cstdio provides the same facilities as the C header file stdio h Normally the C standard headers files may be used to define names in the C global namespace while the equivalent C header files define names in the standard namespace However the standard namespace is not sup ported in this release of the compiler and the effect of including one of the C header files listed in Table 3 4 is the same as including the equiv alent C standard library header file Table 3 4 lists the C header files that provide access to the C library facilities Table 3 4 C Header Files for C Library Facilities
401. stride parameter a is used to space the window values within the output vector w The length of the output vector should therefore be N a Algorithm T ar52 Ma N 2 where n 0 1 2 N 1 and is an input parameter Domain a gt 0 N gt 0 a gt 0 0 4 66 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs DSP Run Time Library gen_hamming generate hamming window Synopsis dFinclude lt window h gt void gen_hamming_frl6 w a N fractl6 wll Window vector int a Address stride in samples for window vector int N Length of window vector Description This function generates a vector containing the Hamming window The length of the window required is specified by the parameter N and the stride parameter a is used to space the window values within the output vector w The length of the output vector should therefore be N a Algorithm w n 0 54 0 46 cof 2m N 1 where n 0 1 2 N 1 Domain a gt 0 N gt 0 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs 4 67 DSP Run Time Library Reference gen_hanning generate hanning window Synopsis dFinclude lt window h gt void gen_hanning_frl6 w a N fractl6 wll Window vector int a Address stride in samples for window vector int N Length of window vector Description This function generates a vector containing the Hanning window The
402. strrcehr ptrl T ptr2 points to the second T of TESTING See Also memchr strchr VisualDSP 3 5 C C Compiler and Library Manual 3 133 for ADSP 219x DSPs C Run Time Library Reference strspn length of segment of characters in both strings Synopsis include lt string h gt size_t strspn const char s1 const char s2 Description The strspn function returns the length of the initial segment of s1 which consists entirely of characters in the string pointed to by s2 The string pointed to by s2 is treated as a set of characters The order of the charac ters in the string is not significant Error Conditions The strspn function does not return an error condition Example include lt string h gt size_t len char ptrl ptr2 ptrl TESTING ptr2 ERST len strspn ptrl ptr2 Jen 4 See Also strcspn strlen 3 134 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library strstr find string within string Synopsis d Finclude lt string h gt char strstr const char sl const char s2 Description The strstr function returns a pointer to the first occurrence in the string pointed to by s1 of the characters in the string pointed to by s2 This excludes the terminating null character in s1 Error Conditions If the string is not found strstr returns a null pointer If s2 points to a string of zero length s1 is ret
403. structs with Multiple Instructions There can be many assembly instructions in one template If the asm string is longer than one line you may continue it on the next line by placing a backslash at the end of the line or by quoting each line separately This is an example of multiple instructions in a template asm se exp 1 hi sr norm 1 hi 0 sr0 e normalized output e inval input tset isr Sri STOT 5 clobbers Assembly Construct Reordering and Optimization For the purpose of optimization the compiler assumes that the side effects ofan asm construct are limited to changes in the output operands or the items specified using the clobber specifiers This does not mean that you 1 74 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler cannot use instructions with side effects but you must be careful to notify the compiler that you are using them by using the clobber specifiers see Table 1 10 on page 1 73 The compiler may eliminate supplied assembly instructions if the output operands are not used move them out of loops or replace two with one if they constitute a common subexpression Also if the instruction has a side effect on a variable that otherwise appears not to change the old value of the variable may be reused later if it happens to be found in a register Use the keyword volatile to prevent an asm instruction from being moved combined
404. structures can be initialized by arbitrary expressions involv ing literals previously declared variables and functions Indexed Initializer Support ISO ANSI Standard C and C requires the elements of an initializer to appear in a fixed order the same as the order of the elements in the array or structure being initialized The cc219x compiler by comparison sup ports labeling elements for array initializers This feature lets you specify array or structure elements in any order by specifying the array indices or structure field names to which they apply All index values must be con stant expressions even in automatic arrays For an array initializer the syntax INDEX appearing before an initializer element value specifies the index to be initialized by that value Subse quent initializer elements are then applied to sequentially following VisualDSP 3 5 C C Compiler and Library Manual 1 87 for ADSP 219x DSPs C C Compiler Language Extensions elements of the array unless another use of the INDEX syntax appears The index values must be constant expressions even if the array being ini tialized is automatic The following example shows equivalent array initializers the first ini tializer is in ISO ANSI standard C C the second initializer uses the cc219x compiler The index precedes the value being assigned to that element Example 1 Standard amp cc219x C C Array Initializer Standard Array
405. t e ETSI Support Overview on page 1 106 e Calling ETSI Library Functions on page 1 108 e Using the ETSI Built In Functions on page 1 109 e Linking ETSI Library Functions on page 1 109 e Working with ETSI Library Source Code on page 1 110 e ETSI Support for Data Types on page 1 110 e ETSI Header File on page 1 111 ETSI Support Overview The use of fractional arithmetic is vital for many applications on DSP pro cessors as information can be held more compactly than in floating point It would take 24 bits in floating point format to match the precision of 16 bit fractional data Also control of normalization and precision is more complex with floating point Many DSPs do not include hardware support for floating point arithmetic and these operations are therefore very expensive in both code size and performance terms for such DSPs 1 106 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler Fractional data has a representation similar to that of integers except that while an integer value is considered to have a decimal point to the right of the least significant bit a fractional value is considered to have a decimal point to the left of the most significant bit Fractional values are usually held in 16 bit or 32 bit containers In each case signed values are in the range 1 0 1 0 The bit operations on fractional data are identical to those on integer
406. t 2 xb bli yb b i 1 xa alil ya aLitl VisualDSP 3 5 C C Compiler and Library Manual 2 17 for ADSP 219x DSPs Loop Guidelines xc xa xb yc ya yb cli xc c i 1 ye Bad harder for the compiler to optimize Avoiding Loop Rotation by Hand Tip Do not rotate loops by hand Programmers are often tempted to rotate loops in DSP code by hand attempting to execute loads and stores from earlier or future iterations at the same time as computation from the current iteration This technique introduces loop carried dependencies that prevent the compiler from rear ranging the code effectively However it is better to give the compiler a normalized version and leave the rotation to the compiler int ss short a short b int n int sum 0 intiz for i s 08 T lt ii TEF d sum a i b i return sum Good will be rotated by the compiler int ss short a short b int n short ta tb int sum 0 int 05 ta ali tb bli for i 1 i lt n i sum ta tb tas val ids tb ib kas sum ta tb 2 18 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Achieving Optimal Performance from C C Source Code return sum Bad rotated by hand hard for the compiler to optimize By rotating the loop the scalar variables ta and tb have been added intro ducing loop carried dependencies Avoid
407. t always the same style that is better Tip Try both pointer and index styles 2 12 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Achieving Optimal Performance from C C Source Code The pointer style introduces additional variables that compete with the surrounding code for resources during the compiler optimizer s analysis Array accesses on the other hand must be transformed to pointers by the compiler and sometimes it does not do the job as well as you could do by hand The best strategy is to start with array notation If the generated code looks unsatisfactory try using pointers Outside the critical loops use the indexed style since it is easier to understand Function Inlining The function inlining may be used in two ways e By annotating functions in the source code with the inline key word In this case function inlining is only performed when optimization is enabled e By turning on automatic inlining with the 0a switch on page 1 37 This switch automatically enables optimization Tip Inline small frequently executed functions You can use the compiler s inline keyword to indicate that functions should have code generated inline at the point of call Doing this avoids various costs such as program flow latencies function entry and exit instructions and parameter passing overheads Using an inline function also has the advantage that the compiler can optimize through the i
408. t data while d process d the declaration of d is delayed until its initial value is available so that no variable is uninitialized at any point in the function Escape Character Constant The character escape e may be used in character and string literals and maps to the ASCII Escape code 27 Alignment Inquiry Keyword __alignof__ The __alignof__ type name construct evaluates to the alignment required for an object of a type The __alignof__ expression construct can also be used to give the alignment required for an object of the expression type If expression is an 1value may appear on the left hand side of an assign ment the alignment returned takes into account alignment requested by pragmas and the default variable allocation rules Keyword for Specifying Names in Generated Assembler asm The asm keyword can be used to direct the compiler to use a different name for a global variable or function see also pragma linkage_name identifier on page 1 126 VisualDSP 3 5 C C Compiler and Library Manual 1 145 for ADSP 219x DSPs C C Compiler Language Extensions For example int N asm C11045 tells the compiler to use the label C11045 in the assembly code it gener ates wherever it needs to access the source level variable N By default the compiler would use the label _N The asm keyword can also be used in function declarations but not func tion definition However a defi
409. t m complex_fractl6 c Complex void cmatssub const complex_double a complex_double b Matrix Scalar int n int m complex_double c Subtraction void cmatssubf const complex_float a complex_float b int n int m complex_float c void cmatssub_frl6 const complex_fractl6 a complex_fractl6 b int n int m complex_fractl6 c 4 14 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs DSP Run Time Library Table 4 5 Matrix Functions Contd Description Prototype Complex void cmatsmlt const complex_double a complex_double b Matrix Scalar int n int m complex_double c Multiplication void cmatsmltf const complex_float a complex_float b int n int m complex_float c void cmatsmlt_frl6 const complex_fractl6 a complex_fractl6 b int n int m complex_fractl6 c Complex void cmatmadd const complex_double a Matrix Matrix const complex_double b int n int m complex_double c Addition void cmatmaddf const complex_float a const complex_float b int n int m complex_float c void cmatmadd_frl6 const complex_fractl6 a const complex_fractl6 b int n int m complex_fractl6 c Complex void cmatmsub const complex_double a Matrix Matrix const complex_double b int n int m complex_double c Subtraction void cmatmsubf const complex_float a const complex_float b int n int m complex_float c void cmatmsub_frl6 const complex_fractl6 a
410. t no load or store in the loop accesses the same memory as any other This helps to produce shorter loop kernels as it permits instructions in the loop to be rearranged more freely See pragma no_alias on page 1 125 for more information 2 36 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Achieving Optimal Performance from C C Source Code Useful Optimization Switches Table 2 1 lists the compiler switches useful during the optimization process Table 2 1 C C Compiler Optimization Switches Switch Name Description const read write Specifies that data accessed via a pointer to const data may be modi on page 1 24 fied elsewhere flags link e Specifies linker section elimination on page 1 27 force circbuf Treats array references of the form array i n as circular buffer on page 1 27 operations ipa Turns on inter procedural optimization Implies use of 0 on page 1 30 May be used in conjunction with 0s or Ov no fp associative Does not treat floating point multiply and addition as an associative on page 1 34 0 Enables code optimizations and optimizes the file for speed on page 1 37 0S Optimizes the file for size on page 1 37 0v num Controls speed vs size optimizations sliding scale on page 1 38 save temps on page 1 44 Saves intermediate files for example s VisualDSP 3 5 C C Compiler and Library Manu
411. t32 32 bits fractional 2 On any platform the basic type int will be the native word size The data type long is 32 bits as is float A pointer is the same size as an int 1 54 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler In the ADSP 219x processor architecture the long long int unsigned long long int and long double data types are not implemented they will not be redefined to other types In general double word data types should be expected to run more slowly relying largely on software emu lated arithmetic Analog Devices does not support data sizes smaller than a single word location for the ADSP 219x processors For the current processors this means that both short and char have the same size as int Although 16 bit chars are unusual they do conform to the standard Type double poses a special problem The C language tends to default to double for constants and in many floating point calculations Without some special handling many programs would inadvertently end up using slow speed emulated 64 bit floating point arithmetic even when variables are declared consistently as float In order to avoid this problem and provide the best performance the size of double on the ADSP 219x processors is always 32 bits This should be acceptable for most DSP programming It is not however fully standard conforming The standard include files automatically redefine the math library i
412. tart 3 160 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library va_start initialize the variable length argument list processing Synopsis d Finclude lt stdarg h gt void va_start va_list ap parmN Description The va_start macro is used in a function declared to take a variable num ber of arguments to start processing those variable arguments The first argument to va_start should be a variable of type va_list which is used by va_arg to walk through the arguments The second argument is the name of the last named parameter in the func tion s parameter list the list of variable arguments immediately follows this parameter The va_start macro must be invoked before either the va_arg or va_end macro can be invoked Error Conditions The va_start macro does not return an error condition Example See va_arg on page 3 158 See Also va_arg va_end VisualDSP 3 5 C C Compiler and Library Manual 3 161 for ADSP 219x DSPs C Run Time Library Reference 3 162 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs 4 DSP RUN TIME LIBRARY This chapter describes the DSP run time library which contains a broad collection of functions that are commonly required by signal processing applications The services provided by the library include support for gen eral purpose signal processing such as companders filters and Fast Fourier Transform FFT fu
413. te Header File Control Pragmas The header file control pragmas help the compiler to handle header files These pragmas are hdrstop no_pch once and system_header pragma hdrstop The pragma hdrstop is used in conjunction with the pch precompiled header switch on page 1 40 The switch tells the compiler to look for a precompiled header pch file and if it cannot find one to generate a file for use on a later compilation The pch file contains a snapshot of all the code preceding the header stop point By default the header stop point is the first non preprocessing token in the primary source file The pragma hdrstop can be used to set the point earlier in the source file 1 136 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler In the example include standard_defs h include common_data h Finclude frequently_changing_data h int i the default header stop point is start of the declaration of i This might not be a good choice as in this example frequently_changing_data h might change frequently causing the pch file to be regenerated often and therefore losing the benefit of precompiled headers The hdrstop pragma can be used to move the header stop to a more appropriate place In this case include standard_defs h include common_data h pragma hdrstop include frequently_changing_data h int the precompiled header file would not in
414. ted on an address boundary that is multiple of twice the FFT size If the input data can be overwritten then optimum memory usage can be achieved by specifying the input array as either the output array or as the temporary array provided that the mem ory size of the input array is at least 2 n Specifying the input array as the temporary array will also result in increased run time performance 4 94 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs DSP Run Time Library The twiddle table is passed in the argument w which must contain at least n 2 twiddle factors The function twidfftrad2_fr16 may be used to ini tialize the array If the twiddle table contains more factors than needed for a particular call on rfft_fr16 then the stride factor has to be set appro priately otherwise it should be 1 The argument scale_method controls how the function should scale the output to avoid overflow If no scaling is selected by setting scale_method to zero then the input signal should be sufficiently conditioned to avoid overflow The block_exponent argument will be set to zero The function will perform static scaling if scale_method is set to 1 For static scaling the function will scale intermediate results to prevent over flow The final output will be scaled by 1 n and block_exponent will be set to log2 n If scale_method is set to 2 then the function will select dynamic scaling Under dynamic scaling the function
415. ted to by s1 The behavior of memcpy is undefined if the two objects overlap The memcpy function returns the address of s1 Error Conditions The memcpy function does not return an error condition Example include lt string h gt char a SRC char b DEST memcpy b a 3 fe AD SRET See Also memmove memcpy_from_shared memcpy_to_shared strcpy strncpy 3 96 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library memcpy_from_shared copy characters from an object in the ADSP 2192 12 processor s shared memory 0x20000 0x20FFF to non shared memory in default data area Synopsis d Finclude lt string h gt void memcpy_from_shared void sl void s2 size_t n Description The memcpy_from_shared function copies n characters from the object pointed to by s2 into the object pointed to by s1 The s2 parameter must be an object in the ADSP 2192 12 processor s shared memory 0x20000 0x20FFF Error Conditions The memcpy_from_shared function does not return raise or set any error conditions See Also memcpy memcpy_to_shared VisualDSP 3 5 C C Compiler and Library Manual 3 97 for ADSP 219x DSPs C Run Time Library Reference memcpy_to_shared copy characters from object in default data area to an object in the ADSP 2192 12 processor s shared memory 0x20000 0x20FFF Synopsis Finclude lt string h gt void memcpy_to_shared
416. tem control set system registers General Register set ASTAT SSTAT MSTAT ICNTL IMASK IRPTL DMPG1 DMPG2 IOPG System Control Register set BO B1 B2 B3 B4 B5 B6 B7 SYSCTL CACTL DBGCTRL DBGSTAT CNTO CNT1 CNT2 CNT3 Also any 8 bit value used as a register identifier VisualDSP 3 5 C C Compiler and Library Manual 1 95 for ADSP 219x DSPs C C Compiler Language Extensions The prototypes for these functions are as defined in sysreg h void sysreg_write const int sysreg const int value int sysreg_read const int sysreg The sysreg parameter for these functions can be a member of the SysReg enumeration defined in sysreg h This enumerations is used to map the actual registers to a small constant defined as a user friendly name The SysReg enumeration has the following definitions General Register set sysreg_ASTA 0x0 ASTAT register arithmetic status sysreg_SSTA 0x1 SSTAT register shifter status sysreg_MSTA 0x2 MSTAT register multiplier status sysreg_ICNTL 0x3 ICNTL register interrupt control sysreg_IMASK 0x4 IMASK register interrupts enabled mask sysreg_IRPTL 0x5 Interrupt Latch register sysreg_DMPG1 0x6 DMPG1 high address register sysreg_DMPG2 0x7 DMPG2 high address register sysreg_I0PG 0x8 IOPG I O page register System Control Register set sysreg_BO 0x9 BO base register sysreg_Bl
417. tements declare the overload of two func tions named f int f int int f x char x return x no anach The no anach disable C anachronisms switch directs the compiler to disallow some old C language features that are prohibited by the C standard See the anach switch on page 1 52 for a full description of these features no demangle The no demangle disable demangler switch directs the compiler to pre vent the driver from filtering any linker errors through the demangler The demangler s primary role is to convert the encoded name of a func tion into a more understandable version of the name VisualDSP 3 5 C C Compiler and Library Manual 1 53 for ADSP 219x DSPs Compiler Command Line Interface Data Type Sizes The sizes of intrinsic C C data types are selected by Analog Devices so that normal C C programs execute with hardware native data types and therefore at high speed Table 1 6 shows the size used for each of the intrinsic C C data types Table 1 6 Data Type Sizes for ADSP 219x Processors Type Bit Size sizeof returns char 8 bits signed 1 unsigned char 8 bits unsigned 1 int 16 bits signed 1 unsigned int 16 bits unsigned 1 short 16 bits signed 1 unsigned short 16 bits unsigned 1 long 32 bits signed 2 unsigned long 32 bits unsigned 2 float 32 bits float 2 double 32 bits float 2 pointer 16 bits 1 function pointer 32 bits 2 fract16 16 bits fractional 1 frac
418. tered using atexit Error Conditions The atexit function returns a non zero value if the function cannot be registered Example d Finclude lt stdlib h gt extern void goodbye void if atexit goodbye exit 1 See Also abort exit VisualDSP 3 5 C C Compiler and Library Manual 3 33 for ADSP 219x DSPs C Run Time Library Reference atof convert string to a double Synopsis include lt stdlib h gt double atof const char nptr Description The atof function converts a character string into a floating point value of type double and returns its value The character string is pointed to by the argument nptr and may contain any number of leading whitespace characters as determined by the function isspace followed by a floating point number The floating point number may either be of the form of a decimal floating point number or a hexadecimal floating point number A decimal floating point number has the form sign digits digits e E sign digits The sign token is optional and is either plus or minus and digits are one or more decimal digits The sequence of digits may contain a decimal point The decimal digits can be followed by an exponent which consists of an introductory letter e or E and an optionally signed integer If neither an exponent part nor a decimal point appears a decimal point is assumed to follow the last digit in the string The form of a
419. the arrays However benefits in run time performance will be realized if the output array is allocated on an address boundary that is a multiple of twice the FFT size If the input data can be overwritten then optimum memory usage can be achieved by specifying the input array as either the output array or as the temporary array Specifying the input array as the temporary array will also result in increased run time performance 4 36 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs DSP Run Time Library The twiddle table is passed in the argument w which must contain at least n 2 twiddle factors The function twidfftrad2_fr16 may be used to ini tialize the array If the twiddle table contains more factors than needed for a particular call on cfft_fr16 then the stride factor has to be set appro priately otherwise it should be 1 The argument scale_method controls how the function should scale the output to avoid overflow If no scaling is selected by setting scale_method to zero then the input signal should be sufficiently conditioned to avoid overflow The block_exponent argument will be set to zero The function will perform static scaling if scale_method is set to 1 For static scaling the function will scale intermediate results to prevent over flow The final output will be scaled by 1 n and block_exponent will be set to log2 n If scale_method is set to 2 then the function will select dynamic scaling
420. tic scaling if scale_method is set to 1 For static scaling the function will scale intermediate results to prevent over flow The final output will be scaled by 1 n and block_exponent argument will be set to log2 n If scale_method is set to 2 then the function will select dynamic scaling Under dynamic scaling the function will inspect the intermediate results and will only scale to avoid overflow Dynamic scaling therefore mini mizes loss of precision but at the possible cost of slightly reduced performance The block_exponent argument will be set to a value between 0 which indicates that no scaling was performed and 10g2 n as if static scaling was performed Algorithm N 1 X k x n n 0 When the sequence length n is not a power of four the radix2 method must be used See cfft on page 4 36 for more information Domain Input sequence length n must be a power of four and at least 16 VisualDSP 3 5 C C Compiler and Library Manual 4 39 for ADSP 219x DSPs DSP Run Time Library Reference cfft2d NxN point 2 D complex input FFT Synopsis include lt filter h gt void cfft2d_frl6 in t out wl wst n block_exponent scale_method const complex_fractl6 in pointer to input matrix a n n complex_fractl6 t pointer to working buffer t n n complex_fractl6 out pointer to output matrix c n n const complex_fractl6 wl twiddle sequence int wst
421. tically converted to bool when needed These keywords behave more or less as if the declaration that follows had appeared at the beginning of the file except that assigning a nonzero inte ger to a boo type always causes it to take on the value true typedef enum false true bool Pointer Class Support Keyword restrict The restrict operator keyword is an extension that supports restricted pointer features The use of restrict is limited to the declaration of a pointer and specifies that the pointer provides exclusive initial access to the object to which it points More simply restrict is a way that you can identify that a pointer does not create an alias Also two different restricted pointers can not designate the same object and therefore are not 1 84 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler aliases The compiler is free to use the information about restricted point ers and aliasing in order to better optimize C or C code that uses pointers The restrict keyword is most useful when applied to function parameters about which the compiler would otherwise have little information void fir short in short c short restrict out int n The behavior of a program is undefined if it contains an assignment between two restricted pointers except for the following cases e A function with a restricted pointer parameter may be called with an argument that is a restricted pointer e A
422. tional header defines numerous function objects hash_map The hash_map header defines two hashed map template containers hash_ set The hash_set header defines two hashed set template containers iterator The iterator header defines common iterators and operations on iterators list The list header defines a list template container map The map header defines two map template containers memory The memory header defines facilities for managing memory numeric The numeric header defines several numeric operations on sequences queue The queue header defines two queue template container adapters VisualDSP 3 5 C C Compiler and Library Manual 3 21 for ADSP 219x DSPs C and C Run Time Library Guide set The set header defines two set template containers stack The stack header defines a stack template container adapter utility The utility header defines an assortment of utility templates vector The vector header defines a vector template container The embedded C library also includes several headers for compatibility with traditional C libraries such as fstream h The fstream h header defines several iostreams template classes that manipulate external files iomanip h The iomanip h header declares several iostreams manipulators that take a single argument iostream h The iostream h header declares the iostreams objects that manipulate the standard streams new h The
423. tle understanding about what the code in the statement does In particular use of an asm statement in a loop may inhibit useful transformations The compiler has been enhanced with a large number of built in func tions These generate specific hardware instructions and are designed to allow the programmer to more finely tune the code produced by the com 2 14 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Achieving Optimal Performance from C C Source Code piler or to allow access to system support functions A complete list of compiler s built in functions is given in Compiler Built In Functions on page 1 94 Use of these builtins is much preferred to using inline asm statements Since the compiler knows what each builtin does it can easily optimize around them Conversely since the compiler does not parse asm state ments it does not know what they do and so is hindered in optimizing code that uses them Note also that errors in the text string of an asm state ment will be caught by the assembler and not the compiler Examples of efficient use of built in functions are given in System Sup port Built In Functions on page 2 26 Memory Usage The compiler in conjunction with the use of the linker description file LDF allows the programmer control over where data is placed in mem ory This section describes how to best lay out data for maximum performance Tip Try to put array
424. tor_for The pragma vector_for notifies the optimizer that it is safe to execute two iterations of the loop in parallel The vector_for pragma does not force the compiler to vectorize the loop the optimizer checks various properties of the loop and does not vectorize it if it believes it is unsafe or if it cannot deduce that the various properties necessary for the vectoriza tion transformation are valid Strictly speaking the pragma simply disables checking for loop carried dependencies void copy short a short b int i pragma vector_for for i 0 i lt 100 i ali b i In cases where vectorization is impossible for example if array a were aligned on a word boundary but array b was not the information given in the assertion made by vector_for may still be put to good use in aiding other optimizations 1 124 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler pragma no_alias Use the pragma no_alias to tell the compiler the following has no loads or stores that conflict due to references to the same location through dif ferent pointers known as aliases In this example void vadd int a int b int out int n int i pragma no_alias for i 0 i lt n i outLi ali blil the use of pragma no_alias just before the loop informs the compiler that the pointers a b and out point to different arrays so no load from b or a will be using the sam
425. ts a set of extensions to the ANSI standard for the C and C languages These extensions add support for DSP hardware and allow some C programming features when compiling in C mode The extensions are also available when compiling in C mode This section contains e Inline Function Support Keyword inline on page 1 62 e Inline Assembly Language Support Keyword asm on page 1 63 e Dual Memory Support Keywords pm dm on page 1 78 e Placement Support Keyword section on page 1 83 e Boolean Type Support Keywords bool true false on page 1 84 e Pointer Class Support Keyword restrict on page 1 84 e Variable Length Array Support on page 1 85 e Non Constant Aggregate Initializer Support on page 1 87 e Indexed Initializer Support on page 1 87 e Aggregate Constructor Expression Support on page 1 89 e Fractional Type Support on page 1 90 e Preprocessor Generated Warnings on page 1 93 e C Style Comments on page 1 94 e Compiler Built In Functions on page 1 94 e ETSI Support on page 1 106 e Pragmas on page 1 119 e GCC Compatibility Extensions on page 1 138 VisualDSP 3 5 C C Compiler and Library Manual 1 59 for ADSP 219x DSPs C C Compiler Language Extensions The additional keywords that are part of these C C extensions do not conflict with any ISO ANSI C C keywords The formal definitions of these extension keywords are prefix
426. ts the information generated by the interprocedural analysis see Interprocedural Analysis on page 1 57 to increase the cases where it knows it is safe to do so Consider the following code void copy short a short b int i for i1 0 1 lt 100 i ali bli If you call copy with two calls say copy x y and later copy y z the interprocedural analysis will not be able to tell that a never aliases b Therefore the optimizer cannot be sure that one iteration of the loop is not dependent on the data calculated by the previous iteration of the loop If it is known that each iteration of the loop is not dependent on the pre vious iteration then the vector_for pragma can be used to explicitly notify the compiler that this is the case VisualDSP 3 5 C C Compiler and Library Manual 1 123 for ADSP 219x DSPs C C Compiler Language Extensions pragma loop_count min max modulo The loop_count min max modulo pragma appears just before the loop it describes It asserts that the loop will iterate at least min times no more than max times and a multiple of modulo times This information enables the optimizer to omit loop guards to decide whether the loop is worth completely unrolling and whether code need be generated for odd itera tions The last two arguments can be omitted if they are unknown For example int i pragma loop_count 24 48 8 for C1 03 7 lt ny EFE pragma vec
427. turns a non zero value Error Conditions The isgraph function does not return any error conditions Example include lt ctype h gt int ch for ch 0 ch lt Ox7f ch printf 04x ch printf 2s isgraph ch graph putchar n See Also isalnum iscntrl isprint VisualDSP 3 5 C C Compiler and Library Manual 3 75 for ADSP 219x DSPs C Run Time Library Reference isinf test for infinity Synopsis d Finclude lt math h gt int isinff float x int isinf double x Description The isinf function returns a zero if the argument is not set to the IEEE constant for Infnity or Infinity otherwise the function will return a non zero value Error Conditions The isinf function does not return or set any error conditions Example d Finclude lt stdio h gt d Finclude lt math h gt static int fail 0 main test int isinf double union double d float f unsigned long l ou ifdef _ DOUBLES _ARE_FLOATS u l OxFF800000L if isinf u d 0 fail u 1 OxFF800001L if isinf u d 0 failt 3 76 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library u 1 Ox7F800000L if isinf u d 0 fail u 1 Ox7F800001L if isinf u d 0 fail dfendif test int isinff float u 1 OxFF800000L if isinff u f 0 fail u 1 OxFF800001L if isinff u f 0 fail u 1 Ox7F800000L if
428. twiddle factor stride int n number of FFT points K int block_exponent block exponent of output data int scale method scaling method desired O none l static 2 dynamic Description This function computes the two dimensional Fast Fourier Transform of the complex input matrix a n n and stores the result to the complex output matrix c n n The size of the input array in the output array out and the temporary working buffer t is n n where n represents the number of points in the FFT The function does not impose any special memory alignment requirements on the arrays However benefits in run time performance will be realized if the output array is allocated on an address boundary that is a multiple of twice the FFT size The twiddle table is passed in the argument w which must contain at least n 2 twiddle factors The function twidfft2d_fr16 may be used to initial ize the array If the twiddle table contains more factors than needed for a particular call on cfft2d_fr16 then the stride factor has to be set appro priately otherwise it should be 1 4 40 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs DSP Run Time Library The arguments block_exponent and scale_method have been added for future expansion However the current version of the function ignores the argument and always scales the output by n n this is equivalent to static scaling The function will also set block_exponent to l
429. types on page 1 25 Supports building a h file directly and writing a com plete set of debugging information for the header file VisualDSP 3 5 C C Compiler and Library Manual 1 13 for ADSP 219x DSPs Compiler Command Line Interface Table 1 4 C C Compiler Common Switches Cont d Switch Name Description on page 1 25 default linkage asm C C Sets the default linkage type C C asm dry on page 1 25 Displays but does not perform main driver actions verbose dry run dryrun on page 1 26 Displays but does not perform top level driver actions terse dry run E on page 1 26 Preprocesses but does not compile the source file ED on page 1 26 EE on page 1 26 Produce preprocessed file and compile source Preprocesses and compiles the source file extra keywords on page 1 26 Recognizes Analog Devices extensions to ISO ANSI stan dards for C and C Default mode flags tools lt argl gt Larges on page 1 27 Passes command line switches through the compiler to other build tools fp associative on page 1 27 Treats floating point multiplication and addition as asso ciative force cirbuf on page 1 27 full version on page 1 27 Treats array references of the form array i n as circular buffer operations Displays version information for build tools g on page 1 28 Gener
430. uble pow double double float powf float float Description The pow function computes the value of the first argument raised to the power of the second argument Error Conditions A domain error occurs if the first argument is negative and the second argument cannot be represented as an integer If the first argument is zero the second argument is less than or equal to zero and the result cannot be represented EDOM is stored in errno Example d Finclude lt math h gt double z z pow 4 0 2 0 Pe z 16 0 See Also exp Idexp 3 104 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library qsort quicksort Synopsis d Finclude lt stdlib h gt void qsort void base size_t nelem size_t size int compare const void const void Description The qsort function sorts an array of nelem objects pointed to by base The size of each object is specified by size The contents of the array are sorted into ascending order according to a comparison function pointed to by compare which is called with two arguments that point to the objects being compared The function shall return an integer less than equal to or greater than zero if the first argu ment is considered to be respectively less than equal to or greater than the second If two elements compare as equal their order in the sorted array is unspec ified The qsort function executes a binary search
431. ubtract with carry 1 118 multiply and accumulate 1 116 multiply and accumulate with rounding 1 112 multiply and accumulate without saturation 1 116 multiply and subtract 1 116 multiply and subtract with rounding 1 112 multiply and subtract without saturation 1 116 multiply both most significant bits and least significant bits of long by same short 1 116 multiply short by a long 1 118 multiply two longs 1 118 multiply with rounding 1 113 round 1 113 saturate 1 114 shift right with rounding 1 114 short absolute 1 111 short add 1 111 short division 1 111 short multiply 1 112 short negate 1 113 short normalize 1 113 short shift left 1 114 short shift right 1 114 short subtract 1 114 ETSI fract_arith h header file 1 111 exit normal program termination function 3 52 exit program termination function 3 52 VisualDSP 3 0 C C Compiler and Library Manual for ADSP 219x DSPs INDEX exp exponential function 3 53 exponentiation 4 25 4 26 extensions using compiler language 1 3 external memory access 1 99 external_memory_read function 3 54 external_memory_write function 3 56 extra keywords enable short form keywords compiler switch 1 26 EZ KIT Lite 1 166 F fabs float absolute value function 3 58 false see Boolean type support keywords bool true false far address operator 1 102 jump return see longjmp setjmp functions type qualifiers 1 99 far pointers 1
432. uct operand 1 68 construct optimization 1 74 construct reordering 1 74 construct template 1 64 construct with input and output operands 1 75 constructs with multiple instructions 1 74 subroutines 1 169 assignments memory 1 80 atan arc tangent function 3 31 atan_fr16 function 3 31 atan2 arc tangent of quotient function 3 32 atan2 atan2f arc tangent division functions 3 33 atan2_fr16 function 3 32 atexit select exit function function 3 33 atof convert string to double function 3 34 atoi convert string to integer function 3 37 atol convert string to long integer function 3 38 attributes functions variables and types 1 146 autocoh autocoherence function 4 28 autocorr autocorrelation function 4 29 automatic inlining 1 57 2 13 loop control variables 2 21 variables 1 78 B base 10 anti log function 4 26 binary array search see bsearch function bitfields signed 1 45 unsigned 1 47 1 3 VisualDSP 3 0 C C Compiler and Library Manual for ADSP 219x DSPs INDEX bool see Boolean type support keywords bool true false boolean type keywords 1 84 Boolean type support keywords bool true false 1 60 1 84 bsearch binary search in sorted array function 3 39 bss compiler switch 1 23 build lib build library compiler switch 1 24 built in functions 1 94 1 95 circular buffer 1 103 system support 2 26 C C comments compiler switch 1 24 c compile only compiler switch 1 24 C
433. unction 3 135 strtod convert string to double function 3 136 strtok convert string to tokens function 3 140 strtol convert string to long integer function 3 142 strtoul convert string to unsigned long integer function 3 144 strxfrm transform string using LC_COLLATE function 3 146 strxfrm function 3 146 support example 1 176 switches common C and C modes 1 21 C mode only 1 21 C C mode selection 1 21 symbol unresolved 1 103 syntax only only check syntax compiler switch 1 45 sysdef system definitions compiler switch 1 45 sysreg h header file 1 95 1 102 2 26 sysreg_read read from non memory mapped register function 3 148 sysreg_write write to non memory mapped register function 3 151 system control register set 3 148 3 151 header files 1 149 registers 1 95 T T linker description file compiler switch 1 46 1 26 VisualDSP 3 0 C C Compiler and Library Manual for AD tan tangent function 3 154 tan_fr16 function 3 154 tanh hyperbolic tangent function 3 155 template asm in C program 1 64 assembly construct 1 64 instantiation pragmas 1 134 terminate see atexit exit functions threads enable thread safe build compiler switch 1 46 time time the compiler switch 1 47 tokens string convert see strtok function tolower convert from uppercase to lowercase function 3 156 toupper convert from lowercase to uppercase function 3 157 transformations 4 6 true see Bo
434. unction then it may clobber the L registers In that case the L registers are re zeroed after any call to that function The registers M1 M2 M6 and M7 have their required value set in an analogous manner The IMASK ICNTL IRPTL SSTAT SYSCTL CACTL CCODE LPSTACKA and LPSTACKP registers are never used by the compiler and are never preserved User Reserved Registers User reserved registers will never be preserved in the function wrappers whether in the clobbered set or not Function Results The registers in which a function returns its result must always be clob bered by the callee and retain their new value in the caller They may appear in the clobbered set of the callee but it will make no difference to VisualDSP 3 5 C C Compiler and Library Manual 1 133 for ADSP 219x DSPs C C Compiler Language Extensions the generated code the return register will not be saved and restored Only the return register used by the particular function return type is spe cial Return registers used by different return types will be treated in the clobbered list in the convention way For example typedef struct int x int y Point typedef struct int x 10 Big int fo Result in AX1 SR1 SRO and IO may be preserved across call Point g Result in SRI and SRO AX1 and IO may be preserved across call Big f Result pointer in IO AX1 SR1 and SRO may be preserved across call pragma result_
435. upt was raised A handler for an interrupt or signal is set using the interrupt or signal C run time library functions These functions pass the signal name and a handler function pointer as parameters The signal macro names are defined in signal h The default interrupt vector code may be replaced with custom code by modifying or creating a new piece of code to be placed at the vector addresses This is usually done by copying the default 219x_int_tab asm file and LOF file into your project and modifying them as required An interrupt pragma defined function can be placed in the interrupt vec tor code directly or be jumped to from the vector if it does not fit in the interrupt vector space see Interrupt Handler Pragmas on page 1 122 The reset vector code which is placed at address zero 0 and does a jump to____system_start should not be replaced Stack Frame The stack frame or activation record provides for the following activities e space for local variables for the current procedure For the com piler this includes temporary storage as well as that required for explicitly declared user automatic variables e place to save linkage information such as return addresses location information for the previous caller s stack frame and to allow this procedure to return to its caller VisualDSP 3 5 C C Compiler and Library Manual 1 155 for ADSP 219x DSPs C C Run Time Model and Environment e space to sav
436. uptf interrupts poll_flag_in raise signal functions reciprocal square root rsqrt function 4 101 reference 3 15 register classification mode status MSTAT 1 162 registers 1 161 VisualDSP 3 0 C C Compiler and Library Manual for ADSP 219x DSPs clobbered 1 130 DAGI 1 164 DAG 1 165 data 1 163 for asm constructs 1 68 miscellaneous 1 163 user reserved 1 133 regs_clobbered string 1 131 remove function 3 14 rename function 3 14 reserve reserve register compiler switch 1 43 resetting optimization 1 126 restrict keyword 2 23 qualifier 2 22 restricted pointer 2 22 retain_name pragma 1 127 return registers 1 134 values 1 159 rfft N point real input FFT function 4 94 rfft2d NxN point 2 D real input FFT function 4 98 rfftrad4 N point inverse FFT function 4 96 rms root mean square function 4 100 rsqrt reciprocal square root function 4 100 run time header 1 154 linking library functions 3 6 run time environment See also mixed C C assembly programming programming See mixed C C assembly programming S S stop after compilation compiler switch 1 43 s strip debugging information compiler switch 1 43 saturated arithmetic 1 93 save temps save intermediate files compiler switch 1 44 search character string see strchr strrchr functions search memory character see memchar function search path for include files 1 29 for library files 1 31 searching for included files 1 152 se
437. upts function causes the compiler to emit an instruc tion to disable hardware interrupts This function is implemented as a compiler built in The emitted instruc tion will be inlined at the point of its use The inclusion of the sysreg h include file is mandatory when using disable_interrupts The disable_interrupts function does not return a value Error Conditions The disable_interrupts function does not return raise or set any error conditions Example d Finclude lt sysreg h gt main disable_interrupts emits DIS INTS instruction inline See Also enable_interrupts io_space_read io_space_write mode_change sysreg_read sysreg_write VisualDSP 3 5 C C Compiler and Library Manual 3 49 for ADSP 219x DSPs C Run Time Library Reference div division Synopsis include lt stdlib h gt div_t div int numer Description int denom The div function divides numer by denom both of type int and returns a structure of type div_t The type div_t is defined as typedef struct int quot int rem div_t where quot is the quotient of the division and rem is the remainder such that if result is of type div_t result quot denom result rem numer Error Conditions If denom is zero the behavior of the div function is undefined Example d Finclude lt stdlib h gt div_t result result div 5 2 See Also Idiv fmod modf result quot 2 result rem 1
438. urned Example d Finclude lt string h gt char ptrl ptr2 ptrl TESTING ptr2 strstr ptrl EJ ptr2 points to the E in TESTING See Also strchr VisualDSP 3 5 C C Compiler and Library Manual 3 135 for ADSP 219x DSPs C Run Time Library Reference strtod convert string to double Synopsis include lt stdlib h gt double strtod const char nptr char endptr Description The strtod function extracts a value from the string pointed to by nptr and returns the value as a double The strtod function expects nptr to point to a string that represents either a decimal floating point number or a hexadecimal floating point number Either form of number may be pre ceded by a sequence of whitespace characters as determined by the isspace function that the function ignores A decimal floating point number has the form sign digits E digits te E sign digits The sign token is optional and is either plus or minus and dig its are one or more decimal digits The sequence of digits may contain a decimal point The decimal digits can be followed by an exponent which consists of an introductory letter e or E and an optionally signed integer If neither an exponent part nor a decimal point appears a decimal point is assumed to follow the last digit in the string The form of a hexadecimal floating point number is sign 0x 0X Chexdigs E hexdigs p P sign
439. use the directive form The C compiler supports pragmas for Arranging alignment of data Defining functions that can act as interrupt handlers Changing the optimization level midway through a module Changing how an externally visible function is linked Header file configurations and properties Giving additional information about loop usage to improve optimizations The following sections describe the pragmas that support these features Data Alignment Pragmas on page 1 121 Interrupt Handler Pragmas on page 1 122 Loop Optimization Pragmas on page 1 123 General Optimization Pragmas on page 1 125 Linking Control Pragmas on page 1 126 Function Side Effect Pragmas on page 1 128 Template Instantiation Pragmas on page 1 134 Header File Control Pragmas on page 1 136 1 120 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler The compiler will issue a warning when it encounters an unrecognized pragma directive or pragma operator The compiler will not expand any pre processor macros used within any pragma directive or pragma operator Data Alignment Pragmas The data alignment pragmas include align and pad pragmas Alignments specified using these pragmas must be a power of two The compiler will reject uses of those pragmas that specify alignments that are not powers of two pragma align num The align num pragma may be used before variable and field
440. value is clobbered by the asm template execution The compiler may make no assumptions about the regis ter s final value The operand must appear as part of the second argument to the asm construct Example d Table 1 9 on page 1 72 lists the registers that may be allocated for each register constraint letter The use of any letter not listed in the Con straint column of this table results in unspecified behavior The compiler does not check the validity of the code by using the constraint letter Table 1 10 on page 1 73 lists the registers that may be named as part of the clobber list It is also possible to claim registers directly instead of requesting a register from a certain class using the constraint letters You can claim the registers directly by simply naming the register in the location where the class letter would be The register names are the same as those used to specify the clobber list see Table 1 10 For example asm 0 41 2 ar sum output gt g x G Cy input ys would load x into ALU X register y into ALU Y register and sum will be calculated in register AR VisualDSP 3 5 C C Compiler and Library Manual 1 71 for ADSP 219x DSPs C C Compiler Language Extensions Table 1 9 ASM Operand Constraints Constraint Description Registers b input xregs to MAC MX1 MXO SR1 SRO MRI MR
441. ve names which begin with __builtin_ Note that identifiers beginning with double underlines __ are reserved by the C standard so these names will not conflict with user program identifiers The header files also define more readable names for the built in functions without the __builtin_ prefix These additional names are disabled if the no builtin switch is used on page 1 34 The cc219x compiler provides built in versions of some of the C library functions as described in Using the Compiler s Built In C Library Func tions on page 3 5 1 94 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler The sysreg h header file defines a set of functions that provide efficient system access to registers modes and addresses not normally accessible from C source These functions are specific to individual architectures and this section lists the built in functions supported at this time on ADSP 219x DSPs The compiler supports e Access to System Registers on page 1 95 e I O Space Read or Write on page 1 97 e Interrupt Control on page 1 98 e Mode Control on page 1 99 e Near and Far Type Qualifiers on page 1 99 e Circular Buffer Built In Functions on page 1 103 Access to System Registers The inclusion of sysreg h allows the use of functions that will generate efficient inline instructions to implement read and write of values from and to general register set and sys
442. verall application unnecessarily For more information refer to General Optimization Pragmas on page 1 125 Loop Optimization Pragmas Many pragmas are targeted towards helping to produce optimal code for inner loops These are the 1oop_count and no_alias pragmas pragma loop_count The loop_count pragma enables the programmer to inform the compiler about a loop s iteration count The compiler is able to make more reliable decisions about the optimization strategy for a loop if it knows the itera tion count range If you know that the loop count is always a multiple of some constant this can also be useful as it allows a loop to be partially unrolled or vectorized without the need for conditionally executed itera tions Knowledge of the minimum trip count may allow the compiler to omit the guards that are usually required after software pipelining Any of the parameters of the pragma that are unknown may be left blank An example of the use of the 100p_count pragma might be tpragma loop_count minimum 40 maximum 100 modulo 4 for i 0 i lt n i ali b i VisualDSP 3 5 C C Compiler and Library Manual 2 35 for ADSP 219x DSPs Pragmas Good the loop_count pragma gives compiler helpful information to assist optimization For more information refer to pragma loop_count min max modulo on page 1 124 pragma no_alias When immediately preceding a loop the no_alias pragma asserts tha
443. void sl void s2 size_t n Description The memcpy_to_shared function copies n characters from the object pointed to by s2 into the object pointed to by s1 The s1 parameter must be an object in the ADSP 2192 12 processor s shared memory 0x20000 0x20FFF Error Conditions The memcpy_to_shared function does not return raise or set any error conditions See Also memcpy memcpy_from_shared 3 98 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library memmove copy characters between overlapping objects Synopsis d Finclude lt string h gt void memmove void sl const void s2 size_t n Description The memmove function copies n characters from the object pointed to by s2 into the object pointed to by s1 The entire object is copied correctly even if the objects overlap The memmove function returns a pointer to s1 Error Conditions The memmove function does not return an error condition Example d Finclude lt string h gt char ptr str ABCDE ptr str 2 memmove str str 3 ptr ABC str ABABC See Also memcpy strcpy strncpy VisualDSP 3 5 C C Compiler and Library Manual 3 99 for ADSP 219x DSPs C Run Time Library Reference memset set range of memory to a character Synopsis include lt string h gt void memset void sl int c size_t n Description The memset function sets a range of memory to the input
444. volution Synopsis d Finclude lt filter h gt void conv2d_frl 6 minl const fractl6 minl int mrowl int mcoll const fractl6 min2 fractl6 mrow2 int mcol2 fractl6 mout Description mrowl mco DSP Run Time Library pointer to input matrix 1 nu nu ber of rows in matrix 1 ber of columns in matrix 1 pointer to input matrix 2 nu nu poi ber of rows in matrix 1 ber of columns in matrix 2 nter to output matrix min2 mrow2 mcol2 mout tf E K Ei K egi This function computes the two dimensional convolution of input matrix minl of size mrowl x mcoll and min2 of size mrow2 x mcol2 and stores the result in matrix mout of dimension mrowl mrow2 1 x mcoll mcol2 1 Algorithm Two dimensional input matrix min1 is convolved with input matrix min2 placing the result in a matrix pointed to by mout mcol2 1 mrow2 1 mout c r X gt minI c i r j min2 mcol2 1 i mrow2 1 j i 0 j 0 for c 0 to mcoll mcol2 1 and r 0 to mrow2 1 Domain 1 0 to 1 0 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs 4 49 DSP Run Time Library Reference conv2d3x3 2 D convolution Synopsis include lt filter h gt void conv2d3x3_frl6 minl const fractl6 minl int mrowl int mcoll const fractl6 min2 fractl6 moutl Description mrowl mcoll min2 mout pointer to i
445. without incurring a stall The array declaration of one of either a or b is modified to pm int a 100 and any pointers to the buffer a become for example pm int p a to allow simultaneous accesses to the two buffers Note that the explicit placement of data in PM can only be done for global data 2 16 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Achieving Optimal Performance from C C Source Code Loop Guidelines Loops are where an application will ordinarily spend the majority of its time It is therefore useful to look in detail at how to help the compiler to produce the most efficient code possible for them Keeping Loops Short For best code efficiency loops should be as small as possible Large loop bodies are usually more complex and difficult to optimize Additionally they may require register data to be stored in memory This will cause a decrease in code density and execution performance Avoiding Unrolling Loops Tip Do not unroll loops yourself Not only does loop unrolling make the program harder to read but it also prevents optimization by complicating the code for the compiler void val const short aL const short bL short cL int n int i for i 0 i lt n i cli bli a i Good the compiler will unroll if it helps void va2 const short aL const short b short cL int n short xa xb xc ya yb yc int i for i 0 i lt n i
446. word inline on page 1 62 dm Specifies the location of a static or global variable or qualifies a pointer declaration as referring to Data Memory For more information see Dual Memory Support Keywords pm dm on page 1 78 1 60 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler Table 1 7 Keyword Extensions Cont d Keyword extensions Description pm Specifies the location of a static or global variable or qualifies a pointer declaration as referring to Program Memory For more information see Dual Memory Support Keywords pm dm on page 1 78 section string Specifies the section in which an object or function is placed For more information see Placement Support Keyword section on page 1 83 bool true false A Boolean type For more information see Boolean Type Support Keywords bool true false on page 1 84 restrict keyword Specifies restricted pointer features For more information see Pointer Class Support Keyword restrict on page 1 84 Table 1 8 Operational Extensions Operation extensions Description Variable length arrays Support for variable length arrays lets you use automatic arrays whose length is not known until runtime For more information see Variable Length Array Support on page 1 85 Non constant initializers Support for non co
447. word section The section keyword directs the compiler to place an object or function in an assembly SECTION in the compiler s intermediate assembly output file You name the assembly SECTION with section s string literal parameter If you do not specify a section for an object or function declaration the compiler uses a default section The LDF file supplied to the linker must also be updated to support the additional named sections VisualDSP 3 5 C C Compiler and Library Manual 1 83 for ADSP 219x DSPs C C Compiler Language Extensions Applying section is only meaningful when the data item is something that the compiler can place in the named section Apply section only to top level named objects that have static duration they are explicitly static or are given as external object definitions The example shows the declaration of a static variable that is placed in the section called bingo static section bingo int x Boolean Type Support Keywords bool true false The bool true and false keywords are extensions to ANSI C that sup port the C Boolean type The boo keyword is a unique signed integral type There are two built in constants of this type true and false When converting a numeric or pointer value to bool a zero value becomes false a nonzero value becomes true A bool value may be converted to int by promotion taking true to one and false to zero A numeric or pointer value is automa
448. x DSPs Compiler C C and Assembly Language Interface This section describes how to call assembly language subroutines from within C or C programs and C or C functions from within assembly language programs Before attempting to perform either of these calls be sure to famil iarize yourself with the information about the C C run time model including details about the stack data types and how argu ments are handled contained in C C Run Time Model and Environment on page 1 153 This section contains e Calling Assembly Subroutines from C C Programs on page 1 170 e Calling C C Functions from Assembly Programs on page 1 172 e Using Mixed C C and Assembly Naming Conventions on page 1 174 e C Programming Examples on page 1 176 VisualDSP 3 5 C C Compiler and Library Manual 1 169 for ADSP 219x DSPs C C and Assembly Language Interface Calling Assembly Subroutines from C C Programs Before calling an assembly language subroutine from a C C program create a prototype to define the arguments for the assembly language sub routine and the interface from the C C program to the assembly language subroutine Even though it is legal to use a function without a prototype in C C prototypes are a strongly recommended practice for good software engineering When the prototype is omitted the compiler cannot perform argument type checking and assumes that the return value
449. xternal memory address to write The second parameter is the lower 16 bits of the address of the external memory to write This function is implemented as a compiler built in The emitted instruc tions will be inlined at the point of external_memory_write use The inclusion of the sysreg h include file is mandatory when using external_memory_write Error Conditions The external_memory_write function does not return raise or set any error conditions Example d Finclude lt sysreg h gt section external_memory_section static int GlobalTable 256 int main int page value_to_write 0 asm 40 PAGE GlobalTable e page 3 56 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs C C Run Time Library external_memory_write page amp GlobalTable 1 value_to_write See Also external_memory_read disable_interrupts enable_interrupts io_space_read i0_space_write sysreg_read sysreg_write VisualDSP 3 5 C C Compiler and Library Manual 3 57 for ADSP 219x DSPs C Run Time Library Reference fabs float absolute value Synopsis d Finclude lt math h gt double fabs double f float fabsf float f Description The fabs function returns the absolute value of the argument Error Conditions The fabs function does not return an error condition Example d Finclude lt math h gt double y fabs 2 3 y 2 3 fabs 2 3 gt y 2 3 lt l
450. y delete operation The value is ignored A single operator and operator function can be used to overload both prefix and postfix operations The base class name may be omitted in a base class initializer if there is only one immediate base class Assignment to this in constructors and destructors is allowed This is allowed only if anachronisms are enabled and the assignment to this configuration parameter is enabled A bound function pointer a pointer to a member function for a given object can be cast to a pointer to a function 1 52 VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs Compiler e A nested class name may be used as a un nested class name pro vided no other class of that name has been declared The anachronism is not applied to template classes e A reference to anon const type may be initialized from a value of a different type A temporary is created it is initialized from the converted initial value and the reference is set to the temporary e A reference to a non const class type may be initialized from an rvalue of the class type or a derived class thereof No additional temporary is used e A function with old style parameter declarations is allowed and may participate in function overloading as though it were proto typed Default argument promotion is not applied to parameter types of such functions when the check for compatibility is done so that the following sta
451. y Guide Table 4 5 Matrix Functions Contd Description Prototype Real void matsmlt const double a double b int n int m Matrix Scalar double c Multiplication void matsmltf const float a float b int n int m float c void matsmlt_frl6 const fractl6 a fractl6 b int n int m fractl6 c Real void matmadd const double a const double b int n int m Matrix Matrix double c Addition void matmaddf const float a const float b int n int m float c void matmadd_frl6 const fractl6 a const fractl6 b int n int m fractl6 c Real void matmsub const double a const double b int n int m Matrix Matrix double c Subtraction void matmsubf const float a const float b int n int m Float c void matmsub_fr16 const fractl6 a const fractl6 b int n int m fractl6 c Real void matmmlt const double a int n int k const double b Matrix Matrix int m double c Multiplication void matmmitf const float a int n int k const float b int m float c void matmmlt_frl6 const fractl6 a int n int k const fractl6 b int m fractl6 c Complex void cmatsadd const complex_double a complex_double b Matrix Scalar int n int m complex_double c Addition void cmatsaddf const complex_float a complex_float b int n int m complex_float c void cmatsadd_frl6 const complex_fractl6 a complex_fractl6 b int n in
452. y Manual for ADSP 219x DSPs ities Acuna E A A anda A T 4 96 P E aE R A A OTE 4 98 NS E E E E E AEE E E 4 100 a E E E E T E E NT 4 101 PR eTa EAE EAA E EE AE E A a E A E 4 102 a aviv i One ane anor se eta errno three pat er sueriftier erent eee seer er 4 104 PISCE sania ear 4 106 GEE adenine teenie eee ane 4 108 ORS a ea tenca AA E ea coun nee 4 109 COMPILER LEGACY SUPPORT O RR E E AEE AE A O E A T A 1 C C Compiler and Ron Time Library smuvissiasismensrinieiisnues A 3 Segment Placement Support Keyword Changed to Section A 3 ion Cee nications A 3 Support for G21 Based Options And Extensions 1 0 0 A 4 ee A E E A 4 Compiler Switch Modifications sensensrssenirrsnssnucorsierimis A 5 New and Obsolete Warnings pcccnininnriroriikoiismireintan A 8 Run Time Mod l srsnscoroieninoioiorapeai Doa A 9 ort Ron Time LIDIA sostenia A 9 INDEX VisualDSP 3 5 C C Compiler and Library Manual xxvii for ADSP 219x DSPs xxviii VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs PREFACE Thank you for purchasing Analog Devices development software for digi tal signal processors DSPs Purpose The VisualDSP 3 5 C C Compiler and Library Manual for ADSP 219x DSPs contains information about the C C compiler and run time library program for ADSP 219x DSPs It includes syntax for command lines switches and language extensions It leads you through the process of using library routines and writing mixed C C
Download Pdf Manuals
Related Search
Related Contents
Avis d`émission - Côte d`Albâtre Elegance MW82-150/8 Dolby, GB Sanyo UR18650E User's Manual ASUS (ME170C) User's Manual L`ACTU DES TRAVAUX GARE CRÉTEIL L`ÉCHAT Sellador elastico Condicionado User Manual - Datamax Port Designs MONZA Service Instruction Number SIN2348 Revision K Copyright © All rights reserved.
Failed to retrieve file