VLSI DV Interview Puzzles · All levels

Handle Equality vs Content Equality

Two packets have identical field values, yet `if (a == b)` fails. What is being compared and how should scoreboards compare content?

Puzzle

Difficulty: Easy · Puzzle 5 of 6 · Topic: Handle and Copy Puzzles

Two packets have identical field values, yet `if (a == b)` fails. What is being compared and how should scoreboards compare content?

Code

systemverilog
class pkt extends uvm_object;
  `uvm_object_utils(pkt)
  rand bit [31:0] addr;
  function new(string name="pkt"); super.new(name); endfunction
endclass

initial begin
  pkt a = pkt::type_id::create("a");
  pkt b = pkt::type_id::create("b");
  a.addr = 'h100;
  b.addr = 'h100;
  $display("eq=%0d", (a == b));
end

Hint

Class `==` is not like packed-struct equality.

Step-by-step solution

diagram
1) For class handles, `==` checks handle identity (same object), not field-by-field data.
2) `a` and `b` are distinct objects, so expression is false even with matching `addr`.
3) In UVM use `a.compare(b)` with configured comparers or explicit field checks.

Answer

Answer: `a == b` compares handle identity; use `compare()`/field comparisons for value equivalence.

Why candidates get it wrong

This trap causes false negatives in scoreboards that accidentally compare object identity.

Interviewer follow-up

What comparer settings would you tune to ignore volatile fields like timestamps?

Related topics