HP aC++ A.03.85 Release Notes

HP aC++ Release Notes
New Features in Version A.03.33
Chapter 1 35
Gather/Scatter Prefetch Pragma
A pragma is now supported to prefetch specified cache lines. The behavior of this pragma is
similar to +Odataprefetch but the prefetch pragma can access specific elements in indexed
arrays that are stored in cache. In addition, any valid lvalue can be used as an argument, but
the intent of the pragma is to support array processing.
Syntax
#pragma prefetch <argument>
There can be only one argument per pragma. The compiler generates instructions to prefetch
the cache lines starting from the address given in the argument. The array element values
prefetched must be valid. Reading outside the boundaries of an array results in undefined
behavior at runtime.
Example
The function below will prefetch ia and b, but not a[ia[i]] when compiled with the
command +O2 +Odataprefetch +DA2.0 (or +DA2.0W).
void testprefc2(int n, double *a, int *ia, double *b)
{
for (int i=0; i<n, i++) {
b[i]=a[ia[i]];
}
}
Recording this routine as:
#define USER_SPECIFIED 30
void testprefc2(int n, double *a, int *ia, double *b)
{
int dist=(int)USER_SPECIFIED;
int nend=max(0,n_dist); /* so as not to read past the end of ia */
for(i=0;i<nend;i++) /* original loop is for (i=0;i<n;i++)*/
{
#pragma prefetch ia[i+4*dist]
#pragma prefetch a[ia[i+dist]]
b[i]=a[ia[i]];
}
/* finish up last part with no prefetching */