EECS150 - Digital Design Lecture 5 - Verilog Logic Synthesis

Similar documents
Logic Synthesis. EECS150 - Digital Design Lecture 6 - Synthesis

EECS150 - Digital Design Lecture 4 - Verilog Introduction. Outline

EECS150 - Digital Design Lecture 10 Logic Synthesis

Synthesis vs. Compilation Descriptions mapped to hardware Verilog design patterns for best synthesis. Spring 2007 Lec #8 -- HW Synthesis 1

CSE140L: Components and Design Techniques for Digital Systems Lab

CSE140L: Components and Design

EECS150 - Digital Design Lecture 10 Logic Synthesis

EECS150 - Digital Design Lecture 7 - Computer Aided Design (CAD) - Part II (Logic Simulation) Finite State Machine Review

EEL 4783: HDL in Digital System Design

EECS150 - Digital Design Lecture 6 - Logic Simulation

Outline. EECS150 - Digital Design Lecture 5 - Verilog 2. Structural Model: 2-to1 mux. Structural Model - XOR. Verilog Basics Lots of Examples

EECS150 - Digital Design Lecture 20 - Finite State Machines Revisited

ECE 4514 Digital Design II. Spring Lecture 15: FSM-based Control

Verilog for Synthesis Ing. Pullini Antonio

EECS150 - Digital Design Lecture 8 - Hardware Description Languages

ECE 2300 Digital Logic & Computer Organization. More Sequential Logic Verilog

Synthesizable Verilog

Verilog for High Performance

Topics. Midterm Finish Chapter 7

EECS150 - Digital Design Lecture 6 - Logic Simulation. Encoder Example

VHDL for Synthesis. Course Description. Course Duration. Goals

Hardware Description Languages: Verilog. Quick History of HDLs. Verilog/VHDL. Design Methodology. Verilog Introduction. Verilog.

Hardware Description Languages: Verilog

FPGA Design Challenge :Techkriti 14 Digital Design using Verilog Part 1

Lecture 12 VHDL Synthesis

VHDL: RTL Synthesis Basics. 1 of 59

! ISP (circa 1977) - research project at CMU " Simulation, but no synthesis

The Verilog Language COMS W Prof. Stephen A. Edwards Fall 2002 Columbia University Department of Computer Science

Outline. EECS Components and Design Techniques for Digital Systems. Lec 11 Putting it all together Where are we now?

Speaker: Kayting Adviser: Prof. An-Yeu Wu Date: 2009/11/23

Verilog. What is Verilog? VHDL vs. Verilog. Hardware description language: Two major languages. Many EDA tools support HDL-based design

Two HDLs used today VHDL. Why VHDL? Introduction to Structured VLSI Design

problem maximum score 1 10pts 2 8pts 3 10pts 4 12pts 5 7pts 6 7pts 7 7pts 8 17pts 9 22pts total 100pts

Advanced Synthesis Techniques

VHDL. VHDL History. Why VHDL? Introduction to Structured VLSI Design. Very High Speed Integrated Circuit (VHSIC) Hardware Description Language

Digital Integrated Circuits

EECS150 - Digital Design Lecture 23 - High-Level Design (Part 1)

CAD for VLSI Design - I. Lecture 21 V. Kamakoti and Shankar Balachandran

A Brief Introduction to Verilog Hardware Definition Language (HDL)

Course Topics - Outline

ECE 4514 Digital Design II. Spring Lecture 13: Logic Synthesis

Writing Circuit Descriptions 8

Digital Design with SystemVerilog

Digital Design with FPGAs. By Neeraj Kulkarni

Lecture #2: Verilog HDL

VHDL simulation and synthesis

Verilog Sequential Logic. Verilog for Synthesis Rev C (module 3 and 4)

Simple Behavioral Model: the always block

Synthesis of Language Constructs. 5/10/04 & 5/13/04 Hardware Description Languages and Synthesis

Hardware Design Environments. Dr. Mahdi Abbasi Computer Engineering Department Bu-Ali Sina University

MASSACHUSETTS INSTITUTE OF TECHNOLOGY Department of Electrical Engineering and Computer Sciences

Don t expect to be able to write and debug your code during the lab session.

Lecture 3. Behavioral Modeling Sequential Circuits. Registers Counters Finite State Machines

