ECE 4750 Computer Architecture, Fall 2016 Tutorial 4 .

2y ago
31 Views
2 Downloads
570.15 KB
50 Pages
Last View : 30d ago
Last Download : 3m ago
Upload by : Bria Koontz
Transcription

ECE 4750 Computer Architecture, Fall 2016Tutorial 4: Verilog Hardware Description LanguageSchool of Electrical and Computer EngineeringCornell Universityrevision: 2016-11-05-14-201Introduction32Verilog Modeling: Synthesizable vs. Non-Synthesizable RTL43Verilog Basics: Data Types, Operators, and Conditionals43.1Hello World . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .43.2Logic Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .53.3Shift Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .103.4Arithmetic Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .113.5Relational Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .123.6Concatenation Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .143.7Enum Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .153.8Struct Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .173.9Ternary Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .193.10 If Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .203.11 Case Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .213.12 Casez Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .22Registered Incrementer224.1RTL Model of Registered Incrementer . . . . . . . . . . . . . . . . . . . . . . . . . . . .234.2Simulating a Model using iverilog . . . . . . . . . . . . . . . . . . . . . . . . . . . . .254.3Verifying a Model with Unit Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . .274.4Reusing a Model with Structural Composition . . . . . . . . . . . . . . . . . . . . . . .294.5Parameterizing a Model with Static Elaboration . . . . . . . . . . . . . . . . . . . . . .3145Sort Unit335.1Flat Sorter Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .335.2Using Verilog Line Traces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .375.3Structural Sorter Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .385.4Evaluating the Sorter Using a Simulator . . . . . . . . . . . . . . . . . . . . . . . . . . .401

ECE 4750 Computer Architecture, Fall 201667Tutorial 4: Verilog Hardware Description LanguageGreatest Common Divisor: Verilog Design Example406.1Control/Datapath Split Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . .416.2Evaluating GCD Unit using a Simulator . . . . . . . . . . . . . . . . . . . . . . . . . . .46TravisCI for Continuous Integration472

ECE 4750 Computer Architecture, Fall 2016Tutorial 4: Verilog Hardware Description Language1. IntroductionIn the lab assignments for this course, we will be using the PyMTL hardware modeling frameworkfor functional-level modeling, verification, and simulator harnesses. Students can choose to useeither PyMTL or Verilog to do their register-transfer-level (RTL) qmodeling. If you are planning touse PyMTL, then you do not need to complete this tutorial. If you are planning to use Verilog, youshould still complete the PyMTL tutorial since we will always be using PyMTL for some aspects ofthe lab assignment.This tutorial briefly reviews the basics of the Verilog hardware description language, but primarily focuses on how we can integrate Verilog RTL modeling into our PyMTL framework. Althoughwe will be using the open-source tool Icarus Verilog (iverilog) for compiling some simple Verilogmodels into simulators, we will primarily be using the open-source tool Verilator (verilator) as ourVerilog simulator. PyMTL has built-in support for testing Verilog simulators created using Verilator.As in the PyMTL tutorial, we will also be using GTKWave (gtkwave) for viewing waveforms. Alltools are installed and available on ecelinux. This tutorial assumes that students have completedthe Linux and Git tutorials.To follow along with the tutorial, access the ECE computing resources, and type the commandswithout the % character. In addition to working through the commands in the tutorial, you shouldalso try the more open-ended tasks marked with the H symbol.Before you begin, make sure that you have sourced the ece4750-setup script or that you have addedit to your .bashrc script, which will then source the script every time you login. Sourcing the setupscript sets up the environment required for this class.You should start by forking the tutorial repository on GitHub. Start by going to the GitHub page forthe tutorial repository located here: rilogClick on Fork in the upper right-hand corner. If asked where to fork this repository, choose yourpersonal GitHub account. After a few seconds, you should have a new repository in your account: https://github.com/ githubid /ece4750-tut4-verilogWhere githubid is your GitHub ID, not your NetID. Now access ecelinux and clone your copyof the tutorial repository as follows:%%%%%%source setup-ece4750.shmkdir -p {HOME}/ece4750cd {HOME}/ece4750git clone https://github.com/ githubid /ece4750-tut4-verilog.git tut4cd tut4/simTUTROOT {PWD}NOTE: It should be possible to experiment with this tutorial even if you are not enrolledin the course and/or do not have access to the course computing resources. All of thecode for the tutorial is located on GitHub. You will not use the setup-ece4750.sh script,and your specific environment may be different from what is assumed in this tutorial.3

ECE 4750 Computer Architecture, Fall 2016Tutorial 4: Verilog Hardware Description Language2. Verilog Modeling: Synthesizable vs. Non-Synthesizable RTLVerilog is a powerful language that was originally intended for building simulators of hardware asopposed to models that could automatically be transformed into hardware (e.g., synthesized to anFPGA or ASIC). Given this, it is very easy to write Verilog code that does not actually model any kindof realistic hardware. Indeed, we actually need this feature to be able to write clean and productiveassertions and line tracing. Non-synthesizable Verilog modeling is also critical when implementingtest harnesses. So students must be very diligent in actively deciding whether or not they arewriting synthesizable register-transfer-level models or non-synthesizable code. Students mustalways keep in mind what hardware they are modeling and how they are modeling it!Students’ design work will almost exclusively use synthesizable register-transfer-level (RTL) models.It is acceptable to include a limited amount of non-synthesizable code in students’ designs for thesole purpose of debugging, assertions, or line tracing. If the student includes non-synthesizable codein their actual design (i.e., not the test harness), they must explicitly demarcate this code by wrappingit in ‘ifndef SYNTHESIS and ‘endif. This explicitly documents the code as non-synthesizable andaids automated tools in removing this code before synthesizing the design. If at any time studentsare unclear about whether a specific construct is allowed in a synthesizable concurrent block, theyshould ask the instructors.Appendix A includes a table that outlines which Verilog constructs are allowed in synthesizableRTL, which constructs are allowed in synthesizable RTL with limitations, and which constructs areexplicitly not allowed in synthesizable RTL. There are no limits on using the Verilog preprocessor,since the preprocessing step happens at compile time.3. Verilog Basics: Data Types, Operators, and ConditionalsWe will begin by writing some very basic code to explore Verilog data types, operators, and conditionals. We will not be modeling actual hardware yet; we are just experimenting with the language.Start by creating a build directory to work in.% mkdir {TUTROOT}/build% cd {TUTROOT}/build3.1. Hello WorldCreate a new Verilog source file named hello-world.v with the contents shown in Figure 1 usingyour favorite text editor. A module is the fundamental hardware building block in Verilog, but fornow we are simply using it to encapsulate an initial block. The initial block specifies code whichshould be executed “at the beginning of time” when the simulator starts. Since real hardware cannotdo anything “at the beginning of time” initial blocks are not synthesizable and you should not12345module top;initial begin display( "Hello World!" );endendmoduleCode at -hello-world.vFigure 1: Verilog Basics: Display Statement – The obligatory “Hello, World!” program to compilinga basic Verilog program.4

ECE 4750 Computer Architecture, Fall 2016Tutorial 4: Verilog Hardware Description Languageuse them in the synthesizable portion of your designs. However, initial blocks can be useful fortest harnesses and when experimenting with the Verilog language. The initial block in Figure 1contains a single call to the display system task which will output the given string to the console.We will be using iverilog to compile Verilog models into simulators in the beginning of this tutorial before we turn our attention to using Verilator. You can run iverilog as follows to compilehello-world.v.% cd {TUTROOT}/build% iverilog -g2012 -o hello-world hello-world.vThe -g2012 option tells iverilog to accept newer SystemVerilog syntax, and the -o specifies thename of the simulator that iverilog will create. You can run this simulator as follows.% cd {TUTROOT}/build% ./hello-worldAs discussed in the Linux tutorial you can compile the Verilog and run the simulator in a single step.% cd {TUTROOT}/build% iverilog -g2012 -o hello-world hello-world.v && ./hello-worldThis makes it easy to edit the Verilog source file, quickly recompile, and test your changes by switching to your terminal, pressing the up-arrow key, and then pressing enter.HTo-Do On Your Own: Edit the string that is displayed in this simple program, recompile, and rerunthe simulator.3.2. Logic Data TypesTo understand any new modeling language we usually start by exploring the primitive data typesfor representing values in a model. Verilog uses a combination of the wire and reg keywords whichinteract in subtle and confusing ways. SystemVerilog has simplified modeling by introducing thelogic data type. We will be exclusively using logic as the general-purpose, hardware-centric datatype for modeling a single bit or multiple bits. Each bit can take on one of four values: 0, 1, X, Z.X is used to represent unknown values (e.g., the state of a register on reset). Z is used to representhigh-impedance values. Although we will use variables with X values in this course, we will not usevariables with Z values (although you may see Z values if you forget to connect an input port of amodule).Table 1 shows the operators that we will be primarily using in this course. Note that Verilog andSystemVerilog support additional operators including * for multiplication, / for division, % for modulus, ** for exponent, and /! for special equality checks. There may occasionally be reasonsto use one of these operators in your assertion or line tracing logic. However, these operators areeither not synthesizable or synthesize poorly, so students are not allowed to use these operators inthe synthesizable portion of their designs.Figure 2 shows an example program that illustrates single-bit logic types. Create a new Verilogsource file named logic-sbit.v and copy some or all of this code. Compile this source file and runthe resulting simulator.5

