Jump to content
Sign in to follow this  
Robert.g.Liu

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

Share this post


Link to post
Share on other sites

1) It's not legal because size is a method, not a random variable. The solve-before constraint only works with random variables.

2) It's not needed because the ordering is already implicit. See the LRM section in iterative constraints on arrays.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×