Kokizzu
Kokizzu

Reputation: 26888

Compiler -march flag benchmark?

does -march flag in compilers (for example: gcc) really matters?

would it be faster if i compile all my programs and kernel using -march=my_architecture instead of -march=i686

Upvotes: 2

Views: 419

Answers (2)

A. K.
A. K.

Reputation: 38216

There is no guarantee that any code you compile with march will be faster/slower w.r.t. the other version. It really depends on the 'kind' of code and the actual result may be obtained only by measurement. e.g., if your code has lot of potential for vectorization then results might be different with and without 'march'. On the other hand, sometimes compiler do a poor job during vectorization and that might result in slower code when compiled for a specific architecture.

Upvotes: 1

Michał Kosmulski
Michał Kosmulski

Reputation: 10020

Yes it does, though the differences are only sometimes relevant. They can be quite big however if your code can be vectorized to use SSE or other extended instruction sets which are available on one architecture but not on the other. And of course the difference between 32 and 64 bit can (but need not always) be noticeable (that's -m64 if you consider it a type of -march parameter).

As anegdotic evidence, a few years back I run into a funny bug in gcc where a particular piece of code which was run on a Pentium 4 would be about 2 times slower when compiled with -march=pentium4 than when compiled with -march=pentium2.

So: often there is no difference, and sometimes there is, sometimes it's the other way around than you expect. As always: measure before you decide to use any optimizations that go beyond the "safe" range (e.g. using your actual exact CPU model instead of a more generic one).

Upvotes: 3

Related Questions