What is the best (cleanest, most efficient) way to write saturating addition in C?
The function or macro should add two unsigned inputs (need both 16- and 32-bit ver
I suppose, the best way for x86 is to use inline assembler to check overflow flag after addition. Something like:
add eax, ebx jno @@1 or eax, 0FFFFFFFFh @@1: .......
It's not very portable, but IMHO the most efficient way.