Computer Architecture: A Constructive Approach Combinational circuits Teacher: Yoav Etsion Teaching Assistant: Yuval H. Nacson Taken (with permission)

Slides:



Advertisements
Similar presentations
Verilog Intro: Part 1.
Advertisements

Chapter 9 Computer Design Basics. 9-2 Datapaths Reminding A digital system (or a simple computer) contains datapath unit and control unit. Datapath: A.
L10 – Transistors Logic Math 1 Comp 411 – Spring /22/07 Arithmetic Circuits Didn’t I learn how to do addition in the second grade?
Combinational Circuits in Bluespec
Datorteknik ArithmeticCircuits bild 1 Computer arithmetic Somet things you should know about digital arithmetic: Principles Architecture Design.
L9 – Arithmetic Circuits 1 Comp 411 – Fall /14/09 Arithmetic Circuits Didn’t I learn how to do addition in the second grade?
Chapter 10-Arithmetic-logic units
Combinational Logic in Verilog
Programmable Logic Architecture Verilog HDL FPGA Design Jason Tseng Week 5.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Logic Circuits I.
Computer Architecture: A Constructive Approach Sequential Circuits Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology.
CS1Q Computer Systems Lecture 9 Simon Gay. Lecture 9CS1Q Computer Systems - Simon Gay2 Addition We want to be able to do arithmetic on computers and therefore.
Digital Arithmetic and Arithmetic Circuits
HCL and ALU תרגול 10. Overview of Logic Design Fundamental Hardware Requirements – Communication: How to get values from one place to another – Computation.
Csci 136 Computer Architecture II – Constructing An Arithmetic Logic Unit Xiuzhen Cheng
Lecture 9 Topics: –Combinational circuits Basic concepts Examples of typical combinational circuits –Half-adder –Full-adder –Ripple-Carry adder –Decoder.
Constructive Computer Architecture Combinational circuits-2 Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology.
Folded Combinational Circuits as an example of Sequential Circuits Arvind Computer Science & Artificial Intelligence Lab Massachusetts Institute of Technology.
Arithmetic Logic Unit (ALU) Anna Kurek CS 147 Spring 2008.
COE 202 Introduction to Verilog Computer Engineering Department College of Computer Sciences and Engineering King Fahd University of Petroleum and Minerals.
CDA 3101 Fall 2013 Introduction to Computer Organization The Arithmetic Logic Unit (ALU) and MIPS ALU Support 20 September 2013.
Anurag Dwivedi. Basic Block - Gates Gates -> Flip Flops.
Oct 2, 2014T01-1http://csg.csail.mit.edu/6.175 Constructive Computer Architecture Tutorial 1 BSV Sizhuo Zhang TA.
Half Adder & Full Adder Patrick Marshall. Intro Adding binary digits Half adder Full adder Parallel adder (ripple carry) Arithmetic overflow.
Constructive Computer Architecture Combinational circuits Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology.
IT253: Computer Organization
Copyright Curt Hill The C/C++ switch Statement A multi-path decision statement.
Computer Architecture: A Constructive Approach Combinational ALU Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology.
6.S078 - Computer Architecture: A Constructive Approach Combinational circuits Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute.
Arithmetic-logic units1 An arithmetic-logic unit, or ALU, performs many different arithmetic and logic operations. The ALU is the “heart” of a processor—you.
CO5023 Introduction to Digital Circuits. What do we know so far? How to represent numbers (integers and floating point) in binary How to convert between.
Constructive Computer Architecture Combinational circuits Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology.
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.
ECE DIGITAL LOGIC LECTURE 15: COMBINATIONAL CIRCUITS Assistant Prof. Fareena Saqib Florida Institute of Technology Fall 2015, 10/20/2015.
Computer Organization and Design Arithmetic & Logic Circuits Montek Singh Nov 2, 2015 Lecture 11.
Computer Architecture: A Constructive Approach Bluespec execution model and concurrent rule scheduling Teacher: Yoav Etsion Taken (with permission) from.
Combinational Circuits
Somet things you should know about digital arithmetic:
Subtitle: How to design the data path of a processor.
Folded “Combinational” circuits
Sequential Circuits - 2 Constructive Computer Architecture Arvind
Swamynathan.S.M AP/ECE/SNSCT
Combinational ALU Constructive Computer Architecture Arvind
Computer Organization and Design Arithmetic & Logic Circuits
Combinational circuits-2
Combinational Circuits in Bluespec
Computer Organization and Design Arithmetic & Logic Circuits
Behavioral Modeling in Verilog
Combinational circuits
Computer Organization and Design Arithmetic & Logic Circuits
BSV Types Constructive Computer Architecture Tutorial 1 Andy Wright
Arithmetic Circuits Didn’t I learn how
BSV objects and a tour of known BSV problems
Combinational circuits
Introduction to Verilog
King Fahd University of Petroleum and Minerals
Computer Organization and Design Arithmetic & Logic Circuits
Combinational circuits
Sequential Circuits - 2 Constructive Computer Architecture Arvind
Lecture 11: Hardware for Arithmetic
Overview Part 1 – Design Procedure Part 2 – Combinational Logic
Part III The Arithmetic/Logic Unit
ECE 352 Digital System Fundamentals
ECE 352 Digital System Fundamentals
Computer Organization and Design Arithmetic Circuits
Combinational ALU 6.S078 - Computer Architecture:
COE 202 Introduction to Verilog
Constructive Computer Architecture Tutorial 1 Andy Wright 6.S195 TA
Arithmetic and Logic Circuits
Presentation transcript:

Computer Architecture: A Constructive Approach Combinational circuits Teacher: Yoav Etsion Teaching Assistant: Yuval H. Nacson Taken (with permission) from Arvind et al.*, Massachusetts Institute of Technology Derek Chiou, The University of Texas at Austin * Joel Emer, Li-Shiuan Peh, Murali Vijayaraghavan, Asif Khan, Abhinav Agarwal, Myron King 1

Introduction to the Course Objectives: Experience the details and subtleties of microprocessor design Learn high-level hardware design methodologies using Bluespec Program and use FPGAs Assumes you have good programming experience, some knowledge of computer architecture Designed in MIT-style: doesn’t tell you everything, you learn a lot from the assignments Read the documentation If you don’t understand, experiment! 2

Technicalities You will need to open an account at the Digital Systems’ Lab in EE An account at the VLSI lab will get you more workstations to work on Five home assignments All include programming in Bluespec; some synthesize to FPGAs Final project We will offer topics, but feel free to suggest your own Grading: 50% assignments, 50% final project No exam NO CHEATING! Anyone caught copying any part of the assignments or posting code to a shared forum will be sent to a Technion trial 3

Documentation Bluespec documentation on the course website Book: “Bluespec by Example” Bluespec reference manual Bluespec build utility: Wrapper script to compile Bluespec all the way to an FPGA bitfile Read documentation an examples by running: build -d (ignore the SceMi aspects) Other documentation links: Send to: 4

Today’s Content Design of a combinational ALU starting with primitive gates And, Or and Not Combinational circuits as acyclic wiring diagrams of primitive gates Introduction to BSV Intro to types – enum, typedefs, numeric types, int#(32) vs integer, bool vs bit#(1), vectors Simple operations: concatenation, conditionals, loops Functions Static elaboration and a structural interpretation of the textual code 5

Combinational circuits are acyclic interconnections of gates And, Or, Not Nand, Nor, Xor … 6

Simple combinational circuits: Ripple-carry Adder 7

Full Adder: A one-bit adder function fa(a, b, c_in); s = (a ^ b)^ c_in; c_out = (a & b) | (c_in & (a ^ b)); return {c_out,s}; endfunction Structural code – only specifies interconnection between boxes Not quite correct – needs type annotations 8

Full Adder: A one-bit adder corrected function Bit#(2) fa(Bit#(1) a, Bit#(1) b, Bit#(1) c_in); Bit#(1) s = (a ^ b)^ c_in; Bit#(1) c_out = (a & b) | (c_in & (a ^ b)); return {c_out,s}; endfunction “Bit#(1) a” type declaration says that a is one bit wide {c_out,s} represents bit concatenation How big is {c_out,s} ? 2 bits 9

Types A type is a grouping of values Integer: 1, 2, 3, … Bool: True, False Bit : 0,1 A pair of Integers: Tuple2#(Integer, Integer) A function fname from Integers to Integers: function Integer fname (Integer arg) Every expression and variable in a Bluespec program has a type; sometimes it is specified explicitly and sometimes it is deduced by the compiler Thus we say an expression has a type or belongs to a type Each expression has a unique type 10

Type declaration versus deduction The programmer writes down types of some expressions in a program and the compiler deduces the types of the rest of expressions If the type deduction cannot be performed or the type declarations are inconsistent then the compiler complains function Bit#(2) fa(Bit#(1) a, Bit#(1) b, Bit#(1) c_in); Bit#(1) s = (a ^ b)^ c_in; Bit#(2) c_out = (a & b) | (c_in & (a ^ b)); return {c_out,s}; endfunction type error Type checking prevents lots of silly mistakes 11

