DOC PREVIEW
MSU ECE 4743 - Nonblocking Assignments in Verilog Synthesis Coding Styles That Kill

This preview shows page 1-2-22-23 out of 23 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Nonblocking Assignments in Verilog Synthesis, CodingStyles That Kill!Clifford E. CummingsSunburst Design, Inc.ABSTRACTOne of the most misunderstood constructs in the Verilog language is the nonblockingassignment. Even very experienced Verilog designers do not fully understand how nonblockingassignments are scheduled in an IEEE compliant Verilog simulator and do not understand whenand why nonblocking assignments should be used. This paper details how Verilog blocking andnonblocking assignments are scheduled, gives important coding guidelines to infer correctsynthesizable logic and details coding styles to avoid Verilog simulation race conditions.SNUG-2000San Jose, CAVoted Best Paper1st PlaceSNUG San Jose 2000 Nonblocking Assignments In VerilogRev 1.2 Synthesis, Coding Styles that Kill21.0 IntroductionTwo well known Verilog coding guidelines for modeling logic are:• Guideline: Use blocking assignments in always blocks that are written to generatecombinational logic [1].• Guideline: Use nonblocking assignments in always blocks that are written to generatesequential logic [1].But why? In general, the answer is simulation related. Ignoring the above guidelines can stillinfer the correct synthesized logic, but the pre-synthesis simulation might not match the behaviorof the synthesized circuit.To understand the reasons behind the above guidelines, one needs to have a full understanding ofthe functionality and scheduling of Verilog blocking and nonblocking assignments. This paperwill detail the functionality and scheduling of blocking and nonblocking assignments.Throughout this paper, the following abbreviations will be used:RHS - the expression or variable on the right-hand-side of an equation will be abbreviated asRHS equation, RHS expression or RHS variable.LHS - the expression or variable on the left-hand-side of an equation will be abbreviated as LHSequation, LHS expression or LHS variable.2.0 Verilog race conditionsThe IEEE Verilog Standard [2] defines: which statements have a guaranteed order of execution("Determinism", section 5.4.1), and which statements do not have a guaranteed order ofexecution ("Nondeterminism", section 5.4.2 & "Race conditions", section 5.5).A Verilog race condition occurs when two or more statements that are scheduled to execute inthe same simulation time-step, would give different results when the order of statement executionis changed, as permitted by the IEEE Verilog Standard.To avoid race conditions, it is important to understand the scheduling of Verilog blocking andnonblocking assignments.SNUG San Jose 2000 Nonblocking Assignments In VerilogRev 1.2 Synthesis, Coding Styles that Kill33.0 Blocking assignmentsThe blocking assignment operator is an equal sign ("="). A blocking assignment gets its namebecause a blocking assignment must evaluate the RHS arguments and complete the assignmentwithout interruption from any other Verilog statement. The assignment is said to "block" otherassignments until the current assignment has completed. The one exception is a blockingassignment with timing delays on the RHS of the blocking operator, which is considered to be apoor coding style [3].Execution of blocking assignments can be viewed as a one-step process:1. Evaluate the RHS (right-hand side equation) and update the LHS (left-hand side expression)of the blocking assignment without interruption from any other Verilog statement.A blocking assignment "blocks" trailing assignments in the same always block from occurringuntil after the current assignment has been completedA problem with blocking assignments occurs when the RHS variable of one assignment in oneprocedural block is also the LHS variable of another assignment in another procedural block andboth equations are scheduled to execute in the same simulation time step, such as on the sameclock edge. If blocking assignments are not properly ordered, a race condition can occur. Whenblocking assignments are scheduled to execute in the same time step, the order execution isunknown.To illustrate this point, look at the Verilog code in Example 1.module fbosc1 (y1, y2, clk, rst); output y1, y2; input clk, rst; reg y1, y2; always @(posedge clk or posedge rst) if (rst) y1 = 0; // reset else y1 = y2; always @(posedge clk or posedge rst) if (rst) y2 = 1; // preset else y2 = y1;endmoduleExample 1 - Feedback oscillator with blocking assignmentsAccording to the IEEE Verilog Standard, the two always blocks can be scheduled in any order. Ifthe first always block executes first after a reset, both y1 and y2 will take on the value of 1. If thesecond always block executes first after a reset, both y1 and y2 will take on the value 0. Thisclearly represents a Verilog race condition.SNUG San Jose 2000 Nonblocking Assignments In VerilogRev 1.2 Synthesis, Coding Styles that Kill44.0 Nonblocking assignmentsThe nonblocking assignment operator is the same as the less-than-or-equal-to operator ("<="). Anonblocking assignment gets its name because the assignment evaluates the RHS expression of anonblocking statement at the beginning of a time step and schedules the LHS update to takeplace at the end of the time step. Between evaluation of the RHS expression and update of theLHS expression, other Verilog statements can be evaluated and updated and the RHS expressionof other Verilog nonblocking assignments can also be evaluated and LHS updates scheduled. Thenonblocking assignment does not block other Verilog statements from being evaluated.Execution of nonblocking assignments can be viewed as a two-step process:1. Evaluate the RHS of nonblocking statements at the beginning of the time step.2. Update the LHS of nonblocking statements at the end of the time step.Nonblocking assignments are only made to register data types and are therefore only permittedinside of procedural blocks, such as initial blocks and always blocks. Nonblocking assignmentsare not permitted in continuous assignments.To illustrate this point, look at the Verilog code in Example 2.module fbosc2 (y1, y2, clk, rst); output y1, y2; input clk, rst; reg y1, y2; always @(posedge clk or posedge rst) if (rst) y1 <= 0; // reset else y1 <= y2; always @(posedge clk or posedge rst) if (rst) y2 <= 1; // preset else y2 <= y1;endmoduleExample 2 - Feedback oscillator with nonblocking assignmentsAgain, according to the IEEE Verilog Standard, the two always blocks can be scheduled in anyorder. No matter which always block


View Full Document

MSU ECE 4743 - Nonblocking Assignments in Verilog Synthesis Coding Styles That Kill

Download Nonblocking Assignments in Verilog Synthesis Coding Styles That Kill
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Nonblocking Assignments in Verilog Synthesis Coding Styles That Kill and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Nonblocking Assignments in Verilog Synthesis Coding Styles That Kill 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?