Verilog Fundamentals. Shubham Singh. Junior Undergrad. Electrical Engineering

What is Verilog HDL? Lecture 1: Verilog HDL Introduction. Basic Design Methodology. What is VHDL? Requirements

Control in Digital Systems

Homework deadline extended to next friday

Verilog introduction. Embedded and Ambient Systems Lab

Blocking(=) vs Nonblocking (<=) Assignment. Lecture 3: Modeling Sequential Logic in Verilog HDL. Procedural assignments

Topics. Midterm Finish Chapter 7

Synthesis of Combinational and Sequential Circuits with Verilog

Digital Design (VIMIAA01) Introduction to the Verilog HDL

MCMASTER UNIVERSITY EMBEDDED SYSTEMS

FSM Components. FSM Description. HDL Coding Methods. Chapter 7: HDL Coding Techniques

Why Should I Learn This Language? VLSI HDL. Verilog-2

Chap 6 Introduction to HDL (d)

problem maximum score 1 8pts 2 6pts 3 10pts 4 15pts 5 12pts 6 10pts 7 24pts 8 16pts 9 19pts Total 120pts

EECS 270 Verilog Reference: Sequential Logic

Programming with HDLs

PINE TRAINING ACADEMY

Register Transfer Level in Verilog: Part I

Combinational Logic II

EPC6055 Digital Integrated Circuits EXAM 1 Fall Semester 2013

Quick Introduction to SystemVerilog: Sequental Logic

Verilog Tutorial. Verilog Fundamentals. Originally designers used manual translation + bread boards for verification

Verilog Tutorial 9/28/2015. Verilog Fundamentals. Originally designers used manual translation + bread boards for verification

Last Lecture. Talked about combinational logic always statements. e.g., module ex2(input logic a, b, c, output logic f); logic t; // internal signal

University of California at Berkeley College of Engineering Department of Electrical Engineering and Computer Sciences. Spring 2010 May 10, 2010

Lecture 15: System Modeling and Verilog

ECE 2300 Digital Logic & Computer Organization. More Verilog Finite State Machines

N-input EX-NOR gate. N-output inverter. N-input NOR gate

CS6710 Tool Suite. Verilog is the Key Tool

EECS Components and Design Techniques for Digital Systems. Lec 20 RTL Design Optimization 11/6/2007

Lecture 3: Modeling in VHDL. EE 3610 Digital Systems

HDLs and SystemVerilog. Digital Computer Design

Recommended Design Techniques for ECE241 Project Franjo Plavec Department of Electrical and Computer Engineering University of Toronto

ECE 551: Digital System *

structure syntax different levels of abstraction

Here is a list of lecture objectives. They are provided for you to reflect on what you are supposed to learn, rather than an introduction to this

Lecture 7. Standard ICs FPGA (Field Programmable Gate Array) VHDL (Very-high-speed integrated circuits. Hardware Description Language)

ECE 353 Lab 4. Verilog Review. Professor Daniel Holcomb With material by Professor Moritz and Kundu UMass Amherst Fall 2016

Hardware Description Language (HDL)

CSCB58 - Lab 3. Prelab /3 Part I (in-lab) /2 Part II (in-lab) /2 TOTAL /8

Image Courtesy CS250 Section 2. Yunsup Lee 9/4/09

ECEN 449 Microprocessor System Design. Verilog. Texas A&M University

ECE 353 Lab 4. Verilog Review. Professor Daniel Holcomb UMass Amherst Fall 2017

Lecture #1: Introduction

TOPIC : Verilog Synthesis examples. Module 4.3 : Verilog synthesis

University of Toronto Faculty of Applied Science and Engineering Edward S. Rogers Sr. Department of Electrical and Computer Engineering

Mealy and Moore examples

Transcription:

EECS150 - Digital Design Lecture 5 - Verilog Logic Synthesis Jan 31, 2012 John Wawrzynek Spring 2012 EECS150 - Lec05-verilog_synth Page 1 Outline Quick review of essentials of state elements Finite State Machines in Verilog More on Verilog Logic Synthesis Spring 2012 EECS150 - Lec05-verilog_synth Page 2

