Static recompilation · on the core of PCSX2

PlayStation 2 games as native applications

PS2Native translates a game's code to C++ ahead of time and compiles it for the machine it will run on. The console around that code is the core of PCSX2.

In development. There is nothing here for players yet.

01 · The idea

Compile the game. Keep the machine.

The aim is a standalone game: no emulator to install, nothing to set up. A PlayStation 2 game talks to the console's hardware directly, though, and rebuilding that hardware is where the first PS2Native stalled. So this one translates the game's code and leaves the hardware to the emulator that has already solved it.

Translated ahead of time

The game's code becomes C++ before the game ever runs: one C++ function for each function of the game, compiled by an ordinary compiler. The rule for a finished game is that no recompiler for PS2 code ships inside it.

On the core of PCSX2

Graphics, sound, storage and timing are PCSX2's, pinned to one version and unmodified. The translated code takes the place of PCSX2's recompilers for the console's two processors and its two vector units.

Your game, your BIOS

You provide your own game and your own BIOS dump. Neither is included here, and nothing generated from them is.

Stop reinventing what PCSX2 has already solved, while preserving the goal of genuine native recompilation.

From the project's brief

02 · How it works

From a disc to native code

Once, on your own machine, the game's executable goes through the recompiler and a C++ compiler. From then on the compiled code runs as the console's main processor, inside PCSX2's core.

When the game is built

  1. 01

    The game's executable

    From your own copy of the game. It is read where it is, and nothing is copied.

    1,003,452 instructions
    in the first game's

  2. 02

    ps2n-recomp

    Finds the functions and every place a block of code can begin, and writes one C++ function for each function of the game.

    22,668 functions,
    written in 1.8 s

  3. 03

    A C++ compiler

    Compiles the generated code like any other program, for the processor it will run on.

    152.4 MB of C++,
    built in 119 s

  4. 04

    Native code

    The game's own code as machine code, carrying fingerprints of the code it was made from and not the code.

    checked against memory
    before it runs

When the game runs

The machine is PCSX2's core

PCSX2 v2.9.170, a pinned and unmodified submodule. PS2Native owns no model of the hardware.

Both processors, vector units
The game's code, compiledRuns in the place of PCSX2's recompilers for the main processor, the second processor and both vector units.
The interpretersFor code no one saw at build time, and a few of the BIOS's instructions at boot.
  • GraphicsThe GS and its renderers
  • SoundSPU2
  • Memory and timeThe scheduler, DMA, timers
  • The second processor's hardwareIts timers, its DMA, its link to the main processor
  • StorageThe disc, memory cards
  • Input, and the restPads, the game database, patches

Code that no one saw coming

Some code does not exist until the game runs, and some is reached in ways no analysis can see. It is interpreted once, reported and captured, and the next build compiles it. Nothing is interpreted silently.

463down to0
places in Killzone's executable where a first build had to interpret, and where it had to after one rebuild. First 4,200 frames, 2026-11-11

  1. RunThe game runs. What was compiled runs compiled.
  2. ReportThe run lists every address it had to interpret from.
  3. CaptureThe reports of several runs go into one file.
  4. RebuildThe recompiler makes those addresses entries.

03 · What comes out

One loop, both sides

Seven instructions of one of the project's own test programs, and the C++ that the recompiler writes for them. Nothing here comes from a game.

bench_sumMIPS R5900eighths so far 65
  1. 001000CC 00025140 9 sll $t2, $v0, 5
  2. 001000D0 01425023 9 subu $t2, $t2, $v0
  3. 001000D4 01491021 9 addu $v0, $t2, $t1
  4. 001000D8 00481026 9 xor $v0, $v0, $t0
  5. 001000DC 25290001 9 addiu $t1, $t1, 1
  6. 001000E0 1528FFFA 11 bne $t1, $t0, 0x001000cc
  7. 001000E4 000258C2 9 srl $t3, $v0, 3

The loop of bench_sum in tests/programs/bench.s, as ps2n-recomp disasm prints it: address, instruction word, cost in eighths of a cycle, instruction.

Beside it, what ps2n-recomp generates for the loop. The comment it writes after each line, naming the instruction the line came from, is left out here.

bench.cppgenerated by ps2n-recomp 0.3.0
  1. L_001000CC:
  2. PS2N_BLOCK_START(10, 0x001000CCu);
  3. M_001000CC:
  4. SLL(T2, V0, 5);
  5. SUBU(T2, T2, V0);
  6. ADDU(V0, T2, T1);
  7. XOR(V0, V0, T0);
  8. ADDIU(T1, T1, 1);
  9. // 001000E0 bne $t1, $t0, 0x001000cc -> bench_sum+0xc
  10. {
  11. const bool taken = ru64(T1) != ru64(T0);
  12. SRL(T3, V0, 3);
  13. PS2N_BLOCK_END(acc, 65u, taken ? 0x001000CCu : 0x001000E8u);
  14. if (taken)
  15. {
  16. goto L_001000CC;
  17. }
  18. }

Every label is a way in

A block of code can begin at any label: after a call returns, or when an interrupt hands control back. L_ is where one begins, and there the runtime checks that the code in memory is still the code that was compiled. M_ is where a block that began earlier runs on through.

The delay slot, as on the console

The branch is decided first. The instruction after it runs either way, and only then does the branch take effect.

Time, in eighths of a cycle

Nine for most instructions, eleven for the branch: 65 for this block. They are added where PCSX2's recompiler would add them, and that is where the rest of the machine is given its turn.

04 · The same run

Not close to the stock run. The same run.

Again and again, PCSX2 lets the console's second processor catch up with the main one. At each of those moments a run can be written down: where the main processor is, its cycle count, hashes of its registers. Two runs with the same record took the same path through the program at the same times.

38,478,822

such moments in the first 4,200 frames of Killzone. The compiled run and the run under stock PCSX2 are the same at every one. Their records, 3 GB each, are the same file byte for byte.

  • 4,199frames fingerprinted, and the same picture at every one of them.
  • 47,705,744event tests at which the compiled run is also the interpreted run.
  • 59 of 63test programs are the stock run too, at every such moment. The other four are listed, each with its cause.

Measured on 2026-11-11, on Windows

compared 38,478,822 different 0 An illustration. The numbers are measured.

Those 4,200 frames are the copyright screen, the developer's logo, a memory card prompt and the intro film. A longer run goes through the menus into the first level and plays there for three and a half minutes: the two are at the same place at the same cycle count at every one of its 93,221,937 moments, the second processor's place and registers compared too since 2026-11-14, and they show the same picture at each of the 1,750 frames compared, one in every ten. Where PS2Native follows the console on purpose, because a recording shows PCSX2's recompiler wrong, a run does differ from the stock run, and each such place is listed with its cause.

05 · Measured

Numbers as measured, whatever they are

Every number on this page came from a run on the date beside it. That goes for the ones that are not flattering as well.

Compiled ahead of time

1,003,452

instructions of Killzone's boot executable, in 22,668 functions.

2026-11-11

Of them, still interpreted

0

in the first 4,200 frames. A first build had to interpret 5,079; one rebuild compiled them.

2026-11-11

Interpreted in all

51

instructions in those frames, at boot, since the BIOS is compiled too. Before, the BIOS's code was 1.11% of the main processor's cycles there.

2026-11-12

Tests that pass

453

and 2 unit test programs of 42 cases, in 153 s. A test that differs from a console recording is listed only once its cause is known.

2026-11-11

Programs that match the console

40of 55

Stock PCSX2: 39 with its recompilers, 38 with its interpreters. On no line of them is stock PCSX2 right and PS2Native wrong.

2026-11-11

Instructions checked one by one

204

against both of PCSX2's implementations: 4,077,475 cases against its recompiler and 36,976,118 against its interpreter, with no difference outside the documented ones.

2026-11-11

Speed so far: a little slower

The first 4,200 frames of Killzone, in seconds. Shorter is faster.

