This topic addresses language features that better help to vectorize code. The __declspec(align(n)) declaration enables you to overcome hardware alignment constraints. The restrict qualifier and the pragmas address the stylistic issues due to lexical scope, data dependence, and ambiguity resolution.
| Option | Description |
|---|---|
| __declspec(align(n)) | Directs the compiler to align the variable to an n-byte boundary. Address of the variable is address mod n=0. |
| __declspec(align(n,off)) | Directs the compiler to align the variable to an n-byte boundary with offset off within each n-byte boundary. Address of the variable is address mod n = off. |
| restrict | Permits the disambiguator flexibility in alias assumptions, which enables more vectorization. |
| __assume_aligned(a,n) | Instructs the compiler to assume that array a is aligned on an n-byte boundary; used in cases where the compiler has failed to obtain alignment information. |
|
#pragma ivdep |
Instructs the compiler to ignore assumed vector dependencies. |
| #pragma vector {aligned | unaligned | always} |
Specifies how to vectorize the loop and indicates that efficiency heuristics should be ignored. |
| #pragma novector | Specifies that the loop should never be vectorized |
Multi-version code is generated by the compiler in cases where data dependence analysis fails to prove independence for a loop due to the occurrence of pointers with unknown values. This functionality is referred to as dynamic dependence testing.
| Sample Code |
|---|
|
float *p, *q;
for(i=L; I<=U; i++) { p[i]=q[i]; }
...
pL=p*4*L; pH=p+4*U; qL=q+4*L; qH=q+4*U;
if(pH<qL || pL>qH) {
// Loop without data dependence for(i=L; i<=U; i++) { p[i]=q[i]; } else {
for(i=L; i<=U; i++) { p[i]=q[i]; } } |