UVM COMPARER - kashyapp1/github_exp GitHub Wiki

uvm_comparer

  • it's a standalone class used to set policy for doing comparisons and finds how miscompares are counted. every uvm object has compare() method which is performing the comparisons with other objects and results of comparison is stored in the comparer object.

  • An object can be passed to set parameters like depth of comparison, verbosity, max number of miscompares etc - an extra layer of flexibility.

  • it also has a set of comparison methods for integers, string, real numbers and objects.

Variables

1. policy : Determines whether comparison is UVM_DEEP, UVM_REFERENCE, or UVM_SHALLOW.

declaration : uvm_recursion_policy_enum policy = UVM_DEFAULT_POLICY

2. show_max: Sets the maximum number of messages to send to the printer for miscompares of an object.

declaration : int unsigned show_max = 1

Example

 //total number of miscompares to be printed
 comp.show_max = 10;

3. verbosity: Sets the verbosity for printed messages. This setting is used by the messaging mechanism to determine whether messages should be suppressed or shown.

declaration : int unsigned verbosity = UVM_LOW

Example

//set verbosity
comp.verbosity = UVM_LOW;

4. sev: Sets the severity for printed messages. This setting is used by the messaging mechanism for printing and filtering messages.

declaration : uvm_severity sev = UVM_INFO

Example

//set severity
comp.sev = UVM_ERROR;

5. miscompares: This string is reset to an empty string when a comparison is started. It holds the last set of miscompares that occurred during a comparison.

declaration : string miscompares = ""

6. physical or abstract: This bit provides a filtering mechanism for fields. The abstract and physical settings allow an object to distinguish between two different classes of fields. It is up to you, in the uvm_object::do_compare method, to test the setting of this field if you want to use the physical trait as a filter.

declaration : bit physical = 1 or bit abstract = 1

7. check_type: This bit determines whether the type, given by uvm_object::get_type_name, is used to verify that the types of two objects are the same. This bit is used by the compare_object method. In some cases it is useful to set this to 0 when the two operands are related by inheritance but are different types.

declaration : bit check_type = 1

8. results: This bit stores the number of miscompares for a given compare operation.

declaration : int unsigned result = 0

Example

`uvm_info(get_full_name(), $sformatf("Comparing objects: result = %0d", comp.result), UVM_LOW)

Methods

Method Description
compare_field Compares two integral values.
compare_field_int This method is the same as compare_field except that the arguments are small integers, less than or equal to 64 bits.
compare_field_real This method is the same as compare_field except that the arguments are real numbers.
compare_object Compares two class objects using the policy knob to determine whether the comparison should be deep, shallow, or reference.
compare_string Compares two string variables.
print_msg Causes the error count to be incremented and the message, msg, to be appended to the miscompares string (a newline is used to separate messages)

Methods definiations:

  1. compare_field : virtual function bit compare_field (
      string name,     uvm_bitstream_t lhs,
      uvm_bitstream_t rhs,
      int size,
      uvm_radix_enum radix = UVM_NORADIX )

name: used to store and print miscompare.
lhs and rhs: used to compare left-hand and right-hand side objects
size: indicates number of bis to compare. (size <= 4096)
radix: used for reporting purposes. Default radix = HEX.

Example

comp.compare_field("int_compare", 4'h3, 4'h6, 4);
  1. compare_field_int : virtual function bit compare_field (
      string name,     uvm_bitstream_t lhs,
      uvm_bitstream_t rhs,
      int size,
      uvm_radix_enum radix = UVM_NORADIX )

Example

comp.compare_field_int("int_compare", 4'h2, 4'h4, 4);
  1. compare_object : virtual function bit compare_field (
      string name,     uvm_object lhs,
    uvm_object rhs )

Example

comp.compare_object("tr_compare", object1, object2);
  1. compare_string : virtual function bit compare_string (
      string name,     string lhs,
    string rhs )

Example

comp.compare_string("string_compare", "team", "kachori");

Code snippet

`include "uvm_macros.svh"
import uvm_pkg::*;

class base_test extends uvm_test;
  transaction object1, object2;
  uvm_comparer comp;

  `uvm_component_utils(base_test)

  function new(string name = "base_test", uvm_component parent = null);
    super.new(name, parent);
  endfunction

  function void build_phase(uvm_phase phase);
    super.build_phase(phase);
    object1 = transaction::type_id::create("object1", this);
    object2 = transaction::type_id::create("object2", this);
    comp = new();
  endfunction

  task run_phase(uvm_phase phase);
    super.run_phase(phase);
    assert(object1.randomize());
    assert(object2.randomize());

    //set verbosity
    comp.verbosity = UVM_LOW;
    //total number of miscompares to be printed
    comp.show_max = 10;

    `uvm_info(get_full_name(), "Comparing objects", UVM_LOW)
    void'(comp.compare_object("tr_compare", object1, object2));
    object2.copy(object1);
    void'(comp.compare_object("tr_compare", object1, object2));
    `uvm_info(get_full_name(), $sformatf("Comparing objects: result = %0d", comp.result), UVM_LOW)

    void'(comp.compare_field_int("int_compare", 4'h2, 4'h4, 4));
    void'(comp.compare_string("string_compare", "team", "kachori"));
    void'(comp.compare_field_real("real compare", 4.5,4.5));

   `uvm_info(get_full_name(), $sformatf("Comparing objects: result = %0d", comp.result), UVM_LOW)

    void'(comp.compare_field_int("int_compare", 4'h4, 4'h4, 4));
    void'(comp.compare_string("string_compare", "kachori", "kachori"));
    void'(comp.compare_field_real("real compare", 4.5,6.5));

    `uvm_info(get_full_name(), $sformatf("Comparing objects: result = %0d", comp.result), UVM_LOW)

  endtask
endclass

Below figure shows the output of uvm_comparer.

uvm_comparer

                             Figure.1.Output of uvm_comparer

Explanation: Here in the output objects are compared and it's mismatch is there so it will give output message as shown in the output and result variable is set equal to two and for integer compare we pass argument as 2,4 and string also "team" and "kachori" is not equal so result variable is increament to 4 as shown in output. but whenever matching is there in the code it will not increament the result variable as well as not displaying the mismatch message on to the output console.

Github lab link:

Github log file link: