timescale 1ns / 1psmodule Shifting_Operation(rstn,pp0,pp1,pp2,pp3,pp4,pp5,pp6,pp7,pp8,pp9,pp10,pp11,pp12,pp13,pp14,pp15,pp16,spp0,spp1,spp2,spp3,spp4,spp5,spp6,spp7,spp8,spp9,spp10,spp11,spp12,spp13,spp14,spp15,spp16);input rstn;input [33:0]pp0,pp1,pp2,pp3,pp4,pp5,pp6,pp7,pp8,pp9,pp10,pp11,pp12,pp13,pp14,pp15,pp16;output [65:0]spp0,spp1,spp2,spp3,spp4,spp5,spp6,spp7,spp8,spp9,spp10,spp11,spp12,spp13,spp14,spp15,spp16;reg [65:0]spp[16:0]; //Internal Connection integer i,j;always @(*)begin if (rstn==0) begin //Active low reset for(i=0;i<17;i=i+1)begin //n/2 partial products in radix-4 spp[i]=0; end end else begin spp[0]<=signed(pp0);<br/> spp[1]<=signed(pp1); spp[2]<=signed(pp2);<br/> spp[3]<=signed(pp3); spp[4]<=signed(pp4);<br/> spp[5]<=signed(pp5); spp[6]<=signed(pp6);<br/> spp[7]<=signed(pp7); spp[8]<=signed(pp8);<br/> spp[9]<=signed(pp9); spp[10]<=signed(pp10);<br/> spp[11]<=signed(pp11); spp[12]<=signed(pp12);<br/> spp[13]<=signed(pp13); spp[14]<=signed(pp14);<br/> spp[15]<=signed(pp15); spp[16]<=$signed(pp16); for(i=0;i<17;i=i+1)begin for(j=0;j<i;j=j+1) begin spp[i]={spp[i],2'b00}; //Shifting Operation end end end end assign spp0=spp[0]; assign spp1=spp[1]; assign spp2=spp[2]; assign spp3=spp[3]; assign spp4=spp[4]; assign spp5=spp[5]; assign spp6=spp[6]; assign spp7=spp[7]; assign spp8=spp[8]; assign spp9=spp[9]; assign spp10=spp[10]; assign spp11=spp[11]; assign spp12=spp[12]; assign spp13=spp[13]; assign spp14=spp[14]; assign spp15=spp[15]; assign spp16=spp[16];endmoduletimescale 1ns / 1ps
//MAIN ADDING UNIT
module Adding_Unit(rstn,in0,in1,in2,in3,in4,in5,in6,in7,in8,in9,in10,in11,in12,in13,in14,in15,in16,out,sign);
input rstn;
input [65:0]in0,in1,in2,in3,in4,in5,in6,in7,in8,in9,in10,in11,in12,in13,in14,in15,in16;
output [63:0]out;
output sign;
wire[65:0]out_ns; //Internal connections
reg[63:0]out_ps; //Internal connections
wire[65:0]s[6:0];
integer i;
//Present state register
always @(*) begin
if (rstn==0) begin //Active low reset
out_ps<=0;
end
else begin
if(out_ns[65]==0)begin
out_ps<=out_ns[63:0];
end
else if(out_ns[65]==1)begin
out_ps<=(~out_ns[63:0])+1;
end
end
end
//Next state logic
csa csa0(in16,in15,in14,s[0]);
csa csa1(in13,in12,in11,s[1]);
csa csa2(in10,in9,in8,s[2]);
csa csa3(in7,in6,in5,s[3]);
csa csa4(in4,in3,in2,s[4]);
csa csa5(s[0],s[1],s[2],s[5]);
csa csa6(s[5],s[3],s[4],s[6]);
csa csa7(s[6],in0,in1,out_ns);
//Assigning output
assign out=out_ps;
assign sign=out_ns[65];
endmodule
//CSA ADDER MODULE
module csa(in1,in2,in3,sum_out);
input [65:0]in1,in2,in3;
output [65:0]sum_out;
wire [65:0]sum1;
wire [65:0]sum2;
full_adder fa0(in1[0],in2[0],in3[0],sum1[0],sum2[0]);
full_adder fa1(in1[1],in2[1],in3[1],sum1[1],sum2[1]);
full_adder fa2(in1[2],in2[2],in3[2],sum1[2],sum2[2]);
full_adder fa3(in1[3],in2[3],in3[3],sum1[3],sum2[3]);
full_adder fa4(in1[4],in2[4],in3[4],sum1[4],sum2[4]);
full_adder fa5(in1[5],in2[5],in3[5],sum1[5],sum2[5]);
full_adder fa6(in1[6],in2[6],in3[6],sum1[6],sum2[6]);
full_adder fa7(in1[7],in2[7],in3[7],sum1[7],sum2[7]);
full_adder fa8(in1[8],in2[8],in3[8],sum1[8],sum2[8]);
full_adder fa9(in1[9],in2[9],in3[9],sum1[9],sum2[9]);
full_adder fa10(in1[10],in2[10],in3[10],sum1[10],sum2[10]);
full_adder fa11(in1[11],in2[11],in3[11],sum1[11],sum2[11]);
full_adder fa12(in1[12],in2[12],in3[12],sum1[12],sum2[12]);
full_adder fa13(in1[13],in2[13],in3[13],sum1[13],sum2[13]);
full_adder fa14(in1[14],in2[14],in3[14],sum1[14],sum2[14]);
full_adder fa15(in1[15],in2[15],in3[15],sum1[15],sum2[15]);
full_adder fa16(in1[16],in2[16],in3[16],sum1[16],sum2[16]);
full_adder fa17(in1[17],in2[17],in3[17],sum1[17],sum2[17]);
full_adder fa18(in1[18],in2[18],in3[18],sum1[18],sum2[18]);
full_adder fa19(in1[19],in2[19],in3[19],sum1[19],sum2[19]);
full_adder fa20(in1[20],in2[20],in3[20],sum1[20],sum2[20]);
full_adder fa21(in1[21],in2[21],in3[21],sum1[21],sum2[21]);
full_adder fa22(in1[22],in2[22],in3[22],sum1[22],sum2[22]);
full_adder fa23(in1[23],in2[23],in3[23],sum1[23],sum2[23]);
full_adder fa24(in1[24],in2[24],in3[24],sum1[24],sum2[24]);
full_adder fa25(in1[25],in2[25],in3[25],sum1[25],sum2[25]);
full_adder fa26(in1[26],in2[26],in3[26],sum1[26],sum2[26]);
full_adder fa27(in1[27],in2[27],in3[27],sum1[27],sum2[27]);
full_adder fa28(in1[28],in2[28],in3[28],sum1[28],sum2[28]);
full_adder fa29(in1[29],in2[29],in3[29],sum1[29],sum2[29]);
full_adder fa30(in1[30],in2[30],in3[30],sum1[30],sum2[30]);
full_adder fa31(in1[31],in2[31],in3[31],sum1[31],sum2[31]);
full_adder fa32(in1[32],in2[32],in3[32],sum1[32],sum2[32]);
full_adder fa33(in1[33],in2[33],in3[33],sum1[33],sum2[33]);
full_adder fa34(in1[34],in2[34],in3[34],sum1[34],sum2[34]);
full_adder fa35(in1[35],in2[35],in3[35],sum1[35],sum2[35]);
full_adder fa36(in1[36],in2[36],in3[36],sum1[36],sum2[36]);
full_adder fa37(in1[37],in2[37],in3[37],sum1[37],sum2[37]);
full_adder fa38(in1[38],in2[38],in3[38],sum1[38],sum2[38]);
full_adder fa39(in1[39],in2[39],in3[39],sum1[39],sum2[39]);
full_adder fa40(in1[40],in2[40],in3[40],sum1[40],sum2[40]);
full_adder fa41(in1[41],in2[41],in3[41],sum1[41],sum2[41]);
full_adder fa42(in1[42],in2[42],in3[42],sum1[42],sum2[42]);
full_adder fa43(in1[43],in2[43],in3[43],sum1[43],sum2[43]);
full_adder fa44(in1[44],in2[44],in3[44],sum1[44],sum2[44]);
full_adder fa45(in1[45],in2[45],in3[45],sum1[45],sum2[45]);
full_adder fa46(in1[46],in2[46],in3[46],sum1[46],sum2[46]);
full_adder fa47(in1[47],in2[47],in3[47],sum1[47],sum2[47]);
full_adder fa48(in1[48],in2[48],in3[48],sum1[48],sum2[48]);
full_adder fa49(in1[49],in2[49],in3[49],sum1[49],sum2[49]);
full_adder fa50(in1[50],in2[50],in3[50],sum1[50],sum2[50]);
full_adder fa51(in1[51],in2[51],in3[51],sum1[51],sum2[51]);
full_adder fa52(in1[52],in2[52],in3[52],sum1[52],sum2[52]);
full_adder fa53(in1[53],in2[53],in3[53],sum1[53],sum2[53]);
full_adder fa54(in1[54],in2[54],in3[54],sum1[54],sum2[54]);
full_adder fa55(in1[55],in2[55],in3[55],sum1[55],sum2[55]);
full_adder fa56(in1[56],in2[56],in3[56],sum1[56],sum2[56]);
full_adder fa57(in1[57],in2[57],in3[57],sum1[57],sum2[57]);
full_adder fa58(in1[58],in2[58],in3[58],sum1[58],sum2[58]);
full_adder fa59(in1[59],in2[59],in3[59],sum1[59],sum2[59]);
full_adder fa60(in1[60],in2[60],in3[60],sum1[60],sum2[60]);
full_adder fa61(in1[61],in2[61],in3[61],sum1[61],sum2[61]);
full_adder fa62(in1[62],in2[62],in3[62],sum1[62],sum2[62]);
full_adder fa63(in1[63],in2[63],in3[63],sum1[63],sum2[63]);
full_adder fa64(in1[64],in2[64],in3[64],sum1[64],sum2[64]);
full_adder fa65(in1[65],in2[65],in3[65],sum1[65],sum2[65]);
assign sum_out=(sum1+(sum2<<1));
endmodule
To verify your Verilog multiplier using the Universal Verification Methodology (UVM) in Vivado, you'll need to create a UVM testbench that stimulates your design with various inputs, including critical and random values, and checks the outputs for correctness. Below is a step-by-step guide to help you set up your UVM testbench in Vivado, along with code examples tailored to your multiplier module.
1. Overview of UVM Testbench Components
A UVM testbench typically consists of the following components:
- Test: The top-level environment that sets up the simulation.
- Environment (env): Contains agents and scoreboards.
- Agent: Includes the driver, monitor, and sequencer for a specific interface.
- Driver: Sends stimulus to the Device Under Test (DUT).
- Monitor: Observes DUT outputs and passes data to the scoreboard.
- Sequencer: Generates sequences of transactions.
- Scoreboard: Checks the DUT outputs against expected results.
2. Setting Up the UVM Testbench
2.1. Define the Transaction Class
The transaction class represents the inputs and outputs of the DUT.
// multiplier_transaction.sv
class multiplier_transaction extends uvm_sequence_item;
// Input operands
rand bit [32:0] x;
rand bit [32:0] y;
// Output results
bit [63:0] mul_out;
bit sign;
// Constraints for randomization (optional)
constraint c_x {
// Add any specific constraints for x
}
constraint c_y {
// Add any specific constraints for y
}
`uvm_object_utils(multiplier_transaction)
function new(string name = "multiplier_transaction");
super.new(name);
endfunction
endclass
2.2. Create the Sequence
The sequence generates a series of transactions to stimulate the DUT.
// multiplier_sequence.sv
class multiplier_sequence extends uvm_sequence #(multiplier_transaction);
`uvm_object_utils(multiplier_sequence)
function new(string name = "multiplier_sequence");
super.new(name);
endfunction
virtual task body();
multiplier_transaction tr;
repeat (100) begin // Generate 100 random transactions
tr = multiplier_transaction::type_id::create("tr");
`uvm_do_with(tr, {
// Apply constraints or specific values if needed
})
end
endtask
endclass
2.3. Implement the Driver
The driver sends the transactions to the DUT inputs.
// multiplier_driver.sv
class multiplier_driver extends uvm_driver #(multiplier_transaction);
`uvm_component_utils(multiplier_driver)
// Virtual interface to DUT
virtual multiplier_if dut_if;
function new(string name = "multiplier_driver", uvm_component parent);
super.new(name, parent);
endfunction
function void build_phase(uvm_phase phase);
super.build_phase(phase);
if (!uvm_config_db#(virtual multiplier_if)::get(this, "", "dut_if", dut_if))
`uvm_fatal("NOVIF", "Virtual interface must be set for dut_if")
endfunction
virtual task run_phase(uvm_phase phase);
multiplier_transaction tr;
forever begin
seq_item_port.get_next_item(tr);
// Apply inputs to DUT
dut_if.x <= tr.x;
dut_if.y <= tr.y;
// Wait for a clock cycle (assuming inputs are sampled on posedge)
@(posedge dut_if.clk);
// Complete the transaction
seq_item_port.item_done();
end
endtask
endclass
2.4. Create the Monitor
The monitor observes the DUT outputs and collects data for checking.
// multiplier_monitor.sv
class multiplier_monitor extends uvm_monitor;
`uvm_component_utils(multiplier_monitor)
// Virtual interface to DUT
virtual multiplier_if dut_if;
// Analysis port to send transactions to scoreboard
uvm_analysis_port #(multiplier_transaction) ap;
function new(string name = "multiplier_monitor", uvm_component parent);
super.new(name, parent);
ap = new("ap", this);
endfunction
function void build_phase(uvm_phase phase);
super.build_phase(phase);
if (!uvm_config_db#(virtual multiplier_if)::get(this, "", "dut_if", dut_if))
`uvm_fatal("NOVIF", "Virtual interface must be set for dut_if")
endfunction
virtual task run_phase(uvm_phase phase);
multiplier_transaction tr;
forever begin
// Wait for the output to be valid (synchronized to clock)
@(posedge dut_if.clk);
tr = multiplier_transaction::type_id::create("tr");
tr.mul_out = dut_if.mul_out;
tr.sign = dut_if.sign;
// Send the transaction to the scoreboard
ap.write(tr);
end
endtask
endclass
2.5. Develop the Scoreboard
The scoreboard compares the DUT outputs with expected results.
// multiplier_scoreboard.sv
class multiplier_scoreboard extends uvm_component;
`uvm_component_utils(multiplier_scoreboard)
// Analysis export to receive transactions
uvm_analysis_imp #(multiplier_transaction, multiplier_scoreboard) sb_ap;
function new(string name = "multiplier_scoreboard", uvm_component parent);
super.new(name, parent);
sb_ap = new("sb_ap", this);
endfunction
virtual function void write(multiplier_transaction tr);
// Compute expected result
bit [63:0] expected_mul_out;
bit expected_sign;
// Reconstruct operands from inputs (you may need to store inputs in driver)
bit [32:0] x; // Retrieve operand x
bit [32:0] y; // Retrieve operand y
// Compute expected results
x = tr.x;
y = tr.y;
bit signed [31:0] x_data = x[31:0];
bit signed [31:0] y_data = y[31:0];
expected_mul_out = x_data * y_data;
expected_sign = x[32] ^ y[32];
// Compare expected and actual results
if ((expected_mul_out !== tr.mul_out) || (expected_sign !== tr.sign)) begin
`uvm_error("MISMATCH", $sformatf("Mismatch detected. Expected: mul_out=%0h, sign=%0b; Got: mul_out=%0h, sign=%0b",
expected_mul_out, expected_sign, tr.mul_out, tr.sign))
end else begin
`uvm_info("MATCH", "Output matches expected result.", UVM_LOW)
end
endfunction
endclass
2.6. Assemble the Agent
The agent groups the driver, monitor, and sequencer.
// multiplier_agent.sv
class multiplier_agent extends uvm_agent;
`uvm_component_utils(multiplier_agent)
multiplier_driver m_driver;
multiplier_monitor m_monitor;
uvm_sequencer #(multiplier_transaction) m_sequencer;
function new(string name = "multiplier_agent", uvm_component parent);
super.new(name, parent);
endfunction
function void build_phase(uvm_phase phase);
super.build_phase(phase);
m_driver = multiplier_driver::type_id::create("m_driver", this);
m_monitor = multiplier_monitor::type_id::create("m_monitor", this);
m_sequencer = uvm_sequencer #(multiplier_transaction)::type_id::create("m_sequencer", this);
// Connect driver and sequencer
m_driver.seq_item_port.connect(m_sequencer.seq_item_export);
endfunction
endclass
2.7. Construct the Environment
The environment contains the agent and the scoreboard.
// multiplier_env.sv
class multiplier_env extends uvm_env;
`uvm_component_utils(multiplier_env)
multiplier_agent m_agent;
multiplier_scoreboard m_scoreboard;
function new(string name = "multiplier_env", uvm_component parent);
super.new(name, parent);
endfunction
function void build_phase(uvm_phase phase);
super.build_phase(phase);
m_agent = multiplier_agent::type_id::create("m_agent", this);
m_scoreboard = multiplier_scoreboard::type_id::create("m_scoreboard", this);
endfunction
function void connect_phase(uvm_phase phase);
super.connect_phase(phase);
// Connect monitor to scoreboard
m_agent.m_monitor.ap.connect(m_scoreboard.sb_ap);
endfunction
endclass
2.8. Define the Test
The test initializes the environment and starts the sequence.
// multiplier_test.sv
class multiplier_test extends uvm_test;
`uvm_component_utils(multiplier_test)
multiplier_env m_env;
function new(string name = "multiplier_test", uvm_component parent);
super.new(name, parent);
endfunction
function void build_phase(uvm_phase phase);
super.build_phase(phase);
m_env = multiplier_env::type_id::create("m_env", this);
endfunction
task run_phase(uvm_phase phase);
super.run_phase(phase);
phase.raise_objection(this);
// Start the stimulus sequence
multiplier_sequence seq;
seq = multiplier_sequence::type_id::create("seq");
seq.start(m_env.m_agent.m_sequencer);
phase.drop_objection(this);
endtask
endclass
2.9. Setting Up the Interface
Define a virtual interface to connect the UVM components to the DUT.
// multiplier_if.sv
interface multiplier_if(input bit clk, input bit rstn);
logic [32:0] x;
logic [32:0] y;
logic [63:0] mul_out;
logic sign;
endinterface
2.10. DUT Wrapper Module
Wrap your DUT with the interface for easy connection.
// multiplier_top.sv
module multiplier_top;
bit clk;
bit rstn;
// Instantiate the interface
multiplier_if dut_if(clk, rstn);
// DUT instance
multiplier dut (
.clk(clk),
.rstn(rstn),
.x(dut_if.x),
.y(dut_if.y),
.mul_out(dut_if.mul_out),
.sign(dut_if.sign)
);
// Clock generation
initial clk = 0;
always #5 clk = ~clk; // 100MHz clock
// Reset
initial begin
rstn = 0;
#20 rstn = 1;
end
endmodule
2.11. Simulation Top Module
Instantiate the test and set up the simulation.
// tb_multiplier.sv
module tb_multiplier;
import uvm_pkg::*;
`include "uvm_macros.svh"
// Instantiate the DUT top module
multiplier_top top();
initial begin
// Set virtual interface
uvm_config_db#(virtual multiplier_if)::set(null, "*", "dut_if", top.dut_if);
// Run the test
run_test("multiplier_test");
end
endmodule
3. Critical and Random Value Testing
3.1. Critical Values
Critical values are inputs that are likely to expose design flaws, such as:
- Zero operands: Test cases where
x or y is zero.
- Maximum and minimum values: Test the limits of input ranges, like
2^31 - 1 and -2^31.
- One-bit values: Inputs with only one bit set.
- Negative numbers: Ensure sign handling is correct.
- Overflow scenarios: Values that cause the result to overflow.
3.2. Implementing Critical Tests
Modify the sequence to include these critical values.
class critical_multiplier_sequence extends uvm_sequence #(multiplier_transaction);
`uvm_object_utils(critical_multiplier_sequence)
function new(string name = "critical_multiplier_sequence");
super.new(name);
endfunction
virtual task body();
multiplier_transaction tr;
// Zero operands
tr = multiplier_transaction::type_id::create("zero_operands");
tr.x = 0;
tr.y = 0;
start_item(tr);
finish_item(tr);
// Maximum positive values
tr = multiplier_transaction::type_id::create("max_positive");
tr.x = 33'h0_7FFF_FFFF;
tr.y = 33'h0_7FFF_FFFF;
start_item(tr);
finish_item(tr);
// Maximum negative values
tr = multiplier_transaction::type_id::create("max_negative");
tr.x = 33'h1_8000_0000; // Sign bit set
tr.y = 33'h1_8000_0000; // Sign bit set
start_item(tr);
finish_item(tr);
// One-bit values
tr = multiplier_transaction::type_id::create("one_bit_values");
tr.x = 33'h0_0000_0001;
tr.y = 33'h0_0000_0001;
start_item(tr);
finish_item(tr);
// Negative and positive operand
tr = multiplier_transaction::type_id::create("neg_pos_operands");
tr.x = 33'h1_0000_0001; // Negative number
tr.y = 33'h0_0000_0001; // Positive number
start_item(tr);
finish_item(tr);
// Additional critical cases can be added similarly
endtask
endclass
3.3. Random Value Testing
Random testing explores a large input space to uncover unexpected issues.
Modify your original sequence to generate random values within the allowed range.
virtual task body();
multiplier_transaction tr;
repeat (1000) begin // Increase iterations for more thorough testing
tr = multiplier_transaction::type_id::create("tr");
`uvm_do_with(tr, {
// Optionally, add randomization constraints
})
end
endtask
4. Integrating with Vivado
4.1. Setting Up Vivado
- Create a Vivado Project: Include your Verilog source files and UVM testbench files.
- Add UVM Libraries: Ensure that the UVM library is available to the simulator.
- For Vivado, you may need to add the UVM library path to the simulation libraries.
- Set the Top Module: In the simulation settings, set
tb_multiplier as the top module for simulation.
- Compile Order: Ensure that the UVM packages and your testbench files are compiled before the simulation.
4.2. Running the Simulation
- In the Vivado simulator, run the simulation for a sufficient time to allow all transactions to process.
- Observe the simulation log for any errors reported by the scoreboard.
- Use waveforms to debug any mismatches.
5. Tips for Verification
- Assertions: Implement SystemVerilog assertions within your DUT or testbench to catch protocol violations.
- Coverage: Use functional coverage to measure how well your tests are exploring the input space.
- Debugging: If mismatches occur, use UVM's verbosity levels to get detailed information about transactions.
- Parameterized Tests: Create different sequences for specific test scenarios, such as corner cases.
By following this guide, you should be able to create a comprehensive UVM testbench for your multiplier module in Vivado. This testbench will not only test the functionality with various inputs but also help identify potential issues in your design when subjected to critical and random values.