1 Modified from  Modified from 1998 Morgan Kaufmann Publishers Chapter Three: Arithmetic for Computers Section 2 citation and following credit line is.

Slides:



Advertisements
Similar presentations
©UCB CPSC 161 Lecture 6 Prof. L.N. Bhuyan
Advertisements

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 II CPSC 321 E. J. Kim. Today’s Menu Arithmetic-Logic Units Logic Design Revisited Faster Addition Multiplication (if time permits)
361 design.1 Computer Architecture ECE 361 Lecture 5: The Design Process & ALU Design.
1 Representing Numbers Using Bases Numbers in base 10 are called decimal numbers, they are composed of 10 numerals ( ספרות ) = 9* * *10.
ECE 232 L8.Arithm.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 8 Computer.
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.
1 Chapter 4: Arithmetic Where we've been: –Performance (seconds, cycles, instructions) –Abstractions: Instruction Set Architecture Assembly Language and.
Chapter Four Arithmetic and Logic Unit
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.
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)
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.
1 CS/COE0447 Computer Organization & Assembly Language Chapter 3.
1 Modified from  Modified from 1998 Morgan Kaufmann Publishers Chapter Three: Arithmetic for Computers citation and following credit line is included:
CS151B Computer Systems Architecture Winter 2002 TuTh 2-4pm BH
EGRE 426 Fall 09 Chapter Three
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.
Csci 136 Computer Architecture II – Constructing An Arithmetic Logic Unit Xiuzhen Cheng
EEL-4713C Computer Architecture Introduction: the Logic Design Process
1 Arithmetic Logic Unit ALU. 2 The Bus Concept 3 CPU Building Blocks  Registers (IR, PC, ACC)  Control Unit (CU)  Arithmetic Logic Unit (ALU)
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.
The Karnaugh Map.
Arithmetic.1 2/15 Computer Arithmetic ALU Performance is critical ( App. C5, C6 4 th ed.)
MIPS ALU. Building from the adder to ALU ALU – Arithmetic Logic Unit, does the major calculations in the computer, including – Add – And – Or – Sub –
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.
1 IKI20210 Pengantar Organisasi Komputer Kuliah No. 23: Aritmatika 18 Desember 2002 Bobby Nazief Johny Moningka
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
Cpu control.1 2/14 Datapath Components for Lab The Processor! ( th ed)
Prof. Hsien-Hsin Sean Lee
Gates AND, OR, NOT NAND, NOR Combinational logic No memory A set of inputs uniquely and unambiguously specifies.
COM181 Computer Hardware Lecture 6: The MIPs CPU.
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.
MIPS ALU. Exercise – Design a selector? I need a circuit that takes two input bits, a and b, and a selector bit s. The function is that if s=0, f=a. if.
9/23/2004Comp 120 Fall September Chapter 4 – Arithmetic and its implementation Assignments 5,6 and 7 posted to the class web page.
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.
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.
CS352H: Computer Systems Architecture
5. Combinational circuits
Arithmetic Where we've been:
Topic 3b Computer Arithmetic: ALU Design
MIPS ALU.
Computer Architecture EECS 361 Lecture 5: The Design Process & ALU Design Just like lat time, I like to start today’s lecture with a recap of our last.
COSC 2021: Computer Organization Instructor: Dr. Amir Asif
Topic 3b Computer Arithmetic: ALU Design
CS/COE0447 Computer Organization & Assembly Language
CS/COE0447 Computer Organization & Assembly Language
COMS 361 Computer Organization
A 1-Bit Arithmetic Logic Unit
October 8 Rules for Programming Assignments ASK QUESTIONS!
Presentation transcript:

1 Modified from  Modified from 1998 Morgan Kaufmann Publishers Chapter Three: Arithmetic for Computers Section 2 citation and following credit line is included: 'Copyright 1998 Morgan Kaufmann Publishers.' Permission is granted to alter and distribute this material provided that the following credit line is included: 'Adapted from Computer Organization & Design, The hardware/Software Interface, Patterson and Hennesy, second edition, Copyright 1998 Morgan Kaufmann Publishers.' " This material may not be copied or distributed for commercial purposes without express written permission of the copyright holder.

2 Modified from  Modified from 1998 Morgan Kaufmann Publishers Computer Arithmetic Overall Outline The outline for the entire subject of Computer Arithmetic is given below. However, for the sake of readability, the subject is divided into logical sections that can be presented together. The outline for each section will indicate what is covered in that specific section. Introduction Numbers and their representation 2’s Complement Detecting Overflow Basic Review –Binary Conversion –Binary Arithmetic –Hex & Octal Numbers –Basic Boolean Algebra Design Process Design of a “Fast” ALU for MIPS ISA Faster Design, Carry-Look-Ahead Adder

3 Modified from  Modified from 1998 Morgan Kaufmann Publishers Computer Arithmetic Overall Outline continued Additional MIPS Requirements Elements of Design Process Summary of Design Process MIPS Arithmetic Instructions Multiplication methods Division Methods Floating Point Summary

