JIT-8

A CHIP-8 just-in-time compiler for Linux x86-64


Description

JIT-8 is a CHIP-8 just-in-time compiler that targets x86-64 on Linux. Instead of interpreting instructions one by one, it compiles executed code paths directly.

Motivation

This project explores how far a compact virtual machine can be pushed with JIT compilation. CHIP-8 is small enough to experiment quickly while still exposing real trade-offs around code generation, invalidation, and quirks handling.

Highlights

  • JIT-based execution model (no main interpreter loop for executed instructions)
  • Written in C++ with CMake build setup
  • Uses ASMJIT for code generation
  • Uses SFML for graphics output
  • Includes compatibility flags for common CHIP-8 quirk behavior

Architecture Overview

The project is split into a few core parts:

  • Frontend for display/input handling
  • Parser that identifies basic blocks and collects register usage
  • JIT compiler that emits x86-64 code for blocks
  • Dispatcher that handles control flow and invalidates dirty blocks when self-modifying behavior appears

Performance

According to the repository benchmarks, JIT-8 can be around 10x faster than the referenced interpreter in favorable cases. Programs with frequent self-modifying behavior may perform worse due to recompilation overhead.

Limitations and Trade-Offs

  • Performance depends on ROM behavior and block stability
  • Heavy self-modifying patterns can reduce or remove JIT speedups
  • Correct quirk handling is important for compatibility across different games

Build

mkdir build
cd build
cmake ..
make -j8

Run

./jit8 <-t slowdown in ns> <-s shift quirks> <-i I register quirks> filepath_rom

Example:

./jit8 -t 500000 -s -i ../rom/c8games/BLINKY

Repository

Source code and details are available on GitHub:

JIT-8 on GitHub

Presentation

For more details look at the following presentation!