How would I determine -march=<type> on the fly

The system I work with generates code and then compiles it into a shared library
to execute. Currently we choose to set -march=core2 which is easy enough but
quite silly because we don’t get any machine specific optimizations that could get
better execution times.

I can’t google how to find the appropriate arch type for the compiler. If I could do
that then I could check the hardware (somehow) and match it to the proper -march
tag, and have the resulting compile line include the target hardware thus generating
better performant code.

Anyone know how that could be done?


David Barto

Sometimes, my best code does nothing. Most of the rest of it has bugs.

Hi David,

-march=native will auto detect the CPU.