First page Back Continue Last page Overview Text
In this example, a technique called delayed branch is used to reduce the branch/jump problem in the pipeline. To make the example easy to understand, a two stage pipeline is assumed. The same idea can be used for pipelines with more stages. It is very common to write the program loop as shown above in the regular program. This program breaks the pipe most of the time. Whenever the pipe is broken, the uncompleted instructions in the pipe need to be flushed. This eliminates any possible speed gain from using the pipeline.
The delayed branch technique changes the order of the instructions in the loop. At first glance, one might think that the program would not generate the same result. However, taking the pipeline into consideration, we can see that the execution result is not changed. The trick is that we do not let the processor flush the pipe but rather let it finish the instructions in the pipe. For example, when the Branch_if instruction is executed, the shift_right instruction is fetched into the pipe. If the value in R1 is nonzero, the Branch_if instruction will cause the Decrement instruction to be fetched next. Since the pipe is not flushed, the shift_right instruction is executed when the Decrement instruction is fetched.
Using delayed branch technique can make the program difficult to debug and maintain. Its use is recommended only when execution speed is an issue. (Unfortunately, it is an issue for many applications). This technique should not be used until the program has been otherwise fully debugged.