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.
Tool/software: TI C/C++ Compiler
Looking for help understanding the compilers use of SUBL with 32-bit unsigned math.
This is a system where it is desired to set OVM once globally for all signed math operations. However, the surprise is that SUBL is being used with unsigned operations and signed saturation is applied to the unsigned math.
For example
unsigned long global_A, global_B, global_C;
main()
{
asm (" SETC OVM");
global_A = 0x7fffffffUL;
global_B = 0x80000000UL;
global_C = global_B-global_A;
}
the operation will use SUBL instead of SUBUL and produces erroneous results due to sign context with unsigned variables. With SUBL, Overflow will be treated as signed math with saturation at 0x7fffffff and 0x80000000. This seems strange. Since the core doesn't support an unsigned OVM mode with 0xffffffff and 0x00000000 saturation, why does the compiler choose SUBL instead of SUBUL for these operations?
Understand that SUBUL has an intended use with 64-bit math (SUBUL/SUBBL), and also that the user must manage OVM appropriately (This can be worked around by selectively applying OVM). However, looking for the rationale behind this. The docs don't provide any clear warnings about this potential case.
v16.9.1.LTS. Haven't tried 17.9
Regards,
Eric
Eric Best said:This is a system where it is desired to set OVM once globally for all signed math operations.
Unfortunately, this is not supported. Please see the section titled Status Registers in the C28x compiler manual. It shows that OVM is presumed to be 0. It must be 0 when a C function starts, or upon return from any function (whether C or assembly) called by C function. While executing a hand-coded assembly function, OVM can be changed to 1, but it must be restored back to 0 before control changes to a C function.
Thanks and regards,
-George