Skip to content

Can super-instructions be rewritten as macros in the instruction definition DSL? #507

@gvanrossum

Description

@gvanrossum

Currently our DSL has two separate but similar bits of syntax for super- and macro instructions:

super(X) = A + B;
macro(X) = A + B;

These differ in that super() inserts some code between components:

<prologue>
{
    <code for A>
}
NEXTOPARG();
next_instr++;
{
    <code for B>
}
<epilogue>

whereas macro() doesn't (omitting NEXTOPARG(); next_instr++;).

(There are some other differences, in particular macros allow interspersing cache effects between the components.)

It turns out it is possible to rewrite any super-instruction of this form as a macro:

macro(X) = A + JOIN + B;

where JOIN is a micro-op defined roughly like this:

        op(JOIN, (word/1 --)) {
            oparg = _Py_OPARG(word);
        }

Given the limited use we have for super-instructions and the code duplication in the code generator to handle both, this seems a nice win.

Note: Eventually we may need to bring super() back into the DSL, but for a different use case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    epic-generatorDSL-based code generator for the interpreter(s)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions