# uvm_comparer

The uvm_comparer class provides a policy object for doing comparisons. The policies determine how miscompares are treated and counted. Results of a comparison are stored in the comparer object. The uvm_object::compare and uvm_object::do_compare methods are passed a uvm_comparer policy object.

Summary

uvm_comparer
The uvm_comparer class provides a policy object for doing comparisons.
Class Declaration
> class uvm_comparer
Variables |
policy | Determines whether comparison is UVM_DEEP, UVM_REFERENCE, or UVM_SHALLOW.
show_max | Sets the maximum number of messages to send to the printer for miscompares of an object.
verbosity | Sets the verbosity for printed messages.
sev | Sets the severity for printed messages.
miscompares | This string is reset to an empty string when a comparison is started.
physical | This bit provides a filtering mechanism for fields.
abstract | This bit provides a filtering mechanism for fields.
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.
result | This bit stores the number of miscompares for a given compare operation.
Methods |
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).

### Variables

### policy

> uvm_recursion_policy_enum policy = UVM_DEFAULT_POLICY

Determines whether comparison is UVM_DEEP, UVM_REFERENCE, or UVM_SHALLOW.

### show_max

> int unsigned show_max = 1

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

### verbosity

> int unsigned verbosity = UVM_LOW

Sets the verbosity for printed messages.

The verbosity setting is used by the messaging mechanism to determine whether messages should be suppressed or shown.

### sev

> uvm_severity sev = UVM_INFO

Sets the severity for printed messages.

The severity setting is used by the messaging mechanism for printing and filtering messages.

### miscompares

> string miscompares = ""

This string is reset to an empty string when a comparison is started.

The string holds the last set of miscompares that occurred during a comparison.

### physical

> bit physical = 1

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.

### abstract

> bit abstract = 1

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 abstract trait as a filter.

### check_type

> bit check_type = 1

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.

### result

> int unsigned result = 0

This bit stores the number of miscompares for a given compare operation. You can use the result to determine the number of miscompares that were found.

### Methods

### 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
> )

Compares two integral values.

The name input is used for purposes of storing and printing a miscompare.

The left-hand-side lhs and right-hand-side rhs objects are the two objects used for comparison.

The size variable indicates the number of bits to compare; size must be less than or equal to 4096.

The radix is used for reporting purposes, the default radix is hex.

### compare_field_int

> virtual function bit compare_field_int (
> | string | name, |  |
> | uvm_integral_t | lhs, |  |
> | uvm_integral_t | rhs, |  |
> | int | size, |  |
> | uvm_radix_enum | radix | = | UVM_NORADIX
> )

This method is the same as compare_field except that the arguments are small integers, less than or equal to 64 bits. It is automatically called by compare_field if the operand size is less than or equal to 64.

### compare_field_real

> virtual function bit compare_field_real (
> | string | name,
> | real | lhs,
> | real | rhs
> )

This method is the same as compare_field except that the arguments are real numbers.

### compare_object

> virtual function bit compare_object (
> | string | name,
> | uvm_object | lhs,
> | uvm_object | rhs
> )

Compares two class objects using the policy knob to determine whether the comparison should be deep, shallow, or reference.

The name input is used for purposes of storing and printing a miscompare.

The lhs and rhs objects are the two objects used for comparison.

The check_type determines whether or not to verify the object types match (the return from lhs.get_type_name() matches rhs.get_type_name()).

### compare_string

> virtual function bit compare_string (
> | string | name,
> | string | lhs,
> | string | rhs
> )

Compares two string variables.

The name input is used for purposes of storing and printing a miscompare.

The lhs and rhs objects are the two objects used for comparison.

### print_msg

> function void print_msg (
> | string | 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).

If the message count is less than the show_max setting, then the message is printed to standard-out using the current verbosity and severity settings. See the verbosity and sev variables for more information.

> class uvm_comparer

The uvm_comparer class provides a policy object for doing comparisons.

> uvm_recursion_policy_enum policy = UVM_DEFAULT_POLICY

Determines whether comparison is UVM_DEEP, UVM_REFERENCE, or UVM_SHALLOW.

> int unsigned show_max = 1

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

> int unsigned verbosity = UVM_LOW

Sets the verbosity for printed messages.

> uvm_severity sev = UVM_INFO

Sets the severity for printed messages.

> string miscompares = ""

This string is reset to an empty string when a comparison is started.

> bit physical = 1

This bit provides a filtering mechanism for fields.

> bit abstract = 1

This bit provides a filtering mechanism for fields.

> bit check_type = 1

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.

> virtual function string get_type_name ()

This function returns the type name of the object, which is typically the type identifier enclosed in quotes.

> int unsigned result = 0

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

> virtual function bit compare_field (
> | string | name, |  |
> | uvm_bitstream_t | lhs, |  |
> | uvm_bitstream_t | rhs, |  |
> | int | size, |  |
> | uvm_radix_enum | radix | = | UVM_NORADIX
> )

Compares two integral values.

> virtual function bit compare_field_int (
> | string | name, |  |
> | uvm_integral_t | lhs, |  |
> | uvm_integral_t | rhs, |  |
> | int | size, |  |
> | uvm_radix_enum | radix | = | UVM_NORADIX
> )

This method is the same as compare_field except that the arguments are small integers, less than or equal to 64 bits.

> virtual function bit compare_field_real (
> | string | name,
> | real | lhs,
> | real | rhs
> )

This method is the same as compare_field except that the arguments are real numbers.

> virtual function bit compare_object (
> | string | name,
> | uvm_object | lhs,
> | uvm_object | rhs
> )

Compares two class objects using the policy knob to determine whether the comparison should be deep, shallow, or reference.

> virtual function bit compare_string (
> | string | name,
> | string | lhs,
> | string | rhs
> )

Compares two string variables.

> function void print_msg (
> | string | 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).

> function bit compare (
> | uvm_object | rhs, |  |
> | uvm_comparer | comparer | = | null
> )

Deep compares members of this data object with those of the object provided in the rhs (right-hand side) argument, returning 1 on a match, 0 otherwise.

> virtual function bit do_compare (
> | uvm_object | rhs,
> | uvm_comparer | comparer
> )

The do_compare method is the user-definable hook called by the compare method.