Csci 136 Computer Architecture II – Constructing An Arithmetic Logic Unit Xiuzhen Cheng

Slides:



Advertisements
Similar presentations
1 ECE 4436ECE 5367 Computer Arithmetic I-II. 2 ECE 4436ECE 5367 Addition concepts 1 bit adder –2 inputs for the operands. –Third input – carry in from.
Advertisements

Arithmetic for Computers
Lecture 19: Hardware for Arithmetic Today’s topic –Designing an ALU –Carry Look-Ahead Adder 1.
1 Lecture 12: Hardware for Arithmetic Today’s topics:  Designing an ALU  Carry-lookahead adder Reminder: Assignment 5 will be posted in a couple of days.
©UCB CPSC 161 Lecture 6 Prof. L.N. Bhuyan
Mohamed Younis CMCS 411, Computer Architecture 1 CMCS Computer Architecture Lecture 7 Arithmetic Logic Unit February 19,
1 CONSTRUCTING AN ARITHMETIC LOGIC UNIT CHAPTER 4: PART II.
Arithmetic CPSC 321 Computer Architecture Andreas Klappenecker.
Arithmetic CPSC 321 Computer Architecture Andreas Klappenecker.
Arithmetic II CPSC 321 E. J. Kim. Today’s Menu Arithmetic-Logic Units Logic Design Revisited Faster Addition Multiplication (if time permits)
1 Lecture 4: Arithmetic for Computers (Part 3) CS 447 Jason Bakos.
1 Representing Numbers Using Bases Numbers in base 10 are called decimal numbers, they are composed of 10 numerals ( ספרות ) = 9* * *10.
Computer Structure - The ALU Goal: Build an ALU  The Arithmetic Logic Unit or ALU is the device that performs arithmetic and logical operations in the.
1  2004 Morgan Kaufmann Publishers Chapter Three.
ECE C03 Lecture 61 Lecture 6 Arithmetic Logic Circuits Hai Zhou ECE 303 Advanced Digital Design Spring 2002.
Arithmetic II CPSC 321 Andreas Klappenecker. Any Questions?
Lecture 8 Arithmetic Logic Circuits
1 Chapter 4: Arithmetic Where we've been: –Performance (seconds, cycles, instructions) –Abstractions: Instruction Set Architecture Assembly Language and.
Arithmetic I CPSC 321 Andreas Klappenecker. Administrative Issues Office hours of TA Praveen Bhojwani: M 1:00pm-3:00pm.
Arithmetic-Logic Units CPSC 321 Computer Architecture Andreas Klappenecker.
1 ECE369 Chapter 3. 2 ECE369 Multiplication More complicated than addition –Accomplished via shifting and addition More time and more area.
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Hao Ji.
1  1998 Morgan Kaufmann Publishers Chapter Four Arithmetic for Computers.
Chapter 3 Arithmetic for Computers. Arithmetic Where we've been: Abstractions: Instruction Set Architecture Assembly Language and Machine Language What's.
1 Bits are just bits (no inherent meaning) — conventions define relationship between bits and numbers Binary numbers (base 2)
EGRE 426 Fall 09 Chapter Three
Computing Systems Basic arithmetic for computers.
Chapter 6-1 ALU, Adder and Subtractor
07/19/2005 Arithmetic / Logic Unit – ALU Design Presentation F CSE : Introduction to Computer Architecture Slides by Gojko Babić.
1 EGRE 426 Fall 08 Chapter Three. 2 Arithmetic What's up ahead: –Implementing the Architecture 32 operation result a b ALU.
1  1998 Morgan Kaufmann Publishers Arithmetic Where we've been: –Performance (seconds, cycles, instructions) –Abstractions: Instruction Set Architecture.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /19/2013 Lecture 7: 32-bit ALU, Fast Carry Lookahead Instructor: Ashraf Yaseen DEPARTMENT OF MATH &
Computing Systems Designing a basic ALU.
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.
Lecture 18: Hardware for Arithmetic Today’s topic –Intro to Boolean functions (Continued) –Designing an ALU 1.
Binary Adder DesignSpring Binary Adders. Binary Adder DesignSpring n-bit Addition –Ripple Carry Adder –Conditional Sum Adder –(Carry Lookahead.
1 Modified from  Modified from 1998 Morgan Kaufmann Publishers Chapter Three: Arithmetic for Computers Section 2 citation and following credit line is.
CPE 232 MIPS Arithmetic1 CPE 232 Computer Organization MIPS Arithmetic – Part I Dr. Gheith Abandah [Adapted from the slides of Professor Mary Irwin (
1  2004 Morgan Kaufmann Publishers Performance is specific to a particular program/s –Total execution time is a consistent summary of performance For.
1 ELEN 033 Lecture 4 Chapter 4 of Text (COD2E) Chapters 3 and 4 of Goodman and Miller book.
Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture Arithmetic: Part II.
C-H1 Lecture Adders Half adder. C-H2 Full Adder si is the modulo- 2 sum of ci, xi, yi.
1  2004 Morgan Kaufmann Publishers Lets Build a Processor Almost ready to move into chapter 5 and start building a processor First, let’s review Boolean.
Addition, Subtraction, Logic Operations and ALU Design
CML CML CS 230: Computer Organization and Assembly Language Aviral Shrivastava Department of Computer Science and Engineering School of Computing and Informatics.
순천향대학교 정보기술공학부 이 상 정 1 3. Arithmetic for Computers.
Prof. Hsien-Hsin Sean Lee
Lec 11Systems Architecture1 Systems Architecture Lecture 11: Arithmetic for Computers Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan Some or all.
ECE/CS 552: Arithmetic I Instructor:Mikko H Lipasti Fall 2010 University of Wisconsin-Madison Lecture notes partially based on set created by Mark Hill.
Arithmetic-Logic Units. Logic Gates AND gate OR gate NOT gate.
1 Lecture 11: Hardware for Arithmetic Today’s topics:  Logic for common operations  Designing an ALU  Carry-lookahead adder.
1 Arithmetic Where we've been: –Abstractions: Instruction Set Architecture Assembly Language and Machine Language What's up ahead: –Implementing the Architecture.
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.
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.
9/23/2004Comp 120 Fall September Chapter 4 – Arithmetic and its implementation Assignments 5,6 and 7 posted to the class web page.
Shivkumar Kalyanaraman Rensselaer Polytechnic Institute 1.
EE204 L03-ALUHina Anwar Khan EE204 Computer Architecture Lecture 03- ALU.
May 2, 2001System Architecture I1 Systems Architecture I (CS ) Lecture 11: Arithmetic for Computers * Jeremy R. Johnson May 2, 2001 *This lecture.
1 CPTR 220 Computer Organization Computer Architecture Assembly Programming.
Based on slides from D. Patterson and www-inst.eecs.berkeley.edu/~cs152/ COM 249 – Computer Organization and Assembly Language Chapter 3 Arithmetic For.
1 Chapter 3 Arithmetic for Computers Lecture Slides are from Prof. Jose Delgado-Frias, Mr. Paul Wettin, and Prof. Valeriu Beiu (Washington State University.
1 (Based on text: David A. Patterson & John L. Hennessy, Computer Organization and Design: The Hardware/Software Interface, 3 rd Ed., Morgan Kaufmann,
Computer Arthmetic Chapter Four P&H.
Computer Architecture & Operations I
Arithmetic Where we've been:
COMS 361 Computer Organization
Instructor: Mozafar Bag-Mohammadi University of Ilam
A 1-Bit Arithmetic Logic Unit
Presentation transcript:

Csci 136 Computer Architecture II – Constructing An Arithmetic Logic Unit Xiuzhen Cheng

Announcement Homework assignment #4: Due on Feb 22, before class Readings: Sections 3.2, 3.3, B.5, B.6 Problems: 3.7, 3.9, 3.10, 3.12, Project #1 is due on 11:59PM, Feb 13. Project #2 is due on 11:59PM, March 10.

What Are We Going To Do? Implementing the MIPS ISA architecture! Must support the arithmetic/logic operations Tradeoffs of cost and speed based on frequency of occurrence, hardware budget. 32 operation result a b ALU

Negating a two's complement number: invert all bits and add 1 remember: “negate” and “invert” are quite different! Converting n bit numbers into numbers with more than n bits: MIPS 16 bit immediate gets converted to 32 bits for arithmetic copy the most significant bit (the sign bit) into the other bits > > "sign extension" (lbu vs. lb) Review on Two's Complement Operations

Just like in grade school (carry/borrow 1s) Two's complement operations easy subtraction using addition of negative numbers Overflow (result too large or too small for finite computer word): Example: -8 <= 4-bit binary number <=7 Review on Addition & Subtraction

No overflow when adding a positive and a negative number No overflow when signs are the same for subtraction Overflow occurs when the value affects the sign: overflow when adding two positives yields a negative or, adding two negatives gives a positive or, subtract a negative from a positive and get a negative or, subtract a positive from a negative and get a positive Detecting Overflow

An exception (interrupt) occurs Control jumps to predefined address for exception Interrupted address is saved for possible resumption Details based on software system / language Don't always want to detect overflow — new MIPS instructions: addu, addiu, subu note: addiu still sign-extends! note: sltu, sltiu for unsigned comparisons Effects of Overflow

Not easy to decide the “best” way to build something Don't want too many inputs to a single gate Don’t want to have to go through too many gates For our purposes, ease of comprehension is important Let's look at a 1-bit ALU for addition: Building blocks: AND, OR, Inverter, MUX, etc. How could we build a 1-bit ALU for add, and, and or? How could we build a 32-bit ALU? Different Implementations for ALU c out = a b + a c in + b c in sum = a xor b xor c in

A 1-bit ALU AND and OR A logic unit performing logic AND and OR. Full Adder A 1-bit Full Adder ((3,2) adder). Implementation of a 1-bit adder A 1-bit ALU that performs AND, OR, and addition Figure B.5.6

A 32-bit ALU, Ripple Carry Adder A 32-bit ALU for AND, OR and ADD operation: connecting 32 1-bit ALUs

What About Subtraction Invert each bit (by inverter) of b and add 1 How do we implement? A very clever solution: a + (-b) = a + (b’ +1)

What About NOR Operation? Explore existing hardware in the ALU NOR (a,b) = not (a or b) = not(a) and not(b) Only need to add an inverter for input a

32-Bit ALU for AND, OR, ADD, SUB, NOR Binvert Ainvert

In-Class Question Prove that you can detect overflow by CarryIn31 xor CarryOut31 that is, an overflow occurs if the CarryIN to the most significant bit is not the same as the CarryOut of the most significant bit

Set on Less Than Operation Idea: For slt $t0, $s1, $s2 Check $s1-$s2. If negative, then set the LSB of $t0 to 1, set all other bits of $t0 to 0; otherwise, set all bits of $t0 to 0. How to set these bits? – Less input line Implementation: Connect Result31 to Less Overflow detection

Set on Less Than Operation Question: In figure B.5.11, Set connects directly to Less0. Can you find out any problem in this implementation? How to fix it?

Conditional Branch MIPS Instruction: beq$S1, $s2, label Idea: Test $s1-$s2. Use an OR gate to test whether the result is 0 or not. It $s1=$s2, set a zero detector.

A Final 32-bit ALU Operations supported: and, or, nor, add, sub, slt, beq/bnq ALU Control lines: 2 operation control signal for and, or, add, and slt, 2 control line for sub, nor, and slt ALU Control LinesFunction 0000And 0001Or 0010Add 0110Sub Slt NOR

SPEED of the 32-bit Ripple Carry Adder CarryOut, Result The critical path Path traversed by CARRY: contains 32 and gates, 32 or gates. We must sequentially evaluate all 1-bit adders.  Ripple-carry is too low to be used in time-critical hardware Speedup: anticipate the carry!  needs more hardware for parallel operation An extreme case – sum of products “Infinite” hardware through two-level logic An example implementation – too expensive!  the number of gates grows exponentially!  How many gates are needed to compute c1:c2:c3:c4:

Carry-Lookahead Adder The concept of propagate and generate c(i+1) = (ai. bi) + (ai. ci) + (bi. ci) = (ai. bi) + ((ai+bi).ci) pi = ai + bi;gi = ai. bi Write down c1, c2, c3, c4. Why fast? First Level of abstraction: pi, gi Still too expensive! Why?  still large number of gates  How many gates are needed to compute c1:c2:c3:c4:

Carry-Lookahead Adder CarryOut is 1 if some earlier adder generates a carry and all intermediary adders propagate the carry.

Build Bigger Adders Can’t build a 16-bit adder with carry lookahead! Could use ripple carry of 4-bit adder Use carry lookahead at higher levels “Super” Propagate Pi vs. “Super” Generate Gi Group concept, 4-bit adder as a building block “Super” Propagate/Generate definition c4 = g3 + (p3.g2) + (p3.p2.g1) + (p3.p2.p1.g0) + (p3.p2.p1.p0.c0) = C1

Super Propagate and Generate A “super” propagate is true only if all propagates in the same group is true P0= P1=P2=P3= A “super” generate is true only if at least one generate in its group is true and all the propagates downstream from that generate are true. G0= G1= G2= G3=

A 16-Bit Adder Give the equations for C1, C2, C3, C4? Better: use the CLA principle again! Second-level of abstraction!

An Example Determine gi, pi, Gi, Pi, and C1, C2, C3, C4 for the following two 16-bit numbers: a: b: Do it yourself

Speed of Ripple Carry vs. Carry Lookahead Example: Assume each AND and OR gate take the same time. Gate Delay is defined to be the number of gates along the critical path. Compare the gate delays of three 16-bit adder, one using ripple carry, one using first-level carry lookahead, and one using two- level carry lookahead.

Summary Traditional ALU can be built from a multiplexor plus a few gates that are replicated 32 times To tailor to MIPS ISA, we expand the traditional ALU with hardware for slt, beq, and overflow detection Carry lookahead is much faster than ripple carry! CLA principle can be applied multiple times!

Questions?