EECS 470 Lab 3. SystemVerilog Style Guide. Department of Electrical Engineering and Computer Science College of Engineering University of Michigan

Similar documents
EECS 470 Lab 2. Synopsys Build System. Department of Electrical Engineering and Computer Science College of Engineering University of Michigan

EECS 470 Lab 1. Verilog: Hardware Description Language

EECS 470 Lab 1. Verilog: Hardware Description Language

Quick Introduction to SystemVerilog: Sequental Logic

Lecture 32: SystemVerilog

Laboratory Exercise 3 Davide Rossi DEI University of Bologna AA

HDLs and SystemVerilog. Digital Computer Design

EECS 470 Lab 6. SystemVerilog. Department of Electrical Engineering and Computer Science College of Engineering. (University of Michigan)

FSM and Efficient Synthesizable FSM Design using Verilog

Problem Set 3 Solutions

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

EECS 470: Computer Architecture. Discussion #2 Friday, September 14, 2007

What, If Anything, In SystemVerilog Will Help Me With FPGA-based Design. Stuart Sutherland, Consultant and Trainer, Sutherland HDL, Inc.

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>

Testbenches for Sequential Circuits... also, Components

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 5 - Verilog Logic Synthesis

Last Lecture: Divide by 3 FSM

Digital Design with SystemVerilog

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

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

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

Verilog for Synthesis Ing. Pullini Antonio

University of California at Berkeley College of Engineering Department of Electrical Engineering and Computer Science

Digital Design and Computer Architecture

SystemVerilog 3.1: It s What The DAVEs In Your Company Asked For

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

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

EECS150 - Digital Design Lecture 4 - Verilog Introduction. Outline

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

In the previous lecture, we examined how to analyse a FSM using state table, state diagram and waveforms. In this lecture we will learn how to design

In the previous lecture, we examined how to analyse a FSM using state table, state diagram and waveforms. In this lecture we will learn how to design

CSE 502: Computer Architecture

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Announcements. Midterm 2 next Thursday, 6-7:30pm, 277 Cory Review session on Tuesday, 6-7:30pm, 277 Cory Homework 8 due next Tuesday Labs: project

Bulletproofing FSM Verification Automated Approach to Detect Corner Case Issues in an FSM Design

271/469 Verilog Tutorial

TSEA44: Computer hardware a system on a chip

Verilog: The Next Generation Accellera s SystemVerilog Standard

Lab 1.5 (Warmup): Synthesis Workflow and SystemVerilog Register File Not Due

ECE 353 Lab 3 (Verilog Design Approach)

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

EECS 270 Verilog Reference: Sequential Logic

Homework deadline extended to next friday

Finite State Machines

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

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

Designing Safe Verilog State Machines with Synplify

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

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

EECS150 - Digital Design Lecture 10 Logic Synthesis

Abstraction. Levels of abstraction in a computer system

Control in Digital Systems

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

ARM 64-bit Register File

EECS150 - Digital Design Lecture 6 - Logic Simulation

Modeling of Finite State Machines. Debdeep Mukhopadhyay

ECE 551: Digital System *

Abstraction. ENGR Michael S. McCorquodale, Peter M. Chen

Finite State Machines

EECS 470 Lab 4. Version Control System. Friday, 31 st January, 2014

Introduction to Verilog/System Verilog

Software Design and Analysis for Engineers

EECS150 - Digital Design Lecture 10 Logic Synthesis

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

System Verilog Tagged Unions and Pattern Matching

EECS 470 Lab 5. Linux Shell Scripting. Friday, 1 st February, 2018

b) Register renaming c) CDB, register file, and ROB d) 0,1,X (output of a gate is never Z)

Digital design laboratory 5

Register Transfer Level

CS 211 Programming Practicum Fall 2018

CSE140L: Components and Design

SystemVerilog Design: User Experience Defines Multi-Tool, Multi-Vendor Language Working Set Experience from Four Years of SVD Adoption

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

ECEU530. Schedule. ECE U530 Digital Hardware Synthesis. Datapath for the Calculator (HW 5) HW 5 Datapath Entity

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

Verilog Synthesis and FSMs. UCB EECS150 Fall 2010 Lab Lecture #3

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

