You are not logged in.

#1 2008-06-03 13:45:47

vsk
Member
Registered: 2008-05-27
Posts: 70

(Not-So-Safe) CFlags Discussion ;)

Hey guys,
I checked out our wiki about makepkg and Gentoo's wiki on safe CFlags.
In both places, I noticed comments like this (paraphrased):
* Most of these flags will cause absolutely no human-perceptible differences!
* This wiki is for 100% safe, tested stuff ONLY, don't post your (awesome) untested options!

Well, I think this very unofficial thread would be a nice place to share said flags. If you do anything special that seems to work, or totally borks crap, I'd like to see it.

Oh, and can anyone confirm this;

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.0, 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.

-- Gentoo Wiki

Offline

#2 2008-06-03 14:19:55

Mr.Elendig
#archlinux@freenode channel op
From: The intertubes
Registered: 2004-11-07
Posts: 4,092

Re: (Not-So-Safe) CFlags Discussion ;)

-march=generic/native do work fine, I used it until gcc 4.3 that added march=core2

Anyway:

CARCH="i686"
CHOST="i686-pc-linux-gnu"
MAKEFLAGS="-j3"

CFLAGS="-march=core2 -mfpmath=sse -O2 -pipe -fomit-frame-pointer"
#CFLAGS="-march=core2 -mfpmath=sse -O3 -pipe -fomit-frame-pointer -funroll-loops"
CXXFLAGS="$CFLAGS"

## hardware ##
E6550
2gb ddr2

The quoted line is what I use on "special" occasions, like e.g. for firefox3

Explanation:
-march=core2            :  speaks for itself
-mfpmath=sse           :  on i686 this is set to 387 by default. sse is faster if you got it
-O2 / -O3                   :  optimize level. -O3 is in most cases the same or slower than -O3. aka  not worth it. But it do help on some code.
-pipe                          :  gcc uses pipes while compiling. Shorter compile time, but may cause build errors on rare ocasions
-fomit-frame-pointer  :  This is set in O2/3 by default on systems where it do not hamper debugging. Afaik, it's not set on x86
-funroll-loops             :  Tries to predict the outcome of a loop and "unroll" it. Generaly a bad idea, but works nicly for some apps like ff3

Last edited by Mr.Elendig (2008-06-03 14:25:54)


Evil #archlinux@libera.chat channel op and general support dude.
. files on github, Screenshots, Random pics and the rest

Offline

#3 2008-06-03 17:27:26

schivmeister
Developer/TU
From: Singapore
Registered: 2007-05-17
Posts: 971
Website

Re: (Not-So-Safe) CFlags Discussion ;)

Core Duo 1.6GHz
2GB RAM

CFLAGS="-march=native -O2 -pipe"
#LDFLAGS="-Wl,-O1 -Wl,--as-needed -Wl,--enable-new-dtags -Wl,--sort-common -s"
MAKEFLAGS="-j3"

I used to have a slightly-less-than-sane setup when I was doing pentium-m as the arch, but I've lost that make.conf lol

Doesn't core2 already provide for -mfpmath-sse? Haven't looked at the updated GCC docs yet. I would also think native does a better job at combining sane optimisations. I recommend against pipe for < 256MB RAM, < 512MB is a little strict.


I need real, proper pen and paper for this.

Offline

#4 2008-06-04 07:07:49

iphitus
Forum Fellow
From: Melbourne, Australia
Registered: 2004-10-09
Posts: 4,927

Re: (Not-So-Safe) CFlags Discussion ;)

pfft. time spent discussing cflags and compiling >>>> time gained by using said cflags

Offline

#5 2008-06-04 09:04:04

JGC
Developer
Registered: 2003-12-03
Posts: 1,664

Re: (Not-So-Safe) CFlags Discussion ;)

Depends on usage. On regular desktop systems, the optimization does not compensate the time required to optimize. Your desktop application is waiting on you most of the time. On a server system where optimizing your master MySQL server can increase performance by 20% compared to what your distro ships, the optimization is worth the compile time.
Some exceptions do exist though: some multimedia applications like ffmpeg can make extensive use of features in your CPU. Recompiling these programs can increase performance a lot due to usage of SSE and friends.

Offline

#6 2008-06-04 15:58:36

Cimi
Member
From: Padova, Italy
Registered: 2006-01-16
Posts: 301
Website

Re: (Not-So-Safe) CFlags Discussion ;)

Mr.Elendig wrote:

-march=generic/native do work fine, I used it until gcc 4.3 that added march=core2

Anyway:

CARCH="i686"
CHOST="i686-pc-linux-gnu"
MAKEFLAGS="-j3"

CFLAGS="-march=core2 -mfpmath=sse -O2 -pipe -fomit-frame-pointer"
#CFLAGS="-march=core2 -mfpmath=sse -O3 -pipe -fomit-frame-pointer -funroll-loops"
CXXFLAGS="$CFLAGS"

## hardware ##
E6550
2gb ddr2

The quoted line is what I use on "special" occasions, like e.g. for firefox3

Explanation:
-march=core2            :  speaks for itself
-mfpmath=sse           :  on i686 this is set to 387 by default. sse is faster if you got it
-O2 / -O3                   :  optimize level. -O3 is in most cases the same or slower than -O3. aka  not worth it. But it do help on some code.
-pipe                          :  gcc uses pipes while compiling. Shorter compile time, but may cause build errors on rare ocasions
-fomit-frame-pointer  :  This is set in O2/3 by default on systems where it do not hamper debugging. Afaik, it's not set on x86
-funroll-loops             :  Tries to predict the outcome of a loop and "unroll" it. Generaly a bad idea, but works nicly for some apps like ff3

http://gentoo-wiki.com/Safe_Cflags

The flag -mfpmath=sse however is not enabled by -march but it usually makes binaries slower due to limitations in the glibc headers. So it's better to not use this flag, even if you have an SSE capable CPU. Also -mfpmath=sse,387 is experimental and unstable.

Last edited by Cimi (2008-06-04 15:59:02)


Murrine Creator - GNOME Developer

Offline

#7 2008-06-04 17:10:03

dunc
Member
From: Glasgow, UK
Registered: 2007-06-18
Posts: 559

Re: (Not-So-Safe) CFlags Discussion ;)

JGC wrote:

Depends on usage. On regular desktop systems, the optimization does not compensate the time required to optimize. Your desktop application is waiting on you most of the time. On a server system where optimizing your master MySQL server can increase performance by 20% compared to what your distro ships, the optimization is worth the compile time.

It depends when you need the time. Take the threads about decreasing boot time as an example. In that instance, you're spending time when you can spare it to save time when you can't: you're in a hurry to get your machine started. Even on a desktop system, if you can make it more responsive by speeding things up it might be worth spending some spare time.

On the other hand, I agree that tweaking CFlags usually isn't worth the hassle, since it doesn't really make enough difference to be noticeable. But in theory... wink


0 Ok, 0:1

Offline

#8 2008-06-04 17:20:16

JeremyTheWicked
Member
From: Poland
Registered: 2008-05-23
Posts: 193

Re: (Not-So-Safe) CFlags Discussion ;)

I got a question. Everybody's ranting about how CFLAGS do/don't make a difference. Has anybody here run (or seen) actual benchmarks that support either view?


arch(3) adj amused because you think you understand something better than other people ;P

Offline

#9 2008-06-04 17:39:05

schivmeister
Developer/TU
From: Singapore
Registered: 2007-05-17
Posts: 971
Website

Re: (Not-So-Safe) CFlags Discussion ;)

Heh, it's sort of a peace-of-mind thing. If there were benchmarks proving these had benefits, then there'd be more Gentoo (or x source-based distro) users bragging about their systems. But the fact is, they can't big_smile


I need real, proper pen and paper for this.

Offline

#10 2008-06-04 18:44:40

Mr.Elendig
#archlinux@freenode channel op
From: The intertubes
Registered: 2004-11-07
Posts: 4,092

Re: (Not-So-Safe) CFlags Discussion ;)

Not realy a benchmark, but:

[oh@Alice][~/test/a]%g++ test.cpp -o test
[oh@Alice][~/test/a]%time ./test 
Sun Jun  1 23:46:43 CEST 2008
155117520
Sun Jun  1 23:46:48 CEST 2008
./test  5.23s user 0.01s system 98% cpu 5.341 total
[oh@Alice][~/test/a]%g++ -march=core2 -mfpmath=sse -O2 -pipe -fomit-frame-pointer test.cpp -o test2 
[oh@Alice][~/test/a]%time ./test2 
Sun Jun  1 23:48:30 CEST 2008
155117520
Sun Jun  1 23:48:34 CEST 2008
./test2  3.75s user 0.00s system 99% cpu 3.786 total

The source:

#include <iostream>
#include <cstdlib>
using namespace std;

const unsigned char SIZE = 15;
unsigned long long result;

void count(unsigned char i, unsigned char j)
{
    if(!i && !j) {
        ++result;
        return;
    }
    
    if(i) {
        count(i - 1, j);
    }
    if(j) {
        count(i, j - 1);
    }
}
 
int main()
{
    system("date");
    result = 0;
    count(SIZE, SIZE);
    cout << result << endl;
    system("date");
    return 0;
}

Evil #archlinux@libera.chat channel op and general support dude.
. files on github, Screenshots, Random pics and the rest

Offline

