CSE 502: Computer Architecture

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

Quick Introduction to SystemVerilog: Sequental Logic

Testbenches for Sequential Circuits... also, Components

MCMASTER UNIVERSITY EMBEDDED SYSTEMS

Lecture 32: SystemVerilog

Chapter 4. Digital Design and Computer Architecture, 2 nd Edition. David Money Harris and Sarah L. Harris. Chapter 4 <1>

Chapter 4. Digital Design and Computer Architecture, 2 nd Edition. David Money Harris and Sarah L. Harris. Chapter 4 <1>

Last Lecture: Divide by 3 FSM

Chapter 4 :: Topics. Introduction. SystemVerilog. Hardware description language (HDL): allows designer to specify logic function only.

EECS150 - Digital Design Lecture 5 - Verilog Logic Synthesis

Modeling Sequential Circuits in Verilog

Verilog for Synthesis Ing. Pullini Antonio

Digital Design with SystemVerilog

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

HDLs and SystemVerilog. Digital Computer Design

Laboratory Exercise 3 Davide Rossi DEI University of Bologna AA

Synthesizable Verilog

MASSACHUSETTS INSTITUTE OF TECHNOLOGY Department of Electrical Engineering and Computer Sciences

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

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

271/469 Verilog Tutorial

Logic Synthesis. EECS150 - Digital Design Lecture 6 - Synthesis

EECS150 - Digital Design Lecture 20 - Finite State Machines Revisited

!== vs.!= and === vs. ==

Verilog Coding Guideline

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

EEL 4783: HDL in Digital System Design

Spring 2017 EE 3613: Computer Organization Chapter 5: Processor: Datapath & Control - 2 Verilog Tutorial

Parallel versus serial execution

EECS150 - Digital Design Lecture 10 Logic Synthesis

Writing Circuit Descriptions 8

EECS150 - Digital Design Lecture 10 Logic Synthesis

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

CSE140L: Components and Design Techniques for Digital Systems Lab

Concurrent & Sequential Stmts. (Review)

ECE 551: Digital System *

EECS 270 Verilog Reference: Sequential Logic

CSE140L: Components and Design

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

Digital Design (VIMIAA01) Introduction to the Verilog HDL

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

Control in Digital Systems

Introduction. Why Use HDL? Simulation output. Explanation

EECS150 - Digital Design Lecture 4 - Verilog Introduction. Outline

ECE Digital Design Laboratory. Lecture 3 Finite State Machines!

Verilog introduction. Embedded and Ambient Systems Lab

EE178 Lecture Verilog FSM Examples. Eric Crabill SJSU / Xilinx Fall 2007

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

Introduction to Verilog/System Verilog

VERILOG 2: LANGUAGE BASICS

EPC6055 Digital Integrated Circuits EXAM 1 Fall Semester 2013

Verilog 1 - Fundamentals

Readings: Storage unit. Can hold an n-bit value Composed of a group of n flip-flops. Each flip-flop stores 1 bit of information.

A short introduction to SystemVerilog. For those who know VHDL We aim for synthesis

Date Performed: Marks Obtained: /10. Group Members (ID):. Experiment # 11. Introduction to Verilog II Sequential Circuits

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

Spiral 1 / Unit 6. Flip-flops and Registers

Building Bigger Systems: Interfacing

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

VHDL for Synthesis. Course Description. Course Duration. Goals

ECE 551 Digital System Design and Synthesis. Instructor: Kewal K. Saluja. Midterm Exam

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

Hardware Description Language (HDL)

(System)Verilog Tutorial Aleksandar Milenković

A Brief Introduction to Verilog Hardware Definition Language (HDL)

Chap 6 Introduction to HDL (d)

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

Veriolog Overview. CS/EE 3710 Fall 2010

271/471 Verilog Tutorial

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

CS232 VHDL Lecture. Types

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

[VARIABLE declaration] BEGIN. sequential statements

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

Course Topics - Outline

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

Microcomputers. Outline. Number Systems and Digital Logic Review

HDL Design Cube. Synthesis and VHDL

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

EE 109L Review. Name: Solutions

Modeling of Finite State Machines. Debdeep Mukhopadhyay

EE 231 Fall EE 231 Homework 8 Due October 20, 2010

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

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

