System verilog 什么是;参考「;在systemverilog中是什么意思?

System verilog 什么是;参考「;在systemverilog中是什么意思?,system-verilog,System Verilog,我在systemverilog中找到了这个: task automatic xxx(ref xxxpackage bus,input interface ift); 我想知道ref的用法。优点是什么?Aref参数是通过引用传递的变量。这种类型的参数不是副本,而是对原始变量的引用 通过引用传递的参数不会复制到子例程区域,而是将对原始参数的引用传递给子例程。然后,子例程可以通过引用访问参数数据 从中的第13.5.2节开始通常,声明为输入的任务和函数参数在进入例程时按值复制,声明为输出的参数在从例程

我在
systemverilog
中找到了这个:

task automatic xxx(ref xxxpackage bus,input interface ift);

我想知道
ref
的用法。优点是什么?

Aref参数是通过引用传递的变量。这种类型的参数不是副本,而是对原始变量的引用

通过引用传递的参数不会复制到子例程区域,而是将对原始参数的引用传递给子例程。然后,子例程可以通过引用访问参数数据


从中的第13.5.2节开始

通常,声明为
输入
的任务和函数参数在进入例程时按值复制,声明为
输出
的参数在从例程返回时按值复制<代码>输入输出参数在输入和从例程返回时都会被复制。使用
ref
声明的参数不会被复制,而是对调用例程时使用的实际参数的引用。在使用ref参数时,有更严格的数据类型兼容性规则

在消耗时间的任务中,可以使用ref而不是inout来捕获任务处于活动状态时发生的值更改。请记住,inout参数在调用时复制到任务中,在任务返回时复制出来。下面是一个你应该尝试的例子

module top;
logic A,B;
task automatic mytask(inout logic arg1, ref logic arg2);
  #0 $display("%m %t arg1 %b arg2 %b",$time,arg1,arg2);
  // actual arguments have been set to 0
  #5 $display("%m %t arg1 %b arg2 %b",$time,arg1,arg2);
  #0 arg1 = 1; arg2 = 1;
  #5 $display("%m %t arg1 %b arg2 %b",$time,arg1,arg2);
endtask
initial #1 mytask(A,B);
initial begin
       A = 'z; B ='z;
       #2 A = 0; B = 0; // after call 
       // arguments have been set to 1
       #5 $display("%m %t A %b B %b",$time,A ,B);
       #5 $display("%m %t A %b B %b",$time,A ,B);
end
endmodule
查看
inout
和pass-by
ref
参数之间的差异


请注意,类变量已经是对类句柄的引用,因此通过引用传递类变量很少有任何好处。另外,在函数中,
ref
参数的唯一好处可能是传递大型数据结构(如数组)的性能,而不是使用
输入
输出
,或
输入
,,下面是DAVE给出的示例的解释。非常感谢戴夫的例子

module top;
logic A,B;
task automatic mytask(inout logic arg1, ref logic arg2);
  #0 $display("%m %t arg1 %b arg2 %b",$time,arg1,arg2);
  // actual arguments have been set to 0
  #5 $display("%m %t arg1 %b arg2 %b",$time,arg1,arg2);
  #0 arg1 = 1; arg2 = 1;
  #5 $display("%m %t arg1 %b arg2 %b",$time,arg1,arg2);
endtask
initial #1 mytask(A,B);
initial begin
       A = 'z; B ='z;
       #2 A = 0; B = 0; // after call 
       // arguments have been set to 1
       #5 $display("%m %t A %b B %b",$time,A ,B);
       #5 $display("%m %t A %b B %b",$time,A ,B);
end
endmodule

/*Both the two 'initial' statements are running simultaneously*/
/* 1) At time t=0 A and B are set to z by second initial statement
   2) At time t=1 mytask(A,B) is called by first initial 
      statement, 
      the first display statements displays arg1 and arg2 =z as 
      set by A and B.
   3) t=3 the second initial statement sets A=0 and B=0, but only  
      A=0 is passed to arg 1 in the ongoing task since it is
      passed by reference, whereas B=0 can only be passed at the
      starting or the end of the task since it is passed by value 
      hence arg2 remains z.
   4) inside the task--At t=6 values of arg1 and arg2 are 
      displayed
   5) at t=6 the values of arg1 and arg2 are made 1.
   6) in the second initial statement at t=7 values of A and B
      is displayed, since arg2 is passed through reference
      therefore it becomes 1, whereas A remains zero until the end of
   the task.
   7) at t=11 the values of arg1 and arg2 are displayed. -- task 
      ends.
   8) Since the task is ended arg2 value is passed to B and is 
      displayed by the second initial statement at t=12. 
   */

我已经根据内核中显示的输出和计时进行了解释,这显示了希望。这有帮助。

谢谢。请告诉我何时应该使用pass-by-reference和val?保留pass-by-value。你最终会明白什么地方需要通过引用传递。你能告诉我为什么z 0会转到0 1吗?如果可以,你能一步一步地告诉我吗?我一点也不明白这个例子的意义。我无法理解你的解释。那么有什么特殊情况吗?您可以在我上面写的标准部分中获得更多信息。有一些有用的例子可以帮助你理解这个概念。