2

优化编译器通常考虑通过软件流水线进行指令调度。但是由于有硬件管道,我想知道软件管道调度的优势是什么?

4

2 回答 2

3

在某些情况下(特定于 CPU 的)执行速度可能取决于执行顺序。使用软件流水线,编译器会重新排序您的语句以获得最佳顺序,如果可以这样做而不影响最终结果的话。

最佳顺序可能取决于现有的硬件流水线,或者某些寄存器可能在某些执行顺序下更优化地使用,等等。

于 2013-07-08T06:35:55.377 回答
1

Software pipelining can make loops execute faster. In some cases really faster.

For example:

num = 100;
i = 0;
loop:
load r0 sp+i;
add r2 r1 r0;
i++;
if ( i < num) goto loop

In this example the add instruction has to wait until r0 has the value loaded from memory. If the latency is say 3 cycles. Then there will be an overhead of 3 cycle per iteration for the execution of this loop. This can be a significant overhead. By software-pipelining this overhead can be reduced a little bit.

num = 100;
load r0 sp+0;
i=0;
loop:
add r2 r1 r0;
i++;
load r0 sp+i
if (i < num) goto loop

In the second case when the program enters the loop it already has the value in r0 when the add instruction is executed. In each iteration by the time program reaches add instruction the value is there in r0. So the latency is reduced.

PS: I have just used mnemonics to explain the idea. This is not a real assembly language of some architecture.

于 2013-07-15T21:52:40.870 回答