为什么我的 System Verilog 动态数组总和约束不起作用? (运行 在 EDA 游乐场(Aldec Tool Riviera Pro 2017)
Why is my System Verilog Dynamic Array sum constraint is not working? (Run on EDA Playground (Aldec Tool Riviera Pro 2017)
为什么我的 System Verilog 动态数组求和约束不起作用? (运行 在 EDA 游乐场(Aldec Tool Riviera Pro 2017)
//////////////////////////////////
/////========================
class c ;
string name;
rand logic [4:0] len;
rand logic [4:0] duty_cycles[];
constraint c1 { duty_cycles.size()==len; len inside {[2:5]}; solve len before duty_cycles;};
constraint c2 { duty_cycles.sum() with (int'(item)) == 20;};
function new(string name="randcreater”)
this.name=name;
endfunction
function void post_randomize ();
$display ("New rand of len %d, sum=%d",duty_cycles.size, duty_cycles.sum());
foreach(duty_cycles[i])begin $display("%d",duty_cycles[i]); end
endfunction
endclass
/////=====================
module testbench ();
c obj;
initial begin
obj = new;
repeat (10) begin
obj.randomize();
#10;
end
end
endmodule
/////////////////////////////////////
结果:
内核:len 2 的新兰特,总和= 6
内核:6
内核:0
内核:len 2 的新兰特,总和= 4
内核:2
内核:2
这是因为您的工具存在错误。 EDAPlayground 上的软件版本较旧。尝试不同的模拟器。
此外,不需要 solve len before duty_cycles;
,因为数组的大小总是在对其元素进行任何约束之前选择一个值。
为什么我的 System Verilog 动态数组求和约束不起作用? (运行 在 EDA 游乐场(Aldec Tool Riviera Pro 2017) //////////////////////////////////
/////========================
class c ;
string name;
rand logic [4:0] len;
rand logic [4:0] duty_cycles[];
constraint c1 { duty_cycles.size()==len; len inside {[2:5]}; solve len before duty_cycles;};
constraint c2 { duty_cycles.sum() with (int'(item)) == 20;};
function new(string name="randcreater”)
this.name=name;
endfunction
function void post_randomize ();
$display ("New rand of len %d, sum=%d",duty_cycles.size, duty_cycles.sum());
foreach(duty_cycles[i])begin $display("%d",duty_cycles[i]); end
endfunction
endclass
/////=====================
module testbench ();
c obj;
initial begin
obj = new;
repeat (10) begin
obj.randomize();
#10;
end
end
endmodule
/////////////////////////////////////
结果:
内核:len 2 的新兰特,总和= 6
内核:6
内核:0
内核:len 2 的新兰特,总和= 4
内核:2
内核:2
这是因为您的工具存在错误。 EDAPlayground 上的软件版本较旧。尝试不同的模拟器。
此外,不需要 solve len before duty_cycles;
,因为数组的大小总是在对其元素进行任何约束之前选择一个值。