Logic Synthesis. EECS150 - Digital Design Lecture 6 - Synthesis

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

EEL 4783: HDL in Digital System Design

EECS150 - Digital Design Lecture 10 Logic Synthesis

EECS150 - Digital Design Lecture 10 Logic Synthesis

CSE140L: Components and Design

CSE140L: Components and Design Techniques for Digital Systems Lab

EECS150 - Digital Design Lecture 5 - Verilog Logic Synthesis

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

EECS150 - Digital Design Lecture 4 - Verilog Introduction. Outline

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

ECEN 468 Advanced Logic Design

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

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

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

Hardware Description Languages: Verilog

EECS 427 Lecture 14: Verilog HDL Reading: Many handouts/references. EECS 427 W07 Lecture 14 1

Verilog for Synthesis Ing. Pullini Antonio

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

Online Verilog Resources

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

Topics. Midterm Finish Chapter 7

EECS150 - Digital Design Lecture 6 - Logic Simulation

Verilog for High Performance

Verilog Design Principles

Synthesizable Verilog

Verilog Behavioral Modeling

Course Topics - Outline

EECS /20/07 EECS

Simple Behavioral Model: the always block

EECS150 - Digital Design Lecture 20 - Finite State Machines Revisited

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

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

Programmable Logic Devices Verilog VII CMPE 415

Verilog HDL. A Guide to Digital Design and Synthesis. Samir Palnitkar. SunSoft Press A Prentice Hall Title

Lecture 12 VHDL Synthesis

Computer Aided Design Basic Syntax Gate Level Modeling Behavioral Modeling. Verilog

CS6710 Tool Suite. Verilog is the Key Tool

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

VHDL for Synthesis. Course Description. Course Duration. Goals

A Brief Introduction to Verilog Hardware Definition Language (HDL)

Chap 6 Introduction to HDL (d)

Chapter 2 Using Hardware Description Language Verilog. Overview

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

VHDL: RTL Synthesis Basics. 1 of 59

Introduction to Digital Design with Verilog HDL

Contents. Appendix D Verilog Summary Page 1 of 16

Topics. Midterm Finish Chapter 7

Combinational Circuit Design

CS6710 Tool Suite. Verilog is the Key Tool. Verilog as HDL (AHT) Verilog has a Split Personality. Quick Review. Synthesis

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

Graduate Institute of Electronics Engineering, NTU. Lecturer: Chihhao Chao Date:

RIZALAFANDE CHE ISMAIL TKT. 3, BLOK A, PPK MIKRO-e KOMPLEKS PENGAJIAN KUKUM. SYNTHESIS OF COMBINATIONAL LOGIC (Chapter 8)

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

Schematic design. Gate level design. 0 EDA (Electronic Design Assistance) 0 Classical design. 0 Computer based language

Writing Circuit Descriptions 8

FPGA: FIELD PROGRAMMABLE GATE ARRAY Verilog: a hardware description language. Reference: [1]

EN2911X: Reconfigurable Computing Topic 02: Hardware Definition Languages

Lecture 15: System Modeling and Verilog

Digital Design (VIMIAA01) Introduction to the Verilog HDL

Verilog Design Principles

Verilog Tutorial. Introduction. T. A.: Hsueh-Yi Lin. 2008/3/12 VLSI Digital Signal Processing 2

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

St.MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

Synthesis of Combinational and Sequential Circuits with Verilog

Veriolog Overview. CS/EE 3710 Fall 2010

HDL Compiler Directives 7

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

A Tutorial Introduction 1

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

Hardware Description Language (HDL)

Lecture #2: Verilog HDL

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

14:332:231 DIGITAL LOGIC DESIGN. Hardware Description Languages

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

EN164: Design of Computing Systems Lecture 06: Lab Foundations / Verilog 2

INSTITUTE OF AERONAUTICAL ENGINEERING Dundigal, Hyderabad ELECTRONICS AND COMMUNICATIONS ENGINEERING

MLR Institute of Technology

HDL Coding Style Xilinx, Inc. All Rights Reserved

Under-Graduate Project Logic Design with Behavioral Models

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

EECS150 - Digital Design Lecture 8 - Hardware Description Languages

Digital Design with SystemVerilog

VLSI Design 13. Introduction to Verilog

Verilog For Synthesis

CMPE 415 Full and Parallel Case

CSE241 VLSI Digital Circuits Winter Recitation 1: RTL Coding in Verilog

