31616

Event scheduling in Verilog

Question:

I was learning about the verilog stratified event queue. I had a minor doubt about the inactive events. I understood that they are carried out after all the active events are done with at the current simulation time. But I wrote a simple code to understand the concept better but the result I got is what confuses me. Here is the code I wrote:

module main; int x; initial begin $monitor("x is %0d",x); #0 x = 5; // inactive event x = 3; // active event end endmodule

RESULT : x is 3.

According to my knowledge the #0 delay creates an inactive event and therefore the result should have been x is 5. But my understanding of the concept might be wrong somewhere. Any help will be appreciated. Thanks.

Answer1:

Definitions of the regions from <a href="https://standards.ieee.org/findstds/standard/1800-2012.html" rel="nofollow">IEEE Std 1800-2012</a>:

<blockquote>

<strong>4.4.2.2 Active events region</strong><br /> The Active region holds the current active region set events being evaluated and can be processed in any order.<strong>4.4.2.3 Inactive events region</strong><br /> The Inactive region holds the events to be evaluated after all the Active events are processed. If events are being executed in the active region set, an explicit #0 delay control requires the process to be suspended and an event to be scheduled into the Inactive region of the current time slot so that the process can be resumed in the next Inactive to Active iteration.<strong>...</strong><strong>4.4.2.9 Postponed events region</strong><br />$monitor, $strobe, and other similar events are scheduled in the Postponed region. No new value changes are allowed to happen in the current time slot once the Postponed region is reached. Within this region, it is illegal to write values to any net or variable or to schedule an event in any previous region within the current time slot.

</blockquote>

Diagram see a diagram of scheduler on Figure 4-1—Event regions

You are correct in your understanding that the #0 puts the x = 5; into the inactive region. However, this #0 also blocks the x = 3; from executing in the first time entering in the active region. It is executed in the second pass to the active region rigged by the Inactive region. This is because blocking statements are always always sequential. $monitor() is always displayed at the end to the time step, after all other regions have completed, hence you will only get the final value if x.

By placing the statements inside of a fork-join, then the two statements will execute in parallel. This will allow the x = 3; to execute the first time the active region is entered.

module main; int x; initial begin $monitor("From $monitor: x is %0d",x); #0 x = 5; // inactive event x = 3; // active event (after inactive event) #1; // go to next time stamp fork #0 x = 7; // inactive event x = 11; // active event join end // reactive event, x value from the observed region always @* $display("From @* $display: x is %0d",x); endmodule

Outputs:

From @* $display: x is 3 From $monitor: x is 3 From @* $display: x is 11 From @* $display: x is 7 From $monitor: x is 7

Answer2:

In your code, x is being overwritten in the same time step. According to <a href="http://standards.ieee.org/getieee/1800/download/1800-2012.pdf" rel="nofollow">IEEE std 1800-2012</a>:

<blockquote>

when a $monitor task is invoked with one or more arguments, the simulator sets up a mechanism whereby each time a variable or an expression in the argument list changes value the entire argument list is displayed <strong><em>at the end of the time step</em></strong>.

</blockquote>

If you use $display after each statement, you will see each value change:

module main; int x; initial begin $monitor("x in $monitor is %0d",x); #0 x = 5; // inactive event $display ("x in $display=%0d", x); x = 3; // active event $display ("x in $display=%0d", x); end endmodule

Output:

x in $display=5

x in $display=3

x in $monitor is 3

exit

Recommend

  • Why conversion from unsigned long long to double can lead to data loss?
  • why '\\97' ascii value equals 55
  • how can i know if my code is Synthesizable? [Verilog]
  • Java: convert floating point binary to floating point decimal
  • How to use Xcode Extract refactoring feature?
  • Cannot establish BLE connection between Android 5 and BLE device
  • Is Android's ARGB_8888 Bitmap internal format always RGBA?
  • How can I get the maximum number of OpenMP threads that may be created during the whole execution of
  • How to merge two Request in Laravel
  • Full 8 bit adder, illogical output
  • NSMutableArray Access Issue
  • NHibernate proxyexception
  • Timing loops with asynchronous functions
  • c++ search a vector for element first seen position
  • It is possible use the same sql azure instance from two different cloud service of two different sub
  • Excel distinct count with conditions
  • runtime-check whether an instance (Base*) override a parent function (Base::f())
  • In C what exactly happens if i use () to initialize a double dimension array instead of the {}?
  • Is it possible to define rest argument in OCaml?
  • Building Qt project for C++11 standard
  • C++ friend class std::vector
  • How do I remove all but some records based on a threshold?
  • Error in installing package: fatal error: stdlib.h: no such file or directory
  • Eliminate partial duplicate rows from result set
  • Visual Studio 2010 debugger build correctly - compiler pdb and linker pdb not in synch?
  • Installing iPhone App to iPhone
  • Custom Tabgroup Appcelerator
  • Admob requires api-13 or later can I not deploy on old API-8 phones?
  • Could not find rake using whenever rails
  • Is it possible to access block's scope in method?
  • Cannot resolve symbol 'MyApi'
  • DirectX11 ClearRenderTargetViewback with transparent buffer?
  • Where to put my custom functions in Wordpress?
  • How to set the response of a form post action to a iframe source?
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Change div Background jquery
  • Qt: Run a script BEFORE make
  • apache spark aggregate function using min value
  • reshape alternating columns in less time and using less memory