SVA : System Tasks & Functions

Assertion severity – system tasks

In System Verilog, severity of assertion messages is classified by using four system tasks. These are $fatal, $error, $warning and $info. If an action block is specified, user-defined severity can be created by using these system tasks.

Every assertion failure has an associated severity which can be specified in the fail-statement block. If assertion does not have a fail-statement block, then by default $error system task will be called with default message.

The syntax of severity system tasks except $fatal is identical to $display, but for $fatal, error code will be the first argument.

  • $fatal:

  • This generates a run time fatal error that terminates the simulation with the specified error code. The error code is mandatory and which will be returned to the operating system. The $fatal ends the simulation, that means it has an implicit call of $finish.

  • $warning:

  • This generates run time warning which can be suppressed by using tool options.

  • $error:

  • This generates a run time error that does not terminate the simulation.

  • $info:

  • This generates information to the user and indicates that the assertion failure carries no specific severity.

    Assertion control – system tasks

    For controlling assertions and coverage, system Verilog provides three system tasks, which are $asserton, $assertoff and $assertkill.

  • $assertoff

  • This stops the evaluation of all specified assertions until a subsequent $asserton. The assertion that is currently evaluated, including execution of the pass or fails statement is not affected.

  • $asserton:

  • This re-enables the execution of all specified assertions. If it is called without any argument, it turns on the assertions for the entire design which is same as $asserton(0, top).

    With argument:
    $asserton(3) – Turns on all assertions on top level and the next three sub-levels below.
    $asserton(0, top.sub1.sub2) Turns on the assertions for the entire hierarchy starting at the scope top.sub1.sub2

  • $assertkill:

  • This aborts immediately the execution of any currently evaluated specified assertion and then stops the evaluation of all specified assertions until a subsequent $asserton.

    Assertion action control system tasks

    $assertpasson, $assertpassoff, $assertfailon, $assertfailoff, $assertnonvacuouson, $assertvacuousoff are action control system tasks in SVA.

    Vector analysis – system functions

  • $onehot (expression):

  • This returns TRUE, if one and only one bit of the expression is high.
    Return type: bit

  • $onehot0 (expression):

  • This returns TRUE, if at most one bit (i.e., zero or one bit) of the expression is high
    It is same as $onehot(expr) || expr == ‘b0.
    Return type: bit

  • $isunknown (expression):

  • This returns TRUE, if any bit of the expression is either X or Z. It is same as ^ === ’bx.
    Return type: bit

  • $countones (expression)

  • This returns the number of 1s in a bit vector expression. X and Z are not counted towards the number of 1s.
    Return type: integer

    Value change system functions

    The system functions $rose, $fell, $stable and $changed are used to detect changes in values between two adjacent clock cycles. It uses sampled values of the expression with return type of bit.

  • $rose:
  • This returns TRUE, if the LSB of the expression changed to 1. Otherwise, it returns false.
    Main difference with posedge is that, posedge returns event, but $rose returns boolean value.
    Posedge cannot be used with expression as it returns event.

  • $fell:

  • This returns TRUE, if the LSB of the expression changed to 0. Otherwise, it returns false.

  • $stable:

  • This returns TRUE, if the value of the expression did not change.

  • $changed:

  • This returns TRUE, if the value of the expression changed.

    Value access system functions

  • $sampled:
  • This returns the current sampled value of the specified expression. As the assertions use sampled values, the use of $sampled in assertions besides the disable-statement and the action block is redundant. When $sampled is invoked prior to the occurrence of the first clocking event, the value of X is returned.

  • $past:

  • This returns the sampled value of the specified expression that was present number of clock cycles in other words number of ticks prior to the time of evaluation of $past. The number of cycles must be one or greater and by default it takes the value as 1. If the specified clock tick in the past is before the start of simulation, $past returns a value of X.

    Sini Balakrishnan

    Sini Balakrishnan

    Staff Engineer at Intel
    Sini has spent more than a dozen years in the semiconductor industry, focusing mostly on verification. She is an expert on Formal Verification and has written international papers and articles on related topics.
    Sini Balakrishnan

    Latest posts by Sini Balakrishnan (see all)

    3 Comments

    1. PRAMOD

      Can we use the below equation to check whether my clock is generated correctly with the period specified

      parameter CLK_PERIOD = 10
      property clk_period_check;
      @(posedge clk)
      $rose(clk1) ##CLK_PERIOD $rose(clk1);
      endproperty

    Leave a Reply

    Your email address will not be published. Required fields are marked *