Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persuade MSVC to generate indirect threaded code. #183

Closed
markshannon opened this issue Dec 14, 2021 · 2 comments
Closed

Persuade MSVC to generate indirect threaded code. #183

markshannon opened this issue Dec 14, 2021 · 2 comments

Comments

@markshannon
Copy link
Member

MSVC is able to merge a normal jump to a computed jump into a single computed jump.

It does, however, seems quite picky about when it will merge the goto and computed branch for the switch into a single branch, but it can be persuaded to do so (at least on this online compiler):

https://godbolt.org/z/nss93dr7T

It seems that MSVC is quite keen on merging similar code paths.
If the code immediately before the dispatch: label resembles DISPATCH to closely, we get the same code as if a default we used.
If all the illegal opcode cases are written as oparg = opcode; instead of oparg = LITERAL_VALUE then the cases are merged and we get jump merging, but with an extra memory read. This might be an acceptable compromise as it should still help the branch predictor.

I don't think we can directly test that the code is compiling as we wish.
We could check it manually initially and then rely on performance testing to show up any regressions.
For that we would need a Windows machine for performance testing.

@markshannon
Copy link
Member Author

This issue is the third part of #33

@markshannon
Copy link
Member Author

We now generate a complete set of labels, so that MSCV can eliminate any bounds checks.
Beyond that it is tricky trying to second guess the compiler.

With the JIT framework we can potentially generate a tailcall based implementation of the interpreter which fix this problem and benefit performance on all platforms. #642

@github-project-automation github-project-automation bot moved this from Todo to Done in Fancy CPython Board Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

1 participant