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.

Compiler/AM5728: Compiler optimization converting function to a single BNOP.S2 instruction.

Part Number: AM5728

Tool/software: TI C/C++ Compiler

I am using the TI C6000 compiler 8.2.2 to perform some benchmarking of function. I have a function for ramp generator that is defined as shown here:

void RG_FXN(RAMPGEN rg)
{
/* Compute the angle rate */
    rg.Angle += uIQmpy(rg.StepAngleMax,rg.Freq);

/* Saturate the angle rate within (-1,1) */
    if (rg.Angle>_IQ(1.0))
        rg.Angle -= _IQ(1.0);
    else if (rg.Angle<_IQ(-1.0))
        rg.Angle += _IQ(1.0);
        rg.Out=rg.Angle;

    return;
}

If I compiler this with the following compiler setting of -O3, the output of the function is BNOP.S2 B3, 5 . Could you explain why the compiler shows this behavior.

Additional data point, if I build the code with O1, then the compiler generates the assembly code as shown here:

I would like to confirm that this is the expected behavior ? and if there is some way to avoid the compiler from optimizing the function out of the code in this manner.

Regards,

Rahul

  • Is RAMPGEN a pointer? If not, the function is getting a local copy of rg, and therefore there are no affects outside of the function.
  • Keith,

    I think you have nailed the root cause here. The code that I am trying to port has RG_FXN defined two ways: it is defined as a function macro when the full algorithm is bench marked but defined as a function when individual components need to be bench marked probably so that the symbol is generated for entry and exit. I think when porting the function macro to the function there is a switch in the code that needs to be convert RAMPGEN to struct pointer that I need to locate/create in this code base.

    thanks for catching this.

    Regards,
    Rahul