5 votes

Float Self-Tagging

1 comment

  1. skybrian
    Link
    A paper about a clever alternative to NaN-tagging for representing unions between doubles and pointers in 64 bits, which is useful for implementing scripting languages and JavaScript in...

    A paper about a clever alternative to NaN-tagging for representing unions between doubles and pointers in 64 bits, which is useful for implementing scripting languages and JavaScript in particular. The trick is that most of the time, you only need 8 bits of exponent (like 32-bit floats) rather than 11 bits (like 64 bit floats) so they can represent commonly-used doubles as themselves, and decode pointers with a single rotation instruction. (High-exponent doubles still work, but are slower since they use a pointer.)

    It’s unclear how original it is. There are comments on Hacker News about previous implementations. But it’s the first I’ve heard of it and a nice writeup.

    3 votes