File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -8952,6 +8952,34 @@ to two controllable entities, which is illegal.
89528952The `@atomic` annotation, described in <<sec-concurrency>>
89538953can 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
You can’t perform that action at this time.
0 commit comments