Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
-march and -mtune for portable x86_64
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Gentoo on AMD64
View previous topic :: View next topic  
Author Message
pentium4borg
n00b
n00b


Joined: 29 Aug 2006
Posts: 44

PostPosted: Sat Feb 12, 2011 9:17 pm    Post subject: -march and -mtune for portable x86_64 Reply with quote

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
View user's profile Send private message
DONAHUE
Watchman
Watchman


Joined: 09 Dec 2006
Posts: 6415
Location: Goose Creek SC

PostPosted: Sun Feb 13, 2011 4:31 am    Post subject: Reply with quote

CFLAGS="-march=native -O2 -pipe" is popular these days
_________________
Defund the FCC.
Back to top
View user's profile Send private message
pentium4borg
n00b
n00b


Joined: 29 Aug 2006
Posts: 44

PostPosted: Sun Feb 13, 2011 4:34 am    Post subject: Reply with quote

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
View user's profile Send private message
DONAHUE
Watchman
Watchman


Joined: 09 Dec 2006
Posts: 6415
Location: Goose Creek SC

PostPosted: Sun Feb 13, 2011 4:48 am    Post subject: Reply with quote

sorry, incomplete reading
_________________
Defund the FCC.
Back to top
View user's profile Send private message
Veldrin
Veteran
Veteran


Joined: 27 Jul 2004
Posts: 1942
Location: Zurich, Switzerland

PostPosted: Sun Feb 13, 2011 10:50 am    Post subject: Reply with quote

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
View user's profile Send private message
Aquous
l33t
l33t


Joined: 08 Jan 2011
Posts: 645

PostPosted: Sun Feb 13, 2011 7:46 pm    Post subject: Reply with quote

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
View user's profile Send private message
wcg
Guru
Guru


Joined: 06 Jan 2009
Posts: 588

PostPosted: Mon Feb 21, 2011 6:11 pm    Post subject: Reply with quote

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
View user's profile Send private message
pentium4borg
n00b
n00b


Joined: 29 Aug 2006
Posts: 44

PostPosted: Mon Feb 21, 2011 6:29 pm    Post subject: Reply with quote

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
View user's profile Send private message
wcg
Guru
Guru


Joined: 06 Jan 2009
Posts: 588

PostPosted: Tue Feb 22, 2011 6:46 pm    Post subject: Reply with quote

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
View user's profile Send private message
pentium4borg
n00b
n00b


Joined: 29 Aug 2006
Posts: 44

PostPosted: Tue Feb 22, 2011 6:57 pm    Post subject: Reply with quote

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
View user's profile Send private message
XavierMiller
Moderator
Moderator


Joined: 23 Jul 2004
Posts: 5425
Location: ~Brussels - Belgique

PostPosted: Tue Feb 22, 2011 7:32 pm    Post subject: Reply with quote

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.
_________________
Xavier Miller
(FR) Merci de respecter les règles du forum.
http://www.xaviermiller.be
Back to top
View user's profile Send private message
wcg
Guru
Guru


Joined: 06 Jan 2009
Posts: 588

PostPosted: Wed Feb 23, 2011 12:44 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Gentoo on AMD64 All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum