[Python-Dev] Re: Re: Int FutureWarnings and other 2.4 TODOs
Tim Peters
tim.one at comcast.net
Thu Dec 4 11:44:09 EST 2003
[Andrew Koenig]
>>> So here's the strategy: If the low-order bit of an integer is
>>> *off*, it's really a pointer to the rest of the implementation. If
>>> the low-order bit is *on*, then it represents an integral value
>>> that can be obtained by doing a one-bit arithmetic right shift.
>>>
>>> Yes, it's sleazy. But I imagine it would be much faster than using
>>> inheritance.
[Phillip J. Eby]
>> I imagine it wouldn't, because it'd add an extra test to not only
>> every Py_INCREF and Py_DECREF, but every PyObject_something call.
[Michael Hudson]
> It wouldn't have to be that bad if you put the pointer/int thingy in
> the ob_ival slot.
Not all HW Python runs on is byte-addressed, so the base idea that "the last
bit" of a pointer-to-non-trivial-structure is always 0 doesn't get off the
ground. C doesn't have an arithmetic right-shift operator either, but that
one is easier to worm around (pyport.h already has a
Py_ARITHMETIC_RIGHT_SHIFT macro to "do the right thing").
OTOH, the only current Python platform I know of that's word-addressed is
the Cray T3E, which also happens to be the only one I know of where C's
signed ">>" zero-fills (and is also the only one I know of that has no
16-bit integral type -- the T3E porters had an interesting <wink> time).
More information about the Python-Dev
mailing list