View previous topic :: View next topic |
Author |
Message |
FizzyWidget Veteran
Joined: 21 Nov 2008 Posts: 1133 Location: 127.0.0.1
|
Posted: Fri Oct 29, 2010 9:15 am Post subject: Cflags -march=native or -march=core2 ? |
|
|
While looking at the wiki for cflags i notice in the big red box at the top of the page it says
Quote: | Warning: GCC 4.2 and above support -march=native, which automatically detects the optimum settings to use based on your processor. -march=native also detects and applies additional settings beyond -march specific to your CPU, (eg. -msse4). Unless you have a specific reason not to (e.g. distcc cross-compiling), you should probably be using -march=native rather than anything listed below. |
Yet if i click the link for my CPU it states to use
Quote: | CFLAGS="-march=core2 -O2 -pipe"
CXXFLAGS="${CFLAGS}" |
which should i use? will -march=native use the -core2 switch or should i just go ahead and use the -core2 switch?
I dont wish to use the incorrect one, if either could be called that, as i'm installing onto a new disk and it would me recompiling a lot of packages if i need to swap, could do it overnight i know but its still a PITA either way _________________ I know 43 ways to kill with a SKITTLE, so taste my rainbow bitch. |
|
Back to top |
|
|
mv Watchman
Joined: 20 Apr 2005 Posts: 6747
|
Posted: Fri Oct 29, 2010 9:37 am Post subject: |
|
|
If >=gcc-4.2 is your active compiler and you compile only on your machine for your machine (not using distcc or building packages for other machines), it is preferrable to use -march=native. |
|
Back to top |
|
|
phajdan.jr Retired Dev
Joined: 23 Mar 2006 Posts: 1777 Location: Poland
|
Posted: Fri Oct 29, 2010 9:38 am Post subject: |
|
|
I think -march=native is a safe choice. Also, CFLAGS are not as important as many people think. _________________ http://phajdan-jr.blogspot.com/ |
|
Back to top |
|
|
FizzyWidget Veteran
Joined: 21 Nov 2008 Posts: 1133 Location: 127.0.0.1
|
Posted: Fri Oct 29, 2010 9:46 am Post subject: |
|
|
Thanks, i decided to take a chance and select native rebuilding world now as im using ~amd64 _________________ I know 43 ways to kill with a SKITTLE, so taste my rainbow bitch. |
|
Back to top |
|
|
d2_racing Bodhisattva
Joined: 25 Apr 2005 Posts: 13047 Location: Ste-Foy,Canada
|
Posted: Fri Oct 29, 2010 12:29 pm Post subject: |
|
|
I use this config for a long time :
Code: |
CFLAGS="-march=native -O2 -pipe"
CXXFLAGS="${CFLAGS}"
|
|
|
Back to top |
|
|
depontius Advocate
Joined: 05 May 2004 Posts: 3509
|
Posted: Fri Oct 29, 2010 1:46 pm Post subject: |
|
|
mv wrote: | If >=gcc-4.2 is your active compiler and you compile only on your machine for your machine (not using distcc or building packages for other machines), it is preferrable to use -march=native. |
My impression was that "-march=native" really only worked if gcc was newer than your CPU. I just got a core-i7-based Thinkpad, and was told to use "-march=core2 -mtune=generic" for it. Of course we just got a new gcc the other day, so I'll have to check if it's time for "-march=native" again. _________________ .sigs waste space and bandwidth |
|
Back to top |
|
|
krinn Watchman
Joined: 02 May 2003 Posts: 7470
|
Posted: Fri Oct 29, 2010 1:59 pm Post subject: |
|
|
it's in fact the contrary, as march=native guess your cpu, if your gcc is older than your cpu, it should be smarter to let gcc detect for you what cpu is compatible and having it picking up the right set for you.
for your core-i7 example, if your gcc support march=native but not march=core2 you'll get more benefits because march=native will pickup a compatible and close cpu to yours.
It's better than let the user pickup one that might be less accurate (ie: the wiki stupid nocona/prescott case for core2)
if your gcc support your cpu, march=native and march=yourcpu are just equivalent. That's why i think march=native strengh will be come up when your gcc is older than your cpu |
|
Back to top |
|
|
Etal Veteran
Joined: 15 Jul 2005 Posts: 1931
|
Posted: Fri Oct 29, 2010 4:13 pm Post subject: |
|
|
krinn wrote: | It's better than let the user pickup one that might be less accurate (ie: the wiki stupid nocona/prescott case for core2) |
Back when it was written, niether "-march=core2" nor "-march=native" existed, so nocona/prescott was in fact the best option |
|
Back to top |
|
|
krinn Watchman
Joined: 02 May 2003 Posts: 7470
|
Posted: Fri Oct 29, 2010 4:20 pm Post subject: |
|
|
it's not about native or core2 presence.
It's about picking nocona because 64bits and prescott when 32bits.
It was dumb, it is dumb, it's still dumb
So, no, it wasn't the best option, even it was harmless. |
|
Back to top |
|
|
depontius Advocate
Joined: 05 May 2004 Posts: 3509
|
Posted: Fri Oct 29, 2010 4:44 pm Post subject: |
|
|
Back when I first got the Core-I7 machine, the "Gentoo safe CFLAGS" page recommended what I used over native. I can see how gcc could attempt some heuristics to guess how to optimize for an unknown CPU, but I'm betting that they don't do that. I'd guess that they just do a table-lookup based on CPUID - for a resource-constrained effort I wouldn't put a lot more into this part of it. _________________ .sigs waste space and bandwidth |
|
Back to top |
|
|
Etal Veteran
Joined: 15 Jul 2005 Posts: 1931
|
Posted: Fri Oct 29, 2010 6:00 pm Post subject: |
|
|
depontius wrote: | Back when I first got the Core-I7 machine, the "Gentoo safe CFLAGS" page recommended what I used over native. I can see how gcc could attempt some heuristics to guess how to optimize for an unknown CPU, but I'm betting that they don't do that. I'd guess that they just do a table-lookup based on CPUID - for a resource-constrained effort I wouldn't put a lot more into this part of it. |
Considering that the difference between flags set by "-march=core2" and "-march=native" on a Core2 machine is a pair of flags that identify the processor cache sizes, I'm pretty sure you're wrong. If it can get the cache sizes, it could just as well check which other features it supports (sse, 3dnow, etc.), which is probably what it does. |
|
Back to top |
|
|
depontius Advocate
Joined: 05 May 2004 Posts: 3509
|
Posted: Mon Nov 01, 2010 12:17 pm Post subject: |
|
|
From http://en.gentoo-wiki.com/wiki/Safe_Cflags/Intel#Core_i7_and_Core_i5.2C_Xeon_55xx
Code: | Core i7 and Core i5, Xeon 55xx
vendor_id : GenuineIntel
cpu family : 6
model : 26
model name : Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz
vendor_id : GenuineIntel
cpu family : 6
model : 37
model name : Intel(R) Core(TM) i5 CPU 650 @ 3.20GHz / 660 @ 3.33 GHz
vendor_id : GenuineIntel
cpu family : 6
model : 26
model name : Intel(R) Xeon(R) CPU X5570 @ 2.93GHz
32 bit profile (x86)
CHOST="i686-pc-linux-gnu"
CFLAGS="-march=prescott -O2 -fomit-frame-pointer -pipe"
CXXFLAGS="${CFLAGS}"
64 bit profile (amd64) for < GCC 4.3
CHOST="x86_64-pc-linux-gnu"
CFLAGS="-march=nocona -O2 -pipe"
CXXFLAGS="${CFLAGS}"
64 bit profile (amd64) for >= GCC 4.3
CHOST="x86_64-pc-linux-gnu"
CFLAGS="-march=core2 -mtune=generic -O2 -pipe"
CXXFLAGS="${CFLAGS}" |
_________________ .sigs waste space and bandwidth |
|
Back to top |
|
|
Etal Veteran
Joined: 15 Jul 2005 Posts: 1931
|
Posted: Mon Nov 01, 2010 7:08 pm Post subject: |
|
|
Not sure what you're getting at... |
|
Back to top |
|
|
depontius Advocate
Joined: 05 May 2004 Posts: 3509
|
Posted: Mon Nov 01, 2010 7:27 pm Post subject: |
|
|
I had been reporting what I saw on the Gentoo safe CFLAGS page, yet people here disagree. I figured I'd give a direct quote. _________________ .sigs waste space and bandwidth |
|
Back to top |
|
|
krinn Watchman
Joined: 02 May 2003 Posts: 7470
|
Posted: Tue Nov 02, 2010 11:29 am Post subject: |
|
|
Code: | Core i7 and Core i5, Xeon 55xx
32 bit profile (x86)
CHOST="i686-pc-linux-gnu"
CFLAGS="-march=nocona -O2 -fomit-frame-pointer -pipe"
CXXFLAGS="${CFLAGS}"
64 bit profile (amd64) for < GCC 4.3
CHOST="x86_64-pc-linux-gnu"
CFLAGS="-march=nocona -O2 -pipe"
CXXFLAGS="${CFLAGS}"
|
Here's how it should have been set.
And thinking that nocona is for 64bits (because of 64bits instructions) is as dumb as thinking core2 is also for 64bits.
And there's a 2nd error :
-march=core2 -mtune=generic is a dumb optimization that will slow down your code |
|
Back to top |
|
|
depontius Advocate
Joined: 05 May 2004 Posts: 3509
|
Posted: Tue Nov 02, 2010 6:43 pm Post subject: |
|
|
Then I suggest you update the "safe CFLAGS" people, and get the web page changed. _________________ .sigs waste space and bandwidth |
|
Back to top |
|
|
jathlon Tux's lil' helper
Joined: 26 Sep 2006 Posts: 89 Location: Canada
|
Posted: Tue Nov 02, 2010 7:18 pm Post subject: |
|
|
I knew I seen it somewhere on these forums. Check this thread;
https://forums.gentoo.org/viewtopic-t-602834.html
for the magic formula. The relevant section of the test on my phenom x6 I get;
Code: |
echo 'int main(){return 0;}' > test.c && gcc -v -Q -march=native -O2 test.c -o test && rm test.c test
COLLECT_GCC_OPTIONS='-v' '-Q' '-O2' '-o' 'test'
/usr/libexec/gcc/x86_64-pc-linux-gnu/4.4.5/cc1 -v test.c -D_FORTIFY_SOURCE=2 -march=amdfam10 -mcx16 -msahf -mpopcnt --param l1-cache-size=64 --param l1-cache-line-size=64 --param l2-cache-size=512 -mtune=amdfam10 -dumpbase test.c -auxbase test -O2 -version -o |
If I use "-march-amdfam10 -O2 -pipe" I get;
Code: |
echo 'int main(){return 0;}' > test.c && gcc -v -Q -march=amdfam10 -O2 test.c -o test && rm test.c test
COLLECT_GCC_OPTIONS='-v' '-Q' '-march=amdfam10' '-O2' '-o' 'test'
/usr/libexec/gcc/x86_64-pc-linux-gnu/4.4.5/cc1 -v test.c -D_FORTIFY_SOURCE=2 -dumpbase test.c -march=amdfam10 -auxbase test -O2 -version -o /home/joededman/tmp/ccpiJBe9.s |
I don't know that all the extra options you get from gcc by selecting "native" actually produces better binaries, but it saves me from adding more entries to me CFLAGS in /etc/make.conf
Later,
joe |
|
Back to top |
|
|
Anon-E-moose Watchman
Joined: 23 May 2008 Posts: 6097 Location: Dallas area
|
Posted: Tue Nov 02, 2010 7:21 pm Post subject: |
|
|
This Code: | gcc -march=native -E -v - </dev/null 2>&1 | sed -n 's/.* -v - //p' | will show what flags will be applied with native
On my system I get
Code: | -D_FORTIFY_SOURCE=2 -march=amdfam10 -mcx16 -msahf -mpopcnt --param l1-cache-size=64 --param l1-cache-line-size=64 --param l2-cache-size=512 -mtune=amdfam10 |
_________________ PRIME x570-pro, 3700x, 6.1 zen kernel
gcc 13, profile 17.0 (custom bare multilib), openrc, wayland |
|
Back to top |
|
|
jathlon Tux's lil' helper
Joined: 26 Sep 2006 Posts: 89 Location: Canada
|
Posted: Tue Nov 02, 2010 7:32 pm Post subject: |
|
|
Ahh, there we go. The simplified version. And so by extension;
Code: |
~ $ gcc -march=amdfam10 -E -v - </dev/null 2>&1 | sed -n 's/.* -v - //p'
-D_FORTIFY_SOURCE=2 -march=amdfam10 |
Thanks, Anon-E-moose
joe |
|
Back to top |
|
|
depontius Advocate
Joined: 05 May 2004 Posts: 3509
|
Posted: Wed Nov 03, 2010 2:00 pm Post subject: |
|
|
For Core I7 : http://gcc.gnu.org/ml/gcc-patches/2010-10/msg01670.html
Code: |
PATCH: Update -march=native for Cora e2 and Core i7
* From: "H.J. Lu" <hongjiu dot lu at intel dot com>
* To: gcc-patches at gcc dot gnu dot org
* Cc: Richard Henderson <rth at redhat dot com>, Uros Bizjak <ubizjak at gmail dot com>
* Date: Tue, 19 Oct 2010 13:23:13 -0700
* Subject: PATCH: Update -march=native for Cora e2 and Core i7
* Reply-to: "H.J. Lu" <hjl dot tools at gmail dot com>
After this patch:
http://gcc.gnu.org/ml/gcc-patches/2010-10/msg01616.html
is checked in, we can use core2/corei7 for -march=native on Core 2 and
Core i7. OK for trunk?
Thanks.
H.J.
---
2010-10-19 H.J. Lu <hongjiu.lu@intel.com>
* config/i386/driver-i386.c (host_detect_local_cpu): Updated
for Core 2 and Core i7.
diff --git a/gcc/config/i386/driver-i386.c b/gcc/config/i386/driver-i386.c
index 8a76857..998214b 100644
--- a/gcc/config/i386/driver-i386.c
+++ b/gcc/config/i386/driver-i386.c
@@ -554,21 +554,21 @@ const char *host_detect_local_cpu (int argc, const char **argv)
case 0x1e:
case 0x1f:
case 0x2e:
- /* FIXME: Optimize for Nehalem. */
- cpu = "core2";
+ /* Nehalem. */
+ cpu = "corei7";
break;
case 0x25:
case 0x2f:
- /* FIXME: Optimize for Westmere. */
- cpu = "core2";
+ /* Westmere. */
+ cpu = "corei7";
break;
case 0x17:
case 0x1d:
- /* Penryn. FIXME: -mtune=core2 is slower than -mtune=generic */
+ /* Penryn. */
cpu = "core2";
break;
case 0x0f:
- /* Merom. FIXME: -mtune=core2 is slower than -mtune=generic */
+ /* Merom. */
cpu = "core2";
break;
default: |
_________________ .sigs waste space and bandwidth |
|
Back to top |
|
|
|