Building Z86: Lessons from Implementing an Out-of-Order x86 CPU on FPGA
Building z86: Lessons from Implementing an Out-of-Order x86 CPU on FPGA
My previous x86 cores, z386 and z486, were built primarily for retro gaming on FPGA. z86 and its companion PC platform z86_pc are a bit different. They certainly serve 1990s PC preservation (running DOOM at 85 FPS, Quake at 35 FPS, and booting Windows 95, 98 SE, and NT 4.0 on live hardware), but they also aim to fill a gap: there has never been an open-source superscalar out-of-order x86 CPU core, even though out-of-order x86 processors became mainstream more than 30 years ago and still dominate modern PCs.
Universities teach Tomasulo's algorithm, register renaming, and reorder buffers out of textbooks without real x86 RTL to inspect or modify, and open-source FPGA/ASIC CPU work has focused almost entirely on RISC-V. My hope is that an Apache-2.0, Linux-booting out-of-order IA-32 implementation can serve both as a teaching artifact and as a practical foundation for future open-source FPGA or chip projects.
The project started in June 2026, when I began collecting Intel P6 materials (the Intel IA-32 Software Developer's Manuals, Shen & Lipasti's Modern Processor Design, P6 patents, and community microcode notes). After releasing z486 in August, a vintage Dell OptiPlex GXpro (Pentium Pro stepping 0619) arrived on my desk in early September. Over the next three months, the project grew into a dual-board v0.1 release targeting both the Xilinx ZCU104 and the $250 Kria KV260.
This post discusses the architectural mechanisms, engineering challenges, and lessons from taking an out-of-order x86 CPU from a blank slate to booting MS-DOS, Windows 95/98/NT 4.0, and 32-bit Linux on FPGA.
In-Order and Out-of-Order Are Very Different Animals
Moving from z486 to z86 is not a matter of widening a pipeline or adding a few more ALUs. In-order and out-of-order processors are fundamentally different machines.
z486 is a classic 5-stage in-order pipeline. Every instruction marches in lockstep from fetch to writeback. When a load misses L1 cache or a multi-cycle x87 divide starts, the entire pipeline simply stalls until the result returns. Control is centralized, state is small, and there is no speculative architectural state to unwind.
- A P6-class CPU is a 14-stage out-of-order machine composed of three loosely coupled pipelines joined by queues and buses: an in-order front end (fetch, variable-length decode into µops, register rename, and resource allocation), an out-of-order execution core (reservation station wakeup/select, multi-port dispatch, and dataflow writeback), and an in-order retirement engine (reorder buffer commit, fault/branch recovery, and committing stores to memory).
Dynamic scheduling buys huge real-world performance - especially on x86, where compilers only have eight integer GPRs and memory latency dominates.
Why Out-of-Order? ILP and Register Renaming
First, a short refresher on how out-of-order execution works. At its core, OOO exists to exploit instruction-level parallelism (ILP) - finding independent work in a sequential instruction stream and running it while earlier instructions are stuck waiting on memory or slow arithmetic.
Consider a short, everyday x86 sequence made of two completely independent computations (Chain A and Chain B). Because x86 only gives the compiler eight general-purpose registers, the compiler naturally reuses EAX for both:
; Chain A - starts with a cache miss
1: mov eax, [ebx] ; slow load (cache miss)
2: add eax, 1 ; true dependency on (1)
3: mov [esi], eax ; true dependency on (2)
; Chain B - logically independent work, but reuses EAX:
4: mov eax, [ecx] ; fast load (cache hit!)
5: add eax, edx ; depends on (4), NOT on (1)-(3)
6: mov [edi], eax ; depends on (5)
- On an in-order CPU (
z486): Instruction 1 misses cache and stalls the pipeline for many cycles. Even though[ecx]is sitting hot in the cache and the ALU is idle, instructions 4-6 cannot pass instruction 1. Chain A and Chain B execute strictly back-to-back. - Reordering alone isn't enough: Even if the CPU tried to run instruction 4 early, 4 writes to
EAX! OverwritingEAXbefore instruction 2 reads the old value corrupts Chain A, and having 1 finish after 4 would clobber Chain B'sEAX. Neither is a real data dependency - they are false dependencies caused purely by reusing the register nameEAX. - How register renaming unlocks ILP: As instructions pass through the Register Alias Table (RAT) in program order, the hardware quietly gives every write its own private physical storage slot in the Reorder Buffer (ROB), turning the two chains into:
1: ROB1 = load [ebx] ; misses cache -> waits in Reservation Station
2: ROB2 = ROB1 + 1 ; waits for ROB1
3: store [esi], ROB2 ; waits for ROB2
4: ROB4 = load [ecx] ; fresh slot ROB4! Hits cache immediately
5: ROB5 = ROB4 + edx ; executes right away while (1) is still waiting!
6: store [edi], ROB5 ; finishes early; waits to commit in order
With the false dependency on EAX gone, Chain B executes in parallel while Chain A is still waiting on memory - hiding latency and keeping multiple execution units busy at once.
Crucially, the ROB still commits registers and releases stores to memory in strict program order (1 → 2 → 3 → 4 → 5 → 6), so if instruction 1 triggers a page fault (#PF), the CPU simply discards ROB4-ROB6 as if Chain B never ran.
3× Performance Jump from z486 to z86
That ability to look dozens of instructions ahead, rename away false hazards, and overlap slow memory or FPU work with independent math is what drives the 3× per-MHz jump from z486 to z86 - and why an out-of-order core needs all that extra bookkeeping hardware:
| Dimension | z486 (MiSTer) | z86 (FULL profile) |
|---|---|---|
| Pipeline | 5-stage in-order | 3-wide OOO (4-1-1 decode) |
| Bookkeeping | None | 40-ROB, 16-RS, 5 ports, 3 WB |
| x87 FPU | 53-bit x87 | Full 80-bit (86b datapath) |
| Caches | L1 only | 16K/16K L1 + 512K URAM L2 |
| Footprint* | 21.9k CPU ALMs | 183.6k PC LUTs |
| Per-MHz IPC | 0.33 DMIPS/MHz | 1.03 DMIPS/MHz |
| DOOM / Quake | 31.3 / 6.8 FPS | 84.8 / 35.2 FPS (150 MHz) |
*Cyclone V uses 8-input ALMs (~1.5-2× Xilinx 6-LUTs); z86's 183.6k LUTs include ~16.2k LUTs of PC peripherals (167.4k CPU+L2 alone).
And x86 heaps extra complexity onto out-of-order execution compared with textbook RISC:
- Variable-length instructions (1-15 bytes) that cross 16-byte fetch boundaries and require parallel length decoding before steering.
- Partial-register updates (
AL/AH/AX/EAX) and splitEFLAGS(where instructions like shifts orINCmodify only a subset of condition flags) - naive renaming stalls constantly on partial writes. - An 8-deep x87 register stack (
ST(0)-ST(7)) whereFXCHswaps stack pointers rather than moving 80-bit data. - Complex CISC instructions, split stores, and Self-Modifying Code (SMC) that must remain strictly precise when a page fault (
#PF) or hardware interrupt hits mid-stream.
How Does x86 Out-of-Order Execution Work?
If you want the full stage-by-stage breakdown of the P6 pipeline, I have written up a detailed pipeline overview on the wiki at P6 Pipelines. Alongside Shen & Lipasti Chapter 7 and Intel's P6 patents, Martin Hinner's P6 Microcode Wiki is also an extraordinary resource documenting many of the concrete mechanisms and internal data structures (micro-op encodings, register aliases, MAR macros, and sequencer flows).
At a high level, z86 follows the same three-pipeline architecture - turning variable-length x86 instructions into fixed-format internal micro-ops (µops) so the out-of-order engine never has to see CISC encoding quirks:
- In-Order Front End: Fetches 16-byte blocks from the L1 instruction cache into a 48-byte stream buffer, finds instruction boundaries in parallel, and feeds a 4-1-1 decoder - one complex decoder (
D0, emitting up to 4 µops or handing off to the microcode ROM) alongside two simple 1-µop decoders (D1andD2). - Rename, Allocate & Out-of-Order Core: Up to 3 µops per cycle pass through the integer and floating-point Register Alias Tables (RAT / fRAT), receive a Reorder Buffer (ROB) slot, and enter the Reservation Station (RS) alongside load/store queues in the Memory Order Buffer (MOB). Ready µops dispatch out of order across 5 execution ports - with stores split into separate address and data ports - and broadcast results back over 3 writeback buses.
- In-Order Retirement: The retirement unit scans the oldest 3 ROB entries in program order, copies committed results into the Retirement Register File (RRF), checks for faults or branch mispredictions (rolling back speculative state cleanly), and releases committed stores (senior stores) to the L1D/L2 cache hierarchy.
Again, the core is fully open source, so anyone interested in the details is encouraged to read the RTL directly. For readability, many source files are annotated with the relevant US patent numbers, Shen & Lipasti section references, and pipeline stage numbers (such as 31, 92, etc.) - though out-of-order hardware is still inherently messy.
Where z86 Intentionally Adapts for UltraScale+ FPGAs
While inspired by P6's structure, z86 also exploits modern FPGA silicon primitives where they pay off:
- BRAM-backed branch prediction: Instead of P6's 512-entry Branch Target Buffer (BTB), z86 uses a 2,048-entry 4-way BRAM BTB, an 8,192-entry BRAM Gshare/Tournament predictor with checkpointed 11-bit global history, an 8-entry loop predictor, and a 16-entry return stack - costing almost no logic LUTs.
- Eliminating partial-register stalls: By tracking when the upper bytes of a register are known to be zero and merging partial writes directly in the ALU and load paths, z86 avoids most x86 partial-register stalls without emitting extra merge µops.
- DSP-accelerated division: Using three FPGA DSP blocks to retire 7 quotient bits per clock completes a 64-bit floating-point divide (
FDIV) in 13-14.5 cycles (2.6× faster than a real Pentium Pro), alongside faster square root (FSQRT) and integer divide (DIV, 3.3× faster). - URAM L2 Cache: A 512 KiB 4-way L2 cache built out of UltraScale+ UltraRAM (with 4 outstanding miss buffers and a hardware stride prefetcher) costs only 3,802 LUTs.
- 100% clean-room open-source microcode: Written from scratch in a unified symbolic microcode assembly (1,526 three-µop lines across 12 .asm files), paired with a Python-generated polynomial floating-point ROM (FPROM) achieving 100 MHz at worst-case slow-corner process, voltage, and temperature (108.1 / 111.8 MHz), both bitstreams run stably at 150 MHz at room temperature via
z86-run --clock 150(with a dynamic clock-rate register keeping the PIT, RTC, and Sound Blaster audio exact across frequencies).
Real-hardware DOS reference medians are from Phil's Ultimate VGA Benchmark Database; Linux benchmarks were compiled with GCC 14.3 (-O2 -march=pentiumpro -mfpmath=387 -mno-mmx -mno-sse) and executed live under 32-bit i686 Linux 6.18.54-z86 (128 MiB RAM).
Performance vs. Historical x86 CPUs & Linux
At 150 MHz, z86 LITE on the $250 KV260 sits between a Pentium 100 and a Pentium 133, while z86 FULL on ZCU104 runs close to a Pentium Pro 200 (matching or beating it on VGA-heavy 3DBench, PC Player, and DOOM, while Quake reflects pure CPU + x87 throughput):
| System / CPU | Clock | 3DBench 1.0c | PC Player (320×200) | DOOM demo3 (MAX) | Quake demo1 (320×200) |
|---|---|---|---|---|---|
| i486DX4-100 (median) | 100 MHz | 62.6 | 15.8 | 36.4 | 9.4 |
| z86 LITE (KV260) | 100 MHz | 66.1 | 24.4 | 37.0 | 13.0 |
| Intel Pentium 100 (median) | 100 MHz | 91.3 | 27.5 | 54.2 | 23.0 |
| z86 LITE (KV260) | 150 MHz | 99.4 | 36.4 | 54.8 | 19.3 |
| Intel Pentium 133 (median) | 133 MHz | 101.2 | 31.5 | 50.7 | 24.2 |
| z86 FULL (ZCU104) | 100 MHz | 99.8 | 40.0 | 57.7 | 23.8 |
| Intel Pentium 166 (median) | 166 MHz | 113.5 | 34.8 | 65.3 | 28.1 |
| z86 FULL (ZCU104) | 150 MHz | 150.0 | 59.8 | 84.8 | 35.2 |
| Intel Pentium Pro 200 (median) | 200 MHz | 144.0 | 60.1 | 71.2 | 41.9 |
Live 32-bit i686 Linux 6.18 benchmarks on ZCU104 (Z86_PROFILE_FULL, 128 MiB RAM):
| Benchmark | 100 MHz | 150 MHz | Per-MHz (150 MHz) |
|---|---|---|---|
| CoreMark 1.0 (-O2, CRC validated) | 253.79 | 383.34 | 2.56 / MHz |
| CoreMark-PRO Overall (9/9 workloads) | 65.31 | 98.04 | 0.65 / MHz |
| ↳ Integer (5 workloads) / FP (4 workloads) | 67.08 / 63.17 | 101.20 / 94.24 | 0.67 / 0.63 |
| Dhrystone 2.1 (DMIPS) | 101.8 | 153.8 | 1.03 DMIPS/MHz |
| Whetstone (Double x87, MWIPS) | 66.7 | 100.0 | 667 KWIPS/MHz |
| LINPACK (Double x87 N=200, MFLOPS) | 29.63 | 44.70 | 0.298 FLOP/clk |
Comparison Against Open-Source x86 FPGA Cores
Compared to prior open-source x86 FPGA cores, z86 delivers 3×-5× the per-MHz integer performance of in-order z486 and ao486, 4.0× the DOOM frame rate of ao486, and 4.3×-5.2× the Quake frame rate of z486 / z486 XL:
| Processor | Pipeline & FPU | Target FPGA | Area | Clock | DMIPS/MHz | 3DBench | DOOM demo3 | Quake demo1 |
|---|---|---|---|---|---|---|---|---|
| ao486 (MiSTer) | 486SX in-order, no FPU | Cyclone V | 15.2k CPU ALMs | 90 MHz | 0.19 | 43.6 | 21.0 FPS | - |
| z386 (MiSTer) | 80386 microcoded, no FPU | Cyclone V | 15.5k CPU ALMs | 85 MHz | 0.23 | 34.0 | 23.0 FPS | - |
| z486 (MiSTer) | 486DX in-order + 53-bit x87 | Cyclone V | 21.9k CPU ALMs | 85 MHz | 0.33 | 53.1 | 31.3 FPS | 6.8 FPS |
| z486 XL (KV260) | 486DX in-order + 53-bit x87 + L2 | UltraScale+ XCK26 | 50.3k PC LUTs | 100 MHz | - | 65.1 | 38.5 FPS | 8.1 FPS |
| TetriumSX (MiSTer) | High-IPC 486SX in-order, no FPU | Cyclone V | 18.5k CPU ALMs | 69 MHz | - | 100.1 | 37.5 FPS | - |
| z86 (LITE) | 1-dec/2-issue OOO IA-32 + 80-bit x87 | UltraScale+ XCK26 | 94.5k PC LUTs | 100 / 150 MHz | 0.52 | 66.1 / 99.4 | 37.0 / 54.8 FPS | 13.0 / 19.3 FPS |
| z86 (FULL) | 3-wide OOO IA-32 + 80-bit x87 | UltraScale+ XCZU7EV | 183.6k PC LUTs | 100 / 150 MHz | 1.03 | 99.8 / 150.0 | 57.7 / 84.8 FPS | 23.8 / 35.2 FPS |
How Does an OOO x86 Compare to Open-Source OOO RISC-V on FPGA?
It is also interesting to place z86 next to Linux-capable, hardware-FP open
Comments
No comments yet. Start the discussion.