Mapping of Different Rounding and Overflow Methods from MATLAB to HLS
The specified fixed-point data types in MATLAB® code are converted to High-Level Synthesis (HLS) fixed-point data types during code generation.
The tables show the mapping of different MATLAB fixed-point rounding and overflow methods to their equivalent HLS methods.
Rounding Methods
MATLAB Fixed-Point Rounding Methods | Description | Equivalent HLS Fixed-Point Rounding Methods |
---|---|---|
(default for MATLAB) | Rounds to the nearest representable number. |
|
| Rounds to the nearest representable number in the direction of zero. |
|
| Rounds to the nearest representable number in the direction of negative infinity. Equivalent to two's complement truncation. |
(default for HLS) |
| Rounds to the nearest representable number. |
|
Convergent | Rounds to the nearest representable number. |
|
Note
The ceiling
rounding method is not supported for HLS code
generation.
Overflow Methods
MATLAB Fixed-Point Overflow Methods | Description | Equivalent HLS Fixed-Point Overflow Methods |
---|---|---|
(default for MATLAB) | Saturate to maximum or minimum value of the fixed-point range on overflow. |
|
| Wrap on overflow. This mode is also known as two's complement overflow. |
(default for HLS) |
The rounding and overflow methods are represented as typecasts on expressions in the generated HLS code.
For example, consider the MATLAB function exampleFun
and the generated HLS code to
understand the conversion of rounding and overflow methods.
MATLAB Code
function y = exampleFun(a, b) y = fi(a + b, 1, 5, 2, fimath('RoundingMethod','Nearest','OverflowAction','Saturate')); end
Generated HLS Code
class exampleFunClass { public: sc_fixed<5,3> exampleFun(sc_fixed<7,3> a, sc_fixed<7,3> b) { return (sc_fixed<5,3,SC_RND,SC_SAT>)((sc_fixed<8,4>)a + (sc_fixed<8,4>)b); } };