Understanding Verilog Blocking and Non-blocking Assignments



Similar documents
More Verilog. 8-bit Register with Synchronous Reset. Shift Register Example. N-bit Register with Asynchronous Reset.

ECE232: Hardware Organization and Design. Part 3: Verilog Tutorial. Basic Verilog

A New Paradigm for Synchronous State Machine Design in Verilog

Chapter 7: Advanced Modeling Techniques

Modeling Sequential Elements with Verilog. Prof. Chien-Nan Liu TEL: ext: Sequential Circuit

Sequential Logic. (Materials taken from: Principles of Computer Hardware by Alan Clements )

Finite State Machine Design and VHDL Coding Techniques

ECE 451 Verilog Exercises. Sept 14, James Barnes

Registers & Counters

LAB #4 Sequential Logic, Latches, Flip-Flops, Shift Registers, and Counters

A Verilog HDL Test Bench Primer Application Note

Let s put together a Manual Processor

Modeling Latches and Flip-flops

Asynchronous & Synchronous Reset Design Techniques - Part Deux

Chapter 13: Verification

Modeling Registers and Counters

VHDL GUIDELINES FOR SYNTHESIS

Chapter 2 Ensuring RTL Intent

Lesson 12 Sequential Circuits: Flip-Flops

State Machines in VHDL

An Integer Square Root Algorithm

EXPERIMENT 8. Flip-Flops and Sequential Circuits

Module 3: Floyd, Digital Fundamental

CS 61C: Great Ideas in Computer Architecture Finite State Machines. Machine Interpreta4on

Design of Digital Circuits (SS16)

ECE 3401 Lecture 7. Concurrent Statements & Sequential Statements (Process)

CS311 Lecture: Sequential Circuits

Sequential Logic: Clocks, Registers, etc.

SystemVerilog Is Getting Even Better!

Introduction to CMOS VLSI Design (E158) Lecture 8: Clocking of VLSI Systems

Set-Reset (SR) Latch

Lecture 10 Sequential Circuit Design Zhuo Feng. Z. Feng MTU EE4800 CMOS Digital IC Design & Analysis 2010

INTRODUCTION TO DIGITAL SYSTEMS. IMPLEMENTATION: MODULES (ICs) AND NETWORKS IMPLEMENTATION OF ALGORITHMS IN HARDWARE

To design digital counter circuits using JK-Flip-Flop. To implement counter using 74LS193 IC.

WEEK 8.1 Registers and Counters. ECE124 Digital Circuits and Systems Page 1

Wiki Lab Book. This week is practice for wiki usage during the project.

Latches, the D Flip-Flop & Counter Design. ECE 152A Winter 2012

COMBINATIONAL and SEQUENTIAL LOGIC CIRCUITS Hardware implementation and software design

Lecture-3 MEMORY: Development of Memory:

Traffic Light Controller. Digital Systems Design. Dr. Ted Shaneyfelt

if-then else : 2-1 mux mux: process (A, B, Select) begin if (select= 1 ) then Z <= A; else Z <= B; end if; end process;

Digital Logic Design. Basics Combinational Circuits Sequential Circuits. Pu-Jen Cheng

ETEC 2301 Programmable Logic Devices. Chapter 10 Counters. Shawnee State University Department of Industrial and Engineering Technologies

Using reverse circuit execution for efficient parallel simulation of logic circuits

Manchester Encoder-Decoder for Xilinx CPLDs

NTE2053 Integrated Circuit 8 Bit MPU Compatible A/D Converter

Chapter 2 Verilog HDL for Design and Test

DEPARTMENT OF INFORMATION TECHNLOGY

Topics. Flip-flop-based sequential machines. Signals in flip-flop system. Flip-flop rules. Latch-based machines. Two-sided latch constraint

Lecture 7: Clocking of VLSI Systems

L4: Sequential Building Blocks (Flip-flops, Latches and Registers)

Digital Controller for Pedestrian Crossing and Traffic Lights

Memory Elements. Combinational logic cannot remember

CSE140: Components and Design Techniques for Digital Systems

PROGETTO DI SISTEMI ELETTRONICI DIGITALI. Digital Systems Design. Digital Circuits Advanced Topics

CS101 Lecture 26: Low Level Programming. John Magee 30 July 2013 Some material copyright Jones and Bartlett. Overview/Questions

Lab #5: Design Example: Keypad Scanner and Encoder - Part 1 (120 pts)

Flip-Flops, Registers, Counters, and a Simple Processor

Counters and Decoders

EE 42/100 Lecture 24: Latches and Flip Flops. Rev B 4/21/2010 (2:04 PM) Prof. Ali M. Niknejad

