Document how to add a bytecode specialization
Personne n'a encore pris cette issue.
- Langage dominant
- Python
- Étoiles
- 2.1k
- Forks
- 1k
- Merge moyen
- 2 j 12 h
- PR mergées (30 j)
- 12
Description
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:
- Set the original
CONTAINS_OPto a uop by changing it fromCONTAINS_OPto_CONTAINS_OPinPython/bytecodes.c. The instruction definition should also change frominsttoop. - Add the uop that calls a specializing function. In this case
_SPECIALIZE_CONTAINS_OP. - The original
CONTAINS_OPis 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_dictinPython/specialize.c. - Add the cache layout in
Lib/opcode.pyso that Python'sdismodule will know how to represent it properly. - Bump magic number in
Include/internal/pycore_magic_number.h. - Run
make regen-allon *nix orbuild.bat --regenon PC.
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Utilisez PR 116385 et le plan en neuf étapes comme sources de référence. Commencez par examiner les modifications référencées et les fichiers indiqués—Python/bytecodes.c, Include/internal/pycore_code.h, Python/specialize.c, Lib/opcode.py et Include/internal/pycore_magic_number.h—puis choisissez l’emplacement approprié dans la devguide ou la documentation de CPython. Le travail est terminé lorsqu’une personne débutante peut suivre le workflow de spécialisation et le vérifier avec make regen-all ou build.bat --regen.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python
- Domaine
- compilers, documentation
- Type d'issue
- Documentation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- Active
- Clarté
- Plutôt claire
- Accessibilité débutants
- 74/100