Skip to content

Commit af4dd3d

Browse files
Merge pull request #1361 from ChrisDodd/cdodd-likely
likely/unlikely annotations
2 parents c25a780 + 3d8e4c9 commit af4dd3d

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

p4-16/spec/P4-16-spec.adoc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8952,6 +8952,34 @@ to two controllable entities, which is illegal.
89528952
The `@atomic` annotation, described in <<sec-concurrency>>
89538953
can be used to enforce the atomic execution of a code block.
89548954

8955+
==== Branch prediction annotations
8956+
8957+
The `@likely` and `@unlikely` annotation can be used on blocks that
8958+
are used in `if`-`else` or `switch` statements to hint when a branch
8959+
is likely or unlikely to be taken.
8960+
8961+
[source.p4]
8962+
----
8963+
if (error_failure) @unlikely {
8964+
/* code that is unlikely to execute as the condition is probably false */
8965+
}
8966+
8967+
switch(value) {
8968+
1: @likely {
8969+
/* code for the most common case */
8970+
}
8971+
2: { /* ... */ }
8972+
default: @unlikely {
8973+
/* code for rare case */
8974+
}
8975+
}
8976+
----
8977+
8978+
These annotations have no effect on the semantics of the program; they are
8979+
just hints to help an optimizer. A warning may be issued if a `@likely`
8980+
block is found to never execute or an `@unlikely` block will always execute,
8981+
but is not required.
8982+
89558983
[#sec-value-set-annotations]
89568984
==== Value set annotations
89578985

0 commit comments

Comments
 (0)