Hi Sundar.Originally posted in cdnusers.org by stephenh
Bear in mind that if you declare a class item as being "rand", the simulator has to generate a value for it.
Vivek's example shows one possible way to fix the data to a known value when you don't want a random value of data.
However, this can impact performance.
If you impose no constraints on the "data" item, the generator is free to just assign a totally random number to it, which is probably quite quick in terms of CPU cycles.
Once you impose constraints on "data", that forces the simulator to so more work each time you call randomize: it has to check the order of generation, then check if the control field is set to 1 or 0, then find a value of "data" that fits the constraint.
So before implementing this, ask yourself what's most important to you, and whether it's really necessary to "not generate" a value. After all, I assume you BFM (transactor) just ignores the data item if rw_wr == 0. In this case, you can safely let the generator pick any value for data, and you save some performance.
It's also generally better to avoid any constraints that are not absolutely necessary, because this might limit future reuse of the class. Always try to leave scope for customisation in anything you do :-)