Discussion Session 6. CS/ECE 552 Ramkumar Ravi 05 Mar 2012

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

EE 3170 Microcontroller Applications

Digital Integrated Circuits

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

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

Verilog Fundamentals. Shubham Singh. Junior Undergrad. Electrical Engineering

ECE 4514 Digital Design II. Spring Lecture 7: Dataflow Modeling

Chapter 2 Using Hardware Description Language Verilog. Overview

Synthesis of Combinational and Sequential Circuits with Verilog

Topics. Midterm Finish Chapter 7

Standard Gotchas Subtleties in the Verilog and SystemVerilog Standards That Every Engineer Should Know

Workshop on Digital Circuit Design in FPGA

Outcomes. Spiral 1 / Unit 6. Flip Flops FLIP FLOPS AND REGISTERS. Flip flops and Registers. Outputs only change once per clock period

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

Digital Design with FPGAs. By Neeraj Kulkarni

Transcription:

CSE 502: Computer Architecture SystemVerilog

More Resources Cannot cover everything in one day You will likely need to look up reference material: SystemVerilog for VHDL Users: http://www.systemverilog.org/techpapers/date04_systemverilog.pdf http://www.doulos.com/knowhow/sysverilog/ http://www.eda.org/sv/systemverilog_3.1a.pdf http://electrosofts.com/systemverilog/operators.html http://www.cl.cam.ac.uk/teaching/1011/ecad+arch/files/systemverilogcheatsheet.pdf http://www.sunburst-design.com/papers/cummingssnug2003sj_systemverilogfsm.pdf

Basic Module Setup Assume: a, b, c are inputs to module f is output of module module is named mymodule all ports declared here declare which ports are inputs, which are outputs module mymodule(a, b, c, f); output f; input a, b, c; // Description goes here module

Module Instantiation Just like C++ object instantiation Module name is analogous to Class name Inputs/outputs are analogous to constructor arguments module mymodule(a, b, c, f); output f; input a, b, c; module_name instance_name(port_connections); module

Example: multiplexor Structural Design Output equals an input Which one deps on sel module mux(a, b, sel, f); output f; input a, b, sel; datatype for describing logical value logic c, d, not_sel; not gate0(not_sel, sel); and gate1(c, a, not_sel); and gate2(d, b, sel); or gate3(f, c, d); module instantiate gates as above

Continuous Assign Statement Specify behavior with assign statement and bit ops. module mux2(a, b, sel, f); output f; input a, b, sel; logic c, d; assign c = a & (~sel); assign d = b & sel; assign f = c d; module

Procedural Statement Can specify behavior of combinational logic procedurally using always_comb block module mymodule(a, b, c, f); output f; input a, b, c; always_comb begin // Combinational logic described in // C-like syntax module

Procedural Behavioral Mux Description module mux3(a, b, sel, f); output logic f; input a, b, sel; always_comb begin if (sel == 0) begin f = a; else begin f = b; module If we are going to drive f this way, need to declare it as logic Important: for behavior to be combinational, every output (f) must be assigned in all possible control paths Why? Otherwise, would be a latch

Condensed if-then-else Form Syntax borrowed from C: if (a) b = c; else b = d; So, we can simplify the mux:...... always_comb begin f = (sel)? b : a; same as b = (a)? c : d; Or even skip the always_comb block: assign f = (sel)? b : a;

Accidental Latch Description module bad(a, b, f); output logic f; input a, b; always_comb begin if (b == 1) begin f = a; module This is not combinational, because for certain values of b, f must remember its previous value. This code describes a latch. (If you want a latch, you should define it using always_latch) Don t do this!

Multiply-Assigned Values module bad2(...);... always_comb begin b =... something... Both of these blocks execute concurrently So what is the value of b? We don t know! always_comb begin b =... something else... module Don t do this!

Multi-Bit Values Can define inputs, outputs, or logic with multiple bits module mux4(a, b, sel, f); output logic [3:0] f; input [3:0] a, b; input sel; always_comb begin if (sel == 0) begin f = a; else begin f = b; module

