# Uvm\_algorithmic\_comparator

**URL:** <https://verificationacademy.com/forums/t/uvm-algorithmic-comparator/28784>\
**Category:** UVM\
**Tags:** UVM\
**Created:** [September 3, 2013, 12:18pm UTC](https://verificationacademy.com/forums/t/uvm-algorithmic-comparator/28784 "2013-09-03T12:18:40Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![gordon](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/g/3da27b/32.png) [@gordon](https://verificationacademy.com/forums/u/gordon)\
**Post date:** [September 12, 2014, 2:06am UTC](https://verificationacademy.com/forums/t/uvm-algorithmic-comparator/28784/2 "2014-09-12T02:06:30Z")

</div>

There are multiple problems with your code - refer to the reference guide for [uvm\_algorithmic\_comparator](https://verificationacademy.com/verification-methodology-reference/uvm/docs_1.1d/html/index.html) for the correct usage / see the corrected code below:

The type signature is uvm\_algorithmic\_comparator #(BEFORE,AFTER,TRANSFORMER) where TRANSFORMER should be a CLASS that contains a method with the signature ‘function AFTER transform (BEFORE b)’ i.e. which takes an object of type BEFORE and returns a transformed object of type AFTER. That class can be your scoreboard class, or some other class of your choosing.

```verilog
class scoreboard extends uvm_algorithmic_comparator#(before_item, after_item, scoreboard);
`uvm_component_utils(scoreboard)

```

Your two fifos were the wrong way around:

```verilog
  uvm_tlm_analysis_fifo #(after_item) after_fifo;
  uvm_tlm_analysis_fifo #(before_item) before_fifo;

```

```verilog
  after_item hi;
  after_item hi1 = new;
  before_item pi;

```

Your constructor does NOT need a third argument, only the uvm\_algorithmic\_comparator constructor does (you call it with super.new()). In this example we are passing ‘this’ so that the base class can call OUR transform() method:

```verilog
  function new(string name = "scoreboard", uvm_component parent=null);
    super.new(name, parent, this);

```

```verilog
    before_fifo = new("before_fifo", this);
    after_fifo = new("after_fifo", this);
  endfunction

```

Note that your usage of the transform() is not strictly as intended, better to use its return value rather than have it update a class member variable. What you have does compile OK however.

```verilog
  function after_item transform (before_item item);
    hi1.data = item.data;
  endfunction

  task run_phase(uvm_phase phase);
    forever
      begin
	before_fifo.get(pi);
	after_fifo.get(hi);
	transform(pi);
	if(!hi.compare(hi1))
	  $display("DATA MISMATCH");
	else
	  $display("DATA MATCHED");
      end
  endtask	

endclass

```

Note that this comparator is suitable only for simple scoreboarding requirements.

---

_[View the full topic](https://verificationacademy.com/forums/t/uvm-algorithmic-comparator/28784)._
