Mapping of Different Rounding and Overflow Methods from MATLAB to SystemC
The specified fixed-point data types in MATLAB® code are converted to SystemC fixed-point data types during code generation.
The tables show the mapping of different MATLAB fixed-point rounding and overflow methods to their equivalent SystemC methods.
Rounding Methods
MATLAB Fixed-Point Rounding Methods | Description | Equivalent SystemC 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 SystemC) |
| Rounds to the nearest representable number. |
|
Convergent | Rounds to the nearest representable number. |
|
Note
The ceiling
rounding method is not supported for SystemC code
generation.
Overflow Methods
MATLAB Fixed-Point Overflow Methods | Description | Equivalent SystemC 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 SystemC) |
The rounding and overflow methods are represented as typecasts on expressions in the generated SystemC code.
For example, consider the MATLAB function exampleFun
and the generated SystemC 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 SystemC 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); } };