0% found this document useful (0 votes)
37 views

Chapter3 C

This document provides an overview of the software development tools used for the TMS320C6000 digital signal processor (DSP), including a C/C++ compiler, assembly optimizer, assembler, linker, and utilities. It describes the features and usage of the optimizing C/C++ compiler, such as how it fully conforms to ANSI C standards, supports C++ with some exceptions, and includes a complete run-time library. It also covers invoking and using the compiler, optimizing C code, linking C/C++ code, interfacing C/C++ with assembly code, and using the stand-alone simulator.

Uploaded by

sperate
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

Chapter3 C

This document provides an overview of the software development tools used for the TMS320C6000 digital signal processor (DSP), including a C/C++ compiler, assembly optimizer, assembler, linker, and utilities. It describes the features and usage of the optimizing C/C++ compiler, such as how it fully conforms to ANSI C standards, supports C++ with some exceptions, and includes a complete run-time library. It also covers invoking and using the compiler, optimizing C code, linking C/C++ code, interfacing C/C++ with assembly code, and using the stand-alone simulator.

Uploaded by

sperate
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

Chapter III

C / C++
Learning Objectives

‹ The TMS320C6000 is supported by a set of


software development tools, which includes an
optimizing C/C++ compiler, an assembly optimizer,
an assembler, a linker, and assorted utilities.

‹ This chapter provides an overview of these tools and


introduces the features of the optimizing C/C++
compiler.

Chapter 2, Slide 2 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005


Introductory information

Chapter 2, Slide 3 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005


Introductory information

‹ ANSI-standard C : C/C++ compiler fully conforms to


the ANSI C standard as defined
‹ C++ : The C6000 C/C++ compiler supports C++ as
defined by the ISO/IEC 14882–1998 standard with
certain exceptions.
‹ ANSI-standard run-time support : The compiler tools
come with a complete run-time library. All library
functions conform to the ANSI C/C++ library standard.
The library includes functions for standard input
and output, string manipulation, dynamic memory
allocation, data conversion, timekeeping, trigonometry,
and exponential and hyperbolic functions.

Chapter 2, Slide 4 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005


C/C++ compiler
‹ The C/C++ compiler accepts C/C++ source code
and produces C6000 assembly language source
code. A shell program, an optimizer, and an interlist
utility are parts of the compiler:

‹ The shell program enables you to compile,


assemble, and link source modules in one step. If
any input file has a ‘.sa’ extension, the shell
program invokes the assembly optimizer.
‹ The optimizer modifies code to improve the
efficiency of C programs.
‹ The ASM code generator utility interweaves
C/C++ source statements with assembly language
output.

Chapter 2, Slide 5 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005


The Shell Program Overview

Chapter 2, Slide 6 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005


Invoking the C/C++ compiler

cl6x [ options] filenames [–z [ link_options] [ object files]]

cl6x Command that runs the compiler and the assembler


Options Options that affect the way the shell processes input files.
filenames One or more C/C++ source files, assembly language source files,
linear assembly files, or object files.
-z Option that invokes the linker.
link_options Options that control the linking process.
object files Name of the additional object files for the linking process.

Chapter 2, Slide 7 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005


Invoking the C/C++ compiler
‹ file type:

Chapter 2, Slide 8 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005


Compiler’s Behavior With Options

Chapter 2, Slide 9 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005


Optimizing your C code
‹ The easiest way to invoke optimization is to use the
cl6x shell program, specifying the -ox option on the
cl6x command line. The x denotes the level of
optimization (0, 1, 2, and 3), which controls the type
and degree of optimization.

Chapter 2, Slide 10 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005


Optimizing Software Pipelining
‹ Software pipelining is a technique used to schedule
instructions from a loop so that multiple iterations of
the loop execute in parallel. The compiler always
attempts to software pipeline. In general, code size
and performance are better, when you use the -o2 or
-o3 option.

Chapter 2, Slide 11 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005


Linking C/C++ Code
‹ Invoking the Linker as an Individual Program
lnk6x {–c | –cr} filenames [ -options] [–o name.out] –l libraryname [ lnk.cmd]

when linking C/C++ programs, you must:


- Include the compiler’s run-time-support library
- Specify the type of initialization
- Determine how you want to allocate your program into memory
–l libraryname You must link all C/C++ programs with a run-time-support
library. The library contains standard C/C++ functions as well
as functions used by the compiler to manage the C/C++
environment. You must use the - l linker option to specify
which C6000 run-time-support library to use.
–c Auto initializes variables at run-time.
–cr Initializes variables at load time.
Chapter 2, Slide 12 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005
Linking C/C++ Code
‹ Invoking the Linker as an Individual Program

Example :
lnk6x -c prog1 prog2 prog3 -o prog.out -l rts6200.lib

when you link while compiling, the linker options must follow the -z
option. The -z option divides the command line into compiler options
(options before -z) and linker options (options following -z).

