Unit 6
Unit 6
Pipelining is the process of accumulating instruction from the processor through a pipeline. It allows
storing and executing instructions in an orderly process. It is also known as pipeline processing.
Pipelining is a technique where multiple instructions are overlapped during execution. Pipeline is
divided into stages and these stages are connected with one another to form a pipe like structure.
Instructions enter from one end and exit from another end.
Pipelining increases the overall instruction throughput.
In pipeline system, each segment consists of an input register followed by a combinational circuit. The
register is used to hold data and combinational circuit performs operations on it. The output of
combinational circuit is applied to the input register of the next segment.
Pipeline system is like the modern day assembly line setup in factories. For example in a car
manufacturing industry, huge assembly lines are setup and at each point, there are robotic arms to
perform a certain task, and then the car moves on ahead to the next arm.
Types of Pipeline
It is divided into 2 categories:
1. Arithmetic Pipeline
2. Instruction Pipeline
Arithmetic Pipeline
Arithmetic pipelines are usually found in most of the computers. They are used for floating point
operations, multiplication of fixed point numbers etc. For example: The input to the Floating Point
Adder pipeline is:
X = A*2^a
Y = B*2^b
Here A and B are mantissas (significant digit of floating point numbers), while a and b are exponents.
The floating point addition and subtraction is done in 4 parts:
1. Compare the exponents.
2. Align the mantissas.
3. Add or subtract mantissas
4. Produce the result.
Registers are used for storing the intermediate results between the above operations.
Pipeline Conflicts
There are some factors that cause the pipeline to deviate its normal performance. Some of these factors
are given below:
1. Timing Variations
All stages cannot take same amount of time. This problem generally occurs in instruction processing
where different instructions have different operand requirements and thus different processing time.
2. Data Hazards
When several instructions are in partial execution, and if they reference same data then the problem
arises. We must ensure that next instruction does not attempt to access data before the current
instruction, because this will lead to incorrect results.
3. Branching
In order to fetch and execute the next instruction, we must know what that instruction is. If the present
instruction is a conditional branch, and its result will lead us to the next instruction, then the next
instruction may not be known until the current one is processed.
4. Interrupts
Interrupts set unwanted instruction into the instruction stream. Interrupts effect the execution of
instruction.
5. Data Dependency
It arises when an instruction depends upon the result of a previous instruction but this result is not yet
available.
Advantages of Pipelining
1. The cycle time of the processor is reduced.
2. It increases the throughput of the system
3. It makes the system reliable.
Disadvantages of Pipelining
1. The design of pipelined processor is complex and costly to manufacture.
2. The instruction latency is more.
Instruction Pipeline
Pipeline processing can occur not only in the data stream but in the instruction stream as well.
Most of the digital computers with complex instructions require instruction pipeline to carry out
operations like fetch, decode and execute instructions.
In general, the computer needs to process each instruction with the following sequence of steps.
1. Fetch instruction from memory.
2. Decode the instruction.
3. Calculate the effective address.
4. Fetch the operands from memory.
5. Execute the instruction.
6. Store the result in the proper place.
Each step is executed in a particular segment, and there are times when different segments may take
different times to operate on the incoming information. Moreover, there are times when two or more
segments may require memory access at the same time, causing one segment to wait until another is
finished with the memory.
The organization of an instruction pipeline will be more efficient if the instruction cycle is divided into
segments of equal duration. One of the most common examples of this type of organization is a Four-
segment instruction pipeline.
A four-segment instruction pipeline combines two or more different segments and makes it as a
single one. For instance, the decoding of the instruction can be combined with the calculation of the
effective address into one segment.
The following block diagram shows a typical example of a four-segment instruction pipeline. The
instruction cycle is completed in four segments.
Segment 1:
The instruction fetch segment can be implemented using first in, first out (FIFO) buffer.
Segment 2:
The instruction fetched from memory is decoded in the second segment, and eventually, the effective
address is calculated in a separate arithmetic circuit.
Segment 3:
An operand from memory is fetched in the third segment.
Segment 4:
The instructions are finally executed in the last segment of the pipeline organization.
Data hazards
Data hazards occur when instructions that exhibit data dependence modify data in different stages of a
pipeline. Ignoring potential data hazards can result in race conditions (also termed race hazards).
Due to the data dependency, data hazards have occurred. If the data is modified in different stages of a
pipeline with the help of instructions that exhibit data dependency, in this case, the data hazard will
occur. When the instructions are read/write the registers that are used by some other instructions, in
this case, the instruction hazards will occur. Because of the data hazard, there will be a delay in the
pipeline. The data hazards are basically of three types:
1. read after write (RAW), a true dependency
2. write after read (WAR), an anti-dependency
3. write after write (WAW), an output dependency
RAW:
RAW hazard can be referred to as 'Read after Write'. It is also known as Flow/True data dependency.
If the later instruction tries to read on operand before earlier instruction writes it, in this case, the RAW
hazards will occur. The condition to detect the RAW hazard is when On and In+1 both have a
minimum one common operand.
For example:
I1: add R1, R2, R3
I2: sub R5, R1, R4
There is a RAW hazard because subtraction instruction reads output of the addition. The hazard for
instructions 'add R1, R2, R3' and 'sub R5, R1, R4' is described as follows:
When the instruction tries to enter into the write back stage of the pipeline, at that time, all the previous
instructions contained by the program have already passed through the read stage of register and read
their input values. Now without causing any type of problem, the write instruction can write its
destination register. The WAR instructions contain less problems as compared to the WAW because in
WAR, before the write back stage of a pipeline, the read stage of a register occur.
WAW
WAW can be referred to as 'Write after Write'. It is also known as Output Data dependency. If the later
instruction tries to write on operand before earlier instruction writes it, in this case, the WAW hazards
will occur. The condition to detect the WAW hazard is when On and On+1 both have a minimum one
common operand.
For example:
The dependency is described as follows:
add R1, R2, R3
sub R1, R2, R4
Here addition instruction creates a WAW hazard because subtraction instruction writes on the same
register. The hazard for instructions 'add R1, R2, R3' and 'sub R1, R2, R4' are described as follows:
In the write back stage of a pipeline, the output register of instruction will be written. The order in
which the instruction with WAW hazard appears in the program, in the same order these instructions
will be entered the write back stage of a pipeline. The result of these instructions will be written into
the register in the right order. The processor has improved performance as compared to the original
program because it allows instructions to execute in different orders.
A characteristic of RISC processors’ ability is to execute one instruction per clock cycle. This is done
by overlapping the fetch, decode and execute phases of two or three instructions by using a procedure
referred as pipelining.
Characteristics of CISC
The characteristics of CISC are as follows −
A large number of instructions typically from 100 to 250 instructions.
Some instructions that perform specialized tasks and are used infrequently.
A large variety of addressing modes- typically from 5 to 20 different modes.
Variable length instruction formats.
Instructions that manipulate operands in memory.
Example
For performing an ADD operation, CISC will execute a single ADD command which will execute all
the required load and store operations.
RISC will execute each operation for loading data from memory, adding values and storing data back
to memory using different low-level instructions.