Uvm_comparer : parametrized classes .compare issue

Hi ,

I am facing an issue with .compare method, where compare between two objects of the same parameterized class but different parameter values with different data inside return success always.

EXAMPLE :

class trans #(parameter type T=bit) extends uvm_sequence_item;
 rand bit[T:0] data;

`uvm_object_param_utils_begin(trans#(T))
   `uvm_field_int(data, UVM_DEFAULT)
`uvm_object_utils_end

function new(string name=””);
  super.new(name);
endfunction

function void post_randomize();
uvm_report_info(get_name(),$sformatf(“data randomized = %0d”,data),UVM_LOW);
endfunction

// User compare hook
function bit do_compare(uvm_object rhs, uvm_comparer comparer);
    bit status = 1'b1;
    trans that;
    if(!$cast(that, rhs)) begin
      status = 1'b0;
    end else begin
     // Custom compare method is returning 1.
     status &= comparer.compare_object("item", this, that);
    end
return(status);
end function : do_compare

endclass

TEST :

class test extends uvm_component;
`uvm_component_utils(test)
function new(string name, uvm_component parent);
super.new(name,parent);
endfunction

task run_phase(uvm_phase phase);
pkt#(8) d1;
pkt#(9) d2;
d1 = new(“d1”);
d2 = new(“d2”);

void'(d1.randomize());
void'(d2.randomize());

if(d1.compare(d2)) begin
`uvm_info(“CMP”,$sformatf(“COMPARE SUCESS”),UVM_HIGH)
end
else begin
`uvm_info(“CMP”,$sformatf(“COMPARE Failed”),UVM_HIGH)
end
endtask 

endclass

I am getting output as always COMPARE success even though the data is different.

I implemented do_compare hook also to compare classes manually by using compare_object, but the status is same (its returing 1).

     status &= comparer.compare_object("item", this, that);

Please help .

I found an article regarding this issue , :

In to the article it mentions UVM committee is fixed the issue.

In reply to lalithjithan:

I see probable issues in your code, but your example fails the Copy, Paste, Compile test, so I don’t know if your example really demonstrates your problem, or has entirely new problems of it’s own.

Provide an executable example that replicates the behavior: Minimal reproducible example - Wikipedia

Preferably one you can share on https://www.edaplayground.com

In reply to warnerrs:

Hi ,

sorry for not providing good example.

The issue i am facing is related to a issue raised : 0006699: comparer false pass for instances with different parameters - Accellera Mantis

now , i made a fix based on the solution provided in the above mantis. (inside my do_compare method checking get_object_type() of both objects like below code.

  function bit do_compare(uvm_object rhs, uvm_comparer comparer);
   a_item that;
   if(!$cast(that, rhs)) begin
      status = 1'b0;
   end else begin
     status &= comparer.compare_object("item", this.item, that.item);

    // FIX 
     if(that.item.get_object_type() != this.item.get_object_type()) begin
        status = '0; 
     end

   end
   return(status);
  endfunction: do_compare

As per the 0006699: comparer false pass for instances with different parameters - Accellera Mantis the compare method of uvm_object should check :

if (get_check_type() && (lhs.get_object_type() != rhs.get_object_type())) begin

instead of

if (check_type && (lhs.get_type_name() != rhs.get_type_name())) begin

please share your thoughts!