我想知道为什么在下面的例子中,RNG的状态没有被保存下来。
module test;
string Seed_s = "0";
int unsigned Seed_i = 0;
initial
begin
process p;
p = process::self();
$display("Process randstate1 = ", p.get_randstate());
Seed_s = p.get_randstate();
$display("Process Seed_s = %s", Seed_s);
Seed_i = Seed_s.atobin();
$display("Process Seed_s = %s", Seed_s);
$display("Process randstate2 = %d", Seed_i);
p.set_randstate(Seed_s);
$display("Process randstate3 = ", p.get_randstate());
end
endmodule
这是输出结果
Process randstate1 = 0000000000000000000000000000000000001001011001101001101001011110
Process randstate2 = 157719134
Process randstate3 = 0X1Z00ZZXZX011Z00X0ZX01XZXZ0X111XZZXZZZXZXZXZZXZZZZXZZZZXXXXXXXX
我希望看到randstate1 = randstate3. 我在这里遗漏了什么?
EDIT:在atobin()前后添加了一个显示字符串。
Process randstate1 = 0000000000000000000000000000000000001001011001101001101001011110
Process Seed_s = 0000000000000000000000000000000000001001011001101001101001011110
Process Seed_s = 0000000000000000000000000000000000001001011001101001101001011110
Process randstate2 = 157719134
Process randstate3 = 0X1Z00ZZXZX011Z00X0ZX01XZXZ0X111XZZXZZZXZXZXZZXZZZZXZZZZXXXXXXXX
你的代码在Questa中工作正常,产生了以下输出
# Process randstate1 = MS47527bb5f9e2c20661d2ea9091ed841d
# Process randstate2 = 0
# Process randstate3 = MS47527bb5f9e2c20661d2ea9091ed841d
我猜测你的模拟器在执行以下操作时出现了错误 Seed_s.atobin();
我将显示 Seed_s
之前和之后。
这看起来像是模拟器的bug。 你用的是什么模拟器?
当我创建您的代码的简化版本,并用Cadence Incisive模拟器运行它时,我得到的前后状态是一样的。set_randstate
:
module tb;
string Seed_s;
initial begin
process p;
p = process::self();
$display("Process randstate = ", p.get_randstate());
Seed_s = p.get_randstate();
p.set_randstate(Seed_s);
$display("Process randstate = ", p.get_randstate());
end
endmodule
输出。
Process randstate = svseed=1 ; 3130931317 ;
Process randstate = svseed=1 ; 3130931317 ;
当我使用Synopsys VCS运行时,我得到的结果与你的相似。