Arithmetic for Computers Chapter 3 1. Arithmetic for Computers  Operations on integers  Addition and subtraction  Multiplication and division  Dealing.

Slides:



Advertisements
Similar presentations
Morgan Kaufmann Publishers Arithmetic for Computers
Advertisements

Chapter 3 Arithmetic for Computers. Exam 1 CSCE
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.
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3:
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3: IT Students.
Chapter 3 Arithmetic for Computers. Multiplication More complicated than addition accomplished via shifting and addition More time and more area Let's.
CS 447 – Computer Architecture Lecture 3 Computer Arithmetic (2)
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.
1  2004 Morgan Kaufmann Publishers Chapter Three.
Chapter 6 Arithmetic. Addition Carry in Carry out
1 Lecture 8: Binary Multiplication & Division Today’s topics:  Addition/Subtraction  Multiplication  Division Reminder: get started early on assignment.
1 Lecture 4: Arithmetic for Computers (Part 5) CS 447 Jason Bakos.
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 6: Logic/Shift Instructions Partially adapted from Computer Organization and Design, 4.
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Hao Ji.
Lecture 12: Computer Arithmetic Today’s topic –Numerical representations –Addition / Subtraction –Multiplication / Division 1.
Computer Organization and Architecture Computer Arithmetic Chapter 9.
Computer Arithmetic Nizamettin AYDIN
Computer Arithmetic. Instruction Formats Layout of bits in an instruction Includes opcode Includes (implicit or explicit) operand(s) Usually more than.
Computer Architecture Lecture 3: Logical circuits, computer arithmetics Piotr Bilski.
Computer Arithmetic.
ECE232: Hardware Organization and Design
Lecture 7: Multiplication and Floating Point EEN 312: Processors: Hardware, Software, and Interfacing Department of Electrical and Computer Engineering.
Multiplication of signed-operands
CSF 2009 Arithmetic for Computers Chapter 3. Arithmetic for Computers Operations on integers Addition and subtraction Multiplication and division Dealing.
Fixed and Floating Point Numbers Lesson 3 Ioan Despi.
Chapter 3 Arithmetic for Computers (Integers). Florida A & M University - Department of Computer and Information Sciences Arithmetic for Computers Operations.
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3:
Lecture notes Reading: Section 3.4, 3.5, 3.6 Multiplication
Csci 136 Computer Architecture II – Multiplication and Division
Mohamed Younis CMCS 411, Computer Architecture 1 CMSC Computer Architecture Lecture 11 Performing Division March 5,
Chapter 3 Arithmetic for Computers. Chapter 3 — Arithmetic for Computers — 2 Arithmetic for Computers Operations on integers Addition and subtraction.
C OMPUTER O RGANIZATION AND D ESIGN The Hardware/Software Interface 5 th Edition Chapter 3 Arithmetic for Computers.
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
Morgan Kaufmann Publishers Arithmetic for Computers
Chapter 8 Computer Arithmetic. 8.1 Unsigned Notation Non-negative notation  It treats every number as either zero or a positive value  Range: 0 to 2.
By Wannarat Computer System Design Lecture 3 Wannarat Suntiamorntut.
Chapter 9 Computer Arithmetic
William Stallings Computer Organization and Architecture 8th Edition
Computer System Design Lecture 3
More Binary Arithmetic - Multiplication
Computer Architecture & Operations I
ALU Architecture and ISA Extensions
Multiplication and Division basics
Computer Architecture & Operations I
Morgan Kaufmann Publishers Arithmetic for Computers
Morgan Kaufmann Publishers
Morgan Kaufmann Publishers
Morgan Kaufmann Publishers
Ch 3: Computer Arithmetic
CDA 3101 Summer 2007 Introduction to Computer Organization
William Stallings Computer Organization and Architecture 7th Edition
Arithmetic for Computers
CS352H: Computer Systems Architecture
CSCE 350 Computer Architecture
Computer Arithmetic Multiplication, Floating Point
ECEG-3202 Computer Architecture and Organization
Chapter 8 Computer Arithmetic
Digital System Design II 数字系统设计2
Morgan Kaufmann Publishers Arithmetic for Computers
Presentation transcript:

