CS274: Computer Architecture - Floating Point Bit Fields (100 Points)

Assignment Goals

The goals of this assignment are:
  1. To manipulate the fields of an IEEE 754 floating point value

Background Reading and References

Please refer to the following readings and examples offering templates to help get you started:

The Assignment

Purpose

This assignment develops your working knowledge of the IEEE 754 floating point standard by having you reconstruct decimal values from their sign, exponent, and mantissa fields by hand and in code. Decoding the bias, the implicit leading 1, and the fractional place values makes concrete why floating point arithmetic rounds the way it does, which we build on in our study of computer arithmetic hardware.

Recall the C program to extract the IEEE bit fields from an IEEE 754 float data type, shown below:

Task

In this assignment, you will write a program to prompt the user for the sign, mantissa, and exponent of an IEEE 754 single precision floating point value (in binary). Using the IEEE 754 standard, calculate the decimal value of this float.

Repeat this process for an IEEE 754 double precision floating point value. Instead of an int, you can declare the mantissa as a long int to enable the additional bit storage.

You may use C, C++, Java, or Python for your solution, but be sure to include a Makefile that compiles and runs the program(s).

Written Questions: Points and Hints

The Writeup, Textbook Questions, and Submission criterion is worth 10 points, allocated as follows:

Item Points A complete answer shows…
Readme writeup 4 A description of your decoding approach and how to build and run your program(s) via the Makefile
Textbook Question 3.9 1 The arithmetic carried out in the requested representation, with intermediate values and any overflow noted
Textbook Question 3.13 1 Each step of the computation shown, not just the final bit pattern or value
Textbook Question 3.18 1 The value converted to the requested IEEE format, with the sign, biased exponent, and mantissa fields identified separately
Textbook Question 3.21 1 The bit pattern interpreted under each requested reading, with the work for each interpretation
Textbook Question 3.23 1 The conversion and a statement of the rounding/accuracy consequences the problem asks about
IEEE 754 representation of 0.1 1 The single precision bit pattern for 0.1, the exact decimal value that pattern actually represents, and a sentence on why they differ

Hints

  • 3.9: Set up the operands in the requested format first, then perform the arithmetic digit-by-digit in that base; state explicitly whether the result fits in the given number of bits.
  • 3.13: Convert to binary scientific notation (normalize to 1.xxxx times 2^e) before touching the fields; then apply the bias to get the stored exponent and truncate/round the fraction to the available mantissa bits.
  • 3.18: Work field by field: sign bit from the value’s sign, exponent from the normalized power of two plus the bias, mantissa from the bits after the implicit leading 1. Double-check your bias against the format’s exponent width.
  • 3.21: The same 32 bits mean different things under different interpretations; decode the pattern once per requested reading (integer, instruction, floating point), and for the floating point reading undo the bias and re-attach the implicit 1.
  • 3.23: After converting, compare the exactly representable neighbor values; the gap between them tells you how much accuracy is lost and connects to your program’s output.
  • 0.1 question: 0.1 has an infinitely repeating binary fraction; carry the expansion a few bits past the 23-bit mantissa so you can round correctly, then convert the stored pattern back to decimal to see the exact value your program would report.

Design Questions to Help You Begin

Please answer the following questions in your README file before you begin writing your program.
  1. Patterson and Hennessy Textbook Question 3.9
  2. Patterson and Hennessy Textbook Question 3.13
  3. Patterson and Hennessy Textbook Question 3.18
  4. Patterson and Hennessy Textbook Question 3.21
  5. Patterson and Hennessy Textbook Question 3.23
  6. What is the IEEE 754 single precision representation for the value 0.1? What is the actual value of this binary representation?

Submission

In your submission, please include answers to any questions asked on the assignment page, as well as the questions listed below, in your README file. If you wrote code as part of this assignment, please describe your design, approach, and implementation in a separate document prepared using a word processor or typesetting program such as LaTeX. This document should include specific instructions on how to build and run your code, and a description of each code module or function that you created suitable for re-use by a colleague. In your README, please include answers to the following questions:
  • Describe what you did, how you did it, what challenges you encountered, and how you solved them.
  • Please answer any questions found throughout the narrative of this assignment.
  • If collaboration with a buddy was permitted, did you work with a buddy on this assignment? If so, who? If not, do you certify that this submission represents your own original work?
  • Please identify any and all portions of your submission that were not originally written by you (for example, code originally written by your buddy, or anything taken or adapted from a non-classroom resource). It is always OK to use your textbook and instructor notes; however, you are certifying that any portions not designated as coming from an outside person or source are your own original work.
  • Approximately how many hours it took you to finish this assignment (I will not judge you for this at all...I am simply using it to gauge if the assignments are too easy or hard)?
  • Your overall impression of the assignment. Did you love it, hate it, or were you neutral? One word answers are fine, but if you have any suggestions for the future let me know.
  • Using the grading specifications on this page, discuss briefly the grade you would give yourself and why. Discuss each item in the grading specification.
  • Any other concerns that you have. For instance, if you have a bug that you were unable to solve but you made progress, write that here. The more you articulate the problem the more partial credit you will receive (it is fine to leave this blank).

Assignment Rubric

Description Pre-Emerging (< 50%) Beginning (50%) Progressing (85%) Proficient (100%)
Algorithm Implementation (60%) The program does not compile or run via the Makefile, or the decimal value is obtained by casting or by a library conversion rather than by applying the IEEE 754 formula to the user-entered fields The program builds, prompts for the sign, exponent, and mantissa bits, and applies the IEEE 754 formula, but produces an incorrect decimal value due to a minor issue (for example, the wrong exponent bias, a missing implicit leading 1, or mantissa bits weighted from the wrong end) The single precision case is decoded correctly for the tested inputs (sign, biased exponent of 127, implicit 1 plus fractional place values), but the double precision case is missing or incorrect (for example, the 1023 bias or long int mantissa storage is not handled), or a general input such as a negative value fails, or the Makefile does not both compile and run the program The program prompts for the sign, exponent, and mantissa in binary and correctly computes the decimal value for both single precision (bias 127, 23 mantissa bits) and double precision (bias 1023, 52 mantissa bits in a long int), including the implicit leading 1 and negative values, and includes a Makefile that compiles and runs it
Code Quality and Documentation (30%) Code commenting and structure are absent, the decoding is one uncommented block, and/or the code departs significantly from the style guide Comments are sparse or restate the code, and/or there are minor departures from the style guide that reduce the readability of the bit manipulation logic The decoding steps are commented and organized into functions, and the code mostly adheres to the style guide, but the comments restate operations rather than tying them to the IEEE 754 fields (sign, biased exponent, mantissa) Bit extraction and reconstruction steps are commented in terms of the IEEE 754 standard (which bits form the sign, exponent, and mantissa, and how bias and the implicit 1 are applied), single and double precision logic is cleanly separated or parameterized, and the code follows the style guide
Writeup, Textbook Questions, and Submission (10%) An incomplete submission is provided; the readme and the answers to the assigned textbook questions are missing The program is submitted, but the readme is missing the solution description or answers to one or more of the assigned questions (3.9, 3.13, 3.18, 3.21, 3.23, and the 0.1 representation question) The readme describes the solution and answers every assigned question, but one or more answers are superficial or state a result without showing the conversion or arithmetic work The readme describes the solution and answers each assigned question (3.9, 3.13, 3.18, 3.21, 3.23, and the 0.1 representation question) correctly with work shown, including the intermediate bit patterns, biased exponents, and rounding steps used to reach each answer

Please refer to the Style Guide for code quality examples and guidelines.