Welcome to Emulationworld

Forum Index | FAQ | New User | Login | Search

Make a New PostPrevious ThreadView All ThreadsNext ThreadShow in Flat Mode*


SubjectRe: Ahhh! That's genius! Reply to this message
Posted byBart T.
Posted on12/13/03 08:31 PM



> I'm wondering if (because C makes quite a good job on the register copies but a
> bad job on the flag calculation) dead flag analysis could bring C emulators very
> close to Asm ones and possibly even past them!

You could always write a better emulator in assembly which uses the same trick.

What's nice about this approach is that you don't have to worry about instruction decoding anymore. This can normally take a considerable amount of time and memory. If you look at the fast assembly 68K emulators, they generate many different permutations of each instruction simply to avoid having to extract register fields.

Starscream and Turbo68K had mostly the same approach and generated a lot of instructions. A68K is faster and I think that's mostly due to the fact that it generates much less code.

I'm not sure exactly what Generator does, but you can easily generate different permutations for instructions based on flags and then have a fetch/decode stage which outputs code like this:

push reg1
push reg2
call _OpXXXX
add esp,4
push reg1
push reg2
call _OpYYYY
... etc. ...

Or, to make it truly portable, have an array of structs of a type like this:

struct instruction
{
void (*Handler)(struct instruction *);
UINT32 field1, field2, field3, etc. ;
};

And simply iterate through this. I think this is what ElSemi was talking about (correct me if I'm wrong.)


It's a good approach, especially when you don't have to keep re-fetching code (if it's mostly in ROM, for instance, or in protected non-writeable memory pages) and you want to avoid having to write a full-blown dynarec.

I don't know if it would be worth it for emulating a 68K on X86, though. Flag calculation is simple (LAHF, SETO AL), and decoding can be pretty optimal, as A68K shows.

It's probably great for something like ARM or a low-end MIPS or PPC.


----
Bart

-
Entire Thread
Subject  Posted byPosted On
*Does Generator have a 68000 Dynarec?  finaldave12/10/03 03:35 PM
.*Re: Does Generator have a 68000 Dynarec?  Bart T.12/10/03 03:48 PM
..*Ahhh! That's genius!  finaldave12/11/03 05:03 AM
...*Re: Ahhh! That's genius!  smf12/12/03 07:56 AM
....*Re: Ahhh! That's genius!  ElSemi12/13/03 07:31 AM
.....*Re: Ahhh! That's genius!  finaldave12/13/03 05:19 PM
.......Re: Ahhh! That's genius!  Bart T.12/13/03 08:31 PM
.......*Re: Ahhh! That's genius!  ElSemi12/14/03 05:18 AM
........*Re: Ahhh! That's genius!  Riff12/15/03 00:38 AM
.........*Re: Ahhh! That's genius!  Bart T.12/15/03 01:17 AM
..........*Re: Ahhh! That's genius!  Riff12/15/03 02:27 PM
...........*Re: Ahhh! That's genius!  Bart T.12/16/03 03:20 AM
...........*Re: Ahhh! That's genius!  finaldave12/15/03 03:48 PM
............*Re: Ahhh! That's genius!  Bart T.12/15/03 04:30 PM
.............*Re: Ahhh! That's genius!  Kayamon12/18/03 08:56 AM
..............*Re: Ahhh! That's genius!  finaldave12/18/03 09:36 AM
...............*Re: Ahhh! That's genius!  smf12/19/03 04:33 AM
.............*Re: Ahhh! That's genius!  finaldave12/16/03 05:16 AM
..............*Re: Ahhh! That's genius!  Bart T.12/16/03 01:04 PM
...............*Re: Ahhh! That's genius!  finaldave12/16/03 03:40 PM
................*Re: Ahhh! That's genius!  smf12/17/03 06:33 AM
.................*Re: Ahhh! That's genius!  finaldave12/17/03 06:39 AM
..................*Re: Ahhh! That's genius!  smf12/17/03 09:57 AM
...................*Re: Ahhh! That's genius!  finaldave12/17/03 12:39 PM
....................*Re: Ahhh! That's genius!  smf12/17/03 02:59 PM