Today. Implementation of FSMs. Designing Digital System (1) Designing Digital System (2)

Laboratory Exercise 7

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

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

HDL. Hardware Description Languages extensively used for:

Spiral 1 / Unit 4 Verilog HDL. Digital Circuit Design Steps. Digital Circuit Design OVERVIEW. Mark Redekopp. Description. Verification.

ECEN 468 Advanced Logic Design

Verilog Coding Guideline

CSE140L: Components and Design Techniques for Digital Systems Lab

Since this register file will mimic the MIPS architecture, address zero will always return the value zero regardless of attempts to write to it.

EECS150 - Digital Design Lecture 20 - Finite State Machines Revisited

Verilog Execution Semantics

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

Logic Synthesis. EECS150 - Digital Design Lecture 6 - Synthesis

MCMASTER UNIVERSITY EMBEDDED SYSTEMS

Advanced Synthesis Techniques

Synthesizable Verilog

Memory Controller. System Integration Issues. Encoding numbers 1GB RAM FSM. Communicating FSMs Clocking, theory and practice. Combinational Logic

Writing Circuit Descriptions 8

Computer Organization EE 3755 Midterm Examination

378 Lab Survival Guide Lab tips, Verilog tricks, and other useful info

Transcription:

EECS 470 Lab 3 SystemVerilog Style Guide Department of Electrical Engineering and Computer Science College of Engineering University of Michigan Thursday, 18 th January 2018 (University of Michigan) Lab 3: Style Thursday, 18 th January 2018 1 / 36

Overview Administrivia Verilog Style Guide Brevity Indentation and Alignment SystemVerilog Features Finite State Machines Project 2 (University of Michigan) Lab 3: Style Thursday, 18 th January 2018 2 / 36

Administrivia Administrivia Homework Homework 2 is due Wednesday, 30 th January at 9:00PM (via Gradescope) Projects Project 2 is due Tuesday, 23 rd September at 11:59PM (via submission script) Help We are available to answer questions on anything here. Office hours can be found on the course web site. (University of Michigan) Lab 3: Style Thursday, 18 th January 2018 3 / 36

Verilog Style What is good style? Easy to read Easy to understand Mostly a matter of personal preference Why should I use good style? Easier to debug Important for group work Mandatory in projects 1-3 (University of Michigan) Lab 3: Style Thursday, 18 th January 2018 4 / 36

Verilog Style Rules Goal: Clarity For any problem, one solution is the clearest We want to approximate this solution By creating a set of rules to follow Format We ll look at a bad example Then how to fix it Derive a rule (University of Michigan) Lab 3: Style Thursday, 18 th January 2018 5 / 36

Brevity Brevity by Example Example always_comb if (foo[3] == 1'b1) bar[3] = 1'b1; bar[2] = 1'b0; bar[1] = 1'b1; bar[0] = 1'b1; else if (foo[2] == 1'b1) bar[3] = 1'b0; bar[2] = 1'b1; bar[1] = 1'b0; bar[0] = 1'b0; (University of Michigan) Lab 3: Style Thursday, 18 th January 2018 6 / 36

Brevity Brevity by Example Example always_comb if (foo[3] == 1'b1) bar[3] = 1'b1; bar[2] = 1'b0; bar[1] = 1'b1; bar[0] = 1'b1; else if (foo[2] == 1'b1) bar[3] = 1'b0; bar[2] = 1'b1; bar[1] = 1'b0; bar[0] = 1'b0; vs. Example Reformatted always_comb if (foo[3]) bar = 4'b1011; else if (foo[2]) bar = 4'b0100; (University of Michigan) Lab 3: Style Thursday, 18 th January 2018 6 / 36

Brevity Brevity by Example Example logic [5:0] shift; always_ff @(posedge clock) if (reset) shif_reg <= #1 6'b0; else shift[0] <= #1 foo; shift[1] <= #1 shift[0]; shift[2] <= #1 shift[1]; shift[3] <= #1 shift[2]; shift[4] <= #1 shift[3]; shift[5] <= #1 shift[4]; (University of Michigan) Lab 3: Style Thursday, 18 th January 2018 7 / 36

