Minecraft Maps / Redstone Device

Half-Precision Floating Point Adder

  • 3,575 views, 3 today
  • 84 downloads, 0 today
  • 10
  • 2
  • 3
properinglish's Avatar properinglish
Level 32 : Artisan Engineer
34
I present to you my floating point adder! First, the obvious question: What is this? Floating point is a way of representing an extremely broad range of numbers using the formula: Significant digits x BaseExponent. Half-precision means we do this using 16 bits - 1 sign bit, 5 exponent bits, and 10 significant digit (mantissa) bits. I'll be updating this thread with information about each component of the FPAS and how it works. Enjoy!

The steps in floating point addition/subtraction are:
1. Mantissa Alignment: You need to align the mantissa of each number.

2. Addition/Subtraction: Pretty straightforward - normal addition and two's complement subtraction.

3. Normalization: Putting the result back into a normalized form. This means left shifting so that the 20 is on and adjusting the exponent.

4. Rounding: During the alignment shift rounding bits (known as the guard, round, and sticky bits) are generated. These allow you to get some extra precision through rounding.

5. Re-normalization: There's one situation where rounding generates a sum that needs to be renormalized and this can be accomplished by a single right shift and adding 1 to the exponent.

Components



Organization:


Alignment Control: This is the logic that controls the alignment step, telling the shifter how many positions to shift (in this case, right shift). To do this I simply subtract one exponent from the other, however sometimes this generates a negative result. In that case a two's complement converter is turned on so that the absolute value is the output. Alignment control also selects the greater exponent and sends it to the exponent normalization adder. Finally, if any exponents are on an 11th mantissa bit (called the hidden bit) is turned on.


Mantissa Multiplexing: You always want the mantissa of the smaller number to go through the alignment shifter. This can be accomplished by "double multiplexing" the A and B inputs so that depending on the state of the exponents either mantissa A or B can go through the alignment shifter.

Barrel Shifter: Both the mantissa alignment and normalization steps are performed by a barrel shifter. This shifter shifts its inputs by a number of positions defined by its inputs - in this case the inputs come from the alignment control. The barrel shifter I used was built by Redstonewarrior and Anomalouscobra.

Sign Bits: The sign bits controls whether addition or subtraction occurs and whether the output is positive or negative.


Adder: I threw together a simple insta-carry adder for this. The only thing notable is that I prevent piston block-dropping with a two tick repeater. It's also hooked up so that it can subtract the mantissa that comes through the alignment shifter if the sign bit specifies.


Leading Zero Counter (Normalization Shifter Control): This component determines how many 0's there are before the first most significant 1 in the adder output. It then tells the normalization shifter how many positions to shift. I'm going to expand upon this section with more details about the logic for this because it's pretty cool.


Normalization Shifter: This takes the output of the leading zero counter and shifts the adder output that many positions to the left. Note that there's an intrinsic right shift. to normalize for the carry-out of the adder.


Exponent Normalizer: This is just an adder that subtracts the "output-of-the-leading-zero-counter - 1" from the output of the alignment normalizer to generate the exponent output.


Rounding Logic: This determines how the FPA will round based on the guard, round, and sticky bits. IEEE 754 specifies that there be four rounding modes - so that's what I did. They are:

  • Round to the nearest (ties go to even) - This is the default mode. If the guard bit and the round or sticky bits are on it rounds up. When there's a tie (only the guard bit is on) it rounds to even - so if the unit in the last place (ULP) is on it rounds up but if the ULP is 0 it remains 0.

  • Round towards zero (truncation) - This mode disregards the guard, round, and sticky bits and never rounds up.

  • Round towards positive infinity - Rounding towards positive infinity means you always round up. When a number is positive and any of the three rounding bits are on it rounds up by adding 1. When a number is negative and any of these bits are on it rounds up by adding 0 (adding one would make this more negative).

  • Round towards negative infinity - This is the opposite of rounding towards positive infinity. If the number is positive and any of the three rounding bits are on 0 is added. If the number is negative and any of these bits are on it adds one.

If you have any questions or would like more pictures/information, let me know! This was built on the Redstone Development Foundation Build Server! :D

Additional Notes

A big thanks to redstonewarrior and anomalouscobra for use of their barrel shifter!
Progress100% complete
Tags

Create an account or sign in to comment.

1
06/10/2012 1:24 pm
Level 41 : Master Electrician
fibonatic
fibonatic's Avatar
I assume that you used 2 as the base number? and shouldn't the exponent also has a sign bit?
I also looked at the theoretically use of floating point number to calculate certain function, such as log, exp, sqrt, sin, cos and tan, using a polynomial approximation which has a smaller error than the 1th mantissa bit.
1
06/10/2012 2:36 pm
Level 32 : Artisan Engineer
properinglish
properinglish's Avatar
Yup, it's base 2. The exponent doesn't need a sign bit because it has an offset of -15. So an exponent of 0 is represented as 01111. Single precision would have an offset of -127 so in that case 0 would be 01111111.
1
06/10/2012 1:14 pm
Level 1 : New Miner
jacopo975
jacopo975's Avatar
world map please
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome