3.3.2. Vectorization concepts

This section describes some concepts that are commonly used when considering vectorization of code.

Data references

Data references in your code can be classified as one of three types:

Scalar

A single location that does not change through all the iterations of the loop.

Index

An integer quantity that increments by a constant amount each pass through the loop.

Vector

A range of memory locations with a constant stride between consecutive elements.

Example 3.2 shows the classification of variables in the loop:

i,j

index variables

a,b

vectors

x

scalar

Example 3.2. Categorization of a vectorizable loop

float *a, *b;
int i, j, n;
...
for (i = 0; i < n; i++)
{
    *(a+j) = x +b[i];
    j += 2;
};

When classifying variables ensure that vectorization of the loop provides the same results as the scalar version. Loops are unable to vectorize directly if there are data dependencies within the loop that calculate future iterations. See Data dependencies.

Stride patterns and data accesses

The stride pattern of data accesses in a loop is the pattern of accesses to data elements between sequential loop iterations. For example, a loop that linearly accesses each element of an array has a stride of one. Another example is a loop that accesses an array with a constant offset between each element used is described as having a constant stride.

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