Topics of Chapter 5 Sequential Machines. Memory elements. Memory element terminology. Clock terminology

CHAPTER 11: Flip Flops

Experiment # 9. Clock generator circuits & Counters. Eng. Waleed Y. Mousa

Sequential Logic Design Principles.Latches and Flip-Flops

Getting the Most Out of Synthesis

ASYNCHRONOUS COUNTERS

DIGITAL COUNTERS. Q B Q A = 00 initially. Q B Q A = 01 after the first clock pulse.

Verilog for Behavioral Modeling

Sequential Circuit Design

Digital Logic Design Sequential circuits

Flip-Flops and Sequential Circuit Design. ECE 152A Winter 2012

Flip-Flops and Sequential Circuit Design

Computer organization

Review: MIPS Addressing Modes/Instruction Formats

Chapter 8. Sequential Circuits for Registers and Counters

Life Cycle of a Memory Request. Ring Example: 2 requests for lock 17

8254 PROGRAMMABLE INTERVAL TIMER

VHDL Test Bench Tutorial

ECE410 Design Project Spring 2008 Design and Characterization of a CMOS 8-bit Microprocessor Data Path

9/14/ :38

Design and Verification of Nine port Network Router

Microprocessor & Assembly Language

Digital Circuit Design Using Xilinx ISE Tools

Lecture 11: Sequential Circuit Design

Synthesizable Finite State Machine Design Techniques Using the New SystemVerilog 3.0 Enhancements

Lecture 10: Sequential Circuits

Chapter 5 :: Memory and Logic Arrays

Digital Design Verification

Designing Digital Circuits a modern approach. Jonathan Turner

Sequential Circuits. Combinational Circuits Outputs depend on the current inputs

Asynchronous IC Interconnect Network Design and Implementation Using a Standard ASIC Flow

CHAPTER 3 Boolean Algebra and Digital Logic

Two-Phase Clocking Scheme for Low-Power and High- Speed VLSI

