Graphics Reference
In-Depth Information
g[i] = (big expression involving i) * h[i] + (second big expression
involving i);
}
Extracting the two big expressions as separate functions may not necessarily be
a good approach, as calling separate functions from within the large function could
cause cache thrashing. A better approach is to rewrite the code as:
if(m>n){
lo=a;hi=b;out=c;in=d;
} else {
lo=e;hi=f;out=g;in=h;
}
for (int i = lo; i < hi; i++)
out[i] = (big expression involving i) * in[i] + (second big expression involving i);
This change effectively cuts the code size in half.
Many architectures provide one or more cache control instructions that can also
help improve instruction cache use. Specifically, they can be used to instruct the
CPU to fetch one or more cache lines worth of code into the instruction cache.
By issuing cache instruction calls to the address of a function well in advance,
the function can be in cache when it is called. However, in practice it can be dif-
ficult to put these instructions to effective use. Careful profiling can help gauge
what improvements are made. To utilize the instruction cache effectively, it is quite
important to study the machine code generated by the compiler to see how effi-
cient it is, and to gain a sense of how changes in the high-level code can affect the
generated code.
13.3 Data Cache Optimizations
The utilization of a data cache is also improved by reducing the size and increas-
ing both the spatial and temporal locality of the data processed. Although size
reduction can be seen as a form of compression, it rarely involves using a tra-
ditional coding method such as, say, Huffman, Lempel-Ziv, or arithmetic coding
[Sayood00]. These are great when working with larger sets of data from high-latency
sources such as secondary storage devices or network connections. When work-
ing with just a few bytes of data at a time from main and cached memory, the
decompression time for these methods costs more than the savings. Instead, size
reduction involves reassessing the stored data to see if it really has to be stored
 
Search WWH ::




Custom Search