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

Similar documents
Verilog 1 - Fundamentals

Verilog 1 - Fundamentals

Course Details: Webpage

Digital Design Using Verilog

Welcome to CS250 VLSI Systems Design

Chap 6 Introduction to HDL (d)

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

Digital Design with FPGAs. By Neeraj Kulkarni

Synthesizable Verilog

Course administrative notes. Verilog 2 - Design Examples

EECS150 - Digital Design Lecture 5 - Verilog Logic Synthesis

CSE140L: Components and Design

CSE140L: Components and Design Techniques for Digital Systems Lab

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

Chapter 2 Using Hardware Description Language Verilog. Overview

EN2911X: Reconfigurable Computing Topic 02: Hardware Definition Languages

Verilog Fundamentals. Shubham Singh. Junior Undergrad. Electrical Engineering

EECS150 - Digital Design Lecture 10 Logic Synthesis

EEL 4783: HDL in Digital System Design

Introduction to Verilog/System Verilog

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

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

Hardware Description Language (HDL)

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

EECS150 - Digital Design Lecture 10 Logic Synthesis

Verilog for Synthesis Ing. Pullini Antonio

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

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

Verilog Design Principles

Lecture 15: System Modeling and Verilog

Speaker: Shao-Wei Feng Adviser: Prof. An-Yeu Wu Date: 2010/09/28

Hardware Description Languages. Hardware Description Languages. Hardware Description Languages. Digital Design Using Verilog

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

Image Courtesy CS250 Section 3. Yunsup Lee 9/11/09

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

Online Verilog Resources

A Verilog Primer. An Overview of Verilog for Digital Design and Simulation

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

Logic Synthesis. EECS150 - Digital Design Lecture 6 - Synthesis

ENGN1640: Design of Computing Systems Topic 02: Design/Lab Foundations

ENGN1640: Design of Computing Systems Topic 02: Lab Foundations

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

This Lecture. Some components (useful for the homework) Verilog HDL (will continue next lecture)

Design Using Verilog

Verilog Hardware Description Language ROOM: B405

Week 2 Status Update

Synthesis of Combinational and Sequential Circuits with Verilog

Verilog HDL Introduction

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

ENGN1640: Design of Computing Systems Topic 02: Design/Lab Foundations

TOPIC : Verilog Synthesis examples. Module 4.3 : Verilog synthesis

Hardware Description Languages: Verilog

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

Hardware description languages

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

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

Writing Circuit Descriptions 8

A Brief Introduction to Verilog Hardware Definition Language (HDL)

Course Topics - Outline

Verilog Coding Guideline

Introduction to Verilog HDL. Verilog 1

Verilog Design Principles

CSE140L: Components and Design Techniques for Digital Systems Lab. Verilog HDL. Instructor: Mohsen Imani UC San Diego. Source: Eric Crabill, Xilinx

Lecture 32: SystemVerilog

Introduction to Verilog HDL

HDLs and SystemVerilog. Digital Computer Design

Lab 7 (All Sections) Prelab: Introduction to Verilog

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

CS6710 Tool Suite. Verilog is the Key Tool

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

ECE 353 Lab 3 (Verilog Design Approach)

Contents. Appendix D Verilog Summary Page 1 of 16

Lecture #2: Verilog HDL

a, b sum module add32 sum vector bus sum[31:0] sum[0] sum[31]. sum[7:0] sum sum overflow module add32_carry assign

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

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

EN164: Design of Computing Systems Lecture 07: Lab Foundations / Verilog 3

Verilog Tutorial (Structure, Test)

VLSI Design 13. Introduction to Verilog

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

Hardware Description Language VHDL (1) Introduction

Programmable Logic Devices Verilog VII CMPE 415

Introduction To HDL. Verilog HDL. Debdeep Mukhopadhyay Dept of CSE, IIT Madras 1

DIGITAL SYSTEM DESIGN

EECS150 - Digital Design Lecture 6 - Logic Simulation

Verilog Behavioral Modeling

Tutorial on Verilog HDL

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

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

Verilog HDL. Testing & Verification Dept. of Computer Science & Engg,, IIT Kharagpur

Advanced Digital Design with the Verilog HDL

Introduction to Digital Design with Verilog HDL

Verilog Overview. The Verilog Hardware Description Language. Simulation of Digital Systems. Simulation of Digital Systems. Don Thomas, 1998, Page 1

Combinational Circuit Design

Digital Design (VIMIAA01) Introduction to the Verilog HDL

Digital Circuit Design and Language. Datapath Design. Chang, Ik Joon Kyunghee University

Verilog for High Performance

In this lecture, we will go beyond the basic Verilog syntax and examine how flipflops and other clocked circuits are specified.

