[Python-Dev] Tagged integers (original) (raw)

Jeff Epler jepler at unpythonic.net
Thu Jul 15 04:32:18 CEST 2004


On Wed, Jul 14, 2004 at 02:41:19AM -0400, James Y Knight wrote:

- Thus, no code can directly access object fields ->obrefcnt, or ->obtype. Introduced PyGETTYPE/PyGETREF macros and search&replaced code in python to use them. These macros check the tag bits, and do the right thing if it is tagged data.

If this looks like a promising direction, Py_GETTYPE and Py_GETREF macros could be added today, in 2.5 or 2.6 ob_refcnt and ob_type would be removed/renamed, and 2.6 or 2.7 would see the first actual use of tagged types. Sure, you couldn't compile a 2.4 extension on 2.6, but will it matter?

By the way, I don't know what optimizers actually do, but given PyObject *spam(PyObject *o) { Py_GETTYPE(o); junk; Py_GETREF(o); junk; Py_INCREF(o); junk; Py_DECREF(o); junk; } the compiler is free to notice that "o" can't change (its address is never taken), so the "is it a tagged object" test can be done once, not 4 times.

I assume that tagged integers could be turned off at compile time, for the platforms where they don't work for one reason or another.

I'm showing my ignorance here, but what other types are traditionally tagged, and do any of those translate well to Python?

I suppose you could tag some singleton objects, like None, True, False, and (), but those are already shared.

Tagging length-1 strings and unicode strings seems like it might have its advantages, though the length-0 and length-1 strings, length-0 unicode strings, and first 256 length-1 unicode strings are already shared too.

I can't see much use for a 21-bit-mantissa floating-point type, and I can't see how you could use tagging for any other types in Python.

Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.python.org/pipermail/python-dev/attachments/20040714/85ce004a/attachment.pgp



More information about the Python-Dev mailing list