Module 9: SystemVerilog for Design & Verification · 9.1 SystemVerilog Design Enhancements

The logic Type

Section 4.2 explained the historical differences between wire and reg data types in classic Verilog. SystemVerilog simplifies digital design by introducing the unified logic data type. This article explains how logic eliminates semantic confusion while enforcing stricter multi-driver checking.

What logic Is

The logic keyword defines a standard 4-state data type (0, 1, x, z). Unlike classic Verilog, you can drive a logic signal using continuous assignments or procedural blocks. The compiler determines hardware synthesis targets from assignment context rather than variable type.

// Classic Verilog: requires distinct types for procedural and continuous contexts
wire combinational_result;
assign combinational_result = a & b;

reg sequential_result;
always @(posedge clk) sequential_result <= d;
// SystemVerilog: logic functions in both contexts
logic combinational_result;
assign combinational_result = a & b;

logic sequential_result;
always_ff @(posedge clk) sequential_result <= d;

In the SystemVerilog example, both signals use the logic data type. The synthesis tool infers combinational gates or sequential registers from the procedural sensitivity list. This unified syntax removes the misleading historical association between reg and physical flip-flop registers.

When wire Is Required

The logic type permits only a single driver on any given net. Therefore, logic cannot model bidirectional or multi-driver buses where multiple sources connect directly. Shared tri-state buses still require the wire net type:

// Tri-state bus: requires wire because logic prohibits multiple drivers
wire [7:0] shared_bus;
assign shared_bus = (driver_a_en) ? data_a : 8'bz;
assign shared_bus = (driver_b_en) ? data_b : 8'bz;

The single-driver restriction in logic provides valuable compile-time protection. If an engineer accidentally drives a logic net from multiple blocks, the compiler generates a syntax error. This feature eliminates the multi-driver conflicts discussed in Section 8.4 during compilation.

Converting Verilog Code to SystemVerilog

Migrating existing Verilog-2001 source code to SystemVerilog is straightforward:

module counter (
    input  logic       clk, rst_n, en,
    output logic [7:0] count   // Converted from: output reg [7:0] count
);
    always_ff @(posedge clk or negedge rst_n) begin
        if (!rst_n) count <= 8'b0;
        else if (en) count <= count + 1'b1;
    end
endmodule

Convert all module ports and internal signals to logic. Retain wire only for explicit tri-state buses and external bidirectional pads. Modern industry coding guidelines recommend logic as the default type for all RTL digital designs.

Practice Exercise

Convert the following Verilog module to SystemVerilog using logic. Retain the wire type only where multiple drivers or high-impedance states require it.

module bus_driver (
    input  wire       clk, rst_n, drive_en,
    input  wire [7:0] data_in,
    output wire [7:0] shared_bus,
    output reg  [7:0] status_reg
);
    assign shared_bus = drive_en ? data_in : 8'bz;
    always @(posedge clk or negedge rst_n) begin
        if (!rst_n) status_reg <= 8'b0;
        else        status_reg <= data_in;
    end
endmodule
Solution
module bus_driver (
    input  logic       clk, rst_n, drive_en,
    input  logic [7:0] data_in,
    output wire  [7:0] shared_bus,     // Must remain wire: bidirectional tri-state bus
    output logic [7:0] status_reg      // Converted to logic
);
    assign shared_bus = drive_en ? data_in : 8'bz;
    always_ff @(posedge clk or negedge rst_n) begin
        if (!rst_n) status_reg <= 8'b0;
        else        status_reg <= data_in;
    end
endmodule

The shared_bus signal must retain the wire type because it uses high-impedance tri-state assignments. All other ports and registers convert directly to logic.

The logic data type replaces wire and reg for point-to-point signals. It enforces single-driver checking at compile time to prevent bus contention defects. Retain wire only for physical multi-driver and tri-state networks. The next article introduces specialized procedural blocks: always_ff, always_comb, and always_latch.

always_ff, always_comb and always_latch →