Forum Index | FAQ | New User | Login | Search

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


Subjectthis way last opcode costs more than the first Reply to this message
Posted byTerry Bogard
Posted on12/17/03 07:40 PM



> I was just having a quick look at the source code to FPSE and was shocked that
> the cpu emulator looks like it's actually very very compact (cpu2.cpp in the
> source, 500 lines) and just seems to have stuff like
>
> case ADDU: rd = rs rt; break;
> case SUBU: rd = rs - rt; break;
> case BNE: if (rt!=rs) { JUMP(PC immS*4); } break;
>
> Is this because MIPS is a very reduced instruction set (i.e. the decode is
> similar in each opcode)?

Maybe the overhead isn't much with a fast CPU and a reduced instruction set, but when I tried to write a Z80 emu, I chose to initialize an array of function pointers *ONCE*, and then decode opcodes this way:

opcode = readOpcodeFromMemory(PC);

(functionArray[opcode]) (parameters);

Downsides were the init time, which was kinda long, and the fact that all functions implementing opcodes shared the same signature, which was a useless parameter passing, sometimes. But no time wasted to "seek" the correct opcode implementation.

Was it a very bad idea?



-
Entire Thread
Subject  Posted byPosted On
*Playstation Emu  finaldave12/16/03 09:16 AM
..this way last opcode costs more than the first  Terry Bogard12/17/03 07:40 PM
..*Re: this way last opcode costs more than the first  Bart T.12/17/03 09:46 PM
.*Re: Playstation Emu  galibert12/16/03 09:37 PM
..*Re: Playstation Emu  finaldave12/18/03 04:59 AM
...*Re: Playstation Emu  tratax12/30/03 07:11 PM
..*Re: Playstation Emu  finaldave12/17/03 05:05 AM
...*Re: Playstation Emu  smf12/17/03 06:21 AM
....*Re: Playstation Emu  finaldave12/17/03 06:21 PM
.....*Re: Playstation Emu  Riff12/17/03 07:57 PM
......*Re: Playstation Emu  smf12/18/03 05:24 AM
.......*Re: Playstation Emu  tratax12/30/03 07:07 PM
........*Re: Playstation Emu  smf01/02/04 05:56 AM
........*Re: Playstation Emu  R. Belmont12/31/03 01:19 AM
.........*Re: Playstation Emu  tratax01/01/04 06:06 PM
.......*Re: Playstation Emu  ElSemi12/18/03 01:24 PM
........*Re: Playstation Emu  Riff12/18/03 04:56 PM
.*Re: Playstation Emu  Bart T.12/16/03 01:02 PM