by femto · 2y ago · 0 comments
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);