1 1000 0000 0100 0000 Fast multiplication Division hardware - - PDF document

1
SMART_READER_LITE
LIVE PREVIEW

1 1000 0000 0100 0000 Fast multiplication Division hardware - - PDF document

0000 1000 Multiplication hardware 0001 0000 0010 0000 Computer arithmetic o The multiplication 0100 0000 algorithm we learned in Multiplicand grammar school leads to 1001 Integers and floats Shift left a simple if somewhat 0100 64 bits


slide-1
SLIDE 1

1

CS240 Computer Organization

Department of Computer Science Wellesley College

Computer arithmetic

Integers and floats

Arithmetic 10-2

Multiplication hardware

  • The multiplication

algorithm we learned in grammar school leads to a simple if somewhat inefficient design:

  • 1000

Multiplicand

x 1001 Multiplier

  • 1000

0000 0000 1000 1001000 Product

  • Multiplicand

64-bit ALU

Product Multiplier Control

Write Shift left Shift right 64 bits 64 bits 0000 1000 0000 0000 0001 0000 0000 1000 0100 0010 0010 0000 0000 1000 1001 0001 0100 0000 0000 1000 0100 1000

Arithmetic 10-3

Refined version of mult hardware

Multiplicand

32-bit ALU

Product Control test

Write Shift right 32 bits 64 bits 1000 0000 1001 0100 0100 0010 0010 0001 0001 0100 1000

Twos-complement multiplication

  • Multiplication of

signed integers could be done by multiplying numbers and then figuring out the sign.

  • However, the above

algorithm works for twos-complement provided we extend the sign bit appropriately.

Arithmetic 10-4

slide-2
SLIDE 2

2

Fast multiplication

Arithmetic 10-5 32-bit ALU 32-bit ALU 32-bit ALU 32-bit ALU

Mplier1 * Mcand Mplier2 * Mcand Mplier3 * Mcand Mplier31 * Mcand Mplier0 * Mcand product bits 31 - 0

. . .

1*1000 0*1000 0100 0010 0*1000 0001 1*1000 0100 1 product bits 63 - 32

Arithmetic 10-6

Division hardware

1001 Quotient 1000 1001010 Dividend

  • 1000

10 101 1010

  • 1000

10 Remainder

  • Divisor

64-bit ALU

Remainder Quotient Control

Write Shift right Shift left 64 bits 64 bits 1000 0000 0000 0100 1010 0100 0000 0000 0010 0000 0001 0000 1010 0001 0000 0010 0000 1010 0000 1000 0100 0000 1010 0100 1010 1001 0000 0010

Arithmetic 10-7

Refined version of division hardware

Divisor

32-bit ALU

Remainder Control test

Write Shift right 32 bits 64 bits Shift left

Arithmetic 10-8

Representing reals

  • Numbers with fractions,

e.g., 3.14159265… (π).

  • Very small numbers, e.g., .

000000001 = 1.0 x 10-9

  • Very large numbers, e.g.,

3,155,760,000 = 3.15576 x 109

slide-3
SLIDE 3

3

Arithmetic 10-9

Binary fractions

  • We can also show binary

numbers in normalized scientific notation using the notation: 1.xxxx2 x 2yyyy

  • We now call the “.” symbol

the binary point. We also call this format “floating- point” because the binary point is not fixed.

Arithmetic 10-10

Life is not also so easy

  • What if the fractional part is not an exact power of two? We

will need to approximate!

2-1 = .12 = .510 2-2 = .012 = .2510 2-3 = .0012 = .12510 2- 4 = .00012 = .062510 2-5 = .000012 = .0312510 2-6 = .0000012 = .01562510 2-7 = .00000012 = .007812510 2-8 = .000000012 = .003906310 2-9 = .0000000012 = .001953110 2-10 = .00000000012 = .000976610 etc…

  • Then, sum to the degree of precision necessary. For example,

what does .310 = ?

Arithmetic 10-11

Floating-point numbers: (-1)sign x fraction x 2exponent

  • A fixed word size means that there is a tradeoff

between accuracy and range:

  • more bits for fraction gives more precision of fraction
  • more bits for exponent increases range of numbers that can

be represented.

Arithmetic 10-12

IEEE 754 floating-point standard

  • Single precision
  • Double precision

31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

s exponent fraction

1 bit 8 bits 23 bits

31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

s exponent fraction

1 bit 11 bits 20 bits

31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

fraction continued

32 bits

slide-4
SLIDE 4

4

Arithmetic 10-13

Water over (and under) the dam

  • Overflow is now the case

where the positive exponent is too large to be represented in the exponent field.

  • But now there is also

underflow, i.e., the case where the negative exponent is too large to fit in the exponent field. In this case, the fractional part has become so small that it cannot be represented.

Arithmetic 10-14

Some unpleasant details

  • Placing the exponent before the fraction simplifies sorting
  • f floating point numbers using integer comparison

instructions.

  • But, what about negative exponents? They “look” big

because the leading digit is a 1!

  • Exponent is “biased” to make sorting easier. The bias is

subtracted from the normal, unsigned value, to determine the real value. Bias = 127 for single precision and 1023 for double precision:

(–1)sign x (1 + fraction) x 2exponent – bias

Arithmetic 10-15

So an IEEE engineer walks into a bar ...

... and orders

1.00000000001000000082740370999090373516082763671875 root beers. The bartender says, "I'll have to charge extra; that's a root beer float". And the engineer says, "In that case, make it a double."

We order a -.7510 float and make it a double.

Arithmetic 10-16

Aaaahhhh!!!

slide-5
SLIDE 5

5

Floating point multiplication: 1.000 x 2-1 times -1.110 x 2-2

1.

Add exponent without bias:

  • 1 + (-2) = -3

2.

Multiple significants: 1.000

  • x 1.110
  • 0000
  • 1000
  • 1000
  • 1000

1.110000

3.

Normalize and check for

  • verflow or underflow:

1.110 x 2-3

Arithmetic 10-17 4.

Round the product: 1.110 x 2-3

5.

Calculate sign of result: 1 x (-1) = -1

Arithmetic 10-18

The infamous Pentium bug (1994)