Wall-clock time of the first 4,200 frames of Killzone
RunSeconds
With PCSX2's software renderer
Stock
22.7 s22.7 s stock PCSX2, software renderer. Three runs: 22.7 s, 22.6 s and 22.8 s
PS2Native
23.4 s23.4 s PS2Native, software renderer. Three runs: 23.4 s, 23.4 s and 23.3 s. On 2026-11-11, 25.7 s
With nothing drawn
Stock
11.3 s11.3 s stock PCSX2, nothing drawn. Three runs: 11.3 s, 11.3 s and 11.2 s
PS2Native
12.3 s12.3 s PS2Native, nothing drawn. Three runs: 12.3 s, 12.2 s and 12.3 s. On 2026-11-11, 15.1 s

These frames are logos, a prompt and a film, measured again on 2026-11-13: 1.03 and 1.09 times stock PCSX2's time, where on 2026-11-11 they took 1.12 and 1.35. The run into the first level took 1.35 times stock PCSX2's time then, and takes 0.97 times now, its three and a half minutes of play 0.95 times: seven changes to how the code is generated, the VU0 instructions and the BIOS's code compiled, profile-guided optimization, loops that have reached a fixed point skipped, the COP2 instructions and calls through a register made by compiled code itself, the FPU's arithmetic done in SSE registers, and the vector units' programs and the second processor's code compiled ahead of time, each measured. 2026-11-14

Six loops that never leave the processor

Time of the compiled code relative to PCSX2's recompiler. Below 1.00 is faster.

Time of six CPU-bound workloads, compiled ahead of time, relative to PCSX2's recompiler
WorkloadTime relative to PCSX2's recompiler
sum
0.940.94 register arithmetic: 64.7 ms against 68.9 ms
call
1.011.01 seven million calls: 29.4 ms against 29.1 ms. In the proof of concept, 1.15
fpu
1.011.01 floating point: 50.5 ms against 49.8 ms. From 0.90 to 1.03 over the builds of the night
mem
1.061.06 word loads and stores: 19.7 ms against 18.6 ms
jump
1.071.07 a jump through a table: 52.0 ms against 48.8 ms. In the proof of concept, 1.47
mmi
1.241.24 128-bit arithmetic: 10.2 ms against 8.2 ms. 1.43 earlier the same night

Measured again, as in the proof of concept: without profile-guided optimization, whose training is the game's. The jump through a table and the calls, 1.47 and 1.15 then, are now about as fast as PCSX2's recompiler. The 128-bit arithmetic, at 1.43 when measured again, is at 1.24 since its loads and stores are made on the locals; its parallel instructions still work on the registers in memory, where PCSX2's recompiler keeps them in host registers. A loop moves by a few percent from one build to the next with nothing in it changed. 2026-11-13

06 · What is static

What is translated today, and what is not yet

The rule is that no recompiler for PS2 code ships in a finished game. Today that holds for everything Killzone runs as far as its first level: the game's own code, the BIOS's, the programs on the vector units and the second processor's modules. Code no build has seen is interpreted, and listed.

1 · MAIN PROCESSOR

The game's code

EE

Static

Translated ahead of time. In the first 4,200 frames of Killzone not one instruction of the executable is interpreted.

2 · MAIN PROCESSOR

The BIOS kernel

EE

Static

System calls, interrupts and threads are the BIOS's own code, translated ahead of time on your machine from your own dump. Of it, 51 instructions at boot are interpreted. In a finished game it will be a file of its own beside the game.

3 · VECTOR UNITS

Micro programs

VU0, VU1

Static

Translated ahead of time, each block by what it does, wherever the game writes it. In the run into Killzone's first level not one block of them is interpreted, and none runs on PCSX2's recompiler.

4 · SECOND PROCESSOR

The IOP's modules

IOP

Static

Translated ahead of time, block by block, each found by its instructions wherever the IOP's kernel loads it. In the run into Killzone's first level not one block of them is interpreted, and none runs on PCSX2's recompiler.

The hardware stays PCSX2's

Graphics, sound, DMA, timers, the disc, pads and memory cards are not rebuilt. That is the part the project does not reinvent.

No finished game on a stand-in

Until PS2Native had translators of its own for them, PCSX2's recompilers for the vector units and the second processor stood in, labeled as that; its recompiler for the main processor never did. None is in use now. Packaging does not exist yet: when it does, it is to refuse a release that uses one.

08 · Roadmap

Prove the architecture before building the application

