Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <ol start="2"> <li>I saw some programs got crashed when compiling with -O3, is it deterministic?</li> </ol> </blockquote> <p>If the program is single threaded, all algorithms used by program are deterministic, and if the inputs from run to run are identical, yes. The answer is "not necessarily" if any of those conditions is not true.</p> <p>The same applies if you compile without using -O3.</p> <blockquote> <p>If I run an executable once without any crash, does it mean it is safe to use -O3?</p> </blockquote> <p>Of course not. Once again, the same applies if you compile without using -O3. Just because your application runs once does not mean it will run successfully in all cases. That's part of what makes testing a hard problem.</p> <p><br></p> <p>Floating point operations can result in weird behaviors on machines in which the floating point registers have greater precision than do doubles. For example,</p> <pre><code>void add (double a, double b, double &amp; result) { double temp = a + b; result = temp; if (result != temp) { throw FunkyAdditionError (temp); } } </code></pre> <p>Compile a program that uses this <code>add</code> function unoptimized and you probably will never see any <code>FunkyAdditionError</code> exceptions. Compile optimized and certain inputs will suddenly start resulting in these exceptions. The problem is that with optimization, the compiler will make <code>temp</code> a register while <code>result</code>, being a reference, won't be compiled away into a register. Add an <code>inline</code> qualifier and those exceptions may disappear when your compiler is compiled with <code>-O3</code> because now <code>result</code> can also be a register. Optimization with regard to floating point operations can be a tricky subject.</p> <p>Finally, let's look at one of those cases where things did go bump in the night when a program was compiled with -O3, <a href="https://stackoverflow.com/questions/280069">GCC: program doesn't work with compilation option -O3</a>. The problem only occurred with -O3 because the compiler probably inlined the <code>distance</code> function but kept one (but not both) of the results in an extended precision floating point register. With this optimization, certain points <code>p1</code> and <code>p2</code> can result in both <code>p1&lt;p2</code> and <code>p2&lt;p1</code> evaluating to <code>true</code>. This violates the strict weak ordering criterion for a comparison function.</p> <p>You need to be very careful with regard to how optimization and floating point operations interact on machines with extended precision floating point registers (e.g., Intel and AMD).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload