User`s guide

Improving the Performance of Ported Code
4.2 Code Flow and Branch Prediction
JSB XYZ ;Call a routine
BLBS R0,10$ ;Branch to continue on success
BRW ERROR ;Destination too far for byte offset
10$:
In this case, and any case where the inline code following the branch is only a
few lines and does not rejoin the code flow at the branch destination, the forward
branch is considered taken. This eliminates the delay that occurs on OpenVMS
Alpha and OpenVMS I64 systems for a mispredicted branch. The compiler will
automatically change the sense of the branch, and will move the code between the
branch and the label out of line to a point beyond the normal exit of the routine.
For this example it would generate the following code:
JSR XYZ
BLBC $L1
10$:
.
.
.
(routine exit)
$L1: BRW ERROR
4.2.2 Changing the Compilers Branch Prediction
The compiler provides two directives, .BRANCH_LIKELY and .BRANCH_
UNLIKELY, to change its assumptions about branch prediction. The directive
.BRANCH_LIKELY is for use with forward conditional branches when the
probability of the branch is large, say 75 percent or more. The directive
.BRANCH_UNLIKELY is for use with backward conditional branches when
the probability of the branch is less than 25 percent.
These directives should only be used in performance-sensitive code. Furthermore,
you should be more cautious when adding .BRANCH_UNLIKELY, because it
introduces an additional branch indirection for the case when the branch is
actually taken. That is, the branch is changed to a forward branch to a branch
instruction, which in turn branches to the original branch target.
There is no directive to tell the compiler not to follow an unconditional branch.
However, if you want the compiler to generate code that does not follow the
branch, you can change the unconditional branch to be a conditional branch that
you know will always be taken. For example, if you know that in the current code
section R3 always contains the address of a data structure, you could change a
BRB instruction to a TSTL R3 followed by a BNEQ instruction. This branch will
always be taken, but the compiler will fall through and continue code generation
with the next instruction. This will always cause a mispredicted branch when
executed, but may be useful in some situations.
4.2.3 How to Use .BRANCH_LIKELY
If your code has forward conditional branches that you know will most likely
be taken, you can instruct the compiler to generate code using that assumption
by inserting the directive .BRANCH_LIKELY immediately before the branch
instruction. For example:
Improving the Performance of Ported Code 4–5