5 ms·
Setting the high bit would mean that the integer values are no longer automatically distinguishable from pointer values, which is kind of the whole point.
by breadbox 12y ago
Setting the high bit would mean that the integer values are no longer automatically distinguishable from pointer values, which is kind of the whole point.
- TheLoneWolfling 12y agoWhy? You could just check if the high bit is set, instead of if the low bit is set. IIRC, you can do this just by checking if it is less than zero.
- infogulch 12y agoFirst, pointers are typically unsigned integers. Second, memory addresses are virtual, they don't have to exist physically. That is, you don't have to physically have up through 2 quintillion addressable bytes for a pointer with that value to be valid. This is especially true with Address Space Layout Randomization (ASLR) security techniques employed by operating systems. tl;dr: all valid pointer values are possible, regardless of how much memory you actually have.
- TheLoneWolfling 12y agoSo then store the pointer implicitly right-shifted by 1. Means that boxed access is slower, but unboxed access is faster. And, when you get down to the assembly level, it doesn't matter - you can treat an unsigned integer as signed for a comparison if it makes things easier.
- Someone 12y agoThere could be addressable memory with the high bit set, for example ROM space for booting or video memory. That may be rare nowadays (or is it? I remember reading recently that some 64-bit CPU chose to preferably use a memory range from -2GB to +2GB. AMD64?), but whether there is is outside of the control of most language implementers. They can control their own memory allocator, though, and guarantee that it never stores 64-bit quantities at odd addresses.
- breadbox 12y agoThe issue is that pointers with the high bit set are commonplace, whereas pointers that are not aligned to the processor's word size are easily avoided (and on some architectures, outright invalid).
- TheLoneWolfling 12y agoSo then store the pointer right-shifted by 1.
- jzwinck 12y agoOn amd64, a pointer must have the top 17 bits all the same, or else it is not a valid pointer. On Windows and Linux, user space is the "lower half" which means bits 47 to 63 must all be zero for a value to be a pointer. This gives you 65535 tag values without using the LSB at all.