C8 · Lesson 5 · CISC and RISC
Two philosophies of instruction sets, and why the difference matters less inside the chip than on paper
RISC-V instructions are all 32 bits, touch memory only through loads and stores, and each does one simple thing. The x86 instructions in most laptops and servers range from 1 to 15 bytes, can add a memory operand directly to a register, and include single instructions that copy whole strings. The first is called RISC (reduced instruction set computer) and the second CISC (complex instruction set computer). The argument between them shaped the 1980s; today both kinds of chip translate instructions into simple internal operations, and the real trade-offs, code size, decoding cost and how many instructions a program needs, can be put in numbers with the iron law of lesson 31.
- The same statement,
a = b + cwith all three in memory, in RISC-V. It takes two loads, an add and a store: four 4-byte instructions, 16 bytes. - An x86 compiler would write
mov eax, [b],add eax, [c],mov [a], eax: three instructions, becauseaddcan read memory itself, in about 15 bytes. - Step through and watch the memory change only at the store.
Predict
A program runs 1.0 billion x86 instructions at an average of 1.5 cycles each. Compiled for RISC-V, it needs 1.3 billion instructions at 1.1 cycles each. Both chips run at 3 GHz. Which finishes first?
Time is instructions × cycles per instruction ÷ clock rate. x86: = 0.500 s. RISC-V: = 0.477 s, 4.7% faster. Fewer, more complex instructions only win if they don't cost proportionally more cycles; the product is what counts.
Name it
Two philosophies
| CISC (x86) | RISC (RISC-V, ARM) | |
|---|---|---|
| Instruction length | 1 to 15 bytes | fixed 4 bytes (2 with compression) |
| Memory operands | most instructions can read or write memory | only loads and stores |
| Registers | 8 in the original, 16 in x86-64 | 32 |
| Addressing | many modes, such as base + index × scale + offset | base + offset |
| Decoding | sequential, complex | simple, parallel |
What happened
In the 1980s, RISC designs ran faster because their simple, fixed instructions pipelined well (lesson 40). Then x86 processors began translating each instruction into simple internal micro-operations and running those on a RISC-like core, keeping compatibility while gaining most of the speed. What remains of the difference:
- Decoding cost: finding where variable-length instructions begin takes energy and limits how many can be decoded per cycle; x86 chips cache decoded micro-operations to avoid repeating it.
- Code density: variable-length code is often smaller, which saves instruction cache. RISC-V's compressed extension (RV32C) gives common instructions 16-bit forms and recovers most of the gap.
- Instruction count: memory operands and complex addressing let CISC do more per instruction, but each takes more cycles.
The iron law
An instruction set changes the first factor, the microarchitecture the second, and the circuit and process the third. Comparing two designs on any one factor alone is how marketing misleads.
Average instruction size
If a fraction of instructions has a short form of bytes and the rest are bytes, the average is . With RV32C, about half to two-thirds of the instructions in typical code compress to 2 bytes.
Worked example
A RISC-V program has 60% of its instructions in compressible forms. How much smaller is it with RV32C, and how does that compare with x86 code averaging 3.7 bytes per instruction for 20% fewer instructions?
Show the solution
- Average size with RV32C. which is 30% smaller than 4 bytes.
- Per 100 RISC-V instructions. That's 280 bytes compressed and 400 uncompressed.
- The x86 version. It needs 80 instructions at 3.7 bytes:
- Compare. Compressed RISC-V is slightly smaller than x86 here, and uncompressed RISC-V is a third larger.
- What sets the density. Code density comes down to the encoding more than to CISC versus RISC as such.
Answer RV32C averages 2.8 bytes an instruction, 30% smaller; per 100 RISC-V instructions that's 280 bytes, against 296 for x86 and 400 uncompressed.
Worked example
Count the RISC-V instructions and bytes for a[i] = a[i] + 5, with the array's address in a0 and i in a1 (words), and compare an x86 add dword [rdi + rsi*4], 5 of 4 bytes.
Show the solution
- Write the RISC-V sequence. RISC-V needs the address computed first, then a load, an add and a store.
slli t0, a1, 2
add t0, a0, t0
lw t1, 0(t0)
addi t1, t1, 5
sw t1, 0(t0)
- Count it. Five instructions, 20 bytes (or 12 to 16 compressed, depending on which registers are used).
- The x86 version. x86 does it in one 4-byte instruction, which the processor splits internally into a load, an add and a store, three micro-operations.
- Compare. The work is the same; x86 packs it more densely, and RISC-V exposes each step to the compiler, which can reuse the address or the loaded value.
Answer RISC-V takes five instructions, 20 bytes (12 to 16 compressed); x86 takes one 4-byte instruction that becomes three micro-operations.
Worked example
A chip decodes x86 instructions at 4 per cycle, but a loop body runs from its micro-operation cache at 6 per cycle. The loop has 600 instructions, 1.1 micro-operations each, and executes 10⁶ times at 3 GHz. If decode is the bottleneck, how much time does the cache save?
Show the solution
- Cycles per iteration from the decoders.
- From the micro-op cache. The 600 instructions are 660 micro-operations:
- Time for a million iterations at 3 GHz.
- The saving. 13.3 ms, 27%.
- Why the cache exists. Decoding x86 is expensive; a fixed-length RISC instruction set can decode many instructions per cycle directly.
Answer the micro-op cache saves 13.3 ms, 27%: 36.7 ms against 50 ms.
Check
A program executes 1 billion instructions at an average CPI of 1.2 on a 4 GHz processor. How long does it take?
Write units the way you normally would: 1.5 s and 1500 ms are the same answer.
Check
Design A runs 1 billion instructions at CPI 1.4. Design B needs 1.4 times as many instructions at CPI 1.2. Both run at the same clock.
(a)
What is B's run time as a fraction of A's?
(b)
What CPI would B need to tie A?
Check
In a RISC-V program, a fraction 0.6 of instructions compress to 2 bytes and the rest stay 4 bytes. What's the average instruction size?
Check
A loop of 600 x86 instructions, 1.1 micro-operations each, is limited by decoding at 5 instructions per cycle. A micro-operation cache delivers 8 per cycle. How many cycles per iteration does the cache save?
Check
Memory holds a at 0x1000, b at 0x1004 and c at 0x1008 (the starter stores them). Compute a = b + c with loads and a store, as a RISC machine must.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
Why do modern x86 processors translate instructions into micro-operations before executing them?
Check
Model code size. A program has n = 2500 instructions; their kinds and proportions are: arithmetic 45% (compressible 70% of the time), loads and stores 30% (compressible 60%), branches and jumps 15% (compressible 50%), other 10% (never). Compute size_rv32 (bytes, all 4-byte), size_rvc (bytes, compressed where possible, using the expected counts) and saving (the fractional reduction).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Explain why
RISC designs were once much faster than CISC ones; today high-end x86 and ARM processors perform similarly. Explain what changed, and what differences between the instruction sets still matter.
Early RISC chips won because fixed-length, load-store instructions were easy to pipeline: each took about one cycle in a simple pipeline, while CISC instructions took many cycles in microcode. When transistor budgets grew, x86 designers began translating each instruction into simple micro-operations and running those on an out-of-order core much like a RISC one, so the execution engines converged. What remains is at the edges: decoding variable-length x86 instructions costs energy and limits decode width, which is why x86 chips cache decoded micro-operations; code density affects instruction-cache use, where x86 and compressed RISC-V are similar; and simpler encodings make RISC designs cheaper to build and verify, which matters most for small, low-power cores.
Practice
Keep practicing
8 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.