Skip to content

Stupid Half‐Precision Floating‐Point Conversion Table

widberg edited this page Feb 5, 2024 · 4 revisions

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!

Home
FAQ

For FMTK Users and Mod Developers

Read the Docs

For FMTK Developers

Asobo BigFile Format Specification
Asobo Classes
      Animation_Z
      Binary_Z
      Bitmap_Z
      Camera_Z
      CollisionVol_Z
      Fonts_Z
      GameObj_Z
      GenWorld_Z
      GwRoad_Z
      Keyframer*_Z
      Light_Z
      LightData_Z
      Lod_Z
      LodData_Z
      Material_Z
      MaterialAnim_Z
      MaterialObj_Z
      Mesh_Z
      MeshData_Z
      Node_Z
      Omni_Z
      Particles_Z
      ParticlesData_Z
      RotShape_Z
      RotShapeData_Z
      Rtc_Z
      Skel_Z
      Skin_Z
      Sound_Z
      Spline_Z
      SplineGraph_Z
      Surface_Z
      SurfaceDatas_Z
      UserDefine_Z
      Warp_Z
      World_Z
      WorldRef_Z
Asobo File Format Idioms
Asobo CRC32
Asobo LZ Compression
Asobo Arithmetic Coding Compression
Asobo Save Game File Format Specification
Asobo Audio Formats
TotemTech/ToonTech/Zouna/ACE/BSSTech/Opal Timeline
Zouna Modding Resources
Miscellaneous

Clone this wiki locally