This is a function for addition with saturation, given by a third party:
/*
* operation: s32 + s32
* saturation: Yes
* rounding mode: N/A
*/
inline int32_T c28x_add_s32_s32_s32_sat(int32_T a, int32_T b)
{
int32_T result;
asm(" SETC OVM");
result = a + b;
asm(" CLRC OVM");
return result;
}
It will not return correct results if -O1-4 is enabled, because the addition is not performed between SETC OVM and CLRC OVM. I suppose the compiler is free to move these statements around.
- Where is this behavior documented?
- Do you have a suggested workaround?