VERILOG 2: LANGUAGE BASICS

Transcription:

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

Upcoming dates! 9/8/09 (12:30pm) - Lab 1 due (No late days for Lab 1!)! Submit using SVN (source, build, writeup)! 9/8/09 - Lab 2 out! Write and Synthesize a Two-Stage SMIPSv2 processor! Did you know about tutorials?! Tutorial 3: Build, Run, and Write SMIPS Programs! Tutorial 4: Simulating Verilog RTL using Synopsys VCS! Tutorial 5: RTL-to-Gates Synthesis using Synopsys DC! SMIPS Specifictaion

Heads-up for Lab 1! standard cell library cache directory! check dc-syn/makefile if ALIB_DIRECTORY exists! dc.tcl changed! copy it from ~cs250/lab1/build/dc-syn/dc_scripts! change clock period to 1 ns! change build/dc-syn/constraints.tcl

Some other stuff...! NX Client! You should use this for fast GUI experience! However, ilinux1.eecs is suffering with RAM, so please logout! SVN! https://isvn.eecs.berkeley.edu/cs250/<username>! Guarded with your instructional account password! Only commit the most recent build - source files are fine! License server! We had an outage on 9/2 Wednesday! Now we have a backup license server - look at cs250.bashrc

Some other stuff...! Please exit the tools after using! Don t keep your tools occupying one or several licenses! It s a shared resource, and you should be fair! Check the News page for any updates! http://inst.eecs.berkeley.edu/~cs250/fa09/news.html! Tools are only supported on ilinux[1-3].eecs! Noticed that VCS (old version) is installed on the Sun Boxes! Labs and Tutorials have version numbers! I ll try hard not to change the version whenever it s in transit! Writeup should be in text or PDF

Any questions! Let s form groups of two and talk about Lab 1! Any questions on lab1 or any tools?! Critical Path! Synopsys Design Vision! Synopsys IC Compiler

Primary Verilog data type is a bitvector Value Meaning 0 Logic zero 1 Logic one X Z Unknown logic value High impedance, floating An X bit might be a 0, 1, Z, or in transition. We can set bits to be X in situations where we don t care what the value is. This can help catch bugs and improve synthesis quality.

wire is used to denote a standard hardware net wire [15:0] instruction; wire [15:0] memory_req; wire [ 7:0] small_net; Absolutely no type safety when connecting nets!? instruction memory_req instruction small_net

Verilog includes ways to specify bit literals in various bases 4 b10_11 Base format (d,b,o,h) Underscores are ignored Decimal number representing size in bits! Binary literals! 8 b0000_0000! 8 b0xx0_1xx1! Hexadecimal literals! 32 h0a34_def1! 16 haxxx! Decimal literals! 32 d42 We ll learn how to actually assign literals to nets a little later

Verilog module includes a module name and a port list A B 4 4 adder 4 module adder( A, B, cout, sum ); input [3:0] A; input [3:0] B; output cout; output [3:0] sum; // HDL modeling of // adder functionality cout sum endmodule Ports must have a direction (or be bidirectional) and a bitwidth Note the semicolon at the end of the port list!

Verilog module includes a module name and a port list cout A B 4 4 adder 4 sum Traditional Verilog-1995 Syntax module adder( A, B, cout, sum ); input [3:0] A; input [3:0] B; output cout; output [3:0] sum; ANSI C Style Verilog-2001 Syntax module adder( input [3:0] A, input [3:0] B, output cout, output [3:0] sum );

A module can instantiate other modules creating a hierarchy a b cin module FA( input a, b, cin output cout, sum ); cout FA // HDL modeling of 1 bit // adder functionality c endmodule

A module can instantiate other modules creating a hierarchy A B adder FA FA FA FA cout S module adder( input [3:0] A, B, output cout, output [3:0] S ); wire c0, c1, c2; FA fa0( A[0], B[0], 1 b0, c0, S[0] ); FA fa1( A[1], B[1], c0, c1, S[1] ); FA fa2( A[2], B[2], c1, c2, S[2] ); FA fa3( A[3], B[3], c2, cout, S[3] ); endmodule Carry Chain

Verilog supports connecting ports by position and by name Connecting ports by ordered list FA fa0( A[0], B[0], 1 b0, c0, S[0] ); Connecting ports by name (compact) FA fa0(.a(a[0]),.b(b[0]),.cin(1 b0),.cout(c0),.sum(s[0]) ); Connecting ports by name FA fa0 (.a (A[0]),.b (B[0]),.cin (1 b0),.cout (c0),.sum (S[0]) ); For all but the smallest modules, connecting ports by name yields clearer and less buggy code.