#11 2008-06-04 21:05:54

Gullible Jones
Member
Registered: 2004-12-29
Posts: 4,863

Re: (Not-So-Safe) CFlags Discussion ;)

I used Gentoo for a while. What I chiefly noticed was that, once you get past -march=i686, -march stuff doesn't make a big difference; and -O3 actually slows a system down noticably. -fomit-frame-pointer was basically the only thing that reliably made stuff faster, and it breaks debugging on x86.

Offline

#12 2008-06-05 15:57:07

X/ax
Member
From: Oost vlaanderen, Belgium
Registered: 2008-01-13
Posts: 275
Website

Re: (Not-So-Safe) CFlags Discussion ;)

Related to building firefox3: Has anyone built it yet (I changed the pkgbuild from rc1 to rc2, but build failed)


My coding blog (or an attempt at it)
Archer start page (or an attempt at it)

Offline

#13 2008-06-05 16:12:00

_Marco_
Member
Registered: 2008-04-21
Posts: 242

Re: (Not-So-Safe) CFlags Discussion ;)

yes, I built it this morning...
I used the PKGBUILD of spookyet with some little modifications
http://aur.archlinux.org/packages.php?ID=15184
(thanks spookyet)
everything worked well, if it still fail tell us the error..
bye

Offline

#14 2008-06-05 16:56:07

GGLucas
Member
Registered: 2008-03-13
Posts: 113

Re: (Not-So-Safe) CFlags Discussion ;)

Mr.Elendig wrote:

Not realy a benchmark, but:

[oh@Alice][~/test/a]%g++ test.cpp -o test
[oh@Alice][~/test/a]%time ./test 
Sun Jun  1 23:46:43 CEST 2008
155117520
Sun Jun  1 23:46:48 CEST 2008
./test  5.23s user 0.01s system 98% cpu 5.341 total
[oh@Alice][~/test/a]%g++ -march=core2 -mfpmath=sse -O2 -pipe -fomit-frame-pointer test.cpp -o test2 
[oh@Alice][~/test/a]%time ./test2 
Sun Jun  1 23:48:30 CEST 2008
155117520
Sun Jun  1 23:48:34 CEST 2008
./test2  3.75s user 0.00s system 99% cpu 3.786 total

The source:

#include <iostream>
#include <cstdlib>
using namespace std;

const unsigned char SIZE = 15;
unsigned long long result;

void count(unsigned char i, unsigned char j)
{
    if(!i && !j) {
        ++result;
        return;
    }
    
    if(i) {
        count(i - 1, j);
    }
    if(j) {
        count(i, j - 1);
    }
}
 
int main()
{
    system("date");
    result = 0;
    count(SIZE, SIZE);
    cout << result << endl;
    system("date");
    return 0;
}

I take it this code isn't reliable for testing options aside from the obvious gains ?
Using -O3 instead of -O2 for this one sped it up by over 25% (from 4.0s to 2.7s), I'm betting this isn't the case with regular applications ?

Edit: After some testing it seems the speed gain is caused by -finline-functions specifically, which seems logical.

Last edited by GGLucas (2022-06-24 08:11:45)

Offline

#15 2008-06-05 17:24:55

X/ax
Member
From: Oost vlaanderen, Belgium
Registered: 2008-01-13
Posts: 275
Website

Re: (Not-So-Safe) CFlags Discussion ;)

_Marco_ wrote:

yes, I built it this morning...
I used the PKGBUILD of spookyet with some little modifications
http://aur.archlinux.org/packages.php?ID=15184
(thanks spookyet)
everything worked well, if it still fail tell us the error..
bye

Currently trying with those files, thanks for the post smile

// As for the topic: I'm currently only using march=core2
I'm not really experienced with the flags, so I try to keep things on a level I can understand, or find myself in...


My coding blog (or an attempt at it)
Archer start page (or an attempt at it)

Offline

#16 2008-06-05 21:18:13

_Marco_
Member
Registered: 2008-04-21
Posts: 242

Re: (Not-So-Safe) CFlags Discussion ;)

hi, I have modified my /etc/makepkg.conf as follow:

CHOST="i686-pc-linux-gnu"
CFLAGS="-march=prescott -O2 -pipe -fomit-frame-pointer"
CXXFLAGS="-march=prescott -O2 -pipe -fomit-frame-pointer"

(I have a Genuine Intel(R) CPU T2300 @ 1.66GHz)

are they "automatically" used when I compile a program with "configure - make"/"PKGBUILD - makepkg" or do I have to do something manually?
(I checked the arch and gentoo wiki for CFLAG but I didn't find an answer)
thanks smile

Offline

#17 2008-06-05 21:30:29

droog
Member
Registered: 2004-11-18
Posts: 877

Re: (Not-So-Safe) CFlags Discussion ;)

