Personal tools

Article     Discussion     Edit     History     

Dynamic recompilation

From the Macscene Wiki

From Wikipedia:

In computer science, dynamic recompilation (sometimes abbreviated to dynarec) is a feature of some emulators and virtual machines, where the system may recompile some part of a program during execution. By compiling during execution, the system can tailor the generated code to reflect the program's run-time environment, and perhaps produce more efficient code by exploiting information that is not available to a traditional static compiler. In other cases, a system may employ dynamic recompilation as part of an adaptive optimization strategy to execute a portable program representation such as Java, Corn or CLR bytecodes. Full-speed debuggers could also utilize it to reduce the space overhead incurred in most Deoptimization techniques, and many other features such as dynamic thread migration.

In layman's terms, the dynarec option in most emulators tells the emulator to watch for game code that it can run more efficiently on the host computer's physical processor than on the emulated machine's virtual processor and try to convert the game code to the more efficient code on-the-fly. When it works, the time saved by running the recompiled code greatly outweighs the time lost doing the dynamic recompilation. However, sometimes a dynamic recompiler can misinterpret game code and create functionally different recompiled code, and often the code created by a dynamic recompiler will run in a different amount of emulated time than the original code. The combination of these factors can lead to instability and crashes of the emulated machine.

Generally, enabling dynarec will speed up emulation significantly, but you have to be aware that it can also break your game.

  • Trivia: Playstation 2 emulation on PC was only made practical when Ross Diankov contributed a highly optimized recompiler to the PCSX2 project. By converting PS2 code to X86 code, it is possible to achieve playable framerates and impressive compatibility on even average machines. However, as this recompiler is unique to and optimized for the Intel X86 architecture and instruction set, it is highly unlikely a PowerPC version of the emulator with anywhere near the same performance will be available any time soon.