Arithmetic for Computers Chapter 3 1

Arithmetic for Computers  Operations on integers  Addition and subtraction  Multiplication and division  Dealing with overflow  Floating-point real numbers  Representation and operations §3.1 Introduction 2

Integer Addition  Example: §3.2 Addition and Subtraction 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 3

Integer Subtraction  Add negation of second operand  Example: 7 – 6 = 7 + (–6) +7: … –6: … : …  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 4

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 (positive or negative)  c.f. 2s-complement modulo arithmetic  E.g., clipping in audio, saturation in video 5

Multiplication  Start with long-multiplication approach 1000 × Length of product is the sum of operand lengths multiplicand multiplier product §3.3 Multiplication 6

Multiplication Hardware Initially 0 7

Optimized Multiplier  Algorithm and hardware refined to take one clock cycle per step  Perform steps in parallel: add/shift One cycle per partial-product addition That’s ok, if frequency of multiplications is low The hardware is usually further optimized to halve the width of the adder and registers by noticing where there are unused portions of registers and adders 8

 Using 4-bit numbers to save space, multiply 2 ten × 3 ten, or 0010 two × 0011 two Multiplication - example 9

Faster Multiplier  Uses multiple adders  Cost/performance tradeoff Can be pipelined Several multiplication performed in parallel 10

LEGv8 Multiplication  Three multiply instructions:  MUL: multiply  Gives the lower 64 bits of the product  SMULH: signed multiply high  Gives the upper 64 bits of the product, assuming the operands are signed  UMULH: unsigned multiply high  Gives the lower 64 bits of the product, assuming the operands are unsigned 11

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 n-bit operands yield n-bit quotient and remainder quotient dividend remainder divisor §3.4 Division 12

Division Hardware Initially dividend Initially divisor in left half 13

 Using a 4-bit version of the algorithm, divide 7 ten by 2 ten, or two by 0010 two. Divide - example 14

Optimized Divider  One cycle per partial-remainder subtraction  The speed-up comes from shifting the operands and the quotient simultaneously with the subtraction.  This refinement halves the width of the adder and registers  Looks a lot like a multiplier!  Same hardware can be used for both 15

 Remember the signs of the divisor and dividend and then negate the quotient if the signs disagree -7  +2: quotient = -3  Remainder = (dividend – quotient x divisor) = -7 – (-3 x +2) =  +2: quotient = -3, remainder =  -2: quotient = -3, remainder =  -2: quotient = +3, remainder = -1  The correctly signed division algorithm negates the quotient if the signs of the operands are opposite and makes the sign of the nonzero remainder match the dividend Signed Division 16

Faster Division  Can’t use parallel hardware as in multiplier  Subtraction is conditional on sign of remainder  Faster dividers (e.g. SRT division) generate multiple quotient bits per step using a table lookup based on the upper bits of the dividend and remainder  Still require multiple steps  The accuracy of this fast method depends on having proper values in the lookup table 17

LEGv8 Division  Two instructions:  SDIV (signed)  UDIV (unsigned)  Both instructions ignore overflow and division-by-zero  LEGv8 software must check the divisor to discover division by 0 as well as overflow. 18

19

Floating Point  Representation for non-integral numbers  Including very small and very large numbers  Like scientific notation  –2.34 ×  × 10 –4  × 10 9  Normalized number: A number in floating-point notation that has no leading 0s  In binary  ±1.xxxxxxx 2 × 2 yyyy  Types float and double in C  Floating point: Computer arithmetic that represents numbers in which the binary point is not fixed normalized not normalized §3.5 Floating Point 20