I found this in systemverilog
:
task automatic xxx(ref xxxpackage bus,input interface ift);
I want to know the usage of ref
. What is the advantage?
I found this in systemverilog
:
task automatic xxx(ref xxxpackage bus,input interface ift);
I want to know the usage of ref
. What is the advantage?
A ref argument is a variable passed by reference. This type of argument are not a copy but a reference to the original variable.
From section 13.5.2 in IEEE Std 1800-2012.
Hey bunch here's the explanation of the example that DAVE gave. Thanks a lot for the example Dave.
I have explained as per the output displayed in the kernel and timing it shows hope this helps.
Normally, task and function arguments declared as
input
are copied by value upon entry to the routine, and arguments declared asoutput
are copied by value upon returning from the routine.inout
arguments are copied both upon entry and return from the routine. Arguments declared withref
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.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.
See the difference between the
inout
and pass byref
arguments.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 aninput
,output
, orinout
.