Homework 2

CMSC 411 / Olano, Fall 2015

This assignment uses several files that I have checked into your assn2 git respository. Do a "git pull" in your work directory to get a copy of these files.

Unsigned multiply

In the unsigned-multiply.cpp file in your assn2 directory, implement the standard algorithm for multiplication of two 32-bit unsigned integers, as described by the diagram. You can use 32 or 64-bit intermediate values as indicated in the figure, but can only use basic ALU operations (addition, logic operations and shifts), and one loop over the bits of the multiplier. To use force a 64-bit addition, convert both operands to uint64_t using static_cast

For up to 10 points of extra credit, implement the enhanced version of this algorithm, using just one combined 64-bit product/multiplier register and only a 32-bit add (in C/C++, you ensure this by making sure both operands and the result of your add are uint32_t

Signed multiply

In the signed-multiply.cpp file in your assn2 directory, implement Booth's algorithm for multiplication of two signed 32-bit integers, as described by the diagram. You can use 32 or 64-bit intermediate values as indicated in the figure, but can only use basic ALU operations (addition, subtraction, logic operations and shifts), and one loop over the bits of the multiplier. To force a 32-bit on just the top 32 bits of a 64-bit number, you can use the intComponents union defined in the included bittypes.h. This union allows access to the same data, either as a 64-bit int, or as two 32-bit ints. It is OK to assume a little-endian Inel processor.

Floating point multiply

In the float-multiply.cpp file in your assn2 directory, implement the multiplication of two floating point numbers using only integer operations. In the simple case, you will need to extract the sign bit, reconstruct the exponent and mantissa. Then multiply the mantissas and add the exponents. Finally, pack back into binary single precision floating point form. Be sure to handle, as input or output, denormalized numbers, infinity, and NaN. You can enter infinity by typing "inf" for one of the numbers, and NaN by tying "nan". This table may help for infinity and not a number handling:

 + – inf -inf nan + +/inf –/-inf inf -inf nan – –/-inf +/inf -inf inf nan inf inf -inf inf -inf nan -inf -inf inf -inf inf nan NaN NaN NaN nan nan nan