Sub topic 5
RISC versus CISC design choices
This chapter assumes you know the fetch-decode-execute cycle, the instruction formats from the earlier chapters, and the basic addressing modes. Here you will compare two ways of designing an instruction set, see why their features come as a group, and apply the performance equation that GATE questions use.
The core trade-off
Every instruction set puts work in one of two places: the hardware or the program.
- A CISC (Complex Instruction Set Computer) gives the hardware many powerful instructions. One instruction may read memory, compute and write memory back. Programs are short, and each instruction is hard to execute.
- A RISC (Reduced Instruction Set Computer) gives the hardware a small set of simple instructions. Programs are longer, and each instruction is easy to execute quickly.
Neither is faster in general. The choice trades instruction count against cycles per instruction and clock period.
Typical characteristics
| Feature | RISC | CISC |
|---|---|---|
| Instruction length | Fixed, such as 32 bits | Variable, such as 1 to 15 bytes |
| Instruction formats | Few | Many |
| Memory access | Only load and store instructions | Most instructions may use memory operands |
| Addressing modes | Few and simple | Many and complex |
| General registers | Many (often 32 or more) | Fewer (often 8 to 16) |
| Control unit | Usually hardwired | Often microprogrammed |
| Cycles per instruction (CPI) | Close to 1 | Larger, and varies by instruction |
| Code size | Larger | Smaller |
| Pipelining | Easy | Harder |
Why the features come together
The RISC features follow from one decision: make every instruction cheap and uniform.
- Load/store architecture. Only
LOADandSTOREtouch memory. Arithmetic works on registers. Memory delays then appear in only two instruction types, and the ALU never waits for a memory operand. - Fixed-length instructions. The hardware knows where the next instruction starts without decoding the current one. It can fetch ahead safely.
- Few formats. Register fields sit at the same bit positions in every format. Decode is a simple wiring job, so a hardwired control unit is small and fast.
- Many registers. Arithmetic has to work on registers, so the compiler needs enough of them to keep values out of memory.
- Pipelining. Uniform instructions can pass through the same stages (fetch, decode, execute, memory, write-back) in about one cycle each, which gives a CPI near 1.
CISC features come from the older goal of narrowing the semantic gap between high-level languages and machine code. Memory was expensive, so dense code mattered. A microprogrammed control unit made it cheap to add one more complex instruction, because the designer only wrote more microcode.
One statement, two encodings
Take A = A + B, where A and B are memory words.
CISC (one instruction):
ADD A, B ; M[A] <- M[A] + M[B]
RISC (four instructions):
LOAD R1, A ; R1 <- M[A]
LOAD R2, B ; R2 <- M[B]
ADD R1, R1, R2 ; R1 <- R1 + R2
STORE R1, A ; M[A] <- R1The CISC version has a quarter of the instructions. Its ADD needs two memory reads and one write, so it takes many cycles and many microinstructions. Each RISC instruction is simple. After the pipeline fills, one finishes per cycle.
The performance equation
CPU time is the product of three factors:
CPU time = instruction count × CPI × clock period
RISC raises the first factor and lowers the other two. This program applies the equation.
def cpu_time(instr_count, cpi, freq_hz):
"""Execution time in seconds."""
return instr_count * cpi / freq_hz
cisc = cpu_time(1_000_000, 4.0, 1e9)
risc = cpu_time(1_600_000, 1.25, 1e9)
print(f"CISC: {cisc * 1000:.1f} ms") # CISC: 4.0 ms
print(f"RISC: {risc * 1000:.1f} ms") # RISC: 2.0 ms
print(f"Speedup of RISC: {cisc / risc:.1f}") # Speedup of RISC: 2.0Here RISC executes 60% more instructions but is twice as fast overall. The speedup is not guaranteed. If RISC needed 3,000,000 instructions at the same CPI, it would take 3.75 ms and lose.
Design pressures in the encoding
Fixed length limits what one instruction can hold. Suppose a 32-bit format has a 6-bit opcode and three register fields, and the machine has 32 registers. Each register field needs 5 bits, so the register fields take 15 bits. The opcode and register fields together take 21 bits, leaving 11 bits. A load with a displacement must fit its offset in whatever bits remain, and a large constant needs two instructions. CISC avoids this with variable-length encoding. A long constant simply makes the instruction longer, which is why the decoder must examine the instruction before it can find the next one.
Many registers also affect encoding. Doubling the registers adds one bit to every register field. With three fields, that is three more bits per instruction.
Control unit and pipelining
The choice of ISA affects the control unit.
- A regular RISC format lets a small hardwired decoder produce control signals within one short clock period.
- A CISC instruction may need a long sequence of register transfers, and a microprogram stores that sequence in a control store. Chapter material on microprogrammed control covers this in detail.
- Variable length and memory operands cause irregular pipeline stage use. Modern CISC processors, such as x86, handle this by translating each complex instruction into simpler internal operations, which a RISC-like core then executes.
Common errors
- "RISC always runs faster." It does not. Compare using the performance equation, not the label.
- "RISC programs are smaller." They are usually larger, because one CISC instruction becomes several RISC instructions.
- "RISC has no complex addressing." It has few modes, usually register plus displacement. Questions often ask which modes a load/store machine lacks, such as memory-indirect.
- "CISC cannot be pipelined." It can, but irregular instructions make it harder. Real CISC chips translate to internal simple operations.
- Mixing up the control unit. Hardwired control is typical of RISC and microprogrammed control of CISC. This is a tendency, not a rule.
Exercise
A CISC program runs 500 instructions with an average CPI of 6 on a 2 GHz clock. The same program on a RISC machine, also at 2 GHz, runs 800 instructions with an average CPI of 1.5. How much faster is the RISC machine?
Show answer
CISC cycles = 500 × 6 = 3000, so time = 3000 / 2×10^9 = 1.5 microseconds. RISC cycles = 800 × 1.5 = 1200, so time = 0.6 microseconds. Speedup = 1.5 / 0.6 = 2.5.
Exercise
A RISC machine has 32-bit fixed-length instructions, a 6-bit opcode, three register fields and 64 registers. How many bits remain in a three-register arithmetic instruction, and why does a load with a 16-bit displacement still fit?
Show answer
Each register field needs 6 bits (2^6 = 64), so the three fields take 18 bits. With the 6-bit opcode, 24 bits are used and 8 remain. A load needs only the opcode, one destination register and one base register (6 + 6 + 6 = 18 bits), leaving 14 bits, which cannot hold a 16-bit displacement. The format must shrink the register fields or use a different field layout. With 32 registers (5 bits each), a load would use 6 + 5 + 5 = 16 bits and leave 16 bits for the displacement, which fits exactly.