HeadlinesBriefing favicon HeadlinesBriefing.com

DeiMOS superoptimizes classic 6502 code

Hacker News •
×

DeiMOS, a new superoptimizer targeting the classic MOS 6502 CPU, attempts to generate the shortest possible machine code for a given task. By exhaustively exploring instruction sequences, it can produce provably optimal snippets that traditional compilers miss. The 6502’s tiny 8‑bit architecture and limited opcode set keep the search space tractable enough for exhaustive analysis. Developers can supply custom test harnesses.

The tool works by letting users supply two functions: one that creates an initial CPU state and another that validates the final state. For each candidate program, DeiMOS runs the test suite across every possible 8‑bit input—at most 256 cases—discarding failures instantly. Early‑exit heuristics prune billions of dead‑end programs, turning a raw 4 billion‑combination space into a manageable workload quickly today.

To keep all cores busy, DeiMOS assigns each worker a non‑crashing prefix and lets it enumerate all suffixes, communicating via lightweight TCP processes. Users can further restrict generated opcodes, eliminating jumps, stack accesses, or decimal mode to focus the search. Checkpointable emulation caches CPU state only for permitted memory ranges, cutting overhead and delivering optimal 4‑byte programs in seconds.