Sunday, 28 January 2018

Automatic/Static Variables and Function/Task with Automatic Lifetime in SystemVerilog

Before going into static and automatic variable let’s first go through 2 important terminology and then will go through automatic and static.

Scope:
Scope is the region or section of code where a variable can be accessed.
Variables declared inside a module, interface, program, or checker, but outside a task, process, or function, are local in scope.

Lifetime:
Lifetime is the time duration where an object/variable is in a valid state.
Variables declared outside a module, program, interface, checker, task, or function are local to the
compilation unit and have a static lifetime (exist for the whole simulation).
Variables declared inside a static task, function, or block are local in scope and default to a static lifetime.

Specific variables within a static task, function, or block can be explicitly declared as automatic. Such
variables have the lifetime of the call or block and are initialized on each entry to the call or block.
---------------------------------------------------------------------
---------------------------------------------------------------------
Result:
---------------------------------------------------------------------
---------------------------------------------------------------------


Automatic Function/Task (Function/Task with Automatic Lifetime):
In Verilog default lifetime of all the task/function is static.
Tasks and functions may be declared as automatic. Variables declared in an automatic task, function, or block are local in scope, default to the lifetime of the call or block, and are initialized on each entry to the call or block.

In other word, Automatic task/function variables cannot be accessed by hierarchical references. Automatic variables are automatically destroyed once the scope (task, function, block) in which they are created ends and regenerated when again enters into scope (task, function, block).
---------------------------------------------------------------------
---------------------------------------------------------------------


Class methods has Automatic lifetime by default:
Because of backward compatibility reason, SystemVerilog could not change the default lifetime qualifier to ‘automatic’ but since class methods were new, it changed the lifetime of all methods to be automatic.
---------------------------------------------------------------------
---------------------------------------------------------------------


The keyword ‘static’ is overloaded. There is a semantic difference between the meaning of ‘static’ used to the left of a function/task keyword and ‘static’ used to the right of the function/task keyword.

When used to the left of the function or task, ‘static’ is a class qualifier and has the same as on any static method in C++/Java. It is a method of the class type, not of an instance of a class object. Other class qualifiers are ‘local’ and ‘protected’ and along with ‘static’ are only allowed in front of methods of a class. There is no corresponding ‘automatic’ class qualifier.

When used to the right of a function or task, ‘static’ is a lifetime qualifier, with ‘automatic’ being the corresponding qualifier.

For more details refer this link.

4 comments:

  1. hi sir, your website is really super cool...i am new to this UVM platform, but i have a good hand in SYSTEMC...so can you please do a simple uvm testbench in systemc approach for the dut(fir filter) and send it to me coumarvignesh@gmail.com ...it may help me alot to proceed further ..thank you sir

    ReplyDelete
  2. Alright...

    This might sound really creepy, maybe even kind of "out there"....

    HOW would you like it if you could just click "Play" and listen to a short, "miracle tone"...

    And magically bring MORE MONEY to your LIFE?

    I'm talking about hundreds... even thousands of dollars!!!

    Do you think it's too EASY? Think it's IMPOSSIBLE???

    Well then, I'll be the one to tell you the news..

    Many times the largest miracles life has to offer are the EASIEST!!!

    Honestly, I'm going to PROVE it to you by letting you listen to a REAL "miracle wealth building tone" I developed...

    You just push "Play" and watch as your abundance angels fly into your life. starting pretty much right away.

    CLICK here now to PLAY this magical "Miracle Money Tone" - as my gift to you!!!

    ReplyDelete
  3. vlsi physical design training
    Vlsichip technologies provides a good platform to enhance your career in VLSI field. Faculties are very supportive here and make you learn things from scratch to higher level. Sandeep sir has a vast experience which he shares with his students and that really helped us during our interviews. Apart from teaching they also provide placement opportunities in core companies like cadence, synopsys, mentor graphics etc.

    ReplyDelete