CS 473 - HW4
More MIPS
Due Monday, October 7, 2002
Revision 1
Consider the following block of C code, which generates a histogram:
for (i = 0; i < 100; i++)
histo[awry[i]] = histo[awry[i]]+1;
Make the following assumptions:
i is a local variable declared as int,
stored in register $t0
awry and histo are both global
variables, declared as int[]. Following standard C
semantics, you don't need to do bounds checking on the arrays.
You can assume you can use awry and
histo as symbols.
- Assume the ``standard'' MIPS pipeline (as shown on page 499),
additionally assuming any extra data paths needed for instructions
that this pipeline can't handle. Also, assume no delayed loads
and branches. The main points here are that
- you have a five-stage pipeline
- a taken branch requires a 1-cycle stall
- a
lw, in which the loaded value is used for
arithmetic in the immediately following instruction, also
requires a one-cycle stall.
On to the problems:
- (20 points) ``Naively'' compile the code sequence shown into
MIPS assembly code. By ``naively'' translate, I mean perform a
straightforward translation, without thinking about
optimizing the code. How large (measured in
bytes) is your resulting code? How many cycles does it take to
execute, given the assumptions?
- (20 points) Optimize your code from the previous question for
minimum execution time: do absolutely anything you can think of
to make the code run as quickly as possible. Continue to assume
no delayed loads or branches. Now how large is it? How many
cycles does it take? The resulting optimized code is
typically very, very different from a naive compilation.
- (20 points) Now optimize your code for minimum size. This time,
do absolutely anything you can think of to make the code as
small as possible. How large is it? How fast is it? The
resulting optimized code is typically very similar to a naive
compilation
- (30 points) Finally, optimize your code for a compromise between
speed and size on a dual-pipeline superscalar MIPS, as shown on
pages 511 through 514. Also as on page 513, you should assume a
delayed branch this time. How big is your code? How fast?
You can use SPIM to debug your code; to do that, you'll need to put in
an extra loop to initialize awry with values.
Unfortunately, SPIM doesn't do instruction cycle counting, so you
can't use it to get the cycle counts.
Last modified: Mon Sep 30 15:29:40 MDT 2002