LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   GCC options: (-m64) vs (-march=native) vs (-march=core2) -- Which one(s) to use? (https://www.linuxquestions.org/questions/linux-software-2/gcc-options-m64-vs-march%3Dnative-vs-march%3Dcore2-which-one-s-to-use-758242/)

GrapefruiTgirl 09-28-2009 10:18 AM

GCC options: (-m64) vs (-march=native) vs (-march=core2) -- Which one(s) to use?
 
Reference of compiler flags: http://gcc.gnu.org/onlinedocs/gcc/i3...4-Options.html

So, what that page doesn't quite tell me, is which if any of the compiler flags I'm using, are absolutely mutually inclusive/exclusive, except for one thing it does say:

-march=XXX implies -mtune=XXX

----------------------------------------------

My CPU is an Intel E2160 CORE2 with EM64T, and I'm running and building stuff for Slack64.

So, I'd like to know, if possible, ragarding my CPU:

1) Is -march=native identical to -march=core2? Will they produce identical code for me?

2) Does -march=[native|core2] imply -m64 or is -m64 just a generic sort of thing, for non-specific CPU's when no -march is specified?

Do I need to specify -m64 at all? Maybe my GCC + CPU will = CPU-optimized 64 bit code by default, just by specifying the -march flag??

To make selection of the best method simple, consider the following possible combinations, noting the order of the flags. Is Any particular one of these methods going to be "the best" for me?:

t) gcc -march=core2
u) gcc -march=native
v) gcc -m64
w) gcc -march=native -m64
x) gcc -march=core2 -m64
y) gcc -m64 -march=native
z) gcc -m64 -march=core2

Please help clarify/distinguish these options for me :)

Sasha

H_TeXMeX_H 09-28-2009 11:16 AM

First let me refer you to the safe cflags listing:
http://en.gentoo-wiki.com/wiki/Safe_...eron_Dual-Core

1) See:
http://en.gentoo-wiki.com/wiki/Safe_...march.3Dnative

Quote:

GCC 4.2 introduces a new -march option, -march=native, which automatically detects the features your CPU supports and sets the options appropriately. If you have an Intel or AMD CPU and are using >=sys-devel/gcc-4.2.3, using -march=native is recommended. Do not use -march=native if you use distcc on nodes with different architectures as this may produce unusable code.
So no, march=native will likely be different from march=core2. You can go ahead and use march=native and it will work just fine, or you can use the safe cflags as listed above and that should be fine too. march=native is a more automated method and will likely be the best option, for the march=core2 you will need to check to see if you can also add -msse4.1, I think march=native will autodetect this.

2) You really never need to specify -m64, unless you are compiling a 64-bit executable on a 32-bit system. And you only need to specify -m32 when you are compiling a 32-bit executable on a 64-bit system.

So no, you don't need to specify -m64, in fact even without the -march flag you still don't need it.

Probably the best thing to use is either -march=native or the safe cflags above.

GrapefruiTgirl 09-28-2009 03:57 PM

H_TeXMeX_H,

Thank you so much for pointing me towards those Gentoo Wiki pages. Ever since the Gentoo team had their crash a while back and/or a lot of their most helpful pages got lost, it's been more difficult to find them using Google OR by using their Wiki index pages.

It looks like based on those pages, exactly what I want is "-march=native" and that should do the most, with the least. According to my /proc/cpuinfo, I don't appear to have a use for -msse4_1 though.

Thanks for the perfect answer!

Sasha

H_TeXMeX_H 09-29-2009 04:28 AM

Actually the old gentoo wiki is still available here:
http://www.gentoo-wiki.info/

It still contains some things not available in the new wiki.

~sHyLoCk~ 09-29-2009 05:47 AM

AFAIK, -march=core2 is only supported from gcc4.3.2 up right? I use -march=native -mtune=native and I have the same processor as you. If you are planning to install the compiled packages to another system then try -mtune=generic

GrapefruiTgirl 09-29-2009 07:53 AM

H_TeXMeX_H, thanks again for the link to the Gentoo ARCHIVE -- I had no idea, and had never encountered that via Google. Phooey :|

Shylock -- Yes, according to the GCC changelog: http://gcc.gnu.org/gcc-4.3/changes.html the way I read it, gcc4.3.x introduced the -march=core2 flag, and gcc4.2.x introduced the -march=native flag according to this Gentoo Wiki page: http://en.gentoo-wiki.com/wiki/Safe_...march.3Dnative

I'm just building for my own system, so I'll be using "native".

Cheers :)
Sasha


All times are GMT -5. The time now is 05:08 AM.