Title: Document how to add a bytecode specialization · Issue #1286 · python/devguide · GitHub
Open Graph Title: Document how to add a bytecode specialization · Issue #1286 · python/devguide
X Title: Document how to add a bytecode specialization · Issue #1286 · python/devguide
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: h...
Open Graph 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 pic...
X 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...
Opengraph URL: https://github.com/python/devguide/issues/1286
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Document how to add a bytecode specialization","articleBody":"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!\r\n\r\nThere reference is this PR: https://github.com/python/cpython/pull/116385/files\r\n\r\nAssuming you found an instruction that serves as a good specialization candidate. Let's use the example of `CONTAINS_OP`:\r\n1. 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`.\r\n2. Add the uop that calls a specializing function. In this case `_SPECIALIZE_CONTAINS_OP`.\r\n3. The original `CONTAINS_OP` is now a new macro consisting of `_SPECIALIZE_CONTAINS_OP + _CONTAINS_OP`.\r\n4. Define the cache structure in `Include/internal/pycore_code.h`. At the very least, a 16-bit counter is needed.\r\n5. Write the specializing function itself in `Python/specialize.c`. Refer to any other function in that file for the format.\r\n6. Remember to update operation stats by calling `add_stat_dict` in `Python/specialize.c`.\r\n7. Add the cache layout in `Lib/opcode.py` so that Python's `dis` module will know how to represent it properly.\r\n8. Bump magic number in `Include/internal/pycore_magic_number.h`.\r\n9. Run `make regen-all` on *nix or `build.bat --regen` on PC.","author":{"url":"https://github.com/Fidget-Spinner","@type":"Person","name":"Fidget-Spinner"},"datePublished":"2024-03-06T17:24:44Z","url":"https://github.com/python/devguide/issues/1286"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:7f982854-fb2c-b04d-355a-0961ad6ad6cd |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8E64:23DB5F:2CD16D:3874C3:6B01F76C |
| html-safe-nonce | 23dc63fe1e6c93fdb58162129d586817ec05625ebd51c781cd9d7131f182fb84 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RTY0OjIzREI1RjoyQ0QxNkQ6Mzg3NEMzOjZCMDFGNzZDIiwidmlzaXRvcl9pZCI6Ijc3NjUyMjkyMzcyMDM3NjEwMDQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | b13a8fed38b6725e211307ff53a4a3cb8683c6be3dd935ce9fede07470ed5d47 |
| hovercard-subject-tag | issue:2172056425 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/devguide/1286/issue_layout |
| twitter:image | https://opengraph.githubassets.com/fb305d6adafe13332ae0c8c123b01810ec076c5104318477c08cf2927aa73e23/python/devguide/issues/1286 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/fb305d6adafe13332ae0c8c123b01810ec076c5104318477c08cf2927aa73e23/python/devguide/issues/1286 |
| og:image:alt | 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 pic... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Fidget-Spinner |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/devguide git https://github.com/python/devguide.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 63972479 |
| octolytics-dimension-repository_nwo | python/devguide |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 63972479 |
| octolytics-dimension-repository_network_root_nwo | python/devguide |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width