Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I disable vectorization while using GCC?

I am compiling my code using following command:

gcc -O3 -ftree-vectorizer-verbose=6 -msse4.1 -ffast-math 

With this all the optimizations are enabled.

But I want to disable vectorization while keeping the other optimizations.

like image 473
PhantomM Avatar asked Oct 15 '11 13:10

PhantomM


People also ask

Does GCC automatically use SIMD?

The v4 series of the gcc compiler can automatically vectorize loops using the SIMD processor on some modern CPUs, such as the AMD Athlon or Intel Pentium/Core chips.

What is vectorization in compiler?

A vectorizing compiler transforms such loops into sequences of vector operations. These vector operations perform additions on blocks of elements from the arrays a , b and c . Automatic vectorization is a major research topic in computer science.

What is the use of vectorize option?

Vectorization is the process of converting an algorithm from operating on a single value at a time to operating on a set of values (vector) at one time. Modern CPUs provide direct support for vector operations where a single instruction is applied to multiple data (SIMD).

What is SLP vectorization?

The SLP Vectorizer The goal of SLP vectorization (a.k.a. superword-level parallelism) is to combine similar independent instructions into vector instructions. Memory accesses, arithmetic operations, comparison operations, PHI-nodes, can all be vectorized using this technique.


2 Answers

Most of the GCC switches can be used with a no prefix to disable their behavior. Try with -fno-tree-vectorize (after -O3 on the command line).

like image 194
Mat Avatar answered Nov 08 '22 15:11

Mat


you can also selectively enable and disable vectorization with the optimize function attributes or pragmas

http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html

http://gcc.gnu.org/onlinedocs/gcc/Function-Specific-Option-Pragmas.html

e.g.

__attribute__((optimize("no-tree-vectorize")))
void f(double * restrict a, double * restrict b)
{
    for (int i = 0; i < 256; i++)
        a[i] += b[i];
}
like image 35
jtaylor Avatar answered Nov 08 '22 13:11

jtaylor