6.x1, 6.x2, 6.x3
The following code computes the maximum of two memory locations, whose
addresses are in $a1 and $a2, and places the result back into the
memory location specified by $a3.
lw $t1, 0($a1)
lw $t2, 0($a2)
slt $t0, $t1, $t2
add $t3, $t1, $zero
beq $t0, $zero, done
add $t3, $t2, $zero
done:
sw $t3, 0($a3)
Assume the code is executed using the pipelined architecture is used
as described in Chapter 6 with the following assumptions:
Forwarding is used wherever possible.
Branch hazards are dealt with as discussed on pages 418 and
419, i.e., the pipeline is optimized for branches that are not taken
and that we moved the branch execution to the ID stage.
- 6.x1: Identify above all data and branch hazards in the
code. Identify which hazards can be helped by forwarding and which
may lead to stalls.
- 6.x2: Indicate in the table below which stages of each instruction
are in the pipeline during execution of the code assuming the branch
is not taken. Each entry should contain a IF, ID, EX, MEM or WB, or
should be left blank.
| INSTRUCTION | CYCLE NUMBER
|
|---|
| 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 | 12 | 13 | 14 | 15
|
|---|
lw $t1, 0($a1) | | | | | | | | | | | | | | |
|
lw $t2, 0($a2) | | | | | | | | | | | | | | |
|
slt $t0, $t1, $t2 | | | | | | | | | | | | | | |
|
add $t3, $t1, $zero | | | | | | | | | | | | | | |
|
beq $t0, $zero, done | | | | | | | | | | | | | | |
|
add $t3, $t2, $zero | | | | | | | | | | | | | | |
|
sw $t3, 0($a3) | | | | | | | | | | | | | | |
|
- 6.x3: Indicate in the table below which stages of each
instruction are in the pipeline assuming the branch is taken.
| INSTRUCTION | CYCLE NUMBER
|
|---|
| 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 | 12 | 13 | 14 | 15
|
|---|
lw $t1, 0($a1) | | | | | | | | | | | | | | |
|
lw $t2, 0($a2) | | | | | | | | | | | | | | |
|
slt $t0, $t1, $t2 | | | | | | | | | | | | | | |
|
add $t3, $t1, $zero | | | | | | | | | | | | | | |
|
beq $t0, $zero, done | | | | | | | | | | | | | | |
|
add $t3, $t2, $zero | | | | | | | | | | | | | | |
|
sw $t3, 0($a3) | | | | | | | | | | | | | | |
|