yes they are automatically used when you use makepkg, not if you manually ./configure && make

Offline

#18 2008-06-05 21:33:04

_Marco_
Member
Registered: 2008-04-21
Posts: 242

Re: (Not-So-Safe) CFlags Discussion ;)

what should I do in that case?

Offline

#19 2008-06-05 21:44:21

Mr.Elendig
#archlinux@freenode channel op
From: The intertubes
Registered: 2004-11-07
Posts: 4,092

Re: (Not-So-Safe) CFlags Discussion ;)

As a general rule you shoudn't do ./configure && make && make install at all. You should always use makepkg, to avoid the chance of messing up your system.

If you want to do it anyway, you can export the cflags before you run make.


Evil #archlinux@libera.chat channel op and general support dude.
. files on github, Screenshots, Random pics and the rest

Offline

#20 2008-06-05 21:46:11

droog
Member
Registered: 2004-11-18
Posts: 877

Re: (Not-So-Safe) CFlags Discussion ;)

if you dont use makepkg you could put in your ~/.bashrc

export CFLAGS='-march=prescott -O2 -pipe -fomit-frame-pointer'
alias gcc='gcc $CFLAGS'

but not really any need to because makepkg should be used for making packages.

Offline

#21 2008-06-05 22:53:09

Redroar
Member
Registered: 2008-03-17
Posts: 200

Re: (Not-So-Safe) CFlags Discussion ;)

I was under the impression that if you created /etc/make.conf that would handle the non-makepkg compilations. Or am I horribly wrong?


Stop looking at my signature. It betrays your nature.

Offline

#22 2008-06-05 23:14:59

LTSmash
Member
From: Aguascalientes - Mexico
Registered: 2008-01-02
Posts: 348
Website

Re: (Not-So-Safe) CFlags Discussion ;)

I created that wiki page xD... but it's not really much the same (well completly different now xD)


Proud Ex-Arch user.
Still an ArchLinux lover though.

Currently on Kubuntu 9.10

Offline

#23 2008-06-05 23:25:43

Misfit138
Misfit Emeritus
From: USA
Registered: 2006-11-27
Posts: 4,189

Re: (Not-So-Safe) CFlags Discussion ;)

Redroar wrote:

I was under the impression that if you created /etc/make.conf that would handle the non-makepkg compilations. Or am I horribly wrong?

Hmm. The point is, instead of using make install, use ABS and makepkg. That way, pacman is aware of all installed files and can manipulate, upgrade, install, remove, etc.
Otherwise, It's up to the user to manage and track all manually installed software...which can quickly become overwhelming to a human being. wink

Offline

#24 2008-06-06 00:28:09

Redroar
Member
Registered: 2008-03-17
Posts: 200

Re: (Not-So-Safe) CFlags Discussion ;)

Misfit138 wrote:

Hmm. The point is, instead of using make install, use ABS and makepkg. That way, pacman is aware of all installed files and can manipulate, upgrade, install, remove, etc.
Otherwise, It's up to the user to manage and track all manually installed software...which can quickly become overwhelming to a human being. wink

I agree wholeheartedly. I just seem to remember the standard file that gcc sources to is /etc/make.conf. Or at least it is on Gentoo, FreeBSD, and a couple others. I didn't want to make a definitive statement since I've never used it on Arch, I've always used makepkg.


Stop looking at my signature. It betrays your nature.

Offline

#25 2008-06-06 00:53:11

Misfit138
Misfit Emeritus
From: USA
Registered: 2006-11-27
Posts: 4,189

Re: (Not-So-Safe) CFlags Discussion ;)

Redroar wrote:
Misfit138 wrote:

Hmm. The point is, instead of using make install, use ABS and makepkg. That way, pacman is aware of all installed files and can manipulate, upgrade, install, remove, etc.
Otherwise, It's up to the user to manage and track all manually installed software...which can quickly become overwhelming to a human being. wink

I agree wholeheartedly. I just seem to remember the standard file that gcc sources to is /etc/make.conf. Or at least it is on Gentoo, FreeBSD, and a couple others. I didn't want to make a definitive statement since I've never used it on Arch, I've always used makepkg.

Ah, I see your point now, sorry. I have heard conflicting information on this. A dev once told me that makepkg.conf is for makepkg only- not make. He recommended to export the environment variables from rc.conf. Someone else said make an alias for make in .bashrc, which passes the cflags, and I think I read in the wiki that make sources makepkg.conf. I hope a dev can set us all straight on this.
Here's the wiki page which states that makepkg.conf passes variables for make, gcc and makepkg: http://wiki.archlinux.org/index.php/Makepkg.conf
I don't know if it is true.

Offline

Board footer

Powered by FluxBB