GCC recommendations and options for fastest code

前端 未结 7 1477
野趣味
野趣味 2020-12-23 18:34

I\'m distributing a C++ program with a makefile for the Unix version, and I\'m wondering what compiler options I should use to get the fastest possible code (it falls into t

7条回答
  •  情话喂你
    2020-12-23 19:16

    I would try profile guided optimization:

    -fprofile-generate Enable options usually used for instrumenting application to produce profile useful for later recompilation with profile feedback based optimization. You must use -fprofile-generate both when compiling and when linking your program. The following options are enabled: -fprofile-arcs, -fprofile-values, -fvpt.

    You should also give the compiler hints about the architecture on which the program will run. For example if it will only run on a server and you can compile it on the same machine as the server, you can just use -march=native. Otherwise you need to determine which features your users will all have and pass the corresponding parameter to GCC.

    (Apparently you're targeting 64-bit, so GCC will probably already include more optimizations than for generic x86.)

提交回复
热议问题