Oct 2, 2014T01-1http://csg.csail.mit.edu/6.175 Constructive Computer Architecture Tutorial 1 BSV Sizhuo Zhang 6.175 TA.

Slides:



Advertisements
Similar presentations
each of these is an instantiation of “full_adder”
Advertisements

Stmt FSM Richard S. Uhler Computer Science & Artificial Intelligence Lab Massachusetts Institute of Technology (based on a lecture prepared by Arvind)
Modeling Processors Arvind Computer Science & Artificial Intelligence Lab Massachusetts Institute of Technology February 22, 2011L07-1
Constructive Computer Architecture Tutorial 5: Programming SMIPS: Single-Core Assembly Andy Wright TA October 10, 2014http://csg.csail.mit.edu/6.175T04-1.
Programmable Logic Architecture Verilog HDL FPGA Design Jason Tseng Week 5.
Computer Architecture: A Constructive Approach Sequential Circuits Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology.
C Tokens Identifiers Keywords Constants Operators Special symbols.
Pipelining combinational circuits Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology February 20, 2013http://csg.csail.mit.edu/6.375L05-1.
Constructive Computer Architecture Combinational circuits-2 Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology.
COE 202 Introduction to Verilog Computer Engineering Department College of Computer Sciences and Engineering King Fahd University of Petroleum and Minerals.
Constructive Computer Architecture: Guards Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology September 24, 2014.
Data Structure and c K.S.Prabhu Lecturer All Deaf Educational Technology.
Constructive Computer Architecture Tutorial 2 Advanced BSV Sizhuo Zhang TA Oct 9, 2015T02-1http://csg.csail.mit.edu/6.175.
Realistic Memories and Caches – Part II Li-Shiuan Peh Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology April 2, 2012L14-1.
Constructive Computer Architecture Tutorial 4 Debugging Sizhuo Zhang TA Oct 23, 2015T04-1http://csg.csail.mit.edu/6.175.
Constructive Computer Architecture Tutorial 2 Advanced BSV Andy Wright TA September 26, 2014http://csg.csail.mit.edu/6.175T02-1.
Constructive Computer Architecture Sequential Circuits Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology
Constructive Computer Architecture Combinational circuits Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology.
Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 1 ECE 406 – Design of Complex Digital Systems Lecture 6: Procedural Modeling Spring 2009 W. Rhett.
2: Basics Basics Programming C# © 2003 DevelopMentor, Inc. 12/1/2003.
Constructive Computer Architecture Sequential Circuits Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology September.
Constructive Computer Architecture Sequential Circuits - 2 Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology.
Modular Refinement Arvind Computer Science & Artificial Intelligence Lab Massachusetts Institute of Technology March 8,
October 20, 2009L14-1http://csg.csail.mit.edu/korea Concurrency and Modularity Issues in Processor pipelines Arvind Computer Science & Artificial Intelligence.
Modeling Processors Arvind Computer Science & Artificial Intelligence Lab Massachusetts Institute of Technology March 1, 2010
February 27, 2006http://csg.csail.mit.edu/6.375/L08-1 Bluespec-2: Types Arvind Computer Science & Artificial Intelligence Lab Massachusetts Institute of.
Functions and Types in Bluespec
Bluespec-3: A non-pipelined processor Arvind
Data types Data types Basic types
C# Operator Overloading and Type Conversions
Discussion 2: More to discuss
Bluespec-6: Modeling Processors
Folded “Combinational” circuits
Scheduling Constraints on Interface methods
Sequential Circuits - 2 Constructive Computer Architecture Arvind
Sequential Circuits Constructive Computer Architecture Arvind
Sequential Circuits: Constructive Computer Architecture
Combinational ALU Constructive Computer Architecture Arvind
BSV Tutorial 1 Ming Liu Feb 12, 2016
Combinational circuits-2
Caches-2 Constructive Computer Architecture Arvind
Stmt FSM Arvind (with the help of Nirav Dave)
Behavioral Modeling in Verilog
Combinational circuits
Pipelining combinational circuits
Constructive Computer Architecture: Guards
BSV Types Constructive Computer Architecture Tutorial 1 Andy Wright
Sequential Circuits Constructive Computer Architecture Arvind
Pipelining combinational circuits
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
BSV objects and a tour of known BSV problems
6.375 Tutorial 2 Guards and Scheduling Ming Liu
Debugging BSV and Typeclasses. Constructive Computer Architecture
Constructive Computer Architecture Tutorial 3 RISC-V Processor
Combinational circuits
Modules with Guarded Interfaces
Pipelining combinational circuits
Sequential Circuits - 2 Constructive Computer Architecture Arvind
Bluespec-3: A non-pipelined processor Arvind
Stmt FSM Arvind (with the help of Nirav Dave)
Bluespec-5: Modeling Processors
Constructive Computer Architecture: Guards
2. Second Step for Learning C++ Programming • Data Type • Char • Float
Modeling Processors Arvind
5. 3 Coding with Denotations
Verilog HDL Basic Syntax
Caches-2 Constructive Computer Architecture Arvind
CS295: Modern Systems Bluespec Introduction – More Topics
CS295: Modern Systems Introduction To Bluespec – Types
Constructive Computer Architecture Tutorial 1 Andy Wright 6.S195 TA
Presentation transcript:

