First post, by FallenAngel
I just looked through some of the core code (core_normal.cpp and its includes) of DosBox 0.61 and found some stuff, that (in my opinion) seriously impacts performance:
As far as I understand that code, the opcode-parsing is done by ONE huge switch statement, which is equivalent to some hundred if- statements, hence in the worst case (the current instruction is the last one in the opcode list), to parse ONE opcode, the host-CPU will have to compare the current opcode to all existing opcodes (some hundred).
Instead of that, you could have an array of function pointers, where the opcode is represented by the array index:
void Opcode0x00 ()
{
//code for opcode 0x00
}
void Opcode0x01 ()
{
//code for opcode 0x00
}
//...
typedef void (*funcptr)();
funcptr pOpcodes[256];
then apply the function pointers to the array:
pOpcodes[0] = Opcode0x00;
pOpcodes[1] = Opcode0x01;
//...
To execute an give opcode (let it be "dwOpcode"), you would then not have to use all those case-statements, but only to use the code line
pOpcodes[dwOp]();
Wouldn't that cause a huge performance boost ?
P.S. : I'm a newbie and not a native Englisch speaker, please be patient with me.