Jump to content

Comparing Objects with different levels of inheritance


Recommended Posts

I'm trying to figure out a way to compare an item with it's superclass. using the uvm_in_order_class comparator.

so I've overloaded the do_compare function in this manner.

function bit do_compare(uvm_object rhs, uvm_comparer comparer);

bit cast_good;

SubClass _rhs;

comparer.check_type = 0;

//compare superclass fields

do_compare = super.do_compare(rhs, comparer);

//if types match, compare subclass fields.

cast_good = $cast(_rhs, rhs);

if (cast_good) begin

do_compare &= comparer.compare_field("field_1", this.field_1, _rhs.field_1, $bits(field_1));

do_compare &= comparer.compare_field("field_2", this.field_2, _rhs.field_2, $bits(field_2));

...

end

endfunction

So the check_type field in comparer is meant to turn off the type checking, which it does. except in the first comparison. This appears to be due to the way (order) in which the compare function operates. If the comparer is null (which it seems to be, and I can't set it to a local comparer as it is set to null in the uvm_object class) it assigns the internal reference to uvm_default_comparer. It then does the type comparison, then calls so_compare (at which point the type comparison gets switched off).

So what I'm looking for is a way to apply the comparer policy with check type switched off. But I can't see a way of applying this policy either in the object class or the comparator class.

Google searching, just leads me to the comment "the user can then simply apply a different policy class." but there is no description of how.

Any thoughts?

Edited by calvapete
mistake
Link to comment
Share on other sites

Thanks for your quick reply,

We are now rounding on the (my) problem...

If I do this:

uvm_default_comparer.check_type = 0;

does that turn off type checking for every comparison in the test? or does each object have it's own uvm_default_comparer?

My main issue is that I'm not entirely sure where the comparer sits? Is it part of the uvm_object subclass (where the compare/do_compare lives), or is it part of the uvm_in_order_class_comaparator?

i.e. where would I new the comparer? and where does the comparer get passed to object?

These are probably very dumb questions, but I'm pretty new to uvm, so thanks very much for your help.

Pete

Link to comment
Share on other sites

uvm_default_comparer.check_type = 0;

does that turn off type checking for every comparison in the test? or does each object have it's own uvm_default_comparer?

The default comparer is used by all objects, unless compare() is called with a specific comparer.

My main issue is that I'm not entirely sure where the comparer sits? Is it part of the uvm_object subclass (where the compare/do_compare lives), or is it part of the uvm_in_order_class_comaparator?

It does not sit anywhere. compare() uses the default comparer (which is a global class reference) when compare() is called with a null comparer.

i.e. where would I new the comparer? and where does the comparer get passed to object?

Anywhere new() can be called, before you call compare(). The comparer is a (optional) compare() parameter.

Erling

Link to comment
Share on other sites

Anywhere new() can be called, before you call compare(). The comparer is a (optional) compare() parameter.

Erling

Okay, so the next question is, where is compare function called?

I am using the in_order_class_comparator but when I have a look at it (and its hierarchy) I can't see the compare function being called. Or a reference to a comparer.

Do I have to create new comparator which explicitly calls the compare function? or is there some other mechanism for passing my comparer to the comparator?

Pete

Link to comment
Share on other sites

Okay, so the next question is, where is compare function called?

The compare() is called by a policy class of uvm_in_order_comparator, the default policy is uvm_class_comp. It calls compare() with a null comparer, i.e it is using the default comparer. If you want to use your own comparer with the in order comparator, you'll have to roll your own class compare policy and instantate the comparator with the that policy.

Erling

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...