Five phases. Each one ends with a stop, and the next begins only with the maintainer's approval.

  1. Phase 1Done · 2026-11-10

    Feasibility assessment

    The first PS2Native, PCSX2 and three other recompilation projects, read at the source. The recommendation: statically recompiled code as the processors, PCSX2's core as the machine, a BIOS supplied by the user.

  2. Phase 2Done on Windows · 2026-11-11

    Proof of concept

    Every one of 63 test programs runs with its own code compiled ahead of time, the same as its interpreted run at every event test. The Linux step is deferred by the maintainer: its scripts are written and have never been run.

  3. Phase 3Done · 2026-11-16

    The first real game: Killzone

    The European release, from the maintainer's own copy, and then a second game, Agent Under Fire. Nothing of either game is in the repository, and nothing generated from them. The phase's report: docs/phase3-report.md.

    • G0BaselineDone as far as the intro film
    • G1The interpreter as referenceDone for the first 4,200 frames
    • G2The game's code compiledDone
    • G3The compiled gameDone for the first 4,200 frames
    • G4Further into the gameDone as far as the first level: by script, and played by the maintainer in a window, with sound and a controller, on Windows
    • G5Measurement and reportDone as far as the first level: 1.35 times stock PCSX2's time, all of it in the game's own code
    • G6SpeedDone: the run into the first level takes 1.21 to 1.23 times stock PCSX2's time, from 1.35, and is still the stock run
    • G7VU0's instructionsDone: the game's VU0 instructions are PS2Native's own, the same as PCSX2's recompiler in every case the self-test tried, and the run into the first level is still the stock run
    • G8The BIOS's EE codeDone: the BIOS's code that runs on the main processor is compiled ahead of time from the user's own dump, but for 51 instructions at boot; the run into the first level takes 1.18 times stock PCSX2's time and is still the stock run
    • G9VU0's instructions in compiled codeDone: compiled code carries them out itself where their block lets it; the run into the first level takes 1.19 times stock PCSX2's time, from 1.21, and is still the stock run
    • G10PerformanceDone: profile-guided optimization, loops that have reached a fixed point no longer run their identical times round, compiled code carries out the COP2 instructions and its calls through a register itself, the way loads and stores seldom take is short, and the FPU's arithmetic is done in SSE registers; the run into the first level takes 1.01 times stock PCSX2's time, from 1.18, its play as long as stock PCSX2's, and is still the stock run
    • G11The vector units' programsDone: the programs the game runs on its two vector units are compiled ahead of time, each block by what it does, wherever the game writes it: 589 different blocks, where PCSX2's recompiler makes 6,088 programs. What a build has not seen is interpreted, which in the run into the first level is nothing. 20,000 random programs give PCSX2's results; the run takes 0.97 times stock PCSX2's time, from 1.01, its play 0.95 times, and is still the stock run
    • G12The second processor's codeDone: the second processor's modules, the BIOS's and the game's, are compiled ahead of time, each block found by its instructions wherever they are loaded: 8,023 blocks. In the run into the first level none is interpreted, and none runs on PCSX2's recompiler, the last that stood in. 4,000 random programs give PCSX2's results; the run is still the stock run, the second processor's registers now compared too, in the time it took before: 0.97 times stock PCSX2's, its play 0.95 times
    • G13Playing onEnded with the phase: the maintainer played Killzone into its first level and Agent Under Fire's first five missions, further than the scripts reach. Each session was written down, what it had to interpret compiled into the next build, and run again against stock PCSX2: still the stock run. The first met 26 blocks of micro code and 791 of the second processor's code that no build had seen, most of them in the memory card's modules
    • G14How a game is shownDone: by default on Vulkan, drawn at three times the console's resolution into a picture of 1920 by 1080, full screen where a window that size does not fit
    • G15WidescreenDone: a game's widescreen patch, from the PCSX2 installed on the computer, applied by default: Killzone in 16:9, drawn wide by the game itself
    • G16Frame rateDone: a game's frame-rate patch applied by default too. In its first level Killzone shows 41 new pictures a second where it showed 25, keeping the console's pace in the window; the code the patch changes is compiled ahead of time like the rest, and with the patch the compiled game takes the time stock PCSX2 takes with it (1.00 times)
    • G17EE overclockDone: where a patch asks for PCSX2's main-processor overclock, it is applied with it, and time is counted as PCSX2 counts it at that setting. With it Killzone shows 46 new pictures a second in its first level where 41; the compiled game is still the stock run, and takes the time stock PCSX2 takes with the same setting (1.00 times)
    • G18A second gameDone: Agent Under Fire, a game made of four programs that load one another without the console's loader, all four compiled ahead of time, the one in memory told by its code. Into its first mission nothing of it is interpreted, it is still the stock run, and it keeps the console's pace in the window. The maintainer then played its first five missions. A wait loop in the fourth, whose blocks check their own code at every run, took 7.6 times stock PCSX2's time; since compiled code makes that check itself it takes 1.8, 0.27 of the console's time
  4. Phase 4Begun · 2026-11-16

    The application

    A wizard that takes a game and gives back a native application. Every setting is fixed when the game is built, and the result shows no emulator's interface. The maintainer decided its design on 2026-11-16: the wizard brings its own compiler, so a game is compiled on the user's own computer with nothing to install, into a module that a ready-made runtime loads, and a packaged game is a folder. The first step, measured the same day: a game's compiled code as a module of its own costs no time that shows. Agent Under Fire took as long as with its code built into the runtime, and every test passed. The second, on 2026-11-17: the compiled code now needs nothing but a compiler and PS2Native's own headers, no part of PCSX2's source and no system library, and comes in four modules (the game's, the BIOS's, the vector units' and the I/O processor's). Every test passed, and Agent Under Fire stayed the same run as stock PCSX2's at every point compared. The third, the same day: the compiler the wizard brings is LLVM's own, and with it a folder of 254 MB compiles Agent Under Fire from its disc image. On a Windows 10 laptop with nothing else installed it compiled the game in about 8 minutes into the same code as the development build's, and the game played there at close to the console's pace. The fourth, the same day: a game is now a folder that plays it, started from a program named after the game, with no console window beside it. Killzone and Agent Under Fire played from their folders at the console's pace, and the sessions recorded on the development build, the maintainer's own among them, played back from the folders were the same at every point compared. The fifth, the wizard itself, was done on 2026-11-18: it goes through all of PCSX2's settings for a game, PCSX2's own pages, and makes a game from its disc image into a folder that plays it, every default accepted, in about five and a half minutes for Agent Under Fire. On 2026-11-18 the maintainer made a third game with it, Gran Turismo 3, which loads its code from its own data: its first session ran that code interpreted, slower than the console, and once the game was made again from what that session wrote down, it played at the console's pace. The sixth met its criterion the same day: a game's folder now carries its own compiler, and when a session ends the game compiles what it met for the first time by itself, in the background, with a notification when it begins and another when it is done; its next start has it. While a game runs code it meets for the first time, a notice over its picture says so. The maintainer then played a fourth game made with the wizard, Jak and Daxter, which also runs code it loads from its data: 39 minutes and then 23 at the console's pace, 0.17% and then 0.04% of the main processor's work interpreted, what each session met for the first time compiled about a minute after it. The eighth step, the folder others can be given, was begun the same day: a game made from its disc image in any format PCSX2 plays, PCSX2's patches fetched at the user's word where PCSX2 is not installed, settings that PS2Native fixes refused when edited by hand, and the licence of everything in the folder. With it the wizard made a fifth game, Silent Hill 3, from a .chd image, as on a computer without PCSX2, in two and a half minutes. The design: docs/phase4-proposal.md; what was measured: docs/app-log.md.

    1. Choose the game
    2. Give the BIOS
    3. Accept the defaults
    4. Recompile
    5. Package
  5. Phase 5Later

    Maintenance

    Automated regression tests, compatibility reports, and checks against each new version of PCSX2 before it is taken up.

Required

Windows x64

Built and run. Everything measured on this page was measured here.

Required

Linux x64

Its scripts are written and have never been run. Nothing is known to work there yet.

Optional

macOS, Android, iOS

Bounded by what PCSX2 supports. Nothing is built or tested for them.

Follow the work

PS2Native is free software and is being built in the open. There is nothing to download yet. There is a great deal to read.