[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Switch Case Loop Slower For Emulator



Hi Bryan,

"Bryan Parkoff" <BParkoff@satx.rr.com> wrote in message
n36dnU3V1OhT6TqjXTWQkQ@giganews.com">news:n36dnU3V1OhT6TqjXTWQkQ@giganews.com...
>     I have noticed that every programmers use Switch Case Loop for
Emulator.
> Switch Case has to scan 256 opcode each time.  I think that Switch Case
Loop
> is very long for scanning.  There has to be another way to reduce Switch
> Case Loop by removing too much case for scanning each opcodes.
>     It has to use clever algorithm that will reduce Intel's cycle and
> improve performance.

If you are running an emulator on a system which has plenty of memory,
(every PC these days) you can set up a huge jump table with the addresses
of the opcode handling routines indexed according to value of the opcode.

Go one step further and create a table which is word indexed according
to opcode and the following byte.
You can then do a direct jump to an opcode handling routine and pass it
the operand (in the case of single byte operands).
This saves an extra memory fetch for the operand as well.

This method is employed in the Amiga "Apple2000" emulator. The jump
table it produces is 256k in size, however, the emulator manages to
run at full Apple2 speed ( or faster) even on a 68020 running at a lowly
14MHz.

Cheers,
Red