On 05/10/2011 11:13 AM, Tarmo Pikaro wrote: >> It would be much easier to ship an executable containing both the guest >> application and qemu, so that executing it starts qemu with a >> pre-defined configuration and runs the guest binary. > > - Binary recompilation would allow faster execution than emulated code
Digital Equipment Corp (DEC) did a lot of work with static binary recompilation in the early 1990's, converting VAX VMS applications to Alpha VMS. It's quite possible to do if you spend enough time on it, and have a well defined application environment. That said, Hewlett Packard (HP) has done a very similar amount of work with dynamic binary recompilation of PA-RISC HP/UX to IA-64 HP/UX, and achieved similar results to what DEC achieved. There has been a *lot* of papers about dynamic recompilation over the last decade or two. I believe that the general consensus is that -- with the addition of dynamic profiling -- dynamic recompilation allows faster execution than static recompilation. A lot of this is stuff that QEMU doesn't do. But the gist is, you add profiling information to basic blocks as you translate them. This first compilation pass is very quick and dirty, producing only moderately poor translated code. As the program runs, a profile is collected that allows the emulation environment to identify portions of the program that should be compiled again, with much higher optimization. The thing that allows this dynamic compilation to produce code that runs faster than static compilation is that the VM can make simplifying assumptions about how a portion of the program acts (either discovered from the profile, or a true guess) and check those assumptions before the translated code is executed. If the assumptions turn out to be invalid, then the VM can fall back to the original quick compilation, or re-compile the portion of the program without the assumptions. If you're truly interested, a fair portion of these sorts of papers are written in the context of Java Virtual Machines. But the techniques apply equally well to any dynamic compilation process. r~ P.S: I seem to recall reading that HP had done some testing of their PA-RISC dynamic recompiler, producing PA-RISC output too. The recompiled programs could then run on the same hardware as the original program. The recompiled programs ran faster than the originals, due to the techniques described.