Combinational ALU 6.S078 - Computer Architecture:

Slides:



Advertisements
Similar presentations
L10 – Transistors Logic Math 1 Comp 411 – Spring /22/07 Arithmetic Circuits Didn’t I learn how to do addition in the second grade?
Advertisements

Combinational Circuits in Bluespec
Arithmetic-Logic Units CPSC 321 Computer Architecture Andreas Klappenecker.
Combinational Comparators
Computer Architecture: A Constructive Approach Instruction Representation Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute.
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.
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.
1 Lecture 6 BOOLEAN ALGEBRA and GATES Building a 32 bit processor PH 3: B.1-B.5.
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)
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.
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.
September 8, 2009http://csg.csail.mit.edu/koreaL03-1 Combinational Circuits in Bluespec Arvind Computer Science & Artificial Intelligence Lab Massachusetts.
Folding complex combinational circuits to save area Arvind Computer Science & Artificial Intelligence Lab Massachusetts Institute of Technology February.
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 Arthmetic Chapter Four P&H. Data Representation Why do we not encode numbers as strings of ASCII digits inside computers? What is overflow when.
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
Somet things you should know about digital arithmetic:
Folded Combinational Circuits as an example of Sequential Circuits
Folded “Combinational” circuits
Sequential Circuits - 2 Constructive Computer Architecture Arvind
Swamynathan.S.M AP/ECE/SNSCT
Combinational ALU Constructive Computer Architecture Arvind
Morgan Kaufmann Publishers
Computer Organization and Design Arithmetic & Logic Circuits
Combinational circuits-2
ALU Design: Shifter Details
Combinational Circuits in Bluespec
Combinational Circuits in Bluespec
Computer Organization and Design Arithmetic & Logic Circuits
Combinational Circuits in Bluespec
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
Arithmetic Where we've been:
CSE Winter 2001 – Arithmetic Unit - 1
Combinational circuits
King Fahd University of Petroleum and Minerals
Computer Organization and Design Arithmetic & Logic Circuits
Instructor: Alexander Stoytchev
Arithmetic Circuits (Part I) Randy H
Systems Architecture I
Combinational circuits
Instructor: Alexander Stoytchev
Sequential Circuits - 2 Constructive Computer Architecture Arvind
Lecture 11: Hardware for Arithmetic
CS 140 Lecture 14 Standard Combinational Modules
Combinational Circuits in Bluespec
Unit 10 Arithmetic-logic Units
Overview Part 1 – Design Procedure Part 2 – Combinational Logic
Part III The Arithmetic/Logic Unit
CSE 140 Lecture 14 Standard Combinational Modules
ECE 352 Digital System Fundamentals
Instructor: Alexander Stoytchev
Combinational Circuits
ECE 352 Digital System Fundamentals
Computer Organization and Design Arithmetic Circuits
Constructive Computer Architecture Tutorial 1 Andy Wright 6.S195 TA
Arithmetic and Logic Circuits
Presentation transcript:

Combinational ALU 6.S078 - Computer Architecture: A Constructive Approach Combinational ALU Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology February 10, 2012 http://csg.csail.mit.edu/6.S078

Arithmetic-Logic Unit (ALU) Op - Add, Sub, ... - And, Or, Xor, Not, ... - GT, LT, EQ, Zero, ... Result Comp? A B ALU ALU performs all the arithmetic and logical functions We will first implement individual functions and then combine them to form an ALU February 10, 2012 http://csg.csail.mit.edu/6.S078

A w-bit Ripple-Carry Adder types world equivalent of w+1 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 Lifting a type into the value world Structural interpretation of a loop – unfold it to generate an acyclic graph February 10, 2012 http://csg.csail.mit.edu/6.S078

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 February 10, 2012 http://csg.csail.mit.edu/6.S078

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 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 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]; February 10, 2012 http://csg.csail.mit.edu/6.S078

Logical right shift by 2 a b c d 0 0 a b 0 0 a b Fixed size shift operation is cheap in hardware – just wire the circuit appropriately Rotate, sign-extended shifts – all are equally easy February 10, 2012 http://csg.csail.mit.edu/6.S078

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}; February 10, 2012 http://csg.csail.mit.edu/6.S078

A 2-way multiplexer (s==0)?A:B Gate-level implementation AND OR S A B A B S (s==0)?A:B Gate-level implementation We will use conditional expressions which will be synthesized using muxes February 10, 2012 http://csg.csail.mit.edu/6.S078

