Quantcast
Channel: Tools
Viewing all articles
Browse latest Browse all 91752

Forum Post: Wrong result with compiler optimization level above 2(-O2)

$
0
0

Hi, I've found an unexplicable compiler behavior. The following code does NOT give correct answer  when compiler optimization level is set above 2(-O2).


#include <vector>
#include <complex>

using namespace std; /* Because of the library: "complex" */

typedef float     _REAL;
typedef complex<_REAL>  _COMPLEX;

inline _COMPLEX    Conj(const _COMPLEX& cI)
         {return conj(cI);}

inline _REAL     SqMag(const _COMPLEX& cI)
        {return cI.real() * cI.real() + cI.imag() * cI.imag();}

 
vector<_COMPLEX> HistoryBuf(17, _COMPLEX(0.0, 0.0));
vector<_COMPLEX> cGuardCorrBlock(16, _COMPLEX(0.0, 0.0));
vector<_REAL>  rGuardPowBlock(16, 0.0);

 
int main()
{

 int j;


 for(j = 0; j < 17; j++)
 {
  HistoryBuf[j] = (_REAL)j;

 }

 

 for(j = 0; j < 16; j++)
 {
   
  cGuardCorrBlock[j] += HistoryBuf[j] *
   Conj(HistoryBuf[j + 1]);

  
  rGuardPowBlock[j] += SqMag(HistoryBuf[j]) +
   SqMag(HistoryBuf[j + 1]);


  System_printf("\r\n rGuardPowBlock[%d]=%f; \n",j, rGuardPowBlock[j]);


 }

 return 0;

}

Error is in the Prinf result. Note:When I turn off the optimization level, it is correct. Can the develope team behind CodGen look into this matter??Thanks in advance!

 PS: my DSP platform is C6748, C/C++compiler 7.4.6

 


Viewing all articles
Browse latest Browse all 91752

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>