Document how to add a bytecode specialization in Interpreter.md file#130831
Document how to add a bytecode specialization in Interpreter.md file#130831faizanoor3001 wants to merge 10 commits intopython:mainfrom
Conversation
…ecode-specialization-guide
Fidget-Spinner
left a comment
There was a problem hiding this comment.
Thanks. Look good mostly. Just a few minor edits.
InternalDocs/interpreter.md
Outdated
|
|
||
| 3. Write the specializing function itself in [Python/specialize.c ](../Python/specialize.c). | ||
| Refer to any other function in that file for the format. | ||
| 4. Remember to update operation stats by calling add_stat_dict in |
There was a problem hiding this comment.
| 4. Remember to update operation stats by calling add_stat_dict in | |
| 4. Remember to update operation stats by calling `add_stat_dict` in |
InternalDocs/interpreter.md
Outdated
| - Add a uop that calls the specializing function `_SPECIALIZE_CONTAINS_OP`. | ||
| For example. |
There was a problem hiding this comment.
| - Add a uop that calls the specializing function `_SPECIALIZE_CONTAINS_OP`. | |
| For example. | |
| - Add a uop that calls the specializing function: |
InternalDocs/interpreter.md
Outdated
| - The original `CONTAINS_OP` is now a new macro consisting of | ||
| `_SPECIALIZE_CONTAINS_OP` and `_CONTAINS_OP`. |
There was a problem hiding this comment.
Create a macro for the original bytecode name:
macro(CONTAINS_OP) = _SPECIALIZE_CONTAINS_OP + _CONTAINS_OP;
InternalDocs/interpreter.md
Outdated
| 3. Write the specializing function itself in [Python/specialize.c ](../Python/specialize.c). | ||
| Refer to any other function in that file for the format. | ||
| 4. Remember to update operation stats by calling `add_stat_dict` in | ||
| [Python/specialize.c ](../Python/specialize.c). | ||
| 5. Add the cache layout in [Lib/opcode.py](../Lib/opcode.py) so that Python's | ||
| dis module will know how to represent it properly. | ||
| 6. Bump magic number in [Include/core/pycore_magic_number.h](../Include/internal/pycore_magic_number.h). | ||
| 7. Run ``make regen-all`` on `*nix` or `build.bat --regen` on Windows. | ||
|
|
There was a problem hiding this comment.
| 3. Write the specializing function itself in [Python/specialize.c ](../Python/specialize.c). | |
| Refer to any other function in that file for the format. | |
| 4. Remember to update operation stats by calling `add_stat_dict` in | |
| [Python/specialize.c ](../Python/specialize.c). | |
| 5. Add the cache layout in [Lib/opcode.py](../Lib/opcode.py) so that Python's | |
| dis module will know how to represent it properly. | |
| 6. Bump magic number in [Include/core/pycore_magic_number.h](../Include/internal/pycore_magic_number.h). | |
| 7. Run ``make regen-all`` on `*nix` or `build.bat --regen` on Windows. | |
| 3. Write the specializing function itself (_Py_Specialize_ContainsOp) in [Python/specialize.c ](../Python/specialize.c). | |
| Refer to other functions in that file for the pattern. | |
| 4. Add a call to `add_stat_dict` in `_Py_GetSpecializationStats` which is in | |
| [Python/specialize.c ](../Python/specialize.c). | |
| 5. Add the cache layout in [Lib/opcode.py](../Lib/opcode.py) so that Python's | |
| `dis` module will know how to represent it properly. | |
| 6. Bump magic number in [Include/core/pycore_magic_number.h](../Include/internal/pycore_magic_number.h). | |
| 7. Run `make regen-all` on `*nix` or `build.bat --regen` on Windows. | |
There was a problem hiding this comment.
This suggestion has some edits to the text as well, not just whitespace.
|
Let's give @brandtbucher a chance to review as well. |
brandtbucher
left a comment
There was a problem hiding this comment.
Looks correct. A couple of possible minor improvements, if we're aiming to be comprehensive here:
| 6. Bump magic number in [Include/core/pycore_magic_number.h](../Include/internal/pycore_magic_number.h). | ||
|
|
||
| 7. Run ``make regen-all`` on `*nix` or `build.bat --regen` on Windows. | ||
|
|
There was a problem hiding this comment.
Seems like the only thing missing is adding an actual specialized variant. Maybe that's implied/obvious, but it wouldn't hurt to provide a dumb example of _Py_Specialize_ContainsOp and _CONTAINS_OP_UNICODE_UNICODE that just guards and calls PyUnicode_Contains or something.
ZeroIntensity
left a comment
There was a problem hiding this comment.
Several grammar nitpicks--English is hard!
|
I've applied the suggestions. Ready to merge? And backport? |
Co-authored-by: Ken Jin <kenjin4096@gmail.com> Co-authored-by: Peter Bierma <zintensitydev@gmail.com> Co-authored-by: Brandt Bucher <brandtbucher@gmail.com>
Solves: python/devguide#1286
Description
CONTAINS_OPas an example.PS: Initial PR for reference: python/devguide#1522
📚 Documentation preview 📚: https://cpython-devguide--1522.org.readthedocs.build/