Array
(
    [content] => 
    [params] => Array
        (
            [0] => /forum/index.php?threads/system-verilog-final-means-final.2474/
        )

    [addOns] => Array
        (
            [DL6/MLTP] => 13
            [Hampel/JobRunner] => 1030170
            [SV/ChangePostDate] => 2010200
            [SemiWiki/Newsletter] => 1000010
            [SemiWiki/WPMenu] => 1000010
            [SemiWiki/XPressExtend] => 1000010
            [ThemeHouse/XLink] => 1000670
            [ThemeHouse/XPress] => 1010394
            [XF] => 2011072
            [XFI] => 1030270
        )

    [wordpress] => /var/www/html
)

System Verilog : Final means Final !

Asic With Ankit

New member
Dear Readers,

Today I would like to share some basic things on ‘final’ block in System Verilog. This is a newly added feature in System Verilog over Verilog. Final block is good for summary information. You can have summary information printed in log file at the end of simulation.

Final block executes at the end of the simulations without delays. ‘final’ block is like an initial block in SV only difference is that it occurs at the end of the simulations. Final block does not allow delays and time consuming or blocking activities and because of this reason it typically used in display statistical information on simulation result. Final block executes in zero time. Considering this nature of execution it is similar to ‘function’.Function also executes in zero time and does not allow timing related or blocking type of activities.

Lets try to understand this with syntax:

program asic_with_ankit;
int error, warning;

initial begin
//Main program activities…..
end

final begin
$display (“Test is done with %d errors and %d warnings”, error, warning);
end
endprogram

Simulation ends means what?

Simulation ends when last initial block ends in the program. When last initial block ends, it implicitly calls $exit which tells particular program is done! When every program is completed (exited) an implicit call to $finish is done. User can call $finish any time whenever he/she wants to end the simulation.

This process does not mean that your simulation is over, a module or program can have one or more ‘final’blocks that contains code to be run just before simulator terminates/finishes.

This is a great place to perform certain activity in your simulation like:
  • Cleaning up tasks such as closing files
  • Printing reports which can have summary of number of warnings, errors etc..
  • Display statistic information about the simulation

final block can only trigger once in a simulations and because of this I name it as ‘final means final! :) you cannot call it again!

Happy Reading,
ASIC With Ankit

<script src="//platform.linkedin.com/in.js" type="text/javascript"></script>
<script type="IN/Share" data-counter="right"></script>
 
Last edited by a moderator:

LinkedIn

Active member
Narendra Varma Alluri • well , its good to have a block which is executed at the end part of simulation. But can a program have multiple final blocks?? if so , in which order will they be executed?? Will they be Triggered concurrently at the same time??
 

Asic With Ankit

New member
Hi Narendra,

Here are the answers :
1. Yes, program block can have multiple final blocks
2. and all the final blocks will be executed at the same simulation time stamp.

You can refer my recently published blog post 'which final is final'. This will help you to understand the final block execution with example.

Regards,
Ankit (ASIC With Ankit)
 
Top