Assignment 6, due Mar 23

Part of the homework for 22C:60 (CS:2630), Spring 2012
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

On every assignment, write your name legibly as it appears on your University ID card! Homework is due on paper at the start of class on the day indicated (usually Friday). Exceptions will be made only by advance arrangement (excepting "acts of God"). Late work must be turned in to the TA's mailbox (ask the CS receptionist in 14 MLH for help). Never push homework under someone's door!

  1. Background: One approximation for π is 333/106. In a high level language, you could write a function to (approximately) multiply an integer by π as follows:
    unsigned int timespi( unsigned int i ) {
        return (i * 333)/106;
    }
    

    Note that, to 64 bits of precision in hex, 1/106 = 0.026A439F656F1826

    a) Write the fastest SMAL Hawk instruction sequence you can find to multiply by 333, using the tricks discussed in Chapter 9 of the notes and Chapter 14 of the Hawk manual. (0.5 points)

    b) Write the fastest SMAL Hawk instruction sequence you can find to divide by 106, using all the tricks. (0.5 points)

  2. Background: Given a 64-bit value, with the least significant half in R3 and the most significant half in R4, give the fastest code you can work out for:

    a) Shifting the value 1 place left. (0.2 points)

    b) Shifting the value 6 places left. Strong hint: Yes, 6 repetitions of the code from part a) will work, but the problem can be solved in half as many instructions. (0.8 points)

  3. Background: The first unsigned multiplication routine given in Section 14.3 of the Hawk manual is not the same as the unsigned multiply code given in Chapter 9.

    a) Explain the most important difference between the two. Your explanation must be concise and at a high level. (0.4 points)

    b) Modify the code from Section 14.3 so it computes the 64-bit product of two unsigned 32-bit operands. (Hint: the modification required involves changing exactly one instruction.) (0.6 points)