Hi, I need some long long (64 bit) additions in a fast interrupt code.
After each addition, I need to limit the result to MIN/MAX_INT64 if some overflow occurred.
In assembler, I would use the brach command BVC/BVS to check the overflow flag after the addition - this would be only one additional command, very nice (in normal case, where no overflow occurs).
Is there any way to implement / insert such functionality also in C / C++ code?
I tried to include dspfncts.h, and then check the variable Overflow, but this will add 3 additional assembly lines (to load the value of the overflow bit - it does NOT use the very compact commands BVC/BVS). As I have quite many such additions, this will blow up my code quite a bit.
Is there any possibility to do this overflow check in an efficient way in C/C++?
PS: There is not possibly some pragma or so to enable "saturating add/sub"? I looked for it quite a time in the help file and google ..., I did not find anything - but this would be very smart, if I could enable and disable saturating add/sub by some pragma switch. (I do not need the saturation flag - I just want to be sure, that I avoid the nasty range flip - I use my variable ranges thus, that the probability for such a flip is nearly zero, but I cannot exclude this possibility for sure).