ECE 551: Digital System *

HDLs and SystemVerilog. Digital Computer Design

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

PINE TRAINING ACADEMY

Lecture 2: Data Types, Modeling Combinational Logic in Verilog HDL. Variables and Logic Value Set. Data Types. Why use an HDL?

Lab #1. Topics. 3. Introduction to Verilog 2/8/ Programmable logic. 2. Design Flow. 3. Verilog --- A Hardware Description Language

Introduction to Verilog HDL. Verilog 1

Table of Contents. Verilog. Verilog

Course Topics - Outline

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

Register Transfer Level in Verilog: Part I

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

The Verilog Hardware Description Language

Verilog 1 - Fundamentals

Transcription:

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). EECS150 - Digital Design Lecture 6 - Synthesis Verilog HDL Synthesis Tool circuit netlist February 3, 2005 John Wawrzynek 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 2005 EECS150 - Lec06-synthesis Page 1 Spring 2005 EECS150 - Lec06-synthesis Page 2 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. How does it work? A variety of general and ad-hoc (special case) methods: Instantiation: maintains a library of primitive modules (AND, OR, etc.) and user defined modules. macro expansion / substitution: a large set of language operators (+, -, Boolean operators, etc.) and constructs (if-else, case) expand into special circuits. Inference: special patterns are detected in the language description and treated specially (ex: inferring memory blocks from variable declaration and read/write statements, FSM detection and generation from always @ (posedge clk) blocks). Logic optimization: Boolean operations are grouped and optimized with logic minimization techniques. Structural reorganization: advanced techniques including sharing of operators, and retiming of circuits (moving FFs), and others? Spring 2005 EECS150 - Lec06-synthesis Page 3 Spring 2005 EECS150 - Lec06-synthesis Page 4 1

Operators Synthesis vs Compilation 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 2005 EECS150 - Lec06-synthesis Page 5 X[3] X[2] X[1] X[0] Y[5] Y[4] Y[3] Y[2] Y[1] Y[0] Levels of Representation High Level Language Program (e.g., C) Assembly Language Program (e.g.,mips) Machine Language Program (MIPS) Control Signal Specification Compiler Assembler Machine Interpretation 61C temp = v[k]; v[k] = v[k+1]; v[k+1] = temp; lw $to, 0($2) lw $t1, 4($2) sw$t1, 0($2) sw$t0, 4($2) 0000 1001 1100 0110 1010 1111 0101 1000 1010 1111 0101 1000 0000 1001 1100 0110 1100 0110 1010 1111 0101 1000 0000 1001 0101 1000 0000 1001 1100 0110 1010 1111 Compiler recognizes all possible constructs in a formally defined program language translates them to a machine language representation of execution process Synthesis Spring 2005 EECS150 - Lec06-synthesis Page 6 15 Recognizes a target depent subset of a hardware description language Maps to collection of concrete hardware resources Iterative tool in the design flow 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 @ (a or b or s0 or s1) if (!s0 && s1 s0) f=a; else f=b; Should expand if-else into 4-bit wide multiplexor and optimize the control logic: Module Template Synthesis tools expects to find modules in this format. module <top_module_name>(<port list>); /* Port declarations. followed by wire, reg, integer, task and function declarations */ /* Describe hardware with one or more continuous assignments, always blocks, module instantiations and gate instantiations */ // Continuous assignment wire <result_signal_name>; assign <result_signal_name> = <expression>; // always block always @(<event expression>) // Procedural assignments // if statements // case, casex, and casez statements // while, repeat and for loops // user task and user function calls // Module instantiation <module_name> <instance_name> (<port list>); // Instantiation of built-in gate primitive gate_type_keyword (<port list>); The order of these statements is irrelevant, all execute concurrently. The statements between the and in an always block execute sequentially from top to bottom. (However, beware of blocking versus non-blocking assignment) Statements within a fork-join statement in an always block execute concurrently. Spring 2005 EECS150 - Lec06-synthesis Page 7 Spring 2005 EECS150 - Lec06-synthesis Page 8 2

