Digital Signal Processing Reference
In-Depth Information
dotpfunc.c is 206 with a code size of 176; (2) with compiler options -g -o3 ,the
number of cycles is reduced from 206 to 66, but the code size is increased to 484;
(3) with options -g -pm - o3 , the number of cycles is further reduced to 25 with
a code size of 72. The - pm option uses program level optimization, with the source
files compiled into one intermediate file. The results obtained with this option can
be compared to the results obtained with the function dotp in Example 1.3. Note
that the function dotpfunc.c can be readily profiled by creating a profiling area,
dragging (with your mouse) the function into the profiling area.
In Chapter 8 we use optimization techniques associated with the dot product
example, using two arrays each with N numbers. We show that the number of cycles
can be reduced to 7
1 with a fixed-point implementation, or 108 cycles
using 200 numbers in each array. For a floating-point implementation, we obtain 124
cycles (see Table 8.4).
+
( N /2)
+
Example 3.2: Sum of n
+
(n
-
1)
+
(n
-
2)
+
...
+
1, Using C
Calling an Assembly Function ( sum )
This example illustrates a C program calling an assembly function. The C
source program sum.c shown in Figure 3.8 calls the assembly-coded function
sumfunc.asm shown in Figure 3.9. It implements the sum of n
+
( n
-
1)
+
( n
-
2)
+
1. The value of n is set in the main C program. It is passed through register
A4 (by convention). For example, the address of more than one value can be passed
to the assembly function through A4, B4, A6, B6, and so on. The resulting sum from
the assembly ( asm ) function is returned to result in the C program, which then
prints this resulting sum.
The assembly function's name is preceded by an underscore (by convention). The
value n in register A4 in the asm function is moved to register A1 to set A1 as a
loop counter since only A1, A2, B0, B1, and B2 can be used as conditional registers.
A1 is then decremented. A loop section of code starts with the label or address
...
+
// Sum.c Finds n+(n-1)+...+1. Calls ASM function sumfunc
#include <stdio.h>
main()
{
short n=6; //set value
short result; //result from asm function
result = sumfunc(n); //call ASM function sumfunc
printf("sum = %d", result); //print result from asm function
}
FIGURE 3.8. C program that calls an ASM function to find n
+
( n
-
1)
+
( n
-
2)
+ ...+
1
( sum.c ).
Search WWH ::




Custom Search