Mastering Assertion Control in Verilog and SystemVerilog

In this blog post, we will explore various assertion control functions in Verilog and SystemVerilog, diving deep into how you can use them effectively to manage and control assertions within your design. We will cover both the assertion control system tasks and the assertion actions, providing practical examples for each function. Let's get started!

Utilizing Assertion Control System Tasks

$assertcontrol: The Powerful Tool for Assertion Management

The $assertcontrol system task allows you to manipulate the behavior of assertions, giving you precise control over their execution. The task has the following syntax:

$assertcontrol(control_type, assertion_type, directive_type);

The control_type argument is an integer value that controls the assertion behavior. Here's a list of the available control_type values and their meanings:

ValueControl TypeDescription
1LockLock assertion state
2UnlockUnlock assertion state
3OnEnable assertion checking
4OffDisable assertion checking
5KillAbort and stop assertion checking
6PassOnEnable pass action execution
7PassOffDisable pass action execution
8FailOnEnable fail action execution
9FailOffDisable fail action execution
10NonvacuousOnEnable pass action on nonvacuous success
11VacuousOffDisable pass action on vacuous success

The assertion_type argument specifies which types of assertions are affected by the control operation. Here's a list of the available assertion_type values and their meanings:

ValueAssertion TypeDescription
1ConcurrentAffects concurrent assertions
2Simple ImmediateAffects simple immediate assertions
4Observed Deferred ImmediateAffects observed deferred immediate assertions
8Final Deferred ImmediateAffects final deferred immediate assertions
16ExpectAffects expect statements
32UniqueAffects unique constraints
64Unique0Affects unique0 constraints
128PriorityAffects priority constraints

The directive_type argument specifies which types of directives are affected by the control operation. Here's a list of the available directive_type values and their meanings:

ValueDirective TypeDescription
1Assert directivesAffects assert directives
2Cover directivesAffects cover directives
4Assume directivesAffects assume directives

To use the $assertcontrol system task, pass the appropriate values for control_type, assertion_type, and directive_type as arguments. For example, to disable simple immediate assertions:

module TopModule;
  // ...your code...
  initial begin
    $assertcontrol(4, 2, 1); // Disabling simple immediate assertions
  end
endmodule

In this example, the control_type value 4 corresponds to disabling assertions, the assertion_type value 2 corresponds to simple immediate assertions, and the directive_type value 1 corresponds to assert directives.

Here's another example that demonstrates enabling pass action execution for concurrent assertions:

module TopModule;
  // ...your code...
  initial begin
    // Enabling pass action execution for concurrent assertions
    $assertcontrol(6, 1, 1);
  end
endmodule

In this case, the control_type value 6 corresponds to enabling pass action execution, the assertion_type value 1 corresponds to concurrent assertions, and the directive_type value 1 corresponds to assert directives.

$asserton: Quickly Enable Assertion Checking

The $asserton function allows you to enable assertion checking with ease. The example below demonstrates its usage:

module TopModule;
  // ...your code...
  initial begin
    $asserton();
  end
endmodule

$assertoff: Temporarily Disable Assertion Checking

With $assertoff, you can temporarily disable assertion checking. Check out the following example:

module TopModule;
  // ...your code...
  initial begin
    $assertoff();
  end
endmodule

$assertkill: Abort and Stop Assertion Checking

When you need to abort and stop assertion checking, use the $assertkill function. Here's how you can implement it:

module TopModule;
  // ...your code...
  initial begin
    $assertkill();
  end
endmodule

Managing Assertion Actions

$assertpasson: Enable Pass Action Execution

To enable the pass action execution for both vacuous and nonvacuous success, use the $assertpasson function:

module TopModule;
  // ...your code...
  initial begin
    $assertpasson();
  end
endmodule

$assertpassoff: Disable Pass Action Execution

To disable pass action execution, you can use the $assertpassoff function as shown below:

module TopModule;
  // ...your code...
  initial begin
    $assertpassoff();
  end
endmodule

$assertfailon: Enable Fail Action Execution

Use the $assertfailon function to enable the fail action execution:

module TopModule;
  // ...your code...
  initial begin
    $assertfailon();
  end
endmodule

$assertfailoff: Disable Fail Action Execution

The $assertfailoff function helps you disable fail action execution:

module TopModule;
  // ...your code...
  initial begin
    $assertfailoff();
  end
endmodule

$assertnonvacuouson: Enable Pass Action on Nonvacuous Success

To enable pass action execution only on nonvacuous success, use $assertnonvacuouson:

module TopModule;
  // ...your code...
  initial begin
    $assertnonvacuouson();
  end
endmodule

$assertvacuousoff: Disable Pass Action on Vacuous Success

Lastly, to disable pass action execution on vacuous success, you can use the $assertvacuousoff function:

module TopModule;
  // ...your code...
  initial begin
    $assertvacuousoff();
  end
endmodule

Here's a recap of the assertion control functions we've discussed in this blog post:

FunctionDescription
$assertcontrolFine-grained control over assertions and actions
$assertonEnable assertion checking
$assertoffDisable assertion checking
$assertkillAbort and stop assertion checking
$assertpassonEnable pass action execution
$assertpassoffDisable pass action execution
$assertfailonEnable fail action execution
$assertfailoffDisable fail action execution
$assertnonvacuousonEnable pass action on nonvacuous success
$assertvacuousoffDisable pass action on vacuous success

By mastering the assertion control functions in Verilog and SystemVerilog, you can effectively manage and control the evaluation of assertions and the execution of action blocks in your designs. These functions provide a powerful way to ensure your designs meet your desired specifications, enabling you to create more reliable and efficient systems. Happy designing!