Tom Kelliher, CS 220
Oct. 17, 1997
Final: 12:00--2:00pm on 12/18/97 in HS 149.
Collect homework.
Read
Pentium Pro: A Tour of the Microarchitecture
(http://www.intel.com/procs/ppro/info/p6white/index.htm
).
Consider a block diagram picture of unsigned integer multiplication via multiplicand shift:
Similar to multiplication: shift and subtract --- paper and pencil division.
Hard to speed up.
Algorithm:
quotientMask = 0x1; count = 0; quotient = 0; while (dividend >= divisor) { ++count; quotientMask <<= 1; // << is the shift operator in C divisor <<= 1; } --count; quotientMask >>= 1; divisor >>= 1; for ( ; count >= 0; --count) { if (dividend >= divisor) { quotient |= quotientMask; dividend -= divisor; } quotientMask >>= 1; divisor >>= 1; } remainder = dividend;Example: 10/3 in 4 bits.
Algorithm:
Issues:
Algorithm:
Issues:
Issues:
Rounding methods:
Hardware assists:
Comment: Floating point arithmetic is not associative. Consider:
double result1, result2; result1 = (MAXDOUBLE + -MAXDOUBLE) + 1.0; // = 1.0 result2 = MAXDOUBLE + (-MAXDOUBLE + 1.0); // = 0.0It may not always be commutative, either!