Hi,
the below randomization code:
class classifier_lut_cfg extends uvm_object;
rand bit [31:0] cls_out_doq_active_reg;
function void post_randomize ();
int tmp_hw2sw_ring;
std::randomize(tmp_hw2sw_ring) with {cls_out_doq_active_reg[tmp_hw2sw_ring] == 1;};
endfunction : post_randomize
gives me the following err:
“A reference to a rand variable in an array index is not currently supported in this context”
any solution/other idea of how to rand ‘tmp_hw2sw_ring’ while “cls_out_doq_active_reg[tmp_hw2sw_ring] == 1;”
In reply to yakirye:
I’m not sure why you are attempting to randomize a local variable in the post_randomize() function. Why don’t you make tmp_hw2sw_ring a class variable and randomize it with the class constraints?
In reply to cgales:
In reply to yakirye:
I’m not sure why you are attempting to randomize a local variable in the post_randomize() function. Why don’t you make tmp_hw2sw_ring a class variable and randomize it with the class constraints?
Hi, this is a very simplified part of the code as there are few reasons for it.
The ‘tmp_hw2sw_ring’ is later used as an assignment to a multidimensional array.
Why, Do you think the err is related to the fact that its a local var?
In reply to yakirye:
Without a complete example showing your issue, it’s difficult to make any recommendations.
It seems that you are trying to impose a constraint in the post_randomize() function which needs to be utilized in the main randomize() call. What about the case where cls_out_doq_active_reg is all 0’s? It is impossible to randomize tmp_hw2sw_ring to a valid value if this occurs.
If you post your entire class and what you are trying to accomplish, perhaps a better approach could be provided.
In reply to cgales:
In reply to yakirye:
Without a complete example showing your issue, it’s difficult to make any recommendations.
It seems that you are trying to impose a constraint in the post_randomize() function which needs to be utilized in the main randomize() call. What about the case where cls_out_doq_active_reg is all 0’s? It is impossible to randomize tmp_hw2sw_ring to a valid value if this occurs.
If you post your entire class and what you are trying to accomplish, perhaps a better approach could be provided.
‘cls_out_doq_active_reg’ is never zero (by constraint).
the error seems to be related to a kind of a syntax/elab issue.
unfortunally, i can’t provide the entire class as it is too sensitive…
In reply to yakirye:
The following works:
class classifier_lut_cfg;
rand bit [31:0] cls_out_doq_active_reg;
function void post_randomize ();
int tmp_hw2sw_ring;
std::randomize(tmp_hw2sw_ring) with {cls_out_doq_active_reg[tmp_hw2sw_ring] == 1;};
$display("post_randomize: cls_out_doq_active_reg is %0h, tmp_hw2_sw_ring is %0d", cls_out_doq_active_reg, tmp_hw2sw_ring);
endfunction : post_randomize
endclass
module testbench();
classifier_lut_cfg c;
initial begin
c = new();
repeat (10) begin
if (!c.randomize()) $display("Randomize failed");
else $display("Randomize success");
end
end
endmodule
If it doesn’t work for you, you likely have a tool issue and should contact your vendor.