Robert.g.Liu Posted December 20, 2012 Report Share Posted December 20, 2012 (edited) 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 December 20, 2012 by Robert.g.Liu Quote Link to comment Share on other sites More sharing options...
dave_59 Posted December 20, 2012 Report Share Posted December 20, 2012 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. Quote Link to comment Share on other sites More sharing options...
Robert.g.Liu Posted December 20, 2012 Author Report Share Posted December 20, 2012 Thanks Dave. Quote Link to comment Share on other sites More sharing options...
ajeetha.cvc Posted December 24, 2012 Report Share Posted December 24, 2012 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.