This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Pass By Reference compiled out by optimizer?

Hi

I am using the 6.1.12 compiler on a DM648 and noticed that my pass-by-reference function was no getting compiled (no assembly) when Optimizations -o1, -o2, or -o3 were used. When I looked at mixed mode, I can see the "C" code and function call assembly for before and after these functions, but none for the two pass-by-reference functions below.

The strange thing is if I uncomment the UTIL_waitloop(), the call by reference functions will now have assembly. Any ideas?

Cheers

--------calls to functions ------------

            int sx = 0;
            int sy = 0;
            int dsx = 0;
            int dsy = 0;
                //UTIL_waitLoop(1000000);   // 1,000,000 = 5 msec
            vps->GetStamper().GetIntegratedMotion( info_out_cur.stamp, info_out_cur.prevStamp, sx, sy ); // no assembly
                //UTIL_waitLoop(1000000);   // 1,000,000 = 5 msec
            vps->GetStamper().GetDisplayShift( info_out_cur.prevStamp, dsx, dsy );  // no assembly
           
            VideoFormat::PreShiftFrame( &info_out_cur, sx+dsx, sy+dsy );
            VideoFormat::ShiftFrameEven( &info_out_cur );       

---------definition ----------------------

   void GetDisplayShift( u8 inStamp, int& outX, int& outY ) const;
protected:
      void GetIntegratedSceneMotion( u8 inStamp, int& sceneX, int& sceneY ) const;

---------function -----------------------

void FrameStamper::GetIntegratedMotion( u8 curStamp, u8 prevStamp, int& outX, int& outY ) const
{
   outX = 0;
    outY = 0;

   int i = (prevStamp + 1) % (MAX_STAMP+1);

   for(;;)
   {
      outX += m_FrameX[i];
      outY += m_FrameY[i];

      if( i == curStamp )
         break;

      i = (i+1)%(MAX_STAMP+1);
   }
}

void FrameStamper::GetDisplayShift( u8 inStamp, int& outX, int& outY ) const
{
   if( inStamp > MAX_STAMP )
   {
      outX = 0;
      outY = 0;
   }
   else
   {
      outX = m_DisplayX[inStamp];
      outY = m_DisplayY[inStamp];
   }
}

  • Eddie said:
    I am using the 6.1.12 compiler on a DM648 and noticed that my pass-by-reference function was no getting compiled (no assembly) when Optimizations -o1, -o2, or -o3 were used.

    When you enable optimization the compiler has a tendancy to shift around the resulting binary code, so the disassembly is no longer effective for debugging, so it is most likely that the code for your functions still exists, it is just no longer mapped to the C code you are looking at in mixed mode due to the optimizer. Modifying the code slightly, like adding in the wait loop can have an impact on how the optimizer functions, so it is not suprising to see the code come and go when you do something like that.

    This being said the key question is does the functionality of your code change to the point that it looks like those functions are actually not being executed anymore, or are you just noting the missing assembly?

  • Hi Bernie

    I attached some screen shots. The first shot shows both functions missing, and the second shows the only one missing when I added the while loop func call.

    The code doesn't work as expected because the dsx and dsy parameters are not being calculated by the functions.

    6644.Pass by reference calls missing.doc

    Cheers
    Eddie

  • In the case that the code no longer functions properly than you are probably looking at a compiler bug, in which case your best bet for now would probably to leave some function call in there like the delay as a shim to ensure functionality, or moving the function calls to another C file which has optimization disabled, you could also try earlier versions of the CGT to see if the issue goes away with earlier optimizers.

    If you can strip down your project to something you can send in which showcases the issue and that we can reproduce here than I can submit this as a bug against the compiler, which would hopefully get it fixed in future version.

  • I think we may have found something interesting in your screen shots, I did not catch it myself but one of the CGT engineers pointed out that the disassembly listing in your mixed mode view is incomplete, it is skipping from 0xE102DF82 to 0xE102DFCE so there are a few instructions that are not being shown in the mixed mode view. Could you open up the disassembly window and look at the same location from there to see what is missing in the mixed mode view? If we can see a listing of the disassembly in a more complete form this may make more sense.

  • That is truly strange, but not as strange as what I see in today's mixed view. In the uploaded doc, I added the disassembly window alongside the mixed view. Now there is no gap in the addresses and guess what, the function calls to GetIntegratedMotion() and GetDisplayShift are present!!!!!

    4353.DisassemblyPass-By-Reference.doc

    I've made no upgrades to the build tools or GUI. I did add some code that caused the memory locations to shift.

    I believe now that the compiler is not removing these functions. I'm stumped as to why I thought they were not being called when I stepped through the assembly.

    Cheers

  • That is a bit unusual though I am glad to hear it is working, it can be tough to track down these sorts of issues but if you see it again please let us know.

  • A better way to see what is going on ... Add -s to the compile options then inspect the resulting .asm file.  I suspect the "missing" functions are being inlined.

    Thanks and regards,

    -George

     

  • Good idea. Thanks again.[B*]