Vlsi Project10-1
Vlsi Project10-1
Usn: 1EW21EE013
Can_id: CAN_33840330
Introduction
This report presents the RTL design and functional verification of an 8-bit Subtractor using
Verilog. The 8-Bit Subtractor is a digital circuit designed to perform subtraction on two 8-bit
inputs (A and B). It uses two's complement arithmetic to compute the difference (Diff) and
provides a borrow output (Borrow_out) to indicate unsigned overflow. This module is
essential for arithmetic operations in processors, ALUs, and other digital systems. Its
efficient design ensures accurate and reliable subtraction. The implementation was verified
using EDA Playground with Aldec Riviera-PRO simulator.
Design Architecture
The architecture consists of two 8-bit inputs (A and B) and an optional borrow input
(Borrow_in). The subtrahend (B) is negated using two's complement (~B + 1). The
difference is computed by adding the minuend (A) and the negated subtrahend (B_comp). A
9-bit sum captures the borrow, and the final outputs are the 8-bit difference (Diff) and the
borrow flag (Borrow_out).
Block Diagram
Below is the block diagram of the 8-bit Subtractor:
RTL Code
module subtractor_8bit(
input [7:0] A, // 8-bit Minuend
input [7:0] B, // 8-bit Subtrahend
input Borrow_in, // Initial borrow (optional, usually 0)
output [7:0] Diff, // 8-bit Difference
output Borrow_out // Borrow output
);
wire [7:0] B_comp; // Two's complement of B
wire [8:0] Sum; // 9-bit sum to capture borrow
// Assign outputs
assign Diff = Sum[7:0];
assign Borrow_out = ~Sum[8]; // Borrow occurs when MSB is 0 (unsigned overflow)
endmodule
Testbench Code
module tb_subtractor_8bit;
// Inputs
reg [7:0] A;
reg [7:0] B;
reg Borrow_in;
// Outputs
wire [7:0] Diff;
wire Borrow_out;
// Testbench logic
initial begin
// Initialize inputs
A = 8'b00000000;
B = 8'b00000000;
Borrow_in = 0;
// End simulation
$finish;
end
endmodule
Simulation Results
Expected Output:
Driver
forever begin
this.item = uvm_object_registry#(subtractor_8bit_sequence_item,
"subtractor_8bit_sequence_item")::create("item");
seq_item_port.get_next_item(item);
drive(item);
seq_item_port.item_done();
end
endtask
Monitor
Agent
drv=subtractor_8bit_driver::type_id::create("drv",this);
mon=subtractor_8bit_monitor::type_id::create("mon",this);
seqr=subtractor_8bit_sequencer::type_id::create("seqr",this);
endfunction: build_phase
endclass: subtractor_8bit_agent
Environment
subtractor_8bit_agent agent;
subtractor_8bit_scoreboard scb;
// subtractor_8bit_coverage cov_subscriber; // Declare the coverage subscriber
function new(string name = "subtractor_8bit_env", uvm_component parent = null);
super.new(name, parent);
`uvm_info("subtractor_8bit_env", "Inside constructor of subtractor_8bit_env",
UVM_HIGH)
endfunction
endclass : subtractor_8bit_env
Test
subtractor_8bit_env env;
// subtractor_8bit_main_seq main_seq;
phase.raise_objection(this);
// repeat(`TEST_COUNT) begin
// main_seq=subtractor_8bit_main_seq::type_id::create("main_seq");class
subtractor_8bit_test extends uvm_test;
`uvm_component_utils(subtractor_8bit_test)
subtractor_8bit_env env;
// subtractor_8bit_main_seq main_seq;
// repeat(`TEST_COUNT) begin
// main_seq=subtractor_8bit_main_seq::type_id::create("main_seq");
// main_seq.start(env.agent.seqr);
// end
wait(env.scb.test_cnt==`TEST_COUNT);
phase.drop_objection(this);
endtask
*/
endclass: subtractor_8bit_test
// subtractor_8bit_env env;
subtractor_8bit_mul_seq mul_seq;
phase.raise_objection(this);
repeat(`TEST_COUNT) begin
// forever begin
mul_seq=subtractor_8bit_mul_seq::type_id::create("mul_seq");
mul_seq.start(env.agent.seqr);
end
wait(env.scb.test_cnt==`TEST_COUNT);
phase.drop_objection(this);
endtask
endclass: subtractor_8bit_mul_test
Testbench
`include "uvm_macros.svh"
import uvm_pkg::*;
`include "interface.sv"
`include "sequence_items.sv"
`include "sequencer.sv"
`include "sequence.sv"
`include "driver.sv"
`include "monitor.sv"
`include "scoreboard.sv"
`include "agent.sv"
`include "environment.sv"
`include "test.sv"
`timescale 1ns/1ns
`include "uvm_macros.svh"
module top;
// bit i_clk=0;
// bit i_rst;
subtractor_8bit_if top_if();
subtractor_8bit dut(
.A (top_if. A),
.B (top_if.B),
.Borrow_in (top_if.Borrow_in),
.Diff (top_if.Diff),
.Borrow_out (top_if.Borrow_out)
);
initial begin
// i_rst = 1;
// #2 i_rst =0;
end
initial begin
uvm_config_db #(virtual subtractor_8bit_if) :: set(null,"*","subtractor_8bit_vif",top_if);
`uvm_info("TOP","Configured database for interface...",UVM_LOW)
end
initial begin
run_test("subtractor_8bit_test");
end
initial begin
$dumpfile("waveform.vcd");
$dumpvars;
end
initial begin
#10000000;
$finish();
end
endmodule
// TODO: Receiving items from monitor in scoreboard
Stimulus Generation
- Development of constrained-random and directed test sequences.
- Use of UVM sequences and transaction-based stimulus generation.
Sequence Item
// randc logic [7:0] D0, D1, D2, D3, D4, D5, D6, D7; // 8-bit inputs
// randc logic [2:0] S; // 3-bit select
// logic [7:0] Y ; // 8-bit output
// randc logic i_up_down; // Control signal: 1 for UP, 0 for DOWN
// logic [3:0] o_count ; // Parameterized width counter output
module shifter_8bit (
input [7:0] data_in, // 8-bit input data
input [2:0] shift_amount, // Shift amount (0 to 7)
input shift_direction, // Shift direction (0: left, 1: right)
output [7:0] data_out // 8-bit shifted output
);
reg [7:0] shifted_data; // Temporary register to hold shifted data
*/
//`uvm_object_utils_begin(subtractor_8bit_sequence_item)
// `uvm_field_int(A, UVM_ALL_ON)
// `uvm_field_int(B, UVM_ALL_ON)
// `uvm_field_int(result, UVM_ALL_ON)
// `uvm_object_utils_end
endclass
Sequence
task body();
`uvm_info(get_name(), "Running main sequence...", UVM_HIGH);
this.item = uvm_object_registry#(subtractor_8bit_sequence_item,
"subtractor_8bit_sequence_item")::create("item");
start_item(item);
item.randomize();
finish_item(item);
endtask
endclass
Scoreboard
subtractor_8bit_sequence_item item[$];
subtractor_8bit_sequence_item s_item;
int test_cnt = 0;
int test_valid = 0;
int test_invalid = 0;
subtractor_8bit_ref(
item.A, // 8-bit Minuend
item.B, // 8-bit Subtrahend
item.Borrow_in, // Initial Borrow
ex_res, // 8-bit Difference
ex_borrow // Borrow Output
);
if ((ex_res == item.Diff) && (ex_borrow == item.Borrow_out)) begin
`uvm_info(get_name, $sformatf("[%0d/%0d] Test Passed", test_cnt, `TEST_COUNT),
UVM_HIGH);
test_analysis(item, ex_res, ex_borrow, 1);
test_valid++;
end else begin
`uvm_error(get_name, $sformatf("[%0d/%0d] Test failed", test_cnt, `TEST_COUNT));
test_analysis(item, ex_res, ex_borrow, 1);
test_invalid++;
end
endfunction
// Assign outputs
Diff = Sum[7:0];
Borrow_out = ~Sum[8]; // Borrow occurs when MSB is 0 (unsigned overflow)
endfunction
function void report_phase(uvm_phase phase);
super.report_phase(phase);
`uvm_info(get_name, $sformatf("Total tests: %0d", test_cnt), UVM_LOW)
`uvm_info(get_name, $sformatf("Passed tests: %0d", test_valid), UVM_LOW)
`uvm_info(get_name, $sformatf("Failed tests: %0d", (test_invalid / test_cnt) * 100),
UVM_LOW)
endfunction
endclass
- Error detection.
initial begin
$dumpfile("dump.vcd");
$dumpvars();
end
UVM Report
current_design ripple_carry_adder_8bit
set clk_name v_clk
set clk_period 2.5
set clk_io_pct 0.2
create_clock -name $clk_name -period $clk_period
Power Measurement:
Area Measurement:
Design area 235 u^2 13% utilization.
Timing Information:
Clock frequency
Group Slack
--------------------------------------------
max slew
max capacitance
Generated GDS
Below is the generated GDS file:
Conclusions
In this report, the RTL code of 8-bit Subtractor has been designed in Verilog. The code is
successfully verified with the UVM with 100% test case pass. The design code is further
processed in the OpenROAD tool to generate its GDS using the nangate45 platform. There is
no setup and hold violations.