Integer Division.

Slides:



Advertisements
Similar presentations
Computer Engineering FloatingPoint page 1 Floating Point Number system corresponding to the decimal notation 1,837 * 10 significand exponent A great number.
Advertisements

Topics covered: Floating point arithmetic CSE243: Introduction to Computer Architecture and Hardware/Software Interface.
Datorteknik FloatingPoint bild 1 Floating point Number system corresponding to the decimal notation 1,837 * 10 significand exponent a great number of corresponding.
Floating Point Numbers
CS 447 – Computer Architecture Lecture 3 Computer Arithmetic (2)
Computer ArchitectureFall 2007 © September 5, 2007 Karem Sakallah CS 447 – Computer Architecture.
Chapter 6 Arithmetic. Addition Carry in Carry out
Integer Arithmetic Floating Point Representation Floating Point Arithmetic Topics.
Floating Point Numbers
CPSC 321 Computer Architecture ALU Design – Integer Addition, Multiplication & Division Copyright 2002 David H. Albonesi and the University of Rochester.
Computer ArchitectureFall 2008 © August 27, CS 447 – Computer Architecture Lecture 4 Computer Arithmetic (2)
Simple Data Type Representation and conversion of numbers
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.
Fixed-Point Arithmetics: Part II
Computing Systems Basic arithmetic for computers.
Arithmetic Chapter 4.
Arithmetic Chapter 4.
Fundamental of Computer Architecture By Panyayot Chaikan November 01, 2003.
ECE232: Hardware Organization and Design
CH09 Computer Arithmetic  CPU combines of ALU and Control Unit, this chapter discusses ALU The Arithmetic and Logic Unit (ALU) Number Systems Integer.
Oct. 18, 2007SYSC 2001* - Fall SYSC2001-Ch9.ppt1 See Stallings Chapter 9 Computer Arithmetic.
CSC 221 Computer Organization and Assembly Language
Floating Point Arithmetic
Conversion to Larger Number of Bits Ex: Immediate Field (signed 16 bit) to 32 bit Positive numbers have implied 0’s to the left. So, put 16 bit number.
Lecture notes Reading: Section 3.4, 3.5, 3.6 Multiplication
Computer Arithmetic Floating Point. We need a way to represent –numbers with fractions, e.g., –very small numbers, e.g., –very large.
Computer Architecture Lecture 22 Fasih ur Rehman.
Computer Engineering FloatingPoint page 1 Floating Point Number system corresponding to the decimal notation 1,837 * 10 significand exponent A great number.
Chapter 3 Arithmetic for Computers. Chapter 3 — Arithmetic for Computers — 2 Arithmetic for Computers Operations on integers Addition and subtraction.
Floating Point Numbers Representation, Operations, and Accuracy CS223 Digital Design.
Dr Mohamed Menacer College of Computer Science and Engineering Taibah University CE-321: Computer.
Cosc 2150: Computer Organization Chapter 9, Part 3 Floating point numbers.
Chapter 9 Computer Arithmetic
William Stallings Computer Organization and Architecture 8th Edition
Arithmetic UNIT-V.
Floating Point Representations
More Binary Arithmetic - Multiplication
2.4. Floating Point Numbers
Lecture 9: Floating Point
Topics IEEE Floating Point Standard Rounding Floating Point Operations
Floating Point Number system corresponding to the decimal notation
CS/COE0447 Computer Organization & Assembly Language
Unit -2 ARITHMETIC.
William Stallings Computer Organization and Architecture 7th Edition
Topic 3d Representation of Real Numbers
CSCE 350 Computer Architecture
Number Representations
UNIT-6 Arithmetic Course code: 10CS46 Prepared by :
How to represent real numbers
ECEG-3202 Computer Architecture and Organization
Computer Architecture
Chapter 8 Computer Arithmetic
UNIVERSITY OF MASSACHUSETTS Dept
Topic 3d Representation of Real Numbers
UNIVERSITY OF MASSACHUSETTS Dept
Numbers with fractions Could be done in pure binary
Computer Organization and Assembly Language
Number Representations
Lecture 9: Shift, Mult, Div Fixed & Floating Point
Presentation transcript:

Integer Division

Manual Division 21 10101 13 1101 274 100010010 26 1101 14 10000 13 1101 1 1110 1101 1 Longhand division examples.

Circuit Arrangement Circuit arrangement for binary division. Shift left a a a q q n n - 1 n - 1 A Dividend Q Quotient setting n + 1 -bit Add/Subtract adder Control sequencer m m n - 1 Divisor M Circuit arrangement for binary division.

Restoring Division Shift A and Q left one binary position Subtract M from A, and place the answer back in A If the sign of A is 1, set q0 to 0 and add M back to A (restore A); otherwise, set q0 to 1 Repeat these steps n times

Examples A restoring-division example. 1 1 1 1 1 1 1 1 Initially 1 1 1 1 1 1 1 1 1 1 Initially 1 1 1 Shift 1 Subtract 1 1 1 1 First cycle Set q 1 1 1 1 Restore 1 1 1 Shift 1 Subtract 1 1 1 1 Set q 1 1 1 1 1 Second cycle Restore 1 1 1 Shift 1 Subtract 1 1 1 1 Set q 1 Third cycle Shift 1 1 Subtract 1 1 1 1 1 Set q 1 1 1 1 1 Fourth cycle Restore 1 1 1 1 Remainder Quotient A restoring-division example.

Nonrestoring Division Avoid the need for restoring A after an unsuccessful subtraction. Step 1: (Repeat n times) If the sign of A is 0, shift A and Q left one bit position and subtract M from A; otherwise, shift A and Q left and add M to A. Now, if the sign of A is 0, set q0 to 1; otherwise, set q0 to 0. Step2: If the sign of A is 1, add M to A

Examples A nonrestoring-division example. Initially 1 1 1 Shift 1 1 1 1 Shift 1 First cycle Subtract 1 1 1 1 Set q 1 1 1 1 Shift 1 1 1 Add 1 1 Second cycle Set q 1 1 1 1 1 Shift 1 1 1 1 Add 1 1 Third cycle Set q 1 1 Shift 1 1 Subtract 1 1 1 1 Fourth cycle Set q 1 1 1 1 1 1 Quotient Add 1 1 1 1 1 1 1 Restore remainder 1 Remainder A nonrestoring-division example.

Floating-Point Numbers and Operations

Floating-Point Numbers So far we have dealt with fixed-point numbers (what is it?), and have considered them as integers. Floating-point numbers: the binary point is just to the right of the sign bit. Where the range of F is: The position of the binary point is variable and is automatically adjusted as computation proceeds.

Floating-Point Numbers What are needed to represent a floating-point decimal number? Sign Mantissa (the significant digits) Exponent to an implied base (scale factor) “Normalized” – the decimal point is placed to the right of the first (nonzero) significant digit.

IEEE Standard for Floating-Point Numbers Think about this number (all digits are decimal): ±X1.X2X3X4X5X6X7×10±Y1Y2 It is possible to approximate this mantissa precision and scale factor range in a binary representation that occupies 32 bits: 24-bit mantissa (1 sign bit for signed number), 8-bit exponent. Instead of the signed exponent, E, the value actually stored in the exponent field is an unsigned integer E’=E+127, so called excess-127 format

IEEE Standard 32 bits S E ¢ M Sign of 8-bit signed 23-bit number : exponent in mantissa fraction 0 signifies + excess-127 1 signifies - representation E ¢ - 127 Value represented = ± 1. M ´ 2 (a) Single precision 1 1 1 1 . . . ¼ - 87 (101000)2=4010, 40-127=-87 Value represented = 1.001010 ´ 2 (b) Example of a single-precision number 64 bits S E ¢ M Sign 11-bit excess-1023 52-bit exponent mantissa fraction E ¢ - 1023 Value represented = ± 1. M ´ 2 (c) Double precision IEEE standard floating-point formats.

IEEE Standard For excess-127 format, 0 ≤ E’ ≤ 255. However, 0 and 255 are used to represent special value. So actually 1 ≤ E’ ≤ 254. That means -126 ≤ E ≤ 127. Single precision uses 32-bit. The value range is from 2-126 to 2+127. Double precision used 64-bit. The value range is from 2-1022 to 2+1023.

Two Aspects If a number is not normalized, it can always be put in normalized form by shifting the fraction and adjusting the exponent. excess-127 exponent 1 1 1 1 1 ... (There is no implicit 1 to the left of the binary point.) (100001000)2=13610, 136-127=-9 Value represented 9 = + 0.0010110 ¼ ´ 2 (a) Unnormalized value 1 1 1 1 1 ... 6+127=133. 13310, = (100000101)2 6 Value represented = + 1.0110 ¼ ´ 2 (b) Normalized version Floating-point normalization in IEEE single-precision format.

Two Aspects As computations proceed, a number that does not fall in the representable range of normal numbers might be generated. It requires an exponent less than -126 (underflow) or greater than +127 (overflow). Both are exceptions that need to be considered.

Special Values The end value 0 and 255 are used to represent special values. When E’=0 and M=0, the value exact 0 is represented. (±0) When E’=255 and M=0, the value ∞ is represented. (± ∞) When E’=0 and M≠0, denormal numbers are represented. The value is ±0.M2-126. When E’=255 and M≠0, Not a Number (NaN).

Exceptions A processor must set exception flags if any of the following occur in performing operations: underflow, overflow, divide by zero, inexact, invalid. When exception occurs, the results are set to special values.

Arithmetic Operations on Floating-Point Numbers Add/Subtract rule Choose the number with the smaller exponent and shift its mantissa right a number of steps equal to the difference in exponents. Set the exponent of the result equal to the larger exponent. Perform addition/subtraction on the mantissas and determine the sign of the result. Normalize the resulting value, if necessary. Multiply rule Add the exponents and subtract 127. Multiply the mantissas and determine the sign of the result. Divide rule Subtract the exponents and add 127. Divide the mantissas and determine the sign of the result.

Guard Bits and Truncation During the intermediate steps, it is important to retain extra bits, often called guard bits, to yield the maximum accuracy in the final results. Removing the guard bits in generating a final result requires truncation of the extended mantissa – how?

Guard Bits and Truncation Chopping – biased, 0 to 1 at LSB. Von Neumann Rounding (any of the bits to be removed are 1, the LSB of the retained bits is set to 1) – unbiased, -1 to +1 at LSB. Why unbiased rounding is better for the cases that many operands are involved? Rounding (A 1 is added to the LSB position of the bits to be retained if there is a 1 in the MSB position of the bits being removed) – unbiased, -½ to +½ at LSB. Round to the nearest number or nearest even number in case of a tie (0.b-1b-20000 - 0.b-1b-20, 0.b-1b-21100 - 0.b-1b-21+0.001) Best accuracy Most difficult to implement 0.b-1b-2b-3000 -- 0.b-1b-2b-31110.b-1b-2b-3 All 6-bit fractions with b-4b-5b6 not equal to 000 are truncated to 0.b-1b-21

Implementing Floating-Point Operations Hardware/software In most general-purpose processors, floating-point operations are available at the machine-instruction level, implemented in hardware. In high-performance processors, a significant portion of the chip area is assigned to floating-point operations. Addition/subtraction circuitry