Document how to add a bytecode specialization
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 2.1k
- 分支
- 1k
- 平均合併
- 2 天 12 小時
- 30 天內合併 PR
- 12
描述
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.
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
使用 PR 116385 和九步大綱作為參考資料。首先檢視所引用的變更和指定的檔案—Python/bytecodes.c、Include/internal/pycore_code.h、Python/specialize.c、Lib/opcode.py 和 Include/internal/pycore_magic_number.h—然後選擇 devguide 或 CPython 文件中的適當位置。完成的標準是:新貢獻者能夠依照 specialization 工作流程操作,並使用 make regen-all 或 build.bat --regen 進行驗證。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- compilers, documentation
- Issue 類型
- 文件
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 活躍
- 描述清晰度
- 基本清楚
- 新手友好度
- 74/100