Processor architecture: RISC, CISC and pipelining
A-Level Computer Science · Advanced Architecture, Networks and Computational Thinking
Two design philosophies
CISC provides many complex instructions, each able to do a lot, so a program needs fewer instructions but each one may take several clock cycles and the hardware is complicated. RISC provides a small set of simple instructions, each designed to complete in one cycle, so programs are longer but the hardware is simpler, uses less power and is easier to pipeline.
Why RISC won in mobile devices
Simpler hardware means lower power consumption and less heat — decisive for a phone running on a battery. The compiler does more work to turn one complex operation into several simple instructions, and that is an acceptable trade because compilation happens once while execution happens billions of times.
Pipelining
Instead of finishing one instruction before starting the next, the processor overlaps them: while instruction $1$ is being executed, instruction $2$ is being decoded and instruction $3$ fetched. With $4$ stages, four instructions take $7$ cycles instead of $16$.
The catch is a branch. When a jump is taken, the instructions already in the pipeline are the wrong ones and must be discarded, which is why processors use branch prediction to guess which way a conditional jump will go.
Parallel processing
SISD is a single processor on a single data stream. SIMD applies the same instruction to many data items at once — the model behind graphics processors, image filters and much machine learning. MIMD runs different instructions on different data, which is what a multi-core general-purpose processor does.
Why more cores does not mean proportionally more speed
A program only speeds up if the work can be divided; the part that must run sequentially sets a floor on the total time no matter how many cores are added. Add the cost of coordinating cores and sharing memory, and doubling cores rarely halves the run time — that is the evaluation point.
Worked example: calculate the benefit of a pipeline and the limit of multiple cores
(a) A processor has a $5$-stage pipeline, each stage taking $1$ cycle. Calculate the number of cycles needed for $100$ instructions, with and without the pipeline.
(b) A program has $30\%$ of its workload that must run sequentially. Explain why going from $4$ to $8$ cores does not make the program twice as fast.
Solution
(a) Without a pipeline. Each instruction must go through all $5$ stages before the next one starts.
Number of cycles $=100\times5=\mathbf{500}$ cycles.
With a pipeline. The first instruction takes the full $5$ cycles to pass through the pipeline; after that, one more instruction completes every cycle.
Number of cycles $=5+(100-1)=\mathbf{104}$ cycles.
About $4.8$ times faster — close to the number of stages, and that is the general rule: with $n$ stages, the maximum benefit approaches $n$ times when the number of instructions is large enough.
But this is an ideal figure. In practice, each jump instruction that is taken forces the wrongly fetched instructions to be flushed and fetching to restart, costing about $4$ cycles. A program with many loops and branches will not reach this $4.8$ times.
(b) Why $8$ cores are not twice as fast as $4$ cores.
Only $70\%$ of the workload can be divided among multiple cores; the remaining $30\%$ must run sequentially and does not speed up at all however many cores there are.
Suppose one core takes $100$ units of time:
With $4$ cores: $30+\dfrac{70}{4}=30+17.5=47.5$ units.
With $8$ cores: $30+\dfrac{70}{8}=30+8.75=38.75$ units.
Doubling the number of cores reduces the time by only about $18\%$, not $50\%$.
Absolute limit: even with infinitely many cores, the time never falls below $30$ units — so the best possible speed-up is only $3.3$ times. The sequential part sets a floor that cannot be passed.
An additional practical cost: more cores also bring coordination overhead and contention for shared memory, so the real figure is even worse than the $38.75$ units calculated above.