CS352H: Computer Systems Architecture

Slides:



Advertisements
Similar presentations
Morgan Kaufmann Publishers Arithmetic for Computers
Advertisements

Chapter 3 Arithmetic for Computers. Chapter 3 — Arithmetic for Computers — 2 Arithmetic for Computers Operations on integers Addition and subtraction.
CS/ECE 3330 Computer Architecture Chapter 3 Arithmetic.
Chapter 3 Arithmetic for Computers. Exam 1 CSCE
Arithmetic for Computers
Datorteknik IntegerMulDiv bild 1 MIPS mul/div instructions Multiply: mult $2,$3Hi, Lo = $2 x $3;64-bit signed product Multiply unsigned: multu$2,$3Hi,
Lecture 20: Hardware for Arithmetic Today’s topic –Carry Look-Ahead Adder 1.
Lecture 15: Computer Arithmetic Today’s topic –Division 1.
CMPT 334 Computer Organization Chapter 3 Arithmetic for Computers [Adapted from Computer Organization and Design 5 th Edition, Patterson & Hennessy, ©
Lecture Objectives: 1)Perform binary division of two numbers. 2)Define dividend, divisor, quotient, and remainder. 3)Explain how division is accomplished.
Chapter 3 Arithmetic for Computers. Multiplication More complicated than addition accomplished via shifting and addition More time and more area Let's.
361 div.1 Computer Architecture ECE 361 Lecture 7: ALU Design : Division.
Lecture 9 Sept 28 Chapter 3 Arithmetic for Computers.
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 4: Arithmetic / Data Transfer Instructions Partially adapted from Computer Organization.
Integer Multiplication and Division ICS 233 Computer Architecture and Assembly Language Dr. Aiman El-Maleh College of Computer Sciences and Engineering.
Computer Organization Multiplication and Division Feb 2005 Reading: Portions of these slides are derived from: Textbook figures © 1998 Morgan Kaufmann.
1 Lecture 8: Binary Multiplication & Division Today’s topics:  Addition/Subtraction  Multiplication  Division Reminder: get started early on assignment.
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 6: Logic/Shift Instructions Partially adapted from Computer Organization and Design, 4.
Lecture Objectives: 1)Explain the relationship between addition and subtraction with twos complement numbering systems 2)Explain the concept of numeric.
Lec 13Systems Architecture1 Systems Architecture Lecture 13: Integer Multiplication and Division Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan.
CSF 2009 Arithmetic for Computers Chapter 3. Arithmetic for Computers Operations on integers Addition and subtraction Multiplication and division Dealing.
Lecture 6: Multiply, Shift, and Divide
Csci 136 Computer Architecture II – Constructing An Arithmetic Logic Unit Xiuzhen Cheng
Chapter 3 Arithmetic for Computers (Integers). Florida A & M University - Department of Computer and Information Sciences Arithmetic for Computers Operations.
05/03/2009CA&O Lecture 8,9,10 By Engr. Umbreen sabir1 Computer Arithmetic Computer Engineering Department.
Integer Multiplication and Division
Integer Multiplication and Division ICS 233 Computer Architecture and Assembly Language Dr. Aiman El-Maleh College of Computer Sciences and Engineering.
Csci 136 Computer Architecture II – Multiplication and Division
Chapter 3 Arithmetic for Computers. Chapter 3 — Arithmetic for Computers — 2 Arithmetic for Computers Operations on integers Addition and subtraction.
EI 209 Chapter 3.1CSE, 2015 EI 209 Computer Organization Fall 2015 Chapter 3: Arithmetic for Computers Haojin Zhu ( )
Division Check for 0 divisor Long division approach – If divisor ≤ dividend bits 1 bit in quotient, subtract – Otherwise 0 bit in quotient, bring down.
CDA 3101 Spring 2016 Introduction to Computer Organization
Integer Multiplication, Division Arithmetic shift Twice the number of places MIPS multiply unit. mult, multu Significant bits Mfhi, mflo, div, divu Arithmetic.
1 Lecture 11: Hardware for Arithmetic Today’s topics:  Logic for common operations  Designing an ALU  Carry-lookahead adder.
Integer Multiplication and Division COE 301 Computer Organization Dr. Muhamed Mudawar College of Computer Sciences and Engineering King Fahd University.
By Wannarat Computer System Design Lecture 3 Wannarat Suntiamorntut.
Integer Multiplication and Division ICS 233 Computer Architecture & Assembly Language Prof. Muhamed Mudawar College of Computer Sciences and Engineering.
Arithmetic for Computers Chapter 3 1. Arithmetic for Computers  Operations on integers  Addition and subtraction  Multiplication and division  Dealing.
Computer System Design Lecture 3
More Binary Arithmetic - Multiplication
Computer Architecture & Operations I
ALU Architecture and ISA Extensions
Computer Architecture & Operations I
Lecture Adders Half adder.
Integer Multiplication and Division
MIPS mul/div instructions
Single Bit ALU 3 R e s u l t O p r a i o n 1 C y I B v b 2 L S f w d O
Morgan Kaufmann Publishers Arithmetic for Computers
Morgan Kaufmann Publishers Arithmetic for Computers
Morgan Kaufmann Publishers
Addition and multiplication
Morgan Kaufmann Publishers
Ch 3: Computer Arithmetic
Lecture 8: Binary Multiplication & Division
CDA 3101 Summer 2007 Introduction to Computer Organization
Lecture 8: Addition, Multiplication & Division
Lecture 8: Addition, Multiplication & Division
Computer Architecture Computer Science & Engineering
Topic 3c Integer Multiply and Divide
Lecture 12: Adders, Sequential Circuits
Lecture 12: Adders, Sequential Circuits
CS 140 Lecture 14 Standard Combinational Modules
CSE 140 Lecture 14 Standard Combinational Modules
Addition and multiplication
Instructor: Mozafar Bag-Mohammadi University of Ilam
Addition and multiplication
Computer Architecture EECS 361 Lecture 6: ALU Design
CSC3050 – Computer Architecture
Morgan Kaufmann Publishers Arithmetic for Computers
Number Representation
Presentation transcript:

