Saturation and Wrapping
What Are Saturation and Wrapping?
Saturation and wrapping describe a particular way that some processors deal with overflow conditions. For example, the ADSP-2100 family of processors from Analog Devices® supports either of these modes. If a register has a saturation mode of operation, then an overflow condition is set to the maximum positive or negative value allowed. Conversely, if a register has a wrapping mode of operation, an overflow condition is set to the appropriate value within the range of the representation.
Saturation and Wrapping
Consider an 8-bit unsigned word with binary-point-only scaling of 2-5. Suppose this data type must represent a sine wave that ranges from -4 to 4. For values between 0 and 4, the word can represent these numbers without regard to overflow. This is not the case with negative numbers. If overflows saturate, all negative values are set to zero, which is the smallest number representable by the data type. The saturation of overflows is shown in the following figure.
If overflows wrap, all negative values are set to the appropriate positive value. The wrapping of overflows is shown in the following figure.
Note
For most control applications, saturation is the safer way of dealing with fixed-point overflow. However, some processor architectures allow automatic saturation by hardware. If hardware saturation is not available, then extra software is required, resulting in larger, slower programs. This cost is justified in some designs — perhaps for safety reasons. Other designs accept wrapping to obtain the smallest, fastest software.
The Simulink® software supports saturation and wrapping for all fixed-point data types. You can select saturation or wrapping for fixed-point Simulink blocks with the Saturate on integer overflow check box.