ssingh Posted October 10, 2012 Report Share Posted October 10, 2012 While generating constrained random data, how can we ensure that a given value is not generated more than once? I want to generate unique addresses for my write sequence to memory. Quote Link to comment Share on other sites More sharing options...
whiteriver Posted October 10, 2012 Report Share Posted October 10, 2012 (edited) Try reading about randc in systemverilog documentation. I never had to use, but I guess you could use something like: <inside sequence class> randc bit [7:0] address; virtual task body(); <loop> void'(this.randomize()); `uvm_do_with(req, {req.addr == address;}) </loop> ... the randc generates a random value sequence without repeating any value. After all possible values are met, it generates a new random sequence. Edited October 10, 2012 by whiteriver Quote Link to comment Share on other sites More sharing options...
ssingh Posted October 11, 2012 Author Report Share Posted October 11, 2012 1. randc has a limitation of 16 bits. 2. randc does not generate same data in one cyclic iteration between lower bound and upper bound of the address. But if the simulator leaps by big margin and finishes one cycle, it can generate the same value in next iteration. Quote Link to comment Share on other sites More sharing options...
whiteriver Posted October 11, 2012 Report Share Posted October 11, 2012 to the limitation 1: then, what about using the randc as a seed to each value generated? it would be something like: <inside sequence class> randc bit [15:0] addr_seed; bit [31:0] addr_to_send; virtual task body(); <loop> void'(this.randomize()); addr_to_send = $random(addr_seed); `uvm_do_with(req, {req.addr == addr_to_send;}) </loop> ... it will generate 32-bit values, the only implication is that it is limited to 2^16 possible values. Which brings to your second statement. I don't know how to solve it. But you can hack and create a sequence of seeds: int seeds = 0; <outer repeat loop> <inner repeat loop 2^16 -1 times> addr_to_send = $random((addr_seed<<16*seeds)); `uvm_do_with... </inner repeat> seeds+1; </outer repeat> which then has the limitation of 2^17 possible values (2x outer loop). Quote Link to comment Share on other sites More sharing options...
ssingh Posted October 11, 2012 Author Report Share Posted October 11, 2012 I don't want to be limited to 2^16 possible values. I got one more possible solution on another forum: You can have a queue of addresses that you have written to, and have a constraint rand unint64 address; uint64 list[$]; constraint not_in_list {!(address inside {list};} function void post_randomize() list.push_back(address); endfunction Thank you for your suggestion. Quote Link to comment Share on other sites More sharing options...
whiteriver Posted October 12, 2012 Report Share Posted October 12, 2012 that is a great approach. I will add this to my notes. OTOH, the bigger the list, more time the simulator takes to resolve the constraint. 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.