Procedural Assignments Verilog has two types of assignments within always blocks: Blocking procedural assignment = 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 <= The RHS is executed and assignment takes place at the 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. The notion of the current time step is tricky in synthesis, so to guarantee that your simulation matches the behavior of the synthesized circuit, follow these 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. Supported Verilog Constructs Net types: wire, tri, supply1, supply0; register types: reg, integer, time (64 bit reg); arrays of reg. Continuous assignments. Gate primitive and module instantiations. always blocks, user tasks, user functions. inputs, outputs, and inouts to a module. All operators (+, -, *, /, %, <, >, <=, >=, ==,!=, ===,!==, &&,,!, ~, &, ~&,, ~, ^~, ~^, ^, <<, >>,?:, { }, {{ }}) [Note: / and % are supported for compile-time constants and constant powers of 2.] Procedural statements: if-else-if, case, casex, casez, for, repeat, while, forever,,, fork, join. Procedural assignments: blocking assignments =, nonblocking assignments <= (Note: <= cannot be mixed with = for the same register). Compiler directives: `define, `ifdef, `else, `if, `include, `undef Miscellaneous: Integer ranges and parameter ranges. Local declarations to - block. Variable indexing of bit vectors on the left and right sides of assignments. iv. Do not make assignments to the same variable from more than one always Spring block. 2005 EECS150 - Lec06-synthesis Page 9 Spring 2005 EECS150 - Lec06-synthesis Page 10 Unsupported Language Constructs Generate error and halt synthesis Net types: trireg, wor, trior, wand, triand, tri0, tri1, and charge strength; register type: real. Built-in unidirectional and bidirectional switches, and pull-up, pull-down. Procedural statements: assign (different from the continuous assignment ), deassign, wait. Named events and event triggers. UDPs (user defined primitives) and specify blocks. force, release, and hierarchical net names (for simulation only). Simply ignored delay, delay control, and drive strength. scalared, vectored. initial block. Compiler directives (except for `define, `ifdef, `else, `if, `include, and `undef, which are supported). Calls to system tasks and system functions (they are only for simulation). Combinational Logic CL can be generated using: 1. primitive gate instantiation: AND, OR, etc. 2. continuous assignment (assign keyword), example: Module adder_8 (cout, sum, a, b, cin); output cout; output [7:0] sum; input cin; input [7:0] a, b; assign {cout, sum} = a + b + cin; 3. Always block: always @ (event_expression) // procedural assignment statements, if statements, // case statements, while, repeat, and for loops. // Task and function calls Spring 2005 EECS150 - Lec06-synthesis Page 11 Spring 2005 EECS150 - Lec06-synthesis Page 12 3

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. module mux4to1 (out, a, b, c, d, sel); output out; Example: 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. input a, b, c, d; input [1:0] sel; reg out; always @(sel or a or b or c or d) case (sel) 2'd0: out = a; 2'd1: out = b; 2'd3: out = d; case Spring 2005 EECS150 - Lec06-synthesis Page 13 Combinational logic always blocks (cont.) 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 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. (The synthesis directive full_case will accomplish the same, but can lead to differences between simulation and synthesis.) Spring 2005 EECS150 - Lec06-synthesis Page 14 Latch rule If a variable is not assigned in all possible executions of an always statement then a latch is inferred E.g., when not assigned in all branches of an if or case Even a variable declared locally within an always is inferred as a latch if incompletely assigned in a conditional statement Combinational Logic (cont.) Be careful with nested IF-ELSE. They can lead to priority logic Example: 4-to-2 encoder x[0] x[1] : encode 1 00 if (x[0] == 1'b1) y = 2'b00; x[2] 1 01 else if (x[1] == 1'b1) y = 2'b01; 0 x[3] 1 10 else if (x[2] == 1'b1) y = 2'b10; 0 y[1:0] else if (x[3] == 1'b1) y = 2'b11; 11 0 else y = 2'bxx; x[3:0] : encode 00 casex (x) // synthesis parallel-case 4 bxxx1: y = 2'b00; 4 bxx10: y = 2'b01; 4'bx100: y = 2'b10; 4'b1000: y = 2'b11; case 01 10 10 Double gates Incorrect Version - Ignore y[1:0] Spring 2005 EECS150 - Lec06-synthesis Page 15 Spring 2005 EECS150 - Lec06-synthesis Page 16 4

