You are on page 1of 3

HW # 2 Solutions

1a)

Carry
X
+Y
Sum

0
0
0
0

0
0
0
0

0
0
0
0

0
0
0
0

0
0
0
0

0
0
0
0

0
0
0
0

0
0
0
0

0
0
0
0

0
0
0
0

0
0
0
0

0
0
0
0

0
0
0
0

0
0
0
0

0
0
0
0

0
0
0
0

0
0
0
0

0
0
0
0

0
0
0
0

0
0
0
0

0
0
0
0

0
0
0
0

0
0
0
0

0
0
0
0

0
0
0
0

0
1
0
1

1
0
0
1

1
1
0
0

1
1
1
1

1
0
1
0

1
1
0
0

1
1
0

X
-Y

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

1
0

0
0

1
0

1
1

0
1

1
0

1
1

Carry
X
+Y
Difference

1
0
1
0

1
0
1
0

1
0
1
0

1
0
1
0

1
0
1
0

1
0
1
0

1
0
1
0

1
0
1
0

1
0
1
0

1
0
1
0

1
0
1
0

1
0
1
0

1
0
1
0

1
0
1
0

1
0
1
0

1
0
1
0

1
0
1
0

1
0
1
0

1
0
1
0

1
0
1
0

1
0
1
0

1
0
1
0

1
0
1
0

1
0
1
0

1
0
1
0

1
1
1
1

1
0
1
0

0
1
1
0

0
1
0
1

1
0
0
1

1
1
1
1

1
1
0

location

multiplicand
multiplier

0
0
0
0
0
0
0
0

0
0
0
0
0
0
0
0

0
0
0
0
0
0
0
0

0
0
0
0
0
0
0
0

0
0
0
0
0
0
0
0

0
0
0
0
0
0
0
0

0
0
0
0
0
0
0
0

0
0
0
0
0
0
0
0

0
0
0
0
0
0
0
0

0
0
0
0
0
0
0
0

0
0
0
0
0
0
0
0

0
0
0
0
0
0
0
0

0
0
0
0
0
0
0
0

0
0
0
0
0
0
0
0

0
0
0
0
0
0
0
0

0
0
0
0
0
0
0
0

0
0
0
0
0
0
0
0

0
0
0
0
0
0
0
0

0
0
0
0
0
0
0
0

0
0
0
0
0
0
0
0

0
0
0
0
0
0
0
0

0
0
0
0
0
0
0
1

0
0
0
0
0
0
1
0

0
0
0
0
0
0
1
0

0
0
0
0
0
1
0
1

0
1
0
0
1
1
1
0

0
0
0
0
1
0

0
1
0
1
0
1

1
1
1
1
1

1
0
1
0

0
1
0
1

1
1
1 pp0
pp1
pp3
pp4
pp6
1

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
1

0
0

0
1

1
1

1
0

0
1

1
1

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
1

0
0

0
1

0
1

1
0

1
1

1
1

1b)

1c)

+
Product
1d)

0
0

0
0
0
0

0
0
0

0
0

0
0
0
0
0

0
0
0
0

Divisor
Dividend
Quotient

all previous alignments would produce a negative number if subtracted, so they are not shown. We begin showing work at the 29th attempt

sub => neg!


don't subtract

sub => pos!


subtract

sub => pos!


subtract
sub => zero!
subtract
Remainder

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

1
1

0
1

1
0

1
1

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

1
0
0

0
1
1

1
1
0

1
0
0

0
1
1

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

1
0
0

0
1
0

0
1
1

1
0
1

1
1
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

1
1
0

1
1
0

0
0
0

1
1
0

2a)

s
X
+Y

exponent
0 1 0
0 1 0

1
0

1
0

1
1

0
0

1
0

0
1

mantissa
0 0 1
0 0 1

0
0

0
0

0
1

0
0

0
0

0
1

0
0

0
0

0
1

0
0

0
0

0
1

0
0

0
0

0
1

0
0

0
0

0
1

1
0

0
0

1.125000238419 x 2 ^ -37
1.142857074738 x 2 ^ -54

Put larger abs value on top

1
0

0
0

1
1

0
0

1
0

1
1

0
0

1
0

0
1

0
0

0
0

1
1

0
0

0
0

0
1

0
0

0
0

0
1

0
0

0
0

0
1

0
0

0
0

0
1

0
0

0
0

0
1

0
0

0
0

0
1

1
0

0
0

1.125000238419 x 2 ^ -37
1.142857074738 x 2 ^ -54

Shift mantissa to line up exp