Flip-Flop Timing Details d clk FF q Three important times associated with flip-flops: setup time hold time clock-to-q delay. Spring 2012 EECS150 lec04-seq_logic Page 3 State Elements Always blocks are the only way to specify the behavior of state elements. Synthesis tools will turn state element behaviors into state element instances. D-flip-flop with synchronous set and reset example: module dff(q, d, clk, set, rst); input d, clk, set, rst; output q; reg q; keyword always @(posedge clk) if (rst) q <= 1 b0; else if (set) q <= 1 b1; else q <= d; module always @ (posedge clk) is key to flip-flop generation. This gives priority to reset over set and set over d. clk On FPGAs, maps to native flip-flop. d set s q rst r How would you add an CE (clock enable) input? Spring 2012 EECS150 - Lec05-verilog_synth Page 4

State Transition Diagram Finite State Machines What does this one do? Holds a symbol to keep track of which bubble the FSM is in. Did you know that every SDS is a FSM? Implementation Circuit Diagram Spring 2012 EECS150 - Lec05-verilog_synth Page 5 CL functions to determine output value and next state based on input and current state. out = f(in, current state) next state = f(in, current state) Finite State Machines module FSM1(clk, rst, in, out); input clk, rst; input in; Must use reset to force output out; to initial state. reset not always shown in STD // Defined state encoding: parameter IDLE = 2'b00; parameter S0 = 2'b01; Constants local to this module. parameter S1 = 2'b10; reg out; out not a register, but assigned in always block reg [1:0] state, next_state; THE register to hold the state of the FSM. // always block for state register always @(posedge clk) if (rst) state <= IDLE; else state <= next_state; Combinational logic signals for transition. A separate always block should be used for combination logic part of FSM. Next state and output generation. (Always blocks in a design work in parallel.) Spring 2012 EECS150 - Lec05-verilog_synth Page 6

FSMs (cont.) // always block for combinational logic portion always @(state or in) case (state) // For each state def output and next IDLE : begin out = 1 b0; if (in == 1 b1) next_state = S0; else next_state = IDLE; S0 S1 : begin out = 1 b0; if (in == 1 b1) next_state = S1; else next_state = IDLE; : begin out = 1 b1; if (in == 1 b1) next_state = S1; else next_state = IDLE; default: begin next_state = IDLE; out = 1 b0; case module Each state becomes a case clause. For each state define: Output value(s) State transition Spring 2012 EECS150 - Lec05-verilog_synth Page 7 Use default to cover unassigned state. Usually unconditionally transition to reset state. Example - Parallel to Serial Converter ld out out Specifies the muxing with rotation forces Q register (flip-flops) to be rewritten every cycle connect output module ParToSer(ld, X, out, clk); input [3:0] X; input ld, clk; output out; reg [3:0] Q; wire [3:0] NS; assign NS = (ld)? X : {Q[0], Q[3:1]}; always @ (posedge clk) Q <= NS; assign out = Q[0]; module 8 Spring 2012 EECS150 - Lec05-verilog_synth Page

Parameterized Version Parameters give us a way to generalize our designs. A module becomes a generator for different variations. Enables design/module reuse. Can simplify testing. parameter N = 4; Declare a parameter with default value. Note: this is not a port. Acts like a synthesistime constant. ParToSer #(.N(8)) ps8 (... ); module ParToSer(ld, X, out, CLK); input [3:0] [N-1:0] X; X; input ld, clk; output out; Replace all occurrences reg out; of 3 with N-1. reg [3:0] [N-1:0] Q; Q; wire [3:0] [N-1:0] NS; NS; assign NS = (ld)? X : {Q[0], Q[3:1]}; Q[N-1:1]}; ParToSer #(.N(64)) ps64 (... ); Overwrite parameter N at instantiation. always @ (posedge clk) Q <= NS; assign out = Q[0]; module Spring 2012 EECS150 - Lec05-verilog_synth Page 9 EECS150 Design Methodology Hierarchically define structure and/or behavior of circuit. HDL Specification Simulation Functional verification. Synthesis Maps specification to resources of implementation platform (FPGA for us). Note: This in not the entire story. Other tools are often used analyze HDL specifications and synthesis results. More on this later. Spring 2012 EECS150 - Lec05-verilog_synth Page 10

Logic Synthesis Verilog and VHDL started out as simulation languages, but quickly people wrote programs to automatically convert Verilog code into low-level circuit descriptions (netlists). Synthesis converts Verilog (or other HDL) descriptions to implementation technology specific primitives: For FPGAs: LUTs, flip-flops, and RAM blocks For ASICs: standard cell gate and flip-flop libraries, and memory blocks. Spring 2012 EECS150 - Lec05-verilog_synth Page 11 Why Logic Synthesis? 1. Automatically manages many details of the design process: Fewer bugs Improved productivity 2. Abstracts the design data (HDL description) from any particular implementation technology. Designs can be re-synthesized targeting different chip technologies. Ex: first implement in FPGA then later in ASIC. 3. In some cases, leads to a more optimal design than could be achieved by manual means (ex: logic optimization) Why Not Logic Synthesis? 1. May lead to non-optimal designs in some cases. Spring 2012 EECS150 - Lec05-verilog_synth Page 12

foo.v Parsing and Syntax Check Main Logic Synthesis Steps Load in HDL file, run macro preprocessor for `define, `include, etc.. Design Elaboration Inference and Library Substitution Logic Expansion Logic Optimization Partition, Place & Route Compute parameter expressions, process generates, create instances, connect ports. Recognize and insert special blocks (memory, flip-flops, arithmetic structures,...) Expand combinational logic to primitive Boolean representation. Apply Boolean algebra and heuristics to simplify and optimize under constraints. CL to LUTs, map memory and state elements to chip, assign physical locations, route connections. Spring 2012 EECS150 - Lec05-verilog_synth Page 13 foo.ncd Operators and Synthesis Logical operators map into primitive logic gates Arithmetic operators map into adders, subtractors, Unsigned 2s complement Model carry: target is one-bit wider that source Watch out for *, %, and / Relational operators generate comparators Shifts by constant amount are just wire connections No logic involved Variable shift amounts a whole different story --- shifter Conditional expression generates logic or MUX Y = ~X << 2 Spring 2012 EECS150 - Lec05-verilog_synth Page 14 X[3] X[2] X[1] X[0] Y[5] Y[4] Y[3] Y[2] Y[1] Y[0]

Simple Example module foo (A, B, s0, s1, F); input [3:0] A; input [3:0] B; input s0,s1; output [3:0] F; reg F; always @ (*) if (!s0 && s1 s0) F=A; else F=B; module A B F Should expand if-else into 4-bit wide multiplexor and optimize the control logic and ultimately to a single LUT on an FPGA: Spring 2012 EECS150 - Lec05-verilog_synth Page 15 More about Always blocks Spring 2012 EECS150 - Lec05-verilog_synth Page 16

Combinational logic always blocks Make sure all signals assigned in a combinational always block are explicitly assigned values every time that the always block executes. Otherwise latches will be generated to hold the last value for the signals not assigned values. Sel case value 2 d2 omitted. Out is not updated when select line has 2 d2. Latch is added by tool to hold the last value of out under this condition. Similar problem with if-else statements. module mux4to1 (out, a, b, c, d, sel); output out; input a, b, c, d; input [1:0] sel; reg out; always @(sel or a or b or c or d) begin case (sel) 2'd0: out = a; 2'd1: out = b; 2'd3: out = d; case module Spring 2012 EECS150 - Lec05-verilog_synth Page 17 Combinational logic always blocks To avoid synthesizing a latch in this case, add the missing select line: 2'd2: out = c; Or, in general, use the default case: default: out = foo; If you don t care about the assignment in a case (for instance you know that it will never come up) then you can assign the value x to the variable. Example: default: out = 1 bx; The x is treated as a don t care for synthesis and will simplify the logic. Be careful when assigning x (don t care). If this case were to come up, then the synthesized circuit and simulation may differ. Spring 2012 EECS150 - Lec05-verilog_synth Page 18

Incomplete Triggers Leaving out an input trigger usually results in latch generation for the missing trigger. module and_gate (out, in1, in2); input in1, in2; output out; reg out; in2 not in always sensitivity list. always @(in1) begin out = in1 & in2; module A latched version of in2 is synthesized and used as input to the and-gate, so that the and-gate output is not always sensitive to in2. Easy way to avoid incomplete triggers for combinational logic is with: always @* Spring 2012 EECS150 - Lec05-verilog_synth Page 19 Procedural Assignments Verilog has two types of assignments within always blocks: Blocking procedural assignment = In simulation the RHS is executed and the assignment is completed before the next statement is executed. Example: Assume A holds the value 1 A=2; B=A; A is left with 2, B with 2. Non-blocking procedural assignment <= In simulation the RHS is executed and all assignment take place at the same time ( of the current time step - not clock cycle). Example: Assume A holds the value 1 A<=2; B<=A; A is left with 2, B with 1. In synthesis the difference shows up primarily when inferring state elements: always @ (posedge clk) begin always @ (posedge clk) begin a = in; b = a; a <= in; b<= a; b stores in b stores the old a Spring 2012 EECS150 - Lec05-verilog_synth Page 20

