# Comparators

The following classes define comparators for objects and built-in types.

Contents

Comparators | The following classes define comparators for objects and built-in types.
uvm_in_order_comparator #(T,comp_type,convert,pair_type) | Compares two streams of data objects of the type parameter, T.
uvm_in_order_built_in_comparator #(T) | This class uses the uvm_built_in_* comparison, converter, and pair classes.
uvm_in_order_class_comparator #(T) | This class uses the uvm_class_* comparison, converter, and pair classes.

## uvm_in_order_comparator #(T,comp_type,convert,pair_type)

Compares two streams of data objects of the type parameter, T. These transactions may either be classes or built-in types. To be successfully compared, the two streams of data must be in the same order. Apart from that, there are no assumptions made about the relative timing of the two streams of data.

Type parameters

T | Specifies the type of transactions to be compared.
comp_type | A policy class to compare the two transaction streams. It must provide the static method “function bit comp(T a, T b)” which returns TRUE if a and b are the same.
convert | A policy class to convert the transactions being compared to a string. It must provide the static method “function string convert2string(T a)”.
pair_type | A policy class to allow pairs of transactions to be handled as a single uvm_object type.

Built in types (such as ints, bits, logic, and structs) can be compared using the default values for comp_type, convert, and pair_type. For convenience, you can use the subtype, uvm_in_order_built_in_comparator #(T) for built-in types.

When T is a uvm_object, you can use the convenience subtype uvm_in_order_class_comparator #(T).

Comparisons are commutative, meaning it does not matter which data stream is connected to which export, before_export or after_export.

Comparisons are done in order and as soon as a transaction is received from both streams. Internal fifos are used to buffer incoming transactions on one stream until a transaction to compare arrives on the other stream.

Summary

uvm_in_order_comparator #(T,comp_type,convert,pair_type)
Compares two streams of data objects of the type parameter, T.
Ports |
before_export | The export to which one stream of data is written.
after_export | The export to which the other stream of data is written.
pair_ap | The comparator sends out pairs of transactions across this analysis port.
Methods |
flush | This method sets m_matches and m_mismatches back to zero.

### Ports

### before_export

The export to which one stream of data is written. The port must be connected to an analysis port that will provide such data.

### after_export

The export to which the other stream of data is written. The port must be connected to an analysis port that will provide such data.

### pair_ap

The comparator sends out pairs of transactions across this analysis port. Both matched and unmatched pairs are published via a pair_type objects. Any connected analysis export(s) will receive these transaction pairs.

### Methods

### flush

> virtual function void flush()

This method sets m_matches and m_mismatches back to zero. The uvm_tlm_fifo#(T)::flush takes care of flushing the FIFOs.

## uvm_in_order_built_in_comparator #(T)

This class uses the uvm_built_in_* comparison, converter, and pair classes. Use this class for built-in types (int, bit, string, etc.)

Summary

uvm_in_order_built_in_comparator #(T)
This class uses the uvm_built_in_* comparison, converter, and pair classes.
Class Hierarchy
uvm_in_order_comparator#(T)
uvm_in_order_built_in_comparator#(T)
Class Declaration
> class uvm_in_order_built_in_comparator #(
> | type | T | = | int
> ) extends uvm_in_order_comparator #(T)

## uvm_in_order_class_comparator #(T)

This class uses the uvm_class_* comparison, converter, and pair classes. Use this class for comparing user-defined objects of type T, which must provide compare() and convert2string() method.

Summary

uvm_in_order_class_comparator #(T)
This class uses the uvm_class_* comparison, converter, and pair classes.
Class Hierarchy
uvm_in_order_comparator#(T,uvm_class_comp#(T),uvm_class_converter#(T),uvm_class_pair#(T,T))
uvm_in_order_class_comparator#(T)
Class Declaration
> class uvm_in_order_class_comparator #(
> | type | T | = | int
> ) extends uvm_in_order_comparator #( T , uvm_class_comp #( T ) , uvm_class_converter #( T ) , uvm_class_pair #( T, T ) )

> class uvm_in_order_built_in_comparator #(
> | type | T | = | int
> ) extends uvm_in_order_comparator #(T)

This class uses the uvm_built_in_* comparison, converter, and pair classes.

> class uvm_in_order_class_comparator #(
> | type | T | = | int
> ) extends uvm_in_order_comparator #( T , uvm_class_comp #( T ) , uvm_class_converter #( T ) , uvm_class_pair #( T, T ) )

This class uses the uvm_class_* comparison, converter, and pair classes.

> virtual function void flush()

This method sets m_matches and m_mismatches back to zero.

> virtual class uvm_object extends uvm_void

The uvm_object class is the base class for all UVM data and hierarchical classes.

> virtual function void flush()

Removes all entries from the FIFO, after which used returns 0 and is_empty returns 1.