Skip to content

Allow inlining jump table #3862

@ultimaweapon

Description

@ultimaweapon

Background

I'm working on a port of Lua to Rust and currently hit a road block to make Rust performance to match with C version due to Rust currently does not support computed goto. For people who does not familiar with computed goto it is a GCC extension to allows getting the address of a label and goto statement can jump into that label dynamically:

static void *array[] = { &&foo, &&bar, &&hack };

goto *array[i];

This technique can drastically increase the performance of bytecode interpreter due to a jump to next handler can be inlined instead of jumping back to the beginning on the loop then do a next jump.

Proposal

I propose adding an attribute on continue statement to inline the jump like this:

loop {
    match inst.op() {
        Op::Bar => {
           inst = instructions.next();

            #[inline]
            continue;
        }
        Op::Foo => {
            inst = instructions.next();

            #[inline]
            continue;
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions