uvm_algorithmic_comparator

File: 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 <UVMInOrderClassComparator #(T)> for comparing streams of class objects.

The UVMAlgorithmicComparator 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.

class uvm.comps.uvm_algorithmic_comparator.UVMAlgorithmicComparator(name, parent=None, transformer=None)[source]

Bases: UVMComponent

CLASS: UVMAlgorithmicComparator

Compares two streams of data objects of different types.

The algorithmic comparator is a wrapper around UVMInOrderClassComparator. 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 UVMAlgorithmicComparator’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:

def transform(self, b):
    # Should return transformed transaction

Matches and mismatches are reported in terms of the ~AFTER~ transactions. For more information, see the UVMInOrderComparator class.

Port: 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.

Port: 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.

type_name = 'UVMAlgorithmicComparator'
get_type_name()

This function returns the type name of the object, which is typically the type identifier enclosed in quotes. It is used for various debugging functions in the library, and it is used by the factory for creating objects.

This function must be defined in every derived class.

A typical implementation is as follows:

class mytype (UVMObject):
  ...
  type_name = "mytype"

  def get_type_name(self):
    return my_type.type_name

We define the type_name static variable to enable access to the type name without need of an object of the class, i.e., to enable access via the scope operator, ~mytype::type_name~.

Returns

Type name of the object.

Return type

str

connect_phase(phase)[source]

The UVMConnectPhase phase implementation method.

This method should never be called directly.

Parameters

phase (UVMPhase) –

write(b)[source]
get_object_type()

Function: get_object_type

Returns the type-proxy (wrapper) for this object. The uvm_factory’s type-based override and creation methods take arguments of uvm_object_wrapper. This method, if implemented, can be used as convenient means of supplying those arguments. This method is the same as the static get_type method, but uses an already allocated object to determine the type-proxy to access (instead of using the static object).

The default implementation of this method does a factory lookup of the proxy using the return value from get_type_name. If the type returned by get_type_name is not registered with the factory, then a None handle is returned.

For example:

class cmd (UVMObject):
  type_id = UVMObjectRegistry()
  @classmethod
  def type_id get_type(cls):
    return type_id.get()
  def get_object_type(self):
    return cmd.type_id.get()

This function is implemented by the `uvm_*_utils macros, if employed.

Returns:

classmethod get_type()

Returns the type-proxy (wrapper) for this object. The UVMFactory’s type-based override and creation methods take arguments of uvm_object_wrapper. This method, if implemented, can be used as convenient means of supplying those arguments.

The default implementation of this method produces an error and returns None. To enable use of this method, a user’s subtype must implement a version that returns the subtype’s wrapper.

For example:

class cmd(UVMObject):
  type_id = None

  @classmethod
  def get_type(cls):
    return cls.type_id.get()

Then, to use:

factory.set_type_override(cmd.get_type(), subcmd.get_type())

This function is implemented by the uvm_*_utils functions, if employed.

Returns:

type_id = <uvm.base.uvm_registry.UVMComponentRegistry object>
m_children: Dict[str, 'UVMComponent']
m_children_by_handle: Dict['UVMComponent', 'UVMComponent']
m_children_ordered: List['UVMComponent']
event_pool: UVMEventPool