CS352H: Computer Systems Architecture Lecture 5: MIPS Integer ALU September 10, 2009

Integer Addition Example: 7 + 6 Overflow if result out of range Adding +ve and –ve operands, no overflow Adding two +ve operands Overflow if result sign is 1 Adding two –ve operands Overflow if result sign is 0 University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 2

Integer Subtraction Add negation of second operand Example: 7 – 6 = 7 + (–6) +7: 0000 0000 … 0000 0111 –6: 1111 1111 … 1111 1010 +1: 0000 0000 … 0000 0001 Overflow if result out of range Subtracting two +ve or two –ve operands, no overflow Subtracting +ve from –ve operand Overflow if result sign is 0 Subtracting –ve from +ve operand Overflow if result sign is 1 University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 3

Dealing with Overflow Some languages (e.g., C) ignore overflow Use MIPS addu, addui, subu instructions Other languages (e.g., Ada, Fortran) require raising an exception Use MIPS add, addi, sub instructions On overflow, invoke exception handler Save PC in exception program counter (EPC) register Jump to predefined handler address mfc0 (move from coprocessor reg) instruction can retrieve EPC value, to return after corrective action University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 4

Throw Hardware At It: Money is no Object! Using ci for CarryIni c2 = b1c1 + a1c1 + a1b1 and c1 = b0 c0 + a0 c0 + a0b0 Substituting for c1, we get: c2 = a1a0b0 + a1a0c0 + a1b0c0 + b1a0b0 + b1a0c0 + b1b0c0 + a1b1 Continuing this to 32 bits yields a fast, but unreasonably expensive adder Just how fast? Assume all gate delays are the same regardless of fan-in University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 5

Carry-Lookahead Adders The basic formula can be rewritten: ci+1 = bici + aici + aibi ci+1 = aibi + (ai + bi)ci Applying it to c2, we get: c2 = a1b1 + (a1 + b1)(a0b0 + (a0 + b0)c0) Define two “signals” or abstractions: Generate: gi = ai * bi Propagate: pi = ai + bi Redefine ci+1 as: ci+1 = gi + pi * ci So ci+1 = 1 if gi = 1 (generate) or pi = 1 and ci = 1 (propagate) University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 6

Carry-Lookahead Adders Our logic equations are simpler: c1 = g0 + p0c0 c2 = g1 + p1g0 + p1p0c0 c3 = g2 + p2g1 + p2p1g0 + p2p1p0c0 c4 = g3 + p3g2 + p3p2g1 + p3p2p1g0 + p3p2p1p0c0 University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 7

Carry-Lookahead Adders ai bi ci+1 0 0 0 kill 0 1 ci propagate 1 0 ci propagate 1 1 1 generate a0 b0 s0 g0 p0 c1 = g0 + p0c0 a1 b1 s1 g1 p1 c2 = g1 + p1g0 + p1p0c0 a2 b2 s2 g2 p2 c3 = g2 + p2g1 + p2p1g0 + p2p1p0c0 a3 b3 s3 g3 p3 c4 = … University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 8

