3 ms·
This is a tangent, but I was reminded of early Macintosh days, where the 68000 processor in the original Mac hardware only paid attention to the lower 24 bits o
by wrs 4y ago
This is a tangent, but I was reminded of early Macintosh days, where the 68000 processor in the original Mac hardware only paid attention to the lower 24 bits of addresses, and only the lower 22 were actually connected to memory. The heap manager used the upper bits of pointers as a convenient place to store flags, and didn’t bother zeroing them on dereference because they were ignored anyway.
The release of the 68020 and Macs with more RAM resulted in the need for a whole transition to “32-bit clean” system and apps that took a while. I also seem to recall something about early versions of Microsoft Mac apps being limited to the lower megabyte of RAM for a similar reason.
- bombcar 4y agoAs we get to 64 bits and more the temptation to do “useful” things with the unused bits will grow …
- cesarb 4y agoThere's even official hardware support for doing that. ARM calls it Top Byte Ignore, it's supported on all 64-bit ARM CPUs, and it's been enabled on Linux for a long time (see https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/arm64/tagged-pointers.rst?h=v5.19 https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/lin... and https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/arm64/tagged-address-abi.rst?h=v5.19 https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/lin...). Intel calls it Linear Address Masking and AMD calls it Upper Address Ignore, however these will be available only on very recent hardware, and the Linux patches for them are still under development (see https://lwn.net/Articles/902094/ https://lwn.net/Articles/902094/ and https://lwn.net/Articles/888914/ https://lwn.net/Articles/888914/).
- cyber_kinetist 4y agoPeople are already doing all sorts of useful things with it! Only the 48 bits of the address space are actually being used by virtual memory (no current 64-bit OS is anticipating people to use more than 256TB of address space), so you can use the remaining 16 bits for... lots of things. (Note that there's also the lower 3 bits that aren't being used since memory addresses are aligned to a multiple of 8.) The primary example is Lua (before 5.4, and also LuaJIT): they use NaN-boxing to make their object take only 8 bytes. Although a double (Lua's only number type) already takes up 8 bytes of memory, there are some bits residing on the high 16-bits that are free to use when the number is NaN. With that you can store the type tag in there, which enables you to use the remaining bits for things other than double (like for example, storing memory addresses...) The Crafting Interpreters book has a much better explanation of this: https://craftinginterpreters.com/optimization.html#nan-boxing https://craftinginterpreters.com/optimization.html#nan-boxin... You can look up at https://en.wikipedia.org/wiki/Tagged_pointer https://en.wikipedia.org/wiki/Tagged_pointer to see some more examples. Apple seems to use this a lot for their Objective-C runtime on iOS where the leftover bits are used for things like refcounts or various boolean flags for their objects. Personally I had experience exploiting this in my game engine: for storing the generational index for a memory arena (to catch any use-after-free errors).
- p_l 4y agoNan-boxing is also used by Firefox, especially in JS implementation.
- Vogtinator 4y agoEven more extreme: https://en.wikipedia.org/wiki/A20_line https://en.wikipedia.org/wiki/A20_line
- agent86 4y agoAndy Hertzfeld called this his "worst blunder" with the original Macintosh. He talks about this, and a few other things he wishes they did differently in retrospect, in his folkore.org post titled "Mea Cupla".[1] [1] https://www.folklore.org/StoryView.py?project=Macintosh&story=Mea_Culpa.txt https://www.folklore.org/StoryView.py?project=Macintosh&stor...