system中的"ref"是什么意思?

bun*_*nch 2 system-verilog

我发现这个systemverilog:

task automatic xxx(ref xxxpackage bus,input interface ift);
Run Code Online (Sandbox Code Playgroud)

我想知道它的用法ref.有什么好处?

dav*_*_59 13

通常,声明为的任务和函数参数input在进入例程时output由值复制,声明为的参数在从例程返回时按值复制.inout参数在进入和从例程返回时都被复制.声明的参数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
Run Code Online (Sandbox Code Playgroud)

查看inout和传递ref参数之间的区别.

请注意,类变量已经是对类句柄的引用,因此通过引用传递类变量很少有任何好处.另外,在功能,唯一的好处ref参数可能是在传递大的数据结构等的阵列,而不是使用性能input,outputinout.