short cuts for multiply and divide for positive numbers 1. multiply by 2 k is the same as shift k to...

58
Com puterA rchitecture CSE 3322 Lecture 13 H W D ue 3/24/09 3.4.2a, 3.7.2a, 3.8.1a

Upload: hilda-barber

Post on 17-Jan-2018

217 views

Category:

Documents


0 download

DESCRIPTION

Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as shift k to the right, 0 fill For 2’s Complement Numbers It does not always work!

TRANSCRIPT

Page 1: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

Computer Architecture CSE 3322Lecture 13

HW Due 3/24/09 3.4.2a, 3.7.2a, 3.8.1a

Page 2: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

Short Cuts for Multiply and Divide

For Positive Numbers 1. Multiply by 2k is the same as shift k to the left, 0 fill 2. Divide by 2k is the same as shift k to the right, 0 fill

0

11

22

31

1

1

2222

2

ccc...cc

cc

nn

in

ii

Page 3: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

Short Cuts for Multiply and Divide

For Positive Numbers 1. Multiply by 2k is the same as shift k to the left, 0 fill 2. Divide by 2k is the same as shift k to the right, 0 fill

1

1

2

in

iicc

For 2’s Complement Numbers It does not always work!

Page 4: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

Short Cuts for Multiply and Divide

For Positive Numbers 1. Multiply by 2k is the same as shift k to the left, 0 fill 2. Divide by 2k is the same as shift k to the right, 0 fill

1

1

2

in

iicc

For 2’s Complement Numbers It does not always work!Ex: -5 = -0101 , 2’s Complement = 1011Divide by 4 by shift right 2, fill with ?

Page 5: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

Short Cuts for Multiply and Divide

For Positive Numbers 1. Multiply by 2k is the same as shift k to the left, 0 fill 2. Divide by 2k is the same as shift k to the right, 0 fill

1

1

2

in

iicc

For 2’s Complement Numbers It does not always work!Ex: -5 = -0101 , 2’s Complement = 1011Divide by 4 by shift right 2, fill with ?1110 is 0001+1=0010 = 2 WRONG!

Page 6: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

Floating Point NumbersNormalized Mantissa or Significand and Exponent

Add 0.713 x 10-2 and 0.964 x 10-1

Page 7: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

Floating Point NumbersNormalized Mantissa or Significand and Exponent

Add 0.713 x 10-2 and 0.964 x 10-1 1. Align the exponents by shifting the smaller

0.0713 x 10-1

0.9640 x 10-1

Page 8: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

Floating Point Numbers Normalized Mantissa or Significand and Exponent

Add 0.713 x 10-2 and 0.964 x 10-1 1. Align the exponents by shifting the smaller

0.0713 x 10-1

0.9640 x 10-1

2. Add 1.0353 x 10-1

Page 9: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

Floating Point Numbers

Add 0.713 x 10-2 and 0.964 x 10-1 1. Align the exponents by shifting the smaller

0.0713 x 10-1

0.9640 x 10-1

2. Add 1.0353 x 10-1

3. Normalize 0.10353 x 100

Page 10: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

Floating Point Numbers

Add 0.713 x 10-2 and 0.964 x 10-1 1. Align the exponents by shifting the smaller

0.0713 x 10-1

0.9640 x 10-1

2. Add 1.0353 x 10-1

3. Normalize 0.10353 x 100

4. Round off 0.104 x 100

Page 11: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

Normalized REAL Binary Number: ±1.yyyyyyyyy x 2eeee

Page 12: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

Normalized REAL Binary Number: ±1.yyyyyyyyy x 2eeee

Leading 1 Binary Point Significand = 1.yyyyyyyyyExponent(signed)Arithmetic

Page 13: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

Normalized REAL Binary Number: ±1.yyyyyyyyy x 2eeee

Leading 1 Binary Point Significand = 1.yyyyyyyyyExponent(signed)Arithmetic

16

181

41

212 43210

1

0

ccccccc in

ii

143210 nccccc.c

Page 14: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

Floating Point Numbers

Add 1.0101 x 23 and 1.1011 x 21

Page 15: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

Floating Point Numbers

Add 1.0101 x 23 and 1.1011 x 21 1. Align the exponents by shifting the smaller

1.0101 x 23

0.011011 x 23

Page 16: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

Floating Point Numbers

Add 1.0101 x 23 and 1.1011 x 21 1. Align the exponents by shifting the smaller

1.0101 x 23

0.011011 x 23

2. Add 1.101111 x 23

Page 17: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

Floating Point Numbers

Add 1.0101 x 23 and 1.1011 x 21 1. Align the exponents by shifting the smaller

1.0101 x 23

0.011011 x 23

2. Add 1.101111 x 23

