CS301
– Fall 2001
Prof.
Hartman
Homework
#8
Due
Friday, November 30th by 5:00 pm
We’ve seen that
the Visual C++ compiler does not unroll loops. It (along with every other
compiler I know of) will also not generate complicated instructions like XCHG
and LOOP (or LOOPNE, etc.) However, these are slow instructions, so it is rare
that they would speed up code…
For this
assignment you are going to examine a tight loop and various ways of optimizing
it. In the file addtiming.c
are several functions that calculate the (32 bit, so not actually correct) sum
of the first SIZE integers (along with a timing function that counts actual
clock cycles — unfortunately including those that the system takes…) Your job
is to run this code on as many types of machines as possible and turn in the
output, formatted as a table (chip type down the left side, loop type across
the top). On very slow machines you may need to change the AVGTIMES constant to
something smaller to get the code to run in a reasonable amount of time. You
can only run the program on Pentium or later compatible chips (earlier chips do
not have the RDTSC instruction.) Make sure to compile and run the code using
the “release” environment in Visual C++. Verify that you do have “Optimize for
speed” checked. Yes, this is an easy assignment…
While you won’t
be graded on it, you should also understand the following concepts (and you may
be tested on them):