Closed
Description
https://en.wikipedia.org/wiki/Tagged_pointer
Currently, a reference to a Python object is a PyObject *
. This means that we need to do a lot of boxing, unboxing and pointer chasing when handling int
s and float
s.
Because int
s and float
s are pure value types, we can freely replace references to them with their values, and vice-versa.
For 32 bit machines, using a single bit to tag small (up to 31 bit) integers is the most obvious scheme.
Tag | Meaning | Encoding |
---|---|---|
0 | int (31 bit) | val<<1 |
1 | PyObject * (including large ints and all floats) | ((intptr_t)val)-1 |
For 64 bit machines, there at least two schemes that we could use.
- NaN-tagging works for machines with up to about 52 bits of VM space, and allows tagging of all floats.
- A tagging scheme that allows 64 bit (aligned) pointers and boxes almost all floats, works as follows:
Tag | Meaning | Encoding |
---|---|---|
0 | int (61 bit) | val<<3 |
1-6 | float abs(val) < 2**512 |
rotate_bits(val, 4) |
7 | PyObject * (including large ints and large floats) | ((intptr_t)val)-1 |
Any C extensions that use macros to access the internals of tuples, lists, etc. would need recompiling, but they need recompiling for every release anyway.
Metadata
Metadata
Assignees
Labels
No labels