Multi-Bit Constants and Concatenation Can give constants with specified number bits In binary or hexadecimal Can concatenate with { and } Can reverse order (to index buffers left-to-right) logic [3:0] a, b, c; logic signed [3:0] d; logic [1:0] e, f; assign a = 4 b0010; // four bits, specified in binary assign b = 4 hc; // four bits, specified in hex == 1100 assign c = 3; // == 0011 assign d = -2; // 2 s complement == 1110 as bits assign e = {a, b}; // concatenate == 0010_1100 assign f = a[2 : 1]; // two bits from middle == 01 assign g = b[c +: 2]; // two bits from bit c == 11

Case Statements and Don t-cares module newmod(out, in0, in1, in2); input in0, in1, in2; output logic out; always_comb begin case({in0, in1, in2}) 3'b000: out = 1; 3'b001: out = 0; 3'b010: out = 0; 3'b011: out = x; 3'b10x: out = 1; default: out = 0; case module output value is undefined in this case Last bit is a don t care -- this line will be active for 100 OR 101 default gives else behavior. Here active if 110 or 111

Arithmetic Operators Standard arithmetic operators defined: + - * / % Many subtleties here, so be careful: four bit number + four bit number = five bit number Or just the bottom four bits arbitrary division is difficult

Addition and Subtraction Be wary of overflow! logic [3:0] d, e, f; assign f = d + e; 4 b1000 + 4 b1000 = In this case, overflows to zero logic [3:0] a, b; logic [4:0] c; assign c = a+b; Five bit output can prevent overflow: 4 b1000 + 4 b1000 gives 5 b10000 Use signed if you want values as 2 s complement i == 4 b1010 == -6 j == 5 b11010 == -6 logic signed [3:0] g, h, i; logic signed [4:0] j; assign g = 4 b0001; // == 1 assign h = 4 b0111; // == 7 assign i = g h; assign j = g h;

Multiplication Multiply k bit number with m bit number How many bits does the result have? logic signed [3:0] a, b; logic signed [7:0] c; assign a = 4'b1110; // -2 assign b = 4'b0111; // 7 k+m If you use fewer bits in your code Get least significant bits of the product assign c = a*b; c = 8 b1111_0010 == -14 logic signed [3:0] a, b, d; assign a = 4'b1110; // -2 assign b = 4'b0111; // 7 assign d = a*b; d = 4 0010 == 2 Underflow!

Sequential Design Everything so far was purely combinational Stateless What about sequential systems? flip-flops, registers, finite state machines New constructs always_ff @(posedge clk, ) non-blocking assignment <=

Edge-Triggered Events Variant of always block called always_ff Indicates that block will be sequential logic (flip flops) Procedural block occurs only on a signal s edge @(posedge ) or @(negedge ) always_ff @(posedge clk, negedge reset_n) begin // This procedure will be executed // anytime clk goes from 0 to 1 // or anytime reset_n goes from 1 to 0

Flip Flops (1/3) q remembers what d was at the last clock edge One bit of memory Without reset: module flipflop(d, q, clk); input d, clk; output logic q; always_ff @(posedge clk) begin q <= d; module

Asynchronous reset: Flip Flops (2/3) module flipflop_asyncr(d, q, clk, rst_n); input d, clk, rst_n; output logic q; always_ff @(posedge clk, negedge rst_n) begin if (rst_n == 0) q <= 0; else q <= d; module

Synchronous reset: Flip Flops (3/3) module flipflop_syncr(d, q, clk, rst_n); input d, clk, rst_n; output logic q; always_ff @(posedge clk) begin if (rst_n == 0) q <= 0; else q <= d; module

Multi-Bit Flip Flop module flipflop_asyncr(d, q, clk, rst_n); input [15:0] d; input clk, rst_n; output logic [15:0] q; always_ff @(posedge clk, negedge rst_n) begin if (rst_n == 0) q <= 0; else q <= d; module

Parameters Parameters allow modules to be easily changed module my_flipflop(d, q, clk, rst_n); parameter WIDTH=16; input [WIDTH-1:0] d; input clk, rst_n; output logic [WIDTH-1:0] q;... module default value set to 16 Instantiate and set parameter: my_flipflop f0(d, q, clk, rst_n); uses default value my_flipflop #(12) f0(d, q, clk, rst_n); changes parameter to 12 for this instance

Non-Blocking Assignment a <= b; <= is the non-blocking assignment operator All left-hand side values take new values concurrently always_ff @(posedge clk) begin b <= a; c <= b; c gets the old value of b, not value assigned just above This models synchronous logic!