3. Normalize – Check for Overflow and Underflow

1.101111 x 23

Page 18: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

Round - Off

4.56 3 significant digits + .0357 4.5957

Page 19: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

Round - Off

4.56 3 significant digits + .0357 4.5957

4.60 Rounded Off

Page 20: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

Round - Off

4.56 3 significant digits + .0357 4.5957

4.60 Rounded Off

What if 4.5950 ?

Page 21: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

Round - Off

4.56 3 significant digits + .0357 4.5957

4.60 Rounded Off

What if 4.5950 ? 4.60 Round to even

Page 22: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

Round - Off

Binary Decimal.00 .00.01 .25.10 .50.11 .75

Page 23: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

Round - Off

Binary Decimal.00 .00.01 .25.10 .50 Are there any trailing 1’s ?

If not, round to even.11 .75

Page 24: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

Floating Point Numbers

Add 1.0101 x 23 and 1.1011 x 21 1. Align the exponents by shifting the smaller

1.0101 x 23

0.011011 x 23

2. Add 1.101111 x 23

3. Normalize – Check for Overflow and Underflow

1.101111 x 23

4. Round to 4 bits Guard bit = 1 and Round bit = 1

Page 25: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

Floating Point Numbers

Add 1.0101 x 23 and 1.1011 x 21 1. Align the exponents by shifting the smaller

1.0101 x 23

0.011011 x 23

2. Add 1.101111 x 23

3. Normalize – Check for Overflow and Underflow

1.101111 x 23

4. Round to 4 bits Guard bit = 1 and Round bit = 1

1.1100 x 23

Page 26: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

IEEE 754 Floating Point StandardNormalized REAL Binary Number:

±1.yyyyyyyyy x 2eeee

IEEE 754(-1)S x ( 1 + F) x 2E-127

s exponent+127 significand - 1

1 bit E (8 bits) F (23 bits)

Page 27: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

IEEE 754 Floating Point StandardNormalized REAL Binary Number:

±1.yyyyyyyyy x 2eeee

IEEE 754(-1)S x ( 1 + F) x 2E-127

s exponent+127 significand - 1

1 bit E (8 bits) F (23 bits)

Bias Exponent E>0

Page 28: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

IEEE 754 Floating Point StandardNormalized REAL Binary Number:

±1.yyyyyyyyy x 2eeee

IEEE 754(-1)S x ( 1 + F) x 2E-127

s exponent+127 significand - 1

1 bit E (8 bits) F (23 bits)

• Only Zero is F = 0 and E = 0• Simplifies data exchange• Compare using integer processes• Accuracy and round-off & Overflow and Underflow

Page 29: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

IEEE 754 Floating Point Standard

1 10000010 01010000000000000000000

161

412

23

1

i

iixcF = .25+.0625 = .3125

Page 30: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

IEEE 754 Floating Point Standard

1 10000010 01010000000000000000000

161

412

23

1

i

iixcF = .25+.0625 = .3125

E = 27 + 2 = 128 + 2 = 130

Page 31: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

IEEE 754 Floating Point Standard

1 10000010 01010000000000000000000

161

412

23

1

i

iixcF = .25+.0625 = .3125

E = 27 + 2 = 128 + 2 = 130

Number = (-1)S x ( 1 + F) x 2E-127

Page 32: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

IEEE 754 Floating Point Standard

1 10000010 01010000000000000000000

161

412

23

1

i

iixcF = .25+.0625 = .3125

E = 27 + 2 = 128 + 2 = 130

Number = (-1)S x ( 1 + F) x 2E-127

= – ( 1 + .3125) x 2130 – 127

Page 33: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

IEEE 754 Floating Point Standard

1 10000010 01010000000000000000000

161

412

23

1

i

iixcF = .25+.0625 = .3125

E = 27 + 2 = 128 + 2 = 130

Number = (-1)S x ( 1 + F) x 2E-127

= – ( 1 + .3125) x 2130 – 127

= – 1.3125 x 23 = – 1.3125 x 8 = – 10.5

Page 34: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

IEEE 754 Floating Point Standard

Consider representing –5 in IEEE 754 Floating Point Format

Page 35: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

IEEE 754 Floating Point StandardConsider representing –5 in IEEE 754 Floating Point Format

5 = 101.0 x 20 = 1.01 x 22

Page 36: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

IEEE 754 Floating Point StandardConsider representing –5 in IEEE 754 Floating Point Format

5 = 101.0 x 20 = 1.01 x 22

IEEE 754(-1)S x ( 1 + F) x 2E-127

s exponent+127 significand - 1

1bit E (8 bits) F (23 bits)

Page 37: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

IEEE 754 Floating Point Standard

Consider representing –5 in IEEE 754 Floating Point Format5 = 101.0 x 20 = 1.01 x 22