SRight 17 (don't forget implicit 1)

1
0

0
0

1
1

0
0

1
1

1
1

0
0

1
1

0
0

0
0

0
0

1
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
0

0
1

0
0

0
0

0
1

0
0

1
0

0
1

1.125000238419 x 2 ^ -37
0.000008702278 x 2 ^ -37

1
0
0

0
0
0

0
0
0

1
0
1

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
0
0

0
1
1

0
0
0

0
0
0

0
1
1

0
0
0

1
0
1

0
1
1

1
0
1

0
0
0

1
0
1

1
0
1

0
0
1

1
0
0

1
0
0

1
0
0

1
0
0

1
0
0

1
0
0

1
0
0

1
0
0

1
0
0

1
0
0

1
0
0

1
0
0

1
0
0

1
1
1

1
0
0

1
0
0

1
1
0

1
0
1

1
0
1

0
1
1

0
1

1
0

1
0

1
0

0
1

0
1

0
1

0
1

0
1

0
1

0
1

0
1

0
1

0
1

0
1

0
1

0
1

1
0

0
1

0
1

0
1

1
0

1
0

1
1

1.124991536140 x 2 ^-37

1.125000238419 x 2 ^ -37
1.142857074738 x 2 ^ -54

1.125000238419
1.142857074738
1.285714507103

1.285714507103 x 2 ^ - 91

Add mantissa
don't forget implict 1
and sign!

X
Y

neg
pos

turn into
2's comp numbers

X
Y

Turn the result back


into unsigned numbers

sign = same as larger abs value


exp = same as larger abs value
mantissa and implict 1's spot

neg

1
0
1

1
0

0
0

1
0

No renormalization necessary
Result

2b)

1
1

0
1

exponent
0 1 0

mantissa
0 0 0

1
0

exponent
0 1 0
0 1 0

1
0

1
1

0
0

1
0

0
1

mantissa
0 0 1
0 0 1

0
0

0
0

0
1

0
0

0
0

0
1

0
0

0
0

0
1

0
0

0
0

0
1

0
0

0
0

0
1

0
0

0
0

0
1

1
0

0
0

1
1
1

0
0
0

0
0
1

0
1
0

0
0
0

0
0
1

0
1
0

0
0
0

0
0
1

0
1
0

0
0
0

0
0
1

0
1
0

0
0
0

0
0
1

0
1
0

0
0
0

0
0
1

0
1
0

1
0
1

0
0
1

mantissa
0 1 0

Multiply mantissa
don't forget implict 1's
Only take the top 25 bits of multiplication

X
Y

Add exponents
real X exp + 127
real Y exp + 127
real X exp and Y Exp + 254

real result exp + 127

No renormalization necessary
Result

X
Y

0
0
1

1
1
0

0
0
1

1
0
0

1
1
0

0
0
0

1
0
1

0
1
1

1
0
0

0
1
0

1
1
1

0
1
0

0
1
0

0
1
1

1
1
0

1
1
0

XOR

s
1

subtract 127 to go back to (-127) normalized form

XOR signs

0
1

X
*Y

1
1

1
1
0

0
0
0

0
0
1

1
0
1

exponent
0 0 1

3)

Class
A
B
C
D
E

Frequency

CPI- P1
33.33%
16.67%
16.67%
16.67%
16.67%

Weighted Ave P1
1
2
3
4
3

CPI - P2
0.33
0.33
0.50
0.67
0.50
2.33

Weighted Ave P2
2
2
2
4
4

0.67
0.33
0.33
0.67
0.67
2.67

Peak performance will be obtained when each processor executes a stream of the fastest instructions.
This makes the weighted CPI irrelevant. When P1 executes a series of intructions of class A, we get a
peak performance of 4,000 MIPS since the clock rate is 4 GHz. When P2 executes a series of instructions of
class A, B, or C, we get a peak performance of 3,000 MIPS since the clock rate is 6 GHz.
This makes the peak performance ratio of P2/P1= 3:4. In the best case P2 is slower than P1.
However, the question asked about performance of the system for a given program. In this case, we should use the weighted average CPIs. This would make the average
performance of P1 2G cycles/sec divided by 2.33 cycles/instruction = 838 M instruction / sec (MIPS).
Similarly, P2 would have an average performance of 3G cycles/sec divided by 2.67 cycles/instruction =
1,123 MIPS. This would make the average performance ratio of P2/P1 = 1.31.
In the typical case P2 is faster than P1.
4)

Program P - 1 GHz machine in 10 sec => 10 G cycles


Program P' - 1 GHz machine in 9 sec => 9 G cycles
We saved 1G cycles. Each time one multiply by 4 is replaced with two additions, we save 2 cycles.
Thus, we replaced 500 M multiplications with additions.

You might also like