VHDL Modeling Behavior from Synthesis Perspective -Part B - EL 310 Erkay Savaş Sabancı University

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

Sequential Logic - Module 5

Lecture 12 VHDL Synthesis

VHDL: RTL Synthesis Basics. 1 of 59

Finite State Machines (FSM) Description in VHDL. Review and Synthesis

The University of Alabama in Huntsville ECE Department CPE Midterm Exam February 26, 2003

Synthesis from VHDL. Krzysztof Kuchcinski Department of Computer Science Lund Institute of Technology Sweden

ECE Digital Design Laboratory. Lecture 3 Finite State Machines!

CprE 583 Reconfigurable Computing

VHDL And Synthesis Review

The University of Alabama in Huntsville Electrical and Computer Engineering CPE/EE 422/522 Spring 2005 Homework #6 Solution

VHDL for Synthesis. Course Description. Course Duration. Goals

Summary of FPGA & VHDL

State Machine Descriptions

Creating Safe State Machines

CSE 260 Introduction to Digital Logic and Computer Design. Exam 1. Your name 2/13/2014

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

Assignment. Last time. Last time. ECE 4514 Digital Design II. Back to the big picture. Back to the big picture

Hardware Description Languages. Modeling Complex Systems

8 Register, Multiplexer and

Finite State Machines

FINITE STATE MACHINES (FSM) DESCRIPTION IN VHDL. Cristian Sisterna UNSJ

Synthesizable Verilog

Luleå University of Technology Kurskod SMD152 Datum Skrivtid

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

Inferring Storage Elements

ECEU530. Homework 4 due Wednesday Oct 25. ECE U530 Digital Hardware Synthesis. VHDL for Synthesis with Xilinx. Schedule

קורס VHDL for High Performance. VHDL

Lecture 4: Modeling in VHDL (Continued ) EE 3610 Digital Systems

Lecture 08 Finite State Machine Design Using VHDL

Part 4: VHDL for sequential circuits. Introduction to Modeling and Verification of Digital Systems. Memory elements. Sequential circuits

COE 405, Term 062. Design & Modeling of Digital Systems. HW# 1 Solution. Due date: Wednesday, March. 14

Sequential Circuit Design: Principle

CSE140L: Components and Design

COVER SHEET: Total: Regrade Info: 5 (14 points) 7 (15 points) Midterm 1 Spring 2012 VERSION 1 UFID:

Introduction to VHDL #3

3 Designing Digital Systems with Algorithmic State Machine Charts

DESCRIPTION OF DIGITAL CIRCUITS USING VHDL

Lab 3. Advanced VHDL

Computer-Aided Digital System Design VHDL

EEL 4783: HDL in Digital System Design

ECE 448 Lecture 4. Sequential-Circuit Building Blocks. Mixing Description Styles

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

VHDL simulation and synthesis

The process. Sensitivity lists

Introduction to Design Vision. Instructor: Prof. Shantanu Dutt. TA: Soumya Banerjee

Timing in synchronous systems

The University of Alabama in Huntsville ECE Department CPE Midterm Exam Solution Spring 2016

CSE140L: Components and Design Techniques for Digital Systems Lab

The University of Alabama in Huntsville ECE Department CPE Final Exam Solution Spring 2004

[VARIABLE declaration] BEGIN. sequential statements

Used to perform operations many times. See previous Parallel to Serial Example

Modeling Complex Behavior

EL 310 Hardware Description Languages Midterm

Outline. CPE/EE 422/522 Advanced Logic Design L05. Review: General Model of Moore Sequential Machine. Review: Mealy Sequential Networks.

The University of Alabama in Huntsville ECE Department CPE Midterm Exam Solution March 2, 2006

