Hardware and Virtual Machines
How RISC and CISC processors are designed and pipelined, how computers run instructions in parallel, and what virtual machines are.
RISC and CISC
RISC uses a few simple, fast instructions. CISC uses many complex instructions, so a task can need fewer of them.
| RISC (reduced instruction set computer) | CISC (complex instruction set computer) | |
|---|---|---|
| Instruction set | small | large: many instructions |
| Instructions | simple, of fixed length | of different lengths |
| Clock cycles | most finish in one clock cycle | some do a lot of work over many clock cycles |
| Addressing modes | few | many |
| Registers | many general-purpose registers | fewer |
| Control unit | hard-wired | microprogrammed |
| Using memory | only LOAD and STORE instructions | many kinds of instruction |
| Programs | longer | a task can need fewer instructions |
A clock cycle is one tick of the processor's clock.
Remember:Each RISC instruction is simple and quick. That makes pipelining (next note) straightforward.
Example:The box below multiplies two numbers. CISC uses one instruction over several clock cycles. RISC uses four instructions, one clock cycle each.
Multiply the numbers at 2:3 and 5:2,
then store the result at 2:3.
(The mnemonics are illustrative,
not Cambridge's.)
CISC MULT 2:3, 5:2
one instruction, several clock
cycles
RISC LOAD A, 2:3
LOAD B, 5:2
PROD A, B
STORE 2:3, A
four instructions, one clock
cycle eachPipelining: five stages at once
Pipelining overlaps instructions, like a factory line, so one instruction can finish every clock cycle.
An instruction passes through five stages, one clock cycle each:
- instruction fetch (IF)
- instruction decode (ID)
- operand fetch (OF)
- instruction execute (IE)
- write back (WB).
Without pipelining, one instruction finishes every stage before the next one starts.
With pipelining, the next instruction enters IF as the one before moves to ID. Up to five instructions are in progress at once. Once the pipe is full, one instruction finishes every cycle.
Example:n instructions take 5 + (n − 1) cycles instead of 5n. So six instructions take 10 cycles, not 30.
RISC suits this: each instruction is simple and spends one cycle in each stage. RISC also uses many general-purpose registers.
Registers in RISC processors
RISC needs many registers, because its instructions can only work on values that are already in registers.
A RISC processor has many general-purpose registers: registers that instructions can use for any data. A CISC processor has few.
Why do registers matter more in RISC? Only LOAD and STORE instructions address memory. An instruction such as an add works only on values that are already in registers.
- Enough registers: the program loads each value once. It keeps every result it still needs in a register, and stores only the answer.
- Too few registers: a result that is still needed has to be stored in memory and loaded back later.
Example:The box below works out P = (W + X) × (Y + Z). Two registers need 10 instructions, and four need 8. The extra 2 are the STORE and the LOAD of T.
P = (W + X) × (Y + Z)
W, X, Y, Z, T and P are in
memory; R1 to R4 are registers.
ADD R1, R2 puts R1 + R2 into R1.
(The mnemonics are illustrative,
not Cambridge's.)
2 REGISTERS 4 REGISTERS
LOAD R1, W LOAD R1, W
LOAD R2, X LOAD R2, X
ADD R1, R2 LOAD R3, Y
STORE T, R1 LOAD R4, Z
LOAD R1, Y ADD R1, R2
LOAD R2, Z ADD R3, R4
ADD R1, R2 PROD R1, R3
LOAD R2, T STORE P, R1
PROD R1, R2
STORE P, R1Branches and interrupts in a pipeline
A pipeline assumes the next instruction comes next. A taken branch or an interrupt breaks that plan.
A pipeline assumes the next instruction is the one after.
Watch out:If a branch (a jump) is taken, the instructions fetched behind it are the wrong ones. They are flushed, and the pipeline refills from the branch target. Cycles are wasted.
Interrupts need care too.
A CISC processor checks for an interrupt at the end of each fetch-execute cycle. It saves its registers and runs the service routine (the code that deals with the interrupt).
A pipelined RISC processor may have five instructions part-done when an interrupt arrives. It usually:
- lets the instruction in WB finish
- discards the rest
- runs the service routine
- restarts with the next instruction in order: the first one it discarded.
Flynn's four architectures
Flynn sorts computers by two counts: how many instruction streams and how many data streams they handle at once.
Computers are classified by how many instruction streams and data streams they handle at once. In the names, S means single, M multiple, I instruction and D data.
| Single data | Multiple data | |
|---|---|---|
| Single instruction | SISD: one processor runs one instruction on one data item at a time | SIMD: many processors (an array processor) apply the same instruction to different data at once |
| Multiple instruction | MISD: several processors apply different instructions to the same data | MIMD: many processors work independently, each running its own instructions on its own data |
Examples:
- SIMD: brightening every pixel of an image together.
- MISD: three different checks on one reading.
- MIMD: the cores of a multi-core computer.
Massively parallel computers
A massively parallel computer splits one task between a very large number of processors that work at the same time.
A massively parallel computer has a very large number of separate processors.
- The task is split into blocks of code.
- Each processor works on a different block, at the same time and independently.
- The processors are linked by a network. They communicate by passing messages, or through shared pools of memory.
So it needs both parallelism (working at the same time) and coordination (fitting the parts together).
Watch out:Extra processors speed up only the part of a task that can run in parallel.
A task takes 100 s on one processor, and 90% of it can run in parallel:
| Processors | Time |
|---|---|
| 1 | 100 s |
| 4 | 32.5 s |
| 16 | 15.625 s |
| 1024 | still 10.09 s |
The serial 10 s (the part that cannot run in parallel) never shrinks.
Virtual machines
A virtual machine is software that acts as a whole computer, so one computer can run another operating system safely.
A virtual machine is software that emulates (copies the behaviour of) a whole computer. A guest operating system runs inside it, on a host computer. The virtual machine software, called a hypervisor, passes the guest's requests to the host OS.
Uses:
- running an operating system, or an old (legacy) program, that the host cannot run
- testing risky software in isolation
- running several virtual machines on one computer.
| Virtual machines | |
|---|---|
| Benefits | a crash or virus in a guest does not reach the host or other guests; no extra hardware is needed |
| Limitations | extra code runs, so it is slower; memory and processor time are shared; some hardware cannot be emulated; host and guests must all be maintained |
Exam:Explain a benefit; do not just name it. For example: a crash in the guest does not affect the host.
KEY TERMS
CHECK YOURSELF
1.Why is RISC easier to pipeline than CISC?
2.One instruction applied to many data items at once is which classification?
3.What is a genuine drawback of running software in a virtual machine?
4.An interrupt arrives while a pipelined RISC processor has five instructions part-done. What usually happens?
5.With pipelining, how many clock cycles do 4 instructions take on a five-stage pipeline?
6.Which list gives the five stages of a RISC pipeline, in order?
7.Which of these describes a CISC processor rather than a RISC one?
8.The cores of a multi-core computer each run their own instructions on their own data, independently. Which architecture is this?
9.Which of these describes a massively parallel computer?
10.A firm's old accounts program needs an operating system its new computers cannot run. How can a virtual machine help?