Oct 2, 2014T01-1http://csg.csail.mit.edu/6.175 Constructive Computer Architecture Tutorial 1 BSV Sizhuo Zhang TA

Bit#(numeric type n) Literal values: Decimal: 0, 1, 2, … (each have type Bit#(n) Binary: 5’b01101, 2’b11 Hex: 5’hD, 2’h3, 16’h1FF0 Common functions: Bitwise Logic: |, &, ^, ~, etc. Arithmetic: +, -, *, %, etc. Indexing: a[i], a[3:1] Concatenation: {a, b} truncate, truncateLSB zeroExtend, signExtend Oct 2, 2014T01-2http://csg.csail.mit.edu/6.175

Bool Literal values: True, False Common functions: Boolean Logic: ||, &&, !, ==, !=, etc. All comparison operators (==, !=, >, =, <=) return Bools Oct 2, 2014T01-3http://csg.csail.mit.edu/6.175

Int#(n), UInt#(n) Literal values: Decimal:  0, 1, 2, … (Int#(n) and UInt#(n))  -1, -2, … (Int#(n)) Common functions: Arithmetic: +, -, *, %, etc.  Int#(n) performs signed operations  UInt#(n) performs unsigned operations Comparison: >, =, <=, ==, !=, etc. Oct 2, 2014T01-4http://csg.csail.mit.edu/6.175

Constructing new types Renaming types: typedef Enumeration types: enum Compound types: struct vector maybe tagged union Oct 2, 2014T01-5http://csg.csail.mit.edu/6.175

typedef Syntax: typedef ; Basic: typedef 8 BitsPerWord; typedef Bit#(BitsPerWord) Word;  Can’t be used with parameter: Word#(n) Parameterized: typedef Bit#(TMul#(BitsPerWord,n)) Word#(numeric type n);  Can’t be used without parameter: Word Oct 2, 2014T01-6http://csg.csail.mit.edu/6.175

enum Creates the type Color with values Red and Blue Can create registers containing colors Reg#(Color) Values can be compared with == and != Oct 2, 2014T01-7http://csg.csail.mit.edu/6.175 typedef enum {Red, Blue} Color deriving (Bits, Eq);

struct Elements from MemReq x can be accessed with x.addr, x.data, x.wren Struct Expression  X = MemReq{addr: 0, data: 1, wren: True}; Oct 2, 2014T01-8http://csg.csail.mit.edu/6.175 typedef struct { Bit#(12) addr; Bit#(8) data; Bool wren; } MemReq deriving (Bits, Eq);

struct Parametrized struct Oct 2, 2014T01-9http://csg.csail.mit.edu/6.175 typedef struct { t a; Bit#(n) b; } Req#(type t, numeric type n) deriving (Bits, Eq);

Tuple Types: Tuple2#(type t1, type t2) Tuple3#(type t1, type t2, type t3) up to Tuple8 Construct tuple: tuple2( x, y ), tuple3( x, y, z ) … Accessing an element: tpl_1( tuple2(x, y) ) // x tpl_2( tuple3(x, y, z) ) // y Pattern matching Oct 2, 2014T01-10http://csg.csail.mit.edu/6.175 Tuple2#(Bit#(2), Bool) tup = tuple2(2, True); match {.a,.b} = tup; // a = 2, b = True

Vector Type: Vector#(numeric type size, type data_type) Values: newVector(), replicate(val) Functions: Access an element: [] Rotate functions Advanced functions: zip, map, fold Can contain registers or modules Must have ‘import Vector::*;’ in BSV file Oct 2, 2014T01-11http://csg.csail.mit.edu/6.175

Maybe#(t) Type: Maybe#(type t) Values: tagged Invalid tagged Valid x (where x is a value of type t) Functions: isValid(x)  Returns true if x is valid fromMaybe(default, m)  If m is valid, returns the valid value of m if m is valid, otherwise returns default  Commonly used fromMaybe(?, m) Oct 2, 2014T01-12http://csg.csail.mit.edu/6.175

tagged union Maybe is a special type of tagged union Tagged unions are collections of types and tags. The type contained in the union depends on the tag of the union. If tagged Valid, this type contains a value of type t Oct 2, 2014T01-13http://csg.csail.mit.edu/6.175 typedef union tagged { void Invalid; t Valid; } Maybe#(type t) deriving (Eq, Bits);

tagged union Values: tagged value Pattern matching to get values: Oct 2, 2014T01-14http://csg.csail.mit.edu/6.175 case (x) matches tagged Valid.a : return a; tagged Invalid : return 0; endcase if(x matches tagged Valid.a &&& a > 1) begin $display(“%d”, a); end

Reg#(t) Main state element in BSV Type: Reg#(type data_type) Instantiated differently from normal variables Uses <- notation Written to differently from normal variables Uses <= notation Can only be done inside of rules and methods Oct 2, 2014T01-15http://csg.csail.mit.edu/6.175 Reg#(Bit#(32)) a_reg <- mkReg(0); // value set to 0 Reg#(Bit#(32)) b_reg <- mkRegU(); // uninitialized

Reg and Vector Register of Vectors Reg#( Vector#(32, Bit#(32) ) ) rfile; rfile <- mkReg( replicate(0) ); Vector of Registers Vector#( 32, Reg#(Bit#(32)) ) rfile; rfile <- replicateM( mkReg(0) ); Each has its own advantages and disadvantages Oct 2, 2014T01-16http://csg.csail.mit.edu/6.175

Partial Writes Reg#(Bit#(8)) r; r[0] <= 0 counts as a read & write to the entire reg r  let r_new = r; r_new[0] = 0; r <= r_new Reg#(Vector#(8, Bit#(1))) r Same problem, r[0] <= 0 counts as a read and write to the entire register r[0] <= 0; r[1] <= 1 counts as two writes to register  double write problem Vector#(8,Reg#(Bit#(1))) r r is 8 different registers r[0] <= 0 is only a write to register r[0] r[0] <= 0 ; r[1] <= 1 is not a double write problem Oct 2, 2014T01-17http://csg.csail.mit.edu/6.175

Modules Modules are building blocks for larger systems Modules contain other modules and rules Modules are accessed through their interface module mkAdder( Adder#(32) ); Adder#(32) is the interface Module can be parametrized module name#(params)(args …, interface); Oct 2, 2014T01-18http://csg.csail.mit.edu/6.175 module mkMul#(Bool signed)(Adder#(n) a, Mul#(n) x);

Interfaces Contain methods for other modules to interact with the given module Interfaces can also contain sub-interfaces Special interface: Empty No method, used in testbench Oct 2, 2014T01-19http://csg.csail.mit.edu/6.175 interface MyIfc#(numeric type n); method ActionValue#(Bit#(n)) f(); interface SubIfc#(n) s; endinterface module mkTb(Empty); module mkTb(); // () are necessary

Interface Methods Method Returns value, doesn’t change state method Bit#(32) first; Action Changes state, doesn’t return value method Action enq(Bit#(32) x); ActionValue Changes state, returns value method ActionValue#(Bit#(32)) deq; Oct 2, 2014T01-20http://csg.csail.mit.edu/6.175

Implement Interface of Module Instantiate methods at the end of module Oct 2, 2014T01-21http://csg.csail.mit.edu/6.175 interface MyIfc#(numeric type n); method ActionValue#(Bit#(n)) f(); interface SubIfc#(n) s; endinterface module mkDut(MyIfc#(n)); …… method ActionValue#(Bit#(n)) f(); …… endmethod interface SubIfc s; // no param “n” // methods of SubIfc endinterface endmodule

Implement Interface of Module Return interface at the end of module Interface expression Oct 2, 2014T01-22http://csg.csail.mit.edu/6.175 module mkDut(MyIfc#(n)); …… MyIfc ret = (interface MyIfc; method ActionValue#(Bit#(n)) f(); …… endmethod interface SubIfc s; // no param “n” // methods of SubIfc endinterface endinterface); return ret; endmodule

Vector Sub-interface Sub-interface can be vector BSV reference guide Section 5 Oct 2, 2014T01-23http://csg.csail.mit.edu/6.175 interface VecIfc#(numeric type m, numeric type n); interface Vector#(m, SubIfc#(n)) s; endinterface Vector#(m, SubIfc) vec = ?; for(Integer i=0; i<valueOf(m); i=i+1) begin // implement vec[i] end VecIfc ifc = (interface VecIfc; interface Vector s = vec; // interface s = vec; Endinterface);

Best way to learn BSV BSV Reference guide Lab code Try it Makefile in lab 1,2,3… Oct 2, 2014T01-24http://csg.csail.mit.edu/6.175

Scheduling Compile flag (BSV user guide) -aggressive-conditions (Section 7.12)  predicated implicit guards -show-schedule (Section 8.2.2)  method/rule schedule information  Output file: info-dir/*.sched -show-rule-rel r1 r2 (Section 8.2.2)  Print conflict information Oct 2, 2014T01-25http://csg.csail.mit.edu/6.175