Are Program Blocks Necessary?

That’s a frequent SystemVerilog question I’m asked (and asked).

Program blocks came directly from donation of the Vera language to SystemVerilog by Synopsys , and try to mimic the scheduling semantics that a PLI application has interacting with a Verilog simulator.  So coming from a Vera background, program blocks make perfect sense and do help people transitioning from Vera to SV. But looking at SV from scratch, they are just extra language baggage.

Who would have ever thought we’d be having language wars within the same language! :eek:

As far as I can tell, a program block by itself only addresses two race conditions between the testbench and DUT, both of which are covered by using a clocking block by itself.

  1. Erroneous use of blocking assignments for sequential logic. You have a race within your DUT regardless of the race between your testbench and DUT.
  2. Erroneous use of non-blocking assignments in combinational gated clock logic. You may have a race within your DUT regardless of the race between your testbench and DUT.

As a user, if you don’t understand why these create races within your DUT, you’re going to have the same races within your testbench, and there’s nothing a program block does that prevent races within your testbench. There lays the false sense of security of having a race-free testbench.

Using a clocking block by itself takes care of the same testbench to DUT races that a program block addresses, plus it takes care of the races caused by non-zero delay skews introduced by gate-level propagation. It does this by the use of the input skews for sampling and output skews for driving.

Now, in addition to the false sense of security, and the redundancy with clocking blocks, here are some additional reasons why I don’t recommend using program blocks

  1. If you have legacy Verilog testbench code, sometimes you want to share legacy BFM tasks by having your “class” based testbench call those BFM tasks. You’re going to run into nasty timing problems if that task was designed to be scheduled in the active region, and now is scheduled in the re-active. Sampling will be off by a clock cycle. You’ll have even nastier problems if some tasks are called from a program block, and other are still called from a module.
  2. One person’s Design IP is another person’s Verification IP. At the system level (ESL), there is less of a distinction between models written to represent higher level abstractions of the design, versus part of a testbench. You can’t have differences in scheduling just because one time it’s called from a program, and another time it’s called from a module. Same problem with C code called from a program block or module.
  3. Unless you’re an experienced Vera user, there is the unexpected surprise that your simulation exits immediately after the thread in your program block ends. Again this is an issue with mixing legacy testbenches, or mixed-language testbenches.
  4. Most advanced users can barely understand the scheduling semantics of SystemVerilog even without using program blocks. Why introduce unnecessary complexity. Many other enviroments, like SystemC and VHDL have been in production for years without needing the kind of scheduling semantics the program block introduces. Quick quiz: How can you get an assertion pass and fail in the same time slot?

The SystemVerilog language has had many hands involved with its development, including yours and mine. I’m not dismissing anyone efforts, but sometimes you have to take a step back and realize how bloated the language has become. Just because some feature exists in the LRM doesn’t justify that it needs to be used. Let me tell you about virtual interfaces… :evil:

Dave Rich

Post Author

Posted May 7th, 2009, by

Post Tags

,

Post Comments

8 Comments

About Verification Horizons BLOG

This blog will provide an online forum to provide weekly updates on concepts, values, standards, methodologies and examples to assist with the understanding of what advanced functional verification technologies can do and how to most effectively apply them. We're looking forward to your comments and suggestions on the posts to make this a useful tool. Verification Horizons BLOG

@dennisbrophy Tweets

  • Loading tweets...

@dave_59 Tweets

  • Loading tweets...

Comments

8 comments on this post | ↓ Add Your Own

Commented on September 9, 2009 at 11:19 pm
By Sumana M

Waiting to hear about the “Virtual Interfaces” story! I’ve always found the usage of program blocks confusing in SV.

Commented on September 11, 2009 at 11:08 pm
By SystemVerilog Coding Guidelines « No Simulation

[...] the release notes for the tool(s) you are using. Finally, there are a few constructs to avoid, like program blocks and wildcard indexes for associative arrays, most of which might be worth hours of debate, [...]

Commented on September 23, 2009 at 8:19 pm
By Tony Brown

I don’t know If I said it already but …I’m so glad I found this site…Keep up the good work I read a lot of blogs on a daily basis and for the most part, people lack substance but, I just wanted to make a quick comment to say GREAT blog. Thanks, :)

A definite great read..Tony Brown

Commented on December 6, 2009 at 2:30 pm
By Syswip

Hi Dave Rich,
Very interesting article. But I’m looking forward
to read the article about Virtual Interfaces :)
Bests.

Commented on June 14, 2012 at 4:47 am
By Jimik Shah

Hi Dave Rich,

Very useful information…Thanks a lot.

Commented on August 26, 2012 at 8:01 am
By Kiran Polu

Thanks Dave Rich. Your article is very clear and pointed to the topic.

Commented on December 13, 2013 at 1:42 am
By Vineet Bhatnagar

Always had this doubt…thanks a lot !

Commented on February 24, 2014 at 10:42 pm
By Bhairava Dacha

Hi Dave,

Thank you very much for such a good article. I stuck with your quick quiz :). Can you please, let me know, how to make assertion pass and fail in same time slot.

Add Your Comment

Archives