Docsity

3 Problems with Solutions in Practice Set 4 | CS 433, Assignments of Computer Architecture and Organization

Toggle sidebar
bg1
CS433g: Computer System Organization – Fall 2005
Practice Set 4 - Solution
Problem 1
Consider the following format for predicated MIPS instructions:
(pT) ADD R1, R2, R3
where the ADD instruction is predicated on the predicate register pT. Assume a set of 1-bit
predicate registers that are set by a compare instruction of the form:
CMP.ne pT, pF = R8, R0
The example above uses a not equal (.ne) comparison relation to match the code fragment above.
(You can assume the availability of any comparison relation with two operands; i.e. .le for less
than or equal to and .gt for greater than.) The above compare sets the 1-bit predicate registers as
follows:
pT = (R8 != R0)
pF = !(R8!= R0)
So pT is true if R8 is not equal to R0, and pF is the complement of pT.
• Using the predicated instructions described above, write the three basic blocks of the
following code fragment as a single basic block:
SUB R1, R13, R14
BNEZ R1, L1
ADDI R2, R2, #1
SW 0(R7), R2
J L2
L1: MULT.D F0, F0, F2
ADD.D F0, F4, F2
S.D 0(R8), F0
L2: ...
• What are all the dependencies in your new basic block?
Solution:
1. The code fragment with predicated instructions is as below:
SUB R1, R13, R14
CMPI.ne pT, pF = R1, #0
(pF) ADDI R2, R2, #1
(pF) SW 0(R7), R2
(pT) MULT.D F0, F0, F2
(pT) ADD.D F0, F4, F2
(pT) S.D 0(R8), F0
L2: . . .
2. The data dependencies of the basic block are:
pf3
pf4

Partial preview of the text

Download 3 Problems with Solutions in Practice Set 4 | CS 433 and more Assignments Computer Architecture and Organization in PDF only on Docsity!

CS433g: Computer System Organization – Fall 2005 Practice Set 4 - Solution

Problem 1

Consider the following format for predicated MIPS instructions:

(pT) ADD R1, R2, R

where the ADD instruction is predicated on the predicate register pT. Assume a set of 1-bit predicate registers that are set by a compare instruction of the form:

CMP.ne pT, pF = R8, R

The example above uses a not equal (.ne) comparison relation to match the code fragment above. (You can assume the availability of any comparison relation with two operands; i.e. .le for less than or equal to and .gt for greater than.) The above compare sets the 1-bit predicate registers as follows:

pT = (R8 != R0) pF = !(R8!= R0)

So pT is true if R8 is not equal to R0, and pF is the complement of pT.

  • Using the predicated instructions described above, write the three basic blocks of the following code fragment as a single basic block:

SUB R1, R13, R BNEZ R1, L ADDI R2, R2, # SW 0(R7), R J L

L1: MULT.D F0, F0, F ADD.D F0, F4, F S.D 0(R8), F L2: ...

  • What are all the dependencies in your new basic block?

Solution:

  1. The code fragment with predicated instructions is as below: SUB R1, R13, R CMPI.ne pT, pF = R1, # (pF) ADDI R2, R2, # (pF) SW 0(R7), R (pT) MULT.D F0, F0, F (pT) ADD.D F0, F4, F (pT) S.D 0(R8), F L2:...
  2. The data dependencies of the basic block are:

(a) RAW dependency due to R1 between SUB and CMPI. (b) RAW dependency due to pF between CMPI and ADDI. (c) RAW dependency due to pF between CMPI and SW. (d) RAW dependency due to R2 between ADDI and SW. (e) RAW dependency due to pT between CMPI and MULT.D. (f) RAW dependency due to pT between CMPI and ADD.D. (g) RAW dependency due to pT between CMPI and S.D. (h) RAW dependency due to F0 between MULT.D and S.D. (i) RAW dependency due to F0 between ADD.D and S.D. (j) WAW dependency due to F0 between MULT.D and ADD.D. (k) WAR dependency due to F0 between MULT.D and ADD.D.

Problem 2

Consider the following code excerpt from a larger set of instructions:

. . . loop: SW 7(R1), R2 (1) ADD R1, R1, #8 (2) LW R2, 7(R1) (3) ADD R4, R2, R1 (4) SD 200(R7), F2 (5) BEZ R4, loop (6) SW 7(R4), R5 (7) . . .

List all data dependences between the above instructions that a compiler would find. Assume that this code fragment is a portion of a larger piece of code, but the instructions that are not shown do not create additional data dependences.

Is it possible to reorder any instruction pairs that the compiler identifies as dependent?

What additional information is necessary to determine this? For this

part, disregard any instructions that come in between the two dependent instructions.

Solution :

Data dependences: Potentially between 1 and 5 for 7(R1) and 200(R7) Potentially between 1 and 7 for 7(R1) and 7(R4) Between 2 and 3 for R Between 2 and 4 for R Between 3 and 4 for R Between 4 and 6 for R Between 4 and 7 for R

... ;intervening instructions recover: L.D F2,0(R1) ADD.D F4,F0,F JUMP back ;return to original path ... ... null:...