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.

If() condition works in CCSV3.3 but not in CCSV5

I have codes run correctly in CCSV3.3 but failed in CCSV5. Do not know why.

I have a function declared as long Is_connected( long),  this function is called in another function as

              if (! Is_connected(i))

This if statement does not work as expected, when Is_connected() return a non zero integer, if(! Is_connected(i)) will assert the if condition true.

If I change the above statement as

                          j=Is_connected(i);

                           if (!j) 

 if j is a non zero integer, then if(!j)  will assert the condition false as expected.

Why if(! Is_connected(i)) does not work as expected in CCSV5?

Honghui Qi

 

  • Hi,

    Is "Is_connected(i)" an array?

    Regards,

    Gautam

  • Is_connected() is a function, taking 32bit interger as an input, returning a 32 bits integer as an output.

    Thanks.

    Honghui

  • Guatam,

    In the function "Is_connected()", I have this return statement on a global integer array[ ] , for example ,

    { ;;;  return (array[5] & (1<< shift)); }

    This does not work on if(! Is_connected(i))  

     I changed this return statement as

    { int x; ;;;  x = array[5] & (1<<shift); return x;}

    Then it works with if (! Is_connect(i))

    Does return statement not directly working on array?  What is your means of "Is_connected(i) " an array ?

    Honghui

  • honghui Qi said:

    I have codes run correctly in CCSV3.3 but failed in CCSV5. Do not know why.

    Which target processor are you working with? What was the version of compiler tools used with CCS 3.3 and what is the version used wtih CCSv5? What is the exact version of CCSv5?

    honghui Qi said:

    This if statement does not work as expected, when Is_connected() return a non zero integer, if(! Is_connected(i)) will assert the if condition true.

    My first suggestion would be to compare the assembly code generated by the two versions and confirm if the compiler is generating incorrect code. for that line of C code? Are you compilng with optimization turned on?
    Depending on the version of compiler tools you are using there may be a newer version you could try out as well.

  • The processor is the F28335, the CCS details are as follows

    CCSV3.3.82.13, code generation tools v5.2.6, BIOS 5.33.06

    CCSV 5.5.0.00077, compiler version is Ti v6.2.0, DSP/BIOS version 5.42.1.09

    No optimization used at all in either case. 

    As you suggested, I compared assembly codes,  The last statements (mainly return statement) are almost the same, only one MOV T, *-SP[6] is out of order (I have difficult to cut and paste the codes here). As in the place to call the function, they are different as follows.

    in CCSV5 if(! IS_Connected(id))

    0644   MOVL ACC, *-SP[4]

    7670&221   LCR IS_Connected

    ED04    SBF C$L24, NEQ

    In CCS3.3, if(!Is_Connected(id))

    0644    MOVL ACC, *-SP[4]

    7670FC09   LCR Is_Connected

    FF58    TEST   ACC

    ED04    SBF   4, NEQ

    Hope these give you some insight about it.

    I have a way to fix it, but I still do not understand it, why this does not work as expected, why my fix make it works.

    Honghui

     

  • The important question here is whether the code is actually executing incorrectly (ie is it executing parts of the "if" condition that it shouldn't be) or is it just the debugger giving the impression that the execution path is incorrect.

    Take a look at the assembly instructions a few instructions prior to the ones you show above. You may be running into the behabior described in these related threads:

    http://e2e.ti.com/support/development_tools/code_composer_studio/f/81/p/3431/12177.aspx#12177
    http://e2e.ti.com/support/development_tools/code_composer_studio/f/81/p/104696/681164.aspx#681164
    http://e2e.ti.com/support/development_tools/code_composer_studio/f/81/p/245623/860054.aspx#860054

    If this does not explain the behavior you see and the code is actually executing incorrectly then we would need a small cutdown test case that we can use to reproduce the issue.

  • Thanks for your reply.

    It is not the same problem as you quoted, the problem is the code is actually executing incorrectly, i.e, it execute parts of the if condition that it should not be.  Because of the problem, I debug through and find the problem is on this if statement and debug outcome explained the problem I have when it is free running.

    As for the instructions  prior to the ones I showed in the previous post, since this instrunction if()  is the first instruction in another function call, I guess it does some house keeping job before call this function, as follows

    FE10        ADDB         SP, #16
    30f387:   A046        MOVL         *-SP[6], XAR5
    30f388:   1E44        MOVL         *-SP[4], ACC
    30f389:   A842        MOVL         *-SP[2], XAR4

    260         if(!Is_Connected(id))
    30f38a:   0644        MOVL         ACC, *-SP[4]
    30f38b:   7670F221    LCR          Is_Connected
    30f38d:   ED04        SBF          C$L24, NEQ
    261          return(0);
    30f38e:   0200        MOVB         ACC, #0
    30f38f:   FFEF0222    B            C$L40, UNC
    265         SWI_disable();
            C$L24:
    30f391:   767175AD    LCR          _SWI_disable

     

    Honghui

  • Hi, I think I find where it is wrong, Can you help me to expalin and understand it.

    My codes are legacy code from a TI's processor (C30), where the "int" is 32 bit long integer, while in F28335 "int" is a 16 bit long integer, so the way we did is to define a header file to redefine the int to be long, unsigned to be unsigned ling, so we can use the legacy codes without changes since the whole project is really big.

    The new data type header file is defined as

    #define int long

    #define unsigned unsigned long

     I experimented a very simple project to just called Is_connected () function and found it behave the same as in my real project, i.e. it execute incorrectly. But the watch window clearly shows these arrays and variables are 32 bits.

    Then I remove the header file and specifically define the long and unsigned long, then it works as expected.

    Can you help me to explain it.  it works in CCSv3.3, but not in CCSV5.5.

    I include related parts of the Is_Connect() function here when id = 3500,

    #define int long

    #define unsigned unsigned long

    unsigned  connect_state[] = {0x00000003, 0x00000000,0x00000000,0x08000000,0x00000000,0x00000000};

    int  Is_Connected ( intblockno ) {

    int wordno, bitno;

    const int ONE=1;

     if ( blockno < 3690 ){

    for ( wordno = 0, bitno = blockno - 3500; bitno > 31; ++wordno, bitno -= 32 )

    ;

    return ( connect_state[wordno] & (ONE << bitno) );

    }

    else

    return ( 0 );

    }
    The problem is on this return statement, if I assign this to a long variable, then return, it will work as expected.

    Honghui