什么是“参考在systemverilog中是什么意思? [英] What does " ref " mean in systemverilog?

查看:25
本文介绍了什么是“参考在systemverilog中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 systemverilog 中发现了这个:

I found this in systemverilog:

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

我想知道ref的用法.有什么优势?

I want to know the usage of ref. What is the advantage?

推荐答案

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

Normally, task and function arguments declared as input are copied by value upon entry to the routine, and arguments declared as output are copied by value upon returning from the routine. inout arguments are copied both upon entry and return from the routine. Arguments declared with ref are not copied but instead are references to the actual arguments used when making the call to the routine. There are much stricter data type compatibility rules when using ref arguments.

在消耗时间的任务中,可以使用 ref 而不是 inout 来捕获在任务处于活动状态时发生的值更改.请记住,inout 参数在被调用时被复制到任务中,并在任务返回时被复制出来.这是您应该尝试的示例.

In a task that consumes time, a ref can be used instead of an inout to capture value changes that occur while the task is active. Remember that an inout argument is copied into the task when it is called, and copied out when the task returns. Here is an example that you should try.

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 参数之间的区别.

See the difference between the inout and pass by ref arguments.

请注意,类变量已经是对类句柄的引用,因此通过引用传递类变量很少有任何好处.此外,在函数中,ref 参数的唯一好处可能是在传递大型数据结构(如数组)而不是使用 inputoutput,或<代码>输入.

Note that a class variable is a reference to a class handle already, so passing a class variable by reference rarely has any benefit. Also, in a function, the only benefit of a ref argument might be performance in passing large data structures like an array instead of using an input, output, or inout.

这篇关于什么是“参考在systemverilog中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