ECE 4750 Computer Architecture, Fall 2016Logical Operators& bitwise ANDbitwise ORbitwise XORbitwise XNORbitwise NOT&& !boolean ANDboolean ORboolean NOTArithmetic Operators -additionsubtractionTutorial 4: Verilog Hardware Description LanguageReduction Operators& & reduce via ANDreduce via NANDreduce via ORreduce via NORreduce via XORreduce via XNORShift Operators shift rightshift leftarithmetic shift rightRelational Operators ! equalnot equalgreater thangreater than or equalsless thanless than or equalsOther Operators{}concatenate{N{}} replicate N timesTable 1: Table of Verilog Operators – Not all Verilog operators are shown, just those operators thatare acceptable for use in the synthesizable RTL portion of students’ designs.Lines 13–16 illustrate how to write single-bit literals to express constant values. Lines 23–26 illustratebasic bitwise logical operators (&, , ˆ, ). Whenever we consider an expression in Verilog, we shouldalways ask ourselves, “What will happen if one of the inputs is an X?” Lines 33–36 illustrate whathappens if the second operand is an X for bitwise logical operators. Recall that X means “unknown”.If we OR the value 0 with an unknown value we cannot know the result. If the unknown value is0, then the result should be 0, but if the unknown value is 1, then the result should be 1. So Verilogspecifies that in this case the value of the expression is X. Notice what happens if we AND the value0 with an unknown value. In this case, we can guarantee that for any value for the second operandthe result will always be 0, so Verilog specifies the value of the expression is 0.In addition to the basic bitwise logical operators, Verilog also defines three boolean logical operators(&&, , !). These operators are effectively the same as the basic logical operators (&, , ) whenoperating on single-bit logic values. The difference is really in the designer’s intent. Using &&, , !suggests that the designer is implementing a boolean logic expression as opposed to doing low-levelbit manipulation.HTo-Do On Your Own: Experiment with more complicated multi-stage logic expressions by writingthe boolean logic equations for a one-bit full-adder. Use the display system task to output theresult to the console. Experiment with using X input values as inputs to these logic expressions.6

ECE 4750 Computer Architecture, Fall 20161Tutorial 4: Verilog Hardware Description Languagemodule top;23// Declare single-bit logic variables.4567logic a;logic b;logic c;89initial begin1011// Single-bit literals1213141516aaaa 1'b0;1'b1;1'bx;1'bz; display( display( display( display("1'b0"1'b1"1'bx"1'bz %x%x%x%x",",",",aaaa););););1718// Bitwise logical operators for doing AND, OR, XOR, and NOT192021a 1'b0;b 1'b1;2223242526cccc a & b;a b;a b; b; display( display( display( display("0 & 1"0 1"0 1" 1 %x%x%x%x",",",",cccc););););2728// Bitwise logical operators for doing AND, OR, XOR, and NOT with X293031a 1'b0;b 1'bx;3233343536cccc a & b;a b;a b; b; display( display( display( display("0 & x"0 x"0 x" x %x%x%x%x",",",",cccc););););3738// Boolean logical operators394041a 1'b0;b 1'b1;42434445c a && b;c a b;c !b; display( "0 && 1 %x ", c ); display( "0 1 %x ", c ); display( "!1 %x ", c );4647end4849endmoduleCode at -logic-sbit.vFigure 2: Verilog Basics: Single-Bit Logic and Logical Operators – Experimenting with single-bitlogic variables and literals, logical bitwise operators, and logical boolean operators.7

