循环内非阻塞语句之前和之后的延迟有什么区别?

发布于 2024-12-03 11:30:31 字数 596 浏览 1 评论 0原文

这两个代码片段有什么区别?

    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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅浅淡淡 2024-12-10 11:30:31

当模拟器执行r2 <= @(thoughtge clk) r2 + 1时,它执行以下步骤:

  • 评估r2 + 1
  • 安排非阻塞分配(NBA)更新下一个 posege clk 执行的事件

当模拟器执行 @(thoughtge clk) r2 <= r2 + 1 时,它会执行以下步骤:

  • 挂起always 处理并安排其
  • 在进程恢复时在下一个 posege clk 处恢复,执行 r2 <= r2 + 1 NBA,执行以下操作:
    • 评估r2 + 1
    • 安排当前时间的 NBA 更新活动

第一种形式解析为非阻塞分配,并在零时间内执行。延迟仅适用于 NBA 执行时生成的更新事件。第二种形式解析为语句延迟控制,后跟 NBA。它不会在零时间内执行,因为延迟适用于语句的执行而不仅仅是更新事件。

第一种形式是无限循环,因为 while 循环体在零时间内执行,并且将增加 r2 的事件安排在未来的时间。

对于第二种形式,当循环终止时,您仍然需要注意边界条件。在安排将 r2 设置为 n + 1 的更新后,在应用该更新之前,条件将再次评估为 true。

When the simulator executes r2 <= @(posedge clk) r2 + 1, it performs the following steps:

  • evaluate r2 + 1
  • schedule a non-blocking assignment (NBA) update event to be executed at the next posedge clk

When the simulator executes @(posedge clk) r2 <= r2 + 1, it performs the following steps:

  • suspend the always process and schedule it to resume at the next posedge clk
  • when the process resumes, execute the r2 <= r2 + 1 NBA, by doing the following:
    • evaluate r2 + 1
    • schedule an NBA update event for the current time

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 increment r2 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 to n + 1, the condition will evaluate as true one more time before that update is applied.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文