循环内非阻塞语句之前和之后的延迟有什么区别?
这两个代码片段有什么区别?
always @(posedge clk) begin
r3 <= @(posedge clk) 1;
r2 <= @(posedge clk) 1;
ready = 0;
while (r2 <= n) begin
r2 <= @(posedge clk) r2 + 1; <--- never stops executing
end
end
always @(posedge clk) begin
r3 <= @(posedge clk) 1;
r2 <= @(posedge clk) 1;
ready = 0;
while (r2 <= n) begin
@(posedge clk) r2 <= r2 + 1; <--- normally executes
end
end
what is the difference between this two code snippets?
always @(posedge clk) begin
r3 <= @(posedge clk) 1;
r2 <= @(posedge clk) 1;
ready = 0;
while (r2 <= n) begin
r2 <= @(posedge clk) r2 + 1; <--- never stops executing
end
end
always @(posedge clk) begin
r3 <= @(posedge clk) 1;
r2 <= @(posedge clk) 1;
ready = 0;
while (r2 <= n) begin
@(posedge clk) r2 <= r2 + 1; <--- normally executes
end
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当模拟器执行
r2 <= @(thoughtge clk) r2 + 1
时,它执行以下步骤:r2 + 1
当模拟器执行
@(thoughtge clk) r2 <= r2 + 1
时,它会执行以下步骤:always
处理并安排其r2 <= r2 + 1
NBA,执行以下操作:r2 + 1
第一种形式解析为非阻塞分配,并在零时间内执行。延迟仅适用于 NBA 执行时生成的更新事件。第二种形式解析为语句延迟控制,后跟 NBA。它不会在零时间内执行,因为延迟适用于语句的执行而不仅仅是更新事件。
第一种形式是无限循环,因为
while
循环体在零时间内执行,并且将增加r2
的事件安排在未来的时间。对于第二种形式,当循环终止时,您仍然需要注意边界条件。在安排将
r2
设置为n + 1
的更新后,在应用该更新之前,条件将再次评估为 true。When the simulator executes
r2 <= @(posedge clk) r2 + 1
, it performs the following steps:r2 + 1
When the simulator executes
@(posedge clk) r2 <= r2 + 1
, it performs the following steps:always
process and schedule it to resume at the next posedge clkr2 <= r2 + 1
NBA, by doing the following:r2 + 1
The first form parses as a non-blocking assignment, and executes in zero time. The delay only applies to the update event generated when the NBA executes. The second form parses as a statement delay control followed by an NBA. It does not execute in zero time because the delay applies to the execution of the statement rather than just the update event.
The first form is an infinite loop because the body of the
while
loop executes in zero time and the events that will incrementr2
are scheduled for a future time.With the second form, you will still want to be careful about boundary conditions when the loop terminates. After scheduling an update that sets
r2
ton + 1
, the condition will evaluate as true one more time before that update is applied.