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.

C6000-CGT: C6000 subtraction between int40_t and int32_t

Part Number: C6000-CGT
Other Parts Discussed in Thread: AM5729

Hi, 

I've found an issue in C6000 compiler and I want to ask you if it is a "feature" or a bug.

I want to subtract two 32bit signed numbers and because the result could be bigger than 32bit signed variable, I want to have the result in 40bit variable. Thus I have written the code below and found out that retyping 32bit signed variable to 40bit signed variable actually doesn't work.

My compiler is: C6000 8.3.11

My hardware is: AM5729 C66x core

The code below presents some ways how to subtract two numbers:

result = -1 - (-2,147,483,648) = 2,147,483,647

Please find the result values in the comments at the end of a line.

You can see that the code works if subtraction is between two int32_t numbers or between two int40_t numbers, but it doesn't work if the subtraction is between the first int40_t variable and the second int32_t variable. I guess it is because of non working retyping (int40_t)variable32bit

The code:

    int40_t result;
    int32_t a32 = 0xFFFFFFFF;
    int32_t b32 = 0x80000000;
    int40_t a40 = 0xFFFFFFFFFFi40;
    int40_t b40 = 0xFF80000000i40;

    result = a32 - b32;                     // 0x007FFFFFFF

    result = (int40_t)a32 - (int40_t)b32;   // 0x007FFFFFFF

    result = a40 - (int40_t)b32;            // 0xFF7FFFFFFF

    result = (int40_t)a32;
    result -= (int40_t)b32;                 // 0xFF7FFFFFFF

    result = a40 - b40;                     // 0x007FFFFFFF

    result = a40;
    result -= b40;                          // 0x007FFFFFFF

So, the question is if I don't understand something or it is a bug in C6000 compiler?