Brevity Brevity by Example Example logic [5:0] shift; always_ff @(posedge clock) if (reset) shif_reg <= #1 6'b0; else shift[0] <= #1 foo; shift[1] <= #1 shift[0]; shift[2] <= #1 shift[1]; shift[3] <= #1 shift[2]; shift[4] <= #1 shift[3]; shift[5] <= #1 shift[4]; vs. Example Reformatted logic [5:0] shift; always_ff @(posedge clock) if (reset) shift <= #1 6'b0; else shift <= #1 {shift[4:0], foo}; (University of Michigan) Lab 3: Style Thursday, 18 th January 2018 7 / 36

Brevity Brevity Rule Rule Brevity is strongly correlated with the optimal solution. Be brief, where you can. (University of Michigan) Lab 3: Style Thursday, 18 th January 2018 8 / 36

Brevity General Requirements Clarity Rules Use meaningful names for signal; wire wire; is confusing Comment your designs; (a ^ b ~^ c) (&d) is unintelligible without an explanation Conceptualize what you need to build before you start writing Verilog. A state machine diagram will be make the Verilog much easier... (University of Michigan) Lab 3: Style Thursday, 18 th January 2018 9 / 36

Indentation and Alignment Indentation Why are we interested in indentation? Readability easier to trace down Clarity easier to check what is in a given scope (University of Michigan) Lab 3: Style Thursday, 18 th January 2018 10 / 36

Indentation and Alignment Indentation by Example Example always_comb if(cond) n_state = `IDLE; n_gnt = `NONE; else n_state = `TO_A; n_gnt = `GNT_A; (University of Michigan) Lab 3: Style Thursday, 18 th January 2018 11 / 36

Indentation and Alignment Indentation by Example Example always_comb if(cond) n_state = `IDLE; n_gnt = `NONE; else n_state = `TO_A; n_gnt = `GNT_A; vs. Example Reformatted always_comb if (cond) n_state = `IDLE; n_gnt = `NONE; else n_state = `TO_A; n_gnt = `GNT_A; (University of Michigan) Lab 3: Style Thursday, 18 th January 2018 11 / 36

Indentation and Alignment Indentation Rule Rule Items within the same scope should have the same indentation. (University of Michigan) Lab 3: Style Thursday, 18 th January 2018 12 / 36

Indentation and Alignment Alignment Why are we interested in alignment? Readability easier to trace down Clarity easier to check that everything is assigned (University of Michigan) Lab 3: Style Thursday, 18 th January 2018 13 / 36

Indentation and Alignment Alignment by Example Example always_comb if (cond) n_state = `IDLE; n_gnt = `NONE; else n_state = `TO_A; n_gnt = `GNT_A; (University of Michigan) Lab 3: Style Thursday, 18 th January 2018 14 / 36

Indentation and Alignment Alignment by Example Example always_comb if (cond) n_state = `IDLE; n_gnt = `NONE; else n_state = `TO_A; n_gnt = `GNT_A; vs. Example Reformatted always_comb if (cond) n_state = `IDLE; n_gnt = `NONE; else n_state = `TO_A; n_gnt = `GNT_A; (University of Michigan) Lab 3: Style Thursday, 18 th January 2018 14 / 36

Indentation and Alignment Alignment by Example Example assign mux_out = (cond1)? (foo1&bar): (cond2)? (foo2+cnt3) : (cond3)? (foo3&~bar2) : 0; (University of Michigan) Lab 3: Style Thursday, 18 th January 2018 15 / 36

Indentation and Alignment Alignment by Example Example assign mux_out = (cond1)? (foo1&bar): (cond2)? (foo2+cnt3) : (cond3)? (foo3&~bar2) : 0; Example Reformatted assign mux_out = (cond1)? (foo1 & bar) : (cond2)? (foo2 + cnt3) : (cond3)? (foo3 & ~bar2) : 0; (University of Michigan) Lab 3: Style Thursday, 18 th January 2018 15 / 36

Indentation and Alignment Alignment Rule Rule Assignments should be aligned by column. Ternary statements should have the conditionals aligned, and each if should be on a new line. (University of Michigan) Lab 3: Style Thursday, 18 th January 2018 16 / 36

