University of California at Berkeley

College of Engineering

Department of Electrical Engineering and Computer Science

 

 

EECS 61C, Summer 2004

 

Lab 6-1: Pipelining

 

Purpose

To examine how programs run a bare (pipelined) machine.

Reading

P&H, 6.1-5

Description

 

Up until now, you have been running your programs using a machine simulator called spim, which takes your MIPS assembly code and (1) translates all pseudo instructions and (2) imposes delayed branches, jumps, and loads. Now it is time to switch from a virtual machine (the spim you have been working with) to a bare hardware machine. It is important to note that the bare hardware is still pipelined and still forwards when necessary. To run the bare machine check the bare machine option in Simulator->Settings within spim. Then restart spim. There is a good spim reference manual that explains in more detail how to change these settings in spim. When running your MIPS program on the bare machine, you will need to ensure that you translate all pseudo instructions to TAL instructions and that you insert enough nops so that your code will run correctly on the bare (pipelined) machine.

Exercise 1: Inserting Nops

Copy the file fact.s from ~cs61c/labs/lab6-1/fact.s. The program fact.s calculates factorial using a loop. Try running fact.s on spim (without the bare option), then try running it on the bare machine. Observe the error message given by spim when you try to run fact.s on the bare machine. Convert fact.s by translating pseudo instructions to TAL instructions and by inserting the minimum number of nops (sll $0 $0 0) so that fact.s will run correctly on the bare machine.

Important Note: When you run spim with the bare option, a branch requires a nop after its branch delay slot. It is important that you leave this nop as the second instruction after the branch (do not try to insert an instruction that you want executed in its place) because spim will simply skip whatever instruction is there. In real life (and on your exam), this nop following your branch delay slot is not necessary. And after you finish the lab, you should forget that you ever put it there. =)

Exercise 2: Rearranging Instructions

Now rearrange the instructions within fact.s so that you minimize the number of nops necessary for the program to run correctly. It is important that you do not change the behavior of the program when rearranging instructions. You should never sacrifice correctness for optimizations!