You are now following this Submission
- You will see updates in your followed content feed
- You may receive emails, depending on your communication preferences
When designing firmware with Xilinx Vivado Tool Suite (ap_fixed library) and using Matlab code as a reference model, it can be crucial to consider the rounding and saturation effects properly in Matlab. To that end, the Matlab fixed point class (fi class) may be used. However, it can be tedious to work with this class. To my knowledge, the class is no longer part of the basic Matlab license (outside toolboxes) for current Matlab versions. Additionally, the class has some drawbacks when applying standard functions such as sine / cosine.
A more pragmatic approach consists of performing all computations based on double numbers and applying the rounding and saturation effects at every step, where they occur in the firmeware. Particularly, this happens, when the result of an operation such as addition or multiplication is assigend to a variable of a narrower type.
The "Vivado Design Suite User Guide - High Level Synthesis (v2018.3)" does not provide clear understanding of all rounding and saturation effects. The behaviour of the different rounding methods has to be figured out by comparison of computation results generated by both Matlab scipts and firmware.
The package contains only 2 small files:
- roundsat.m (the actual function)
- xilinx_rounding_overview.m (a script for visualization of the rounding mehtods)
The signature of the function roundsat is as follows:
y=roundsat(x,signed,width,integer,method_round,method_sat,varargin)
Output:
y: double array after rounding and saturation operation
Input:
x: double array to be rounded and saturated
signed: signedness of the fixed point number corresponding to the result
width: width of the fixed point number corresponding to the result
integer: number of integer bits of the fixed point number corresponding to the result
method_round: 'AP_RND', 'AP_RND_ZERO', 'AP_RND_MIN_INF', 'AP_RND_INF', 'AP_RND_CONV', 'AP_TRN' or 'AP_TRN_ZERO'
method_sat: 'AP_SAT', 'AP_SAT_SYM', 'AP_SAT_ZERO' or 'AP_WRAP'
Note: 'AP_WRAP_SM' is not implemented.
varargin: optional parameter: 1 == suppress warning, 0 == don't suppress warning
If the optional parameter is not handed over or set to 0, a warning will be output, if saturation or wrapping is applied to the data. This can be helpful to identify unwanted saturation effects. Sometimes wrapping of numbers is applied intendedly, in this case the warning can be suppressed.
Cite As
Thomas Schuster (2026). Xilinx Vivado Rounding and Saturation (https://www.mathworks.com/matlabcentral/fileexchange/102119-xilinx-vivado-rounding-and-saturation), MATLAB Central File Exchange. Retrieved .
General Information
- Version 1.0.1 (2.41 KB)
MATLAB Release Compatibility
- Compatible with any release
Platform Compatibility
- Windows
- macOS
- Linux
