Understanding Verilog Blocking and Nonblocking ... - Sutherland HDL
Understanding Verilog Blocking and Nonblocking ... - Sutherland HDL
Understanding Verilog Blocking and Nonblocking ... - Sutherland HDL
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
<strong>Blocking</strong>Procedural AssignmentsSutherl<strong>and</strong>H D L6➤ The = token represents a blocking procedural assignment➤ Evaluated <strong>and</strong> assigned in a single step➤ Execution flow within the procedure is blocked until theassignment is completed➤ Evaluations of concurrent statements in the same time stepare blocked until the assignment is completedThese examples will not work ⎯ Why not?//swap //swap bytes bytes in in word wordalways always @(posedge clk) clk)begin beginword[15:8] = word[ word[ 7:0]; 7:0];word[ word[ 7:0] 7:0] = word[15:8];end end//swap //swap bytes bytes in in word wordalways always @(posedge clk) clk)fork forkword[15:8] = word[ word[ 7:0]; 7:0];word[ word[ 7:0] 7:0] = word[15:8];join join
Non-<strong>Blocking</strong>Procedural AssignmentsSutherl<strong>and</strong>H D L7➤ The
ConcurrentProcedural Assignments10Sutherl<strong>and</strong>H D LThe order of concurrent evaluation is indeterminate➤ Concurrent blocking assignments have unpredictable resultsalways @(posedge clk)#5 A = A + 1;always @(posedge clk)#5 B = A + 1;Unpredictable Result:(new value of B could be evaluated beforeor after A changes)➤ Concurrent non-blocking assignments have predictable resultsalways @(posedge clk)#5 A
Delayed AssignmentProcedural Assignments12Sutherl<strong>and</strong>H D L➤ An intra-assignment assignment delay places the timing control after theassignment token➤ The right-h<strong>and</strong> h<strong>and</strong> side is evaluated before the delay➤ The left-h<strong>and</strong> side is assigned after the delayalways @(A)A is evaluated at the time it changes, butB = #5 A;is not assigned to B until after 5 time unitsalways @(negedge clk)Q
Intra-Assignment DelaysWith Repeat Loops13Sutherl<strong>and</strong>H D L➤ An edge-sensitive intra-assignment assignment timing control permits aspecial use of the repeat loop➤ The edge sensitive time control may be repeated severaltimes before the delay is completed➤ Either the blocking or the non-blocking assignment may beusedalways @(IN)OUT OUT
Choosing theCorrect Procedural Assignment14Sutherl<strong>and</strong>H D L➤ Which procedural assignment should be used to model acombinatorial logic buffer?always @(in)#5 out = in;always @(in)#5 out
TransitionPropagation Methods15Sutherl<strong>and</strong>H D L➤ Hardware has two primary propagation delay methods:➤ Inertial delay models devices with finite switching speeds;input glitches do not propagate to the output10 20 30 40 50 6010 20 30 40 50 60Buffer with a 10 nanosecond propagation delay➤ Transport delay models devices with near infiniteswitching speeds; input glitches propagate to the output10 20 30 40 50 6010 20 30 40 50 60Buffer with a 10 nanosecond propagation delay
Combinational LogicProcedural Assignments16Sutherl<strong>and</strong>H D L➤ How will these procedural assignments behave?in1020 30 40 50 6033 36 45<strong>Blocking</strong>,No delayalways @(in)o1 = in;o1zero delayNon-blocking,No delayalways @(in)o2
Sequential LogicProcedural Assignments17Sutherl<strong>and</strong>H D L➤ How will these procedural assignments behave?➤ Sequential assignments➤ No delaysclkin1020 30 40 50 6035 53always @(posedge clk)beginy1 = in;y2 = y1;endalways @(posedge clk)beginy1
Sequential LogicProcedural Assignments18Sutherl<strong>and</strong>H D L➤ How will these procedural assignments behave?➤ Sequential assignments➤ Delayed evaluationclkin1020 30 40 50 6035 53always @(posedge clk)begin#5 y1 = in;#5 y2 = y1;endalways @(posedge clk)begin#5 y1
Sequential LogicProcedural Assignments19Sutherl<strong>and</strong>H D L➤ How will these procedural assignments behave?➤ Sequential assignments➤ Delayed assignmentclkin1020 30 40 50 6035 53always @(posedge clk)beginy1 = #5 in;y2 = #5 y1;endalways @(posedge clk)beginy1
Sequential LogicProcedural Assignments20Sutherl<strong>and</strong>H D L➤ How will these procedural assignments behave?➤ Concurrent assignments➤ No delaysclkin1020 30 40 50 6035 53always @(posedge clk)y1 = in;always @(posedge clk)y2 = y1;?y1y2y1y2? ? ? ??? ??shift register with race conditionalways @(posedge clk)y1
Sequential LogicProcedural Assignments21Sutherl<strong>and</strong>H D L➤ How will these procedural assignments behave?➤ Concurrent assignments➤ Delayed evaluationclkin1020 30 40 50 6035 53always @(posedge clk)#5 y1 = in;always @(posedge clk)#5 y2 = y1;#5#5?y1y2y1y2 ? ? ?shift register with race condition?????? ?always @(posedge clk)#5 y1
Sequential LogicProcedural Assignments22Sutherl<strong>and</strong>H D L➤ How will these procedural assignments behave?➤ Concurrent assignments➤ Delayed assignmentclkin1020 30 40 50 6035 53always @(posedge clk)y1 = #5 in;always @(posedge clk)y2 = #5 y1;always @(posedge clk)y1
Rules of Thumb forProcedural Assignments23Sutherl<strong>and</strong>H D L➤ Combinational Logic:➤ No delays: Use blocking assignments ( a = b; )➤ Inertial delays: Use delayed evaluation blockingassignments ( #5 a = b; )➤ Transport delays: Use delayed assignment non-blockingassignments ( a
An Exception to Non-blockingAssignments in Sequential Logic24Sutherl<strong>and</strong>H D L➤ Do not use a non-blocking assignment if another statement inthe procedure requires the new value in the same time stepbegin#5 A
Exercise 3:Procedural Assignments25Sutherl<strong>and</strong>H D L➤ Write a procedure for an adder (combinational logic) thatassigns C the sum of A plus B with a 7ns propagation delay.always @(A @(A or or B) B)#7 #7 C = A + B; B;➤ Write the procedure(s) for a 4-bit 4wide shift register (positiveedge triggered) of clock <strong>and</strong> has a 4ns propagation delay.always @(posedge clk) clk)always @(posedge clk) clk)beginy1 y1
Exercise 3 (continued):Procedural Assignments26Sutherl<strong>and</strong>H D L➤ Write a <strong>Verilog</strong> procedure for a “black box” ALU pipeline thattakes 8 clock cycles to execute an instruction. The pipelinetriggers on the positive edge of clock. The “black box” isrepresented as call to a function named ALU with inputs A, B<strong>and</strong> OPCODE.How many <strong>Verilog</strong>statements does ittake to model aneight stage pipeline?always @(posedge clk) clk)alu_out