3.14 Reduction of a vector to a scalar

A special category of scalar use within loops is reduction operations. This category involves the reduction of a vector of values down to a scalar result.

The most common reduction is the summation of all elements of a vector. Other reductions include:

  • The dot product of two vectors.

  • The maximum value in a vector.

  • The minimum value in a vector.

  • The product of all vector elements.

  • The index of the maximum or minimum element of a vector.

The following example shows a dot product reduction where x is a reduction scalar.

float a[99], b[99], x;
int i, n;
for (i = 0; i < n; i++) x += a[i] * b[i];

Reduction operations are worth vectorizing because they occur so often. In general, reduction operations are vectorized by creating a vector of partial reductions that is then reduced into the final resulting scalar.

Related concepts
3.17 Nonvectorization on conditional loop exits
3.16 Nonvectorization on loops containing pointers and indirect addressing
3.15 Vectorization on loops containing pointers
3.13 Carry-around scalar variables and vectorization
3.12 Data dependency conflicts when vectorizing code
3.9 Factors affecting NEON vectorization performance
3.6 Automatic vectorization
Related reference
3.11 Recommended loop structure for vectorization
8.189 --vectorize, --no_vectorize
3.10 NEON vectorization performance goals
Non-ConfidentialPDF file icon PDF versionARM DUI0472J
Copyright © 2010-2013 ARM. All rights reserved.