Example :
cl6x -sq prog.c -z c.cmd -o prog.out -l rts6200.lib

Chapter 2, Slide 13 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005


Invoking the Stand-Alone Simulator
‹ Invoking the stand-alone simulator to load and run
an executable COFF ‘.out’ file.

load6x [ options] filename.out

options Options affect how the stand-alone simulator acts and how it
handles your .out file. Options can appear anywhere on the
command line.
filename.out Names the ‘.out’ file to be loaded into the stand-alone
simulator. The ‘.out’ file must be an executable COFF file.

Chapter 2, Slide 14 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005


Interfacing C/C++ With Assembly
‹ The following are ways to use assembly language
with C/C++ code:

Š Use inline assembly language embedded


directly in the C/C++ source.
Š Use separate modules of assembled code and
link them with compiled C/C++ modules
Š Use intrinsics in C/C++ source to directly call
an assembly language statement
Š Use assembly language variables and constants
in C/C++ source

Chapter 2, Slide 15 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005


Inline assembly
‹ The C/C++ compiler can embed C6000 assembly
language instructions or directives directly into the
assembly language by using the asm statement:

asm (” assembler text ”);

‹ The asm statement is syntactically like a call to a


function named asm( ), with one string constant
argument:
1 **************************************************
2 ** you can insert a .byte directive **
3 **in a C/C++ file **
4 **************************************************
5 00000000
6 00000000 00000011 asm( “STR: .byte \”abc\” ” );
7 **************************************************

Chapter 2, Slide 16 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005


Use separate modules
Example (Asm code):
.global _asmfunc
.global _gvar
_asmfunc:
LDW *+b14(_gvar),A3
NOP 4
ADD A3,A4,A3
STW A3,*B14(_gvar)
MV A3,A4
B B3
NOP 5

Example (C code):
extern ”C” {
extern int asmfunc(int a); /* declare external as function */
int gvar = 4; /* define global variable */
}
void main( )
{
int i = 5;
i = asmfunc(i); } /* call function normally */

Chapter 2, Slide 17 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005


Use intrinsics
‹ The C6000 compiler recognizes a number of
intrinsic operators. Intrinsics allow you to express
the meaning of certain assembly statements that
would otherwise be cumbersome or inexpressible in
C/C++.
‹ Intrinsics are used like functions; you can use
C/C++ variables with these intrinsics, just as you
would with any normal function.
‹ The intrinsics are specified with a leading
underscore, and are accessed by calling them as you
do a function.
Example :
int x1, x2, y; // in Assembly : SADD : Adds src1 to src2 and saturates the
y = _sadd(x1, x2); //result. Returns the result.

Chapter 2, Slide 18 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005


Use intrinsics

Chapter 2, Slide 19 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005


Use intrinsics

Chapter 2, Slide 20 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005


Accessing an Assembly Language Variable
‹ It is sometimes useful for a C/C++ program to
access variables or constants defined in assembly
language. There are several methods that you can
use to accomplish this, depending on where and how
the item is defined:
A variable defined in the .bss section, a variable not
defined in the .bss section, or a constant

Chapter 2, Slide 21 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005


Accessing an Assembly Language Variable

Example : Assembly program

* Note the use of underscores in the following lines

.bss _var1,4 ; Define the variable


.global var1 ; Declare it as external

_var2 .usect ”mysect”,4 ; Define the variable


.global _var2 ; Declare it as external

Example : C program

extern int var1; /* External variable */


extern int var2; /* External variable */
var1 = 1; /* Use the variable */
var2 = 1; /* Use the variable*/

Chapter 2, Slide 22 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005


Accessing an Assembly Language Constant

Example : Assembly program

_table_size .set 10000 ; define the constant


.global _table_size ; make it global

Example : C program
extern int table_size; /*external ref */
#define TABLE_SIZE ((int) (&table_size))
….
….
for (i=0; i<TABLE_SIZE; ++i)
….
….
/* use like normal symbol */

Chapter 2, Slide 23 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005


TMS320C6000 C/C++ Language Implementation

‹ The TMS320C6000 C/C++ compiler supports the


C/C++ language standard that was developed by a
committee of the American National Standards
Institute (ANSI) to standardize the C programming
language.
‹ The C++ language supported by the C6000 is
defined by the ISO/IEC 14882–1998 standard with
certain exceptions

Chapter 2, Slide 24 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005


TMS320C6000 C/C++ Language Implementation

‹ Data Types
‹ Keywords
‹ Pragma Directives
‹ Initializing Static and Global Variables
‹ Changing the ANSI C Language Mode

Chapter 2, Slide 25 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005


TMS320C6000 C/C++ Language Implementation

‹ Data Type

Chapter 2, Slide 26 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005


TMS320C6000 C/C++ Language Implementation

‹ Keywords : The C6000 C/C++ compiler supports


