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 Ti v6.4.2, v6.2.10, v6.2.7 have problems with floating-point on optimization level 2 and above.



I use the following code:

float calc(float *A, float *B,float *C)
{
       int i,j;
       float Temp;
       float Ret=0;
       for (i=0;i<10;i++)
       {
             Temp=A[i];
             for(j=0;j<10;j++)
             {
                    Temp-=A[j]*B[j];
             }

             Ret+=Temp;
             C[i]=Temp;
       }

       return Temp;
}


int main(void) {

       float A[10]={0.0, 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9};
       float B[10]={0.2, 1.2, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9};;
       float C[10];
       calc(A, B,C);
       int i;
       for (i=0;i<10;i++)
       {
        printf("Result Temp=%f\n", C[i]);
       }

       return 0;
}

Local Optimization (Level1): C[0]-C[9]

-344.96 -343.86 -342.76 -341.66 -340.56 -339.46 -338.36 -337.26 -336.16 -335.06

Global Optimization (Level2): C[0]-C[9]

-54.56 -53.45999 -52.36 -51.25999 -50.15999 -49.06 -47.95999 -46.86 -45.75999 -44.65999

 6      {
        calc():
00f8d4:   B2BD        MOVL         *SP++, XAR1
00f8d5:   BE09        MOVB         XAR6, #0x09
00f8d6:   AABD        MOVL         *SP++, XAR2
00f8d7:   8BA4        MOVL         XAR1, @XAR4
00f8d8:   E20306BD    MOV32        *SP++, R6H
00f8da:   E20307BD    MOV32        *SP++, R7H
00f8dc:   8E4C        MOVL         XAR0, *-SP[12]
10             for (i=0;i<10;i++)
00f8dd:   B51800A6    RPTB         #24, @AR6
12                   Temp=A[i];
        C$L1:
00f8df:   E2AF0081    MOV32        R0H, *XAR1++, UNCF
13                   for(j=0;j<10;j++)
00f8e1:   E591        ZERO         R1
00f8e2:   86A4        MOVL         XAR2, @XAR4
00f8e3:   C5A5        MOVL         XAR7, @XAR5
15                          Temp-=A[j]*B[j];
00f8e4:   E597        ZERO         R7
00f8e5:   E596        ZERO         R6
00f8e6:   E6CF0003    MOV32        R3H, R0H, UNCF
00f8e8:   E6CF000A    MOV32        R2H, R1H, UNCF
00f8ea:   F609        RPT          #9
00f8eb:   E2501F82 || MACF32       R7H, R3H, *XAR2++, *XAR7++        // wrong below
00f8ed:   E7100098    ADDF32       R0H, R3H, R2H
00f8ef:   E71001B9    ADDF32       R1H, R7H, R6H
00f8f1:   7700        NOP         
19                   C[i]=Temp;
00f8f2:   E7200040    SUBF32       R0H, R0H, R1H
00f8f4:   7700        NOP         
00f8f5:   E2030080    MOV32        *XAR0++, R0H
        C$L2:
00f8f7:   E2AF07BE    MOV32        R7H, *--SP, UNCF
00f8f9:   E2AF06BE    MOV32        R6H, *--SP, UNCF
00f8fb:   86BE        MOVL         XAR2, *--SP
00f8fc:   8BBE        MOVL         XAR1, *--SP
00f8fd:   0006        LRETR       

  • float calc(float *A, float *B,float *C)
    {
    int i,j;
    float Temp;
    for (i=0;i<10;i++)
    {
    Temp=A[i];
    for(j=0;j<i;j++)
    {
    Temp-=A[j]*B[i-j-1];
    }

    C[i]=Temp;
    }

    return Temp;
    }


    12 for(j=0;j<i;j++)
    00f88e: B50900A6 RPTB #9, @AR6
    14 Temp-=A[j]*B[i-j-1];
    C$L2:
    00f890: E2AF008F MOV32 R0H, *--XAR7, UNCF
    00f892: E2AF0180 MOV32 R1H, *XAR0++, UNCF
    00f894: E741360A MPYF32 R2H, R1H, R0H
    || ADDF32 R3H, R3H, R2H // must be SUBF32 R3H,R3H,R2H
    00f896: 7700 NOP
    00f897: 7700 NOP
    00f898: 7700 NOP
    C$L3:
    00f899: E720009B SUBF32 R3H, R3H, R2H
  • Когда уже многоуважаемый TI наконец-то соизволит и исправит свой компилятор?

    When it respected TI has finally deigns and fix your compiler?

  • I cannot reproduce this output. Please tell me your exact command-line arguments to cl2000. You can see them in the build console when CCS runs the compiler.
  • **** Build of configuration Debug for project TestCpU ****

    "c:\\ti\\ccsv6\\utils\\bin\\gmake" -k all

    'Building file: ../main.c'

    'Invoking: C2000 Compiler'

    "c:/ti/ti-cgt-c2000_6.4.2/bin/cl2000" -v28 -ml -mt --cla_support=cla1 --float_support=fpu32 --tmu_support=tmu0 --vcu_support=vcu2 -O2 --opt_for_speed=5 --include_path="c:/ti/ti-cgt-c2000_6.4.2/include" -g --diag_warning=225 --display_error_number --diag_wrap=off --preproc_with_compile --preproc_dependency="main.pp" "../main.c"

    "../main.c", line 33: warning #225-D: function "printf" declared implicitly

    'Finished building: ../main.c'

    ' '

    'Building target: TestCpU.out'

    'Invoking: C2000 Linker'

    "c:/ti/ti-cgt-c2000_6.4.2/bin/cl2000" -v28 -ml -mt --cla_support=cla1 --float_support=fpu32 --tmu_support=tmu0 --vcu_support=vcu2 -O2 --opt_for_speed=5 -g --diag_warning=225 --display_error_number --diag_wrap=off -z -m"TestCpU.map" --stack_size=0x200 --warn_sections -i"c:/ti/ti-cgt-c2000_6.4.2/lib" -i"c:/ti/ti-cgt-c2000_6.4.2/include" --reread_libs --display_error_number --diag_wrap=off --xml_link_info="TestCpU_linkInfo.xml" --rom_model -o "TestCpU.out" "./main.obj" "../2837xD_RAM_lnk_cpu1.cmd" -l"libc.a"

    <Linking>

    warning #10247-D: creating output section ".cio" without a SECTIONS specification

    warning #10210-D: creating ".esysmem" section with default size of 0x400; use the -heap option to change the default size

    'Finished building target: TestCpU.out'

    ' '

    **** Build Finished ****

  • You are not using printf correctly.  Please see this wiki article for the details.  Next I'll highlight a few errors you made, and give you a pointer into that article which discusses that error.

    Yura Secret said:
    "../main.c", line 33: warning #225-D: function "printf" declared implicitly

    You have to include <stdio.h>.  Please go here.

    Yura Secret said:
    warning #10247-D: creating output section ".cio" without a SECTIONS specification

    You have to explicitly control where this section goes in memory.  Please go here.

    Yura Secret said:
    warning #10210-D: creating ".esysmem" section with default size of 0x400; use the -heap option to change the default size

    You have to explicitly size this section, and control where it goes in memory.  Please see this.

    Thanks and regards,

    -George

  • Dear George Moskov.
    I have no problem to use "printf" and "heap memory".
    I have a problem in the code generation under cyclic call "Temp- = A [j] * B [ij-1];" using optimization level 2 and level 3.

    C2000 Compiler->Optimization->Optimization level-> 2 Global Optimizations (and above)

    Instead "Temp- = A [j] * B [ij-1];" getting "Temp+ = A [j] * B [ij-1];"

  • Thank you for reporting the compiler options. I am able to reproduce the problem, and have submitted SDSCM00051506 to track this issue.