lecture 12-13 notes reading: section 3.4, 3.5, 3.6 multiplication –unsigned multiplication...

14
Lecture 12-13 notes • Reading: Section 3.4, 3.5, 3.6 • Multiplication – Unsigned multiplication – Hardware implementation • Division • Floating point

Upload: opal-richards

Post on 05-Jan-2016

217 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Lecture 12-13 notes Reading: Section 3.4, 3.5, 3.6 Multiplication –Unsigned multiplication –Hardware implementation Division Floating point

Lecture 12-13 notes

• Reading: Section 3.4, 3.5, 3.6

• Multiplication– Unsigned multiplication– Hardware implementation

• Division

• Floating point

Page 2: Lecture 12-13 notes Reading: Section 3.4, 3.5, 3.6 Multiplication –Unsigned multiplication –Hardware implementation Division Floating point

Unisigned shift-add multiplier (version 1)

• 64-bit Multiplicand reg, 64-bit ALU, 64-bit Product reg, 32-bit multiplier reg

Product

Multiplier

Multiplicand

64-bit ALU

Shift Left

Shift Right

WriteControl

32 bits

64 bits

64 bits

Multiplier = datapath + control

Page 3: Lecture 12-13 notes Reading: Section 3.4, 3.5, 3.6 Multiplication –Unsigned multiplication –Hardware implementation Division Floating point

MULTIPLY HARDWARE Version 2

• 32-bit Multiplicand reg, 32 -bit ALU, 64-bit Product reg, 32-bit Multiplier reg

Product

Multiplier

Multiplicand

32-bit ALU

Shift Right

WriteControl

32 bits

32 bits

64 bits

Shift Right

Page 4: Lecture 12-13 notes Reading: Section 3.4, 3.5, 3.6 Multiplication –Unsigned multiplication –Hardware implementation Division Floating point

What’s going on?

• Multiplicand stay’s still and product moves right

B0

B1

B2

B3

P0P1P2P3P4P5P6P7

0 0 0 0

A0A1A2A3

A0A1A2A3

A0A1A2A3

A0A1A2A3

Page 5: Lecture 12-13 notes Reading: Section 3.4, 3.5, 3.6 Multiplication –Unsigned multiplication –Hardware implementation Division Floating point

Multiplier is Negative

• Convert to positive->mult->sign conversion• Sign extended algorithm:

1 0 0 1 1 (-13)

x 0 1 0 1 1 (11)

1 1 1 1 1 1 0 0 1 1

1 1 1 1 1 0 0 1 1

0 0 0 0 0 0 0 0

1 1 1 0 0 1 1

0 0 0 0 0 0 0

1 1 0 1 1 1 0 0 0 1 (-143)

Page 6: Lecture 12-13 notes Reading: Section 3.4, 3.5, 3.6 Multiplication –Unsigned multiplication –Hardware implementation Division Floating point

Fast Hardware

• Use multiple hardware ALUs – Binary tree type structured

• Parallel binary addition

Page 7: Lecture 12-13 notes Reading: Section 3.4, 3.5, 3.6 Multiplication –Unsigned multiplication –Hardware implementation Division Floating point

Long Divide: Paper & Pencil

1001 Quotient

Divisor 1000 1001010 Dividend –1000 10

101 1010 –1000 10 Remainder

Dividend = Quotient x Divisor + Remainder

Page 8: Lecture 12-13 notes Reading: Section 3.4, 3.5, 3.6 Multiplication –Unsigned multiplication –Hardware implementation Division Floating point

DIVIDE HARDWARE Version 1

• 64-bit Divisor reg, 64-bit ALU, 64-bit Remainder reg, 32-bit Quotient reg

Remainder

Quotient

Divisor

64-bit ALU

Shift Right

Shift Left

WriteControl

32 bits

64 bits

64 bits

Page 9: Lecture 12-13 notes Reading: Section 3.4, 3.5, 3.6 Multiplication –Unsigned multiplication –Hardware implementation Division Floating point

Initialization:• Set 32-bit Quotient reg to 0• Place the divisor in the high half of the 64-bit

divisor reg• Remainder reg initialized with dividend

Page 10: Lecture 12-13 notes Reading: Section 3.4, 3.5, 3.6 Multiplication –Unsigned multiplication –Hardware implementation Division Floating point

Binary representation of fraction

• (1001.1001)2 = 1 x 2 3 + 0 x 2 2 + 0 x 2 1 +1 x 2 0

+ 1 x 2-1 + 0 x 2-2 + 0 x 2-3 +1 x 2-4

= (9.5625)10

(0.625) 10 = (0.5 + 0.125) 10

= 1 x 2-1 + 0 x 2-2 + 1 x 2-3

= (0.101) 2

2-1 2-2 2-3 2-4 2-5 2-6

0.5 0.25 0.125 0.0625 0.03125 0.0150625

Page 11: Lecture 12-13 notes Reading: Section 3.4, 3.5, 3.6 Multiplication –Unsigned multiplication –Hardware implementation Division Floating point

Scientific Notation

6.02 x 10 1.673 x 1023 -24

exponent

radix (base)Mantissa

decimal point

Sign, magnitude

Sign, magnitude

• Issues:–Arithmetic (+, -, *, / )

–Representation, Normal form

–Range and Precision

–Rounding

–Exceptions (e.g., divide by zero, overflow, underflow)

Page 12: Lecture 12-13 notes Reading: Section 3.4, 3.5, 3.6 Multiplication –Unsigned multiplication –Hardware implementation Division Floating point

IEEE 754 Floating-Point single precision

1 8 23

exponent:excess 127binary integer

fraction:sign + magnitude, normalizedbinary significand w/ hiddeninteger bit: 1.Factual exponent is

e = E - 127

S E F

N = (-1) 2 (1.F)S E-127

0 < E < 255

0 = 0 00000000 0 . . . 0 -1.5 = 1 01111111 10 . . . 0

Magnitude of numbers that can be represented is in the range:

2-126

(1.0) to 2127

(2 - 223)

which is approximately:

1.8 x 10-38

to 3.40 x 10 38

(integer comparison valid on IEEE Fl.Pt. numbers of same sign!)

Page 13: Lecture 12-13 notes Reading: Section 3.4, 3.5, 3.6 Multiplication –Unsigned multiplication –Hardware implementation Division Floating point

Example: -0.75 in float point

• -0.75=-(0.5+0.25)= -(0.11)2

• In scientific notation, the value is -0.112 x 20

• normalized scientific notation:-1.12 x 2-1

• In single precision:– (-1) S x (1 + fraction) x 2 (exponent-127)

– S = 1– fraction = 10000000000000000000000– Exponent = 126 = 01111110

10000000000000000000000011111101

Page 14: Lecture 12-13 notes Reading: Section 3.4, 3.5, 3.6 Multiplication –Unsigned multiplication –Hardware implementation Division Floating point

Floating Point Addition Algorithm(1) Add x=0.5 and y=– 0.4375 in binary

(2) x= 1.000 x 2-1, y= -1.110 x 2-2. right shift the smaller exponent (y) so that both have same exponent value

y= -0.111 x 2-1

(3) Add the fraction parts:

1.000 x 2-1 + -0.111 x 2-1 = 0.001 x 2-1

(4) left shift result to normalize

0.001 x 2-1=1.000 x 2-4

(5) Round (not needed in this example)