Beruflich Dokumente
Kultur Dokumente
Outline
Building blocks
a.
CarryOut
Binvert
Binvert
Operation
CarryIn
Operation
CarryIn
1
Result
1
b
Result
b
2
Less
3
Set
Less
3
Overflow
detection
CarryOut
b.
Overflow
Bnegate
Operation
a0
b0
CarryIn
ALU0
Less
CarryOut
Result0
a1
b1
0
CarryIn
ALU1
Less
CarryOut
Result1
a2
b2
0
CarryIn
ALU2
Less
CarryOut
Result2
a31
b31
0
CarryIn
ALU31
Less
Zero
Result31
Set
Overflow
c0 = Cin
A0
B0
G
P
S
c1 = g0 + c0 p0
A1
B1
G
P
A
0
0
1
1
B
0
1
0
1
C-out
0
C-in
C-in
1
kill
propagate
propagate
generate
g = A and B
p = A xor B
c2 = g1 + g0 p1 + c0 p0 p1
A2
B2
G
P
S
c3 = g2 + g1 p2 + g0 p1 p2 + c0 p0 p1 p2
A3
B3
G
P
Hierarchical CLA
C
L
A
4-bit
Adder
C0
G0= g3+g2p3+
P0= p3p2p1p0
C1 = G0 + C0 P0
G1= g7+g6p7+
P0= p7p6p5p4
C2 = G1 + G0 P1 + C0 P0 P1
4-bit
Adder
C3 = G2 + G1 P2 + G0 P1 P2 + C0 P0 P1 P2
G
P
4-bit
Adder
C4 = . . .
Signed Multiplication?
Booths Algorithm
elegant way to multiply signed numbers
using same hardware as before and save cycles
Booths Algorithm
end of run
middle of run
011110
beginning of run
Booths Example (2 x 7)
Operation
Multiplicand
Product
next?
0. initial value
0010
0000 0111 0
10 -> sub
1a. P = P - m
1110
+ 1110
1110 0111 0
1b.
0010
1111 0011 1
2.
0010
1111 1001 1
3.
0010
1111 1100 1
01 -> add
4a.
0010
+ 0010
0001 1100 1
4b.
0010
0000 1110 0
shift
done
Operation
Multiplicand
0. initial value
1a. P = P - m
0010
1110
0000 1101 0
+ 1110
1110 1101 0
10 -> sub
1b.
0010
1111 0110 1
+ 0010
01 -> add
2a.
Product
0001 0110 1
next?
shift P
2b.
0010
0000 1011 0
+ 1110
10 -> sub
3a.
0010
1110 1011 0
shift
3b.
4a
0010
1111 0101 1
1111 0101 1
11 -> nop
shift
4b.
0010
1111 1010 1
done
Quick example
Division
Divisor
Assumptions:
1101 Quotient
1000 1101010 Dividend
-1000
1010
-1000
0010
0101
-0000
1010
-1000
10 Remainder
Divide Version 1
Quotient
Shift left
64-bit ALU
32 bits
Remainder
Write
64 bits
Control
test
Divide Version 1
S tart
Remainder > 0
Test Remainder
Remainder < 0
33rd repetition?
Divide Version 2
Quotient
Shift left
32-bit ALU
32 bits
Remainder
64 bits
Shift left
Write
Control
test
Divide Version 3
Start
Divisor
32 bits
Rema inder
Shift right
Shift lef t
Wr i te
C on trol
te s t
Remainder >
0
Test Remainder
Remainder < 0
64 bit s
32nd repetition?
Yes: 32 repetitions
Done. Shift left half of Remainder right 1 bit
Divisor
Multiplicand
32 bits
32 bits
32-bit ALU
Remainder
Shift right
Shift left
Write
64 bits
Divide/multiply
C ontrol
test
Product
Shift right
Write
Control
test
64 bits
Multiply
Signed Division
Just make both operands positive and remember the sign
Must set the sign of the remainder though!
In MIPS
HI and LOW registers used for 64-bit register
Binary fractions:
10112 = 1x23 + 0x22 + 1x21 + 1x20
AND:
101.012 = 1x22 + 0x21 + 1x20 + 0x2-1 + 1x2-2
Example:
.75 = 3/4 = 1/2 + 1/4 = .112
exponent
decimal point
sign
+6.02 x 10
Mantissa
23
radix (base)
Issues:
Arithmetic (+, -, *, / )
Representation, Normal form
Range and Precision
Rounding
Exceptions (e.g., divide by zero, overflow, underflow)
Errors
Properties ( negation, inversion, if A = B then A - B = 0 )
Single precision
representation of
(-1)S 2E-127 (1.M)
sign
bit
23
exponent:
excess 127
binary integer
(actual exponent
is e = E - 127)
mantissa:
sign + magnitude, normalized
binary significand with hidden
integer bit: 1.M
0 = 0 00000000 00 . . . 0
-1.5 = 1 01111111 10 . . . 0
325 = 101000101 = 1.01000101 x 28
= 0 10000111 01000101000000000000000
.02 = .0011001101100... = 1.1001101100... x 2-3
= 0 01111100 1001101100...
sign
11
20
32
exponent:
excess 1023
binary integer
actual exponent is e = E - 1023
N = (-1)S 2 E-1023(1.M)
mantissa:
sign + magnitude, normalized
binary significand with hidden
integer bit: 1.M
Range of FP Numbers
Exponent
Fraction
Object
Denormalized Number
1 to 254
any
Normalized Number
(regular floating point number)
255
255
NaN
FP Addition
Basic Algorithm
1. Align
2. Add
3. Normalize
4. Round
Not exact
Usually, rounding throws away bits at the end.
Subtracting two nearly-equal numbers doesnt lose
bits, but answer doesnt have as many significant
bits.
FP Addition
S ig n
Exponent
Significand
Sign
E xponent
Significa nd
S tart
Compare
exponents
Small ALU
1. Compare the exponents of the two numbers.
Shift the smaller number to the right until its
exponent would match the larger exponent
Exponent
difference
0
Control
Shift smaller
number right
S h if t r ig h t
Big ALU
Overflow or
underflow?
Add
Yes
No
0
Exception
Increm ent or
decrement
Normalize
Rounding hardware
No
Still normalized?
Yes
Done
Sign
Exponent
Significand
Round
FP Multiplication
104)(5.2
102)
Basic Algorithm
1. Add exponents
2. Multiply
3. Normalize
4. Round
5. Set Sign
= 5.148 x
107
S ta rt
1 . A d d t h e b i a s e d e x p o n e n t s o f t h e tw o
n u m be rs , s ub tra ct in g t he bia s fr o m th e su m
to g e t th e n e w b i a s e d e x p o n e n t
2 . M u l ti p l y t h e s i g n i f i c a n d s
O v e rf l o w o r
u n d e rf l o w ?
Yes
No
No
S ti l l n o r m a l i z e d ?
Yes
5 . S et th e s ig n o f t h e p r o d uc t t o p os it iv e if t he
si gn s of the o rig in al op er an ds a re t he s am e ;
if th e y d if fe r m a k e t h e s ig n n e g at iv e
D o ne
E x ce p t io n
Key Points