Encoder Example Nested IF-ELSE might lead to priority logic Example: 4-to-2 encoder : 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. To avoid priority logic use the case construct: : encode case (x) 4 b0001: y = 2'b00; 4 b0010: y = 2'b01; 4'b0100: y = 2'b10; 4'b1000: y = 2'b11; case All cases are matched in parallel. Note, you don t need the parallel case directive (except under special circumstances, described later.) Spring 2005 EECS150 - Lec06-synthesis Page 17 Spring 2005 EECS150 - Lec06-synthesis Page 18 This circuit would be simplified during synthesis to take advantage of constant values as follows and other Boolean equalities: If you can guarantee that only one 1 appears in the input, then simpler logic can be generated: : encode if (x[0]) y = 2'b00; else if (x[1]) y = 2'b01; else if (x[2]) y = 2'b10; else if (x[3]) y = 2'b11; else y = 2'bxx; A similar simplification would be applied to the if-else version also. If the input applied has more than one 1, then this version functions as a priority encoder. The least significant 1 gets priority (the more significant 1 s are ignored). Again the circuit will be simplified when possible. Spring 2005 EECS150 - Lec06-synthesis Page 19 Spring 2005 EECS150 - Lec06-synthesis Page 20 5

Parallel version, assuming we can guarantee only one 1 in the input: : encode casex (x) // synthesis parallel_case 4 bxxx1: y = 2'b00; 4 bxx1x: y = 2'b01; 4'bx1xx: y = 2'b10; 4'b1xxx: y = 2'b11; case Note now more than one case might match the input. Therefore we use parallel case directive. Without it synthesis adds appropriate matching logic to force priority. (The semantics of the case construct says that the cases are evaluated from top to bottom. This is only an issue for synthesis when more than one case could match the input.) Parallel version of priority encoder : : encode casex (x) 4 bxxx1: y = 2'b00; 4 bxx1x: y = 2'b01; 4'bx1xx: y = 2'b10; 4'b1xxx: y = 2'b11; case Note because parallel case directive is not used, synthesis adds appropriate matching logic to force priority. (Just what we want for a priority encoder.) Behavior matches that of the if-else version presented earlier. Spring 2005 EECS150 - Lec06-synthesis Page 21 Spring 2005 EECS150 - Lec06-synthesis Page 22 Sequential Logic Example: D flip-flop with synchronous set/reset: module dff(q, d, clk, set, rst); input d, clk, set, rst; @ (posedge clk) key to flip-flop output q; reg q; generation. always @(posedge clk) Note in this case, priority logic is if (reset) appropriate. q <= 0; else if (set) For Xilinx Virtex FPGAs, the tool q <= 1; infers a native flip-flop (no extra else logic is needed for the set/reset. q <= d; We prefer synchronous set/reset, but how would you specify asynchronous preset/clear? clk d s q r Finite State Machines module FSM1(clk,rst, enable, data_in, data_out); input clk, rst, enable; input data_in; output data_out; /* Defined state encoding; this style preferred over defines*/ parameter default=2'bxx; parameter idle=2'b00; parameter read=2'b01; parameter write=2'b10; reg data_out; reg [1:0] state, next_state; /* always block for sequential logic*/ always @(posedge clk) if (rst) state <= idle; else state <= next_state; Style guidelines (some of these are to get the right result, and some just for readability) Must have reset. Use separate always blocks for sequential and combination logic parts. Represent states with defined labels or enumerated types. Spring 2005 EECS150 - Lec06-synthesis Page 23 Spring 2005 EECS150 - Lec06-synthesis Page 24 6

FSMs (cont.) /* always block for CL */ always @(state or enable or data_in) case (state) /* For each state def output and next */ idle : data_out = 1 b0; if (enable) next_state = read; else next_state = idle; read : write : default : next_state = default; data_out = 1 bx; case Use a CASE statement in an always to implement next state and output logic. Always use a default case and asset the state variable and output to bx: avoids implied latches, allows the use of don t cares leading to simplified logic. The FSM compiler within the synthesis tool can re-encode your states. This process is controlled by using a synthesis attribute (passed in a comment). See the Synplify guide for details. More Help Online documentation for Synplify Synthesis Tool: Under refs/links and linked to today s lecture on calar Online examples from Synplicity. Bhasker (same author as Verilog reference book) on reserve in the Engineering library. Trial and error with the synthesis tool. Synplify will display the output of synthesis in schematic form for your inspection. Try different input and see what it produces. Spring 2005 EECS150 - Lec06-synthesis Page 25 Spring 2005 EECS150 - Lec06-synthesis Page 26 Bottom line Have the hardware design clear in your mind when you write the verilog. Write the verilog to describe that HW it is a Hardware Description Language not a Hardware Imagination Language. If you are very clear, the synthesis tools are likely to figure it out. Spring 2005 EECS150 - Lec06-synthesis Page 27 7