Tb08 78 Cummings Chambers Pres User
Tb08 78 Cummings Chambers Pres User
Tb08 78 Cummings Chambers Pres User
SNUG 2018 1 of 36
What's in the Paper? … And Our Agenda
• virtual classes can have non-virtual, virtual & pure virtual methods
Virtual class methods are non-virtual by default Only virtual classes can declare pure virtual methods
SNUG 2018 4 of 36
Sunburst
Upcasting & Downcasting
Assuming Compatible Class Types
• To paraphrase:
– Any extended or derivative class handle can be assigned to a base class handle
– Only some base class handles can be assigned to an extended class handle
SystemVerilog requires a
type-check for downcasting
a =0
=4
showit() (base)
seta()
geta()
BASE(test_classes.base.showit): a= 4
OUTPUT
SNUG 2018 7 of 36
Illegal Casting of Base to Extended Handle
Illegal Downcasting
... ** Error: Illegal assignment …
Handle and bit
// e1 = b1; Types are not assignment compatible
declarations
e1good = $cast(e1, b1);
ILLEGAL $cast
module test; if (!e1good) $display("b1->e1 cast failed");
... ...
base b1, b2; ILLEGAL message
Base handle to extended
ext e1, e2; handle assignment or b1->e1 cast failed
bit e1good, casting is ILLEGAL
e2good;
b1 null b2 null e1 null e2 null
a =4 a =0
showit() (base) data=0
seta() showit() (ext)
geta() e1 would need to reference: seta() e1 is expecting
• e1.data this !!
• e1.setdata() (not available in geta()
the base class) setdata()
• e1.getdata()
getdata()
a =4 a =0
=2
showit() (base) data=0
data=6
seta() showit() (ext)
geta() seta()
geta()
setdata()
getdata()
EXT(test_classes.ext.showit): data= 6 a= 2
OUTPUT
SNUG 2018 9 of 36
Legal Assignment of Extended to Base Handle
Legal Upcasting
a =4 a =2 a =2
showit() (base) data=6 data=6
seta() showit() (base) showit() (ext)
Two views of the
geta() seta() seta()
same object
geta() geta()
setdata() setdata()
getdata() getdata()
BASE(test_classes.base.showit): a= 2
OUTPUT
SNUG 2018 10 of 36
Re-Construct The Extended Class Object
a =4 a =2 a =2
=0
=9
showit() (base) data=6 data=6
data=0
seta() showit() (base) showit() (ext)
Re-constructed
geta() seta() seta()
e1 object
geta() geta()
b2 still points to setdata() setdata()
the old e1 object getdata() getdata()
EXT(test_classes.ext.showit): data= 0 a= 9
OUTPUT
SNUG 2018 11 of 36
Illegal Access to Extended Object Methods
From a Base Class Handle NOTE: b2 handle does not have access to
setdata() or getdata() methods
Handle and bit ...
// b2.setdata(9); ** Error: Field/method name
declarations
// m_data = b2.getdata(); (setdata) not in 'b2'
module test; ...
... ** Error: Field/method name
base b1, b2; (getdata) not in 'b2
ext e1, e2;
bit e1good,
e2good;
b1 null b2 null e1 null e2 null
a =4 a =2 a =9
showit() (base) data=6 data=0
seta() showit() (base) showit() (ext)
Re-constructed
geta() seta() seta()
e1 object
geta() geta()
b2 still points to setdata() setdata()
the old e1 object getdata() getdata()
SNUG 2018 12 of 36
Casting-Back Base to Extended Handle
Downcasting Requires a Type-Check
** Error: Illegal assignment …
Handle and bit ... Types are not assignment compatible
declarations // e2 = b2;
e2good = $cast(e2, b2); LEGAL $cast
module test; if (e2good) $display("b2->e2 cast PASSED!");
... e2.showit; LEGAL message
base b1, b2; end
ext e1, e2; endmodule b2->e2 cast PASSED
b2 and e2 point to
bit e1good,
e2good; the same object
a =4 a =2 a =9 a =2
showit() (base) data=6 data=0 data=6
seta() showit() (base) showit() (ext) showit() (ext)
geta() seta() seta() seta()
geta() geta() geta()
Two views of the setdata() setdata() setdata()
same object getdata() getdata() getdata()
• Using rhs_ means that casting is done in the form $cast(rhs_, rhs);
This is confusing and therefore
a poor practice
Guideline #3: Declare local transaction handles using distinct names such as tr and
avoid local transaction handle names such as rhs_
SNUG 2018 19 of 36
Pure Virtual Methods
SystemVerilog-2009 Enhancement
SNUG 2018 20 of 36
Pure Virtual Methods
Two important purposes
virtual class vc1a;
bit [7:0] a;
pure virtual method
(1) pure virtual methods can only be
pure virtual function void seta(bit [7:0] val);
endclass a method prototype
virtual class vc2a extends vc1a; virtual class vc2b extends vc1b;
vc2a does NOT override
virtual function void seta(bit [7:0] val);
seta() method
endclass a = val;
endfunction
vc2b DOES override
endclass
seta() method
non-virtual classes
Guideline #4: Declare a pure method whenever it is important to force a derivative class
to implement the method, as is done by the uvm_subscriber virtual class
SNUG 2018 24 of 36
Virtual Interfaces
Techniques & Usage
SNUG 2018 25 of 36
Virtual Interface Styles
• VIF styles:
– Pass an interface handle down through class constructors for use by a test
Somewhat straight-forward passing of vif handles Shown in the paper
through constructors, but tedious (not shown in this presentation)
Recommended UVM-style
Typically stored from
– Store the vif handle into the uvm_config_db. Use these methods: top module
uvm_config_db#(virtual dut_if)::set(null, "*", "vif" dif);
uvm_config_db#(virtual dut_if)::get(this, "", "vif" vif);
Typically retrieved by
Simple technique added to UVM (not available in OVM)
driver and monitor
SNUG 2018 26 of 36
Requirements for Virtual Interfaces
• 3 Requirements
– Top module, DUT and real interface to communicate with the DUT
An instantiated copy
of the interface
– You will need a virtual interface to communicate with the test class
A virtual interface handle
declared in a class
– You need a way to tie the real interface to the virtual interface
You need a way to pass a real interface handle
to a virtual interface handle in a class object
SNUG 2018 27 of 36
Interface connections to DUT ports
alu_reg w/ Interface Example
module top; module alu_reg (
logic clk; output logic [15:0] acc_out,
clkgen clkgen (.*); input logic [15:0] din1, din2,
dut_if dif (.*); input op_e opcode,
alu_reg alu_reg (.acc_out(dif.acc_out), .din1(dif.din1), input logic clk, rst_n);
.din2(dif.din2), .opcode(dif.opcode),
.rst_n(dif.rst_n), .*);
... ...
endmodule endmodule
dif dut_if
SNUG 2018 33 of 36
Summary of Guidelines
Guideline #3: Declare local transaction handles using distinct names such as tr and
avoid local transaction handle names such as rhs_
Guideline #4: Declare a pure method whenever it is important to force a derivative class
to implement the method, as is done by the uvm_subscriber virtual class
SNUG 2018 34 of 36
Acknowledgements
Thanks!
• John Dickol and Don Mills for their reviews and comments of the paper and
slides
SNUG 2018 35 of 36
SNUG 2018 36 of 36
SystemVerilog Virtual Classes, Methods, Interfaces
Their Use in Verification and UVM
SNUG 2018 37 of 36