Digital Systems Based on Principles and Applications of Electrical Engineering/Rizzoni (McGraw Hill

Verilog: Blocks

7. Latches and Flip-Flops

Asynchronous counters, except for the first block, work independently from a system clock.

Addressing The problem. When & Where do we encounter Data? The concept of addressing data' in computations. The implications for our machine design(s)

Transcription:

Understanding Verilog Blocking and Non-blocking Assignments International Cadence User Group Conference September 11, 1996 presented by Stuart HDL Consulting

About the Presenter Stuart has over 8 years of experience using Verilog with w a variety of software tools. He holds a BS degree in Computer Science, with an emphasis on Electronic Engineering, and has worked as a design engineer in the defense industry, and as an Applications A Engineer for Gateway Design Automation (the originator of Verilog) and Cadence Design Systems. Mr. has been providing Verilog HDL consulting services since 1991. As a consultant, he has been actively involved in using the Verilog langiage with a many different of software tools for the design of ASICs and systems. He is a member of the IEEE 1364 standards committee and has been involved in the specification and testing of Verilog simulation products from several EDA vendors, including the Intergraph-VeriBest VeriBest simulator, the Mentor QuickHDL simulator, and the Frontline CycleDrive cycle based simulator. In addition to Verilog design consutlting,, Mr. provides expert on-site Verilog training on the Verilog HDL language and Programing Language Interface. Mr. is the author and publisher of the popular pular Verilog IEEE 1364 Quick Reference Guide and the Verilog IEEE 1364 PLI Quick Reference Guide. Please conact Mr. with any questions about this material! HDL Consulting Verilog Consulting and Training Services 22805 SW 92 nd Place Tualatin, OR 97062 USA phone: (503) 692-0898 fax: (503) 692-1512 e-mail: stuart@sutherland sutherland.com

copyright notice 1996 The material in this presentation is copyrighted by HDL H Consulting, Tualatin, Oregon. The presentation is printed with permission as part of the proceedings of the 1996 International Cadence User Group Conference. nce. All rights are reserved. No material from this presentation may be duplicated or transmitted by any means or in any form without the express written permission of HDL Consulting. HDL Consulting 22805 SW 92 nd Place Tualatin, OR 97062 USA phone: (503) 692-0898 fax: (503) 692-1512 e-mail: info@sutherland sutherland.com

Objectives 4 The primary objective is to understand: What type of hardware is represented by blocking and non-blocking assignments? The material presented is a subset of an advanced Verilog HDL training course

5 Procedural assignment evaluation can be modeled as: Blocking Non-blocking Procedural assignment execution can be modeled as: Sequential Concurrent Procedural assignment timing controls can be modeled as: Delayed evaluations Delayed assignments

Blocking 6 The = token represents a blocking procedural assignment Evaluated and assigned in a single step Execution flow within the procedure is blocked until the assignment is completed Evaluations of concurrent statements in the same time step are blocked until the assignment is completed These examples will not work Why not? //swap //swap bytes bytes in in word word always clk) begin begin word[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 word always clk) fork fork word[15:8] = word[ word[ 7:0]; 7:0]; word[ word[ 7:0] 7:0] = word[15:8]; join join

Non-Blocking 7 The <= token represents a non-blocking assignment Evaluated and assigned in two steps: 1 The right-hand hand side is evaluated immediately 2 The assignment to the left-hand side is postponed until other evaluations in the current time step are completed Execution flow within the procedure continues until a timing control is encountered (flow is not blocked) These examples will work Why? //swap //swap bytes bytes in in word word always clk) begin begin word[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 word always clk) fork fork word[15:8] <= <= word[ word[ 7:0]; 7:0]; word[ word[ 7:0] 7:0] <= <= word[15:8]; join join

Representing Simulation Time as Queues 8 Each Verilog simulation time step is divided into 4 queues Time Time 0: 0: Q1 Q1 (in (in any any order) order) :: Evaluate RHS RHS of of all all non-blocking assignments Evaluate RHS RHS and and change change LHS LHS of of all all blocking assignments Evaluate RHS RHS and and change change LHS LHS of of all all continuous assignments Evaluate inputs inputs and and change change outputs outputs of of all all primitives Evaluate and and print print output output from from $display and and $write $write Q2 Q2 (in (in any any order) order) :: Change LHS LHS of of all all non-blocking assignments Q3 Q3 (in (in any any order) order) :: Evaluate and and print print output output from from $monitor and and $strobe $strobe Call Call PLI PLI with with reason_synchronize Q4 Q4 :: Call Call PLI PLI with with reason_rosynchronize Time Time 1: 1:...... Note: this is an abstract view, not how simulation algorithms are e implemented

Sequential 9 The order of evaluation is determinate A sequential blocking assignment evaluates and assigns before continuing on in the procedure begin A = 1; evaluate and assign A immediately #5 B = A + 1; delay 5 time units, then evaluate and assign end A sequential non-blocking assignment evaluates, then continues on to the next timing control before assigning begin A <= 1; evaluate A immediately; assign at end of time step #5 B <= A + 1; delay 5 time units, then evaluate; then assign at end end of time step (clock + 5)

Concurrent 10 The order of concurrent evaluation is indeterminate Concurrent blocking assignments have unpredictable results #5 A = A + 1; #5 B = A + 1; Unpredictable Result: (new value of B could be evaluated before or after A changes) Concurrent non-blocking assignments have predictable results #5 A <= A + 1; #5 B <= A + 1; Predictable Result: (new value of B will always be evaluated before A changes)

Delayed Evaluation 11 A timing control before an assignment statement will postpone when the next assignment is evaluated Evaluation is delayed for the amount of time specified begin #5 A = 1; #5 A = A + 1; B = A + 1; end delay for 5, then evaluate and assign delay 5 more, then evaluate and assign no delay; evaluate and assign What values do A and B contain after 10 time units?

Delayed Assignment 12 An intra-assignment assignment delay places the timing control after the assignment token The right-hand hand side is evaluated before the delay The left-hand side is assigned after the delay always @(A) A is evaluated at the time it changes, but B = #5 A; is not assigned to B until after 5 time units always @(negedge clk) Q <= @(posedge clk) D; D is evaluated at the negative edge of CLK, Q is changed on the positive edge of CLK always always @(instructor_input) if if (morning) understand = instructor_input; else else if if (afternoon) understand = #5 #5 instructor_input; else else if if (lunch_time) understand = wait wait (!lunch_time) instructor_input;

Intra-Assignment Delays With Repeat Loops 13 An edge-sensitive intra-assignment assignment timing control permits a special use of the repeat loop The edge sensitive time control may be repeated several times before the delay is completed Either the blocking or the non-blocking assignment may be used always @(IN) OUT OUT <= <= repeat (8) (8)@(posedge clk) clk) IN; IN; The value of IN is evaluated when it changes, but is not assigned to OUT until after 8 clock cycles

Choosing the Correct Procedural Assignment 14 Which procedural assignment should be used to model a combinatorial logic buffer? always @(in) #5 out = in; always @(in) #5 out <= in; Which procedural assignment should be used to model a sequential logic flip-flop? flop? #5 q = d; #5 q <= d; always @(in) out = #5 in; always @(in) out <= #5 in; q = #5 d; q <= #5 d; The following pages will answer these questions

