LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 03-02-2012, 11:31 PM   #1
Zssfssz
Member
 
Registered: Sep 2011
Location: Las Vegas!
Distribution: Ubuntu n' Flavors, ReactOS, MINIX3, FreeDOS, Arch
Posts: 339

Rep: Reputation: Disabled
-O5? Is it safe? Does it exist?


In several instances I have seen a person mention -O5 optomaztions. One said that the vareable i (it was the only vareable in the example... and C++) would't even be loded into memory but acctualy put in register eax;this makes it sound unsafe... Does GCC have it? Is it safe? Google doesn't bring up anything and the gcc docs are umm... large.
 
Old 03-03-2012, 02:58 AM   #2
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,775

Rep: Reputation: 481Reputation: 481Reputation: 481Reputation: 481Reputation: 481
-O3 is the highest one that exists.
 
Old 03-03-2012, 04:15 AM   #3
H_TeXMeX_H
Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269
I've seen mplayer use '-O4'. However, the only one that is safe is '-O2'.
 
Old 03-03-2012, 11:01 PM   #4
Zssfssz
Member
 
Registered: Sep 2011
Location: Las Vegas!
Distribution: Ubuntu n' Flavors, ReactOS, MINIX3, FreeDOS, Arch
Posts: 339

Original Poster
Rep: Reputation: Disabled
Just tried it with gfortran (I normally test things with c first), it worked. Also tried -O25 and it worked! It there a process to this?
 
Old 03-05-2012, 05:59 AM   #5
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
define "it worked"

The compiler may have just ignored the switch or it may have substituted it for a number that is supported. Basically the various -Ox stitches are responsible for setting up certain optimisation flags, and beyond that don't do anything on their own.
 
Old 03-05-2012, 06:17 AM   #6
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Some compilers actually have -O4 and -O5 optimization levels (e.g XL Fortran for Multicore Acceleration by IBM), but this is very compiler-specific and I think you can live with -O3 at most. I agree with "The compiler ... may have substituted it for a number that is supported" as mentioned by graemef. Indeed, it uses the maximum available level of optimization. I cannot find a reference about this behaviour anyway.

Last edited by colucix; 03-05-2012 at 06:21 AM.
 
Old 03-05-2012, 06:52 AM   #7
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,775

Rep: Reputation: 481Reputation: 481Reputation: 481Reputation: 481Reputation: 481
As I said, for gcc '-O3' is the highest one available. If you give values above 3 it simply ignores them and uses -O3. I'm not sure that -O2 is safer then -O2 -depends on what you mean by 'safe'. -O2 is certainly the most reliable. Using -O3 won't work for all sources and/or arches.
 
Old 03-05-2012, 02:59 PM   #8
orgcandman
Member
 
Registered: May 2002
Location: dracut MA
Distribution: Ubuntu; PNE-LE; LFS (no book)
Posts: 594

Rep: Reputation: 102Reputation: 102
Quote:
Originally Posted by gnashley View Post
As I said, for gcc '-O3' is the highest one available. If you give values above 3 it simply ignores them and uses -O3. I'm not sure that -O2 is safer then -O2 -depends on what you mean by 'safe'. -O2 is certainly the most reliable. Using -O3 won't work for all sources and/or arches.
NOTE: severely opinionated junk follows.

In general, if you've properly coded to the C/C++ virtual machine, -O3 is 'reliable'. However, if you've taken any shortcuts, then you'll likely have lots of "strange" behavior.

Additionally, -O3 may expose you to more compiler bugs (contrary to popular belief, compiler bugs are not fictitious).

The only way to know if a particular level is "safe" for you is to have very robust and aggressive unit tests which execute and use code coverage tools in conjunction to validate that you have actually hit all the lines of code from numerous permutations.
 
Old 03-06-2012, 07:29 AM   #9
H_TeXMeX_H
Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269
Quote:
Originally Posted by orgcandman View Post
In general, if you've properly coded to the C/C++ virtual machine, -O3 is 'reliable'.
Like that ever happens...
 
Old 03-07-2012, 11:23 AM   #10
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 13.1
Posts: 1,320

Rep: Reputation: 252Reputation: 252Reputation: 252
Quote:
Originally Posted by orgcandman View Post
In general, if you've properly coded to the C/C++ virtual machine, -O3 is 'reliable'. However, if you've taken any shortcuts, then you'll likely have lots of "strange" behavior.
What do you refer to with “properly coded” and “shortcuts”? The program might be properly coded, but as -O3 can reorder the computations one can face some overflow/underflow conditions with varying outcome. Although the program is still compiled in a mathematical correct way, the used algorithms can fail due to the reordering of operations.
 
Old 03-07-2012, 01:22 PM   #11
orgcandman
Member
 
Registered: May 2002
Location: dracut MA
Distribution: Ubuntu; PNE-LE; LFS (no book)
Posts: 594

Rep: Reputation: 102Reputation: 102
Quote:
Originally Posted by Reuti View Post
What do you refer to with “properly coded” and “shortcuts”? The program might be properly coded, but as -O3 can reorder the computations one can face some overflow/underflow conditions with varying outcome. Although the program is still compiled in a mathematical correct way, the used algorithms can fail due to the reordering of operations.
-O3 (and any level, really) can only reorder between synchronization points. By properly coded, I mean one codes to the standard in a completely unambiguous manner. Merely 'compliant' is not good enough (example is testing for overflow, which is "compliant" in that the standard allows it, but the results are not guaranteed).

Funny you bring up mathematical models. My current job is writing OTA channel emulation software (emulating Jakes' or Dent's versions of Rayleigh fading, for example). We use -O3. Our algorithms verify correct, statistically. I've used -O3 to compile lots of different software projects. It usually behaves.

As has been noted though, -OXXXX is completely compiler dependent and isn't so much a standard as a request to the compiler to try and do certain actions (omit frame pointers, reorder mathematical expressions, pass values using esoteric registers, etc). There was a time for the gnu compiler when O2 was considered dangerous, and O3 was downright insane. I think as the compilers have gotten better, the amazingly spectacular breakages have been eliminated and the code is usually correct.

Again, just my $.02
 
  


Reply

Tags
-o5, gcc


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] is it safe? smeezekitty Linux - Newbie 2 10-07-2009 03:49 AM
Is It safe,..... udazzleme Linux - General 3 01-23-2006 11:46 PM
Is it safe ? Alex_jacobson Solaris / OpenSolaris 2 03-02-2005 02:24 PM
Is this safe enough? koyi Linux - Security 4 08-18-2004 11:50 PM
is it safe... violaten Linux - Hardware 1 08-03-2003 03:56 AM


All times are GMT -5. The time now is 03:23 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration