richard008
richard008

Reputation: 403

Convert single precision floating point to half precision MIPS

I have a homework assignment as follows:

"Implement half precision floating point addition in MIPS assembly language. Prompt user to input two floating point (decimal) numbers and compute and display the sum.

In half precision format, 16 bits are used to represent a floating point number. The exponent field is 5 bits wide while the significand field has 10 bits.

You will need to convert single precision floating point number to half-precision floating point number and then perform your calculations."

How would I go about converting from single precision floating point to half-precision floating point in MIPS?

Upvotes: 1

Views: 2786

Answers (1)

Eric Postpischil
Eric Postpischil

Reputation: 224596

To convert an IEEE-754 32-bit binary floating-point object to 16-bit:

  • Separate the sign, exponent, and significand fields.
  • If the number is a NaN (exponent is all one bits and significand field is non-zero), return a NaN. (Use the same sign bit, set the exponent field to all ones, set the high bit of the new significand to the high bit of the old significand [it is commonly used to indicate signaling/quiet], and keep whatever other bits of the old significand you like, as long as the new significand is non-zero.)
  • If the exponent field is not all zeroes, add 223 to the significand field. If the exponent field is all zeroes, add 1 to it. (This step normalizes subnormal numbers.)
  • Subtract 127 from the exponent to remove the bias of the 32-bit format and add 15 to add the bias of the 16-bit format.
  • If the exponent field is less than -11, return zero, with the same sign as the input.
  • If the exponent field is less than 1: Set a temporary value to the significand shifted left by a number of bits equal to the 1 minus the exponent field. Shift the significand right that number of bits plus 13. If the temporary value exceeds 223, add one to the significand field (to round up). If that addition does not increase the significand to 210, set the exponent to zero and return the subnormal number (or zero) formed from the sign bit, the zero exponent, and the significand. If the significand did increase to 210, return the number formed from the sign bit, an exponent field of one, and a zero significand.
  • If the low 13 bits of the significand exceed 212 or they equal 212 and the next higher bit is 1, add 213 to the significand. Shift the significand right 13 bits. If it is not less than 211, add one to the exponent and shift the significand right one bit.
  • If the exponent field is larger than 30, return infinity, with the same sign as the input.
  • Otherwise, return the normal number formed from the sign bit, the exponent, and the low ten bits of the significand.

The above was written impromptu; it needs to be checked. Also, it does not contain considerations for signaling exceptions.

Upvotes: 5

Related Questions