Presentation is loading. Please wait.

Presentation is loading. Please wait.

Integer Division.

Similar presentations


Presentation on theme: "Integer Division."— Presentation transcript:

1 Integer Division

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

3 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.

4 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

5 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.

6 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

7 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.

8 Floating-Point Numbers and Operations

9 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.

10 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.

11 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

12 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, =-87 Value represented = 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.

13 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 to Double precision used 64-bit. The value range is from to

14 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.) ( )2=13610, =-9 Value represented 9 = + 2 (a) Unnormalized value 1 1 1 1 1 ... 6+127= , = ( )2 6 Value represented = + 1.0110 2 (b) Normalized version Floating-point normalization in IEEE single-precision format.

15 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.

16 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).

17 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.

18 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.

19 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?

20 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 b-1b-20, 0.b-1b b-1b ) Best accuracy Most difficult to implement 0.b-1b-2b 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

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


Download ppt "Integer Division."

Similar presentations


Ads by Google