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

likely/unlikely annotations #1361

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions p4-16/spec/P4-16-spec.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8952,6 +8952,34 @@ to two controllable entities, which is illegal.
The `@atomic` annotation, described in <<sec-concurrency>>
can be used to enforce the atomic execution of a code block.

==== Branch prediction annotations

The `@likely` and `@unlikely` annotation can be used on blocks that
are used in `if`-`else` or `switch` statements to hint when a branch
is likely or unlikely to be taken.

[source.p4]
----
if (error_failure) @unlikely {
/* code that is unlikely to execute as the condition is probably false */
}

switch(value) {
1: @likely {
/* code for the most common case */
}
2: { /* ... */ }
default: @unlikely {
/* code for rare case */
}
}
----

These annotations have no effect on the semantics of the program; they are
just hints to help an optimizer. A warning may be issued if a `@likely`
block is found to never execute or an `@unlikely` block will always execute,
but is not required.

[#sec-value-set-annotations]
==== Value set annotations

Expand Down