IEEE 754(-1)S x ( 1 + F) x 2E-127

s exponent+127 significand - 1

1bit E (8 bits) F (23 bits)

E –127 = 2E = 2 + 127 = 129 = 1000 0001

Page 38: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

IEEE 754 Floating Point Standard

Consider representing –5 in IEEE 754 Floating Point Format5 = 101.0 x 20 = 1.01 x 22

IEEE 754(-1)S x ( 1 + F) x 2E-127

s exponent+127 significand - 1

1bit E (8 bits) F (23 bits)

E –127 = 2E = 2 + 127 = 129 = 1000 0001

1 +F = 1.01000 ...

Page 39: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

IEEE 754 Floating Point Standard

Consider representing –5 in IEEE 754 Floating Point Format5 = 101.0 x 20 = 1.01 x 22

IEEE 754(-1)S x ( 1 + F) x 2E-127

s exponent+127 significand - 1

1bit E (8 bits) F (23 bits)

1 1000 0001 0100 0000 .... 0000

E = 2 + 127 = 129 = 1000 0001

1 +F = 1.01000 ...

Page 40: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

IEEE 754 Floating Point StandardNormalized REAL Binary Number:

±1.yyyyyyyyy x 2eeee

Double PrecisionIEEE 754(-1)S x ( 1 + F) x 2E-1023

s exponent+1023 significand - 1

1 bit E (11 bits) F (20 bits)

significand – 1 (continued)

F (32 bits)

Page 41: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

Sequential Network Structures - Review

X1X2

Xn

Y1Y2

Ym

Q1Q2

Qm

Z1 Z2 Zk

Combinational Logic

Register Q

Clock

Stability Conditionclki Y Q

Input

Output

Page 42: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

Flip - Flop with NOR Gates

Q = R+Q

Q = S+Q

R

S

PresentState RS Q 00 01 10 11 0 1 Next State Q

Page 43: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

Flip - Flop with NOR Gates

Q = R+Q

Q = S+Q

R

S

PresentState RS Q 00 01 10 11 0 0 1 1 Next State Q

Page 44: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

Flip - Flop with NOR Gates

Q = R+Q

Q = S+Q

R

S

PresentState RS Q 00 01 10 11 0 0 1 1 1 1 Next State Q

Page 45: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

Flip - Flop with NOR Gates

Q = R+Q

Q = S+Q

R

S

PresentState RS Q 00 01 10 11 0 0 1 0 1 1 1 0 Next State Q

Page 46: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

Flip - Flop with NOR Gates

Q = R+Q

Q = S+Q

R

S

PresentState RS Q 00 01 10 11 0 0 1 0 ? 1 1 1 0 ? Next State Q

Page 47: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

D-latch

C

D

Q

D

C

Q

QS

R

Page 48: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

D-latch

C

D

Q

D

C

Q

QS

R

Page 49: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

D flip-flop

Output changes only on the trailing clock edge

QQ

_Q

Dl a t c h

D

C

Dl a t c h

D

C

D

C

Q

D

C

Q

Page 50: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

D flip-flop

Output changes only on the trailing clock edge

QQ

_Q

Dl a t c h

D

C

Dl a t c h

D

C

D

C

Q

D

C

Q

Page 51: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

Sequential Network Structures - Review

X1X2

Xn

Y1Y2

Ym

Q1Q2

Qm

Z1 Z2 Zk

Combinational Logic

Register Q

Clock

Stability Conditionclki Y Q

Input

Output

Page 52: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

Five Components of Computers

Input

Output

MemoryControl

Datapath

Processor

Page 53: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

Start by Building the Datapath

1. Access the Instruction from Memory2. Access the Data from Registers3. Perform the Instruction4. Write the Result

Page 54: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

PC

InstructionMemory

Next PC Logic

Instruction

Address

Simplified Overview

Access the Instruction from Memory

Page 55: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

PC

InstructionMemory

Next PC Logic

Instruction

Address

RegisterFile

Simplified Overview

Access the Data from Registers

Page 56: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

PC

InstructionMemory

Next PC Logic

Instruction

Address

RegisterFile

ALU

Simplified Overview

Perform the Instruction

Page 57: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

PC

InstructionMemory

Next PC Logic

Instruction

Address

RegisterFile

ALU DataMemory

Addr

Data In

DataOut

Simplified Overview

Write the Result

Page 58: Short Cuts for Multiply and Divide For Positive Numbers 1. Multiply by 2 k is the same as shift k to the left, 0 fill 2. Divide by 2 k is the same as

PC

InstructionMemory

Next PC Logic

Instruction

Address

RegisterFile

ALU DataMemory

Addr

Data In

DataOut

Simplified Overview

Timing Assumption