Introduction to the StarCore SC140
Tools: An Approach in Nine Exercises
Emmanuel Roy and David Crawford
This document presents a quick, comprehensive hands-on
introduction to the Star Core SC140 DSP core us ing progr amming
examples and exercises. The goal is to help the software
developer start writing high-level language applications in C.
Included are software-related tips on how to get the most from the
StarCore hardware architecture.
We recommend that you complete the exercises in sequential
order. The exercises require the use of the SC140 C tools
(including compiler, as sembler, linker , and simula tor) to gene rate
executable file s from C and assembly la nguage source fi les and to
verify the code performance. The tools are invoked from a
command prompt (DOS or UNIX). If you desire, you can use an
Integrated Development Environment (IDE). Be sure to consult
the appropriate IDE manuals. This document provides
step-by-step instructions to walk you through the exercises
included in the file
this zip file from the MSC8101 or MSC8102 product page at the
following Web address:
SC140_exercises.zip. You can download
Contents
1Preliminaries ........................... 2
2File I/O Exercise .....................4
3Integer and Fractional
Arithmetic Exercise ................ 5
3.1Hardware Support on StarCore........5
3.2Compiler Support on StarCore........6
4Local Versus Global
Optimization Exercise ............ 9
5Memory Alignment Exercise 12
6Split Summation Exercise .... 16
7Multi-Sample Exercise ......... 18
8Control Code: The True Bit
Exercise ..................................21
9Calling an Assembly Routine
From C Exercise ...................23
10The Challenge ........................ 26
11Solutions to Exercises........... 27
http://www.mot.com/SPS
Solutions to the exercises are provided at the end of this
application note.
The following StarCore sof tware develo pment too ls were used i n the dev elopment of the SC140 exerci ses.
Later versions of the SC140 tools should generate similar or better results:
•Version 1.0 StarCore 100 C Compiler . Produces highl y optimized code . Compiler features include
ANSI C-standard compliance, fixed-point optimization, global optimization, and a standard C
library.
•Version 6.3.44 StarCore 100 Assembler. Translates assembly languag e files into
machine-readable object files.
•sc100-ld Linker. Links and relocates the object files and produces executable program files.
Complex memory configurations can be specified, and detailed linker maps can be generated.
•Version 6.3.77 StarCore 100 Simulator and Version 1.26 Run-time Simulator. The StarCore 100
simulator can run from either a text- based or a gra phical user in terface (GUI ). A separate
simulator utility (runsc100) is currently included for run-time I/O support.
Before starting the exercises, install the files in
SC140_ex.zip on your computer in the following
directory:
•On a Windows platform:
C: \MotorolaDSP\SC140\
•On a UNIX platform: ~/MotorolaDSP/SC140/
The exercises directory structure and files are represented in Figure 1. This directory structure is only a
recommendation; any location can be used. Once you have installed the exercise files (and if you are
running on a Windows platform), all the exercises are located in:
c:\MotorolaDSP\SC140\Exercises\
•
This path is the reference path for all exercises discussed in this document.
Exercises
Ex1 (File I/O)
Ex2 (Integer & Fractional Arithmetic)
Ex3 (Local vs Global Optimization)
Ex6 (Multi-Sample Technique)
Ex7 (Control Code: Use of the True Bit)
Ex8 (Calling an Assembly Routine from C)
Ex9 (The Challenge)
To be created
Ex2.c
Ex3_main.c & Ex3_prod.c
Ex4.asm
Ex5.c
Ex6.c
Ex7.c
Ex8.c and AddVecs.asm
Ex9.c
Figure 1. Directory Structure and Files for SC140 Exercises
A typical development process is represented in Figure 2.
2
Introduction to the SC140 Tools
C files
.c, .h
C Compiler
Front End
IR library
CCSC100
.libfiles
IR files
.obj
[IR = Intermediate Representation]
CompilerAssembler
Optimizer
icode
Object library
files
.elb
Assembly files
.sl
Assembler
asmsc100
Object files
.eln
Assembly
files
.asm
Listing
files
.lst
r
e
k
n
i
L
Map
files
.map
“Run-time” Simulator
runsc100
- Execute Program to completion
- C file I/O capability
Figure 2. StarCore Development Process
sc100-ld
Linker
Absolute files
.eld
Introduction to the SC140 Tools
Interactive Simulator
simsc100
- DOS based
3
1 File I/O Exercise
The file I/O exercise shows how to use standard ANSI C I/O features with in the current tools suite.
Hands On
1. Create a new text file called
2. Within the io.c file, write code using the ANSI C printf function to display Welcome to
StarCore SC140 Tools
3. Compile the file using
-o option specifies the output file name (for example, io.eld). If the applicat io n does not
The
compile successfully, correct the reported mistake(s) and recompile the application until a successful
compilation occurs.
4. Run the executable
The runsc100 executable is a cycle-a ccu rate run-time simulator. It allows you to run an application to
completion and print out intermedi ate/final results. You can use this executable for quick code
verification and/or debugging purposes.
Congratulations, you have completed Exercise 1.
Good To Know
The SC140 core supports both Big Endian and Little Endian data
representations. Therefore, t he SC140 tools support both modes. By
default, ccsc100 and runsc100 use Little Endian mode.
Big Endian mode can be selected by:
runsc100 io.eld to display Welcome to StarCore SC140 Tools.
io.c.
on the screen (remember to include the header file stdio.h),
ccsc100 io.c -o io.eld.
•specifying the -be option for ccsc100
•specifying the -e option for runsc100
If the code is built using Big Endian mode, it must be run using Big
Endian mode.
Reminder: (memory storage of a = 0x12345678)
Big Endian ModeLittle Endian Mode
p:00 1234p:00 7856
p:02 5678p:02 3412
4
Introduction to the SC140 Tools
Hardware Support on StarCore
2 Integer and Fractional Arithmetic Exercise
One of the strengths of b oth the StarC ore architecture and th e StarCore co mpiler is the ability to pe rform
both fractional and integer arithmetic. This exercise presents a reminder about integer and fractional
arithmeti c representation and then shows how to use the StarCore compiler fractional intrinsics. Values
stored in memory or registers are interpreted differently depending on the operation performed. For
integers, the binary point is considered to be immediately to the right of the LSB. For the fractional case,
the binary point is considered to be immediately to the right of the MSB. Table 1 illustrates this for 16-bit
data values.
Table 1. Interpretation of 16-bit Integer and Fractional Data Values
StarCore has a dual instruction set for operations that produce different results depending on whether
fractional or integer arithmetic is used. The instruction set is complementary when an integer or a
fractional operation leads to the same result, regardless of the operation type: for example, an addition.
The instruction set is dual (as shown in Table 2) in two cases, which automatically take care of data
alignment, zero filling, and sign extension:
•when an integer or a fractional operation leads to a different result depending on the operation
type: for example, a multiplication.
•when data is transferred from/to memory.
Table 2. Fractional and Integer Assembly Language Instructions
OperationIntegerFractional
Multiplyimpympy
Multiply accumulateimacmac
Movemove.b, move.w,
move.2w, move.4w
Introduction to the SC140 Tools
move.f, move.2f, move. 4f
5
Compiler Support on StarCore
2.2 Compiler Support on StarCore
The StarCore compiler implements fractional arithmetic using built-in intrinsic functions based on integer
data types. Any fractional values or constants must therefore be defined using their integer equivalent.
Useful relationships for deriving these integer representations from the fractional vales are as follows:
16-bit Integer Value = Fractional Va lue * 2
32-bit Integer Value = Fractional Va lue * 2
40-bit Integer Value = Fractional Va lue * 2
The names of the built-in intrinsics conform to the ITU/ETSI basic operation functions. For instance, the
L_mac() intrinsic function is used in the following example (see Figure 3), and a complete li st of the
intrinsic functions for fractional arithmetic can be found in the SC100 C/C++ Compiler User’s Manual.
The example illustrates how the in structions are mapped based on the type of the arithmetic re quired. For
integer arithmetic, the compiler generates integer instructions (for example, imac). For fractional
arithmetic, it generates fractional instructions (for example, mac). Also, move instructions are generated
with correct data alignment.
15
31
39
Integer
long a;
short b, c;
a = a + b * c;a = L_mac(a,b,c);
move.w (r0),d0move.f (r0) ,d0
imac d0,d1,d2mac d0,d1,d2
Figure 3. Integer and Fractional Compiler Support
long a;
short b, c;
Fractional
(Supported by intrinsics)
Hands On
The energy of a signal, x, represented by Equation 1, is considered:
N 1–
2
yx
=
∑
i0=
, (1)
i()
where x(i) is the signal input sa mple at iterat i on i, y is the energy of the signal, and N is the signal len gth.
1. Open t he example file Ex2.c.
Integer Arithmetic
2. Compile the file using ccsc100 -Ot2 Ex2.c -o Ex2.eld where the -Ot2 option optimizes the
code for ti me (Force Pa rallelization).
3. Run the executable using runsc100.
4. Recompile the file with the
6
-S option, which stops the compiler after compilation.
Introduction to the SC140 Tools
Compiler Support on StarCore
5. Open the generated assembly file Ex2.sl and look at the integer instructions within the loop.
6. In the box provided here, write down the integer C code and the generated assembly instructions for
the loop. N otice that the first data load is automati cally pipelined in the software.
Integer Arithmetic
C codeGenerated Assembly code
Fractional Arithmetic
7. For fractional arithmetic, copy and paste the loop of Ex2.c.
The first loop remains unchanged and performs integer calculation while the second loop is modified
to perform fractional arithmetic.
8. In the second loop, replace the integer arithmetic operation with the appropriate fractional intrinsic.
Remember, fractional arithmetic is performed using C compiler intrinsics. In this example, the L_mac
intrinsic is used. Its prototype is:
long int L_mac(long int, short int, short int).
Therefore, the code modifications should be:
a. Create a new variable “fres” of type “long int.”
b. Replace “res += x[i] * x[ i];” with the instruction “fres = L_mac(fres,x[i],x[i]).”
c. Include the file
prototype.h, which contains all the intrinsics prototypes.
d. Add another printf statement to print out the fractional result. The result is sti l l a “long int,” so
“%d” should still be used.
9. Recompile the code with the
-S option and look at the generated assembly file Ex2.sl within the
second loop.
10. In the box provided below, wri te the f racti onal C code and the gen erate d ass embly ins truct ions fo r that
loop.
Fractional Arithmetic
C codeGenerated Assembly code
Introduction to the SC140 Tools
7
Compiler Support on StarCore
11. Compare the fractional assembly instructions generated to the assembly integer instructi ons.
12. Recompile the code without the
-S option to produce an executable file.
13. Run the code using runsc100. The variables “res” and “fres” should print to the screen. What is the
algebraic relationship between these two variables?
Congratulations, you have completed Exercise 2.
Good To Know
To perform fractional operations:
•Intrinsics are used.
•The variable types remain integer.
•The header file prototype.h should be included in
the C source file.
All assembly instructions (compiler generated or hand
written) between square brackets [ ] execute in parallel as
a single execution set.
8
Introduction to the SC140 Tools
Compiler Support on StarCore
3 Local Versus Global Optimizati on Exercise
The local versus global optimization exercise shows the difference between two C compiler options: local
optimization (the default) and global optimization. Local optimization compiles each file of the project
individually as represented in Figure 4. Global optimization acts as a global binder that links all the
intermediate representation (IR) fi les into one fi le before opt imizing the application. Since all the
application code information is available, this approach enables further optimizations beyond those
achieved using local optimization alone. (Compilation takes longer when global optimization is enabled.)
Global optimization compilation flow is represented in Figure 5.
StarCore C Compiler
Local
Optimization
C files
.c, .h
C compiler
Front End
IR files
.obj
Optimizer
icode
Assembler
asmsc100
C files
.c, .h
C compiler
Front End
IR files
.obj
Optimizer
icode
Assembler
asmsc100
C files
.c, .h
C compiler
Front End
IR files
.obj
Optimizer
icode
Assembler
asmsc100
Object library
files .elb
Linker
Figure 4. StarCore Local Optimizati on
Introduction to the SC140 Tools
9
Compiler Support on StarCore
StarCore C Compiler
C files
.c, .h
C Compiler
Front End
IR files
.obj
Global
Optimization
Assembler
asmsc100
C files
.c, .h
C Compiler
Front End
IR files
.obj
Optimizer
icode
Assembler
asmsc100
C files
.c, .h
C Compiler
Front End
IR files
.obj
Assembler
asmsc100
Object Library
Files, .elb
Figure 5. StarCore Global Optimization
Linker
Hands On
The benefit of Global Optimization is most apparent when several files containing cross references are
used, as is often the case in any sizeable application. In this example, two files are used:
•the main file called
Ex3_main.c
•a function file called Ex3_prod.c
The main file, Ex3_main.c, calls a routine defined in the function file Ex3_prod.c, as shown in Figure 6.
10
Introduction to the SC140 Tools
Compiler Support on StarCore
Ex3_main.c
...
main()
{
...
res=Prod(&array1[0],&array2[0]);
...
}
Figure 6. Files for the Local Versus Global Optimization Exercise
1. Open the two files and understand their functionality.
Local Optimization
2. Compil e the two files:
ccsc100 -Ot2 Ex3_main.c Ex3_prod.c -o Ex3.eld
3. Run the code: runsc100 -t Ex3.eld.
The
-t option for runsc100 enable s the cyc le coun t ge nerat ion. Writ e the cy cle cou nt i n the box below:
runsc100 -t Ex3_glo.eld. Write the cycle count in the box below:
Global Optimization (-Og option) Cycle Count
Introduction to the SC140 Tools
11
Compiler Support on StarCore
To understand how global optimization makes best use of available information, perform these steps:
6. Recompile the application with
ccsc100 -Ot2 Ex3_main.c Ex3_prod.c -S.
7. Rename the
.sl files as Ex3_main1.sl and Ex3_prod1.sl.
-S option (Stop After Compilation) and with the local optimization:
8. Open the files to see what the compiler has produced.
9. Enable global optimizatio n:
10. Open
Ex3_main.sl to see what the compiler has produced.
ccsc100 -Ot2 -Og Ex3_main.c Ex3_prod.c -S.
Since the compiler has all information on the application, it optimizes the application further than with
local optimization. The compiler avoids calling the function by in-lining the function into the main
code (as shown in
Ex3_main.sl). Theref ore, it eliminates the cycle overhead associated with
jumping to and returning from the function and passing the parameters to the functions.
Congratulations, you have completed Exercise 3.
Good To Know
•Global optimization requires a longer compilation
time than local optimization.
•Global optimization further opti mizes the application
speed.
4 Memory Alignment Exercise
The memory alignment exercise shows the usage of wide data moves and the necessary alignments for
performing these moves. The SC140 memory has byte granularity (as represented in Figure7). Two
arithmetic address units (AAUs) transfer the data from memory to the 4 ALUs (and vice versa) via two
64-bit data buses. Each data bus allows the transfer of up to eight bytes from memory to the data registers
in one cycle (and vice versa).
If the compiler must generate the wide data move instructions available in the StarCore instruction
set—such as move.2w, move.2f, move.4w, and so on—data must be correctly aligned in memory. This is
due to the way the address and data buses operate for multi-byte accesses in the StarCore architecture. The
compiler does not generate wide data move instructions if alignment is not guaranteed. However, if a
function is implemented in ass embly la nguage a nd uses wi de dat a move ins truct ions, you must e nsure t hat
the data is aligned on the appropriate boundary. Otherwise, the wrong data is transferred.
P:0x00
P:0x08 CDAB8967452301EF
P:0x10
....
Figure 7. Memory Granularity
ABFFEEDDCCBBAABC
8 bytes
8 bytes
12
Introduction to the SC140 Tools
Loading...
+ 28 hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.