5 ms·
nice!. one thing about NaN is that, because the specification only mentions the exponent part, you have all the mantissa bits free for use, this is the idea beh
by longemen3000 5y ago
nice!. one thing about NaN is that, because the specification only mentions the exponent part, you have all the mantissa bits free for use, this is the idea behind signalling NaNs, that if you return a NaN for an operation, that value should have some helpful debug information
- hinoki 5y agoAlso, NaN boxing. Which is (was?) used by JavaScript Core (Safari’s JS engine). All values are stored as a double; true, false, null, undefined have different NaN values. NaN even has enough spare bits to store Object pointers. Short strings are also stored packed into NaN bits.
- cormacrelf 5y agoHopefully not as an actual double, right? Not that many floating point registers compared to integer on most archs.
- hinoki 5y agoI think you can use general purpose registers so long as you don’t actually need to do IEEE 754 math. I’m not clear on the details of how the byte code/JIT deals with it, my only experience is with hire values are stored in the heap.
- saagarjha 5y agoYes, they’re stored in a union and passed around as whatever is convenient.
- Tuna-Fish 5y agoThere are an equal amount of vector (also used for FP) regs as there are gprs on x86_64 and on Aarch64. Since those registers are rarely used in normal general purpose code, moving some values over there in principle saves register space. (x87 fp is obsolete and should never be used for anything.)
- KMag 5y agoI'm not sure the latency on moving data between SSE and GP registers on modern x86 processors. If I remember correctly, late 1990s x86 was notoriously slow at moving data between GP registers and the x87 fp stack. I could certainly believe that on some architectures, moving data between vector registers and GP registers is slower than an L1 cache access.
- saagarjha 5y agoIt’s still in use, plus Mozilla uses it too.
- an1sotropy 5y agoWhat has always annoyed me is that the spec never says, AFAIK, if the 23rd bit should be ON vs OFF for a signalling vs quiet NaN, which means that you can't portably set a value to a quiet NaN at compile-time. SGI/Irix machines in the 2000s, for example, had perfectly good floating point but had the 23rd being OFF for a quiet NaN, while other machines have it ON for quiet NaN. And this is independent of endien-ness: these SGIs were big endien just like other big-endian machines that made quiet NaN differently.
- junon 5y agoAll but the first one (MSB) which, while not specified, is sometimes used by systems as a flag for loud errors vs. quiet errors.