To perform functional verification of your Verilog multiplier module in Vivado using UVM, we'll develop a UVM testbench that tests critical values and random values to ensure thorough coverage. Below is the UVM testbench code adapted for compatibility with Vivado. This testbench includes all the necessary UVM components: transaction class, sequence, driver, monitor, scoreboard, environment, and test classes.
Note: Before running the UVM testbench in Vivado, ensure that you have UVM library support integrated into your Vivado simulation environment, as Vivado requires additional setup to support UVM.
// Save this file as tb_multiplier.sv
`timescale 1ns/1ps
import uvm_pkg::*;
`include "uvm_macros.svh"
// Include all the UVM classes
`include "multiplier_transaction.sv"
`include "multiplier_sequence.sv"
`include "multiplier_driver.sv"
`include "multiplier_monitor.sv"
`include "multiplier_scoreboard.sv"
`include "multiplier_sequencer.sv"
`include "multiplier_env.sv"
`include "multiplier_test.sv"
module tb_multiplier;
// Clock and reset
logic clk;
logic rstn;
// Instantiate interface
multiplier_interface dut_if(.clk(clk), .rstn(rstn));
// Instantiate DUT
multiplier uut (
.clk(dut_if.clk),
.rstn(dut_if.rstn),
.x(dut_if.x),
.y(dut_if.y),
.mul_out(dut_if.mul_out),
.sign(dut_if.sign)
);
// Clock generation
initial begin
clk = 0;
forever #5 clk = ~clk; // 100 MHz clock
end
// Reset generation
initial begin
rstn = 1;
#2 rstn = 0; // Active low reset
#10 rstn = 1;
end
// Start the UVM test
initial begin
// Set the virtual interface
uvm_config_db#(virtual multiplier_interface)::set(null, "*", "tb_if", dut_if);
run_test("multiplier_test");
end
endmodule
Interface Definition
// Save this file as multiplier_interface.sv
interface multiplier_interface(input logic clk, input logic rstn);
logic [32:0] x;
logic [32:0] y;
logic [63:0] mul_out;
logic sign;
// Clocking block for driving inputs
clocking cb @ (posedge clk);
output x, y;
endclocking
// Clocking block for sampling outputs
clocking cbs @ (posedge clk);
input mul_out, sign;
endclocking
// Modport definitions
modport dut_if (
input clk, rstn,
input x, y,
output mul_out, sign
);
modport tb_if (
input clk, rstn,
output x, y,
input mul_out, sign
);
endinterface
Transaction Class
// Save this file as multiplier_transaction.sv
class multiplier_transaction extends uvm_sequence_item;
rand bit [32:0] x;
rand bit [32:0] y;
// Outputs
bit [63:0] mul_out;
bit sign;
// Expected outputs
bit [63:0] exp_mul_out;
bit exp_sign;
function new(string name = "multiplier_transaction");
super.new(name);
endfunction
// Display method
function void display(string msg = "");
$display("%s Transaction x = %h, y = %h, mul_out = %h, sign = %b", msg, x, y, mul_out, sign);
endfunction
endclass
Sequence Class
// Save this file as multiplier_sequence.sv
class multiplier_sequence extends uvm_sequence #( multiplier_transaction );
function new(string name = "multiplier_sequence");
super.new(name);
endfunction
task body();
multiplier_transaction tr;
// Generate critical test cases
// 1. Zero inputs
tr = multiplier_transaction::type_id::create("tr");
tr.x = 33'd0;
tr.y = 33'd0;
start_item(tr);
finish_item(tr);
// 2. Maximum positive values
tr = multiplier_transaction::type_id::create("tr");
tr.x = {1'b0,32'hFFFFFFFF};
tr.y = {1'b0,32'hFFFFFFFF};
start_item(tr);
finish_item(tr);
// 3. Maximum negative values
tr = multiplier_transaction::type_id::create("tr");
tr.x = {1'b1,32'h0};
tr.y = {1'b1,32'h0};
start_item(tr);
finish_item(tr);
// 4. Positive x, Negative y
tr = multiplier_transaction::type_id::create("tr");
tr.x = {1'b0,32'h7FFFFFFF};
tr.y = {1'b1,32'h1};
start_item(tr);
finish_item(tr);
// 5. Negative x, Positive y
tr = multiplier_transaction::type_id::create("tr");
tr.x = {1'b1,32'h1};
tr.y = {1'b0,32'h7FFFFFFF};
start_item(tr);
finish_item(tr);
// Random tests
repeat(10) begin
tr = multiplier_transaction::type_id::create("tr");
start_item(tr);
assert(tr.randomize());
finish_item(tr);
end
endtask
endclass
Driver Class
// Save this file as multiplier_driver.sv
class multiplier_driver extends uvm_driver #( multiplier_transaction );
virtual multiplier_interface tb_if;
function new(string name = "multiplier_driver", uvm_component parent);
super.new(name, parent);
endfunction
virtual function void build_phase(uvm_phase phase);
super.build_phase(phase);
if (!uvm_config_db#(virtual multiplier_interface)::get(this, "", "tb_if", tb_if)) begin
`uvm_fatal("TB_IF", "Unable to get virtual interface tb_if")
end
endfunction
task run_phase(uvm_phase phase);
super.run_phase(phase);
endtask
task main_phase(uvm_phase phase);
multiplier_transaction tr;
forever begin
seq_item_port.get_next_item(tr);
drive_item(tr);
seq_item_port.item_done();
end
endtask
task drive_item(multiplier_transaction tr);
// Drive inputs via the interface
@(posedge tb_if.clk);
tb_if.cb.x <= tr.x;
tb_if.cb.y <= tr.y;
endtask
endclass
Monitor Class
// Save this file as multiplier_monitor.sv
class multiplier_monitor extends uvm_component;
virtual multiplier_interface tb_if;
// Analysis port
uvm_analysis_port #( multiplier_transaction ) ap;
function new(string name = "multiplier_monitor", uvm_component parent);
super.new(name, parent);
ap = new("ap", this);
endfunction
virtual function void build_phase(uvm_phase phase);
super.build_phase(phase);
if (!uvm_config_db#(virtual multiplier_interface)::get(this, "", "tb_if", tb_if)) begin
`uvm_fatal("TB_IF", "Unable to get virtual interface tb_if")
end
endfunction
task run_phase(uvm_phase phase);
multiplier_transaction tr;
forever begin
tr = multiplier_transaction::type_id::create("tr", this);
// Capture inputs
@(posedge tb_if.clk);
tr.x = tb_if.x;
tr.y = tb_if.y;
// Capture outputs
tr.mul_out = tb_if.mul_out;
tr.sign = tb_if.sign;
// Send the transaction through the analysis port
ap.write(tr);
end
endtask
endclass
Scoreboard Class
// Save this file as multiplier_scoreboard.sv
class multiplier_scoreboard extends uvm_component;
uvm_analysis_imp #( multiplier_transaction, multiplier_scoreboard ) analysis_export;
function new(string name = "multiplier_scoreboard", uvm_component parent);
super.new(name, parent);
analysis_export = new("analysis_export", this);
endfunction
function void write(multiplier_transaction tr);
// Compute expected outputs
compute_expected(tr);
// Compare
if (tr.mul_out !== tr.exp_mul_out || tr.sign !== tr.exp_sign) begin
`uvm_error("MUL_ERR", $sformatf("Mismatch: x=%h y=%h Expected mul_out=%h sign=%b Got mul_out=%h sign=%b",
tr.x, tr.y, tr.exp_mul_out, tr.exp_sign, tr.mul_out, tr.sign));
end else begin
`uvm_info("MUL_OK", $sformatf("PASS: x=%h y=%h mul_out=%h sign=%b", tr.x, tr.y, tr.mul_out, tr.sign), UVM_LOW);
end
endfunction
function void compute_expected(ref multiplier_transaction tr);
bit signed [31:0] sx, sy;
bit signed [63:0] result;
bit [63:0] abs_result;
bit res_sign;
sx = tr.x[32] ? -$signed(tr.x[31:0]) : $signed(tr.x[31:0]);
sy = tr.y[32] ? -$signed(tr.y[31:0]) : $signed(tr.y[31:0]);
result = sx * sy;
abs_result = result[63] ? -result : result;
res_sign = result[63];
tr.exp_mul_out = abs_result;
tr.exp_sign = res_sign;
endfunction
endclass
Sequencer Class
// Save this file as multiplier_sequencer.sv
class multiplier_sequencer extends uvm_sequencer #( multiplier_transaction );
function new(string name = "multiplier_sequencer", uvm_component parent);
super.new(name, parent);
endfunction
endclass
Environment Class
// Save this file as multiplier_env.sv
class multiplier_env extends uvm_env;
multiplier_driver drv;
multiplier_monitor mon;
multiplier_scoreboard sb;
multiplier_sequencer seqr;
function new(string name = "multiplier_env", uvm_component parent);
super.new(name, parent);
endfunction
virtual function void build_phase(uvm_phase phase);
super.build_phase(phase);
seqr = multiplier_sequencer::type_id::create("seqr", this);
drv = multiplier_driver::type_id::create("drv", this);
mon = multiplier_monitor::type_id::create("mon", this);
sb = multiplier_scoreboard::type_id::create("sb", this);
// Connect virtual interface
virtual multiplier_interface tb_if;
if (!uvm_config_db#(virtual multiplier_interface)::get(this, "", "tb_if", tb_if)) begin
`uvm_fatal("TB_IF", "Unable to get virtual interface tb_if")
end
uvm_config_db#(virtual multiplier_interface)::set(this, "drv", "tb_if", tb_if);
uvm_config_db#(virtual multiplier_interface)::set(this, "mon", "tb_if", tb_if);
endfunction
virtual function void connect_phase(uvm_phase phase);
drv.seq_item_port.connect( seqr.seq_item_export );
mon.ap.connect( sb.analysis_export );
endfunction
endclass
Test Class
// Save this file as multiplier_test.sv
class multiplier_test extends uvm_test;
multiplier_env env;
function new(string name = "multiplier_test", uvm_component parent);
super.new(name, parent);
endfunction
virtual function void build_phase(uvm_phase phase);
super.build_phase(phase);
env = multiplier_env::type_id::create("env", this);
endfunction
task run_phase(uvm_phase phase);
multiplier_sequence seq;
phase.raise_objection(this);
seq = multiplier_sequence::type_id::create("seq");
seq.start(env.seqr);
phase.drop_objection(this);
endtask
endclass
Instructions for Running the UVM Testbench in Vivado
-
Setup UVM in Vivado:
- Ensure that UVM library is compiled and available in your Vivado simulation environment.
- In Vivado, you can compile the UVM library by adding the UVM library source files to your simulation sources or by pointing to a pre-compiled UVM library.
-
Add Sources to Vivado:
- Create a new Vivado project or use your existing one.
- Add all the files (
tb_multiplier.sv, multiplier_interface.sv, and all the *.sv class files) to your simulation sources.
- Include your multiplier module file.
-
Set Simulation Settings:
- Go to "Simulation Settings" and ensure that the top module is set to
tb_multiplier.
- Add the UVM compile-time and run-time options:
- For compilation: Include the UVM library directory in the include paths.
- For simulation: Define UVM macros as needed (e.g.,
+define+UVM_NO_DPI if required).
-
Compile and Run Simulation:
- Run the simulation from the Vivado GUI or via TCL commands.
- Observe the simulation log for PASS/FAIL messages from the scoreboard.
- The testbench will automatically apply critical test cases and random values to the DUT.
-
Analyze Results:
- Check the simulation transcript for any
uvm_error messages indicating mismatches.
- Review the
uvm_info messages for passing cases.
Summary
This UVM testbench will thoroughly test your multiplier module, covering critical edge cases and random values to identify any potential issues. The scoreboard compares the DUT output against the expected result, ensuring functional correctness. Ensure that your multiplier module's implementation matches the expected behavior for signed multiplication to pass all test cases.
If you encounter any issues with UVM setup in Vivado, refer to Xilinx documentation on integrating UVM with Vivado simulation, or consider using an external simulator that fully supports UVM for verification.