Return to course page

Question 1: Why would a compiler likely not change

for(i=0; i<strlen(s); i+=1)
    x += s[i];

into

int N = strlen(s);
for(i=0; i<N; i+=1)
    x += s[i];
  1. compilers don't do optimizations if they think they might make code slower

  2. compilers have trouble proving the two variants have the same behavior

  3. compilers only look at one function at a time so it can't work with strlen

  4. compilers don't know how to move code outside of loops

Question 2: If function baz contains an invocation to function foo inside of a loop, and that is the only place foo is invoked in the code,

  1. inlining foo would increase assembly size but reduce bookkeeping ovverhead

  2. inlining foo would decrease assembly size and reduce bookkeeping ovverhead

  3. inlining foo would increase assembly size and increase bookkeeping ovverhead

  4. inlining foo would increase assembly size but decrease bookkeeping ovverhead

Question 3: Which of the following will (almost) never make code slower?
Select all that apply

  1. moving computation out of loops

  2. inlining functions

  3. eliminating unneeded memory references

  4. loop unrolling

  5. reordering code to take advantage of pipeline parallelism

  6. reordering loops to have better cache locality

Question 4: Which of the following will generally make code harder to read and maintain?
Select all that apply

  1. moving computation out of loops

  2. inlining functions

  3. loop unrolling

  4. using multiple accumulators

  5. blocking loops to improve cache hit rates

Question 5: If a functional unit has issue 2, latency 5, capacity 1, what is the best possible improvement that could be gained by exploiting its parallelism capabilities? Answer with a speedup number (such as 1 if no benefit is possible or 7.5 if code could be made 7.5 times faster)
Select all that apply

Answer:
Return to main page
Return to course page