Three abstraction levels Behavioral Algorithm Register Transfer Level Gate Level Manual Logic Synthesis Auto Place + Route V V V Abstract algorithmic description Describes how data flows between state elements for each cycle Low-level netlist of primitive gates

Gate-level Verilog uses structural Verilog to connect primitive gates module mux4( input a, b, c, d, input [1:0] sel, output out ); wire [1:0] sel_b; not not0( sel_b[0], sel[0] ); not not1( sel_b[1], sel[1] ); b d a c sel[1] sel[0] wire n0, n1, n2, n3; and and0( n0, c, sel[1] ); and and1( n1, a, sel_b[1] ); and and2( n2, d, sel[1] ); and and3( n3, b, sel_b[1] ); wire x0, x1; nor nor0( x0, n0, n1 ); nor nor1( x1, n2, n3 ); wire y0, y1; or or0( y0, x0, sel[0] ); or or1( y1, x1, sel_b[0] ); nand nand0( out, y0, y1 ); endmodule out

Blocking vs. Non-blocking 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=? B=? Non-blocking procedural assignment <= In simulation the RHS is executed and all assignment take place at the same time (end of the current time step - not clock cycle). Example: Assume A holds the value 1 A<=2; B<=A; A=? B=? 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; end end b stores in b stores the old a

Guideline i. Use blocking assignments to model combinational logic within an always block ( = ). ii. iii. iv. Use non-blocking assignments to implement sequential logic ( <= ). Do not mix blocking and non-blocking assignments in the same always block. Do not make assignments to the same variable from more than one always block.

Always blocks have parallel inter-block, sequential intra-block semantics module mux4( input a, b, c, d input [1:0] sel, output out ); reg out, t0, t1; always @( a or b or c or d or sel ) begin t0 = ~( (sel[1] & c) (~sel[1] & a) ); t1 = ~( (sel[1] & d) (~sel[1] & b) ); out = ~( (t0 sel[0]) & (t1 ~sel[0]) ); end endmodule The always block is reevaluated whenever a signal in its sensitivity list changes

Always blocks have parallel inter-block, sequential intra-block semantics module mux4( input a, b, c, d input [1:0] sel, output out ); reg out, t0, t1; always @( a or b or c or d or sel ) begin t0 = ~( (sel[1] & c) (~sel[1] & a) ); t1 = ~( (sel[1] & d) (~sel[1] & b) ); out = ~( (t0 sel[0]) & (t1 ~sel[0]) ); end endmodule What happens if we accidentally forget a signal on the sensitivity list?

Always blocks have parallel inter-block, sequential intra-block semantics module mux4( input a, b, c, d input [1:0] sel, output out ); reg out, t0, t1; always @( * ) begin t0 = ~( (sel[1] & c) (~sel[1] & a) ); t1 = ~( (sel[1] & d) (~sel[1] & b) ); out = ~( (t0 sel[0]) & (t1 ~sel[0]) ); end endmodule Verilog-2001 provides special syntax to automatically create a sensitivity list for all signals read in the always block

Using continuous assignments module mux4( input a, b, c, d input [1:0] sel, output out ); wire out, t0, t1; assign out t0 = ~( (t0 (sel[1] sel[0]) & c) &(~sel[1] (t1 ~sel[0]) & a) ); ); assign t1 = ~( (sel[1] & d) (~sel[1] & b) ); assign t0 out = ~( (sel[1] (t0 sel[0]) & c) &(~sel[1] (t1 ~sel[0]) & a) ); ); endmodule The order of these continuous assignment statements does not matter. They essentially happen in parallel!

Using other operators // Four input multiplexer module mux4( input a, b, c, d input [1:0] sel, output out ); assign out = ( sel == 0 )? a : ( sel == 1 )? b : ( sel == 2 )? c : ( sel == 3 )? d : 1 bx; endmodule If input is undefined we want to propagate that information.

More advanced constructs module mux4( input a, b, c, d input [1:0] sel, output out ); reg out; always @( * ) begin if ( sel == 2 d0 ) out = a; else if ( sel == 2 d1 ) out = b else if ( sel == 2 d2 ) out = c else if ( sel == 2 d3 ) out = d else out = 1 bx; end endmodule module mux4( input a, b, c, d input [1:0] sel, output out ); reg out; always @( * ) begin case ( sel ) 2 d0 : out = a; 2 d1 : out = b; 2 d2 : out = c; 2 d3 : out = d; default : out = 1 bx; endcase end endmodule

