我使用此代码等待特定的模拟时间
initial begin
$display("A");
wait($time>1000);
$display("B");
end
模拟结果是:
A
我没看到B
打印出来。
如果我使用以下代码,则可行。
while($time <1000) #1;
是不是因为一旦条件语句中的任何可变条件发生变化,vcs需要判断等待条件,$ time变化太频繁,所以vcs不允许这种用法?
@Tudor的回答启发我。我尝试了@Tudor的代码进行了一些修改。事实证明,wait(func(arglist));
vcs仅在arglist更改时重试评估函数。因为$ time没有args,vcs只会在第一次评估$ time,不会重试。
module top;
int the_time = 0;
int in_arg = 0;
function int the_time_f(int in);
return the_time;
endfunction // the_time_f
initial begin
$display("A");
// This works because 'the_time' is a variable
//wait(the_time > 10);
// This doesn't work because 'the_time_f' is a function
wait(the_time_f(in_arg) >10);
$display("B at %t", $time);
end
initial begin
#10ns;
the_time = 11;
#10ns;
in_arg = 1;
#20ns;
$finish();
end
endmodule // top
得到以下结果
A
B at 20ns
答案 0 :(得分:4)
这似乎是标准中的灰色区域。在IEEE Std 1800-2012标准的 9.4程序时序控件部分中,提到事件控制可以是隐式的(更改网络或变量)或显式的(类型event
的字段) 。 $time
是一个系统函数,而不是一个变量。我也尝试使用wait
的函数,它也不起作用:
module top;
int the_time = 0;
function int the_time_f();
return the_time;
endfunction // the_time_f
initial begin
$display("A");
// This works because 'the_time' is a variable
//wait(the_time > 10);
// This doesn't work because 'the_time_f' is a function
wait(the_time_f() > 10);
$display("B");
end
initial begin
#10ns;
the_time = 11;
#20ns;
$finish();
end
endmodule // top
等待更改变量工作正常,但等待函数返回值的更改不起作用。恕我直言,编译器应该将此标记为编译错误(使用$time
相同),因为它似乎只是忽略该语句。
答案 1 :(得分:3)
在挂起进程的事件控件@(expression)
或wait(expression)
中,SystemVerilog调度语义需要一个事件来评估表达式(称为评估事件。请参阅 4.3事件模拟 1800-2012 LRM的>如果表达式包含一个函数,则只有该函数的参数可见才能导致事件评估(在写入方法中对象的任何成员时,类方法存在异常调用将导致事件)请参阅 9.4.2事件控制
在事件驱动模拟中,时间的值只是当前时间段的一个属性,它永远不是一个事件。模拟器处理队列中当前时隙的所有事件,当该队列为空时,它将时间推进到下一个时隙队列。因此它可以模拟时间段0,5,7,10,跳过未提及的时间。使用while
循环,这将为0到1000之间的每个连续时间单位创建一个时间段 - 非常低效。
所以只需使用
#(1000); // wait for 1000 relative time units