the standard const, register, restrict, and volatile
keywords. In addition, the C6000 C/C++ compiler
extends the C/C++ language through the support of
the following keywords:
- Cregister
- Interrupt
- Near
- Far

Chapter 2, Slide 27 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005


TMS320C6000 C/C++ Language Implementation

‹ Cregister keyword : The C6000 compiler extends the


C/C++ language by adding the cregister keyword to
allow high level language access to control registers.

Chapter 2, Slide 28 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005


TMS320C6000 C/C++ Language Implementation

‹ Cregister keyword : the cregister keyword is not allowed


on any declaration within the boundaries of a function. It
can only be used on objects of type integer or pointer.
Once you have declared the register, you can use the
register name directly.
extern cregister volatile unsigned int AMR;
extern cregister volatile unsigned int CSR;
extern cregister volatile unsigned int IFR;
extern cregister volatile unsigned int ISR;
extern cregister volatile unsigned int ICR;
extern cregister volatile unsigned int IER;
extern cregister volatile unsigned int FADCR;
extern cregister volatile unsigned int FAUCR;
extern cregister volatile unsigned int FMCR;

main()
{
printf (”AMR = %x\n”, AMR); }

Chapter 2, Slide 29 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005


TMS320C6000 C/C++ Language Implementation

‹ Interrupt keyword : The C6000 compiler extends the


C/C++ language by adding the interrupt keyword, which
specifies that a function is treated as an interrupt
function.
You can only use the interrupt keyword with a function
that is defined to return void and that has no parameters.

interrupt void int_handler()


{
unsigned int flags;



}

Chapter 2, Slide 30 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005


TMS320C6000 C/C++ Language Implementation

‹ Near and far keyword : The C6000 C/C++ compiler


extends the C/C++ language with the near and far
keywords to specify how global and static variables are
accessed and how functions are called.
‹ Syntactically, the near and far keywords are treated as
storage class modifiers. They can appear before, after, or
in between the storage class specifiers and types. With
the exception of near and far, two storage class modifiers
cannot be used together in a single declaration.

far static int x;


static near int x;
static int far x;
far int foo( );
static far int foo( );

Chapter 2, Slide 31 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005


TMS320C6000 C/C++ Language Implementation

‹ Pragma directives tell the compiler how to treat


certain function, object, or section of code . The
C6000 C/C++ compiler supports the following
pragmas:

Chapter 2, Slide 32 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005


TMS320C6000 C/C++ Language Implementation

‹ Pragma directive example : CODE_SECTION


The DATA_SECTION pragma allocates space for the symbol in a
section named section name.
#pragma DATA_SECTION ( symbol, “ section name”);

The CODE_SECTION pragma is useful if you have code objects


that you want to link into an area separate from the .text section.

#pragma CODE_SECTION(fonct, ”my_sect”)


int fonct(int x)
{
return c;
}

Chapter 2, Slide 33 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005


TMS320C6000 C/C++ Language Implementation

‹ Initializing Static and Global Variables

The ANSI C standard specifies that global (extern) and static


variables without explicit initializations must be initialized to 0
before the program begins running.
This task is typically done when the program is loaded. Because the
loading process is heavily dependent on the specific environment of
the target application system, the compiler itself makes no provision
for preinitializing variables at run time.
If your loader does not preinitialize variables, you can use the linker
to preinitialize the variables to 0 in the object file. For example, in
the linker command file, use a fill value of 0 in the .bss section:
SECTIONS
{
.bss: fill = 0x00;
}

Chapter 2, Slide 34 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005


TMS320C6000 C/C++ Language Implementation

‹ Changing the ANSI C Language Mode

The -pk, -pr, and -ps options let you specify how the C/C++
compiler interprets your source code. You can compile your source
code in the following modes:
- Normal ANSI mode
- K&R C mode
- Relaxed ANSI mode
- Strict ANSI mode

Chapter 2, Slide 35 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005


Librairies
‹ The following libraries are included with the
TMS320C6000 C/C++ compiler:

Š rts6200.lib, rts6400.lib, and rts6700.lib: run-time-


support object libraries for use with little-endian
C/C++ code
Š rts6200e.lib, rts6400e.lib, and rts6700e.lib: run-time-
support object libraries for use with big-endian
C/C++ code
Š rts.src: run-time-support source library. The run-time-
support object libraries are built from the C, C++, and
assembly source contained in the rts.src library

Chapter 2, Slide 36 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005


Librairies
‹ The run-time-support libraries do not contain
functions involving signals and locale issues. They
do contain the following:

‹ ANSI C/C++ standard library


‹ C I/O library
‹ Low-level support functions that provide I/O to the
host operating system
‹ Intrinsic arithmetic routines
‹ System startup routine, _c_int00
‹ Functions and macros that allow C/C++ to access
specific instructions

Chapter 2, Slide 37 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005


Chapter III
Fin

Chapter 2, Slide 38 Hassen AZIZA, Polytech'Marseille, (c) Septembre 2005

You might also like