Procedural Assignments The sequential semantics of the blocking assignment allows variables to be multiply assigned within a single always block. Unexpected behavior can result from mixing these assignments in a single block. Standard rules: i. Use blocking assignments to model combinational logic within an always block ( = ). ii. Use non-blocking assignments to implement sequential logic ( <= ). iii. Do not mix blocking and non-blocking assignments in the same always block. iv. Do not make assignments to the same variable from more than one always block. Spring 2012 EECS150 - Lec05-verilog_synth Page 21 FSM CL block rewritten always @(state or in) case (state) IDLE : begin out = 1 b0; if (in == 1 b1) next_state = S0; always @* else next_state * for sensitivity = IDLE; list begin next_state S0 : begin = IDLE; Normal values: used out = 1 b0; out = 1 b0; unless specified below. case (state) if (in == 1 b1) next_state = S1; IDLE : else if (in next_state == 1 b1) = next_state IDLE; = S0; S0 : if (in == 1 b1) next_state = S1; Within case only need to S1 S1 : begin specify exceptions to the out out = = 1 b1; 1 b1; normal values. if if (in (in == == 1 b1) 1 b1) next_state next_state = = S1; S1; else next_state = IDLE; default: ; case default: begin Note: The use of blocking assignments allow signal module next_state values = IDLE; to be rewritten, simplifying the specification. out = 1 b0; case module Spring 2012 EECS150 - Lec05-verilog_synth Page 22

Encoder Example Nested IF-ELSE might lead to priority logic Example: 4-to-2 encoder always @(x) begin : encode if (x == 4'b0001) y = 2'b00; else if (x == 4'b0010) y = 2'b01; else if (x == 4'b0100) y = 2'b10; else if (x == 4'b1000) y = 2'b11; else y = 2'bxx; This style of cascaded logic may adversely affect the performance of the circuit. Spring 2012 EECS150 - Lec05-verilog_synth Page 23 Encoder Example (cont.) To avoid priority logic use the case construct: always @(x) begin : encode case (x) 4 b0001: y = 2'b00; 4 b0010: y = 2'b01; 4'b0100: y = 2'b10; 4'b1000: y = 2'b11; default: y = 2'bxx; case All cases are matched in parallel. Spring 2012 EECS150 - Lec05-verilog_synth Page 24

Encoder Example (cont.) This circuit would be simplified during synthesis to take advantage of constant values as follows and other Boolean equalities: A similar simplification would be applied to the if-else version also. Spring 2012 EECS150 - Lec05-verilog_synth Page 25 Verilog in EECS150 We use behavior modeling along with instantiation to 1) build hierarchy and, 2) map to FPGA resources not supported by synthesis. Primary Style Guidelines: Favor continuous assign and avoid always blocks unless: no other alternative: ex: state elements, case they help clarity of code & possibly circuit efficiency : ex: case vs, large nested if else Use named ports. Separate CL logic specification from state elements. Follow our rules for procedural assignments. Verilog is a big language. This is only an introduction. Our text book is a good source. Read and use chapter 4. Be careful of what you read on the web. Many bad examples out there. We will be introducing more useful constructs throughout the semester. Stay tuned! Spring 2012 EECS150 - Lec05-verilog_synth Page 26

Final thoughts on Verilog Examples Verilog may look like C, but it describes hardware! (Except in simulation test-benches - which actually behave like programs.) Multiple physical elements with parallel activities and temporal relationships. A large part of digital design is knowing how to write Verilog that gets you the desired circuit. First understand the circuit you want then figure out how to code it in Verilog. If you do one of these activities without the other, you will struggle. These two activities will merge at some point for you. Be suspicious of the synthesis tools! Check the output of the tools to make sure you get what you want. Spring 2012 EECS150 - Lec05-verilog_synth Page 27