Carry-Lookahead Adders How much better (16-bit adder)? Ripple-carry: 16 * Tadd = 16 * 2 = 32 gate delays Carry-lookahead: Tadd + max (pi, gi) = 2 + 2 = 4 Much better, but still too profligate What if we apply another level of this abstraction? Use the four-bit adder on the previous slide as a building block Define P and G signals P0 = p3p2p1p0 G0 = g3 + p3g2 + p3p2g1 + p3p2p1g0 Similarly for P1 – P3 and G1 – G3 Derive equations for C1 – C4 C1 = G0 + P0 c0 C2 = G1 + P1G0 + P1P0c0, etc. See discussion in Appendix C.6 University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 9

Carry-Lookahead Adders 16-bit adder performance = Tadd + max (Pi, Gi) = 2 + 2 + 1 = 5 (with thrifty hardware) University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 10

Arithmetic for Multimedia Graphics and media processing operates on vectors of 8-bit and 16-bit data Use 64-bit adder, with partitioned carry chain Operate on 8×8-bit, 4×16-bit, or 2×32-bit vectors SIMD (single-instruction, multiple-data) Saturating operations On overflow, result is largest representable value c.f. 2s-complement modulo arithmetic E.g., clipping in audio, saturation in video University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 11

Shifters Two kinds: Logical: value shifted in is always “0” Arithmetic: sign-extend on right shifts What about n-bit, rather than 1-bit, shifts? Want a fast shifter University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 12

Combinatorial Shifter from MUXes University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 13

Unsigned Multiplication Paper and pencil example (unsigned): Multiplicand 1 0 0 0 Multiplier 1 0 0 1 1 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 m bits x n bits = m+n bit product Binary makes it easy: 0: place 0 (0 x multiplicand) 1: place copy (1 x multiplicand) University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 14

Unsigned Combinatorial Multiplier Stage i accumulates A * 2i if Bi == 1 University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 15

How Does it Work? At each stage shift A left (x2) Use next bit of B to determine whether to add in shifted multiplicand Accumulate 2n bit partial product at each stage University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 16

Sequential Multiplication Hardware Initially 0 University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 17

Observations One clock per multiply cycle ~32 clock cycles per integer multiply Vs. one cycle for an add/subtract Half of the bits in the multiplicand are always zero 64-bit adder is wasted Zeros inserted in left of multiplicand as shifted Least significant bits of product unchanged once formed Instead of shifting multiplicand to left, shift product to right! University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 18

Optimized Multiplier Perform steps in parallel: add/shift One cycle per partial-product addition That’s ok, if frequency of multiplications is low University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 19

Faster Multiplier Uses multiple adders Can be pipelined Cost/performance tradeoff Can be pipelined Several multiplication performed in parallel University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 20

MIPS Multiplication Two 32-bit registers for product Instructions HI: most-significant 32 bits LO: least-significant 32-bits Instructions mult rs, rt / multu rs, rt 64-bit product in HI/LO mfhi rd / mflo rd Move from HI/LO to rd Can test HI value to see if product overflows 32 bits mul rd, rs, rt Least-significant 32 bits of product –> rd University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 21

Division §3.4 Division Check for 0 divisor Long division approach If divisor ≤ dividend bits 1 bit in quotient, subtract Otherwise 0 bit in quotient, bring down next dividend bit Restoring division Do the subtract, and if remainder goes < 0, add divisor back Signed division Divide using absolute values Adjust sign of quotient and remainder as required quotient dividend 1001 1000 1001010 -1000 10 101 1010 divisor remainder n-bit operands yield n-bit quotient and remainder University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 22

Initially divisor in left half Division Hardware Initially divisor in left half Initially dividend University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 23

Optimized Divider One cycle per partial-remainder subtraction Looks a lot like a multiplier! Same hardware can be used for both University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 24

Faster Division Can’t use parallel hardware as in multiplier Subtraction is conditional on sign of remainder Faster dividers (e.g. SRT devision) generate multiple quotient bits per step Still require multiple steps University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 25

MIPS Division Use HI/LO registers for result Instructions HI: 32-bit remainder LO: 32-bit quotient Instructions div rs, rt / divu rs, rt No overflow or divide-by-0 checking Software must perform checks if required Use mfhi, mflo to access result University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 26

Next Lecture Floating point Rest of Chapter 3 University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 27