Uvm_algorithmic_comparator

Hello Mavens,

Can anyone explain me how to use uvm_algorithmic_comparator in scoreboard, I tried myself with the following code for comparing the data of two different transaction classes such as after_item and before_item.

Can anybody guide me where I’ve gone wrong.


class scoreboard extends uvm_algorithmic_comparator#(before_item, after_item, after_item);
 						 //  before       after       transformer

 `uvm_component_utils(scoreboard)  


  uvm_tlm_analysis_fifo #(after_item) before_fifo;  // from master_uvc
  uvm_tlm_analysis_fifo #(before_item) after_fifo;   // from slave_uvc


  after_item hi; // transaction class of after
  after_item hi1 = new;; // transaction class of after
  before_item pi; // transaction class of before


 function new(string name = "scoreboard", uvm_component parent, TRANSFORMER after_item);
	super.new(name, parent, "hi1");
	before_fifo = new("before_fifo", this);
	after_fifo = new("after_fifo", this);
 endfunction


//function  after   transform  before   handle
 function after_item transform (before_item item);
//	super.transform(item);                   //Dont know what to write in this function
	hi1.data = item.data;
 endfunction


task run_phase(uvm_phase phase);
     forever
	begin
	    before_fifo.get(pi);  // getting from before_item
	    after_fifo.get(hi);   // getting from after_item
	    transform(pi);
	    if(!hi.compare(hi1))                //I'm calling compare function of after transaction class which only do data comparision
		$display("DATA MISMATCH");
	    else
		$display("DATA MATCHED");
  	end

endtask	
endclass

Thanks in advance

There are multiple problems with your code - refer to the reference guide for uvm_algorithmic_comparator 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.

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

Your two fifos were the wrong way around:

  uvm_tlm_analysis_fifo #(after_item) after_fifo;
  uvm_tlm_analysis_fifo #(before_item) before_fifo;
  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:

  function new(string name = "scoreboard", uvm_component parent=null);
    super.new(name, parent, this);
    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.

  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.