| 1 | |
| 2 | # Lightrec |
| 3 | |
| 4 | Lightrec is a MIPS-to-everything dynamic recompiler for |
| 5 | PlayStation emulators, using |
| 6 | [GNU Lightning](https://www.gnu.org/software/lightning/) |
| 7 | as the code emitter. |
| 8 | |
| 9 | As such, in theory it should be able to run on every CPU that Lightning |
| 10 | can generate code for; including, but not limited to, __x86__, __x86_64__, |
| 11 | __ARM__, __Aarch64__, __MIPS__, __PowerPC__ and __Risc-V__. |
| 12 | |
| 13 | ## Features |
| 14 | |
| 15 | * __High-level optimizations__. The MIPS code is first pre-compiled into |
| 16 | a form of Intermediate Representation (IR). |
| 17 | Basically, just a single-linked list of structures representing the |
| 18 | instructions. On that list, several optimization steps are performed: |
| 19 | instructions are modified, reordered, tagged; new meta-instructions |
| 20 | can also be added. |
| 21 | |
| 22 | * __Lazy compilation__. |
| 23 | If Lightrec detects a block of code that would be very hard to |
| 24 | compile properly (e.g. a branch with a branch in its delay slot), |
| 25 | the block is marked as not compilable, and will always be emulated |
| 26 | with the built-in interpreter. This allows to keep the code emitter |
| 27 | simple and easy to understand. |
| 28 | |
| 29 | * __Run-time profiling__. |
| 30 | The generated code will gather run-time information about the I/O access |
| 31 | (whether they hit RAM, or hardware registers). |
| 32 | The code generator will then use this information to generate direct |
| 33 | read/writes to the emulated memories, instead of jumping to C for |
| 34 | every call. |
| 35 | |
| 36 | * __Threaded compilation__. |
| 37 | When entering a loading zone, where a lot of code has to be compiled, |
| 38 | we don't want the compilation process to slow down the pace of emulation. |
| 39 | To avoid that, the code compiler optionally runs on a thread, and the |
| 40 | main loop will emulate the blocks that have not been compiled yet with |
| 41 | the interpreter. This helps to drastically reduce the stutter that |
| 42 | typically happens when a lot of new code is run. |
| 43 | |
| 44 | ## Emulators |
| 45 | |
| 46 | Lightrec has been ported to the following emulators: |
| 47 | |
| 48 | * [__PCSX-ReArmed__ (libretro)](https://github.com/libretro/pcsx_rearmed) |
| 49 | |
| 50 | * [__pcsx4all__ (my own fork)](https://github.com/pcercuei/pcsx4all) |
| 51 | |
| 52 | * [__Beetle__ (libretro)](https://github.com/libretro/beetle-psx-libretro/) |
| 53 | |
| 54 | * [__CubeSX/WiiSX__](https://github.com/emukidid/pcsxgc/) |
| 55 | |
| 56 | [![Star History Chart](https://api.star-history.com/svg?repos=pcercuei/lightrec&type=Date)](https://star-history.com/#pcercuei/lightrec&Date) |