Changelog:

  • 10 April 2024: change code slightly for this semester.
  • 15 April 2024: change specification of arguments to actually match function used this semester, since its arguments are passed differently
  • 16 April 2024: also make online tool’s copy of explanation use a matching description of the arguments
  • 22 April 2024: adjust answer sheet to mention choice of interpretation re: whether condition codes are in register file

1 Your Task

Fill in a pipeline diagram for a small function’s full execution.

Place you answer in the online tool https://kytos02.cs.virginia.edu/cs3130-spring2024/pld.php.

2 Guidelines

Consider the following code:

long sum_squared(long *array_start, long *array_end) {
    long *pointer;
    pointer = array_start;
    long result = 0;
    while (pointer != array_end) {
        long current = *pointer;
        pointer += 1;
        result += current * current;
    }
    return result;
}

which has been compiled to (numbers inserted for ease of reference)

    sum_squared:
0.      xorl    %eax, %eax
1.      cmpq    %rsi, %rdi
2.      je  .LBB0_2
    .LBB0_1:
3.      movq    (%rdi), %rcx
4.      imulq   %rcx, %rcx
5.      addq    $8, %rdi
6.      addq    %rcx, %rax
7.      cmpq    %rdi, %rsi
8.      jne .LBB0_1
    .LBB0_2:
9.      retq

Assume that this is run on a five-stage pipeline, where

You’re asked to expand this assuming

  1. you start with the first instruction after sum_squared is called
  2. the first instruction of sum_squared does not need to stall
  3. array_start pointing to the array {1, 2}
  4. array_end points to array_start + 2 (one past of the end of the array)
  5. the retq is the last instruction you need to handle