SystemVerilog randomize address equal to 2 to the power of value?
addr = 1, 2, 4, 8, 16, … 32,
I am generation above values using systemverilog constraints
below is the code:
class two_power_addr;
rand bit [14:0] addr;
bit [14:0] temp;
constraint c_addr {addr == temp;}
endclass
module tb();
two_power_addr c;
initial
begin
c=new();
c.temp=16'h1;
for(int i=0; i<15; i++) begin
c.randomize();
c.temp=c.temp<<1;
$display("%0d \n", c.addr);
end
end
endmodule
Instead of above the above constraint i am replacing below like this
class two_power_addr;
rand bit[14:0] addr;
rand bit[14:0] temp;
constraint c_addr {temp == 2**addr;}
endclass
module tb();
two_power_addr c;
initial
begin
c=new();
repeat(20) begin
c.randomize();
c.randomize()with {addr<8;};
$display("%0d \n", c.temp);
end
end
endmodule
both are working fine.
my doubt is instead of 2 to the power i am replacing 10 than it is showing error below like this
means i am changing constraint like this constraint c_addr {temp == 10**addr;}
Error-[IUORCE] Illegal operator in constraint
testbench.sv, 4
$unit, “(10 ** this.addr)”
The operator ** is not allowed in constraints.
Remove the operator or replace it with an expression allowed in constraints.
please provide the solution for above issue
Please use code tags making your code easier to read. I have added them for you.
This error message is incorrect—there is no such restriction. There’s even examples using it in the LRM. This Mentor sponsored public forum is not for discussing tool specific issues. Please read you tool’s user manual or contact your tool vendor directly for support.
class two_power_addr;
rand bit [14:0] addr;
bit [14:0] temp;
constraint c_addr {temp == 3**addr;}
endclass
module tb();
two_power_addr c;
initial
begin
c=new();
for(int i=0; i<3; i++) begin
c.randomize();
$display("output is %0d \n", c.addr);
end
end
endmodule
Hi Dave,
Is this what you are suggesting for power of 3?
I tried with Mentor Questa but it is not giving me expected output. Mostly incorrect logic.