To thoroughly verify your 33-bit signed multiplier design using the Universal Verification Methodology (UVM), we'll create a comprehensive testbench that covers all critical cases where the design may fail, as well as other functional scenarios required for proper verification.
Understanding the Design
Verification Plan
1. Identify Critical Test Cases
We need to test the multiplier with combinations that cover:
2. Create UVM Testbench Components
- Driver: Sends stimuli to the DUT (Device Under Test).
- Sequencer: Controls the flow of sequences.
- Monitor: Observes DUT inputs/outputs for coverage and checking.
- Scoreboard: Compares DUT outputs with expected results.
- Test Cases: Encapsulate different test scenarios.
Implementing the UVM Testbench
Below is a high-level outline of the UVM testbench code with explanations and code snippets.
1. Define the Transaction Class
This class represents the inputs and outputs for each transaction.
class mult_trans extends uvm_sequence_item;
rand bit [32:0] a; // 33-bit signed input A
rand bit [32:0] b; // 33-bit signed input B
bit [63:0] product; // 64-bit unsigned output
bit sign; // 1-bit sign output
`uvm_object_utils(mult_trans)
function new(string name = "mult_trans");
super.new(name);
endfunction
endclass
2. Develop the Sequence
Sequences generate different input stimuli based on the test cases identified.
class mult_sequence extends uvm_sequence #(mult_trans);
`uvm_object_utils(mult_sequence)
function new(string name = "mult_sequence");
super.new(name);
endfunction
task body();
mult_trans tr;
// Test Case Examples:
// 1. Positive * Positive
tr = mult_trans::type_id::create("pos_pos_tr");
tr.a = {1'b0, 32'h00000001}; // +1
tr.b = {1'b0, 32'h00000002}; // +2
start_item(tr);
finish_item(tr);
// 2. Positive * Negative
tr = mult_trans::type_id::create("pos_neg_tr");
tr.a = {1'b0, 32'h00000003}; // +3
tr.b = {1'b1, 32'h00000004}; // -4
start_item(tr);
finish_item(tr);
// 3. Negative * Positive
tr = mult_trans::type_id::create("neg_pos_tr");
tr.a = {1'b1, 32'h00000005}; // -5
tr.b = {1'b0, 32'h00000006}; // +6
start_item(tr);
finish_item(tr);
// 4. Negative * Negative
tr = mult_trans::type_id::create("neg_neg_tr");
tr.a = {1'b1, 32'h00000007}; // -7
tr.b = {1'b1, 32'h00000008}; // -8
start_item(tr);
finish_item(tr);
// 5. Zero Cases
// a) Zero * Any Number
tr = mult_trans::type_id::create("zero_any_tr");
tr.a = {1'b0, 32'h00000000}; // 0
tr.b = {1'b0, 32'hFFFFFFFF}; // Max positive
start_item(tr);
finish_item(tr);
// b) Any Number * Zero
tr = mult_trans::type_id::create("any_zero_tr");
tr.a = {1'b1, 32'hFFFFFFFF}; // Max negative
tr.b = {1'b0, 32'h00000000}; // 0
start_item(tr);
finish_item(tr);
// 6. Maximum Values
// a) Max Positive * Max Positive
tr = mult_trans::type_id::create("max_pos_pos_tr");
tr.a = {1'b0, 32'hFFFFFFFF};
tr.b = {1'b0, 32'hFFFFFFFF};
start_item(tr);
finish_item(tr);
// b) Max Negative * Max Negative
tr = mult_trans::type_id::create("max_neg_neg_tr");
tr.a = {1'b1, 32'h00000000};
tr.b = {1'b1, 32'h00000000};
start_item(tr);
finish_item(tr);
// More test cases can be added similarly to cover all critical values.
endtask
endclass
3. Create the Driver
The driver sends transactions to the DUT.
class mult_driver extends uvm_driver #(mult_trans);
`uvm_component_utils(mult_driver)
function new(string name, uvm_component parent);
super.new(name, parent);
endfunction
virtual task run_phase(uvm_phase phase);
forever begin
mult_trans tr;
seq_item_port.get_next_item(tr);
// Apply inputs to DUT
uvm_config_db#(bit [32:0])::set(this, "*", "a", tr.a);
uvm_config_db#(bit [32:0])::set(this, "*", "b", tr.b);
// Wait for one clock cycle or appropriate time
@(posedge dut.clk);
seq_item_port.item_done();
end
endtask
endclass
4. Implement the Monitor
The monitor observes and captures DUT inputs and outputs.
class mult_monitor extends uvm_monitor;
`uvm_component_utils(mult_monitor)
uvm_analysis_port #(mult_trans) analysis_port;
function new(string name, uvm_component parent);
super.new(name, parent);
analysis_port = new("analysis_port", this);
endfunction
task run_phase(uvm_phase phase);
forever begin
// Capture inputs and outputs
mult_trans tr = mult_trans::type_id::create("monitored_tr");
// Assuming you have access to dut inputs and outputs via virtual interface
tr.a = dut.a;
tr.b = dut.b;
tr.product = dut.product;
tr.sign = dut.sign;
// Send transaction to analysis components
analysis_port.write(tr);
@(posedge dut.clk);
end
endtask
endclass
5. Develop the Scoreboard
The scoreboard computes the expected results and compares them with the DUT outputs.
class mult_scoreboard extends uvm_component;
`uvm_component_utils(mult_scoreboard)
uvm_analysis_imp #(mult_trans, mult_scoreboard) analysis_imp;
function new(string name, uvm_component parent);
super.new(name, parent);
analysis_imp = new("analysis_imp", this);
endfunction
task write(mult_trans tr);
// Compute expected result
bit signed [32:0] signed_a;
bit signed [32:0] signed_b;
bit signed [65:0] signed_result;
bit [63:0] expected_product;
bit expected_sign;
// Sign-extend inputs
signed_a = { {32{tr.a[32]}}, tr.a[31:0] };
signed_b = { {32{tr.b[32]}}, tr.b[31:0] };
// Perform signed multiplication
signed_result = signed_a * signed_b;
// Determine expected sign
expected_sign = signed_result[65];
// Get absolute value
expected_product = signed_result[63:0];
if (expected_sign)
expected_product = -expected_product;
// Compare with DUT outputs
if (expected_product !== tr.product || expected_sign !== tr.sign) begin
`uvm_error("Mismatch", $sformatf("Mismatch detected for inputs A=%h, B=%h. Expected Product=%h, DUT Product=%h. Expected Sign=%b, DUT Sign=%b",
tr.a, tr.b, expected_product, tr.product, expected_sign, tr.sign))
end else begin
`uvm_info("Match", $sformatf("Match detected for inputs A=%h, B=%h. Product=%h, Sign=%b",
tr.a, tr.b, tr.product, tr.sign), UVM_LOW)
end
endtask
endclass
6. Assemble the Environment
Create an environment class to instantiate and connect all components.
class mult_env extends uvm_env;
`uvm_component_utils(mult_env)
mult_driver driver;
mult_monitor monitor;
mult_scoreboard scoreboard;
mult_sequencer sequencer;
function new(string name, uvm_component parent);
super.new(name, parent);
endfunction
function void build_phase(uvm_phase phase);
super.build_phase(phase);
driver = mult_driver::type_id::create("driver", this);
monitor = mult_monitor::type_id::create("monitor", this);
scoreboard = mult_scoreboard::type_id::create("scoreboard", this);
sequencer = mult_sequencer::type_id::create("sequencer", this);
// Connect the analysis port of monitor to scoreboard
monitor.analysis_port.connect(scoreboard.analysis_imp);
endfunction
function void connect_phase(uvm_phase phase);
super.connect_phase(phase);
driver.seq_item_port.connect(sequencer.seq_item_export);
endfunction
endclass
7. Create the Top-Level Test
Instantiate the environment and start the sequence.
class mult_test extends uvm_test;
`uvm_component_utils(mult_test)
mult_env env;
mult_sequence sequence;
function new(string name, uvm_component parent);
super.new(name, parent);
endfunction
function void build_phase(uvm_phase phase);
super.build_phase(phase);
env = mult_env::type_id::create("env", this);
endfunction
task run_phase(uvm_phase phase);
phase.raise_objection(this);
sequence = mult_sequence::type_id::create("sequence");
sequence.start(env.sequencer);
phase.drop_objection(this);
endtask
endclass
8. Testbench Top Module
The top module ties everything together.
module mult_tb;
import uvm_pkg::*;
`include "uvm_macros.svh"
// DUT instance
dut_multiplier dut(/* Port connections */);
initial begin
run_test("mult_test");
end
endmodule
Additional Test Cases for Comprehensive Verification
Conclusion
The provided UVM testbench skeleton covers the critical cases where the multiplier design may fail. By implementing these components and expanding upon the test cases, you can achieve thorough functional verification of your multiplier.
Note: Ensure that all interfaces and connections to the DUT are correctly defined in the testbench, and adjust the code as needed to match your specific DUT port names and signal widths.