SystemVerilog Features SystemVerilog Types User-defined Types Useful for cleaning repeated declarations, specifically bundling connections Types can be named informatively, e.g. arch reg t (University of Michigan) Lab 3: Style Thursday, 18 th January 2018 17 / 36

SystemVerilog Features Structs About struct A package of signals (wire or logic) Basically follow C conventions List of signal declarations Named with t ing Syntax struct List of signals between braces ({}) Name after braces, followed by a semicolon (;) (University of Michigan) Lab 3: Style Thursday, 18 th January 2018 18 / 36

SystemVerilog Features Structs Example typedef struct { logic [7:0] a; //Structs can contain logic b; //other structs, like arch_reg_t c; //<-- this line } example_t; //named with _t Example typedef struct packed { addr_t pc; logic valid; } prf_entry_t; Usage Example prf_entry_t [31:0] prf; assign prf[1].valid = 1'b0; (University of Michigan) Lab 3: Style Thursday, 18 th January 2018 19 / 36

SystemVerilog Features Enums About enum List of possible values, but named instead of numbered Good for state machine states Can be shown in DVE instead of the associated value Syntax enum List of values between braces ({}) Name after braces, followed by a semicolor (;) (University of Michigan) Lab 3: Style Thursday, 18 th January 2018 20 / 36

SystemVerilog Features Enums Example Example Usage Example typedef enum logic [3:0] { IDLE, //=0, by default GNT[0:7], //Expands to GNT0=1,...GNT7=8 RESET //=9 } arb_state; typedef enum logic [1:0] { ADD = 2'b00, //The value associated with MULT = 2'b10, //a particular name can be NOT = 2'b11, //assigned explicitly. AND = 2'b01 } opcode; arb_state state, n_state; assign n_state = IDLE; (University of Michigan) Lab 3: Style Thursday, 18 th January 2018 21 / 36

SystemVerilog Features Enums DVE Example (University of Michigan) Lab 3: Style Thursday, 18 th January 2018 22 / 36

SystemVerilog Features Typedef About typedef Necessary for reuse of a struct or enum Without a typedef, a struct/enum must be redefined at each instance declaration Also useful in clearly naming commonly sized buses Syntax typedef by any signal declaration or struct or enum declaration Name for the type followed by a semicolon (;) (University of Michigan) Lab 3: Style Thursday, 18 th January 2018 23 / 36

SystemVerilog Features Typedef by Example Example: Typedef d Enum //typedef, then definition, then name; typedef enum logic [3:0] { IDLE, GNT[0:7], RESET } arb_state; Example: Type Synonym //typedef, then definition, then name; typedef logic [63:0] addr; (University of Michigan) Lab 3: Style Thursday, 18 th January 2018 24 / 36

Finite State Machines Procedural FSM Design FSM Process All states should be typedef enum All next state logic should go into a combinational block, following all combinational rules All resets should be synchronous (to the clock) All output assignments should go in their own combinational block The only logic in the sequential block should be the state assignment (to the computed next state) (University of Michigan) Lab 3: Style Thursday, 18 th January 2018 25 / 36

Finite State Machines Finite State Machine Skeleton typedef enum logic [(NUM_STATES-1):0] { STATES } fsm_state; module fsm( input wire inputs, output logic outputs ); fsm_state state, next_state; always_comb /* Transitions from a diagram go here */ /* next state = f (inputs, state) */ always_ff @(posedge clock) if(reset) state <= #1 DEFAULT; else state <= #1 next_state; module (University of Michigan) Lab 3: Style Thursday, 18 th January 2018 26 / 36

Finite State Machines Finite State Machine Example typedef enum logic { LOCKED, UNLOCKED } ts_state; module turnstile( input wire coin, push, input wire clock, reset, output ts_state state ); ts_state next_state; always_comb next_state=state; if (state==locked && coin) next_state = UNLOCKED; if (state==unlocked && push) next_state = LOCKED; always_ff @(posedge clock) if (reset) state <= #1 LOCKED; module else state <= #1 next_state; (University of Michigan) Lab 3: Style Thursday, 18 th January 2018 27 / 36

Project 2 Project 2 Overview Part 1: Pipelined Multiplier Change the pipeline depth Synthesize at each size Part 2: Integer Square Root Finite state machine implementation Synthesis (University of Michigan) Lab 3: Style Thursday, 18 th January 2018 28 / 36

Project 2 Pipelined Multiplication Partial Products Multiply the first n bits of the two components Multiply the next n bits, etc. Sum the partial products to get the answer (University of Michigan) Lab 3: Style Thursday, 18 th January 2018 29 / 36

Project 2 Pipelined Multiplication by Example Binary Multiplication 0 0 0 1 1 1 0 1 0 1 0 0 0 1 1 1 0 0 0 0 0 0 0 1 1 1 0 0 + 0 0 0 0 0 0 1 0 0 0 1 1 Decimal Multiplication 7 5 3 5 (University of Michigan) Lab 3: Style Thursday, 18 th January 2018 30 / 36

Project 2 Pipelined Multiplication by Example Example: 4-stage Pipelined Multiplication multiplicand: 00001011 multiplier: 00000111 partial product: 00000000 0 0 0 0 1 0 1 1 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 (University of Michigan) Lab 3: Style Thursday, 18 th January 2018 31 / 36

Project 2 Pipelined Multiplication by Example Example: 4-stage Pipelined Multiplication multiplicand: 00001011 << 2 multiplier: 00000111 >> 2 partial product: 00100001 0 0 0 0 1 0 1 1 0 0 0 0 0 0 1 1 0 0 1 0 0 0 0 1 (University of Michigan) Lab 3: Style Thursday, 18 th January 2018 31 / 36

Project 2 Pipelined Multiplication by Example Example: 4-stage Pipelined Multiplication multiplicand: 00101100 multiplier: 00000001 partial product: 00100001 0 0 1 0 1 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 (University of Michigan) Lab 3: Style Thursday, 18 th January 2018 31 / 36

Project 2 Pipelined Multiplication by Example Example: 4-stage Pipelined Multiplication multiplicand: 00101100 << 2 multiplier: 00000001 >> 2 partial product: 01001101 0 0 1 0 1 1 0 0 0 0 0 0 0 0 0 1 0 0 1 0 1 1 0 0 (University of Michigan) Lab 3: Style Thursday, 18 th January 2018 31 / 36

Project 2 Part 1 Hints Pipeline Depth Figure out the sizes of all the structures as a function of pipeline depth This would be an optimal place to use `define Synthesis Clock Periods (T clk ) Optimize inner module (mult stage.v) first, then outer (mult.v) Understand set dont touch Synthesis is time consuming; 10 minutes for both mult stage and mult (University of Michigan) Lab 3: Style Thursday, 18 th January 2018 32 / 36

Project 2 Part 2 Hints ISR Algorithm Guess-and-check Loop from the top bit of the guess to the bottom Basically binary search for a solution Hardware Implementation How do we implement this in hardware? (University of Michigan) Lab 3: Style Thursday, 18 th January 2018 33 / 36

Project 2 Part 2 Hints ISR State Machine Computing: value On a reset guess initialized to 32 h8000 0000 value is clocked into a register guess gets the next bit set each time we cycle through the FSM again Square guess (multiply it with itself) Wait until the multiplier raises its done if guess <= value else Keep the current bit Clear the current bit Move to the next bit After the last bit, raise done (University of Michigan) Lab 3: Style Thursday, 18 th January 2018 34 / 36

Project 2 Part 2 Hints Reminders Remember to declare bitwidths for signals, e.g. 64 hffff FFFF FFFF FFFF It must take less than 600 cycles to compute a square root Remember to use the 8-stage multiplier for this Remember to check for proper reset behavior Remember the reset pragma (//synopsys sync set reset reset ) (University of Michigan) Lab 3: Style Thursday, 18 th January 2018 35 / 36

Project 2 Lab Assignment Assignment is posted to the course website as Lab 3 Assignment. If you get stuck... Ask a neighbor, quietly Put yourself in the help queue When you are finished, put yourself on help queue to get checked off. If you are unable to finish today, the assignment needs to be checked off by next Wednesday. (University of Michigan) Lab 3: Style Thursday, 18 th January 2018 36 / 36