A 4-way multiplexer case {s1,s0} matches 0: A; 1: B; 2: C; 3: D; endcase B S0 C S1 D S0 February 10, 2012 http://csg.csail.mit.edu/6.S078

Logical right shift by n Shift n can be broken down in several steps of fixed-length shifts of 1, 2, 4, … Thus a shift of size 3 can be performed by first doing a shift of length 2 and then a shift of length 1 We need a Mux to select whether we need to shift at all The whole structure can be expressed an a bunch of nested conditional expressions s0 s1 You will write a Blusepec program to produce a variable size shifter in Lab 1 February 10, 2012 http://csg.csail.mit.edu/6.S078

Type synonyms typedef Bit [7:0] Byte; typedef Bit#(8) Byte; typedef Bit [31:0] Word; typedef Tuple2#(a,a) Pair#(type a); typedef Int#(n) MyInt#(type n); typedef Int#(n) MyInt#(numeric type n); Similar. What is the difference? The same February 10, 2012 http://csg.csail.mit.edu/6.S078

Enumerated types Each enumerated type defines a new type typedef enum {Red, Blue, Green} Color deriving(Bits, Eq); typedef enum {Eq, Neq, Le, Lt, Ge, Gt} BrType 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 January 18, 2012 http://csg.csail.mit.edu/SNU

Struct type Each struct type defines a new type Example: Complex Addition Each struct type defines a new type typedef struct{ Int#(t) r; Int#(t) i; } Complex#(numeric type t) deriving (Eq,Bits); function Complex#(t) \+ (Complex#(t) x, Complex#(t) y); Int#(t) real = x.r + y.r; Int#(t) imag = x.i + y.i; return(Complex{r:real, i:imag}); endfunction What is the type of this + ? January 12, 2012 http://csg.csail.mit.edu/SNU

Combinational ALU function Bit#(width) alu(Bit#(width) a, Bit#(width) b, AluFunc op); Bit#(width) res = case(op) Add : add(a, b); Sub : subtract(a, b); And : (a & b); Or : (a | b); Xor : (a ^ b); Nor : ~(a | b); Slt : setLessThan(a, b); Sltu : setLessThanUnsigned(a, b); LShift: logicalShiftLeft(a, b[4:0]); RShift: logicalShiftRight(a, b[4:0]); Sra : signedShiftRight(a, b[4:0]); endcase; return res; endfunction Once we have implemented 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 February 10, 2012 http://csg.csail.mit.edu/6.S078 14

Comparison operators function Bool aluBr(Bit#(width) a, Bit#(width) b, BrType brOp); Bool brTaken = case(brOp) Eq : (a == b); Neq : (a != b); Le : signedLE(a, 0); Lt : signedLT(a, 0); Ge : signedGE(a, 0); Gt : signedGT(a, 0); endcase; return brTaken; endfunction February 10, 2012 http://csg.csail.mit.edu/6.S078 15

ALU including Comparison operators b Eq LShift Add … … op mux mux brOp February 10, 2012 http://csg.csail.mit.edu/6.S078

Complex combinational circuits February 10, 2012 http://csg.csail.mit.edu/6.S078

Multiplication by repeated addition b Multiplicand a Muliplier * 1101 (13) 1011 (11) 1101 + 1101 + 0000 + 1101 10001111 (143) mi = (a[i]==0)? 0 : b; February 10, 2012 http://csg.csail.mit.edu/6.S078

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 February 10, 2012 http://csg.csail.mit.edu/6.S078

Combinational n-bit multiply function Bit#(TAdd#(w,w)) mulN(Bit#(w) a, Bit#(w) b); Bit#(w) prod = 0; Bit#(w) tp = 0; for(Integer i = 0; i < valueOf(w); i = i+1) begin Bit#(w) m = (a[i]==0)? 0 : b; Bit#(TAdd#(w,1)) sum = addN(m,tp,0); prod[i] = sum[0]; tp = truncateLSB(sum); end return {tp,prod}; endfunction February 10, 2012 http://csg.csail.mit.edu/6.S078

Design issues with combinational multiply Lot of hardware 32-bit multiply uses 31 addN 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 next time: Sequential circuits February 10, 2012 http://csg.csail.mit.edu/6.S078