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.

TMS320F28375D: INT16/INT32 multiplication by “-1”

Part Number: TMS320F28375D

We have question about INT16/INT32 multiplication by “-1” but given by minimum negative number:

Is this CPU limitation or compiler error that result value is not changed ?

 

PS.

In limits.h we have minimum values for 16 bits:

 

#define SHRT_MIN      (-SHRT_MAX-1)      /* MIN VALUE FOR SHORT              */

#define SHRT_MAX             32767       /* MAX VALUE FOR SHORT              */

 

and for 32 bits:

 

 

#define INT_MIN         (-INT_MAX-1)     /* MIN VALUE FOR INT                */

#define INT_MAX         2147483647       /* MAX VALUE FOR INT                */

  • Is this CPU limitation or compiler error that result value is not changed ?

    But what result are you expecting?

    I hope you can see that the result of val = val * -1 might be unexpected because its value exceeds SHRT_MAX. i.e. -32768 x -1 = 32768 but 32768 is greater than 32767 so the "usual" on-paper result cannot be stored. The question is: what do you expect the CPU to do in this circumstance?

    In the case of val = val * (-1); the compiler will use the NEG AX instruction. In the CPU instruction manual, it says that if the initial value is -32768 (0x8000) then the result is unchanged but an overflow is indicated.

    So there is no error. The behaviour you see is the behaviour defined by the CPU.

  • Kier,

    Thanks! This clears it up.

    Jason