Module 4: Introduction to Verilog HDL · 4.4 Structural Modeling

Gate Primitives

Structural modeling describes digital circuits by interconnecting instantiated hardware components. Built-in gate primitives represent the fundamental logic elements of the language. Synthesis tools emit structural netlists using gate primitives and standard cell libraries.

Built-In Logic Primitives

Verilog includes built-in primitives for standard logic operations: and, or, not, nand, nor, xor, and xnor. You instantiate primitives without writing module declarations.

Gate primitives follow a strict positional port ordering rule: the output terminal appears first, followed by one or more input terminals:

wire a, b, c;
wire y_and, y_or, y_not, y_nand, y_nor, y_xor, y_xnor, y_and3;

and  g_and  (y_and,  a, b);      // y_and = a & b
or   g_or   (y_or,   a, b);      // y_or = a | b
not  g_not  (y_not,  a);         // Inverter: single input
nand g_nand (y_nand, a, b);
nor  g_nor  (y_nor,  a, b);
xor  g_xor  (y_xor,  a, b);
xnor g_xnor (y_xnor, a, b);

and  g_and3 (y_and3, a, b, c);   // Multi-input gate: 3 inputs

Every primitive except not accepts two or more inputs. The not primitive accepts exactly one input terminal.

Instance names are optional in the language grammar. However, you must always assign descriptive instance names (g_and) to enable signal identification in waveform viewers.

Buffers and Tri-State Drivers

Verilog includes non-inverting buffers and conditional tri-state drivers:

buf    g_buf  (buf_out, a_in);     // buf_out = a_in (drive buffer)
bufif1 g_tri1 (y, data, en);       // Drives data when en equals 1; high-impedance (z) when 0
bufif0 g_tri0 (y, data, en);       // Drives data when en equals 0; high-impedance (z) when 1
notif1 g_ni1  (y, data, en);       // Inverting output enabled high
notif0 g_ni0  (y, data, en);       // Inverting output enabled low

Tri-state primitives drive high-impedance (z) states when deactivated. Internal FPGA fabrics do not support tri-state routing. Restrict tri-state primitives to top-level I/O pad modeling.

Structural SR Latch Implementation

The cross-coupled NAND latch illustrates structural modeling with signal feedback:

`timescale 1ns / 1ps
`default_nettype none

module sr_latch (
    input  wire s_n,    // Active-low set input
    input  wire r_n,    // Active-low reset input
    output wire q,
    output wire q_n
);
    nand g1 (q,   s_n, q_n);
    nand g2 (q_n, r_n, q);
endmodule

The output of each gate feeds an input of the opposite gate. The digital simulator resolves the closed-loop feedback across consecutive evaluation cycles.

$\overline{S}$ $\overline{R}$ $Q$ $\overline{Q}$ Operational State
1 1 Hold Hold Stored memory condition
0 1 1 0 Set condition
1 0 0 1 Reset condition
0 0 1 1 Invalid state (forbidden)

Structural 1-Bit Full Adder

The 1-bit full adder computes sum and carry outputs using standard Boolean equations:

$$sum = a \oplus b \oplus c_{in} \qquad c_{out} = ab + (a \oplus b), c_{in}$$

`timescale 1ns / 1ps
`default_nettype none

module full_adder_gates (
    input  wire a, b, cin,
    output wire sum, cout
);
    wire s1;   // a XOR b
    wire c1;   // a AND b
    wire c2;   // (a XOR b) AND cin

    xor g1 (s1,   a,  b);
    xor g2 (sum,  s1, cin);
    and g3 (c1,   a,  b);
    and g4 (c2,   s1, cin);
    or  g5 (cout, c1, c2);
endmodule

The five primitive statements map directly to the schematic diagram (Figure 1).

Full adder from primitives
Figure 1: 1-bit full adder schematic mapped to gate primitives

Application of Gate Primitives

Production RTL rarely describes arithmetic logic using individual gate primitives. Continuous assignments such as assign sum = a + b; enable synthesis tools to select optimized carry-lookahead architectures.

Engineers use gate primitives primarily to:

  1. Model low-level clock gating and asynchronous reset synchronizers.
  2. Construct ASIC technology cell libraries and gate-level behavioral models.
  3. Inspect and verify post-synthesis gate netlists during physical verification.

Practice Exercise

Construct a 2-to-1 multiplexer ($y = \overline{sel},a + sel,b$) using structural gate primitives.

Solution
`timescale 1ns / 1ps
`default_nettype none

module mux2to1 (
    input  wire a, b,
    input  wire sel,     // 0 selects a; 1 selects b
    output wire y
);
    wire sel_n, and_a, and_b;

    not g_inv  (sel_n, sel);
    and g_and0 (and_a, sel_n, a);
    and g_and1 (and_b, sel,   b);
    or  g_or   (y,     and_a, and_b);
endmodule

When sel equals 0, gate g_and0 transmits input a while g_and1 remains 0. When sel equals 1, gate g_and1 transmits input b.

The next article examines hierarchical module instantiation and parameter overriding techniques.

← Precedence and Width Module Instantiation →