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

Get rid of conditional inputs and outputs for instructions in bytecodes.c #716

Open
markshannon opened this issue Jan 15, 2025 · 1 comment

Comments

@markshannon
Copy link
Member

Conditional inputs and outputs of the form arg if (oparg &1) are used in a few instructions in bytecodes.c

They have the advantage of reducing the size of bytecodes and the number of instructions executed, but they add conditional code to the instruction bodies. They also complicate the code generators quite a lot, requiring extra logic to split the uops in the jit and special handling in the interpreter generator.

I'm wondering if inefficiencies due to the additional complexity might equal or outweigh the efficiency of the reduced instruction count.
Even if it does not yet, I expect that it might when we add top of stack caching as irregular stack depths complicates code generation even more.

From a maintenance perspective, even if it introduced a small slow down, removing conditional inputs and outputs would probably be worth it.

@brandtbucher
Copy link
Member

I agree.

Maybe there's a nice way to keep the optimization but lean on the code generator to reduce duplication. For example:

inst(FOO_WITH_SELF, (in -- out, self)) {
    // ...
}

macro(FOO_WITHOUT_SELF) = FOO_WITH_SELF + POP_TOP;

inst(BAR_WITHOUT_NULL, (in -- out)) {
    // ...
}

macro(BAR_WITH_NULL) = BAR_WITHOUT_NULL + PUSH_NULL;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants