📜  门| GATE-CS-2015(Set 3)|第65章

📅  最后修改于: 2021-06-30 01:28:19             🧑  作者: Mango

考虑以下具有五个指令I1至I5的代码序列。这些指令中的每一个都具有以下格式。

OP Ri, Rj, Rk 

其中对寄存器Rj和Rk的内容执行操作OP,并将结果存储在寄存器Ri中。

I1 : ADD R1, R2, R3
   I2 : MUL R7, R1, R3
   I3 : SUB R4, R1, R5
   I4 : ADD R3, R2, R4
   I5 : MUL R7, R8, R9 

考虑以下三个语句:

S1: There is an anti-dependence between instructions I2 and I5.
S2: There is an anti-dependence between instructions I2 and I4.
S3: Within an instruction pipeline an anti-dependence always 
    creates one or more stalls. 

以上哪种说法是正确的?

(A)只有S1为真
(B)只有S2为真
(C)仅S1和S2为真
(D)只有S2和S3为真答案: (B)
说明:给出的指令可以编写如下:

I1: R1 = R2 + R3
I2: R7 = R1 * R3
I3: R4 = R1 - R5 
I4: R3 = R2 + R4
I5: R7 = R8 * R9 

当指令需要稍后更新的值时,就会发生反依赖关系,也称为读后写(WAR)。

S1: There is an anti-dependence between instructions I2 and I5.
False, I2 and I5 don't form any write after read situation.  
They both write R7.

S2: There is an anti-dependence between instructions I2 and I4.
True, I2 reads R3 and I4 writes it.

S3: Within an instruction pipeline an anti-dependence always 
    creates one or more stalls. 
Anti-dependency can be removed by renaming variables. 
See following example.
1. B = 3
2. A = B + 1
3. B = 7
Renaming of variables could remove the dependency.
1. B = 3
N. B2 = B
2. A = B2 + 1
3. B = 7

这个问题的测验