Editing Dynamic recompilation

Jump to navigation Jump to search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 1: Line 1:
'''Dynamic recompilation''' (sometimes abbreviated to '''dynarec''' or '''DRC''') 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 potentially produce more efficient code by exploiting information that is not available to a traditional static compiler.
+
In [[computer science]], '''dynamic recompilation''' (sometimes abbreviated to '''dynarec''' or the [[pseudo-acronym]] '''DRC''') is a feature of some [[emulator]]s and [[virtual machine]]s, where the system may [[Compiler|recompile]] some part of a [[Computer program|program]] ''during execution''. By compiling during execution, the system can tailor the generated code to reflect the program's run-time environment, and potentially produce more efficient [[code]] by exploiting information that is not available to a traditional static [[compiler]].
 
 
{{Main|wikipedia:Dynamic recompilation}}
 
  
 
==Uses==
 
==Uses==
Most dynamic recompilers are used to convert machine code between architectures at runtime. This is a task often needed in the emulation of legacy gaming platforms. 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 or .NET Common Language Runtime bytecodes. Full-speed debuggers also utilize dynarec to reduce the space overhead incurred in most deoptimization techniques, and other features such as dynamic thread migration.
+
Most dynamic recompilers are used to convert machine code between architectures at runtime. This is a task often needed in the emulation of legacy gaming platforms. 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 (programming language)|Java]] or .NET [[Common Language Runtime]] bytecodes. Full-speed debuggers also utilize dynarec to reduce the space overhead incurred in most [[deoptimization]] techniques, and other features such as dynamic [[thread migration]].
  
 
==Tasks==
 
==Tasks==
Line 15: Line 13:
 
* Updating of elapsed cycle counts on platforms with cycle count registers
 
* Updating of elapsed cycle counts on platforms with cycle count registers
 
* Management of interrupt checking
 
* Management of interrupt checking
* Providing an interface to virtualized support hardware for example a GPU
+
* Providing an interface to virtualized support hardware for example a [[GPU]]
 
* Optimizing higher level code structures to run efficiently on the target hardware (see below)
 
* Optimizing higher level code structures to run efficiently on the target hardware (see below)
  
 
==Example==
 
==Example==
Suppose a program is being run in an emulator and needs to copy a null-terminated string. The program is compiled originally for a very simple processor. This processor can only copy a byte at a time, and must do so by first reading it from the source string into a register, then writing it from that register into the destination string. The original program might look something like this:
+
Suppose a program is being run in an emulator and needs to copy a null-terminated [[character string|string]]. The program is compiled originally for a very simple processor. This processor can only copy a [[byte]] at a time, and must do so by first reading it from the source string into a [[processor register|register]], then writing it from that register into the destination string. The original program might look something like this:
  
beginning:
+
<source lang=asm>
 +
beginning:
 
     mov A,[first string pointer]    ; Put location of first character of source string
 
     mov A,[first string pointer]    ; Put location of first character of source string
 
                                     ; in register A
 
                                     ; in register A
 
     mov B,[second string pointer]  ; Put location of first character of destination string
 
     mov B,[second string pointer]  ; Put location of first character of destination string
 
                                     ; in register B
 
                                     ; in register B
loop:
+
loop:
 
     mov C,[A]            ; Copy byte at address in register A to register C
 
     mov C,[A]            ; Copy byte at address in register A to register C
 
     mov [B],C            ; Copy byte in register C to the address in register B
 
     mov [B],C            ; Copy byte in register C to the address in register B
Line 36: Line 35:
 
     jnz loop            ; If it wasn't 0 then we have more to copy, so go back
 
     jnz loop            ; If it wasn't 0 then we have more to copy, so go back
 
                         ; and copy the next byte
 
                         ; and copy the next byte
end:                   ; If we didn't loop then we must have finished,
+
end:                     ; If we didn't loop then we must have finished,
                         ; so carry on with something else.
+
                         ; so carry on with something else.</source>
  
 
The emulator might be running on a processor which is similar, but extremely good at copying strings, and the emulator knows it can take advantage of this.
 
The emulator might be running on a processor which is similar, but extremely good at copying strings, and the emulator knows it can take advantage of this.
Line 47: Line 46:
 
Our new recompiled code might look something like this:
 
Our new recompiled code might look something like this:
  
beginning:
+
<source lang=asm>beginning:
 
     mov A,[first string pointer]    ; Put location of first character of source string
 
     mov A,[first string pointer]    ; Put location of first character of source string
 
                                     ; in register A
 
                                     ; in register A
 
     mov B,[second string pointer]  ; Put location of first character of destination string
 
     mov B,[second string pointer]  ; Put location of first character of destination string
 
                                     ; in register B
 
                                     ; in register B
