Safe CFLAGS

From Gentoo Wiki
Jump to: navigation, search

Finding your CPU

To identify the model of your CPU, you can look inside /proc/cpuinfo for the "cpu family" and "model" numbers like so:

user $ grep -m1 -A3 "vendor_id" /proc/cpuinfo

Once you find this information, you can then match your CPU to one listed on this page in order to find out the suggested "safe" CFLAGS.

Below you can find a list of CFLAGS which are to be considered "safe" for the given processors. These are the settings you should use if you are unsure which CFLAGS your processor needs.

x86/amd64

Intel

Server CPU

Xeon E5-2407
vendor_id       : GenuineIntel
cpu family      : 6
model           : 45
model name      : Intel(R) Xeon(R) CPU E5-2407 0 @ 2.20GHz
File/etc/portage/make.conf

CHOST="x86_64-pc-linux-gnu"
CFLAGS="-march=corei7-avx -O2 -pipe"
CXXFLAGS="${CFLAGS}"
Note
corei7-avx march support was introduced only as of gcc-4.6. If you have an earlier version of GCC, use
CFLAGS="-march=native -O2 -pipe"


Xeon 3040
vendor_id       : GenuineIntel
cpu family      : 6
model           : 15
model name      : Intel(R) Xeon(R) CPU            3040  @ 1.86GHz
File/etc/portage/make.conf

CHOST="x86_64-pc-linux-gnu"
CFLAGS="-march=core2 -O2 -pipe"
CXXFLAGS="${CFLAGS}"

Desktop CPU

Core i3/i5/i7 with AVX2 instructions (Haswell)
vendor_id       : GenuineIntel
cpu family      : 6
model           : 60
model name      : Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
File/etc/portage/make.conf

CHOST="x86_64-pc-linux-gnu"
CFLAGS="-march=core-avx2 -O2 -pipe"
CXXFLAGS="${CFLAGS}"
Note
core-avx2 march support was introduced only as of gcc-4.7. If you have an earlier version of GCC, use
CFLAGS="-march=native -O2 -pipe"
Core i3/i5/i7 IvyBridge
File/etc/portage/make.conf

CHOST="x86_64-pc-linux-gnu"
CFLAGS="-march=core-avx-i -O2 -pipe"
CXXFLAGS="${CFLAGS}"
Note
core-avx-i march support was introduced only as of gcc-4.7. If you have an earlier version of GCC, use
CFLAGS="-march=native -O2 -pipe"
Core i3/i5/i7 with AVX instructions
File/etc/portage/make.conf

CHOST="x86_64-pc-linux-gnu"
CFLAGS="-march=corei7-avx -O2 -pipe"
CXXFLAGS="${CFLAGS}"
Note
corei7-avx march support was introduced only as of gcc-4.6. If you have an earlier version of GCC, use
CFLAGS="-march=native -O2 -pipe"
Core i3/i5/i7
vendor_id	: GenuineIntel
cpu family	: 6
model		: 42
model name	: Intel(R) Core(TM) i5-2400 CPU @ 3.10GHz
File/etc/portage/make.conf

CHOST="x86_64-pc-linux-gnu"
CFLAGS="-march=corei7 -O2 -pipe"
CXXFLAGS="${CFLAGS}"
Note
corei7 march support was introduced only as of gcc-4.6. If you have an earlier version of GCC, use
CFLAGS="-march=native -O2 -pipe"
Core 2 Duo
vendor_id       : GenuineIntel
cpu family      : 6
model           : 15
model name      : Intel(R) Core(TM)2 Duo CPU     T7500  @ 2.20GHz
File/etc/portage/make.conf

CHOST="x86_64-pc-linux-gnu"
CFLAGS="-march=core2 -O2 -pipe"
CXXFLAGS="${CFLAGS}"
Pentium M (Dothan)
vendor_id	: GenuineIntel
cpu family	: 6
model		: 13
model name	: Intel(R) Pentium(R) M processor 2.13GHz
File/etc/portage/make.conf

CHOST="i686-pc-linux-gnu"
CFLAGS="-O2 -march=pentium-m -pipe -fomit-frame-pointer"
CXXFLAGS="${CFLAGS}"
Note
When compiling gcc:4.6, switch to
CFLAGS="-O2 -march=i686 -pipe -fomit-frame-pointer"
on this specific package, see https://bugs.gentoo.org/show_bug.cgi?id=411333

AMD

A4/A6/A8-XXXX / XXXXM

vendor_id	: AuthenticAMD
cpu family	: 18
model		: 1
model name	: AMD A8-3500M APU with Radeon(tm) HD Graphics
File/etc/portage/make.conf

CHOST="x86_64-pc-linux-gnu"
CFLAGS="-O2 -march=amdfam10 -mcx16 -mpopcnt -pipe"
CXXFLAGS="${CFLAGS}"

FX-XXXX

vendor_id	: AuthenticAMD
cpu family	: 21
model		: 1
model name	: AMD FX(tm)-8150 Eight-Core Processor

Make sure and check the number listed by model on your system, the -march flag should be bdverX where X is the model number.

