3.4.7. Conditional statements

For efficient vectorization, loops must contain mostly assignments statements and limit the use of if and switch statements.

Simple conditions that do not change between iterations of the loop are described as being loop invariant. These can be moved before the loop by the compiler so that they do not need to be executed on each loop iteration. More complex conditional operations are vectorized by computing all pathways in vector mode and merging the results. If there is significant computation being performed conditionally, then a substantial amount of time is wasted.

Example 3.13 shows an acceptable use of conditional statements.

Example 3.13.  Vectorizable condition

float a[99], b[99], c[i];
int i, n;
...
for (i = 0; i < n; i++)
{
    if (c[i] > 0) 		a[i] = b[i] - 5.0;
    else 	a[i] = b[i] * 2.0;
};

Copyright © 2007 ARM Limited. All rights reserved.ARM DUI 0350A
Non-Confidential