loop:
+
loop:
 
     movs [B],[A]            ; Copy 16 bytes at address in register A to address
 
     movs [B],[A]            ; Copy 16 bytes at address in register A to address
 
                             ; in register B, then increment A and B by 16
 
                             ; in register B, then increment A and B by 16
 
     jnz loop                ; If the zero flag isn't set then we haven't reached
 
     jnz loop                ; If the zero flag isn't set then we haven't reached
 
                             ; the end of the string, so go back and copy some more.
 
                             ; the end of the string, so go back and copy some more.
end:                       ; If we didn't loop then we must have finished,
+
end:                       ; If we didn't loop then we must have finished,
                             ; so carry on with something else.
+
                             ; so carry on with something else.</source>
  
There is an immediate speed benefit simply because the processor doesn't have to load so many instructions to do the same task, but also because the movs instruction is likely to be optimized by the processor designer to be more efficient than the sequence used in the first example. (For example, it may make better use of parallel execution in the processor to increment A and B while it is still copying bytes).
+
There is an immediate speed benefit simply because the processor doesn't have to load so many instructions to do the same task, but also because the movs instruction is likely to be optimized by the processor designer to be more efficient than the sequence used in the first example. (For example, it may make better use of [[Parallel computing|parallel execution]] in the processor to increment A and B while it is still copying bytes).
  
 
===Gaming===
 
===Gaming===
 
*[[MAME]] uses dynamic recompilation in its CPU emulators for MIPS, SuperH, PowerPC and even the Voodoo graphics processing units.
 
*[[MAME]] uses dynamic recompilation in its CPU emulators for MIPS, SuperH, PowerPC and even the Voodoo graphics processing units.
*[[1964]], an open-source [[Nintendo 64 emulators|Nintendo 64 emulator]] for [[wikipedia:x86|x86]] hardware.
+
*[[1964 (emulator)|1964]], a [[Nintendo 64]] emulator for x86 hardware.
*Wii64, a [[Nintendo 64 emulators|Nintendo 64 emulator]] for the Nintendo Wii.
+
*Wii64, a [[Nintendo 64]] emulator for the Wii.
 
*WiiSX, a Sony PlayStation emulator for the Nintendo Wii.
 
