0% found this document useful (0 votes)
29 views4 pages

Microprocessor Pipeline Design and Data Hazards

The document discusses pipeline design for a microprocessor. It provides details on perfect pipelining such as splitting the original 140ps cycle time into 14 even stages of 10ps each, reducing execution time from 1.4ms to 140us. It also notes that instruction latency and throughput may be affected since maintaining a CPI of 1 with 14 stages is optimistic and no-ops may need inserting. The document then analyzes data dependencies in a code sample. It identifies which can be resolved via forwarding and which require stalling. Finally, it discusses how a read after write memory hazard in some code can function correctly on the class processor due to timing.

Uploaded by

Thanh Trúc
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views4 pages

Microprocessor Pipeline Design and Data Hazards

The document discusses pipeline design for a microprocessor. It provides details on perfect pipelining such as splitting the original 140ps cycle time into 14 even stages of 10ps each, reducing execution time from 1.4ms to 140us. It also notes that instruction latency and throughput may be affected since maintaining a CPI of 1 with 14 stages is optimistic and no-ops may need inserting. The document then analyzes data dependencies in a code sample. It identifies which can be resolved via forwarding and which require stalling. Finally, it discusses how a read after write memory hazard in some code can function correctly on the class processor due to timing.

Uploaded by

Thanh Trúc
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

HW #5 – Due 13/10

1) A computer architect needs to design the pipeline for a new microprocessor.


They have an example workload program with 106 instructions. Each
instruction takes 140 ps from start to finish.
a) Execution time = # instructions * cycle time
10,000,000 instructions * 140 ps per instruction = 1.4E-3 sec
b) Perfect pipelining assumes we can issue one instruction immediately after
another. After 10,000,000 cycles of issuing instructions, we have to wait 13
cycles before the last instruction exits the pipeline completely (drain time).
Perfect pipelining also assumes we take the 140 ps required per instruction
earlier and split it up into 14 even stages. Thus, the cycle time is now 10 ps.
Execution time = ((CPI * # of instructions) + drain time) * cycle time

((1.0 *10,000,000) + 13) * 10ps  1.0E-4 sec


Speedup = Execution time B / execution time A = 14x faster
c) Instruction latency might be affected since it is unlikely we will be able to
split the 140 ps original cycle time into 14 equal size chunks. The cycle
time will probably be greater than 10 ps.
Instruction throughput might be affected since a CPI of 1.0 is very
optimistic. It is likely that some no-ops will need to be inserted because the
compiler will not be able to fill all delay slots and maintain correct behavior.
2) Identify all of the data dependencies in the following code. Which
dependencies are data hazards that will be resolved via forwarding? Which
dependencies are data hazards that will cause a stall?
add $3, $3, $2
sub $5, $3, $1
lw $6, 200, ($3)
add $7, $3, $6
ADD $3 $4 $2
SUB $5 $3 $1
LW $6 200 ($3)
ADD $7 $3 $6

A) The SUB requires $3 from the first ADD – Read after Write
B) The LW requires $3 from the first ADD – Read after Write
C) The second ADD requires $3 from the first ADD – Read after Write
D) The second ADD also requires $6 from the LW – Read after Write

ADD IF DEC
EX MEM WB
$3
SUB IF DEC EX MEM WB
$3
LW IF DEC EX MEM WB

NOOP IF DEC EX MEM WB


$6
ADD IF DEC EX MEM WB

A) Can be handled by forwarding the result from the ALU of the EXEC stage of
the ADD instruction to the end of the DEC stage of the SUB instruction.
B) Can be handled by forwarding the result of the ALU passed on to the MEM
stage of the ADD instruction to the end of the DEC stage of the LW instruction.
C) This does not need to be forwarded. Even if D did not require the insertion of a
NOOP, our careful clocking of the register file allows us to write and read back
a value during the same clock cycle. Thus, we don’t need to worry about
dependencies that are more than 2 instructions later.
D) This dependency requires us to insert a NOOP. The grey arrow shows that
since we do not have the value from memory until the end of the MEM stage of
the LW, we do not get the value early enough to forward into the DEC stage of
the following instruction.
Even adding forwarding hardware into the EX stage would not help us since we
do not know the result until the end of the MEM stage. Adding forwarding
capabilities to the EX stage would require a longer cycle time to allow us
enough time to get the forwarded value and then perform the addition.
3) The following code contains a “read after write” data hazard that is resolved by
forwarding:
add $2, $3, $4
add $5, $2, $6
Consider the following code where a memory read occurs after a memory write:
sw $7, 100($2)
lw $8, 100 ($2)
Does the code work correctly on the processor in class? Why/why not? Will
the forwarding unit need to be altered to handle this code?
This works with the processor designed in class because both the SW and LW
access the memory 4 cycles after they have been fetched. Thus, since the LW
is fetched one cycle after the SW, the LW looks for the value one cycle after the
SW has written it. Assuming the memory can be written to in one cycle and we
have no buffering this will work fine.
4) Consider executing the following code on the pipelined datapath from class:
add $2, $3, $1
sub $4, $3, $5
add $5, $3, $7
add $7, $6, $1
add $8, $2, $6
At the end of the fifth cycle of execution, which registers are being read and
which registers will be written?

ADD $2, $3, $1 IF DEC EX MEM WB


SUB $4, $3, $5 IF DEC EX MEM WB
ADD $5, $3, $7 IF DEC EX MEM WB
ADD $7, $6, $1 IF DEC EX MEM WB
ADD $8, $2, $6 IF DEC EX MEM WB

At the end of the fifth cycle:


A) The first ADD is completing its write to $2
B) The SUB is in the MEM stage. It is not currently accessing any registers – if
anything it would be looking up something in memory.
C) The second ADD is in the EXEC stage. It is currently not accessing any
registers – it is currently trying to compute the add.
D) The third ADD is in the DEC stage so it is fetching the operands from $6
and $1.
E) The fourth ADD is in the IF stage. We don’t know what kind of instruction
this is yet since we just got it so we don’t even know if this instruction takes
any registers at all.

Common questions

Powered by AI

Data hazards occur when instructions depend on the results of previous instructions that are not yet complete. Forwarding can resolve certain 'read after write' hazards by passing the result directly to the next instruction needing it, thus bypassing the need to access registers. In the given code, forwarding resolves some hazards by directing the ALU result to stages needing them. However, some hazards, like the dependency requiring a NOOP after an LW instruction, are due to the timing of memory access and cannot be resolved by forwarding alone .

Implementing perfect pipelining is challenging because it requires dividing the total execution time of an instruction into equal segments and maintaining a CPI of 1.0, both of which are ideal conditions. Practical challenges include difficulties in perfectly dividing instruction processing time, real-world limitations in pipeline stages, and compiler overhead that might necessitate no-ops to fill pipeline delay slots. Moreover, there are potential impacts on instruction latency and throughput due to pipeline hazards, forwarding complexities, and cyclical dependencies that could further complicate the objective of achieving perfect pipelining .

Dependencies like those in instruction D mentioned in the document, where a result from a memory load (LW) is needed immediately by a subsequent instruction, require no-ops because the memory result is not available at the necessary pipeline stage (DEC). This is due to the timing of stages and memory access. Forwarding can't resolve these as it cannot bridge the gap in timing between when the result is available and when the subsequent instruction needs it, highlighting a limitation where inserting no-ops becomes necessary .

A memory read after a write executes correctly when the memory write is completed just before the memory read begins looking for data. In the case described, the SW instruction writes to memory 4 cycles after being fetched, and since the LW follows by one cycle, it reads the value right after the write completes. This sequencing depends on the assumption that memory operations (reads and writes) finish within one cycle and no buffering is involved .

The compiler's role in filling pipeline delay slots involves reordering instructions, inserting no-ops, or providing instructions that do not affect the program state but fill pipeline stages until dependencies are resolved. This is necessary to maintain pipeline efficiency and prevent stalls, as it allows subsequent instructions to execute without waiting for unresolved dependencies, effectively optimizing pipeline throughput. However, achieving this without impacting execution correctness presents significant challenges, especially for dynamic or data-dependent instruction flows .

Memory load/store instructions introduce pipeline hazards as they require data that may not be immediately available, synchronizing memory access times within the pipeline flow. Strategies to mitigate these include forwarding for resolving read-after-write (RAW) hazards and inserting no-ops for loads that cause timing mismatches. Adequate memory access scheduling and dependency analysis can help predict and resolve such hazards preemptively, although complex cases might still necessitate pipeline stalls .

Pipelining reduces cycle time by allowing multiple instruction executions to overlap, splitting the instruction cycle into smaller pipeline stages. This lowers per-instruction cycle time but introduces trade-offs such as increased complexity, potential data and control hazards, and the necessity for complex forwarding and stalling mechanisms. These trade-offs can affect overall IPC (instructions per cycle) if the pipeline cannot be perfectly balanced or if hazards cause stalls, negating some cycle time advantages .

Data hazards affect register usage by necessitating specific behaviors during different pipeline stages. When a pipeline stage waits for data from a previous stage (causing a hazard), it might lead to stalls or use of forward paths to maintain execution flow. For instance, at the end of the fifth cycle, the provided pipeline shows various stages where registers are accessed for reading, writing or awaiting data from memory, impacting the timing and execution order. Hazards thus require careful management of register access to avoid conflicts and latency issues .

Maintaining a CPI (cycles per instruction) of 1.0 is optimistic as it assumes every instruction completes exactly in one cycle with no stalls, hazards, or pipeline flushes. In reality, pipelined architecture must handle data hazards, control hazards, and timing disparities between instructions, requiring stalls and no-ops which increment the CPI above 1.0. This means workloads with dependencies, branches, and varying instruction latencies are likely to disrupt the ideal CPI, especially in non-ideal execution conditions .

Perfect pipelining allows a microprocessor to issue one instruction immediately after another, reducing execution time by overlapping the execution of instructions. In the example provided, the cycle time is reduced from 140 ps to 10 ps by splitting the work into 14 even stages, achieving a 14x speedup in execution time as it reduces from 1.4E-3 sec to approximately 1.0E-4 sec. However, this assumes ideal conditions which might not be practically achievable due to potential latency and throughput issues .

You might also like