ECE 4750 Computer Architecture, Fall 2016Tutorial 4: Verilog Hardware Description LanguageMulti-bit logic types are used for modeling bit vectors. Figure 3 shows an example program thatillustrates multi-bit logic types. Create a new Verilog source file named logic-mbit.v and copysome or all of this code. Compile this source file and run the resulting simulator.Lines 5–8 declares multi-bit logic variables. The square brackets contain the index of the mostsignificant and the least-significant bit. In this course, you should always use zero as the indexof the least significant bit. Note that to declare a four-bit logic value, we use [3:0] not [4:0].Lines 14–17 illustrate multi-bit literals that can be used to declare constant values. These literals havethe following general syntax: bitwidth ’ base number where base can be b for binary, h forhexadecimal, or d for decimal. It is legal to include underscores in the literal, which can be helpfulfor improving the readability of long literals.Lines 24–28 illustrate multi-bit versions of the basic bitwise logic operators. As before, we shouldalways ask ourselves, “What will happen if one of the inputs is an X?” Lines 35–39 illustrate whathappens if two bits in the second value are Xs. Note that some bits in the result are X and some canbe guaranteed to be either a 0 or 1.Lines 45–50 illustrate the reduction operators. These operators take a multi-bit logic value and combine all of the bits into a single-bit value. For example, the OR reduction operator ( ) will OR all ofthe bits together.HTo-Do On Your Own: We will use relational operators (e.g., ) to compare two multi-bit logicvalues, but see if you can achieve the same effect with the bitwise XOR/XNOR operators andOR/NOR reduction operators.8

ECE 4750 Computer Architecture, Fall 20161Tutorial 4: Verilog Hardware Description Languagemodule top;23// Declare multi-bit logic variables45678logiclogiclogiclogic[ 3:0][ 3:0][ 10initial begin1112// Multi-bit literals1314151617ADDD 4'b0101;12'b1100 1010 0101;12'hca5;12'd1058; display( display( display( display("4'b0101"12'b1100 1010 0101"12'hca5"12'd1058 %x",%x",%x",%x",ADDD););););1819// Bitwise logical operators for doing AND, OR, XOR, and NOT202122A 4'b0101;B 4'b0011;232425262728CCCCC A & B;A B;A B;A B; B; display( display( display( display( display("4'b0101 &"4'b0101 "4'b0101 "4'b0101 " 4'b00114'b0011 %b", C );4'b0011 %b", C );4'b0011 %b", C );4'b0011 %b", C ); %b", C );2930// Bitwise logical operators when some bits are X313233A 4'b0101;B 4'b00xx;343536373839CCCCC A & B;A B;A B;A B; B; display( display( display( display( display("4'b0101 &"4'b0101 "4'b0101 "4'b0101 " 4'b00xx4'b00xx4'b00xx4'b00xx4'b00xx" &" &" " " " %b",%b",%b",%b",%b",CCCCC);););););4041// Reduction operators4243A 4'b0101;44454647484950CCCCCC &A; &A; A; A; A; A; display( display( display( display( display( 354endmoduleCode at -logic-mbit.vFigure 3: Verilog Basics: Multi-Bit Logic and Logical Operators – Experimenting with multi-bitlogic variables and literals, bitwise logical operators, and reduction operators.9

