ljepson74 Posted January 23, 2016 Report Share Posted January 23, 2016 Yesterday, I learned that when randomize is called, all active constraints in the scope must be met ... even if you are passing a specific member as an argument to the randomize call. i.e. If you try to randomize a specific class member by passing it to the randomize call, like this: randomize(var2), all constraints in the scope of the randomize must still be met, even if they have nothing to do with the member being randomized. ***Someone please jump in if I phrased that poorly or am incorrect. In the below example there are two variables and a constraint on one. Uncommenting the line that causes the constraint on var1 to be violated will cause the later call to randomize to fail, even though it is passed an argument (var2) that has nothing to do with var1. class showit; rand int var1; rand int var2; constraint c_1 { var1<100; } endclass ////////////////////////////////////// module top; showit showit; initial begin showit=new(); //showit.var1=101; UNCOMMENT ME, PLEASE FOR FAIL as_myassert : assert(showit.randomize(var2)) begin $display("\n********** Victory : var2=%0d var1=%0d \n",showit.var2, showit.var1); end else begin $display("\n********** Defeat : var2=%0d var1=%0d \n",showit.var2, showit.var1); end end endmodule : top Pass result: ********** Victory : var2=-1424717967 var1=0 Fail result: ********** Defeat : var2=0 var1=101 I now understand randomize better. I had thought that only the constraints that pertained to the items being randomized were relevant. Quote Link to comment Share on other sites More sharing options...
Logger Posted January 28, 2016 Report Share Posted January 28, 2016 Bonus points for testing what happens when you change the constraint to the following: constraint c_1 { soft var1<100; } ljepson74 1 Quote Link to comment Share on other sites More sharing options...
ljepson74 Posted January 29, 2016 Author Report Share Posted January 29, 2016 Awesome. +2pts for Logger. Thanks a lot, that is great to know about. I'll be using it. re: Section 18.5.14 Soft constraints (from 1800-2012.pdf) Quote Link to comment Share on other sites More sharing options...
Cassandra Posted January 7, 2018 Report Share Posted January 7, 2018 I just came across this thread and thought I'd add something just for fun. If you change the code to this: class showit; rand int var1; rand int var2; constraint c_1 { var1 == 1; } // <----- here endclass It fails too (without the uncommenting). That's because by using only var2 in the randomize, you turn off random for the other vars; rand_mode (0) on var1. Because var1 comes up 0, and 0 < 100, it is fine with that. So it's not 'showit.var1 = 101' that causes the problem, it's 'showit.var1 = any non Zero value'. Change again to class showit; rand int var1 = 1; // <------here rand int var2; constraint c_1 { var1 = 1; } endclass and it 'passes', albeit boringly so. 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.