Combinational ALU Constructive Computer Architecture Arvind

Slides:



Advertisements
Similar presentations
Functions and Functional Blocks
Advertisements

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
1 ALUs. 2 Topics: ALU Overview - core of the integer datapath - 2 operands, 32-bits wide, plus control signals Exercise: A simple multiplier.
1 CS 140 Lecture 14 Standard Combinational Modules Professor CK Cheng CSE Dept. UC San Diego Some slides from Harris and Harris.
Computer Architecture: A Constructive Approach Instruction Representation Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute.
Chapter 3: Boolean Algebra
Lecture 12: Computer Arithmetic Today’s topic –Numerical representations –Addition / Subtraction –Multiplication / Division 1.
Arithmetic for Computers
1 CHAPTER 4: PART I ARITHMETIC FOR COMPUTERS. 2 The MIPS ALU We’ll be working with the MIPS instruction set architecture –similar to other architectures.
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 Computer Concept and Practice Copyright ©2012 by Jaejin Lee Logic Circuits I.
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.
Constructive Computer Architecture Combinational circuits Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology.
Digital Logic Design (CSNB163)
CS 105 DIGITAL LOGIC DESIGN Chapter 4 Combinational Logic 1.
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.
Addition, Subtraction, Logic Operations and ALU Design
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.
Computer Organization and Design Arithmetic & Logic Circuits Montek Singh Nov 2, 2015 Lecture 11.
Csci136 Computer Architecture II Lab#5 Arithmetic Review ALU Design Ripple Carry Adder & Carry lookahead HW #4: Due on Feb 22, before class Feb.16, 2005.
Computer Architecture: A Constructive Approach Combinational circuits Teacher: Yoav Etsion Teaching Assistant: Yuval H. Nacson Taken (with permission)
Computer Arthmetic Chapter Four P&H.
Combinational Circuits
Folded Combinational Circuits as an example of Sequential Circuits
Folded “Combinational” circuits
Sequential Circuits - 2 Constructive Computer Architecture Arvind
COMP541 Datapaths I Montek Singh Mar 28, 2012.
Morgan Kaufmann Publishers
Computer Organization and Design Arithmetic & Logic Circuits
Combinational circuits-2
ALU Design: Shifter Details
Chapter 6 Functions of Combinational Logic
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
Combinational circuits
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
A.R. Hurson 323 CS Building, Missouri S&T
CS/COE0447 Computer Organization & Assembly Language
CS/COE0447 Computer Organization & Assembly Language
Overview Part 1 – Design Procedure Part 2 – Combinational Logic
Part III The Arithmetic/Logic Unit
COMS 361 Computer Organization
CSE 140 Lecture 14 Standard Combinational Modules
Logic Circuits I Lecture 3.
ECE 352 Digital System Fundamentals
Combinational Circuits
ECE 352 Digital System Fundamentals
Computer Organization and Design Arithmetic Circuits
Combinational ALU 6.S078 - Computer Architecture:
Constructive Computer Architecture Tutorial 1 Andy Wright 6.S195 TA
Arithmetic and Logic Circuits
Presentation transcript:

Combinational ALU Constructive Computer Architecture Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology September 11, 2017 http://csg.csail.mit.edu/6.175

Outline Building complex combinational circuits in pieces Parameterization that goes beyond data path widths September 11, 2017 http://csg.csail.mit.edu/6.175

Arithmetic-Logic Unit (ALU) func - Add, Sub, And, Or, ... result a b ALU ALU performs all the arithmetic and logical functions Type of a, e.g., Bit#(32) function Data alu(Data a, Data b, AluFunc func); Data could be bit#(32) what does func look like? Each individual function can be described as a combinational circuit and these can be combined together to produce a combinational ALU September 11, 2017 http://csg.csail.mit.edu/6.175

ALU for comparison operators func - GT, LT, EQ, Zero, ... c a b ALU Br Like ALU but returns a Bool function Bool aluBr(Data a, Data b, BrFunc func); Data could be bit#(32) what does func look like? September 11, 2017 http://csg.csail.mit.edu/6.175

Enumerated types Suppose we have a variable c whose values can represent three different colors Declare the type of c to be Bit#(2) and adopt the convention that 00 represents Red, 01 Blue and 10 Green A better way is to create a new type called Color: typedef enum {Red, Blue, Green} Color deriving(Bits, Eq); Why is this way better? BSV compiler automatically assigns a bit representation to the three colors and provides a function to test if the two colors are equal If you do not use “deriving” then you will have to specify your own encoding and equality function Types prevent us from mixing colors with raw bits September 11, 2017 http://csg.csail.mit.edu/6.175

Enumerated types Each enumerated type defines a new type typedef enum {Red, Blue, Green} Color deriving(Bits, Eq); typedef enum {Add, Sub, And, Or, Xor, Nor, Slt, Sltu, LShift, RShift, Sra} AluFunc deriving(Bits, Eq); typedef enum {Eq, Neq, Le, Lt, Ge, Gt, AT, NT} BrFunc deriving(Bits, Eq); Each enumerated type defines a new type September 11, 2017 http://csg.csail.mit.edu/6.175

Combinational ALU function Data alu(Data a, Data b, AluFunc func); Data res = case(func) Add : addN(a,b); Sub : subN(a,b); And : andN(a,b); Or : orN(a,b); Xor : xorN(a,b); Nor : norN(a,b); Slt : zeroExtend(pack(signedLT(a,b))); Sltu : zeroExtend(pack(lt(a,b)); LShift: shiftLeft(a,b[4:0]); RShift: shiftRight(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 func to select the appropriate circuit Slt, Sltu? September 11, 2017 http://csg.csail.mit.edu/6.175

Comparison operators function Bool aluBr(Data a, Data b, BrFunc brFunc); Bool brTaken = case(brFunc) Eq : (a == b); Neq : (a != b); Le : signedLE(a,b); Lt : signedLT(a,b); Ge : signedGE(a,b); Gt : signedGT(a,b); AT : True; NT : False; endcase; return brTaken; endfunction We only compare with 0? September 11, 2017 http://csg.csail.mit.edu/6.175 8

ALU including Comparison operators b Eq LShift Add … … func mux mux brFunc September 11, 2017 http://csg.csail.mit.edu/6.175

Selectors and Multiplexers September 11, 2017 http://csg.csail.mit.edu/6.175

Selecting a wire: x[i] Constant Selector: e.g., x[2] assume x is 4 bits wide Constant Selector: e.g., x[2] Dynamic selector: x[i] no hardware; x[2] is just the name of a wire [2] x0 x1 x2 x3 x0 x1 x2 x3 x0 x1 x2 x3 i i [i] x0 x1 x2 x3 4-way mux September 11, 2017 http://csg.csail.mit.edu/6.175

A 2-way multiplexer (s==0)? A : B ; Gate-level implementation A mux is simple conditional expression September 11, 2017 http://csg.csail.mit.edu/6.175

A 4-way multiplexer case ({s1,s0}) matches 0: A; 1: B; 2: C; 3: D; endcase September 11, 2017 http://csg.csail.mit.edu/6.175

Shift operators September 11, 2017 http://csg.csail.mit.edu/6.175

Logical right shift by 2 a b c d 0 0 a b a b c d 0 0 a b Fixed size shift operation is cheap in hardware – just wire the circuit appropriately Other types of shifts are similar a b c d c d a b Rotate a b c d a a a b Sign- extended Sign extension is useful for converting say, a 32-bit integer into a 64-bit integer September 11, 2017 http://csg.csail.mit.edu/6.175

Logical right shift by n Suppose we want to build a shifter which shift a value x by n where n is between 0 and 31 One way to do this is by connecting 31 different shifters via a mux n shR0 shRi shR31 x … n-way mux is expensive. How many gates? Can we do better? September 11, 2017 http://csg.csail.mit.edu/6.175

Logical right shift by n Shift n can be broken down in log n steps of fixed-length shifts of size 1, 2, 4, … For example, we can perform Shift 3 (=2+1) by doing shifts of size 2 and 1 Shift 5 (=4+1) by doing shifts of size Shift 21 (=16+4+1) by doings shifts of size For a 32-bit number, a 5-bit n can specify all the needed shifts 310 = 000112 , 510 = 001012 , 2110 = 101012 The bit encoding of n tells us which shifters are needed; if the value of the ith (least significant) bit is 1 then we need to shift by 2i bits 4 and 1 16, 4 and 1 September 11, 2017 http://csg.csail.mit.edu/6.175

Conditional operation: shift versus no-shift s 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==0)?{a,b,c,d}:{0,0,a,b}; September 11, 2017 http://csg.csail.mit.edu/6.175

Logical right shift ckt Define log n shifters of sizes 1, 2, 4, … Define log n muxes to perform a particular size shift Shift circuit can be expressed as log n nested conditional expressions where s0, s1 .. Represent the bits of n s0 s1 In Lab 1 you would design such a shifter September 11, 2017 http://csg.csail.mit.edu/6.175

Complex Combinational Circuits September 11, 2017 http://csg.csail.mit.edu/6.175

Multiplication by repeated addition b Multiplicand a Muliplier * 1101 (13) 1011 (11) 0000 x 1101 1101 + 1101 + 0000 + 1101 10001111 (143) At each step we add either 1101 or 0 to the result depending upon a bit in the multiplier mi = (a[i]==0)? 0 : b; m0 m1 m2 m3 We also shift the result by one position at every step However, our addN circuit adds only two numbers at a time! September 11, 2017 http://csg.csail.mit.edu/6.175

Multiplication by repeated addition cont. b Multiplicand a Muliplier * tp m0 m1 m2 m3 1101 (13) 1011 (11) 0000 + 1101 01101 + 1101 100111 + 0000 0100111 + 1101 10001111 (143) At each step we add either 1101 or 0 to the result depending upon a bit in the multiplier mi = (a[i]==0)? 0 : b; We also shift the result by one position at every step Notice, the first addition is unnecessary because it simply yields m0 September 11, 2017 http://csg.csail.mit.edu/6.175

Multiplication by repeated addition ckt 0 0 0 0 b Multiplicand a Muliplier * tp m0 m1 m2 m3 1101 (13) 1011 (11) 0000 + 1101 01101 + 1101 100111 + 0000 0100111 + 1101 10001111 (143) add4 a1 m1 add4 a2 m2 add4 a3 m3 mi = (a[i]==0)? 0 : b; add4 September 11, 2017 http://csg.csail.mit.edu/6.175

Combinational 32-bit multiply function Bit#(64) mul32(Bit#(32) a, Bit#(32) b); Bit#(32) tp = 0; Bit#(32) prod = 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 = sum[32:1]; end return {tp,prod}; endfunction This circuit uses 32 add32 circuits Lot of gates! Can we do better? Stay tuned… Iteration I produces the ith bit of answer using only i FAs. The most significant 32 bits are produced in the last step which involves an additional 32FA delays Long chains of gates 32-bit multiply has 32 ripple carry adders in sequence! 32-bit ripple carry adder has a 32-long chain of gates Total delay ? 2n FA delays, not nxn why? September 11, 2017 http://csg.csail.mit.edu/6.175 2(n-1) FAs?