Due to the FPU design of the Bulldozer architecture, -mprefer-avx128 gives better FPU preformance at the cost of precision. The -mvzeroupper switch will give much less of a preformance penalty when using both SSE and AVX, it isn't much of a performance boost for most apps, but can provide a significant improvement when used with stuff like media-video/ffmpeg, net-misc/bfgminer or some apps in games-emulation that have some sections coded in assembly.

File/etc/portage/make.conf

CHOST="x86_64-pc-linux-gnu"
CFLAGS="-O2 -march=bdver1 -mprefer-avx128 -mvzeroupper -pipe"
CXXFLAGS="${CFLAGS}"

Geode LX

vendor_id	: AuthenticAMD
cpu family	: 5
model		: 10
model name	: Geode(TM) Integrated Processor by AMD PCS
File/etc/portage/make.conf

CHOST=i486-pc-linux-gnu
CFLAGS="-Os -pipe -march=geode -mmmx -m3dnow -fno-align-jumps -fno-align-functions -fno-align-labels -fno-align-loops -fomit-frame-pointer"
CXXFLAGS="${CFLAGS}"

arm

Cortex-A

ARMv7-A/Cortex-A9 MPCore

with optional VFPv3 FPU
Processor       : ARMv7 Processor rev 0 (v7l)
processor       : 0
BogoMIPS        : 1987.37

processor       : 1
BogoMIPS        : 1987.37

Features        : swp half thumb fastmult vfp edsp thumbee vfpv3 vfpv3d16 tls 
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x1
CPU part        : 0xc09
CPU revision    : 0

Hardware        : Toshiba AC100 / Dynabook AZ
Revision        : 0000
Serial          : 0000000000000000
File/etc/portage/make.conf

CHOST="armv7a-hardfloat-linux-gnueabi"
CFLAGS="-O2 -march=armv7-a -mtune=cortex-a9 -mfpu=vfpv3-d16 -mfloat-abi=hard -pipe -fomit-frame-pointer"
CXXFLAGS="${CFLAGS}"

ARM11

ARMv6/ARM1176JZF-S

ARMv6/ARM1136JF-S

Processor       : ARMv6-compatible processor rev 5 (v6l)
BogoMIPS        : 791.34
Features        : swp half thumb fastmult vfp edsp java 
CPU implementer : 0x41
CPU architecture: 6TEJ
CPU variant     : 0x1
CPU part        : 0xb36
CPU revision    : 5

Hardware        : IMAPX200
Revision        : 0000
Serial          : 0000000000000000
File/etc/portage/make.conf

CHOST="armv6j-hardfloat-linux-gnueabi"
CFLAGS="-Os -march=armv6j -mcpu=arm1136jf-s -mfpu=vfp -mfloat-abi=hard -pipe -fomit-frame-pointer"
CXXFLAGS="${CFLAGS}"

ppc/ppc64

Cell

File/etc/portage/make.conf

CHOST="powerpc-unknown-linux-gnu"
CFLAGS="-mcpu=cell -O2 -pipe -mabi=altivec -maltivec"
CXXFLAGS="${CFLAGS}"
Note
One GCC toolchain can't support PPU and SPU simultaneously, so it's best to let the PPU toolchain rely on AltiVec.
This CPU type is used in the PS3.

G3 (PPC 7XX)

processor       : 0
cpu             : 740/750
clock           : 400.000000MHz
revision        : 131.0 (pvr 0008 8300)
bogomips        : 49.93
timebase        : 24966218
platform        : PowerMac
model           : PowerBook3,1
machine         : PowerBook3,1
motherboard     : PowerBook3,1 MacRISC2 MacRISC Power Macintosh
detected as     : 70 (PowerBook Pismo)
pmac flags      : 0000001f
L2 cache        : 1024K unified
pmac-generation : NewWorld
File/etc/portage/make.conf

CHOST="powerpc-unknown-linux-gnu"
CFLAGS="-mcpu=750 -Os -pipe -fno-strict-aliasing"
CXXFLAGS="${CFLAGS}"

m68k

Not in the List

Try the following command to see if you will see something useful.
You will get something like below...
Notice the -march reply?
Get this info from Distcc Wiki Page[1]


root # gcc -march=native -E -v - </dev/null 2>&1 | grep cc1
 /mnt/livecd/usr/x86_64-pc-linux-gnu/gcc-bin/4.7.3/../../../libexec/gcc/x86_64-pc-linux-gnu/4.7.3/cc1 -E -quiet -v -iprefix /mnt/livecd/usr/x86_64-pc-linux-gnu/gcc-bin/4.7.3/../../../lib/gcc/x86_64-pc-linux-gnu/4.7.3/ - 
-march=corei7-avx -mcx16 -msahf -mno-movbe -maes -mpclmul -mpopcnt -mno-abm -mno-lwp -mno-fma -mno-fma4 -mno-xop -mno-bmi -mno-bmi2 -mno-tbm -mavx -mno-avx2 -msse4.2 -msse4.1 -mno-lzcnt -mno-rdrnd -mno-f16c -mno-fsgsbase --param l1-cache-size=32 --param l1-cache-line-size=64 --param l2-cache-size=10240 -mtune=corei7-avx

External Resources

  1. Distcc, Distcc