View previous topic :: View next topic |
Author |
Message |
pentium4borg n00b
Joined: 29 Aug 2006 Posts: 47
|
Posted: Sat Feb 12, 2011 9:17 pm Post subject: -march and -mtune for portable x86_64 |
|
|
I have a Core 2 Duo machine that I'm planning to reinstall. The old OS has these settings:
Code: | CHOST="x86_64-pc-linux-gnu"
CFLAGS="-march=nocona -O2 -pipe"
CXXFLAGS="${CFLAGS}" |
I want my new install to be portable to a different x86_64 CPU if I change hardware later. The safe CFLAGS guide wasn't too helpful, but I think I figured out the settings I need:
Code: | CHOST="x86_64-pc-linux-gnu"
CFLAGS="-march=x86-64 -mtune=nocona -O2 -pipe"
CXXFLAGS="${CFLAGS}" |
If I change hardware later, I can change my -mtune and recompile, but at least the system will boot on new hardware. Can someone confirm these settings are right? |
|
Back to top |
|
|
DONAHUE Watchman
Joined: 09 Dec 2006 Posts: 7651 Location: Goose Creek SC
|
Posted: Sun Feb 13, 2011 4:31 am Post subject: |
|
|
CFLAGS="-march=native -O2 -pipe" is popular these days _________________ Defund the FCC. |
|
Back to top |
|
|
pentium4borg n00b
Joined: 29 Aug 2006 Posts: 47
|
Posted: Sun Feb 13, 2011 4:34 am Post subject: |
|
|
Doesn't -march=native produce optimized code for the current CPU? If so, the OS will be compiled for my Core 2 Duo and won't be portable to another processor. |
|
Back to top |
|
|
DONAHUE Watchman
Joined: 09 Dec 2006 Posts: 7651 Location: Goose Creek SC
|
Posted: Sun Feb 13, 2011 4:48 am Post subject: |
|
|
sorry, incomplete reading _________________ Defund the FCC. |
|
Back to top |
|
|
Veldrin Veteran
Joined: 27 Jul 2004 Posts: 1945 Location: Zurich, Switzerland
|
Posted: Sun Feb 13, 2011 10:50 am Post subject: |
|
|
You might also want to drop -mtune=nocona, or replace it with -mtune=generic. _________________ read the portage output!
If my answer is too concise, ask for an explanation. |
|
Back to top |
|
|
Aquous l33t
Joined: 08 Jan 2011 Posts: 700
|
Posted: Sun Feb 13, 2011 7:46 pm Post subject: |
|
|
If you read the gcc manual, you'll see that march specifies the instruction set to use, meaning it should be set to either 'generic' or the lowest common denominator of your target CPUs, and that mtune specifies which specific optimizations to apply, meaning it should be set to match the processor you use most frequently.
http://gcc.gnu.org/onlinedocs/gcc/i386-and-x86_002d64-Options.html |
|
Back to top |
|
|
wcg Guru
Joined: 06 Jan 2009 Posts: 588
|
Posted: Mon Feb 21, 2011 6:11 pm Post subject: |
|
|
On a pIII, I would compile with "-march=i686 -mtune=pentium3".
The -march=i686 told gcc to use an instruction set that would run
on pentium pro, pentium II, pentium III, pentium 4, pentium-M,
athlon, and various other intel 32-bit instruction set compatible
cpus. The -mtune=pentium3 told gcc to optimize scheduling of
instructions for a pentium III. On anything other than a pIII
that was still instruction set compatible, the code would run slower
than if instruction scheduling had been tuned for that cpu, but it
would still run (so I could boot the system on a different motherboard
with a different 32-bit cpu that still supported the Pentium Pro
instruction set if necessary and then recompile).
The OP seems to be wondering if there is some 64-bit equivalent
of -march=i686, so that he can compile to a 64-bit instruction set
that will run on both intel and amd 64-bit x86-family cpus, while
using -mtune to schedule instructions for his current 64-bit cpu.
I do not see it in the gcc submodel options:
http://gcc.gnu.org/onlinedocs/gcc/i386-and-x86_002d64-Options.html#i386-and-x86_002d64-Options
(If you have the gcc info pages installed, info gcc -> Invoking GCC: ->
Submodel Options: -> i386 and x86-64 Options:)
I would expect it to be "-march=x86-64" if there were such a 64-bit x86
common denominator instruction set.
"generic" probably works for -mtune=, instruction scheduling for some
average of what would produce best cpu performance over several cpu
models, but the description of what it does is too vague to use it for an
-march= parameter (will it use a 32-bit or 64-bit instruction set, for example). _________________ TIA |
|
Back to top |
|
|
pentium4borg n00b
Joined: 29 Aug 2006 Posts: 47
|
Posted: Mon Feb 21, 2011 6:29 pm Post subject: |
|
|
It turns out -march=x86-64 -mtune=nocona is what I need. I spent some time yesterday compiling a base system with these options (on my Intel machine where the OS will be installed), and then I rsync'd the install to a blank partition on my desktop machine (an AMD64). My desktop was able to boot the system, so I'm good to go. |
|
Back to top |
|
|
wcg Guru
Joined: 06 Jan 2009 Posts: 588
|
Posted: Tue Feb 22, 2011 6:46 pm Post subject: |
|
|
Quote: | -march=x86-64 -mtune=nocona |
I do not see "x86-64" in the options for -march= (and/or -mtune=) in the
gcc documentation, so what are the chances that gcc simply ignored
an unrecognized -march= parameter and compiled with the default
i386 instruction set? (Runs on any kind of x86 386 and newer, but there
are no 64-bit instructions in that instruction set.)
Check your emerge logs, maybe there is a message about it.
If you have the "file" package installed ("emerge --info file" should
tell you), you could run "file pathname" on one of your newly
compiled binaries and see whether file thinks it is 64-bit or not.
For normal athlon64 binaries, file reports "ELF 64-bit LSB executable"
on an amd64 X2 system here. For grub, it reports "ELF 32-bit LSB executable".
(grub needs 32-bit emulation enabled in the kernel to run on this system.)
If you use -march=nocona, it might run on nocona, core2, core7,
and atom, but I do not know if it would run on the amd 64-bit cpus
as well. _________________ TIA |
|
Back to top |
|
|
pentium4borg n00b
Joined: 29 Aug 2006 Posts: 47
|
Posted: Tue Feb 22, 2011 6:57 pm Post subject: |
|
|
I don't see that option in the manual, but I also don't see any errors in the emerge logs. Searching google shows that x86-64 might be an alias for k8, but I'm not sure. I ran file on the mysql binary (which portage compiled) and it shows it as 64-bit:
Quote: | pentium4borg@optimus ~ $ file /usr/bin/mysql
/usr/bin/mysql: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.9, stripped |
Since -march=x86-64 seems to be working and is portable to my AMD machine, I'm just going to go with it. |
|
Back to top |
|
|
xaviermiller Bodhisattva
Joined: 23 Jul 2004 Posts: 8708 Location: ~Brussels - Belgique
|
Posted: Tue Feb 22, 2011 7:32 pm Post subject: |
|
|
Code: | -march=generic -mtune=generic | is more portable: it will compile for all platforms, based on the lowest comon CPU: it will be
- i686 when CHOST=i686-gentoo-linux-gnu
- k8 (or something like that) when CHOST=x86_64-gentoo-linux-gnu
- this_cool_processor when CHOST=this_cool_processor-gentoo-linux-gnu
And so, I use almost the same make.conf for all my platforms. I only have to adjust some USE, CHOST and ACCEPT_KEYWORDS. I do it for i686 and x86_64 builds. _________________ Kind regards,
Xavier Miller |
|
Back to top |
|
|
wcg Guru
Joined: 06 Jan 2009 Posts: 588
|
Posted: Wed Feb 23, 2011 12:44 am Post subject: |
|
|
What happens when you use -march=generic (or
-march=x86-64 for that matter) may depend on
what version of gcc you have as the default
compiler ("gcc-config -l" to see which versions are
installed and which version is currently selected
as the default compiler).
From the gcc-4.4.4 documentation:
Quote: |
There is no -march=generic option because -march indicates the instruction set the compiler can use, and there is no generic instruction set applicable to all processors. In contrast, -mtune indicates the processor (or, in this case, collection of processors) for which the code is optimized.
|
The documentation may not be entirely accurate
for a given compiler version as well (there may be
implemented options not noted in the documentation).
Plus an ebuild can read the host type in CHOST in /etc/make.conf
and override the CFLAGS specfied there with what the maintainers
feel is most appropriate for that application on that architecture. _________________ TIA |
|
Back to top |
|
|
|