Non-Blocking vs. Blocking Use non-blocking assignment <= to describe edge-triggered (synchronous) assignments always_ff @(posedge clk) begin b <= a; c <= b; Use blocking assignment = to describe combinational assignment always_comb begin b = a; c = b;

Design Example Let s say we want to compute f = a + b*c b and c are 4 bits, a is 8 bits, and f is 9 bits First, we will build it as a combinational circuit Then, we will add registers at its inputs and outputs

Finite State Machines (1/2) State names Output values Transition values Reset state reset A/00 0 D/10 0 1 B/00 1 0 1 0 1 C/11

Finite State Machines (2/2) What does an FSM look like when implemented? Combinational logic and registers (things we already know how to do!)

Full FSM Example (1/2) module fsm(clk, rst, x, y); input clk, rst, x; output logic [1:0] y; enum { STATEA=2'b00, STATEB=2'b01, STATEC=2'b10, STATED=2'b11 } state, next_state; // next state logic always_comb begin case(state) STATEA: next_state = x? STATEB : STATEA; STATEB: next_state = x? STATEC : STATED; STATEC: next_state = x? STATED : STATEA; STATED: next_state = x? STATEC : STATEB; case //... continued on next slide

Full FSM Example (2/2) //... continued from previous slide // register always_ff @(posedge clk) begin if (rst) state <= STATEA; else state <= next_state; always_comb begin // Output logic case(state) STATEA: y = 2'b00; STATEB: y = 2'b00; STATEC: y = 2'b11; STATED: y = 2'b10; case module

Multi-Dimensional Arrays module multidimarraytest(); logic [2:0][3:0] myarray; assign myarray[0] = 4'b0010; assign myarray[1][3:2] = 2'b01; assign myarray[1][1] = 1'b1; assign myarray[1][0] = 1'b0; assign myarray[2][3:0] = 4'hC; initial begin $display("myarray == %b", myarray); $display("myarray[2:0] == %b", myarray[2:0]); $display("myarray[1:0] == %b", myarray[1:0]; $display("myarray[1] == %b", myarray[1]); $display("myarray[1][2] == %b", myarray[1][2]); module $display("myarray[2][1:0] == %b", myarray[2][1:0]);

Memory (Combinational read) module mymemory(clk, data_in, data_out, r_addr, w_addr, wr_en); parameter WIDTH=16, SIZE=256, LOGSIZE=8; input [WIDTH-1:0] data_in; output logic [WIDTH-1:0] data_out; input clk, wr_en; input [LOGSIZE-1:0] r_addr, w_addr; Combinational read logic [SIZE-1:0][WIDTH-1:0] mem; assign data_out = mem[r_addr]; always_ff @(posedge clk) begin mem <= mem; if (wr_en) mem[w_addr] <= data_in; module Default: memory does not change Synchronous write

Memory (Synchronous read) module mymemory2(clk, data_in, data_out, r_addr, w_addr, wr_en); parameter WIDTH=16, SIZE=256, LOGSIZE=8; input [WIDTH-1:0] data_in; output logic [WIDTH-1:0] data_out; input clk, wr_en; input [LOGSIZE-1:0] r_addr, w_addr; Synchronous read logic [SIZE-1:0][WIDTH-1:0] mem; always_ff @(posedge clk) begin data_out <= mem[r_addr]; mem <= mem; if (wr_en) mem[w_addr] <= data_in; module What happens if we try to read and write the same address?

Assertions Assertions are test constructs Automatically validated as design as simulated Written for properties that must always be true Makes it easier to test designs Don t have to manually check for these conditions

Example: A good place for assertions Imagine you have a FIFO queue When queue is full, it sets status_full to true When queue is empty, it sets status_empty to true data_in data_out wr_en FIFO status_full rd_en status_empty When status_full is true, wr_en must be false When status_empty is true, rd_en must be false

Immediate Assertions Checks an expression when statement is executed assertion_name: assert(expression) pass_code; else fail_code; Example: always @(posedge clk) begin assert((status_full == 0) (wr_en == 0)) else $error("tried to write to FIFO when full."); Use $display to print text, or $error to print an error message, or $fatal to print an error message and halt simulation