title: floating point instruction anomaly -- FLDZ malfunctioning?
body: <p>I am trying to debug the problem I posted earlier here:
  <a href="https://stackoverflow.com/questions/11833571/c-and-pin-tool-very-weird-double-variable-issue-with-if-statement">C++ and pin tool -- very weird DOUBLE variable issue with IF statement</a>.
  I tracked down the moment when the weird behavior occurred using gdb. What I found is shown in the figure below that shows the gdb screenshot displaying the disassembled code and floating pointer register values. (larger image <a href="https://dl.dropbox.com/u/7335043/bug.png" rel="nofollow noreferrer">here</a>)
  <img src="https://i.stack.imgur.com/IXdCO.png" alt="before and after FLDZ instruction is executed">
  Left-hand side image shows the screenshot before the highlighted <code>FLDZ</code> instruction is executed and the right-hand side image is after the instructions is executed. I looked up the x86 ISA and <code>FLDZ</code> is for loading <code>+0.0</code> into <code>ST(0)</code>. However, what I get is <code>-nan</code> instead of <code>+0.0</code>.
  Does anybody know why this happens?
  The system I am using is Intel xeon 5645 running 64-bit CentOS, but the target program I am trying to debug is 32-bit application. Also, as I mentioned in the earlier post, I tried two versions of gcc, 4.2.4 and 4.1.2 and observed the same problem.
  Thanks.</p>
  
  <p>--added--
  By the way, below is the source code. </p>
  
  <pre><code>void Router::Evaluate( )
  {
    if (_id == 0) aaa++;
  
    if ( _partial_internal_cycles != 0 )
    {
      aaa += 12345;
      cout &lt;&lt; "this is not a zero : " &lt;&lt; endl;
      on = true;
    }
  
    _partial_internal_cycles += (double) 1.0;
  
    if ( _partial_internal_cycles &gt;= (double)1.0 ) {
      _InternalStep( );
      _partial_internal_cycles -= (double)1.0;
    }
  
    if (GetSimTime() &gt; 8646000 &amp;&amp; _id == 0) cout &lt;&lt; "aaa = " &lt;&lt; aaa &lt;&lt; endl;
    if ( on)
    {
      cout &lt;&lt; "break. id = " &lt;&lt; _id &lt;&lt; endl;
      assert(false);
    }
  
  }
  </code></pre>