>I would assume that 1 branch (the first option) is always faster than
>2 branches (the second option). The branch prediction in the CPU
>should figure out with execution path is most likely.

That is not a correct assumption, even if the branch prediction "table" of
the CPU was long enough to remember every branch ever taken for the life
of the power-on.
You would need to know if this code is even executed enough to stay in any
sort of table (let alone in cache).

I'm not saying which is faster, just that the assumption is incorrect. In
this land of pipelines and out of order execution (mixed with operating
system dispatches and redispatches), hard and fast rules are hard to come
by.

What is knowable is that the general approach of the machine is to look
ahead and to prefer that conditional branches not be taken.
And when looking ahead, it knows that an unconditional branch will be
taken so it can continue forward. So maybe it will be able to look further
forward in the fall-through case.

Peter Relson
z/OS Core Technology Design

Reply via email to