A
atass
Guest
I'm a lazy coder and want to use the intrinsic method ".sum()" to
tabulate the total of a 2D array.
logic signed [15:0] array [0:255]; // lots of widgets!
// the old fashioned way
logic signed [31:0] sum;
for ( int i = 0; i < $size(array); ++i )
sum = sum + array;
// the new and superior way
logic signed [31:0] sum;
sum = array.sum(); // INCORRECT RESULT!
----------------
Ok, after reading Chris Spear's "Systemverilog for Verification",
there was a warning against this gotcha. Basically, ".sum()"
performs the computation with fixed-precision (the width of the
parent array.) It does not 'sign-extend' the intermediate calculations
to the full-width of the LHS (lefthand side) variable.
Is this correct? If so, why was it done this way? It feels like
the ".sum()" method is not terribly useful
tabulate the total of a 2D array.
logic signed [15:0] array [0:255]; // lots of widgets!
// the old fashioned way
logic signed [31:0] sum;
for ( int i = 0; i < $size(array); ++i )
sum = sum + array;
// the new and superior way
logic signed [31:0] sum;
sum = array.sum(); // INCORRECT RESULT!
----------------
Ok, after reading Chris Spear's "Systemverilog for Verification",
there was a warning against this gotcha. Basically, ".sum()"
performs the computation with fixed-precision (the width of the
parent array.) It does not 'sign-extend' the intermediate calculations
to the full-width of the LHS (lefthand side) variable.
Is this correct? If so, why was it done this way? It feels like
the ".sum()" method is not terribly useful