1 (Based on text: David A. Patterson & John L. Hennessy, Computer Organization and Design: The Hardware/Software Interface, 3 rd Ed., Morgan Kaufmann,

Slides:



Advertisements
Similar presentations
Arithmetic for Computers
Advertisements

©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 II CPSC 321 E. J. Kim. Today’s Menu Arithmetic-Logic Units Logic Design Revisited Faster Addition Multiplication (if time permits)
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.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Computer Organization Lecture 6 - Logic &
1  2004 Morgan Kaufmann Publishers Chapter Three.
Arithmetic II CPSC 321 Andreas Klappenecker. Any Questions?
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.
Arithmetic for Computers
1 Bits are just bits (no inherent meaning) — conventions define relationship between bits and numbers Binary numbers (base 2)
1 Modified from  Modified from 1998 Morgan Kaufmann Publishers Chapter Three: Arithmetic for Computers citation and following credit line is included:
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.
Csci 136 Computer Architecture II – Constructing An Arithmetic Logic Unit Xiuzhen Cheng
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.
1 Arithmetic I Instructor: Mozafar Bag-Mohammadi Ilam University.
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.
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.
Computer Architecture Lecture Notes Spring 2005 Dr. Michael P. Frank Competency Area 4: Computer Arithmetic.
Addition, Subtraction, Logic Operations and ALU Design
순천향대학교 정보기술공학부 이 상 정 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.
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.
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.
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.
Computer System Design Lecture 3
Computer Arthmetic Chapter Four P&H.
ECE/CS 552: Arithmetic and Logic
Instructions - Type and Format
5. Combinational circuits
Arithmetic Where we've been:
MIPS ALU.
Systems Architecture I
ECE232: Hardware Organization and Design
Rocky K. C. Chang 6 November 2017
CS/COE0447 Computer Organization & Assembly Language
CS/COE0447 Computer Organization & Assembly Language
COMS 361 Computer Organization
Instructor: Mozafar Bag-Mohammadi University of Ilam
A 1-Bit Arithmetic Logic Unit
October 8 Rules for Programming Assignments ASK QUESTIONS!
Fixed Point Arithmetic Operations
COMS 361 Computer Organization
Presentation transcript:

1 (Based on text: David A. Patterson & John L. Hennessy, Computer Organization and Design: The Hardware/Software Interface, 3 rd Ed., Morgan Kaufmann, 2007) Computer Arithmetic

2 COURSE CONTENTS Introduction Instructions è Computer Arithmetic Performance Processor: Datapath Processor: Control Pipelining Techniques Memory Input/Output Devices

3 COMPUTER ARITHMETIC Arithmetic Logic Unit (ALU) Fast Adder

4 Foundation Knowledge Decimal, Binary, Octal, & Hexadecimal Numbers Signed & Unsigned Numbers 2’s Complement Representation 2’s Complement Negation, Addition, & Subtraction Overflow Sign Extension ASCII vs Binary Boolean Algebra Logic Design Assembly Language

5 Numbers Bits are just bits (no inherent meaning) Conventions define relationship between bits and numbers Binary numbers (base 2) decimal: n – 1 Of course it gets more complicated: Numbers are finite (overflow) Fractions and real numbers Negative numbers E.g., no MIPS subi instruction; addi can add a negative number How do we represent negative numbers? I.e., which bit patterns will represent which numbers?

6 Possible Representations Three representations Sign Magnitude: One's Complement Two's Complement 000 = = = = = = = = = = = = = = = = = = = = = = = = -1 Issues: balance, number of zeros, ease of operations Which one is best? Why?

7 MIPS 32 bit signed numbers: two = 0 ten two = + 1 ten two = + 2 ten two = + 2,147,483,646 ten two = + 2,147,483,647 ten two = – 2,147,483,648 ten two = – 2,147,483,647 ten two = – 2,147,483,646 ten two = – 3 ten two = – 2 ten two = – 1 ten maxint: + 2,147,483,647 ten minint: – 2,147,483,648 ten

8 Two’s Complement Operations 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)

9 Additional MIPS Instructions Character transfer lbu $s1, 100($s2)# $s1  memory [$s2+100] (load byte unsigned) sb $s1, 100($s2)# memory [$s2+100]  $s1 (store byte) Conditions sltu $s2, $s3, $s4# if ($s3) < ($s4) then $s2  1; # else $s2  0 (set on less than, unsigned numbers) # Note that slt works on 2’ complement numbers Arithmetic on unsigned numbers addu $s1, $s2, $s3# $s1  $s2 + $s3 (no overflow detection) subu $s1, $s2, $s3# $s1  $s2 - $s3 (no overflow detection) addiu $s1, $s2, 100 # $s1  $s (no overflow detection) MIPS detects overflow with an exception (interrupt), which is an unscheduled procedure call. MIPS includes a register, called exception program counter (EPC) to contain the address of the instruction that caused the exception mfc0 $s1, $epc # $s1  $epc (move from special registers)

10 Shift operations sll $t2, $s0, 8 # $t2  $s0 >10 (shift right by constant) Fill the emptied bits with 0’s Logical operations and $s1, $s2, $s3 # $s1  $s2 and $s3 (bit-by-bit and) or $s1, $s2, $s3 # $s1  $s2 or $s3 (bit-by-bit or) andi $s1, $s2, 100 # $s1  $s2 and 100 ori $s1, $s2, 100 # $s1  $s2 or 100 Op=0 rs=0 rt=16 rd=10 shamt=8 funct=0 sll $t2, $s0, 8 Additional MIPS Instructions

11 ALU: Arithmetic Logic Unit Performs arithmetic (e.g. add) & logical operations (e.g. and) in CPU ControlFunctResult 000andA and B 001orA or B 010addA + B 110subA - B 111slt1 if A<B A B ALU operation Zero Result Overflow 32 Carryout 32

