Beruflich Dokumente
Kultur Dokumente
©Dimitris Nikolopoulos
Faster multiplication
23
CS2504, Spring'2007
©Dimitris Nikolopoulos
Faster multiplication
Parallel shift
Partial sum stored in upper 32 bits
Multiplier in lower 32 bits
Multiplier shifted out bit by bit
Partial sum shifts in place of multiplier
Do not need to extend multiplicand!
Everything happens in place
Faster, simpler hardware!
24
CS2504, Spring'2007
©Dimitris Nikolopoulos
Signed multiplication
Convert operands to positive numbers
Remember original digits
Multiply using original algorithm for 31
iterations
Then add new sign
Caution: shifting the product sum needs to sign
extend the product sign
25
CS2504, Spring'2007
©Dimitris Nikolopoulos
26
CS2504, Spring'2007
©Dimitris Nikolopoulos
Why is the multiplier with 32 adders faster?
Original multiplier needs a clock per bit
Optimized multiplier needs:
An and operation (parallel)
32 adders (pipelined)
Each adder receives output of previous multiplier
Least significant bit goes to result
31 upper bits plus carry out go to next multiplier
Pipeline latency:
Cost of first multiply slow
Following multiplies fast (presumably one per cycle)
27
CS2504, Spring'2007
©Dimitris Nikolopoulos
Multiplication in MIPS
mult, multu
Two registers, Hi-Lo, operating as an
extended 64-bit register
mflo, fetches 32 bits from Lo
mfhi, fetches 32 bits from Hi
Again no automatic check for overflow
Need code
Use mfhi to do the known overflow tests
28
CS2504, Spring'2007
©Dimitris Nikolopoulos
1001 Quotient
Divisor 1000 1001010 Dividend
-1000
1010
-1000
10 Remainder
29
CS2504, Spring'2007
©Dimitris Nikolopoulos
Hardware division
30
CS2504, Spring'2007
©Dimitris Nikolopoulos
Hardware division
Assume 4-bit division
Divisor=00100000, Remainder=0000 0111
Q=nan, D=0010 0000 (8 bits),R=0000 0111
Step 1:
R-D=0000 0111- 0010 0000 < 0
Q=0, R=0000 0111 (restore remainder),
D=0001 0000 (shift divisor)
Step 2:
R-D=0000 0111-0001 0000 < 0
Q=00, R=0000 0111, D = 0000 1000
31
CS2504, Spring'2007
©Dimitris Nikolopoulos
Hardware division
33
CS2504, Spring'2007
©Dimitris Nikolopoulos
34
CS2504, Spring'2007
©Dimitris Nikolopoulos
Signed division
Dividend=Quotient x Divisor + Remainder
Dividend and Quotient signs need to agree
Signed division algorithm
Calculate quotient as usual
Negate quotient if signs of dividend and divisor
disagree
35
CS2504, Spring'2007
©Dimitris Nikolopoulos
We need to represent fraction and exponent
Remember, we are using fixed word sizes!
More bits for fraction improves precision
More bits for exponent increases the range
MIPS uses sign and magnitude representation:
1 bit for the sign
8 bits for the exponent field
23 bits for the fraction
(-1)s x F X 2E
Can represent numbers as small as 2 x 10-38 or as large
as 2 x 1038
37