Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
CFlags This Guy Left = WTF?
View unanswered posts
View posts from last 24 hours

Goto page Previous  1, 2  
Reply to topic    Gentoo Forums Forum Index Gentoo Chat
View previous topic :: View next topic  
Author Message
.yankee
Apprentice
Apprentice


Joined: 24 Feb 2008
Posts: 194
Location: Polska

PostPosted: Sat Dec 13, 2008 2:44 am    Post subject: Reply with quote

Sorry to be acting as a thread-necromancer here, but I got rather surprised no-one responded to this as I would expect:
mv wrote:
Except for -masm=intel and -fforce-addr (whose advantage is more than doubtful) these flags don't look that bad: There's nothing which wouldn't also set by -O3 except -pipe and -mfpmath=sse which is also not really dangerous.


This, I believe to be a very wrong way of thinking, because:

  • Some packages filter C/CXX flags.
  • Thus, those that do filter, for instance -O3, should better not be compiled with anything that this -O3 implies (probably not everything, but still - you never now, unless you know the specific code by heart ;)).

  • Let's now suppose a package has filtered out -O3, but you have in your CFLAGS flags that -O3 sets.
  • Your package compiles, confident it has set aside all the dangers by filtering. 8)
  • And - guess, what - the so-far happy package (that's now pupated and became a cute little program) segfaults! 8O Why so?!
  • Well, just so - you tricked it, because it thought it was safe, as it filtered out -O3, and you forced it to use some of -O3's little goblins anyway (it sadly was allergic to one of them :(). You naughty boy. Be ashamed of yourself!


Am I right?
Back to top
View user's profile Send private message
srunni
Guru
Guru


Joined: 26 Dec 2007
Posts: 365

PostPosted: Sat Dec 13, 2008 6:52 am    Post subject: Reply with quote

Does -funroll-loops actually do anything? :P
_________________
Patrick Ewing wrote:
if it walks like a duck and talks like a duck, it’s a duck, right? So if this duck is not giving you the noise that you want, you’ve got to just punch that duck until it returns what you expect.
Back to top
View user's profile Send private message
.yankee
Apprentice
Apprentice


Joined: 24 Feb 2008
Posts: 194
Location: Polska

PostPosted: Sat Dec 13, 2008 5:30 pm    Post subject: Reply with quote

srunni wrote:
Does -funroll-loops actually do anything? :P

Well, it certainly is nothing to cause one periodically rolling just for fun... Unless he is Richard Stallman and he's laughing at your having this among your global CFLAGS.

Just in case you meant to be serious:
man gcc:

 -funroll-loops
     Unroll loops whose number of iterations can be determined at
     compile time or upon entry to the loop.  -funroll-loops implies
     both -fstrength-reduce and -frerun-cse-after-loop.  This option
     makes code larger, and may or may not make it run faster.
Back to top
View user's profile Send private message
srunni
Guru
Guru


Joined: 26 Dec 2007
Posts: 365

PostPosted: Sat Dec 13, 2008 6:54 pm    Post subject: Reply with quote

So that is where http://www.funroll-loops.info/ gets its name, not the other way around :lol:
_________________
Patrick Ewing wrote:
if it walks like a duck and talks like a duck, it’s a duck, right? So if this duck is not giving you the noise that you want, you’ve got to just punch that duck until it returns what you expect.
Back to top
View user's profile Send private message
Captain Newbie
Apprentice
Apprentice


Joined: 22 Dec 2006
Posts: 182
Location: Socal

PostPosted: Sat Dec 13, 2008 10:51 pm    Post subject: Reply with quote

transient wrote:
In the words of a great ex-dev, HOLY COW I'M GOING SO FAST OH F***

That 'bug' is always good for a laugh, no matter how many times I read it I still giggle.

(And no, I'm not generally known as a giggler.)

-fomit-frame-pointer has disastrous implications for trying to get meaningful backtraces...you'll never, ever find it in my CFLAGS.

Corona688, you're spot-on about the x86's eccentricities.
_________________
/* Nobody will ever see this message :-) */
panic("Cannot initialize video hardware\n");
"As much as it pains me, we hope that developers know what they're doing." - wolf31o2
Back to top
View user's profile Send private message
McLink
Apprentice
Apprentice


Joined: 02 Feb 2008
Posts: 181
Location: /dev/chair

PostPosted: Sun Dec 14, 2008 12:00 pm    Post subject: Reply with quote

I know very little about compiler/GCC internals, so I'm wondering, can anyone explain to me what's so bad about -funroll-loops? The description from gcc(1) tells me very little about what it actually does - e.g. does the produced code not handle conditionally broken loops, or something?
_________________
Mc'abit wrote:
Islam isn't the problem, religion is.
Back to top
View user's profile Send private message
juantxorena
Apprentice
Apprentice


Joined: 19 Mar 2006
Posts: 201
Location: The Shire

PostPosted: Sun Dec 14, 2008 7:10 pm    Post subject: Reply with quote

Sir Link wrote:
I know very little about compiler/GCC internals, so I'm wondering, can anyone explain to me what's so bad about -funroll-loops? The description from gcc(1) tells me very little about what it actually does - e.g. does the produced code not handle conditionally broken loops, or something?


AFAIK it just unroll loops with a constant or known number of iterations. e.g., this code that square the elements in a 10-element array:
Code:

for (i=0;i<10;i++)
{
sqarray[i]=array[i]*array[i];
}

Would be compiled as ten sqarray[i]=array[i]*array[i] functions, each one with the correct value of "i". This is made to avoid using instructions like jumps, returns, and be able to execute the code without jumping to non-sequential address in the memory. In an ideal world, using a computer with infinite memory, no cache (only one level of memory) and no vector processing instructions this would provide a marginal speed improvement in cases like this.

In the real world there are very few opportunities to use this flag safely, and it will make the binaries larger, wasting memory and running slower, because larger binaries means more TLB misses, misuse of cache, etc.

That flag won't break anything, it just make everything slower.
_________________
I cannot write English very well. Please, correct any mistake so that I can improve.
Back to top
View user's profile Send private message
McLink
Apprentice
Apprentice


Joined: 02 Feb 2008
Posts: 181
Location: /dev/chair

PostPosted: Mon Dec 15, 2008 11:43 am    Post subject: Reply with quote

juantxorena: so it's not unsafe as such, but rather, mostly detrimental to performance without other benefits? In that case, why do people often say it's an "unsafe" CFLAG, if it (by itself) doesn't break anything?
_________________
Mc'abit wrote:
Islam isn't the problem, religion is.
Back to top
View user's profile Send private message
juantxorena
Apprentice
Apprentice


Joined: 19 Mar 2006
Posts: 201
Location: The Shire

PostPosted: Mon Dec 15, 2008 1:57 pm    Post subject: Reply with quote

Sir Link wrote:
juantxorena: so it's not unsafe as such, but rather, mostly detrimental to performance without other benefits? In that case, why do people often say it's an "unsafe" CFLAG, if it (by itself) doesn't break anything?


It seems that with gcc-3* unrolling loops was unsafe, because the compiler wasn't very good at knowing what loops can be unrolled safely or not. With gcc-4* this is not the case anymore. However, using this flag is as useless as before. It may be good in certain loops and certain archs, but in that cases that loops are unrolled in the code or the flag is forced in the makefile.
_________________
I cannot write English very well. Please, correct any mistake so that I can improve.
Back to top
View user's profile Send private message
djinnZ
Advocate
Advocate


Joined: 02 Nov 2006
Posts: 4831
Location: somewhere in L.O.S.

PostPosted: Mon Dec 15, 2008 2:14 pm    Post subject: Re: CFlags This Guy Left = WTF? Reply with quote

bobber205 wrote:
Quote:
#CFLAGS="-O3 -march=pentium3 -msse -mmmx -funroll-loops -pipe"
What I want to know is why the guy that did the server before me decided those were a good idea. :roll:
I see:
  • -pipe is absolutely normal no discussion about it.
  • If the server come from an old installation -O3 is not so wrong (I have used without problems for more than a year but only with gcc 3.4.6 with 4.x you must espect only crappy results); is possible than the guy has forget to revise the cflags at the gcc update time.
  • Using -march=i686 -msse -mmmx is better for compatibility between different processors, of course if you know what are you doing, if a devel filter the -march (normally in the ebuild will be filtered directly -msse by example) instead of the signle options for mmx/sse the results are wrong; is possible than the guy (due to absolute ignorance of the -march implicited options) has only update the -march without removing the redundant flags.
  • But, with the use of -funroll-loops only, is reasonable to think not about a ricer but about a very poor know-how and the simple copy of the first suggestion after a search on google for cflags. Tipical of people only able to install/re-install windows or ubuntu than try to use a "real" unix-like OS.
Conclusion:
The guy is only a stufu noob without experience and without the ability (or better: the will) of increase his poor knowledge. If you are evaluating his work must be instructed or fired immediately, a similar employee will only cause trouble (by reparation requests from customers or by recurse to a laywer for itself) in the future IMHO.
If is a self employed or frelance (reseller or mantainer) never more call it, similar people will only cause waste of time and money (by cost increase for the fasteful solutions proposed and by the cost of the failure time caused by its "idiocy").
[paranoid mode]If we are speaking about a reseller or an external mantainer this appear to me as a normal trick to force a reapair call in the future. Something similar to the mantainer for the laser printers I use to call in the past (but never more, only is impossible to find xerox replacements in Italy if you are not a reseller) and his use to set the highest temperature to the fuser in order to decrease the lifetime of the printers and force me to buy a new printer after a year by example.
Similar cflags will not cause big troubles at the first use but after some times and especially at deep update able to lock the entire system (glibc, gcc itself, binutils or baseutils by example).
Otherwise can be a measure to cause trouble in case another person try to update, you can verify the logs and/or the cflags used for the single packages, if the cflags are not constant the wrong set is intentional.
Also, if you are an employee of the same firm of this guy can be a mobbing attempt, put the others in trouble.[/paranoid mode]
Note than i am a specialized "consultant" in tax and personnel management, the analisys is serious, not just for speak and hope than will be useful, not only for you. :twisted:
_________________
scita et risus abundant in ore stultorum sed etiam semper severi insani sunt:wink:
mala tempora currunt...mater stultorum semper pregna est :evil:
Murpy'sLaw:If anything can go wrong, it will - O'Toole's Corollary:Murphy was an optimist :wink:
Back to top
View user's profile Send private message
mv
Watchman
Watchman


Joined: 20 Apr 2005
Posts: 6747

PostPosted: Mon Dec 15, 2008 4:26 pm    Post subject: Reply with quote

juantxorena wrote:
However, using this flag is as useless as before.

No, it isn't. It depends completely on the architecture how useful it is: In fact, an unrolled loop can be a lot faster, because the processor might be able to calculate the commands in parallel while on the original loop it might choose the "false" branch prediction. So a speed increase by some factors (for the loop itself) is not so rare. How much the increase of the code size reduces this advantage depends on cache size etc.
Quote:
It may be good in certain loops and certain archs, but in that cases that loops are unrolled in the code or the flag is forced in the makefile.

This is only true in theory. In practice, all programs ignore the arch, i.e. they respect the CFLAGS and special ./configure options, but that's it (the only partial exception which I know from this rule is mplayer). Summary: No program will unroll its loops, even if it would be good for your arch, unless you put this in your CFLAGS. Whether it is good or not can only be tried by experiment (and the results may vary from program to program and even from task to task).
Back to top
View user's profile Send private message
lightvhawk0
Guru
Guru


Joined: 07 Nov 2003
Posts: 388

PostPosted: Thu Dec 18, 2008 9:02 pm    Post subject: Re: CFlags This Guy Left = WTF? Reply with quote

bobber205 wrote:
Quote:

#CFLAGS="-O3 -march=pentium3 -msse -mmmx -funroll-loops -pipe"

While trying to fix the expat issue on our server, I was having seriously weird segfault errors.
What do you know. I looked at the cflags and saw that...

I replaced them with more sane ones and reemerged gcc 4. I am now on my way to recovery.

What I want to know is why the guy that did the server before me decided those were a good idea. :roll:


You should have been here for Gentoo 1.4, those were at one time considered to be "laid back" cflags.

I remember people running some of the craziest flags. IE

-O3 march=athlon -mfpmath=see,387 -funroll-all-loops -ffast-math -finline-functions -finline-limit=256 -ftracer -pipe

Good times!
_________________
If God has made us in his image, we have returned him the favor. - Voltaire
Back to top
View user's profile Send private message
djdunn
l33t
l33t


Joined: 26 Dec 2004
Posts: 810

PostPosted: Fri Dec 19, 2008 3:16 am    Post subject: Reply with quote

CFLAGS="-O3 -O2 -march=amdfam10 -mtune=amdfam10 -pipe"

ima dork if -O3 is filtered -O2 will be picked up the same for -march then the mtune will still be there.

i actually spend hours watching stuff compile and um i can recognize when certain cflags are filtered and thats why i like to put up fallbacks for the more heavy optimizations
_________________
“Music is a moral law. It gives a soul to the Universe, wings to the mind, flight to the imagination, a charm to sadness, gaiety and life to everything. It is the essence of order, and leads to all that is good and just and beautiful.”

― Plato
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Gentoo Chat All times are GMT
Goto page Previous  1, 2
Page 2 of 2

 
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