# Algorithmic Comparator

A common function of testbenches is to compare streams of transactions for equivalence. For example, a testbench may compare a stream of transactions from a DUT with expected results.

The UVM library provides a base class called uvm_in_order_comparator #(T,comp_type,convert,pair_type) and two derived classes, which are uvm_in_order_built_in_comparator #(T) for comparing streams of built-in types and uvm_in_order_class_comparator #(T) for comparing streams of class objects.

The uvm_algorithmic_comparator also compares two streams of transactions; however, the transaction streams might be of different type objects. This device will use a user-written transformation function to convert one type to another before performing a comparison.

Summary

Algorithmic Comparator
A common function of testbenches is to compare streams of transactions for equivalence.

## uvm_algorithmic_comparator #(BEFORE,AFTER,TRANSFORMER)

Compares two streams of data objects of different types, BEFORE and AFTER.

The algorithmic comparator is a wrapper around uvm_in_order_class_comparator #(T). Like the in-order comparator, the algorithmic comparator compares two streams of transactions, the BEFORE stream and the AFTER stream. It is often the case when two streams of transactions need to be compared that the two streams are in different forms. That is, the type of the BEFORE transaction stream is different than the type of the AFTER transaction stream.

The uvm_algorithmic_comparator’s TRANSFORMER type parameter specifies the class responsible for converting transactions of type BEFORE into those of type AFTER. This transformer class must provide a transform() method with the following prototype:

>     function AFTER transform (BEFORE b);

Matches and mismatches are reported in terms of the AFTER transactions. For more information, see the uvm_in_order_comparator #(T,comp_type,convert,pair_type) class.

Summary

uvm_algorithmic_comparator #(BEFORE,AFTER,TRANSFORMER)
Compares two streams of data objects of different types, BEFORE and AFTER.
Class Hierarchy
uvm_void
uvm_object
uvm_report_object
uvm_component
uvm_algorithmic_comparator#(BEFORE,AFTER,TRANSFORMER)
Class Declaration
> class uvm_algorithmic_comparator #(
> | type | BEFORE | = | int,
> | type | AFTER | = | int,
> | type | TRANSFORMER | = | int
> ) extends uvm_component
Ports |
before_export | The export to which a data stream of type BEFORE is sent via a connected analysis port.
after_export | The export to which a data stream of type AFTER is sent via a connected analysis port.
Methods |
new | Creates an instance of a specialization of this class.

### Ports

### before_export

The export to which a data stream of type BEFORE is sent via a connected analysis port. Publishers (monitors) can send in an ordered stream of transactions against which the transformed BEFORE transactions will (be compared.

### after_export

The export to which a data stream of type AFTER is sent via a connected analysis port. Publishers (monitors) can send in an ordered stream of transactions to be transformed and compared to the AFTER transactions.

### Methods

### new

> function new(
> | string | name, |  |
> | uvm_component | parent | = | null,
> | TRANSFORMER | transformer | = | null
> )

Creates an instance of a specialization of this class. In addition to the standard uvm_component constructor arguments, name and parent, the constructor takes a handle to a transformer object, which must already be allocated (handles can’t be null) and must implement the transform() method.

Compares two streams of data objects of the type parameter, 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 class uvm_void

The uvm_void class is the base class for all UVM classes.

> virtual class uvm_object extends uvm_void

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

> class uvm_report_object extends uvm_object

The uvm_report_object provides an interface to the UVM reporting facility.

> virtual class uvm_component extends uvm_report_object

The uvm_component class is the root base class for UVM components.

> class uvm_algorithmic_comparator #(
> | type | BEFORE | = | int,
> | type | AFTER | = | int,
> | type | TRANSFORMER | = | int
> ) extends uvm_component

Compares two streams of data objects of different types, BEFORE and AFTER.

> function new(
> | string | name, |  |
> | uvm_component | parent | = | null,
> | TRANSFORMER | transformer | = | null
> )

Creates an instance of a specialization of this class.