[wplug] what is optimized by -march in gcc?

Mark Dalrymple wplug at badgertronics.com
Fri May 28 12:36:54 EDT 2004


> So, I am tempted to type ./configure
> CFLAGS="-march=pentium-mmx". Would that make the
> application foo run faster, or would that just make
> gcc run faster?

It should make the application run faster.  The "-march" flag means:

  Generate instructions for the machine type cpu-type. The choices for
  cpu-type are the same as for -mcpu. Moreover, specifying
  -march=cpu-type implies -mcpu=cpu-type.

and "-mcpu" means:

  Tune to cpu-type everything applicable about the generated code,
  While picking a specific cpu-type will schedule things appropriately
  for that particular chip, the compiler will not generate any code that
  does not run on the i386 without the -march=cpu-type option being
  used.

So by using -march, the compiler can use instructions and addressing modes
that the the i586 or the pentium-mmx support, but the i386 doesn't, and it
will also schedule instructions (order them so that it takes
advantage of features or peculiarities of the particular processor) 
appropriately.


> And, given that I have just 64Mb, would there be a
> memory use penalty? 

For this kind of optimization, usually not, or if there is, it's small.
Now, if you were doing other gcc optimizations, like loop unrolling or
oricing function inlining, then you can make the end result substantially
larger.

Optimization is an iterative "measure / change / measure" kind of game,
which can be a lot of fun if you have the time and inclination.

Cheers,
++Mark Dalrymple.  markd at badgertronics.com.  http://badgertronics.com
  "i dream of a nation where all of the trailer parks are replaced
   with beautiful landscapes scattered with yurts"
    -- BlueKanary





More information about the wplug mailing list