You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How to add a new bytecode specialization is knowledge only a few of us remember right now. We should document this somewhere (devguide or CPython, I don't mind). Hopefully a new contributor can pick this up!
Assuming you found an instruction that serves as a good specialization candidate. Let's use the example of CONTAINS_OP:
Set the original CONTAINS_OP to a uop by changing it from CONTAINS_OP to _CONTAINS_OP in Python/bytecodes.c. The instruction definition should also change from inst to op.
Add the uop that calls a specializing function. In this case _SPECIALIZE_CONTAINS_OP.
The original CONTAINS_OP is now a new macro consisting of _SPECIALIZE_CONTAINS_OP + _CONTAINS_OP.
Define the cache structure in Include/internal/pycore_code.h. At the very least, a 16-bit counter is needed.
Write the specializing function itself in Python/specialize.c. Refer to any other function in that file for the format.
Remember to update operation stats by calling add_stat_dict in Python/specialize.c.
Add the cache layout in Lib/opcode.py so that Python's dis module will know how to represent it properly.
Bump magic number in Include/internal/pycore_magic_number.h.
Run make regen-all on *nix or build.bat --regen on PC.
The text was updated successfully, but these errors were encountered:
How to add a new bytecode specialization is knowledge only a few of us remember right now. We should document this somewhere (devguide or CPython, I don't mind). Hopefully a new contributor can pick this up!
There reference is this PR: https://github.com/python/cpython/pull/116385/files
Assuming you found an instruction that serves as a good specialization candidate. Let's use the example of
CONTAINS_OP
:CONTAINS_OP
to a uop by changing it fromCONTAINS_OP
to_CONTAINS_OP
inPython/bytecodes.c
. The instruction definition should also change frominst
toop
._SPECIALIZE_CONTAINS_OP
.CONTAINS_OP
is now a new macro consisting of_SPECIALIZE_CONTAINS_OP + _CONTAINS_OP
.Include/internal/pycore_code.h
. At the very least, a 16-bit counter is needed.Python/specialize.c
. Refer to any other function in that file for the format.add_stat_dict
inPython/specialize.c
.Lib/opcode.py
so that Python'sdis
module will know how to represent it properly.Include/internal/pycore_magic_number.h
.make regen-all
on *nix orbuild.bat --regen
on PC.The text was updated successfully, but these errors were encountered: