在5.2 CLA Pipeline Alignment(P35-P36)这一章节中,我对Example 5-1. Write Followed by Read - Read Occurs First与Example 5-2. Write Followed by Read - Write Occurs First不是很理解,看了很多遍,不知道作者想表达的什么意思,求救于各位高手,望予以解答,小弟在此先行谢过。
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
在5.2 CLA Pipeline Alignment(P35-P36)这一章节中,我对Example 5-1. Write Followed by Read - Read Occurs First与Example 5-2. Write Followed by Read - Write Occurs First不是很理解,看了很多遍,不知道作者想表达的什么意思,求救于各位高手,望予以解答,小弟在此先行谢过。
举个例子
第一条指令的功能是计算:A+B=C
第二条指令的功能是计算:C+D=M
第二条指令要用到第一条指令的计算结果C。由于有流水线,CLA在第一条指令没有执行完之前(也就是在没有计算出C之前),
CLA就已经对第二条指令取指,译码(具体看CLA流水线)。
如果不插入三个NOP,第二条指令使用的C,就不是第一条指令计算的结果。
插入三个NOP,等待第一条语句计算完(计算出C),才能执行第二条指令。具体的过程,你要看CLA的流水线的各阶段,F1 F2 D1 D2 R1 R2 E W。
表达能力有限,大概的意思应该是这样。
楼上解释是正确的。
通常来讲,如果都是CLA指令,都使用相同的流水线,应该没有问题,但这一章节讲的就是特例,比如后一条语句的8级流水线执行到R2时,需要去读前一条语句的运算结果,可它是在W才写入,所以为了使用这个结果,必须加入延时等待。这个例子是因为流水线的读和写是有时间差的,而这两条语句又互相有关系(使用同一个变量或寄存器)那么写程序时就需要人为处理了。
具体就像楼上所说的,还是请仔细看一下流水线的各个阶段去了解一下。
是我没看清楚,上面的就是特例,但内容还是一样的。
第一条语句中Reg1的值可能影响到Reg2的值,那么在Reg1还没写入时,Reg2还是原来的值,因此如果程序设计原意是希望得到Reg1写完后的Reg2的值,那么就需要加入MNOP,否则不需要,就如Example5-1。
你再仔细理解一下这段话:
In both the CLA pipeline the read operation occurs before the write. This means that if a read operation immediately follows a write, then the read will complete first as shown in Example 5-1. In most cases this does not cause a problem since the contents of one memory location does not depend on the state of another. For accesses to peripherals where a write to one location can affect the value in another location the code must wait for the write to complete before issuing the read as shown in Example 5-2.