Motorola SC140 user manual Compiler Support on StarCore, Integer Arithmetic

Page 6

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 Value * 2 15

32-bit Integer Value = Fractional Value * 2 31

40-bit Integer Value = Fractional Value * 2 39

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 list of the intrinsic functions for fractional arithmetic can be found in the SC100 C/C++ Compiler User’s Manual. The example illustrates how the instructions are mapped based on the type of the arithmetic required. 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.

Integer

long a; short b, c;

Fractional

long a;

(Supported by intrinsics)

 

short b, c;

 

a = a + b * c;

a = L_mac(a,b,c);

move.w (r0),d0

move.f (r0),d0

imac d0,d1,d2

mac d0,d1,d2

Figure 3. Integer and Fractional Compiler Support

Hands On

The energy of a signal, x, represented by Equation 1, is considered:

N – 1

 

y = x2(i) ,

(1)

i = 0

where x(i) is the signal input sample at iteration i, y is the energy of the signal, and N is the signal length.

1. Open the example file Ex2.c.

Integer Arithmetic

2.Compile the file using ccsc100 -Ot2 Ex2.c -o Ex2.eld where the -Ot2option optimizes the code for time (Force Parallelization).

3.Run the executable using runsc100.

4.Recompile the file with the -Soption, which stops the compiler after compilation.

6

Introduction to the SC140 Tools

Image 6
Contents Motorola Typical development process is represented in Figure Compiler File I/O Exercise Hands OnGood To Know Integer and Fractional Arithmetic Exercise Interpretation of 16-bit Integer and Fractional Data ValuesCompiler Support on StarCore Integer ArithmeticFractional Arithmetic Good To Know Local Versus Global Optimization Exercise Local OptimizationCompiler Support on StarCore StarCore C Compiler Local Optimization Global OptimizationMemory Alignment Exercise AA BB CC DD First Code Section Second Code Section Split Summation Exercise Code Generated Assembly Code Multi-Sample Exercise = ∑ a i x n For 0 ≤ n LIntermediate Version Compromise Between Memory and Speed Further Speed Optimization Control Code The True Bit Exercise Save Ex7.c as Ex71.c Calling an Assembly Routine From C Exercise Current Following output should be displayed Challenge Solutions to Exercises Introduction to the SC140 ToolsExercise AlignedExpected Motorola INC Intermediate version Compromise between Memory and Speed Compiler Support on StarCore Further Optimizing the Speed Compiler Support on StarCore Compiler Support on StarCore Motorola INC Zoffset equ Moffset equ Exercise Compiler Support on StarCore Compiler Support on StarCore AN2009/D