RTL Debugging Guide
RTL Debugging Guide
Problem Statement
You are given a 3-stage pipeline that passes packet data and a valid signal. During simulation, output
packets are sometimes marked valid with wrong data.
Buggy Code
module packet_pipe (
input logic clk,
input logic rst_n,
input logic [31:0] din,
input logic vin,
output logic [31:0] dout,
output logic vout
);
v1 <= vin;
v2 <= vin; // BUG
v3 <= v2;
end
1
end
endmodule
Observed Failure
Root Cause
v2 is driven directly from vin instead of being pipelined from v1 . Control and data are misaligned.
Fix
v2 <= v1;
Explanation
In pipelines, all control signals must be registered exactly like data. Any mismatch causes packet
corruption.
Problem Statement
Buggy Code
2
logic [$clog2(DEPTH)-1:0] wr_ptr, rd_ptr;
logic [WIDTH-1:0] mem [0:DEPTH-1];
endmodule
Observed Failure
FIFO becomes full and empty at the same time, causing overwrites.
Root Cause
full and empty use identical logic. FIFO cannot distinguish wrap-around state.
Fix
Explanation
FIFO pointers need an extra MSB to differentiate full vs empty after wrap-around.
3
Debug Problem 3: FSM Controller – Missing Defaults and X
Propagation
Problem Statement
Buggy Code
always_comb begin
if (start)
next = LOAD;
else if (state == LOAD)
next = EXEC;
else if (state == EXEC)
next = DONE;
end
Observed Failure
Root Cause
Not all paths assign next . Also, logic ignores current state in IDLE properly.
Fix
always_comb begin
next = state;
case (state)
IDLE : if (start) next = LOAD;
LOAD : next = EXEC;
EXEC : next = DONE;
DONE : next = IDLE;
4
default: next = IDLE;
endcase
end
Explanation
FSM combinational logic must cover all states and assign defaults to prevent latch and X-propagation.
Problem Statement
Buggy Code
Observed Failure
Root Cause
RTL clock gating produces glitchy clocks and breaks STA assumptions.
Fix
5
Explanation
Never gate clocks in RTL. Use clock enable logic or proper clock-gating cells inserted by synthesis.
Problem Statement
Buggy Code
Observed Failure
Root Cause
Fix
Explanation
CDC requires two-flop synchronizers or proper handshake / toggle logic for pulses.
6
Debug Problem 6: Pipeline Stall / Flush Logic Bug
Problem Statement
A 2-stage pipeline supports stall and flush. During branch flush, wrong data leaks to output.
Buggy Code
if (flush) begin
s2_v <= 1'b0; // BUG: data not cleared
end else if (!stall) begin
s2_data <= s1_data;
s2_v <= s1_v;
end
end
end
Observed Failure
Root Cause
Flush clears only valid but not data, allowing stale data reuse.
Fix
if (flush) begin
s2_data <= '0;
s2_v <= 1'b0;
end
Explanation
Flush must invalidate both control and data to avoid ghost packets.
7
Debug Problem 7: Scoreboard Compare Mismatch (Verification
Logic Bug)
Problem Statement
Buggy Code
if (dut_valid) begin
if (exp_q.pop_front() != dut_data)
$error("Mismatch");
end
end
Observed Failure
Root Cause
Fix
if (dut_valid) begin
if (exp_q.size()==0)
$error("Unexpected DUT data");
else if (exp_q.pop_front() != dut_data)
$error("Mismatch");
end
Explanation
8
Debug Problem 8: AXI Write Channel Protocol Bug
Problem Statement
Buggy Code
if (awvalid) begin
wvalid <= 1'b1;
wdata <= data;
wlast <= 1'b1; // BUG
end
Observed Failure
Root Cause
Fix
Explanation
Problem Statement
Two clock domains share reset but sometimes one domain comes up earlier and misbehaves.
Buggy Code
9
always_ff @(posedge clkB or negedge rst_n)
if (!rst_n) qb <= 0; else qb <= db;
Observed Failure
Root Cause
Fix
Synchronize reset per clock domain using two flops before usage.
Explanation
Problem Statement
Buggy Code
always_comb begin
if (req0 && !busy) grant0 = 1;
if (req1 && !busy) grant1 = 1; // BUG: both can assert
end
Observed Failure
Root Cause
10
Fix
always_comb begin
grant0 = 0; grant1 = 0;
if (req0 && !busy) grant0 = 1;
else if (req1 && !busy) grant1 = 1;
end
Explanation
Problem Statement
Buggy Code
Observed Failure
Root Cause
Fix
Explanation
11
Debug Problem 12: Width Truncation in Accumulator
Problem Statement
Buggy Code
Observed Failure
Root Cause
No extended precision.
Fix
Explanation
Buggy Code
Issue
12
Fix
Explanation
Buggy Code
Issue
Fix
Explanation
Buggy Code
if (a == b)
hit = 1;
Issue
13
Fix
Explanation
Buggy Code
if (valid)
data <= next_data;
Issue
Fix
Explanation
Buggy Code
Issue
14
Fix
Explanation
Buggy Code
Issue
Fix
Add bypass logic when wr_en && rd_en && same addr.
Explanation
Buggy Code
Issue
15
Fix
Explanation
Buggy Code
if (in_valid)
buf <= in_data;
Issue
Fix
Explanation
Problem Statement
A CPU-like pipeline redirects PC on branch, but wrong instruction commits after flush.
Buggy Code
16
if (!stall) begin
pc1 <= pc_in;
v1 <= vin;
end
if (flush) begin
v2 <= 1'b0; // BUG: pc2 not cleared
end else if (!stall) begin
pc2 <= pc1;
v2 <= v1;
end
end
end
Observed Failure
Root Cause
Fix
if (flush) begin
pc2 <= '0;
v2 <= 1'b0;
end
Explanation
Flush must reset both data and valid to avoid ghost instructions.
Problem Statement
Buggy Code
17
else begin
if (send) credit <= credit - 1'b1;
if (recv) credit <= credit + 1'b1; // BUG
end
end
Observed Failure
Root Cause
Fix
Explanation
Problem Statement
AXI master returns data out of order under multiple outstanding reads.
Buggy Code
Observed Failure
Root Cause
18
Fix
Explanation
AXI requires maintaining ordering per ID, not simple FIFO pop.
Problem Statement
Buggy Code
Observed Failure
Root Cause
Fix
Explanation
19
Debug Problem 25: DMA Descriptor Fetch Corruption
Problem Statement
Buggy Code
if (desc_valid)
cur_desc <= mem_desc;
Observed Failure
Root Cause
Fix
Explanation
Problem Statement
Buggy Code
if (issue)
exe_reg <= op;
Observed Failure
20
Root Cause
Fix
if (flush)
exe_reg <= '0;
else if (issue)
exe_reg <= op;
Explanation
Problem Statement
Buggy Code
if (fill_en)
cache[line_idx] <= fill_data;
Observed Failure
Root Cause
Fix
Explanation
21
Debug Problem 28: Timer Interrupt Double Trigger
Problem Statement
Buggy Code
if (cnt == 0)
irq <= 1'b1;
Observed Failure
Root Cause
Fix
Explanation
Problem Statement
Read returns old data when read and write same address.
Buggy Code
Observed Failure
22
Root Cause
Fix
Explanation
Problem Statement
Buggy Code
Observed Failure
Root Cause
Fix
if (!cnt_max)
cnt <= cnt + event;
Explanation
23
Debug Problem 31: Out-of-Order Completion Queue Bug
Problem Statement
A completion queue returns responses to software, but occasionally responses mismatch the issued
transaction.
Buggy Code
typedef struct packed {logic [7:0] id; logic [31:0] data;} resp_t;
resp_t cq[$];
Observed Failure
Root Cause
Completion pops FIFO order, but responses may return out-of-order by ID.
Fix
int idx;
if (resp_valid && resp_ready) begin
idx = cq.find_index(x) with ([Link] == resp_id);
if (idx >= 0) [Link](idx);
end
Explanation
24
Debug Problem 32: Write Buffer Merge Corruption
Problem Statement
Write buffer merges stores to same cache line but corrupts data.
Buggy Code
if (wr_en) begin
buf_line <= wr_data; // BUG: overwrites whole line
end
Observed Failure
Root Cause
Fix
Explanation
Write buffers must merge using byte masks, not full overwrite.
Problem Statement
A load reads stale data when a prior store targets same address.
Buggy Code
if (ld_issue)
ld_data <= mem[ld_addr];
Observed Failure
25
Root Cause
No store-to-load forwarding.
Fix
if (stq_hit)
ld_data <= stq_data;
else
ld_data <= mem[ld_addr];
Explanation
Problem Statement
Buggy Code
if (send)
credit <= credit - 1'b1;
Observed Failure
Root Cause
Fix
Explanation
26
Debug Problem 35: Reorder Buffer Commit Bug
Problem Statement
Buggy Code
if (commit_en) begin
arch_reg <= rob_head_data;
rob_head <= rob_head + 1;
end
Observed Failure
Root Cause
Fix
Explanation
Problem Statement
27
Buggy Code
Observed Failure
Root Cause
Fix
if (aw_fire)
beat_cnt <= 0;
else if (w_fire)
beat_cnt <= beat_cnt + 1'b1;
Explanation
Problem Statement
Buggy Code
Observed Failure
Root Cause
28
Fix
if (!stall2) begin
if (!stall1) s1 <= din;
s2 <= s1;
end
Explanation
Problem Statement
Buggy Code
Observed Failure
Root Cause
Fix
if (!pwr_good)
state <= RESET_STATE;
else
state <= next_state;
Explanation
29
Debug Problem 39: Watchdog Timer False Trigger
Problem Statement
Buggy Code
if (kick)
wdt_cnt <= 0;
else
wdt_cnt <= wdt_cnt + 1'b1;
Observed Failure
Root Cause
Fix
Explanation
Problem Statement
Buggy Code
30
Observed Failure
Root Cause
Fix
Explanation
Bus width adapters must serialize wide words across multiple beats.
31
Excellence in World class
VLSI Training & Placements
+91- 9182280927