ECE 4750 Computer Architecture, Fall 2016Tutorial 4: Verilog Hardware Description Language3.3. Shift OperatorsFigure 4 illustrates three shift operators on multi-bit logic values. Create a new Verilog source filenamed logic-shift.v and copy some or all of this code. Compile this source file and run the resulting simulator.Notice how the logical shift operators ( , ) always shift in zeros, but the arithmetic right shiftoperator ( ) replicates the most-significant bit. Verilog requires that the left-hand operand to thearithmetic shift operator be explicitly denoted as signed, which we have done using the signedsystem task. We recommend this approach and avoiding the use of signed data types.To-Do On Your Own: Experiment different multi-bit logic values and shift amounts.H1module top;2345logic [7:0] A;logic [7:0] B;logic [7:0] C;67initial begin89// Fixed shift amount for logical shifts1011A 8'b1110 0101;12131415C A 1;C A 2;C A 3; display( "8'b1110 0101 1 %b", C ); display( "8'b1110 0101 2 %b", C ); display( "8'b1110 0101 3 %b", C );C A 1;C A 2;C A 3; display( "8'b1110 0101 1 %b", C ); display( "8'b1110 0101 2 %b", C ); display( "8'b1110 0101 3 %b", C );161718192021// Fixed s

ECE 4750 Computer Architecture, Fall 2016 Tutorial 4: Verilog Hardware Description Language School of Electrical and Computer Engineering Cornell University revision: 2016-11-05-14-20 1 Introduction 3 2 Verilog Modeling: Synthesizable vs. Non-Synthesizable RTL 4 3

Related Documents:

ECE 4750 Computer Architecture, Fall 2016 Tutorial 3: PyMTL Hardware Modeling Framework % cd tut3/sim % TUTROOT {PWD} NOTE: It should be possible to experiment with this tutorial even if you are not enrolled in the course and

ECE 4750 Computer Architecture, Fall 2016 Tutorial 2: Git Distributed Version Control System 1.Introduction In this course, we will be using Git as our revision control and source code management system. We will be using GitHub for centralized online repository hosting

Electrical & Computer Engineering Student Affairs Office ece.ucsd.edu . ECE 174. ECE 175A: ECE 175B* Year 4: ECE 171B* ECE 172A* DESIGN. PROF. ELECTIVE: PROF. ELECTIVE. TECH. ELECTIVE: TECH. ELECTIVE. MACHINE LEARNING & CONTROLS DEPTH *Pick one of ECE 171B, 172A or 175B to complete the 4th Depth course requirement.

ECE 429: Audio Electronics ECE 461: Introduction to VLSI ECE 466: RF and Microwave Integrated Circuits ECE 468: Advanced Analog CMOS Circuits and Systems ECE 469: High Speed Integrated Electronics . Computer Design and Computer Engineering Concentration Requirements . ECE 401: Advanced Computer Architecture Two of the following .

What is Computer Architecture? “Computer Architecture is the science and art of selecting and interconnecting hardware components to create computers that meet functional, performance and cost goals.” - WWW Computer Architecture Page An analogy to architecture of File Size: 1MBPage Count: 12Explore further(PDF) Lecture Notes on Computer Architecturewww.researchgate.netComputer Architecture - an overview ScienceDirect Topicswww.sciencedirect.comWhat is Computer Architecture? - Definition from Techopediawww.techopedia.com1. An Introduction to Computer Architecture - Designing .www.oreilly.comWhat is Computer Architecture? - University of Washingtoncourses.cs.washington.eduRecommended to you b

engine rpm chart johnson rpm . 100 hp 1989 thru 4750-5250 2.07 115 hp 1989-2005 4750-5250 2.07 125 hp 1994-2005 4750-5250 2.07 135 hp 1990-1996 5000-5600 2.00 150 hp efi 2004 5000-6000 1.87 150 hp efi 2005 5000-5600 1.87 175 hp 1990-1999 5000-5600 1.87 175 hp efi 2000-2002 5000-5600 1.87 200 hp 1991-2005 5000-5600 1.87 200 hp efi 1994-2002 5000-5800 1.87 225 hp 1996-1998 5000-5500 1.64 .

ECE 792E (Advanced Power Electronics), offered every Spring since Spring 2006 ECE 792U (Utility Applications of Power Electronics, FACTS and Custom Power), [offered irregularly] ECE 305 (Taught 1/3 course with Profs. Baran & Lukic, Fall 2010) ECE 534 and ECE 434 combined class - offered only in two semesters 2.

Created and organised by The Interface Mechanical Civil ‘Thou’ (μm) 1/16 (mm) EN 13001-02 Regular, Variable, & Occasional Loads