3 ms·
This is precisely how Ruby's object ids work. An object id is an 8-bit aligned pointer to the object's location in memory. The low 3 bits are used to identify
by regularfry 15y ago
This is precisely how Ruby's object ids work. An object id is an 8-bit aligned pointer to the object's location in memory. The low 3 bits are used to identify booleans, fixnums, nil and symbols.
I'm sure this was borrowed from a lisp implementation.
- arethuza 15y agoLisp machines typically had direct hardware support for these tags - Symbolics machines used 36 bit words, 32 bits of data and 4 bits of tags: http://en.wikipedia.org/wiki/Symbolics http://en.wikipedia.org/wiki/Symbolics
- dfox 15y agoAlso, SPARC has direct hardware support for this (for the cases that are relevant for JITed code, ie. arithmetics). But sadly, on current implementations it is often somehow emulated and thus slow.
- _delirium 15y agoApparently inspired by Lisp as well; this old '91 Usenet post by a Lucid employee claims that SPARC added the tagged-arithmetic support specifically for Lucid Common Lisp: http://compilers.iecc.com/comparch/article/91-04-082 http://compilers.iecc.com/comparch/article/91-04-082
- rayiner 15y agoIt's because there isn't much point. Most Lisps use a tagging scheme like: 00 = Integer 01 = Pointer With 00 as the integer tag, integer addition and subtraction can be done directly without masking off the tags. Multiplication and division need the tags masked, but are slow anyway. The tag can also be stripped off for free on any architecture that offers BASE + OFFSET addressing (just subtract 1 from the desired constant offset).