4 Modified from  Modified from 1998 Morgan Kaufmann Publishers Computer Arithmetic Section 2 Outline In this unit we will cover: Design Process Design a “Fast” ALU for the MIPS ISA –Requirements –ALU to do one-bit andi, ori instructions –32-bit ALU (Ripple Carry) –Expand ALU to support other operations –Test for equality –Overflow –Performance Question

5 Modified from  Modified from 1998 Morgan Kaufmann Publishers The Design Process "To Design Is To Represent" Design activity yields description/representation of an object -- Traditional craftsman does not distinguish between the conceptualization and the artifact -- Separation comes about because of complexity -- The concept is captured in one or more representation languages -- This process IS design Design Begins With Requirements -- Functional Capabilities: what it will do -- Performance Characteristics: Speed, Power, Area, Cost,...

6 Modified from  Modified from 1998 Morgan Kaufmann Publishers Design Process (cont.) Design Finishes As Assembly -- Design understood in terms of components and how they have been assembled -- Top Down decomposition of complex functions (behaviors) into more primitive functions -- bottom-up composition of primitive building blocks into more complex assemblies CPU DatapathControl ALURegsShifter Nand Gate Design is a "creative process," not a simple method

7 Modified from  Modified from 1998 Morgan Kaufmann Publishers Design Refinement Informal System Requirement Initial Specification Intermediate Specification Final Architectural Description Intermediate Specification of Implementation Final Internal Specification Physical Implementation refinement increasing level of detail

8 Modified from  Modified from 1998 Morgan Kaufmann Publishers Design as Search Design involves educated guesses and verification -- Given the goals, how should these be prioritized? -- Given alternative design pieces, which should be selected? -- Given design space of components & assemblies, which part will yield the best solution? Feasible (good) choices vs. Optimal choices Problem A Strategy 1Strategy 2 SubProb 1 SubProb2 SubProb3 BB1BB2BB3BBn

9 Modified from  Modified from 1998 Morgan Kaufmann Publishers Problem: Design a “fast” ALU for the MIPS ISA Requirements? Must support the Arithmetic / Logic operations Tradeoffs of cost and speed based on frequency of occurrence, hardware budget

10 Modified from  Modified from 1998 Morgan Kaufmann Publishers MIPS ALU requirements Add, AddU, Sub, SubU, AddI, AddIU –=> 2’s complement adder/sub with overflow detection And, Or, AndI, OrI, Xor, Xori, Nor –=> Logical AND, logical OR, XOR, nor SLTI, SLTIU (set less than) –=> 2’s complement adder with inverter, check sign bit of result ALU from P&H book chapter 3 (Appendix B) supports these operations

11 Modified from  Modified from 1998 Morgan Kaufmann Publishers MIPS arithmetic instruction format Signed arithmetic generate overflow, no carry R-type: I-Type: opRsRtRdfunct opRsRtImmed 16 Typeopfunct ADDI10xx ADDIU11xx SLTI12xx SLTIU13xx ANDI14xx ORI15xx XORI16xx LUI17xx Typeopfunct ADD0040 ADDU0041 SUB0042 SUBU0043 AND0044 OR0045 XOR0046 NOR0047 Typeopfunct SLT0052 SLTU0053

12 Modified from  Modified from 1998 Morgan Kaufmann Publishers Design Trick: divide & conquer Break the problem into simpler problems, solve them and glue together the solution Example: assume the immediates have been taken care of before the ALU –10 operations (4 bits) 00add 01addU 02sub 03subU 04and 05or 06xor 07nor 12slt 13sltU

13 Modified from  Modified from 1998 Morgan Kaufmann Publishers Refined Requirements (1) Functional Specification inputs: 2 x 32-bit operands A, B, 4-bit mode (control) outputs:32-bit result S, 1-bit carry, 1 bit overflow 10 Operations (m):add, addu, sub, subu, and, or, xor, nor, slt, sltU (2) Block Diagram ALU AB m ovf S 32 4 c

14 Modified from  Modified from 1998 Morgan Kaufmann Publishers Different Implementations 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: –Lets represent our 1-bit full adders with the following block diagram How could we build a 1-bit ALU for add, and, and or? How could we build a 32-bit ALU? c out = a b + a c in + b c in sum = a XOR b XOR c in

15 Modified from  Modified from 1998 Morgan Kaufmann Publishers Selects one of the inputs to be the output, based on a control input Lets build our ALU using a MUX: S C A B 0 1 Review: The Multiplexor note: we call this a 2-input mux even though it has 3 inputs! The S input, select, is control

16 Modified from  Modified from 1998 Morgan Kaufmann Publishers Building a 32 bit ALU (Ripple Carry) 1-bit ALU doing add, and, or 32-bit ALU capable of add, and,or The adder Designed by Directly linking The carries of 1-bit adders in This fashion is Called a ripple Carry adder

17 Modified from  Modified from 1998 Morgan Kaufmann Publishers Two's complement approach: just negate b and add 1. How do we negate in control logic? –A solution: What about subtraction (a – b) ? BinvertCarryIn Least significant bit Oper ation Result A+b’+1 (a-b) A+b

18 Modified from  Modified from 1998 Morgan Kaufmann Publishers Add, and, or, subtract are common to all ALU operations. Now lets try an operation more specific to MIPS Need to support the set-on-less-than instruction (slt) –remember: slt is an arithmetic instruction –produces a 1 in the least significant bit if rs < rt and 0 otherwise –use subtraction: (a-b) < 0 implies a < b Need to support test for equality (beq $t5, $t6, $t7) –use subtraction: (a-b) = 0 implies a = b So now we use a new input for our ALU called “Less”. –The least significant bit of Less will be the most significant bit (bit 32) called “set” of the output of the adder performing a 2’s complement. All other bits of Less will be 0. –Lets See: Tailoring the ALU to the MIPS

Supporting slt To perform slt, Binvert = 1, CarryIn = 1, Operation = 3 1-bit block diagram Least significant bit of Less = The most significant bit (Set) of the output of the adder, all other bits of Less are 0s Comes From Set For block 32

20 Modified from  Modified from 1998 Morgan Kaufmann Publishers 32-bit ALU Block Diagram Only this Less input Is Set and is bit 32 of The result of 2’s complement All other Less inputs are 0

21 Modified from  Modified from 1998 Morgan Kaufmann Publishers Some Improvement Note that when the ALU operation requires subtraction, the Binvert and CarryIn inputs are both set to one for 2’s complement of b. We can simplify the control by combining CarryIn and Binvert into one control called “Bnegate”. Bnegate is 1 for all ALU operations requiring subtraction. Bnegate is 0 for additions and logical operations.

22 Modified from  Modified from 1998 Morgan Kaufmann Publishers Test for equality Notice control lines: Bnegate Operation 000 = and 001 = or 010 = add 110 = subtract 111 = slt Note: Zero is a 1 when the result is 0! Zero = ( Result 31 + … + Result 0)’ So now our ALU can also test for a = b

23 Modified from  Modified from 1998 Morgan Kaufmann Publishers Revised Diagram LSB and MSB need to do a little extra AB M S 32 4 Ovflw ALU0 a0b0 cinco s0 ALU0 a31b31 cinco s31 C/L (combinationa l Logic) to produce select, comp, c-in ?

24 Modified from  Modified from 1998 Morgan Kaufmann Publishers Overflow (Remember) Examples: = 10 but = - 9 but... 2’s ComplementBinaryDecimal Decimal – 6 – 4 – 5 7

25 Modified from  Modified from 1998 Morgan Kaufmann Publishers Overflow Detection Overflow: the result is too large (or too small) to represent properly –Example: - 8 < = 4-bit binary number <= 7 When adding operands with different signs, overflow cannot occur! Overflow occurs when adding: –2 positive numbers and the sum is negative –2 negative numbers and the sum is positive On your own: Prove you can detect overflow by: –Carry into MSB  Carry out of MSB – 6 –4 – 5 7 0

26 Modified from  Modified from 1998 Morgan Kaufmann Publishers Overflow Detection Logic Carry into MSB  Carry out of MSB –For a N-bit ALU: Overflow = CarryIn[N - 1] XOR CarryOut[N - 1] A0 B0 1-bit ALU Result0 CarryIn0 CarryOut0 A1 B1 1-bit ALU Result1 CarryIn1 CarryOut1 A2 B2 1-bit ALU Result2 CarryIn2 A3 B3 1-bit ALU Result3 CarryIn3 CarryOut3 Overflow XYX XOR Y

27 Modified from  Modified from 1998 Morgan Kaufmann Publishers More Revised Diagram LSB and MSB need to do a little extra AB M = control S 32 4 Ovflw ALU0 a0b0 cinco s0 ALU31 a31b31 cinco s31 C/L to produce select, comp, c-in signed-arith and cin xor co Insert Logic For Overflow here

28 Modified from  Modified from 1998 Morgan Kaufmann Publishers But What about Performance? Critical Path (CP) of n-bit Rippled-carry adder is n*CP of 1-bit ALU A0 B0 1-bit ALU Result0 CarryIn0 CarryOut0 A1 B1 1-bit ALU Result1 CarryIn1 CarryOut1 A2 B2 1-bit ALU Result2 CarryIn2 CarryOut2 A3 B3 1-bit ALU Result3 CarryIn3 CarryOut3

29 Modified from  Modified from 1998 Morgan Kaufmann Publishers Is a 32-bit ALU as fast as a 1-bit ALU? Is there more than one way to do addition? –two extremes: ripple carry and sum-of-products (only requires 2 levels of logic) Can you see the ripple? How could you get rid of it? c 1 = b 0 c 0 + a 0 c 0 + a 0 b 0 c 2 = b 1 c 1 + a 1 c 1 + a 1 b 1 c 2 = c 3 = b 2 c 2 + a 2 c 2 + a 2 b 2 c 3 = c 4 = b 3 c 3 + a 3 c 3 + a 3 b 3 c 4 = Not feasible! Why? Problem: ripple carry adder is slow Design Trick: throw hardware at it