Re:Two's complement integers with only sign bit set should b...
by Stenzel on Wednesday February 07, 2024 @04:40AM
(#39286474)
Processors with saturating capabilities usually clip at 0x7FFFFFF and 0x80000000, so the clipping thing has no relation to the original topic. But in fixpoint DSP, 0x8000 (add trailing zeros if you like) is often the only possibility to achieve a multiplicative identity by using a = - b * 0x8000, with the negation part of the assembly instruction.
The normal way to do it is to use the "ETSI Basic Operator" library, which provides saturating arithmetic operations, among other things [1]. If the hardware supports saturated arithmetic the compiler maps the operations to the relevant instructions, otherwise it provides a software implementation.
Example:
Modulo arithmetic: int16_t a,b,c; a = b + c;
Saturating 16-bit arithmetic using ETSI: int16_t a,b,c; a = add(b, c);
[1] https://www.itu.int/rec/T-REC-G.191/en