News for hackers. Stuff that matters.
Re:Emacs internals: Deconstructing Lisp_Object in C (Part 2) by HexDecOctBin on Sunday March 08, 2026 @07:34AM (#47296515)
Why do they use the bottom bit for tag and not the top bit?
Re:Emacs internals: Deconstructing Lisp_Object in C (Part 2) by kryptiskt on Sunday March 08, 2026 @08:16AM (#47296720)
Traditionally it has been done because the last three bits in an object pointer typically are always zero because of alignment, so you could just put a tag there and mask it off (or load it with lea and an offset, especially useful if you have a data structure where you'd use an offset anyway like pairs or vectors). In 64-bit architectures there are two bytes at the top that aren't used (one byte with five-level paging), but they must be masked, since they must be 0x00 or 0xff when used for pointers. In 32-bit archs the high bits were used and unsuitable for tags. All in all, I think the low bits still are the most useful for tags, even if 32-bit is not an important consideration anymore.
Re:Emacs internals: Deconstructing Lisp_Object in C (Part 2) by birdgoose on Sunday March 08, 2026 @01:03PM (#47298902)
The sibling comment explains why we prefer to use the lower bits as a tag (these are guaranteed to be zero if the value is a pointer on a 64-bit system).

Another reason why we wouldn’t want to use the top bit is that, as the parent comment suggested, the tagged pointer representation of a fixnum integer isn’t a pointer at all but is instead twice the number it represents. Generally speaking, we represent integers in twos-complement representation which uses that top bit to determine if the value is positive or negative.