14.4 Instruction Pipelining

COS2621 - Computer Organisation · 14. Processor Structure and Function

Processor Structure and Function

Instruction Pipelining

Instruction pipelining is a technique used in modern microprocessors to enhance performance. This method allows multiple instructions to be processed simultaneously by dividing the instruction execution process into distinct stages. Each stage completes a part of the instruction, enabling the next instruction to begin processing before the previous one has finished.

Stages of Instruction Pipelining

Typically, instruction pipelining consists of five stages:

  • Fetch: The instruction is fetched from memory.
  • Decode: The instruction is decoded to determine the operation and the operands.
  • Execute: The operation is performed using the Arithmetic Logic Unit (ALU).
  • Memory Access: If the instruction requires data from memory, this stage retrieves it.
  • Write Back: The result is written back to the register file.

These stages can overlap. For example, while one instruction is being executed, another can be decoded, and a third can be fetched. This overlapping of stages is what potentially increases the amount of work available for the processor to execute.

Remember: Pipelining increases CPU performance by allowing multiple instructions to be processed at different stages simultaneously.

Example of Instruction Pipelining

Consider 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 non-pipelined architecture, each instruction must complete all stages before the next instruction starts, leading to delays. In a pipelined architecture, the execution of these instructions can overlap:

xyO−112345−22468A(1, 0)B(3, 0)Turning point (2, -1)y = x² − 4x + 3y = 2x − 1
Execution of three instructions in a pipelined architecture

The first instruction (ADD) is fetched in cycle 1, decoded in cycle 2, and executed in cycle 3. Meanwhile, the second instruction (SUB) can be fetched in cycle 2, and the third instruction (AND) can be fetched in cycle 3.

Hazards in Instruction Pipelining

While pipelining improves performance, it can introduce hazards:

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

Watch out: Be mindful of data hazards, as they can lead to incorrect results if not managed properly.

Resolving Hazards

To manage hazards, techniques such as forwarding and stalling can be used. Forwarding allows the output of an instruction to be used as input for a subsequent instruction without waiting for it to be written back to the register file. Stalling inserts no-operation (NOP) instructions to give time for the previous instruction to complete.

Multiple Parallel Pipelines

In modern processors, multiple parallel pipelines are used in superscalar execution. This architecture allows for the simultaneous execution of multiple instructions, improving throughput and performance. Each pipeline can handle a separate instruction stream, thus increasing the overall instruction throughput.

Clock Rate and Execution Speed

An increase in clock rate means that individual operations are executed more rapidly. This increase can significantly affect the execution speed of operations in a processor, enhancing overall performance.

Data and Instruction Flow

The interface between the processor and main memory is the most crucial pathway in the entire computer. It is responsible for carrying a constant flow of program instructions and data between memory chips and the processor.

Summary

  • Instruction pipelining improves CPU performance by overlapping instruction execution.
  • The stages of pipelining include Fetch, Decode, Execute, Memory Access, and Write Back.
  • Hazards can affect pipelining efficiency and must be managed carefully.
  • Multiple parallel pipelines enhance performance through superscalar execution.

Check your understanding

  • What are the five stages of instruction pipelining?
  • How does pipelining improve CPU performance?
  • What is a data hazard, and how can it be resolved?
  • What is the role of multiple parallel pipelines in processor architecture?

Test yourself

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

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

  2. 2. What is the primary benefit of instruction pipelining in modern microprocessors?

  3. 3. Which stage of instruction pipelining is responsible for retrieving the instruction from memory?

  4. 4. Which technique allows the output of an instruction to be used as input for a subsequent instruction without waiting for it to be written back?