![Intel IXP45X Скачать руководство пользователя страница 211](http://html1.mh-extra.com/html/intel/ixp45x/ixp45x_developers-manual_2073092211.webp)
Intel
®
IXP45X and Intel
®
IXP46X Product Line of Network Processors
August 2006
Developer’s Manual
Order Number: 306262-004US
211
Intel XScale
®
Processor—Intel
®
IXP45X and Intel
®
IXP46X Product Line of Network Processors
Recursive data structure traversal is another construct where prefetching can be
applied. This is similar to linked list traversal. Consider the following pre-order traversal
of a binary tree:
The pointer variable t becomes the pseudo induction variable in a recursive loop. The
data structures pointed to by the values t->left and t->right can be pre-fetched for the
next iteration of the loop.
Note the order reversal of the prefetches in relationship to the usage. If there is a
cache conflict and data is evicted from the cache then only the data from the first
prefetch is lost.
3.10.4.4.9
Loop Interchange
As mentioned earlier, the sequence in which data is accessed affects cache thrashing.
Usually, it is best to access data in a contiguous spatially address range. However,
arrays of data may have been laid out such that indexed elements are not physically
next to each other. Consider the following C code which places array elements in row
major order.
In the above example, A[i][j] and A[i+1][j] are not sequentially next to each other.
This situation causes an increase in bus traffic when prefetching loop data. In some
cases where the loop mathematics are unaffected, the problem can be resolved by
induction variable interchange. The above examples becomes:
3.10.4.4.10 Loop Fusion
Loop fusion is a process of combining multiple loops, which reuse the same data, in to
one loop. The advantage of this is that the reused data is immediately accessible from
the data cache. Consider the following example:
preorder(treeNode *t) {
if(t) {
process(t->data);
preorder(t->left);
preorder(t->right);
}
}
preorder(treeNode *t) {
if(t) {
prefetch(t->right);
prefetch(t->left);
process(t->data);
preorder(t->left);
preorder(t->right);
}
}
for(j=0; j<NMAX; j++)
for(i=0; i<NMAX; i++)
{
prefetch(A[i+1][j]);
sum += A[i][j];
}
for(i=0; i<NMAX; i++)
for(j=0; j<NMAX; j++)
{
prefetch(A[i][j+1]);
sum += A[i][j];
}