Verilog is mainly used for describing digital circuit designs, but not all descriptive methods can be synthesized into actual hardware circuits. For example, some keywords used for simulation verification belong to the simulation verification language and can only be used during simulation; they cannot be synthesized into circuits, such as system tasks $dsiplay, initial statements, etc. Therefore, when using Verilog to design digital circuits, special attention must be paid to circuit synthesizability. Testbenches can be written as freely as desired, as long as the required simulation stimulus conditions can be constructed.

Synthesizable and Non-Synthesizable Structures

Structures supported by all synthesis tools

Structure TypeKeywordDescription
Port signalsinout,input,outputThere are only 3 types of port signals
Parameterparameter, localparam---
Signal variableswire, reg, tri, integer---
Modulemodule---
Gate-level primitivesand,nand,or,nor,xor,xnor,buf,not,bufif0,bufif1,notif0,notif1,supply0,supply1Just instantiate them directly
Instantiation---Supports module instantiation, gate-level primitive instantiation, etc.
Functions and tasksfunction, taskSupports descriptions without timing structures
Continuous assignmentassignDoes not support descriptions with delays
Procedural assignmentalways, begin, endCan design sequential logic or combinational logic
Conditional statementsif, case, defaultConditions cannot include comparisons with 'z' or 'x'
Loop statementsfor, while, foreverwhile and forever must contain @(posedge clk) or @(negedge clk) to avoid combinational logic loops
Edge-triggerednegedge,posedge---
Operators---Supports all operators except '===' and '!=='

Structures not supported by any synthesis tool

Structure TypeKeywordDescription
Variable typestimeTime-type variables used during simulation
System tasks---Most system tasks assist simulation and cannot be synthesized into actual circuits
For example, $display, $fopen, $finish, etc.
Procedural structuresinitialinitial is commonly used to assign initial values to signals during simulation
or to control the timing of stimulus signals
Parallel statementsfork, joinCommonly used to describe parallel structures in simulation
Parallel structures described by always @(posedge clk) are synthesizable
Delay statements#All descriptions with the delay symbol '#' are non-synthesizable
However, circuits will have delays during simulation, and synthesis will not report errors
Level-sensitive triggeringwaitMainly used for signal detection and initiation in simulation
Force assignment and releaseforce, releaseMainly used in simulation to block other driving sources and force-assign signals

Structures that synthesis tools may support

Structure TypeKeywordDescription
x/z conditional statementscasex, casezSome synthesis tools can recognize the non-'x/z' comparison logic in these statements
Nets of different strengthswand,triand,wor,triorNeeded when a signal has multiple driving sources
But digital design has now largely abandoned these variable types
Real variablesrealOften used for precise calculations in simulation
Process terminationdisableTerminates execution of a procedural block; most synthesis tools do not support this command
Loop statementsrepeat, while, foreverrepeat is commonly used in simulation to execute statements a fixed number of times
while and forever may also be synthesizable when the loop count is a constant
User-defined primitives (UDP)UDPIn fact, most synthesis tools currently support UDP
It's just that some older synthesis tools do not recognize it
Procedural continuous assignmentassign, deassignMost tools do not support synthesis of the reg data type under this operation
They support synthesis of the wire data type under this operation

Synthesizable Design Recommendations

When using Verilog for digital design, the following principles should be followed: synthesizable structures can be used boldly, non-synthesizable structures are used in simulation, and structures supported by some synthesis tools but not others should be avoided as much as possible.

Unless in certain special designs, such as clock gating, clock switching circuits, etc., do not write logic in the design that could potentially be synthesized into a latch. SeeVerilog Tutorial, Section "6.5 Verilog Avoiding Latches"。

When declaring variables, do not follow the C language format of assigning initial values to register variables. During simulation, variables will have the configured initial values, but after synthesis, the initial register values are indeterminate. If the initial signal values affect the logic function, the simulation process may miss opportunities to identify logic errors due to insufficient verification.

All internal registers should have initial values assigned via reset, to ensure every register has a stable state when the system is reset. Without a reset pin, the initial values of registers in the synthesized circuit cannot be determined, which may lead to functional errors.

Use blocking assignments for combinational logic and non-blocking assignments for sequential logic. Combinational logic is generally described with the continuous assignment statement assign. Circuits described with always can also be synthesized as combinational logic. For example, an "AND logic" can be described as follows:

    reg     F ; // note that it must be a reg type variable
    always @(*) begin
        F = A & B ;
    end  

Signals assigned in an always statement must be declared as reg type. In combinational logic, this reg variable will be synthesized into a wire net; in sequential logic, this reg variable will be synthesized into a flip-flop.

The same variable cannot be controlled by multiple clocks (or always blocks), nor can it be controlled by both edges of a clock. Such descriptions are also non-synthesizable.

Avoid xXorZvalues in the design, because synthesis tools can only recognize 0/10or1logic values.