2-bit Ripple-Carry Adder function Bit#(3) add(Bit#(2) x, Bit#(2) y, Bit#(1) c0); Bit#(2) s = 0; Bit#(3) c=0; c[0] = c0; let cs0 = fa(x[0], y[0], c[0]); c[1] = cs0[1]; s[0] = cs0[0]; let cs1 = fa(x[1], y[1], c[1]); c[2] = cs1[1]; s[1] = cs1[0]; return {c[2],s}; endfunction fa x[0] y[0] c[0] s[0] x[1] y[1] c[1] s[1] c[2] fa is like a blackbox, its internals are not visible to the user. fa can be used as long as we understand its type signature and its function 12

“let” syntax The “let” syntax: asks compiler to infer type avoids having to write down types explicitly let cs0 = fa(x[0], y[0], c[0]); Bits#(2) cs0 = fa(x[0], y[0], c[0]); The same 13

Parameterized types: # A type declaration itself can be parameterized by other types Parameters are indicated by using the syntax ‘#’ For example Bit#(n) represents n bits and can be instantiated by specifying a value of n Bit#(1), Bit#(32), Bit#(8), … 14

An w-bit Ripple-Carry Adder function Bit#(w+1) addN(Bit#(w) x, Bit#(w) y, Bit#(1) c0); Bit#(w) s; Bit#(w+1) c=0; c[0] = c0; for(Integer i=0; i<w; i=i+1) begin let cs = fa(x[i],y[i],c[i]); c[i+1] = cs[1]; s[i] = cs[0]; end return {c[w],s}; endfunction Not quite correct Unfold the loop to get the wiring diagram fa x[0] y[0] c[0] s[0] x[1] y[1] c[1] s[1] c[2] cs fa x[w-1] y[w-1] s[w-1] c[w] c[w-1] … 15

Instantiating the parametric Adder function Bit#(w+1) addN(Bit#(w) x, Bit#(w) y, Bit#(1) c0); // concrete instances of addN! function Bit#(33) add32(Bit#(32) x, Bit#(32) y, Bit#(1) c0) = addN(x,y,c0); function Bit#(4) add3(Bit#(3) x, Bit#(3) y, Bit#(1) c0) = addN(x,y,c0); Define add32, add3 … using addN 16

valueOf(w) versus w Each expression has a type and a value and these come from two entirely disjoint worlds w in Bit#(w) resides in the types world Sometimes we need to use values from the types world into actual computation. The function valueOf allows us to do that Thus i<w is not type correct i<valueOf(w) is type correct 17

TAdd#(w,1) versus w+1 Sometimes we need to perform operations in the types world that are very similar to the operations in the value world Examples: Add, Mul, Log We define a few special operators in the types world for such operations Examples: TAdd#(m,n), TMul#(m,n), … 18

A w-bit Ripple-Carry Adder corrected function Bit#(TAdd#(w,1)) addN(Bit#(w) x, Bit#(w) y, Bit#(1) c0); Bit#(w) s; Bit#(TAdd#(w,1)) c=0; c[0] = c0; let valw = valueOf(w); for(Integer i=0; i<valw; i=i+1) begin let cs = fa(x[i],y[i],c[i]); c[i+1] = cs[1]; s[i] = cs[0]; end return {c[valw],s}; endfunction 19

A w-bit Ripple-Carry Adder function Bit#(TAdd#(w,1)) addN(Bit#(w) x, Bit#(w) y, Bit#(1) c0); Bit#(w) s; Bit#(TAdd#(w,1)) c; c[0] = c0; let valw = valueOf(w); for(Integer i=0; i<valw; i=i+1) begin let cs = fa(x[i],y[i],c[i]); c[i+1] = cs[1]; s[i] = cs[0]; end return {c[valw],s}; endfunction types world equivalent of w+1 Lifting a type into the value world Structural interpretation of a loop – unfold it to generate an acyclic graph 20

Static Elaboration phase When Bluespec program are compiled, first type checking is done and then the compiler gets rid of many constructs which have no direct hardware meaning, like Integers, loops cs0 = fa(x[0], y[0], c[0]); c[1]=cs0[1]; s[0]=cs0[0]; cs1 = fa(x[1], y[1], c[1]); c[2]=cs1[1]; s[1]=cs1[0]; … csw = fa(x[valw-1], y[valw-1], c[valw-1]); c[valw] = csw[1]; s[valw-1] = csw[0]; for(Integer i=0; i<valw; i=i+1) begin let cs = fa(x[i],y[i],c[i]); c[i+1] = cs[1]; s[i] = cs[0]; end 21

Integer versus Int#(32) In mathematics integers are unbounded but in computer systems integers always have a fixed size Bluespec allows us to express both types of integers, though unbounded integers are used only as a programming convenience for(Integer i=0; i<valw; i=i+1) begin let cs = fa(x[i],y[i],c[i]); c[i+1] = cs[1]; s[i] = cs[0]; end 22

Type synonyms typedef bit [7:0] Byte; typedef Bit#(8) Byte; typedef Bit#(32) Word; typedef Tuple2#(a,a) Pair#(type a); typedef Int#(n) MyInt#(type n); typedef Int#(n) MyInt#(numeric type n); The same 23

Arithmetic-Logic Unit (ALU) ALU performs all the arithmetic and logical functions Op - Add, Sub,... - And, Or, Xor, Not,... - GT, LT, EQ, Zero,...  Result Comp? A B ALU We first implement individual functions like Add and then combine them to form an ALU 24

Shift operators 25

00 Logical right shift by 2 Fixed size shift operation is cheap in hardware – just wire the circuit appropriately Rotate, sign-extended shifts – all are equally easy a b c d 0 0 a b 26

Conditional operation: shift versus no-shift We need a mux to select the appropriate wires: if s is one the mux will select the wires on the left otherwise it would select wires on the right s (s==0)?{a,b,c,d}:{0,0,a,b}; 00 27

A 2-way multiplexer (s==0)?A:B A B S AND OR S A B Gate-level implementation We will use conditional expressions which will be synthesized using muxes 28

A 4-way multiplexer case {s1,s0} matches 0: A; 1: B; 2: C; 3: D; endcase S0S0 S0S0 S1S1 A B C D 29

Logical right shift by n Shift n can be broken down in log n steps of fixed-length shifts of size 1, 2, 4, … Shift 3 can be performed by doing a shift 2 and shift 1 We need a mux to omit a particular size shift Shift circuit can be expressed an log n nested conditional expressions You will write a Blusepec program to produce a variable size shifter in Lab s0 s1 30

Enumerated types Suppose we have a variable c whose values can represent three different colors We can declare the type of c to be Bit#(2) and say that 00 represents Red, 01 Blue and 10 Green A better way is to create a new type called Color as follows: typedef enum {Red, Blue, Green} Color deriving(Bits, Eq); The compiler will automatically assign some bit representation to the three colors and also provide a function to test if the two colors are equal. If you do not use “deriving” then you will have to specify the representation and equality Types prevent us from mixing raw bits and bits that represent color 31

Enumerated types typedef enum {Red, Blue, Green} Color deriving(Bits, Eq); typedef enum {Eq, Neq, Le, Lt, Ge, Gt, AT, NT} BrFunc deriving(Bits, Eq); typedef enum {Add, Sub, And, Or, Xor, Nor, Slt, Sltu, LShift, RShift, Sra} AluFunc deriving(Bits, Eq); Each enumerated type defines a new type 32

Combinational ALU function Data alu(Data a, Data b, AluFunc func); Data res = case(func) Add : (a + b); Sub : (a - b); And : (a & b); Or : (a | b); Xor : (a ^ b); Nor : ~(a | b); Slt : zeroExtend( pack( signedLT(a, b) ) ); Sltu : zeroExtend( pack( a < b ) ); LShift: (a << b[4:0]); RShift: (a >> b[4:0]); Sra : signedShiftRight(a, b[4:0]); endcase; return res; endfunction Given an implementation of the primitive operations like addN, Shift, etc. the ALU can be implemented simply by introducing a mux controlled by op to select the appropriate circuit 33

Comparison operators function Bool aluBr(Data a, Data b, BrFunc brFunc);  Bool brTaken = case(brFunc)  Eq : (a == b);  Neq : (a != b);  Le : signedLE(a, 0);  Lt : signedLT(a, 0);  Ge : signedGE(a, 0);  Gt : signedGT(a, 0);  AT : True;  NT : False;  endcase;  return brTaken;  endfunction 34

ALU including Comparison operators mux a func … mux brFunc AddLShiftEq … b 35

Complex combinational circuits Multiplication 36

Multiplication by repeated addition 1101 (13) 1011 (11) (143) b Multiplicand a Muliplier * add4 a0 a1 a2 a3 m0 m1 m2 m3 0 mi = (a[i]==0)? 0 : b; 37

Combinational 32-bit multiply function Bit#(64) mul32(Bit#(32) a, Bit#(32) b); Bit#(32) prod = 0; Bit#(32) tp = 0; for(Integer i = 0; i < 32; i = i+1) begin Bit#(32) m = (a[i]==0)? 0 : b; Bit#(33) sum = add32(m,tp,0); prod[i] = sum[0]; tp = truncateLSB(sum); end return {tp,prod}; endfunction 38

Design issues with combinational multiply Lot of hardware 32-bit multiply uses 31 add32 circuits Long chains of gates 32-bit ripple carry adder has a 31-long chain of gates 32-bit multiply has 31 ripple carry adders in sequence! The speed of a combinational circuit is determined by its longest input-to-output path Can we do better? 39

What Did We Learn? Combinational circuits in Bluespec Add, shift, multiply Bluespec Types Parameterized valueOf Tadd# Integer vs Int# Enumerated Types Static Elaboration 40