Round exact sums to half precision by hand with the guard and sticky bits. Find where the order of two adds matters.
Hardware context: The weight debug unit of a half-precision accelerator and the reference model of a half-precision adder. Round exact sums to half precision by hand with the guard and sticky bits.
A team is writing a reference model for a half-precision adder. Before they trust the model, they want a short list of sums worked out by hand. Each sum is exact, and only the final rounding decides the answer.
This is an Implement problem with no logic to write. Round each sum to half precision with round to nearest, ties to even. Write the result as a 16-bit hex pattern. The first three constants are worked examples.
Two constants ask for a sum that is rounded after each of two adds. The last one asks for a number, not a pattern.
The check compares every constant with the right value and names the first one that is wrong.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
question | 8 | input of each check |
Full specification
| Constant | What to write |
|---|---|
| SUM_A | The half-precision pattern of 1 + 2^-12 (a quarter of a step: it rounds down). |
| SUM_B | The half-precision pattern of 1 + 2^-11 (an exact tie: the even neighbour is 1.0 itself). |
| GAP_4096 | The gap between 4096 and the next half-precision number (2^12 x 2^-10). |
| SUM_C | The half-precision pattern of 1 + 5 x 2^-11. |
| SUM_D | The half-precision pattern of 2 + 2^-10 + 2^-14. |
| SUM_E | The half-precision pattern of 2048 + 7. |
| SUM_F | The half-precision pattern of 2048 + 5. |
| SUM_G | The half-precision pattern of 1024 + 0.5. |
| SUM_H | The half-precision pattern of 1024 + 1.5. |
| SUM_I | The half-precision pattern of 1024 + 0.5 + 2^-6. |
| ORDER_LEFT | The pattern of (1024 + 0.5) + 0.5, rounded after each add. |
| ORDER_RIGHT | The pattern of 1024 + (0.5 + 0.5), rounded after each add. |
| COUNT_STOP | The value where a half-precision counter stops that starts at 4000 and adds 2 per step. |
SUM_A = 16'h3c00; // 1.0: sign 0, exponent field 01111, fraction 0
| Binade | Step between neighbours |
|---|---|
| 1 to 2 | 2^-10 |
| 2 to 4 | 2^-9 |
| 1024 to 2048 | 1 |
| 2048 to 4096 | 2 |
Keep the module name and the constant names. GAP_4096 and COUNT_STOP are decimal numbers.
Examples
Example 1
Worked Example: Below Half a Step- Input
the half-precision pattern of 1 + 2^-12 (a quarter of a step: it rounds down)
- Output
sum_a = 0x3c00
From 1 to 2 the step is 2^-10. 2^-12 is a quarter of a step, so the sum rounds down to 1.0, pattern 3c00. This constant is already filled in.
Example 2
Worked Example: An Exact Tie- Input
the half-precision pattern of 1 + 2^-11 (an exact tie: the even neighbour is 1.0 itself)
- Output
sum_b = 0x3c00
2^-11 is exactly half a step. The neighbours are 1.0 (fraction ends in 0) and 1 + 2^-10 (ends in 1). The even one is 1.0. This constant is already filled in.
Example 3
Worked Example: A Gap- Input
the gap between 4096 and the next half-precision number (2^12 x 2^-10)
- Output
gap_4096 = 4
4096 is 2^12. In its binade the 10-bit fraction counts in steps of 2^12 x 2^-10, which is 4. This constant is already filled in.
Constraints and Contract
- Keep the module name answer and the names of the constants.
- Every pattern is a positive normal half-precision number.
Hints
Hint 1
Find the binade of the exact sum and its step. Then find the two neighbours on either side of the sum.
Hint 2
Look at the part below the step: less than half goes down, more than half goes up. Exactly half is a tie.
Hint 3
At a tie, pick the neighbour whose last fraction bit is 0. For the two-step sums, round after the first add before you do the second.
What the grader checks: The check reads thirteen constants. Each is compared with a value from the IEEE half-precision type of Node. It cannot see how a value was found.
13 checks on Icarus · browser samples / server checks. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain public samples only. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 2 steps and the final capstone