DeiMOS: A Superoptimizer for the MOS 6502 That Exhaustively Finds the Fastest Possible Code

Available in: 中文
2026-04-07T13:27:39.944Z·2 min read
A superoptimizer goes beyond traditional compilers:

DeiMOS is a superoptimizer for the legendary MOS 6502 processor — the 8-bit microprocessor that powered the NES, Commodore 64, Apple II, and countless other classic systems. Unlike compilers that apply heuristic optimization rules, DeiMOS exhaustively searches all possible instruction sequences to find the provably shortest or fastest implementation.

What is a Superoptimizer?

A superoptimizer goes beyond traditional compilers:

The trade-off is speed: superoptimization is computationally expensive and scales poorly with program length.

Why the 6502?

The MOS 6502 (1975) is an ideal target for superoptimization:

  1. Simple instruction set — Limited opcodes and addressing modes reduce search space
  2. Historical significance — Powered the NES, C64, Apple II, Atari
  3. 8-bit architecture — Only 256 possible values per byte, enabling exhaustive verification
  4. No modern complexity — No branch prediction, extensive registers, or out-of-order execution

How DeiMOS Works

  1. Test specification — User provides input generator and output verifier functions
  2. Exhaustive search — Systematically generates and tests all possible instruction sequences
  3. Emulation-based verification — Each candidate is emulated against all 256 possible input values
  4. Smart pruning — Filters out CPU-jamming instructions and useless opcodes to reduce search space

Optimizations Over Naive Approach

The naive approach of generating all byte combinations (256^n for n-byte programs) is impossibly slow for even modest program lengths. DeiMOS uses several key optimizations:

Modern Relevance

While the 6502 is a retro platform, superoptimization research has practical implications:

↗ Original source · 2026-04-07T00:00:00.000Z
← Previous: Microsoft's New Copilot App for Windows 11 Is Really Just Microsoft Edge in DisguiseNext: Pion Handoff: Moving WebRTC Out of the Browser and Into Native Go Applications →
Comments0