15.5 RISC Pipelining

COS2621 - Computer Organisation · 15. Reduced Instruction Set Computers

RISC Pipelining

Introduction to Pipelining

Pipelining is a technique used in RISC (Reduced Instruction Set Computer) architecture to improve instruction throughput. In a pipeline, multiple instruction phases are overlapped in execution. Each phase of instruction processing is completed in a separate segment of the pipeline. The main phases include instruction fetch, instruction decode, execute, memory access, and write-back.

Pipelining Stages

Consider the following stages of a simple instruction pipeline:

  • Instruction Fetch (IF): The instruction is fetched from memory.
  • Instruction Decode (ID): The fetched instruction is decoded to understand the operation.
  • Execution (EX): The operation is executed (e.g., arithmetic operation).
  • Memory Access (MEM): If needed, data is read from or written to memory.
  • Write Back (WB): The result is written back to the register file.

Example of Pipelining

Suppose we have the following sequence of instructions:

1. ADD R1, R2, R3  ; R1 = R2 + R3
2. SUB R4, R1, R5  ; R4 = R1 - R5
3. AND R6, R1, R7  ; R6 = R1 AND R7

In a pipelined architecture, the execution of these instructions would proceed as follows:

  1. Cycle 1: IF for ADD
  2. Cycle 2: ID for ADD, IF for SUB
  3. Cycle 3: EX for ADD, ID for SUB, IF for AND
  4. Cycle 4: MEM for ADD, EX for SUB, ID for AND
  5. Cycle 5: WB for ADD, MEM for SUB, EX for AND
  6. Cycle 6: WB for SUB, MEM for AND
  7. Cycle 7: WB for AND

This overlapping reduces the total time taken to execute the instructions compared to a non-pipelined approach.

Tip: The efficiency of a pipeline can be affected by hazards, which are situations that prevent the next instruction from executing in the following cycle.

Types of Hazards

There are three main types of hazards in pipelining:

  • Data Hazards: Occur when an instruction depends on the result of a previous instruction that has not yet completed.
  • Structural Hazards: Occur when hardware resources are insufficient to support all concurrent operations in the pipeline.
  • Control Hazards: Occur due to branch instructions that change the flow of execution.

Resolving Hazards

To resolve data hazards, techniques such as forwarding (bypassing) can be used. Forwarding allows the output of one instruction to be used as input for another instruction without waiting for it to be written back to the register file.

Watch out: If hazards are not managed properly, they can lead to stalls in the pipeline, which decrease performance.

Conclusion

Pipelining is a vital concept in RISC architecture that enhances performance by overlapping instruction execution. Understanding the stages of pipelining and the potential hazards is essential for optimising performance in RISC-based systems.

Check your understanding

  • What are the main stages of a pipeline?
  • Explain what a data hazard is and how it can be resolved.
  • What is the purpose of instruction forwarding?
  • How does pipelining improve instruction throughput?

Test yourself

4 quick questions on this lesson. Pick an answer to see if you're right.

  1. 1. Which of the following is NOT a stage in a typical instruction pipeline?

  2. 2. Which technique allows the output of one instruction to be used as input for another instruction without waiting for it to be written back to the register file?

  3. 3. What is the primary purpose of pipelining in RISC architecture?

  4. 4. What type of hazard occurs when an instruction depends on the result of a previous instruction that has not yet completed?