Module 8: RTL Coding for Quality & Synthesis · 8.4 Common RTL Bugs & Debugging

X-Propagation in Practice

Section 8.3 explained static timing analysis and timing closure. Section 8.4 focuses on RTL functional defects and debugging techniques. This article analyzes how unknown logic values originate and propagate in Verilog simulations.

Sources of Unknown Values

In Verilog simulation, the x state indicates an unknown logic value. The simulator assigns an x when it cannot determine whether a node is logic 0 or logic 1. Physical silicon does not have an unknown voltage state; gates resolve to a physical 0 or 1. Simulation models use x to represent this hardware uncertainty accurately. Three primary conditions introduce unknown values into a simulation model:

  1. Uninitialized registers: Flip-flops without reset initialization evaluate to x at simulation start. Hardware registers power up in unpredictable states, which simulation models as x.

  2. Unconnected or floating ports: An unconnected input port or a partially driven bus evaluates to x on all undriven bits.

  3. Explicit assignment in RTL: Designers write assignments like default: data = 'x; in case statements. This practice detects invalid state transitions during simulation.

Propagation Through Combinational Logic

Unknown logic values propagate through combinational gates rather than resolving to valid states. For example, the expression 1'bx & 1'b1 produces an unknown result 1'bx. Because the simulator cannot determine the exact value of x, it does not guess. Arithmetic operators, logic gates, and relational comparisons propagate x downstream. Consequently, a single uninitialized register can corrupt large sections of combinational logic.

An uninitialised register’s X spreading through gates to the FSM state
Figure 1: X spreading from one register through downstream logic

Figure 1 illustrates an uninitialized register corrupting a finite state machine. When an unknown value reaches a state register, the state variable becomes x. An FSM in state x cannot evaluate its transition conditions. Comparisons such as state == IDLE evaluate to unknown. As a result, the state machine enters an unrecoverable lockup state.

Systematic Signal Tracing Procedure

Follow this systematic procedure to locate the source of an unknown value:

  1. Locate the earliest simulation timestamp where the unknown value appears in the waveform viewer.
  2. Identify the driver signal for the corrupted node at that timestamp.
  3. Trace backward through combinational logic to find the input registers.
  4. Continue tracing upstream until you locate the uninitialized register or floating wire.
// Defective design: this register lacks a reset condition
reg [7:0] counter;   // Initializes to X in simulation

always @(posedge clk) begin
    counter <= counter + 1;   // X + 1 produces X continuously
end

In the example above, counter never leaves the unknown state. Because x + 1 evaluates to x, the counter cannot recover without an explicit reset signal. All sequential registers must include a defined reset path to avoid this failure.

Do not insert conditional checks like if (val === 8'hxx) to force valid data in RTL. Suppressing x in simulation masks genuine hardware defects. Physical silicon resolves uninitialized nodes arbitrarily, which causes runtime functional failures. Always resolve the root cause by initializing registers and connecting all input ports.

Practice Exercise

A simulation testbench reports that an FSM state evaluates to x at simulation time 45 ns. The system reset was asserted and released before 20 ns. Describe the diagnostic steps to identify the defect.

Solution

First, verify that the state register includes a valid reset path in the sequential always block. If the reset logic is correct, the defect originates in the next-state logic. Inspect the inputs of the combinational next-state block at 45 ns in the waveform viewer. Identify which input signal transitions to x at or before 45 ns. Trace that signal upstream to its driving register or input port. Continue upstream until you locate an uninitialized register, a floating wire, or an invalid default assignment. Add appropriate initialization or wiring to correct the root cause.

Unknown values represent simulation uncertainty caused by uninitialized flip-flops or floating nets. Combinational operators propagate unknown states throughout downstream logic blocks. Engineers trace unknown values upstream to locate missing resets or open connections. The next article revisits latch inference and explains how to detect unwanted latches in synthesized designs.

← Reading a Timing Report Finding a Latch That Got Into Your Design →