makmal 7
TRANSCRIPT
-
7/30/2019 makmal 7
1/12
Lab 7
Investigating Instruction Pipelines
Sem02 Session 2012/13
Electronic Engineering Laboratory IV
BEE31101
Instruction Sheet
Facult
y
ofElectrica
ndE
lectronic
Engineering
-
7/30/2019 makmal 7
2/12
Electronic Engineering Laboratory IV (BEE31101)
Lab 7: Investigating Instruction Pipelinesii
FKEE, Sem02 Session 2012/13
Table of Content
Table of Content ii
Outcomes 1
Instructions 1
Pre-Lab 2
Lab Activities 3
Overview 3
Example Code 3
Assignment1 5
Assignment2 6
Observations 7
Questions 9
References 10
-
7/30/2019 makmal 7
3/12
Electronic Engineering Laboratory IV (BEE31101)
Lab 7: Investigating Instruction Pipelines1
FKEE, Sem02 Session 2012/13
Outcomes
At the end of this lab, you should be able to:
1. Demonstrate the difference between pipelined and sequential processing of the CPUinstructions
2. Explain pipeline data dependency and data hazard
3. Describe a pipeline technique to eliminate data hazard
4. Demonstrate compiler loop unrolling optimizations benefits for instruction pipelining.
Instructions
1. Grouping: Lab group is not predetermine and consists with at most two team members.
2. Pre-Lab: Must be submitted to the instructor at the beginning of lab sessions. Verified by the
instructor and returned to the students at the end of lab session. The verified pre-lab will be
attached with the final report for submission.
3. Lab Activities: All lab activities such as sample code, examples and lab assignments must
be held in the respective lab location and completed within the given times.
4. Demonstration: Student must demonstrate the successful sample code, examples and lab
assignments to the respective instructor. Verification only will be given upon completion of all
lab activities and initialized by the instructor on the cover page.
5. Report Organization: Report must be organized according to given report template.
6. Report Submission: Report must be received by respective technical staff (at respective
lab) before 4.00pm; not later than three (3) days upon completion of lab session.
-
7/30/2019 makmal 7
4/12
Electronic Engineering Laboratory IV (BEE31101)
Lab 7: Investigating Instruction Pipelines2
FKEE, Sem02 Session 2012/13
Pre-Lab
1. What is the function of instruction pipelines in a computer
(2 marks)2. What are pipeline bubble and data hazards?
(3 marks)
Checked by: Date:
Signature & Lab. Stamp
-
7/30/2019 makmal 7
5/12
Electronic Engineering Laboratory IV (BEE31101)
Lab 7: Investigating Instruction Pipelines3
FKEE, Sem02 Session 2012/13
Lab Activities
Overview
Modern CPUs incorporate instruction pipelines which are able to process different stages of
multi-stages of multiple instructions in parallel thus improving the overall performance of the
CPUs. However, most programs include instructions that do not readily lend themselves to
smooth pipelining thus causing pipeline hazards and effectively reducing the CPU performance.
Example 1 : Difference between the sequential and pipelined execution of CPU
instructions
1. In order to be able to do the following exercises, you need to enter a program which the
OS simulator can run.Click on the COMPILER button in the Advanced tab.
2. Enter the following program in the edit window and compile.
-
7/30/2019 makmal 7
6/12
Electronic Engineering Laboratory IV (BEE31101)
Lab 7: Investigating Instruction Pipelines4
FKEE, Sem02 Session 2012/13
3. When the above program is successfully compiled, load it in the CPUs memory by
clicking on the LOAD IN MEMORY button. This will take to the CPU simulator.
4. Open the CPU pipeline window by clicking on the SHOW PIPELINE button in the CPU
simulators window. This window simulates the behavior of CPU pipelined. This pipelined
has five stages which are colour-coded as shown in the key for the Pipelines Stages.
5. Check the box title Stay on top and No instruction pipeline.
6. RUN the program and observe the pipeline. Make a note of values in table 1.1.
7. Uncheck the No instruction pipeline checkbox, FLUSH and RUN. Make a note of
values in table 1.1.
Table 1.1
No pipeline With pipeline
CPI (Clock Per Instruction)
SF (Speed-up Factor)
-
7/30/2019 makmal 7
7/12
Electronic Engineering Laboratory IV (BEE31101)
Lab 7: Investigating Instruction Pipelines5
FKEE, Sem02 Session 2012/13
Assignment 1 : CPU pipeline data hazard, bubbles and NOP instruction
A data hazard is caused by unavailability of an operand value when it is needed. In order to
demonstrate this:
1. Create a program (call assignment1) and enter the following set instructions in CPU
INSTRUCTION IN MEMORY.
MOV #1, R01
MOV #5, R03
MOV #3, R01
ADD R01, R03
HLT
2. Make a note of the expected value in register R03 at the end of the above instructions. Write
the value in table 2.1.3. RUN the instruction, and make sure No instruction pipeline is NOT checked and Do not
insert bubbles is checked. Write the value of register R03 in table 2.1.
4. Insert a NOP instruction (use the Miscellaneous tab) as this following instructions. Reset the
registers and RUN the instruction. Write the value of register R03 in table 2.1.
MOV #1, R01
MOV #5, R03
MOV #3, R01
NOP
ADD R01, R03
HLT
5. Delete the NOP instruction from above program and uncheck Do not insert bubbles. Reset
the registers, RUN and write the value of R03 in table 2.1
6. Have you seen the bubble? What colour is it? Make a note of values in table 2.2.
_______________________________________________________
7. Check the box Enable operand forwarding, reset the register and run. Make a note of
values in table 2.2.
8. What happen to the bubble?
__________________________________________________________________
Table 2.1
Predict Without bubble With NOP,without bubble
Without NOP,with bubble
R03 value
-
7/30/2019 makmal 7
8/12
Electronic Engineering Laboratory IV (BEE31101)
Lab 7: Investigating Instruction Pipelines6
FKEE, Sem02 Session 2012/13
Table 2.2
Without operand forwarding With operand forwarding
CPI (Clock Per Instruction)
SF (Speed-up Factor)
Data hazard
Assignment 2: Loop unrolling optimization minimizing control dependencies
One method of compiler optimization called loop unrolling. This method essentially duplicates
the inner code of a loop as many times as the number of loops, removing some redundant code
as well as the loops compare and jump instructions. We will see if loop unrolling technique can
affected the CPU performance.
1. Enter the following code, check enable optimizer, select optimization option Remove
Redundant Code and compile and load this code in memory. Write the size of the code
generated in table 2.3.
program assignment2
for n = 1 to 8
t = t +1
next
end
2. In the CPU simulator window select program assignment2from the Program list frame,
then click Reset button. Make sure the speed of simulation is set at maximum.
3. Click Show pipeline button and make sure the pipeline window stay on top, Uncheck
boxes ofNo instruction pipeline, Enable operand forwarding and Enable jump
prediction.
4. Write the result in table 2.3
5. Change the program name to assignment 2b, follow the step 1 to 3. BUT in step 1, check
the boxes enable optimizer, select optimization option Remove Redundant Code and
Apply loop unrolling on loop. Write the result in table 2.4
Table 2.3
Program Assignment 2
CPI (clock Per Instruction)
SF (Speed-up Factor)
No. of Instruction Executed
Size of the code generated
-
7/30/2019 makmal 7
9/12
Electronic Engineering Laboratory IV (BEE31101)
Lab 7: Investigating Instruction Pipelines7
FKEE, Sem02 Session 2012/13
Table 2.4
Program Assignment 2b
CPI (clock Per Instruction)
SF (Speed-up Factor)
No. of Instruction Executed
Size of the code generated
Observations
1. Explain why there is difference in the two sets of values in table 1.1 of Example 1.
(4 marks)2. Refer to the assignment 1, briefly comment on your observation the four value of the register
R03 in table 2.1.
(4 marks)
3. What is the effect of operand forwarding method on the CPU performance as refer the result
in table 2.2.
(3 marks)
-
7/30/2019 makmal 7
10/12
Electronic Engineering Laboratory IV (BEE31101)
Lab 7: Investigating Instruction Pipelines8
FKEE, Sem02 Session 2012/13
4. Give the comment on your observations making reference to the code sizes and number of
instruction executed for Assignment 2.
(3 marks)
Conclusion (write the conclusion for this lab)
(5 marks)
-
7/30/2019 makmal 7
11/12
Electronic Engineering Laboratory IV (BEE31101)
Lab 7: Investigating Instruction Pipelines9
FKEE, Sem02 Session 2012/13
Questions
1. Write a program for the following arithmetic operation and predict the value of register R01.
R01 = 4 * (5+2) 3
Instruction Set
(5 marks)
R01 : ________________________________________
(2 marks)
2. By using Instruction Memory View:
a) Create the program arithmetic operation above and RUN. Prove the content of register
R01 is the same with the prediction value.
(print screen the code and Register R01)
(4 marks)
b) Find the value of data hazard for:
i) Instruction pipeline with bubbles and without operand forwarding method
(print screen the pipeline result) (2 marks)
ii) Instruction pipeline with bubble and operand forwarding method
(print screen the pipeline result) (2 marks)
-
7/30/2019 makmal 7
12/12
Electronic Engineering Laboratory IV (BEE31101)
Lab 7: Investigating Instruction Pipelines10
FKEE, Sem02 Session 2012/13
References
1. W. Stalling (2013). Computer Organization & Architecture;Designing for Performance. 9th
Edition. Pearson Prentice Hall.2. Carl Hamacher, Zvonko Vranesic, Safwat Zaky, Nraig Manjikian (2012). Computer
Organization and Embedded Systems. 6th Edition. The McGraw-Hill Companies.