Professional Documents
Culture Documents
cs281 Lec14
cs281 Lec14
Jeremy R. Johnson
Anatole D. Ruslanov
William M. Mongan
• Approximate arithmetic
– Finite Range
– Limited Precision
• Topics
– IEEE format for single and double precision floating point numbers
– Floating point addition and multiplication
– Support for floating point computation in MIPS
Lec 14 Systems Architecture 2
Distribution of Floating Point Numbers
e = -1 e=0 e=1
• 3 bit mantissa 1.00 X 2^(-1) = 1/2 1.00 X 2^0 = 1 1.00 X 2^1 = 2
1.01 X 2^(-1) = 5/8 1.01 X 2^0 = 5/4 1.01 X 2^1 = 5/2
• exponent {-1,0,1} 1.10 X 2^(-1) = 3/4 1.10 X 2^0 = 3/2 1.10 X 2^1= 3
1.11 X 2^(-1) = 7/8 1.11 X 2^0 = 7/4 1.11 X 2^1 = 7/2
0 1 2 3
Lec 14 Systems Architecture 3
Floating Point
x
(
S
1)
(1
(Expone
Bias)
Fractio
2
31 30 23 22 0
(-1)s F 2E-127
0 non-zero denormalized
1-254 anything FP number
255 0 pm infinity
255 non-zero NaN
• Unbiased exponent:
• Biased exponent:
• One can compute the mantissa just similar to the way one would
convert decimal whole numbers to binary.
• Take the decimal and repeatedly multiply the fractional
component by 2. The whole number portion is the next binary
bit.
• For whole numbers, append the binary whole number to the
mantissa and shift the exponent until the mantissa is in
normalized form.
• Single: 1011111101000…00
• Double: 1011111111101000…00
(-1)s F 2E-1023
0 non-zero denormalized
1-2046 anything FP number
2047 0 pm infinity
2047 non-zero NaN
Lec 14 Systems Architecture 17
Floating Point Arithmetic
• Arithmetic
–x y = fl(x+y) = (x + y)(1 + ) for < u
–x y = fl(x y)(1 + ) for < u
2 . A d d t h e s ig n if ic a n d s
Exponent
difference
3 . N o r m a liz e t h e s u m , e ith e r s h iftin g r ig h t a n d
0 1 0 1 0 1
in c r e m e n tin g th e e x p o n e n t o r s h ift in g le ft
a n d d e c r e m e n t in g t h e e x p o n e n t
O v e r f lo w o r Ye s
u n d e r f lo w ?
Big ALU
No E x c e p tio n
0 1 0 1
4 . R o u n d t h e s ig n if ic a n d t o t h e a p p r o p r ia te
n u m b e r o f b its
Increment or Shift left or right
decrement
No
S t ill n o r m a liz e d ?
Rounding hardware
Ye s
Sign Exponent Fraction
D one
Step 1
Step 2
Step 3
Step 4
– When computing result, assume there are several extra digits available
for shifting and computation. This improves accuracy of computation.
– Guard digit: first extra digit/bit to the right of mantissa -- used for
rounding addition results
– Round digit: second extra digit/bit to the right of mantissa -- used for
rounding multiplication results
– Sticky bit: third extra digit/bit to the right of mantissa – used for
resolving ties such as 0.50...00 vs. 0.50...01
• Co-processor 1 features:
– Contains 32 single precision floating point registers: $f0, $f1, … $f31
– Uses special floating point instructions, which are similar (in format) to integer
instructions but have .s or .d attached to signify that they work on fp numbers
– Several special instructions to move between “regular” registers and the co-
processor registers