Gareth
02-21-2008, 04:25 AM
The field utility macros do the right thing for the compare() method for an object, but the ovm_*_comparator classes expect the comparison method to be called comp(). Known issue? Seems like a bit of a duplication of effort that I have to generate the comp() method in the transaction class....
dlong
02-21-2008, 07:20 AM
The comp function and comparator have come from AVM whereas the compare function is generated by the OVM macros. I understand the need to keep the comp function for backwards compatibility but it does seem to be a pain having to write it yourself in order to use the comparators.
The solution I have used in my code is to provide a comparator policy and pair class that work with compare rather than comp.
//------------------------------------------------------------------
// my_object_comp policy compares two ovm_objects by calling their automated compare functions
class my_object_comp #( type T = int );
static function bit comp( input T a , input T b );
return a.compare( b );
endfunction
endclass // my_object_comp
//------------------------------------------------------------------
// my_object_pair - behaves like ovm_class_pair but comparison function is named compare
// and calls ovm_object::compare instead of comp
//
class my_object_pair #( type T1 = int ,
type T2 = T1 )
extends ovm_transaction;
typedef my_object_pair #( T1 , T2 ) this_type;
T1 first;
T2 second;
function new( input T1 f = null , input T2 s = null );
if( f == null ) begin
first = new;
end
else begin
first = f;
end
if( s == null ) begin
second = new;
end
else begin
second = s;
end
endfunction
function string convert2string;
string s;
$sformat( s , "pair : %s , %s" ,
first.convert2string() ,
second.convert2string() );
return s;
endfunction
function bit compare( this_type t );
return t.first.compare( first ) && t.second.compare( second );
endfunction
function void copy( input this_type t );
first.copy( t.first );
second.copy( t.second );
endfunction
function ovm_object clone();
this_type t;
t = new;
t.copy( this );
return t;
endfunction
endclass: my_object_pair
//-------------------------------------------------------------------
//----------------------------------------------------------------------
// CLASS in_order_object_comparator
//----------------------------------------------------------------------
// in_order_object_comparator uses the class comparison and
// printing policy classes. This can make use of the automatically
// generated compare and convert2string methods in the
// transaction type T
class my_in_order_object_comparator #( type T = int )
extends ovm_in_order_comparator #( T ,
my_object_comp #( T ) ,
ovm_class_converter #( T ) ,
my_object_pair #( T, T ) );
function new( string name ,
ovm_component parent);
super.new( name, parent );
endfunction
endclass : my_in_order_object_comparator
//-------------------------------------------------------------------
You can then pass any class derived from ovm_transaction that includes the field automation macros to my_in_order_object_comparator.
Perhaps something like this might find its way into a future release of OVM?
If not, or in the meantime, please feel free to use this code. I have included it as an attachment to make it easier to download.
Regards,
Dave
Powered by vBulletin™ Version 4.0.3 Copyright © 2010 vBulletin Solutions, Inc. All rights reserved.