ECE 1773 – Advanced Computer Architecture
HW #1  -  Due Tuesday, October. 10, 2006, In Class

The goal of this homework is to gain experience with an optimizing compiler and learn PISA, Simplescalar’s MIPS-like instruction set architecture. A description of PISA can be found in the simplescalar paper that is available on the course web site. To complete this assignment you will need access to a Windows x86 machine with CYGWIN installed. Visit www.cygwin.com and install cygwin if you don’t have it. Make sure to install the gcc toolchain. Assuming that you have a working cygwin installation downloadthe following from the course’s web site:

 

  1. Simplescalar GCC port. This is an older version but good enough for our purpose. It installs under /usr/local. Check the directories for the exact location.
  2. The file “mytest.c”.

 

Download the “mytest.c” file from the course’s website. Compile this file to generate assembly. For this use the Simplescalar C compiler. The command line is as follows:

 

ss-gcc –O0  mytest.c –S –o mytest.O0.s

This should produce a  file named: “mytest.O0.s”. The –O0 parameter disables all optimizations.

Next compile the file with some optimizations turned on. To do so use the following command line:

 

ss-gcc –O2  mytest.c –S –o mytest.O2.s

The –O2 option enables most optimizations (excluded are loop-unrolling and function inlining). You should get a file named “mytest.O2.s”. The two .s files contain the assembly code for the compiled program.

What to hand-in:

(1) An annotated printout of the two assembly files. Locate the assembly code for the main function. It begins after the “main:” line. Annotate each line with an explanation of what it does.  For example if the line is “add $1, $2, $3” write “place C+B in register $1” provided that $2 and $3 contain the values for variables C and B. Lookup the instruction definitions in the appendix of the Simplescalar handout.

(2) Compile and link mytest.c with –O2 optimization. To do so use:

 

ss-gcc –v –O2  mytest.c –o mytest

 

The –v option instructs gcc to report all its actions. Can you identify what programs gcc calls and what they do?

 

(3) Now check the binary that was generated. Do so using the disassembler as follows:

ss-objdump –d mytest | less

 

What you get is a complete disassembly of your program. You will notice that there are a lot more functions than just the function main(). To locate main() just search for it by its name. What to hand-in: Compare the disassembly with the assembly file you generated earlier (the one with –O2). List any differences in the generated code.

 

(4) Compile “mytest.c” with “-O2 –funroll-loops”. Check the assembly and explain any differences compared to when you did not use the –funroll-loops option..

 

(5) Compliemytest.cwith ”-E –o mytest.cpp”. Look at mytest.cpp. This is the pure C file that is passed to gcc after the C preprocessor (often called cpp) parses and replaces all # directives (e.g., #include, #define, etc.). What to hand-in: Nothing. Do not print this file. It will be huge.