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

Page 19
Image 19
Motorola SC140 user manual Intermediate Version Compromise Between Memory and Speed