www.ti.com
Data Memory
void PRE_filter1(int input[], int length, int *z)
{
int I, tmp;
for (I = 0; I < length; I++) {
tmp = input[i] - z[0] + (13 * z[1] + 16) / 32; z[1] = z[0];
z[0] = input[i]; input[i] = tmp;
}
}
This technique of replacing references to global data with references to parameters illustrates a general technique that can be used to make virtually any Code reentrant. One simply defines a "state object" as one that contains all of the state necessary for the algorithm; a pointer to this state is passed to the algorithm (along with the input and output data).
typedef struct
PRE_Obj { /* state obj for
int z1; } PRE_Obj;
void
PRE_filter2(PRE_Obj *pre, int input[], int length)
{
int I, tmp;
for (I = 0; I < length; I++)
{
tmp = input[i] -
}
}
Although the C Code looks more complicated than our original implementation, its performance is comparable, it is fully reentrant, and its performance can be configured on a "per data object" basis. Since each state object can be placed in any data memory, it is possible to place some objects in
Notice that while performance is comparable to our original implementation, it is slightly larger and slower because of the state object redirection. Directly referencing global data is often more efficient than referencing data via an address register. On the other hand, the decrease in efficiency can usually be factored out of the
"We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil."
2.3Data Memory
The large performance difference between
SPRU352G | General Programming Guidelines | 19 |