Motorola SC140 user manual Intermediate Version Compromise Between Memory and Speed

Page 19

Compiler Support on StarCore

Hands On

1.Open the Ex6.c file.

2.Compile Ex6.c using the -Ot2option. Run the code and verify that the output is correct. See the comments in Ex6.c for the correct values of y[].

3.Recompile Ex6.c using the -Ot2and -Soptions. Examine the assembly language file Ex6.sl to see how the inner loop is compiled.

Intermediate Version: Compromise Between Memory and Speed

4.Save Ex6.c as Ex6_1.c.

5.Change the C code of Ex6_1.c according to the following steps:

a.Process the first four samples at a time:

Replace the implementation of “y(n) = ai * x(n)” with the equations defined as Group 0 in Equation 5.

b.Replace x(n), x(n+1), x(n+2), x(n+3) with variables (for example, var0, var1, var2, var3, respectively), as follows:

res0 += a[i] * var0; res1 += a[i] * var1; res2 += a[i] * var2; res3 += a[i] * var3;

Group 0

This processes the first group (Group 0). To process the remaining groups, Group 1 and so on, the values from var0, var1, and var2 from Group 0 must be transferred to var1, var2, var3, respectively, for processing Group 1.

c. Transfer the values in var1, var2, and var3 and load the new sample (x(n-1)) into var0.

6.Compile the code with the -Ot2option, and run the code to verify that the correct output values are obtained.

7.Recompile Ex6_1.c using the -Ot2and -Soptions. The inner loop should be only two cycles long. If not, return to Step 5.

During each iteration of the loop, the coefficient, a[i], is loaded into a data register. The data value, x[n-1-i], is loaded into another data register. The values in the other three registers are reused, but they must first be transferred into the registers where the four MAC instructions expect them. This transfer results in two clock cycles for every four MAC instructions.

8.In the box on the following page, write the code for the intermediate version.

Introduction to the SC140 Tools

19

Image 19
Contents Motorola Typical development process is represented in Figure Compiler Hands On File I/O ExerciseGood To Know Interpretation of 16-bit Integer and Fractional Data Values Integer and Fractional Arithmetic ExerciseInteger Arithmetic Compiler Support on StarCoreFractional Arithmetic Good To Know Local Optimization Local Versus Global Optimization ExerciseCompiler Support on StarCore StarCore C Compiler Global Optimization Local OptimizationMemory Alignment Exercise AA BB CC DD First Code Section Second Code Section Split Summation Exercise Code Generated Assembly Code = ∑ a i x n For 0 ≤ n L Multi-Sample ExerciseIntermediate 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 Introduction to the SC140 Tools Solutions to ExercisesAligned ExerciseExpected 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