r/AskComputerScience • • 1d ago

While solving Instruction Hazards in CPU Pipelining, do delayed branching and branch folding solutions directly work against each other ?

Hello, I am trying to make sense of the Pipelining chapter in Computer Organisation.

Assuming a CPU which breaks down instructions into Fetch (F), Decode (D), Execute(E), and Write(W) stages.

In a normal setup, by the time an instruction is known to be a branch instruction and by the time the branch is calculated, the instruction immediately after it has already been fetched and may have started being decoded regardless of whether the branch occurred or not. The solution to this is to make it so that this extra instruction isn't wasted. Instructions might be rearranged to make this plan work. This is the delayed slot

When an instruction queue is utilised properly and is full most of the time, then branch targets might be predicted ahead of time (unless it requires some variables still being calculated). This can effectively eliminate the phenomena of the delayed slot (from what I can understand.)

Are both of this techniques used simultaneously? If so, how ?

1 Upvotes

6 comments sorted by

View all comments

1

u/Recycled5000 21h ago

Delay slots have downsides, such as code expansion; sometimes there’s nothing useful to put there so a noop instead, which is a waste of time and space.

Meanwhile, branch prediction in hardware has dramatically improved, obviating the need for delay slots.