12 ALU Building Blocks 1-bit adder Gates, multiplexor c out = a b + a c in + b c in sum = a  b  c in Note: Cin is carryin, cout is carryout Sum CarryIn C arryOut a b

13 A Simple ALU b 0 2 Result Operation a 1 CarryIn CarryOut A 1-bit ALU that performs AND, OR, and addition (shown below) Building a 32-bit ALU (shown right)

14 Two's complement approach: just negate b and add. How do we negate? By selecting Binvert = 1, and setting CarryIn =1 in the least significant bit of ALU, we get 2’s complement subtraction a - b ALU: Subtraction 0 2 Result Operation a 1 CarryIn CarryOut 0 1 Binvert b

15 To support set-on-less-than instruction (slt) slt is an arithmetic instruction produces a 1 if rs < rt and 0 otherwise use subtraction: (a-b) < 0 implies a < b use a Set & a Less signal to indicate result To support test for equality (beq) use subtraction: (a-b) = 0 implies a = b ALU: Additional Operations

16 ALU: Additional Operations 0 3 Result Operation a 1 CarryIn CarryOut 0 1 Binvert b 2 Less A 1-bit ALU that performs AND, OR, add, subtract: Less is used for slt instruction (see 32-bit ALU next slide) The ALU for the most significant bit: Set is used for slt instruction, it is connected to Less of lsb (see 32-bit ALU next slide) Overflow detection needed on msb 0 3 Result Operation a 1 CarryIn 0 1 Binvert b 2 Less Set(sign) Overflow detection Overflow

17 A 32-bit ALU that performs AND, OR, add, & subtract For subtract, set Binvert = 1 and CarryIn =1 (for add or logical operations, both set to 0) Can combine Binvert & CarryIn to Bnegate Set and Less, together with subtraction, can be used for slt Set(sign) a31 0 ALU0 Result0 CarryIn a0 Result1 a1 0 Result2 a2 0 Operation b31 b0 b1 b2 Result31 Overf l ow Binvert CarryI n Less CarryIn CarryOu t ALU1 Less CarryIn CarryOut ALU2 Less CarryIn CarryOut ALU31 Less CarryIn CarryOut A 32-bit ALU

18 A Final 32-bit ALU Add a zero detector to test for zero results or equality (e.g. in beq instruction) Control lines (Operation) (3-bit): 000 = and 001 = or 010 = add 110 = subtract 111 = slt bit1 & bit0 to multiplexors in ALU bit2 to Bnegate Note: zero is a 1 when the result is zero! Set a31 0 Result0 a0 Result1 a1 0 Result2 a2 0 Operation b31 b0 b1 b2 Result31 Overflow Bnegate Zero ALU0 Less CarryIn CarryOut ALU1 Less CarryIn CarryOut ALU2 Less CarryIn CarryOut ALU31 Less CarryIn 3 bits (Sign) CarryOut 1 bit 2 bits

19 ALU Design: Summary Select building blocks: adders, gates Use multiplexors to select the output we want Perform subtraction using two’s complement Replicate a 1-bit ALU to produce a 32-bit ALU --> regularity Need circuit to detect conditions e.g. zero result, overflow, sign, carry out Shift instructions: Done outside the ALU by barrel shifter, which can shift from 1 to 31 bits in no more time than it takes to add two 32 bit numbers using carry lookahead adders Important points about hardware all of the gates are always working the speed of a gate is affected by the number of inputs to the gate the speed of a circuit is affected by the number of gates in series (on the “critical path” or the “deepest level of logic”) Our primary focus: comprehension, however, Clever changes to organization can improve performance (similar to using better algorithms in software)

20 Ripple carry adder is just too slow: The sequential chain reaction is too slow for time-critical hardware 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 Can you see the ripple? How could you get rid of it? Carry Lookahead Adder ++++

21 Carry lookahead adder (CLA): an approach in-between our two extremes Motivation: If we didn't know the value of carry-in, what could we do? When would we always generate a carry? g i = a i b i When would we propagate the carry? p i = a i + b i Did we get rid of the ripple? c i+1 = g i + p i c i c 1 = g 0 + p 0 c 0 c 2 = g 1 + p 1 c 1 = g 1 + p 1 g 0 + p 1 p 0 c 0 c 3 = g 2 + p 2 c 2 = g 2 + p 2 g 1 + p 2 p 1 g 0 + p 2 p 1 p 0 c 0 c 4 = g 3 + p 3 c 3 = g 3 + p 3 g 2 + p 3 p 2 g 1 + p 3 p 2 p 1 g 0 + p 3 p 2 p 1 p 0 c 0 è Carry lookahead! Carry Lookahead Adder

22 Can’t build a 16 bit adder using the g i & p i CLA method --> too big Could use ripple carry of 4-bit CLA adders Better: use the CLA principle again! (see left figure) Building Bigger Adders CarryIn Result0--3 ALU0 CarryIn Result4--7 ALU1 CarryIn Result8--11 ALU2 CarryIn CarryOut Result ALU3 CarryIn C1 C2 C3 C4 P0 G0 P1 G1 P2 G2 P3 G3 pi gi pi + 1 gi + 1 ci + 1 ci + 2 ci + 3 ci + 4 pi + 2 gi + 2 pi + 3 gi + 3 a0 b0 a1 b1 a2 b2 a3 b3 a4 b4 a5 b5 a6 b6 a7 b7 a8 b8 a9 b9 a10 b10 a11 b11 a12 b12 a13 b13 a14 b14 a15 b15 Carry-lookahead unit

23 Summary Review number system Additional MIPS instructions The design of an ALU Carry lookahead adder