Transition Propagation Methods 15 Hardware has two primary propagation delay methods: Inertial delay models devices with finite switching speeds; input glitches do not propagate to the output 10 20 30 40 50 60 10 20 30 40 50 60 Buffer with a 10 nanosecond propagation delay Transport delay models devices with near infinite switching speeds; input glitches propagate to the output 10 20 30 40 50 60 10 20 30 40 50 60 Buffer with a 10 nanosecond propagation delay

Combinational Logic 16 How will these procedural assignments behave? in 10 20 30 40 50 60 33 36 45 Blocking, No delay always @(in) o1 = in; o1 zero delay Non-blocking, No delay always @(in) o2 <= in; o2 Blocking, Delayed evaluation always @(in) #5 o3 = in; o3 inertial Non-blocking, Delayed evaluation always @(in) #5 o4 <= in; o4 Blocking, Delayed assignment always @(in) o5 = #5 in; o5 Non-blocking, Delayed assignment always @(in) o6 <= #5 in; o6 transport

Sequential Logic 17 How will these procedural assignments behave? Sequential assignments No delays clk in 10 20 30 40 50 60 35 53 begin = in; = ; end begin <= in; <= ; end parallel flip-flops flops shift-register with zero delays

Sequential Logic 18 How will these procedural assignments behave? Sequential assignments Delayed evaluation clk in 10 20 30 40 50 60 35 53 begin #5 = in; #5 = ; end begin #5 <= in; #5 <= ; end #5 #5 #5 #5 shift register with delayed clocks shift register with delayed clocks????????????

Sequential Logic 19 How will these procedural assignments behave? Sequential assignments Delayed assignment clk in 10 20 30 40 50 60 35 53 begin = #5 in; = #5 ; end begin <= #5 in; <= #5 ; end #5 #5 #5 #5 #5 shift register delayed clock on second stage shift register with delays

Sequential Logic 20 How will these procedural assignments behave? Concurrent assignments No delays clk in 10 20 30 40 50 60 35 53 = in; = ;????????? shift register with race condition <= in; <= ; shift-register with zero delays

Sequential Logic 21 How will these procedural assignments behave? Concurrent assignments Delayed evaluation clk in 10 20 30 40 50 60 35 53 #5 = in; #5 = ; #5 #5???? shift register with race condition??????? #5 <= in;??? #5 <= ; #5 shift register with race condition?

Sequential Logic 22 How will these procedural assignments behave? Concurrent assignments Delayed assignment clk in 10 20 30 40 50 60 35 53 = #5 in; = #5 ; <= #5 in; <= #5 ; #5 #5 #5 #5 shift register, delay must be < clock period shift register with delays

Rules of Thumb for 23 Combinational Logic: No delays: Use blocking assignments ( a = b; ) Inertial delays: Use delayed evaluation blocking assignments ( #5 a = b; ) Transport delays: Use delayed assignment non-blocking assignments ( a <= #5 b; ) Sequential Logic: No delays: Use non-blocking assignments ( q <= d; ) With delays: Use delayed assignment non-blocking assignments ( q <= #5 d; )

An Exception to Non-blocking Assignments in Sequential Logic 24 Do not use a non-blocking assignment if another statement in the procedure requires the new value in the same time step begin #5 A <= 1; #5 A <= A + 1; B <= A + 1; end What values do do A and B contain after 10 10 time units? A is 2 A is 2 B is 2 begin case (state) `STOP: next_state <= `GO; `GO: next_state <= `STOP; endcase state <= next_state; end Assume state and next_state are are `STOP at at the the first clock, what is is state: --At At the the 2nd clock? `STOP --At At the the 3rd 3rd clock? `GO --At At the the 4th 4th clock? `GO --At At the the 5th 5th clock? `STOP

Exercise 3: 25 Write a procedure for an adder (combinational logic) that assigns 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 4 wide shift register (positive edge triggered) of clock and has a 4ns propagation delay. clk) clk) begin <= <= #4 #4 in; in; <= <= #4 #4 in; in; clk) <= <= #4 #4 ; ; <= <= #4 #4 ; ; y3 y3 <= <= #4 #4 ; ; clk) out out <= <= #4 #4 y3; y3; y3 y3 <= <= #4 #4 ; ; end end clk) out out <= <= #4 #4 y3; y3;

Exercise 3 (continued): 26 Write a Verilog procedure for a black box ALU pipeline that takes 8 clock cycles to execute an instruction. The pipeline triggers on the positive edge of clock. The black box is represented as call to a function named ALU with inputs A, B and OPCODE. How many Verilog statements does it take to model an eight stage pipeline? clk) alu_out <= <= repeat(7) @(posedge clk) clk) ALU(A,B,OPCODE);