I got an error when assign value larger than (231 - 1) to array size of new[] operator in dynamic array.
*** Error: Array size passed to ‘new’ must be an integral value between 0 and 2147483647 (231 - 1).
class packet ;
int unsigned length;
bit [7:0] payload[];
constraint len_c {
length[1:0] == 2'b00
};
function void post_randomize();
payload = new[length]; // -> Error here
/* Create data for payload */
endfunction
endclass
module top;
packet pkg;
initial begin
pkg = new();
if (! pkg.randomize() with {
length == 32'hFFFF_FFFC;
} ) $display("Cant Randomize!");
/* To do something */
end
endmodule
Could you please help me for this situation ?
Whether anyone have any solution to solve how to assign a large value to array size in dynamic array ?
Typically tools will have some limitations to prevent the user from causing issues by using all of the system memory.
Do you really want a dynamic array of 2 Billion bytes? The storage required for this will be very large and the performance will be extremely poor. You cannot effectively use an array of this size.
I strongly recommend cgales advice about use your tool’s coverage capabilities to collect toggle coverage.
Regardless of how you collect coverage, you would want to use an associate array to model a 2GB memory. They only allocate array elements that are explicitly written to. Any test that you could run would only have enough time to use a tiny fraction of the array, and that all you need to toggle a 32-bits of an address register.
Do you want to check that each individual bit toggles
No, I don’t.
Exactly, I want to check toggle for variable length[31:28], so I need to expand array size in dynamic array.
typedef bit [30:0] address_t; // 2GB needs 31 address bits
bit [7:0] memory[address_t] = '{default:0}; // any element you read that has not been written yet
// returns this default value without having to allocate it