Multi-valued Logic. Standard Logic IEEE 1164 Type std_ulogic is ( U, uninitialized

Logic Synthesis. EECS150 - Digital Design Lecture 6 - Synthesis

IT T35 Digital system desigm y - ii /s - iii

CprE 583 Reconfigurable Computing

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

Luleå University of Technology Kurskod SMD098 Datum Skrivtid

EITF35: Introduction to Structured VLSI Design

EECS150 - Digital Design Lecture 5 - Verilog Logic Synthesis

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

VHDL in 1h. Martin Schöberl

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

SEQUENTIAL STATEMENTS

Laboratory Exercise 3 Davide Rossi DEI University of Bologna AA

Nanosistemų programavimo kalbos 5 paskaita. Sekvencinių schemų projektavimas

Designing Safe Verilog State Machines with Synplify

In our case Dr. Johnson is setting the best practices

Control and Datapath 8

Verilog for High Performance

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

FPGA for Software Engineers

10 Writing Circuit Descriptions

DIGITAL LOGIC WITH VHDL (Fall 2013) Unit 6


EECS150 - Digital Design Lecture 10 Logic Synthesis

EECS150 - Digital Design Lecture 10 Logic Synthesis

Hardware Description Language VHDL (1) Introduction

Sequential Statement

Sequential Circuit Design: Principle

Control Unit: Binary Multiplier. Arturo Díaz-Pérez Departamento de Computación Laboratorio de Tecnologías de Información CINVESTAV-IPN

CSCI Lab 3. VHDL Syntax. Due: Tuesday, week6 Submit to: \\fs2\csci250\lab-3\

Schedule. ECE U530 Digital Hardware Synthesis. Rest of Semester. Midterm Question 1a

CSE 260 Introduction to Digital Logic and Computer Design. Exam 1 Solutions

EE 459/500 HDL Based Digital Design with Programmable Logic. Lecture 6 Combinational and sequential circuits

VHDL. Chapter 7. Behavioral Modeling. Outline. Behavioral Modeling. Process Statement

Digital Systems Design

Quick Introduction to SystemVerilog: Sequental Logic

Nanosistemų programavimo kalbos 4 paskaita. Nuosekliai vykdomi sakiniai

Digital Design with SystemVerilog

Sign here to give permission for your test to be returned in class, where others might see your score:

Finite State Machines

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

DIGITAL LOGIC DESIGN VHDL Coding for FPGAs Unit 6

ECE 545 Lecture 12. Datapath vs. Controller. Structure of a Typical Digital System Data Inputs. Required reading. Design of Controllers

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

Transcription:

VHDL Modeling Behavior from Synthesis Perspective -Part B - EL 310 Erkay Savaş Sabancı University 1

The Wait Statement Syntax wait until condition; Different forms wait until(clk event and clk = 1 ); wait until(rising_edge(clk)); wait until(falling_edge(clk)); It implies synchronous logic. Consider a circuit where signal values are stored in edge-triggered flip-flops and their values are updated in the clock edge. Therefore, all signals whose values are controlled by the wait statement will be synthesized into edgetriggered flip-flops. 2

Wait vs. If-Then-Endif Statement Only one wait statement is permitted in a process and it must be the first statement. Then, an edge-triggered flip-flop will be inferred for every signal in the process. We do not always want to generate flip-flops for every signal Then we must use if-then-endif construct. Edge detection expression limits the flip-flop inference to signals assigned in the body of then statement. The remaining statements will lead to combinational logic. 3

Synchronous Logic with Wait Statement library IEEE; use IEEE.std_logic_1164.all; entity edge is port (reset, clk: in std_logic; Aout, Bout: out integer range 0 to 3); end entity edge; architecture behavioral of edge is process wait until (rising_edge(clk)); if reset = 1 then Aout <= 0; Bout <= 1; else Aout <= 2; Bout <= 2; end if; end process; end architecture behavioral; 4

Synchronous Logic with Wait Statement 5

Example in the Textbook library IEEE; use IEEE.std_logic_1164.all; entity edge is port (reset, clk: in std_logic; Aout, Bout: out integer range 0 to 3); end entity edge; architecture behavioral of edge is process wait until (rising_edge(clk)); if reset = 1 then Aout <= 1; else Aout <= 3; end if; Bout <= 0; end process; end architecture behavioral; 6

Example in the Textbook Warning message gotten from the synthesis compiler: All reachable assignments to bout(0) and bout(1) to assign 0, register removed by optimization. 7

Synchronous Logic with If Statement library IEEE; use IEEE.std_logic_1164.all; entity edge is port (reset, clk: in std_logic; x: in integer range 0 to 3; Aout, Bout: out integer range 0 to 3); end entity edge; architecture behavioral of edge is process(clk, reset, x) is if reset = 1 then Aout <= x; else Aout <= x+1; end if; if(rising_edge(clk)) then Bout <= x; end if; end process; end architecture behavioral; 8

Synchronous Logic with If Statement 9

Synthesis vs. Simulation Semantics library IEEE; use IEEE.std_logic_1164.all; entity semantics is port (reset, clk, x, y, z: in std_logic; aout, bout: in std_logic); end entity semantics; architecture behavioral of semantics is signal sig_a, sig_b: std_logic; process wait until (rising_edge(clk)); if reset='1' then sig_a <= '0'; sig_b <= '0'; else sig_a <= x and y; sig_b <= sig_a xor z; end if; aout <= sig_a bout <= sig_b; end process; end architecture behavioral; 10

Synthesis vs. Simulation Semantics Simulation and Synthesis semantics match in this specific 11 example

Synthesis vs. Simulation Semantics library IEEE; use IEEE.std_logic_1164.all; entity semantics is port (x, y, z: in std_logic; w: out std_logic); end entity semantics; architecture behavioral of semantics is signal s1, s2: std_logic; process(x, y, z) is L1: s1 <= x xor y; L2: s2 <= s1 or z; L3: w <= s1 nor s2; end process; end architecture behavioral; 12

Synthesis vs. Simulation Semantics x y z w w = [(x y) + ((x y) + z)] = [(x y) + z] Semantics of simulation and synthesis do not match In behavioral simulation, the value of the signal s1 used in statement L2 is the one before this execution of process. This implies usage of a latch. The synthesized logic is optimized and purely combinational 13

Variables with Wait Statement library IEEE; use IEEE.std_logic_1164.all; entity var_wait is port (x, y, z, clk: in std_logic; w: out std_logic); end entity var_wait; architecture behavioral of var_wait is process is variable a_var, b_var: std_logic; wait until (rising_edge(clk)); L1: a_var := x or y; L2: b_var := a_var nor z; L3: w <= b_var xor y; end process; end architecture behavioral; 14

Variables with Wait Statement clk z x y a_var_1 b_var w_1 w w Unlike signals, variable assignments take affect immediately. Variables are usually collapsed into combinational logic unless a variable is used before it is defined. 15

Variables with Wait Statement Let us change the statement L1 in the previous example as follows: a_var := (x or y) nor b_var; clk z y w b_var a_var b_var_1 w_1 w x 16

Caveat We expect that level-sensitive or edgesensitive expressions within the conditional part of the code determine whether latches or flip-flops are inferred. However, some synthesis compiler may still infer flip-flops regardless of whether the conditional expression is level- or edgesensitive. 17

Synthesis of State Machines Inputs Output Function Mealy Outputs Next State Function Combinational Network state State Elements Next state clk Output Function Combinational Network Moore Outputs 18

Encoding of State Elements Function of number of states For example, eight states 3 bits to represent each state uniquely. Which state is numbered with what number? State Sequential Gray Code One Hot 0 000 000 00000001 1 001 001 00000010 2 010 011 00000100 3 011 010 00001000 4 100 110 00010000 5 101 111 00100000 6 110 101 01000000 7 111 100 10000000 most compact 19

FSM Compiler & Explorer in Synplify Pro FSM Compiler automatically recognizes state machines in your design and optimizes them. extracts the state machines as symbolic graphs, and then optimizes them by re-encoding the state representations Optimization with respect to time and/or area. and generating a better logic optimization starting point for the state machines. FSM Explorer uses the state machines extracted by the FSM Compiler when it explores different encoding styles. 20

Encoding in Synplify Pro When FSM compiler is enabled default encodingstyle automatically assigns encoding based on the number of states in the state machine as follows: sequential for 0-4 states One Hot for 5-24 states gray for > 24 states Syn_state_directive allows to choose sequential gray One Hot Safe: default encoding & add reset logic to force the state machine to a known state if it reaches an invalid state. 21

State Machine Synthesis: Example library IEEE; use IEEE.std_logic_1164.all; entity state_machine is port (reset, x, clk: in std_logic; w: out std_logic); end entity state_machine ; architecture behavioral of state_machine is type state_type is (state0, state1); signal state, next_state: state_type; process is wait until (rising_edge(clk)); if reset = 1 then w <= 0 ; else... end if; end process; end architecture behavioral; 22

State Machine Synthesis: Example... process wait until (rising_edge(clk)); if reset = 1 then w <= 0 ; else case state is when state0 => if x = 0 then state <= state1; w <= 1 ; else state <= state0; w <= 0 ; end if; when state1 => if x = 1 then state <= state0; w <= 1 ; else state <= state1; w <= 0 ; end if; end case; end if; end process; end architecture behavioral; This is a Mealy machine where output w is a function of both the state and the input. 23

State Machine Synthesis: Example one flip-flop for encoding two state unnecessary flip-flop for output signal 24

State Machine Synthesis: Better VHDL... ns_process: process(state, x) is case state is when state0 => if x = '0' then next_state <= state1; w <= '1'; else next_state <= state0; w <= 0; end if; when state1 => if x = '0' then next_state <= state0; w <= '0'; else next_state <= state1; w <= '1'; end if; end case; end process ns_process; clk_process: process(reset, clk) if (rising_edge(clk)) then if (reset = '1') then state <= state_type'left; else state <= next_state; end if; end if; end process clk_process; end architecture; 25

State Machine Synthesis: Better VHDL No unnecessary latch for output signal which is dependent on the state and input 26

Another Example entity sm1_2 is port (x, clk: in std_logic; z: out std_logic); end entity sm1_2; architecture behavioral of sm1_2 is subtype s_type is integer range 0 to 7; signal state, next_state: s_type; constant s0: s_type := 0; constant s1: s_type := 4; constant s2: s_type := 5; constant s3: s_type := 7; constant s4: s_type := 6; constant s5: s_type := 3; constant s6: s_type := 2; clk_process: process(clk) if (rising_edge(clk)) then state <= next_state; end if; end process clk_process; 27

Another Example ns_process: process(state, x) is z <= '0'; next_state <= s0; case state is when s0 => if x = '0' then z <= '1'; next_state <= s1; else z <= '0'; next_state <= s2; end if; when s1 => if x = '0' then z <= '1'; next_state <= s3; else z <= '0'; next_state <= s4; end if; when s2 => if x = '0' then z <= '0'; next_state <= s4; else z <= '1'; next_state <= s4; end if; when s3 => if x = '0' then z <= '0'; next_state <= s5; else z <= '1'; next_state <= s5; end if; when s4 => if x = '0' then z <= '1'; next_state <= s5; else z <= '0'; next_state <= s6; end if; when s5 => if x = '0' then z <= '0'; next_state <= s0; else z <= '1'; next_state <= s0; end if; when s6 => if x = '0' then z <= '1'; next_state <= s0; when others => null; end case; end process; end architecture; 28

Null Statement a sequential statement that does not cause any action to take place; execution continues with the next statement. In the previous example, when others => null; implies that no action needs to be performed when state is any other than specified in the case statement. Recall that all choices must be covered in case statements. Sometimes it is useful to explicitly say that no action needs to be performed case or if statements. 29

Design Process Develop the VHDL models and use simulation to verify the functional correctness of the model. The model is then synthesized Synthesized model is simulated to verify the performance. Simulation of VHDL model and simulation model of the synthesized model may behave differently. This is what is called semantic mismatch. 30

Simulation vs. Synthesis Incomplete sensitivity list: In VHDL model simulation, sensitivity list can include only a few signals and exclude the others. Especially, if the process produces a combinational logic, then the circuit will be sensitive to a change on any of the signals that are manipulated in the process. process (sel) is if(sel= 1 and En= 0 ) then A<= 1 ; else A<= 0 ; end if; end process; The synthesized circuit will also be sensitive to the signal En. 31

Simulation vs. Synthesis Sequential signal assignments in a process the code below show sequential behavior in VHDL simulation process (x, y, z) L1: s1 <= x xor y; L2: s2 <= s1 or z; L3: w <= s1 nor s2; end process; However, synthesis compiler will generally optimize this sequence to produce combinational logic and avoid latches. 32

Simulation vs. Synthesis User specified delays may not match the actual delays in the synthesized circuit. Simulation Overhead: Conditional and selected CSA can be modeled using process. Since CSAs are always active, it has more simulation overhead. CSAs, on the other hand, are better for synthesis. Speed: Use of variables in process will result in faster simulation. Use of process may obscure the concurrency within the process and may reduce the effectiveness of the inference mechanisms. 33

Synthesis Hints The while-loop statement may not be supported by some synthesis compiler, since iteration number is data dependent. All for loop indices must have statically determinable loop ranges. In order to avoid inference of an unnecessary latch for a signal, every execution path through the process must assign a value for that signal. A latch will be inferred for a variable if it is used before it is defined. Initialize your signals (if you must do so) explicitly under the control of reset signal. Otherwise, initialization may be ignored by the compiler. 34

Synthesis Hints Include all signals in a process in the sensitivity list of the process. The VHDL code should imply hardware. Avoid purely algorithmic descriptions of hardware. To avoid latches for a signal that appears in conditional statements, make sure that default values are assigned to this signals before a conditional block of code. Try to minimize dependencies between statements. Using don t care values to cover when others case in a case statement can enable the compiler to optimize the logic. Try to avoid setting signals to specific values 0000 or 1111 in when others. 35

Synthesis Hints If possible try to specify data ranges for signals. Minimize signal assignment statements in a process and use variables. Use if-then-else statements to infer flip-flops rather than wait statements. To infer flip-flop with a wait statement necessitates that wait statement must be the first and only wait statement in the process; thus leading to flip-flop inference for every signal in the process. Do not use don t care symbols in comparisons. Such comparisons will always return FALSE. Check vendor specific constraints on the permitted types and range for the for-loop index 36

Synthesis Hints Move common complex operations out of the branches of conditional statements. Using a case statement rather than if-then-elsif will produce less logic since priority logic will have to be generated for the latter. The choice of coding style must be guided by the building blocks that are available in the target technology. For example, if latches are not available, then level sensitive expressions will lead to the synthesis of latches in gate level equivalents. This will complicate the circuit and timing analysis. 37