What's new

A CPU portable Dynarec?

zorbid

New member
The x86 emulator QEMU team is writing a more or less CPU indenpendant Dynamic Recompiler. I thought you might find it interresting for Mupen (if this can be applied to the R4300i). The main coder is french too...
From http://fabrice.bellard.free.fr/qemu/qemu-doc.html

3.2 Portable dynamic translation

QEMU is a dynamic translator. When it first encounters a piece of code, it converts it to the host instruction set. Usually dynamic translators are very complicated and highly CPU dependant. QEMU uses some tricks which make it relatively easily portable and simple while achieving good performances.

The basic idea is to split every x86 instruction into fewer simpler instructions. Each simple instruction is implemented by a piece of C code (see `op-i386.c'). Then a compile time tool (`dyngen') takes the corresponding object file (`op-i386.o') to generate a dynamic code generator which concatenates the simple instructions to build a function (see `op-i386.h:dyngen_code()').

In essence, the process is similar to [1], but more work is done at compile time.

A key idea to get optimal performances is that constant parameters can be passed to the simple operations. For that purpose, dummy ELF relocations are generated with gcc for each constant parameter. Then, the tool (`dyngen') can locate the relocations and generate the appriopriate C code to resolve them when building the dynamic code.

That way, QEMU is no more difficult to port than a dynamic linker.

To go even faster, GCC static register variables are used to keep the state of the virtual CPU.
 
Last edited:
OP
zorbid

zorbid

New member
BTW, to make things clear, I wanted to bring your attention on this because Mupen is designed with portability in mind, and the method they use is if not new, not widely used.

I know that you can't simply use their x86 emulator in Mupen...:doh:
 

Hacktarux

Emulator Developer
Moderator
Actually i was thinking about a smilar method but there's some drawbacks... While it's cpu portable it's not os portable... You have to write an object file reader for each OS you want to support. Secondly you can't optimize it as much as a standard dynarec because generated asm is produced by a c compiler and because register caching is impossible to implement. Anyway i'm designing it so that it'll be easier to write new dynarecs for new machines, so maybe one of the dynarecs can use such method :) I'll see when i'll have some time to work on it (not until the end of this fucking month :( )
 
OP
zorbid

zorbid

New member
Hacktarux said:
Actually i was thinking about a smilar method but there's some drawbacks... While it's cpu portable it's not os portable... You have to write an object file reader for each OS you want to support.
I didn't know that. I only have basic C(++) notions, but nothing I'd qualify knowlege...

Secondly you can't optimize it as much as a standard dynarec because generated asm is produced by a c compiler and because register caching is impossible to implement.
Actually they use register caching in QEMU :)
Anyway i'm designing it so that it'll be easier to write new dynarecs for new machines, so maybe one of the dynarecs can use such method :) I'll see when i'll have some time to work on it (not until the end of this fucking month :( )
Bonne merde pour tes exams :)
 

Top