简体   繁体   中英

Different types of branches

So my undertanding of branching is there is two types:

two way branch, a branch is taken based on the result of an some computation that is stored in a register. expensive and causes pipeline flushes.

one way branch, this is like a function pointer or a goto, it will go to constant address. Correct me if im mistaken but I think this are much cheaper than the two branch because modern processors will resolve these instructions early in the pipeline.

I imagined loop unrolling would be faster if a third type of branch existed. Normally, loop unrolling increases instruction size, but avoids the two way branching. What if you had a branch that aovids both instruction size and two branching. Like a branch that does something like loop over a piece of code a constant amount of times.

What type of branchs exist?

A jump (or call) can be:

-either direct or indirect
-either relative or absolute
-either conditional or unconditional

Conditional/unconditional describes whether the branch is predicated or not.

Relative/absolute is a matter of encoding the branch target , either as an offset from the current instruction pointer or as the absolute address of the branch target.

If the branch is absolute , the target address can be stored as a variable, as it can be used from anywhere in the code (ideally). This means you can load this variable and perform an indirect branch to it.

These properties of a branch are almost orthogonal. Common combinations are:

-direct relative conditional. Your standard if .
-direct relative unconditional. Your standard goto and function call.
-direct absolute unconditional. Some function calls.
-direct absolute conditional. Rare, not many hardware architectures can encode such an instruction.
-indirect absolute unconditional. Function pointers. This is usually the most expensive branch type.

Other combinations tend to be difficult to encode.

There can be some further complications, for example far branches , but this should be a good start.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM