Your processor does not run one instruction at a time, then wait, then run the next. Modern CPUs are pipelined: they overlap many instructions, each at a different stage — fetch, decode, execute, write-back. When everything flows smoothly, throughput is high. When it doesn't, the pipeline stalls.
A stall is dead time. If instruction B needs the result of instruction A, and A takes five cycles to finish, then without any other work to do the processor sits idle for four cycles waiting. Those wasted cycles add up fast.
Instruction scheduling is the compiler technique that fills those gaps. Instead of emitting instructions in the obvious order, the compiler looks ahead and moves independent instructions into the delay slots — the idle cycles after a slow operation. The result is the same computation (every dependency is still respected), but far fewer stalls.
The idea sounds simple. Finding the optimal schedule, as you will see, is anything but.
Comments
Loading comments...