Jump to content

solve before with size of dynamic array


Recommended Posts

In this following code example,

class test;
rand bit [7:0] da[];
rand int unsigned len;
constraint cst_len { len inside { 2, 4, 8 }; }
constraint cst {
da.size == len;
solve len before da.size;
}
endclass

The issue is from "solve len before da.size".

It was working with some simulator. Now it stops working on the uvm platform with all simulators.

The intent is clear: find out the len value first and allocate that amount of memory and produce random number for each array element.

So the question we have:

1) is it legal sv code?

2) is it really necessary?

Edited by Robert.g.Liu
Link to comment
Share on other sites

Robert,

If you don't need constraints on the payload/dynamic array contents, a better approach would be to use the simple $urandom as below:

class test;

bit [7:0] da[];

rand int unsigned len;

constraint cst_len { len inside { 2, 4, 8 }; }

function void post_randomize;

da = new[this.len];

foreach (da )

da = $urandom;

$display ("%p", this);

$display ("da.size: %0d", da.size);

endfunction : post_randomize

endclass : test

program p;

test t0;

initial begin : test

t0 = new;

a1: assert (t0.randomize);

end : test

endprogram : p

HTH,

Ajeetha, CVC

www.cvcblr.com/blog

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...