What happens if the case statement is not complete? module mux3( input a, b, c input [1:0] sel, output out ); reg out; always @( * ) begin case ( sel ) 2 d0 : out = a; 2 d1 : out = b; 2 d2 : out = c; endcase end If sel = 3, mux will output the previous value. What have we created? endmodule

What happens if the case statement is not complete? module mux3( input a, b, c input [1:0] sel, output out ); reg out; always @( * ) begin case ( sel ) 2 d0 : out = a; 2 d1 : out = b; 2 d2 : out = c; default : out = 1 bx; endcase end endmodule We can prevent creating state with a default statement

How do you make sequential logic? module latch ( input clk, input d, output reg q ); always @( clk ) begin if ( clk ) q <= d; end endmodule module flipflop ( input clk, input d, output q ); always @( posedge clk ) begin q <= d; end endmodule Edge-triggered always block

Why non-blocking statements? wire A_in, B_in, C_in; reg A_out, B_out, C_out; A B C always @( posedge clk ) A_out = A_in; assign B_in = A_out + 1; always @( posedge clk ) B_out = B_in; assign C_in = B_out + 1; always @( posedge clk ) C_out = C_in; +1 +1

Why non-blocking statements? wire A_in, B_in, C_in; reg A_out, B_out, C_out; A B C always @( posedge clk ) A_out <= A_in; assign B_in = A_out + 1; always @( posedge clk ) B_out <= B_in; assign C_in = B_out + 1; always @( posedge clk ) C_out <= C_in; +1 +1

Guideline i. Use blocking assignments to model combinational logic within an always block ( = ). ii. iii. iv. Use non-blocking assignments to implement sequential logic ( <= ). Do not mix blocking and non-blocking assignments in the same always block. Do not make assignments to the same variable from more than one always block.

Putting it all together: FSM for GCD A_MUX_SEL_IN = 0 A_MUX_SEL_SUB = 1 A_MUX_SEL_B = 2!" #$%" &'("!" )'*" '+"," #$%" &'("," )'*" '+","."/"!"-"," /.3.@%!"#$% A_MUX_SEL = A_MUX_SEL_IN A_EN = 1 B_MUX_SEL = B_MUX_SEL_IN B_EN = 1 OPERANDS_RDY = 1 A zero? lt sub,-./01234506% &"'&% if (A < B) A_MUX_SEL = A_MUX_SEL_B A_EN = 1 B_MUX_SEL = B_MUX_SEL_A B_EN = 1 B 78%"%9%:%;%<%8%:%=%>%;% if (B!= 0) A_MUX_SEL = A_MUX_SEL_SUB A_EN = 1 /.3?6@4/2A% ()*+% RESULT_VAL = 1 B_MUX_SEL_A = 0 B_MUX_SEL_IN = 1

Putting it all together: FSM for GCD! First make a register for saved state localparam WAIT = 2'd0; localparam CALC = 2'd1; localparam DONE = 2'd2; reg [1:0] state_next; wire [1:0] state; vcrdff_pf#(2,wait) state_pf (.clk (clk),.reset_p (reset),.d_p (state_next),.q_np (state) );

Putting it all together: FSM for GCD! Then local parameters for the mux control signals localparam A_MUX_SEL_X = 2'dx; localparam A_MUX_SEL_IN = 2'd0; localparam A_MUX_SEL_B = 2'd1; localparam A_MUX_SEL_SUB = 2'd2; localparam B_MUX_SEL_X = 1'dx; localparam B_MUX_SEL_IN = 1'd0; localparam B_MUX_SEL_A = 1'd1;

Putting it all together: FSM for GCD! Signals for each state always @(*) begin // Default control signals A_mux_sel = A_MUX_SEL_X; A_en = 1'b0; B_mux_sel = B_MUX_SEL_X; B_en = 1'b0; operands_rdy = 1'b0; result_val = 1'b0; case ( state ) WAIT : begin A_mux_sel A_en B_mux_sel B_en operands_rdy = 1'b1; end = A_MUX_SEL_IN; = 1'b1; = B_MUX_SEL_IN; = 1'b1; CALC : begin if ( A_lt_B ) begin A_mux_sel = A_MUX_SEL_B; A_en = 1'b1; B_mux_sel = B_MUX_SEL_A; B_en = 1'b1; end else if (!B_zero ) begin A_mux_sel = A_MUX_SEL_SUB; end end A_en = 1'b1; DONE : begin result_val = 1'b1; end endcase

Putting it all together: FSM for GCD! Then state transitions always @(*) begin // Default is to stay in the same state state_next = state; case ( state ) WAIT : if ( operands_val ) state_next = CALC; CALC : if (!A_lt_B && B_zero ) state_next = DONE; DONE : if ( result_rdy ) state_next = WAIT; endcase end