We have noticed incorrect code generation when optimization -O3 switched on. The problem disappears when the optimization is changed to -O0. We use the FPU. When a float value is converted first to unsigned int and then to signed int (or first to signed and then to unsigned), then the second conversion is incorrect. This behaviour was observed both with 6.0.1 and 616.6.0 tools.
* F32TOI32 / F32TOI16 instruction is used for conversion to unsigned int
* F32TOUI32 / F32TOUI16 instruction is used for signed int.
An example
float TST_fVar = -2.0; /* 32 bit float */ int TST_nVar; /* 16 bit signed int */ unstigned int TST_wVar; /* 16 bit unsigned int */
void error_demo1( void )
{
TST_wVar = (unsigned int)TST_fVar; /* TST_wVar == 0 (ok) */
TST_nVar = (int)TST_fVar; /* TST_nVar == 0 (!!!) */
}
void error_demo2( void )
{
TST_nVar = (int)TST_fVar; /* TST_nVar == -2 (ok) */
TST_wVar = (unsigned int)TST_fVar; /* TST_wVar == 0xFFFD (!!!) */
}
When (float)-2.0 is converted to (int)0, there is no workaround ...