|
> 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?
|