Stupid Half‐Precision Floating‐Point Conversion Table - widberg/fmtk GitHub Wiki

The game has a half‐precision to single-precision floating-point number conversion table where the index is the half‐precision floating-point number reinterpret_cast'ed to an unsigned short and the element is the single-precision floating-point number. For example, using Clang's built-in __fp16 type:

__fp16 float16_value = 0.5;
float float32_value = float16_to_float32_table[*(unsigned short*)&float16_value];

A simple playground for half‐precision floating-point numbers is available on Compiler Explorer https://godbolt.org/z/vjcTT3TM9. Compiler Explorer will truncate the output so I recommend compiling and running it locally with Clang.

This table did not appear to have any Xrefs and was likely statically linked as part of a math library but was never used. While programmatically doing this conversion is not cheap, it is probably not worth the size of this table to avoid even if it was used. Since there are 2^16=65536 possible indices and each element, a float, is 4 bytes, the total size of the table is (2^16)*4B=262144B. That's 256KiB! The game's executable is 6997.27KiB which means the percent of the executable that is this table is 256KiB/6997.27KiB=0.036585697=3.66%. Nearly 4% of the executable is this unused conversion table!

There is also a much smaller table and routine to go from single-precision to half-precision. The code is on Compiler Explorer https://godbolt.org/z/8Mqd8GfE7. Thankfully they didn't do a table-only approach since that would have been a big table. Since there would be 2^32=65536 possible indices and each element, a half-precision floating-point number, is 2 bytes, the total size of the table is (2^32)*2B=8589934592B. That's 8GiB, twice the size of the game disc!