Page 103 - Computer_Science_F5
P. 103
Computer Science (b) Randomly generate a coin flip (b) Discuss the performance
outcome (heads or tails).
penalty caused by the
(c) Compare the bet and outcome to
stall.
determine a win or loss.
FOR ONLINE READING ONLY
(d) Update the user’s balance based on
Step 3: Explain how forwarding
the result. Part 2: Forwarding
could bypass the pipeline
A data hazard occurs because stall. Briefly describe the
instruction 3 (compare) depends on concept of detecting the
the outcome generated in instruction dependency and sending
2 (random flip). Without proper the result directly from
handling, the pipeline might stall.
Complete the following activities. instruction 2 to instruction 3.
Step 4: Trace the pipeline (with
Part 1: The Penalty of stalling forwarding):
Step 1: Trace the pipeline (Without (a) Use a new table similar
forwarding): to Part 1, but assume
(a) List the four instructions the pipeline forwards
involved in the coin flip the random flip result
program. directly to the compare
(b) Create a table with instruction.
columns for instruction, (b) Simulate the pipeline
IF, ID, EX, MEM, flow with forwarding,
WB, and cycle (clock avoiding stalls. Fill in the
cycle). table accordingly.
(c) Simulate the pipeline
flow, assuming a stall if Step 5: Performance improvement:
instruction 3 needs data (a) Compare the number
from instruction 2 that of cycles taken with
is not yet available. Fill forwarding to the number
in the table, indicating with stalling
stalls with “Stall” in the (b) Discuss the performance
corresponding cycle. gain achieved by
eliminating the stall.
Step 2: Observe the impact:
(a) Count the total number of Deliverable: Write the summary of
cycles it takes to complete your findings from both parts of the
the program with stalling. activity and keep in a portfolio.
94
for Advanced Secondary Schools
Computer Science Form 5.indd 94 23/07/2024 12:33