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.

TMS320F280039C: Shift operations not match divisions in CLA task

Part Number: TMS320F280039C

Dear Champs,

I am asking this for our customer.

In their CLA task 8 (as background), they use shift operation like below,

D2D_i16InjectAcNoiseCmd = i16InjectAcNoiseCmd >> 5;

D2D_i16InjectAcNoiseCmd is in type short.

The user expected the result should be i16InjectAcNoiseCmd/32, but they found the result was wrong from CCS watch window.

Why D2D_i16InjectAcNoiseCmd became 2044 after i16InjectAcNoiseCmd (294) >> 5?

But if they changed to use D2D_i16InjectAcNoiseCmd = i16InjectAcNoiseCmd / 32, then the result was expected.

Is there any concern when using shift operation (right shift or left shift) in CLA?

Wayne Huang

  • HI Wayne,

    Would it be possible to provide a test case and let me know the compiler version and optimization level?

    http://software-dl.ti.com/ccs/esd/documents/sdto_cgt_How-to-Submit-a-Compiler-Test-Case.html

    Thanks,

    Ashwini

  • Dear Ashwini,

    I already could make a simple project to reproduce the user's issue.

    You can just use below codes to reproduce it.

    I will also send you the project for reference.

    #pragma INTERRUPT(Cla1Task8_background, "BACKGROUND")
    interrupt void Cla1Task8_background()
    {

    __mdebugstop();

    volatile short A = 2044;
    volatile short B = -800;
    volatile short C = 0;

    if(B > 792)
    B = 792;
    else if ((B + 792) < 0 )
    B = 0-792;

    A = B >> 5;
    C = B / 32;

    .........

    You can see A is 2023, which was not expected.

    This issue happens as long as you use negative integer for B and declare B as short or int16.

    Note that we also found that if A, B, C were declared as int rather than short/int16, then there was no such issue.

    It seems there is something wrong with sign bit handling.

    Would you please help check if there is any limitation here or anything wrong with the compiler?

    The compiler we used here is:

    CCS 11.0

    C2000 compiler V21.6.0.LTS

    Optimization

    -v28 -ml -mt --cla_support=cla2 --float_support=fpu32 --idiv_support=idiv0 --tmu_support=tmu1 --vcu_support=vcrc -O1 --opt_for_speed=3 --fp_mode=relaxed 

    ......

    --abi=eabi --cla_background_task=on --cla_signed_compare_workaround=on

    Wayne Huang

  • Hi Wayne,

    Thanks a lot for the test case. The compiler team is investigating this. One observation is that if the volatile keyword is removed, the compute is correct.

    Thanks,

    Ashwini

  • Wayne,

    CLA loads of 16bit signed, negative integers to MRn registers will incorrectly zero-extend by 16 bits rather than sign-extend.  The work around is to instead use a 32bit signed integer.

    I filed bug EXTSYNC-3279 for tracking the issue. 

    Thanks and regards,
    Greg