Digital Signal Processing Reference
In-Depth Information
PI = 3.1563
DataType: fixed
Data
Scaling: binary point
Signed: true
WordLength: 8
Numeric type
FractionLength: 5
RoundMode: round
OverflowMode: saturate
ProductMode: full precision
Fixed - point math
MaxProductWordLength: 128
SumMode: full precision
MaxSumWordLength: 128
CastBeforeSum: true
Figure 3.20 MATLAB support for fixed-point arithmetic
3.5.12 SystemC Support for Fixed-point Arithmetic
As with MATLAB , once a simulation is working in SystemC using double-precision floating-point
numbers, by merely substituting or redefining the same variablewith fixed-point attributes the same code
can be used for fixed-point implementation. This simple conversion greatly helps the developer to explore
a set of word lengths and rounding or truncation options for different variables by changing the attributes.
Here we look at an example showing the power of SystemC for floating-point and fixed-point
simulation. This program reads a file with floating-point numbers. It defines a fixed-point variable
fx_value in Q6.10 with simple truncation and saturation attributes. The program reads a floating-
point value in a fp_value variable originally defined as of type double, and a simple assignment of
this variable to fx_value changes the floating-point value to Q6.10 format by rounding the
number to 16 bits; and when the integer part is greater than what the format can support the value is
saturated. SystemC supports several options for rounding and saturation.
int sc_main (int argc , char *argv[])
{
sc_fixed < 16,6, SC_TRN, SC_SAT> fx_value;
double fp_value;
int i, size;
ofstream fout("fx_file.txt");
ifstream fin("fp_file.txt");
if (fin.is_open())
fin >> size;
else
cout << "Error opening input file!\n";
cout << "size = " << size << endl;
Search WWH ::




Custom Search