Structural, Dataflow or Behavioural
This final article of Module 4 reviews the three primary modeling styles in Verilog: structural, dataflow, and behavioral. Professional digital designs integrate all three styles within common source files. This guide presents selection criteria and summarizes the core foundations of the module.
The Three Modeling Styles
| Modeling Style | Language Keywords | Abstraction Level | Primary Applications |
|---|---|---|---|
| Structural | Module instances, gate primitives | Gate level and block level | Composing verified submodules, gate netlists, and vendor library primitives |
| Dataflow | Continuous assign statements |
Register-transfer level (RTL) | Single-expression combinational equations, multiplexers, and comparators |
| Behavioral | Procedural always blocks |
RTL and algorithmic | Sequential clocked registers, state machines, and multi-branch decoders |
All three modeling styles synthesize directly into silicon gates. Except for delay statements (#) and simulation-only constructs (initial), you can combine all three styles freely within a module.
Structural Modeling Criteria
Use structural modeling when:
- Interconnecting previously verified submodules into a higher-level subsystem.
- Instantiating vendor library primitives that synthesis tools cannot infer automatically (such as clock buffers
BUFG, phase-locked loopsPLL, and dual-port block RAMs):
BUFG u_clk_buf (
.I(clk_raw),
.O(clk)
);
- Reading and verifying post-synthesis gate netlists during physical design verification.
Dataflow Modeling Criteria
Use dataflow continuous assignments (assign) when expressing combinational logic as a direct boolean equation:
assign parity = ^data_byte;
assign zero = ~|alu_result;
assign eq = (a == b);
assign y = sel ? a : b;
assign sign_ext = {{8{narrow[7]}}, narrow};
assign carry = add_result[WIDTH];
assign overflow = (a[7] == b[7]) && (result[7] != a[7]);
Continuous assignments represent discrete logic nodes in schematic diagrams. Avoid dataflow modeling when managing multi-branch case structures or sequential memory storage.
Behavioral Modeling Criteria
Use procedural always blocks for:
- Clocked Sequential Logic: Flops and registers require edge-triggered procedural blocks:
always @(posedge clk or negedge rst_n) begin
if (!rst_n)
count <= 8'h00;
else
count <= count + 8'd1;
end
- Multi-Output Combinational Blocks: Updating several related signals from shared conditions:
always @(*) begin
alu_out = 8'h00; // Default assignments prevent latches
carry = 1'b0;
overflow = 1'b0;
case (opcode)
4'h0: begin
{carry, alu_out} = {1'b0, a} + {1'b0, b};
overflow = (a[7] == b[7]) && (alu_out[7] != a[7]);
end
4'h1: alu_out = a & b;
endcase
zero = ~|alu_out;
negative = alu_out[7];
end
- Finite State Machines: Managing sequential state transitions and combinational output logic.
Coexistence of Styles in a Single Module
Select the modeling style based on the specific requirements of each circuit element:
`timescale 1ns / 1ps
`default_nettype none
module mixed_style_example (
input wire [7:0] a,
input wire [7:0] b,
input wire clk,
input wire rst_n,
input wire sel,
output reg [7:0] result
);
// 1. Dataflow: 2-to-1 input selection multiplexer
wire [7:0] mux_out;
assign mux_out = sel ? a : b;
// 2. Structural: Verified submodule adder instantiation
wire [7:0] add_out;
wire cout_unused;
adder #(.WIDTH(8)) u_add (
.a (mux_out),
.b (8'h01),
.cin (1'b0),
.sum (add_out),
.cout(cout_unused)
);
// 3. Behavioral: Clocked sequential output register
always @(posedge clk or negedge rst_n) begin
if (!rst_n)
result <= 8'h00;
else
result <= add_out;
end
endmodule
The decision tree in Figure 1 illustrates this selection process:
- If the function is a verified module or hard IP primitive: use structural instantiation.
- If the logic requires sequential clock storage: use an edge-triggered behavioral
alwaysblock. - If the logic is a single combinational expression: use a dataflow
assignstatement. - If the combinational logic contains multiple outputs or case decodes: use a combinational behavioral
always @(*)block.
Comprehensive Review of Module 4
- Foundations of HDL: Hardware description languages model physical hardware concurrently. A digital simulator models temporal events, while a logic synthesis tool maps descriptions into standard cell netlists.
- Syntax and Grammar: Use ANSI-style port declarations. Declare nets as
wirefor continuous drivers andregfor procedural assignments. Use explicit descending index ranges[N-1:0]. Prefix source files with`timescaleand`default_nettype none. - Verilog Operators: Size numerical literals explicitly (
8'hAA). Protect multi-operator expressions with parentheses. Recognize self-determined contexts to prevent arithmetic overflow truncation. Use>>>exclusively with signed types. - Structural Modeling: Connect submodule ports using explicit named mapping (
.port(signal)). Tie off unused inputs to fixed logic levels. Replicate parameterized structures withgeneratefor-loops. - Dataflow Modeling: Continuous
assignstatements operate concurrently and continuously. Implement standard data steering using conditional operator chains.
Module 4 focused primarily on combinational logic. Module 5 introduces procedural modeling and sequential synchronous circuits: edge-triggered flip-flops, synchronous counters, shift registers, and finite state machines.