Re: More on Lisp structures performance
"Tim Bradshaw (as tfb at tfeb dot org)" <[email protected]>
| Newsgroups | gmane.lisp.lispworks.general |
|---|---|
| Message-ID | <[email protected]> |
On 22 Jan 2026, at 14:48, Yuri Davidovsky (as work at disclosure dot ie) <[email protected]> wrote: > > but lisp requires each value it owns to have a passport to identify itself, which in LW is an additional tag of 3 bits It is 4 bits in 64-bit LW (and I expect in almost any modern 64-bit Lisp). That's because addresses are double-word aligned so there are 4 free bits. The remainder of this only talks about 64-bit LW (or SBCL). In common with other implementations LW reserves two tags (0000 and 1000) for 'even fixnum' and 'odd fixnum', which allows fixnums to protrude into the space of tags so you get 61-bit fixnums. SBCL now goes much further and reserves *half* the tag space for fixnums: any tag of the form xxx0 is a fixnum tag in SBCL, which allows you to have 63-bit fixnums. For immediate quantities (say single-floats) there will be some additional tag bits, perhaps. Below are a couple of functions which will let you look at things. So for instance ? (print-decoded-object-address (cons 1 1)) P 0000000000000000000000001000000000110000000001100001100001110000 0001 (1 . 1) ? (print-decoded-object-address 1) I 0000000000000000000000000000000000000000000000000000000000000000 1000 1 ? (print-decoded-object-address 0) I 0000000000000000000000000000000000000000000000000000000000000000 0000 0 Disclaimer: Martin might say I'm wrong. --tim #-LispWorks (error "no") (defconstant 64-bit #+LispWorks-64bit t #+LispWorks-32bit nil) (defun decoded-object-address (o) (let ((tag-mask (load-time-value (1- (expt 2 (if 64-bit 4 3))))) (tagged-address (sys:object-pointer o))) (let ((address (logandc2 tagged-address tag-mask)) (tag (logand tagged-address tag-mask))) (assert (= address (sys:object-address o))) ;sanity (values address tag)))) (defun print-decoded-object-address (o &key (stream t) (address-base 2) (tag-base 2)) (format stream "~&~A" (if (sys:immediatep o) #\I #\P)) (multiple-value-bind (address tag) (decoded-object-address o) (ecase address-base (2 (format stream " ~V,'0B" (if 64-bit 64 32) address)) (16 (format stream " ~V,'0X" (if 64-bit 16 8) address))) (ecase tag-base (2 (format stream " ~V,'0B~%" (if 64-bit 4 3) tag)) (16 (format stream " ~2,'0X~%" tag))))) _______________________________________________ Lisp Hug - the mailing list for LispWorks users [email protected] http://www.lispworks.com/support/lisp-hug.html