*WiiSX, a Sony PlayStation emulator for the Nintendo Wii.
*[[Mupen64Plus]], an open-source, multi-platform, plugin-based Nintendo 64 emulator.<ref>[http://pandorawiki.org/Mupen64plus_dynamic_recompiler Mupen64Plus]</ref>
+
*[[Mupen64Plus]], a multi-platform Nintendo 64 emulator.<ref>[http://pandorawiki.org/Mupen64plus_dynamic_recompiler Mupen64Plus]</ref>
*[[Yabause]], an open-source multi-platform [[Sega Saturn emulators|Sega Saturn emulator]].<ref>[http://wiki.yabause.org/index.php5?title=SH2_dynamic_recompiler SH2]</ref>
+
*[[Yabause]], a multi-platform [[Sega Saturn|Saturn]] emulator.<ref>[http://wiki.yabause.org/index.php5?title=SH2_dynamic_recompiler SH2]</ref>
*The backwards compatibility functionality of the [[Xbox 360 emulators|Xbox 360]] (i.e. running games written for the original [[Xbox emulators|Xbox]]) is widely assumed to use dynamic recompilation.
+
*The backwards compatibility functionality of the [[Xbox 360]] (i.e. running games written for the original [[Xbox (console)|Xbox]]) is widely assumed to use dynamic recompilation.
*[[PPSSPP]], an open-source, multi-platform [[PlayStation Portable emulators|Sony PlayStation Portable emulator]]. Recompilers for both x86 and ARM.
+
*[[PPSSPP]], a [[Sony]] [[PlayStation Portable]] emulator. Recompilers for both x86 and ARM.
*PSEmu Pro, a [[PlayStation emulators|Sony PlayStation emulator]].
+
*[[PSEmu Pro]], a [[Sony]] [[PlayStation]] emulator.
*[[UltraHLE]], the first [[Nintendo 64 emulators|Nintendo 64 emulators]] emulator to fully run commercial games.
+
*[[Ultrahle]], the first [[Nintendo 64]] emulator to fully run commercial games.
*[[PCSX2]],<ref>[http://www.pcsx2.net PCSX2]</ref> an open-source, plugin-based [[PlayStation 2 emulators|Sony PlayStation 2 emulator]], has a recompiler called "microVU", the successor of "SuperVU".
+
*[[PCSX2]],<ref>[http://www.pcsx2.net PCSX 2]</ref> a [[Sony]] [[PlayStation 2]] emulator, has a recompiler called "microVU", the successor of "SuperVU".
*[[Dolphin]], an open-source [[GameCube emulators|Nintendo GameCube]] and [[Wii emulators|Wii emulator]], has a dynarec option.
+
*[[Dolphin (emulator)|Dolphin]], a [[Nintendo GameCube]] and [[Wii]] emulator, has a dynarec option.
*GCEmu,<ref>[http://sourceforge.net/projects/gcemu-project GCEmu]</ref> a [[GameCube emulators|Nintendo GameCube emulator]].
+
*GCemu,<ref>[http://sourceforge.net/projects/gcemu-project GCemu]</ref> a [[Nintendo GameCube]] emulator.
*[[nullDC]], an open-source [[Sega Dreamcast emulators|Sega Dreamcast]] and [[Sega NAOMI and variants|NAOMI emulator]] for [[wikipedia:x86|x86]].
+
*[[NullDC]], a [[Sega]] [[Dreamcast]] emulator for x86.
*GEM,<ref>{{cite web|url=http://gem.tni.nl/ |title=Gameboy Emulator for MSX &#124; The New Image |publisher=GEM |date= |accessdate=2014-01-12}}</ref> a [[Game Boy/Game Boy Color emulators|Nintendo Game Boy/Color]] emulator for [[MSX emulators|MSX]] uses an optimizing dynamic recompiler.
+
*GEM,<ref>{{cite web|url=http://gem.tni.nl/ |title=Gameboy Emulator for MSX &#124; The New Image |publisher=GEM |date= |accessdate=2014-01-12}}</ref> a [[Game Boy|Nintendo Game Boy]] emulator for [[MSX]] uses an optimizing dynamic recompiler.
*[[DeSmuME]],<ref>[http://desmume.org/2013/04/30/desmume-0-9-9-released/ DeSmuME v0.9.9]</ref> an open-source [[Nintendo DS emulators|Nintendo DS emulator]], has a dynarec option.
+
*[[DeSmuME]],<ref>[http://desmume.org/2013/04/30/desmume-0-9-9-released/ DeSmuME v0.9.9]</ref> a [[Nintendo DS]] emulator, has a dynarec option.
*Soywiz's Psp,<ref>{{cite web|author=Publicado por Carlos Ballesteros Velasco |url=http://pspemu.soywiz.com/2013/07/release-soywizs-psp-emulator-2013-07-28.html |title=Soywiz's PSP Emulator: Release : Soywiz's Psp Emulator 2013-07-28 (r525) |publisher=Pspemu.soywiz.com |date=2013-07-28 |accessdate=2014-01-12}}</ref> a [[PlayStation Portable emulators|Sony PlayStation Portable emulator]], has a dynarec option.
+
*Soywiz's Psp,<ref>{{cite web|author=Publicado por Carlos Ballesteros Velasco |url=http://pspemu.soywiz.com/2013/07/release-soywizs-psp-emulator-2013-07-28.html |title=Soywiz's PSP Emulator: Release : Soywiz's Psp Emulator 2013-07-28 (r525) |publisher=Pspemu.soywiz.com |date=2013-07-28 |accessdate=2014-01-12}}</ref> a [[Sony]] [[PlayStation Portable]] emulator, has a dynarec option.
  
 
==See also==
 
==See also==
* Comparison of platform virtual machines
+
* [[Comparison of platform virtual machines]]
* Binary translation
+
* [[Binary translation]]
* Just-in-time compilation
+
* [[Just-in-time compilation]]
* Binary recompiler
+
* [[Binary recompiler]]
  
 
==References==
 
==References==
Line 91: Line 90:
  
 
==External links==
 
==External links==
*[http://web.archive.org/web/20051018182930/www.zenogais.net/Projects/Tutorials/Dynamic%20Recompiler.html Dynamic recompiler tutorial]
+
*[http://web.archive.org/web/20051018182930/www.zenogais.net/Projects/Tutorials/Dynamic+Recompiler.html Dynamic recompiler tutorial]
 
*[http://emulatemii.com/wordpress/?tag=dynarec Blog posts about writing a MIPS to PPC dynamic recompiler]
 
*[http://emulatemii.com/wordpress/?tag=dynarec Blog posts about writing a MIPS to PPC dynamic recompiler]
  
[[Category:Wikipedia copies]]
+
[[Category:Virtualization software]]
 +
[[Category:Compiler construction]]
 +
[[Category:Emulation software]]

Please note that all contributions to Emulation General Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see Emulation General Wiki:Copyrights for details). Do not submit copyrighted work without permission!

To edit this page, please answer the question that appears below (more info):

Cancel Editing help (opens in new window)

Templates used on this page: