SystemVerilog 在写入时钟块之前进行计算

问题描述

我有一个任务,它的工作是通过时钟块将数据驱动到总线上。见片段:

task effects_driver::ReadQueueData();
  stream_intf_.cycles(); // clocking block event
  if (sample_q_.size() >= 2) // check to see if there is enough data in the queue
    begin
      automatic bit [31:0] sample0,sample1;
      sample0 = sample_q_.pop_front(); // read from queue
      sample1 = sample_q_.pop_front(); // read from queue
      stream_intf_.cb.AXIS_TDATA <= {sample1,sample0}; // drive two samples at once
      stream_intf_.cb.AXIS_TVALID <= 1;
    end
  else
    ...
endtask

您会注意到我需要先从队列中读取几个项目,然后再将其写入时钟块。这是正确的方法吗?我能保证模拟器会在将自动变量写入时钟块之前对自动变量执行这些阻塞分配吗?

谢谢!

附言我偶尔会遇到这种情况——我需要在写入时钟块之前即时进行一些快速计算。

解决方法

我相信您的意思是问“我是否保证模拟器会在将自动变量写入时钟块之前对自动变量执行这些阻塞赋值?”因为这就是您的代码所做的。

答案是肯定的,保证在执行后面的语句之前完成阻塞赋值。

另请注意,无需声明具有自动生命周期的 sample0sample1,因为类方法始终具有自动生命周期。其中声明的变量是隐式自动的。