Skip to content

Standard annotations for expected code path to optimize #1308

Open
@ChrisDodd

Description

There should be a way for the programmer to indicate which path through a control or parser should be the most common and should be optimized for.

One possibility would be something like:

if (pred) @unexpected {
    ... code that rearely executes
}

putting an @unexpected annotation on the block in the if statement tells optimizers that the code in the block will rarely be executed and the fall-through case should be optimized for.

Putting the annotation on the statement fits well with what p4c currently supports (annotations on block statements) and also works in other cases like:

switch(something) {
    case 1: @expected {
        ... common case code ...
    }
    case 2: {
        ... another case, less common ...
    }
    default: @unexpected {
        ... rarely executed code ...
    }
}

This contrasts with eg. gccc's way of doing this sort of thing, which is by having a __builtin_expected(expression, value) function.

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions