Cirrus Logic CS470xx User manual

Type
User manual
Copyright 2013 Cirrus Logic AUG 2013
DS811UM15
Programming Tool for the Cirrus
Logic 32-Bit Audio DSPs
http://www.cirrus.com
Cirrus Logic C-Compiler
Users Manual
ii DS811UM13
Cirrus Logic C-Compiler User’s Manual
Contacting Cirrus Logic Support
For all product questions and inquiries contact a Cirrus Logic Sales Representative.
To find one near you, go to
http://www.cirrus.com
IMPORTANT NOTICE
Cirrus Logic, Inc. and its subsidiaries (“Cirrus”) believe that the information contained in this document is accurate and reliable. However, the information is subject
to change without notice and is provided “AS IS” without warranty of any kind (express or implied). Customers are advised to obtain the latest version of relevant
information to verify, before placing orders, that information being relied on is current and complete. All products are sold subject to the terms and conditions of sale
supplied at the time of order acknowledgment, including those pertaining warranty, indemnification, and limitation of liability. No responsibility is assumed by Cirrus
for the use of this information, including use of this information as the basis for manufacture or sale of any items, or for infringement of patents or other rights of
third parties. This document is the property of Cirrus and by furnishing this information, Cirrus grants no license, express or implied under any patents, mask work
rights, copyrights, trademarks, trade secrets or other intellectual property rights. Cirrus owns the copyrights associated with the information contained herein and
gives consent for copies to be made of the information only for use within your organization with respect to Cirrus integrated circuits or other products of Cirrus.
This consent does not extend to other copying such as copying for general distribution, advertising or promotional purposes, or for creating any work for resale.
CERTAIN APPLICATIONS USING SEMICONDUCTOR PRODUCTS MAY INVOLVE POTENTIAL RISKS OF DEATH, PERSONAL INJURY, OR SEVERE PROP-
ERTY OR ENVIRONMENTAL DAMAGE (“CRITICAL APPLICATIONS”). CIRRUS PRODUCTS ARE NOT DESIGNED, AUTHORIZED OR WARRANTED FOR
USE IN PRODUCTS SURGICALLY IMPLANTED INTO THE BODY, AUTOMOTIVE SAFETY OR SECURITY DEVICES, LIFE SUPPORT PRODUCTS OR OTHER
CRITICAL APPLICATIONS. INCLUSION OF CIRRUS PRODUCTS IN SUCH APPLICATIONS IS UNDERSTOOD TO BE FULLY AT THE CUSTOMER'S RISK
AND CIRRUS DISCLAIMS AND MAKES NO WARRANTY, EXPRESS, STATUTORY OR IMPLIED, INCLUDING THE IMPLIED WARRANTIES OF MERCHANT-
ABILITY AND FITNESS FOR PARTICULAR PURPOSE, WITH REGARD TO ANY CIRRUS PRODUCT THAT IS USED IN SUCH A MANNER. IF THE CUSTOM-
ER OR CUSTOMER'S CUSTOMER USES OR PERMITS THE USE OF CIRRUS PRODUCTS IN CRITICAL APPLICATIONS, CUSTOMER AGREES, BY SUCH
USE, TO FULLY INDEMNIFY CIRRUS, ITS OFFICERS, DIRECTORS, EMPLOYEES, DISTRIBUTORS AND OTHER AGENTS FROM ANY AND ALL LIABILITY,
INCLUDING ATTORNEYS' FEES AND COSTS, THAT MAY RESULT FROM OR ARISE IN CONNECTION WITH THESE USES.
Cirrus Logic, Cirrus, and the Cirrus Logic logo designs are trademarks of Cirrus Logic, Inc. All other brand and product names in this document may be trademarks
or service marks of their respective owners.
DS811UM13 iii
Cirrus Logic C-Compiler User’s Manual
Contents
Contents. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-iii
Appendix Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-iv
Appendix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1-v
Chapter 1. Introduction.........................................................................................1-1
1.1 Welcome to the Cirrus C-Compiler (CCC) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1-1
1.2 Standard Conformance of CCC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1-2
Chapter 2. CCC Command Line Options.............................................................2-1
2.1 Description of CCC Command Line Options. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-1
2.1.1 Command Line Format....................................................................................................2-1
2.1.1.1 Details of Command Line Options.................................................................2-2
2.1.1.2 System Environment Variables Used by the Compiler..................................2-4
2.1.1.3 Additional Information and Examples of Using Command Line Options.......2-4
Chapter 3. Data Types...........................................................................................3-1
3.1 Overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-1
3.2 Integer Data Types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-1
3.3 Fixed-point Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-2
3.3.1 Fixed-point Constants......................................................................................................3-3
3.3.2 Fixed-point Type Conversions.........................................................................................3-4
3.3.3 Fixed-point Type Expressions.........................................................................................3-7
3.3.4 Costly Fixed-point Expressions.......................................................................................3-9
3.4 Floating Point Data Types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-10
Chapter 4. Memory Zones.....................................................................................4-1
4.1 Overview of Cirrus DSP Architecture Memory Zones . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-1
4.2 Memory-zone Qualifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-1
4.3 Declaration of a Global Variable. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-2
4.4 Declaration of a Local Variable. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-5
4.5 Memory-zone Typecast Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-7
Chapter 5. Use of Circular Buffers.......................................................................5-1
5.1 Overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5-1
5.2 Circular Buffer Modulo Addressing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5-1
Chapter 6. Function Attributes.............................................................................6-1
6.1 Function Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-1
Chapter 7. Generated Code..................................................................................7-1
7.1 Overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-1
7.2 CCC Calling Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-1
7.2.1 Static Stack Frame Calling Convention...........................................................................7-7
7.3 Hardware Register Preservation During Function Calls . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-7
7.3.1 The CCC Translates C Functions into Assembly Functions...........................................7-8
7.3.2 User-defined C-callable Assembly Functions..................................................................7-8
7.3.3 Register Clobber Information Pragma.............................................................................7-9
iv DS811UM13
Cirrus Logic C-Compiler User’s Manual
Chapter 8. Assembler Instructions with C-expression Operands....................8-1
8.1 ASM Statement Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-1
8.2 Implementation of Extended ASM Support. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-2
8.2.1 ASM String Template ......................................................................................................8-2
8.2.2 Output Operand List Followed by Input Operand List .....................................................8-3
8.2.2.1 C Expressions................................................................................................8-3
8.2.2.2 Operand-constraint Strings............................................................................8-3
8.2.3 Clobber List .....................................................................................................................8-5
Chapter 9. Optimizing C Code Targeted for Cirrus Logic DSPs .......................9-1
9.1 Overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-1
9.2 C-Language Coding Guidelines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-1
9.2.1 General Coding Guidelines .............................................................................................9-1
9.2.2 CCC and Cirrus Logic DSP-specific Optimizations.........................................................9-3
9.2.2.1 Create Loops That Can Be Implemented as Hardware Loops......................9-3
9.2.2.2 Change the Method of Accessing Arrays ......................................................9-6
9.2.2.3 Increase the Efficiency of Comparison Code.................................................9-9
9.2.2.4 Copy Whole Structures That Are Contiguous In Memory............................9-10
9.2.2.5 Avoid Using Large Switch Statements or If-else Constructions...................9-11
9.3 Optimizing an Existing Application to Run on Cirrus DSPs . . . . . . . . . . . . . . . . . . . . . . . .9-12
9.3.1 Phase 1: Developer Submits Initial C Code Application................................................9-13
9.3.2 Phase 2: Make General Code Optimizations ................................................................9-13
9.3.3 Phase 3: Convert Data Types to Data Types Supported
by the Cirrus Logic DSP Architecture.....................................................................................9-14
9.3.3.1 Convert C-Code Floating-point to Fixed-point Arithmetic............................9-14
9.3.4 Phase 4: Apply Target and Assembly Compiler-specific Modifications to the Code .....9-14
9.3.5 Phase 5: Create and Test Downloadable Code............................................................9-15
Chapter 10. Known Issues in CCC.....................................................................10-1
10.1 Sequence Point Before Function Call . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10-1
10.2 Externalized Inline Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10-1
10.3 Problems with More Flexible Array Initialization from C99 . . . . . . . . . . . . . . . . . . . . . . . .10-1
10.4 Overflow when Using Abs Function for Fixed Point Types. . . . . . . . . . . . . . . . . . . . . . . .10-2
10.5 Saturated Fixed Point Type Unary Negation Does Not Saturate. . . . . . . . . . . . . . . . . . . .10-2
10.6 Multiplication of Unsigned Saturated Short Accum Type
with Signed Integer Produces Wrong Code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10-2
10.6 Revision History. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10-3
Appendix A. Support of Standard Libraries....................................................... A-1
Tables
Table 2-1. Command Line Options ...............................................................................................................2-2
Table 2-2. Internal Functions.........................................................................................................................2-9
Table 3-1. Integer Data Types.......................................................................................................................3-1
Table 3-2. Fixed-point Data Types................................................................................................................3-2
Table 3-3. Fixed-point Constants ..................................................................................................................3-3
Table 3-4. Available Functions for Bitwise Conversion.................................................................................3-4
DS811UM13 v
Cirrus Logic C-Compiler User’s Manual
Table 3-5. Conversions for Saturation and Rounding ...................................................................................3-5
Table 3-6. Arithmetic Data Types..................................................................................................................3-8
Table 4-1. Memory Zones and their Qualifiers..............................................................................................4-1
Table 5-1. Supported Modulo Addressing Values.........................................................................................5-1
Table 6-1. List of Function Attributes.............................................................................................................6-1
Table 9-1. Rules for Translating “For Loops” into Hardware Loops............................................................10-3
Table 9-2. Conditions for Translating Square Bracket Indexing into Pointer Addressing............................10-7
Appendix A-1. Support of Standard Libraries............................................................................................... A-1
DS811UM15 1-1
Introduction
Cirrus Logic C-Compiler User’s Manual
1
Chapter 1
1Introduction
1.1 Welcome to the Cirrus C-Compiler (CCC)
The Cirrus
®
C Compiler (CCC) compiles C source files to produce assembler code that is
able to run on the Cirrus DSP platforms such as the CS4953xx, CS4970x4, CS485xx,
CS47xxx, and the CS498xx multi-core DSPs.
The CCC is part of the Cirrus Logic Integrated Development Environment (CLIDE) that is
available to Cirrus Logic customers to enable them to develop their own custom audio
algorithms to run on Cirrus Logic DSPs. CLIDE receives input from DSP Composer
and
provides output to DSP Composer. The Cirrus Device Manager (CDM) must be running to
use the CLIDE tool set. When the SDK for the Cirrus DSP used in the customer’s design is
launched, the CDM should also be automatically launched.
The CLIDE User’s Manual describes the CLIDE graphical user’s interface (GUI), which
allows the user to access the following applications from CLIDE:
Cirrus Logic C-Compiler—described in this manual
CASM—Cirrus Logic Cross-assembler (CASM) described in the 32-bit DSP Assembly
Programmer’s Guide
CLIDE debuggerdescribed in the CLIDE User’s Manual, debugs both Assembly and C
language source files, and replaces the Hydra debugger
Primitive Elements Wizard—described in the CLIDE User’s Manual and is an XML file
Wizard used to create custom primitives that are debugged within CLIDE
Simulatordescribed in the CLIDE User’s Manual
Source editordescribed in the CLIDE User’s Manual
1-2 DS811UM15
Introduction
Cirrus Logic C-Compiler User’s Manual
1
1.2 Standard Conformance of CCC
CCC supports the C99 standard with Embedded C extension for fixed point types and
memory zone qualifier, but without the following features:
Floating point types (except for floating point constants in expressions that can be
evaluated to a constant value in compile time) and related standard libraries
File and console input/output and related standard libraries
Variable number of function arguments and related standard library
Several other standard libraries: time.h, signal.h, locale.h, and setjmp.h
Wchar type
Restricted pointers
Variable length arrays
The long long int type and library functions (the type key word is supported, but it's size
is not 64 bits)
Universal character names (\u and \U)
Mixed declarations and code
More flexible array initialization (for example, "int x[5] = {[2] = 2, [4] = 3};")
Declaration in for loop (for example, "for (int x = 0...")
Multiple appearance of inline attribute in function declaration
Static array size in function parameter (for example, "int foo(int x[static 5])")
Saturation on overflow for fixed point abs functions declared in stdfix.h (see
Section 10.4)
Note: Bit fields are supported with the following restrictions:
No single bit field can be longer than 32 bits.
All bit fields are treated as unsigned integers. A “signed” attribute is ignored.
DS811UM15 2-1
CCC Command Line Options
Cirrus Logic C-Compiler User’s Manual
2
Chapter 2
2CCC Command Line Options
2.1 Description of CCC Command Line Options
This chapter describes the options for using the command line in the CCC.
2.1.1 Command Line Format
The format of the compiler command line is as follows:
ccc2 -<options> <C source file>
When calling the CCC compiler without arguments, the command line options Help message
is displayed.
2-2 DS811UM15
CCC Command Line Options
Cirrus Logic C-Compiler User’s Manual
2
2.1.1.1 Details of Command Line Options
The <options> field contains zero or more compiler control directives. Each directive starts
with the character “-” and ends with a space. Table 2-1 contains the command line options
that are available.
Table 2-1. Command Line Options
Command Line Option Description
-c Stop after assembling. Do not link. Compiler produces the assembler (.s) and the object (.o) file.
-cdl
Create file dependency list. Important for incremental build. The list will be created in a file with
extension .cdf.
-Cl
Emits corresponding C line for every instruction block. This command option is only valid if the -g
option is used.
-D<symbol> Define a symbol.
-edi-lines Emit corresponding C line numbers as comments in the .s file.
-emit-hints
Emit useful information about generated code, such as: advises how to change the C code in order to
improve the generated code, information about stack usage for passing arguments, information about
points in code where SRS is used, et cetera.
-esc Emit .s file in the same folder where .c file is located, regardless of -o switch.
-falias-analysis[=N]
Use alias analysis information. N specifies how deep in the function call graph the analysis should go.
Increasing the limit makes analysis more precise but also increases compilation time. Default value is
1. Value -1 means "as deep as possible".
-fcompact Turn on compactor optimization, which utilizes instruction-level parallelism.
-fconst-pool[=M]
Load constants from memory. M can be X, Y, or P, to select which memory zone the pool is going to
be. Default is P.
-fcse Turn on common subexpression elimination optimization.
-femit-asm-struct Emits an assembly .struct definition in the .s file for the struct types used in the C code.
-fif Try several compilation strategies and choose the best result. Compilation lasts longer.
-finline-functions Automatically find suitable functions to inline. Available only if -wpo is enabled.
-fno-inline Do not inline functions. That is, ignore the inline function attribute.
-fnfs
Do not use stack. Statically allocate function memory instead. Valid only if there is no recursion in the
program. Refer to Section 7.2.1 for additional information regarding static stack frame calling
conventions.
-fno0init
Do not initialize to 0 static storage duration objects that are not explicitly initialized. Useful for reducing
.uld size.
-fno-hw-loop-detection Do not create hw loops.
-fprc Propagate constants and evaluate constant expressions.
-funsafe-loop-optimizations
Assume number of loop iterations is never 0. If number of loop iterations is not constant, but can be
calculated each time before the loop is entered, hardware loop can be used only if the number of
iterations is never 0.
DS811UM15 2-3
CCC Command Line Options
Cirrus Logic C-Compiler User’s Manual
2
-fwrapv
Specify signed integer overflow behavior as wrap-around, which makes code slightly larger.
Otherwise, the overflow behavior is undefined.
-g
Write DWARF2 debug information into the object file and create debuggable code. (See Chapter 6 for
more information on debug attributes.)
-h Print command line help screen.
-ida
Ignore function debug_on and debug_off attributes. (See Chapter 6 for more information on debug
attributes.)
-ira
Use interprocedural register allocation. Allocates only registers clobbered by a called function for each
function call. Default setting assumes all clobberable registers are clobbered.
-I<include_path> Pass the include path to the compiler.
-o<output file name>
Specify the name of the output files (file extension, if given, is ignored). Default output file name is the
same as the input file name, or the last input file name, if multiple input files are provided.
-ruf Report error for undeclared function calls.
-s Silent option. Compile without providing any progress information.
-S Stop before calling assembler and linker. Compiler output is just the assembler (.s) file.
-v Display the version of the compiler.
-w Suppress warnings
-wpo
Whole program optimization. Turn on when you pass all C source files of your program at once. Other
switches become available.
Table 2-1. Command Line Options (Continued)
Command Line Option Description
2-4 DS811UM15
CCC Command Line Options
Cirrus Logic C-Compiler User’s Manual
2
2.1.1.2 System Environment Variables Used by the Compiler
The compiler makes use of the following system environment variables:
The CCC_INCLUDE variable specifies the default include path.
The CCC_LIB variable specifies the default runtime library path.
The C-compiler’s compile process is also affected by the CASMSPEC and CLINKSPEC
environment variables. (See the 32-bit DSP Assembly Programmer’s Guide for more
information about the CASMSPEC and CLINKSPEC environment variables.)
When called from command line, CCC calls casm and clink like this:
casm.exe FileName.s -oOutputFileName.O --debug --casmspec -s -c
clink.exe OutputFileName.O LibPath\crt0.o -lLibPath -oOutputFileName.img --
clinkspec
where LibPath is geathered from CCC_LIB environment variable.
The whole build process is configurable from CLIDE on Project Properties page.
2.1.1.3 Additional Information and Examples of Using Command Line Options
2.1.1.3.1 -fno0int
Example 1 With -fno0int
int big_buffer[10000];
int big_initialized_buffer[10000] = {0};
Example 2 Without -fno0init
_big_buffer:
.bsc (0x2710), 0x00000000
_big_initialized_buffer:
.bsc (0x2710), 0x00000000
With -fno0init:
_big_buffer:
.bss (0x2710)
_big_initialized_buffer:
.bsc (0x2710), 0x00000000
DS811UM15 2-5
CCC Command Line Options
Cirrus Logic C-Compiler User’s Manual
2
2.1.1.3.2 -fwrapv
Example 3 With/Without -fwrapv
With -fwrapv:
int is_negative(int x)
{
int ret;
if (x < 0)
{
ret = 1;
}
else
{
ret = 0;
}
return ret;
}
Without -fwrapv:
_is_negative:
a0 & a0
if (a >= 0) jmp (else_0)
uhalfword(a0) = (0x1)
jmp (endif_0)
else_0:
a0 = 0
endif_0:
ret
With -fwrapv:
_is_negative:
a0 = a0h #!!!
a0 & a0
if (a >= 0) jmp (else_0)
uhalfword(a0) = (0x1)
jmp (endif_0)
else_0:
a0 = 0
endif_0:
ret
2-6 DS811UM15
CCC Command Line Options
Cirrus Logic C-Compiler User’s Manual
2
Example 4 Function is_negative is from Example 3
int t = 0xFFFFFFFE;
void main()
{
int y = is_negative(t + 2); //overflow occurs
...
}
Without -fwrapv, y will be 0. With -fwrapv, y will be 1.
Example 5
int shift_right_for_2(int x)
{
return x >> 2;
}
Without -fwrapv:
_shift_right_for_2:
a0 = a0 >> 1
a0 = a0 >> 1
a0l = (0x0)
ret
With -fwrapv:
_shift_right_for_2:
a0 = a0h#!!!
a0 = a0 >> 1
a0 = a0 >> 1
a0l = (0x0)
ret
Example 6 shift_right_for_2 is from Example 5
int t = 0xFFFFFFFF;
void main()
{
t <<= 2; //overflow occurs
int y = shift_right_for_2(t);
...
}
Without -fwrapv, y will be 0xFFFFFFFF. With -fwrapv, y will be 0x3FFFFFFF.
DS811UM15 2-7
CCC Command Line Options
Cirrus Logic C-Compiler User’s Manual
2
2.1.1.3.3 -fconst-pool
Example 7
int foo(int x)
{
return x + 0x1234567;
}
Without -fconst-pool:
.code_ovly
_foo:
a1 = (0x123)
lo16(a1) = (0x4567)
a0 = a0 + a1
ret
With -fconst-pool=X:
.xdata_ovly
__extractedConst_0_1
.dw (0x1234567)
.code_ovly
_foo:
a1 = pmem[__extractedConst_0_1 + 0]
a0 = a0 + a1
ret
2-8 DS811UM15
CCC Command Line Options
Cirrus Logic C-Compiler User’s Manual
2
Example 8
int bar(int x)
{
return x - 0x1234567;
}
int foo(int x)
{
return x + 0x1234567;
}
Without -fconst-pool:
.code_ovly
_bar:
a1 = (0x123)
lo16(a1) = (0x4567)
a0 = a0 - a1
ret
_foo:
a1 = (0x123)
lo16(a1) = (0x4567)
a0 = a0 + a1
ret
With -fconst-pool:
.code_ovly
__extractedConst_0_2
.dw (0x1234567)
.code_ovly
_bar:
a1 = pmem[__extractedConst_0_2 + 0]
a0 = a0 - a1
ret
_foo:
a1 = pmem[__extractedConst_0_2 + 0]
a0 = a0 + a1
ret
DS811UM15 2-9
CCC Command Line Options
Cirrus Logic C-Compiler User’s Manual
2
2.1.1.3.4 -emit-hints
There are currently four groups of info messages that the CCC reports when the -emit-hints
switch is turned on:
1. Information about stack usage for function arguments.
Every function call where stack is being used for the passing of arguments or a return value is
gong to be reported. See Section 9.2.1 for additional information.
2. Information about translation of loops into hardware loops.
If the compiler is not able to translate a certain loop in the source code into a hardware loop,
there will be message containing the reason it was unable to translate. If you want to make
the compiler translate that loop into a hardware loop, try to satisfy the condition stated in the
message. See Section 9.2.2.1 for additional information.
3. Information about usage of compiler internal runtime functions in the generated code.
Cirrus DSP does not have direct hardware support for all C functionalities, so some of them
are implemented by calling internal runtime functions. The code that causes the usage of
those functions can usually be changed so that it does not require those functions. See
Section 3.3.4 for additional information.
Section 3.3 explains that the following three types are best used in C programs for the Cirrus
DSP: fract, long fract, and long accum. If you use just those fixed-point types, then only one
of the internal functions in the following table can be present in the compiled code. All other
internal functions are related to the usage of fixed-point types other than fract, long accum,
and long fract.
Table 2-2. Internal Functions
int_to_fract
int_to_laccum
int_to_lfract
uint_to_fract
uint_to_laccum
uint_to_lfract
An integer (signed or unsigned) variable is being converted to one of the fixed-point types. Very often, this
conversion is a result of a coding mistake. It is useful only in a small number of cases. If bitwise conversion was
intended, then it can be performed by intrinsic functions in the stdfix.h header. See Section 3.3.2 for more
information.
laccum_to_int
A fixed-point variable is being converted to an integer type. Very often, this conversion is a result of a coding
mistake. It is useful only in a small number of cases. If bitwise conversion was intended then it can be
performed by intrinsic functions in the stdfix.h header. See Section 3.3.2 for more information.
div_sat_laccum
A fixed-point division is being performed. The function does full precision division. If you want faster or less
precise division, call the appropriate function. Several different division functions are given in dsplib.h.
div
udiv
Integer division (signed or unsigned) is being performed. The function does full precision division. If you want
faster or less precise division, write and call the appropriate function.
lshift
rshift
ulshift
urshift
The shifting of integer variables (signed or unsigned) for a variable number (that is, not constant) of places is
being performed. Listed functions shift values one bit at a time for a desired number of times, but better results
(speed-wise) can be obtained by multiplying the value with a constant picked from the look-up table. In the next
version, CCC compiler will be able to do this automatically, but, at the moment, the only way to do it is manually
in the source code.
2-10 DS811UM15
CCC Command Line Options
Cirrus Logic C-Compiler User’s Manual
2
4. Information about the use of an SRS (Shifter/Rounder/Saturator) unit.
This group of messages is useful if you want to control the SRS unit from C code, as seen in
Section 3.3.2. That way, you can be sure that changes of SRS behavior which you introduce
are going to affect only the intended lines of code. In the SRS for shifting example in
Section 3.3.2, from line 4 to line 10, the behavior of SRS is altered. An info message would
be emitted for line 7 (“*p = (long accum)(*p);”), but not for any other line in between the 4th
and 10th line. That way, you can be sure that only line 7 would be affected by SRS changes,
which was the intention in the example.
lshift_laccum
rshift_laccum
The shifting of fixed-point variable for a variable number (that is, not constant) of places is being performed. The
situation is similar to integer shifting functions, but it has to be noted that some fixed-point types are more than
32 bits wide, and their shifting using the look-up table is not as simple.
mul_sat_laccum
This function is called when the multiplication of two fixed-point types is being performed, where at least one of
the types is wider than 32 bits. Check if that was the intention or just a coding error and whether that precise
multiplication is necessary. If it is necessary, it is important to note that this function performs full precision
multiplication of two long _Accum types, but the same function is called for all other cases. Therefore, if lower
precision types are multiplied (for example, _Fract * long _Accum) then this function introduces unnecessary
overhead. For the next version of the CCC, it is planned to have separate functions for every possible
multiplication case, but, at the moment, the only way to get the best efficiency in the described cases is to
manually write assembly function for the desired multiplication (or embed the assembly code in asm
statement).
mod
umod
This performs a division reminder operation on integers (signed or unsigned). There is no hardware support for
this operation, so try to avoid it if code speed is important. In cases where the right operand is a power of two,
this operation can be performed using bit masking. In other cases, avoiding division reminder operation is not
trivial.
Table 2-2. Internal Functions
DS811UM15 3-1
Data Types
Cirrus Logic C-Compiler User’s Manual
3
Chapter 3
3Data Types
3.1 Overview
CCC fully supports all standard C data types, but support for the “long long” integer type and
floating-point types is currently restricted. CCC extends the standard C data type set with
fixed-point data types as described in ISO/IEC TR 18037.
The size of the long long type is 32 bits. A future version of CCC will implement long long as
64 bits.
Since Cirrus DSPs that CCC targets are fixed-point DSPs, floating-point arithmetic can only
be supported through emulation. Because of that, support of floating-point data types in CCC
is restricted to usage in constant expressions. In other words, floating-point arithmetic is
supported if it can be performed in compile time.
For more information on the C programming language standard, see ISO/IEC JTC1 SC22
WG14 N102.
For extensions to the C programming language standard for embedded processors, see
“Programming languages, their environments and system software interfaces — Extensions
for the programming language C to support embedded processors.” in ISO/IEC TR 18037.
3.2 Integer Data Types
Sizes of integer data types are given in Table 3-1:
The size of the pointers are 16 bits. Enums are implemented as a signed integer. The char
type without an explicit sign qualifier is treated as unsigned.
Table 3-1. Integer Data Types
Type Size in Bits
char 32
short 32
int 32
long 32
long long 32
3-2 DS811UM15
Data Types
Cirrus Logic C-Compiler User’s Manual
3
3.3 Fixed-point Data Types
The compiler complies with the fixed-point types standard declared in the Embedded C
Extension (ISO/IEC JTC1 SC22 WG14 N1021). In the document, two groups of fixed-point
data types are added to the C language: the fract types and the accum types. The data value
of a fract type (both signed and unsigned) has no integral part, hence values of a fract type
are in range [-1.0, +1.0]. Accum types in CCC are defined to have 8 integral bits, and the
values of accum type are in range [-256.0, +256]. Unsigned accum types have 9 integral bits,
and its values are in range [0.0, 512.0]. A type’s precision depends on the number of
fractional bits it has. Table 3-2 describes the available fixed-point types along with their size
and format in CCC.
The formal names of the new keywords start with an underscore followed by an uppercase
letter to avoid possible name clashes in existing programs. However, in the header stdfix.h,
these formal names are used to define the natural spellings as aliases. So, instead of
“_Fract” and “_Accum”, the user can use “fract” and “accum”.
In the Cirrus DSP architecture, data registers are 32 bits long, a data register pair is 64 bits
long, and accumulators are 72 bits long; all of which are signed. Long accum, fract, and long
fract data types are best used in C programs for the Cirrus DSP processor. Other data types
are supported, but operations with those types usually require more instructions and often
involve calls to runtime functions (see Section 3.3.4).
Table 3-2. Fixed-point Data Types
Type Syntax Size in Bits Number Format
signed
short
_Fract
32 s.31
—32s.31
long 32 s.31
unsigned
short 32 0.31
—320.31
long 64 0.63
signed
short
_Accum
40 s8.31
—40s8.31
long 72 s8.63
unsigned
short 40 9.31
—409.31
long 72 9.63
DS811UM15 3-3
Data Types
Cirrus Logic C-Compiler User’s Manual
3
3.3.1 Fixed-point Constants
In C language, the type of a constant is determined by the constant suffix. For example, suffix
“f” defines float type constant, therefore constant “0.5f” is a float type constant, while “0.5”
(without suffix) is a double type constant. Suffixes for fixed-point constants are shown in
Table 3-3.
Note: The suffix is not case sensitive; the table only gives lowercase letters.
A fixed-point constant evaluates to the closest representable value that is in the range of the
indicated type. Exceptions are constants with the value of the type's upper bound range
(such as 1.0r, 256.0lk, 512.0ulk, et cetera). These constants denote the maximal value for the
type because the exact value is not representable (value ranges are left-closed and right-
open intervals). A _Fract constant can also be expressed in hexadecimal format. This
hexadecimal number is interpreted as a bit representation of the fixed-point value rather than
the integer value. For this approach to work, the suffix of the fixed-point constant must be 'r'.
Note: The C standard specifies that constants without a suffix are considered to be an integer
type if a decimal point is not present or double type if a decimal point is present. All other
types are defined by a suffix. Fixed-point constants must always have a suffix. Otherwise,
they are not fixed-point constants. For more information about usage of floating-point (both
float and double) constants, see Section 3.4.
Here are examples of some fixed point constants:
0.8932r// _Fract constant
0.8932LR// long _Fract constant
12.6574k// _Accum constant
-150.778892LK// long _Accum constant
Table 3-3. Fixed-point Constants
Type Syntax Suffix
signed
short
_Fract
hr
—r
long lr
unsigned
short uhr
—ur
long ulr
signed
short
_Assum
hk
—k
long lk
unsigned
short uhk
—uk
long ulk
  • Page 1 1
  • Page 2 2
  • Page 3 3
  • Page 4 4
  • Page 5 5
  • Page 6 6
  • Page 7 7
  • Page 8 8
  • Page 9 9
  • Page 10 10
  • Page 11 11
  • Page 12 12
  • Page 13 13
  • Page 14 14
  • Page 15 15
  • Page 16 16
  • Page 17 17
  • Page 18 18
  • Page 19 19
  • Page 20 20
  • Page 21 21
  • Page 22 22
  • Page 23 23
  • Page 24 24
  • Page 25 25
  • Page 26 26
  • Page 27 27
  • Page 28 28
  • Page 29 29
  • Page 30 30
  • Page 31 31
  • Page 32 32
  • Page 33 33
  • Page 34 34
  • Page 35 35
  • Page 36 36
  • Page 37 37
  • Page 38 38
  • Page 39 39
  • Page 40 40
  • Page 41 41
  • Page 42 42
  • Page 43 43
  • Page 44 44
  • Page 45 45
  • Page 46 46
  • Page 47 47
  • Page 48 48
  • Page 49 49
  • Page 50 50
  • Page 51 51
  • Page 52 52
  • Page 53 53
  • Page 54 54
  • Page 55 55
  • Page 56 56
  • Page 57 57
  • Page 58 58
  • Page 59 59
  • Page 60 60
  • Page 61 61
  • Page 62 62
  • Page 63 63
  • Page 64 64
  • Page 65 65
  • Page 66 66
  • Page 67 67
  • Page 68 68
  • Page 69 69
  • Page 70 70
  • Page 71 71
  • Page 72 72
  • Page 73 73
  • Page 74 74
  • Page 75 75
  • Page 76 76

Cirrus Logic CS470xx User manual

Type
User manual

Ask a question and I''ll find the answer in the document

Finding information in a document is now easier with AI