the difference between -mtune and -march

Miles Bader miles@gnu.org
Tue Feb 8 10:40:00 GMT 2011


ali hagigat <hagigatali@gmail.com> writes:
> So why do we need -mtune? We can compile by -march from the beginning.

My understanding:

   -march=FOO:  specifies which instructions are OK to use: anything that
                works on a FOO (or compatible) CPU

   -mtune=BAR:  specifies which CPU to optimize for when
                choosing/scheduling instructions (taken from the set
                which is OK for FOO)

So if FOO and BAR are _the same_, it's pretty obvious: it will require
that CPU, and be optimized for it.

If FOO and BAR are _different_, then you the result is guaranteed to run
on FOO, but will run best on BAR -- of course BAR should be a subset of
FOO!

A common case, I think is to be fairly conservative with FOO, so the
software will run on a wide range of CPUs, but try to choose BAR to
match the most common model in current use.

E.g., "-march=i386 -mtune=core2" will run on any i386 derivative, but
will work best on a core2.

For personal use, it's usually OK to just use -march (e.g.,
-march=native to run on the current machine), but somebody who ships
software may need more flexibility.

-Miles

-- 
"Most attacks seem to take place at night, during a rainstorm, uphill,
 where four map sheets join."   -- Anon. British Officer in WW I



More information about the Gcc-help mailing list