VOGONS


First post, by FallenAngel

User metadata
Rank Newbie
Rank
Newbie

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.

Reply 2 of 4, by ih8registrations

User metadata
Rank Oldbie
Rank
Oldbie

I thought it still depends on the case statement? That if not sequential, it is still broken down into if else. As for what the opcode-parsing is being generated as, it's not like we have to guess; compile to the assembly point and see what it is being converted to.

Reply 3 of 4, by 3803

User metadata
Rank Newbie
Rank
Newbie

I'm not into C++ myself, but I get what you mean. Why don't you consider trying what you suggest, and post if it makes any difference? I'm eager to know if it would give dosbox another performance boost 😀

Reply 4 of 4, by DoomWarrior

User metadata
Rank Newbie
Rank
Newbie

i had an other idea ! What's about an sorted hastable with the opcode as an key.
But i don't code c++ for more then 2 years. so i'm not quite sure if this would speed up emulation.
But the advance of an hastable would be direct access. On the other hand hashtable shouldn't be faster then an array-field if you don't delete keys and values OR put new keys/values into it. 😒

but would be intressting to see the diffrent speed results with the diffrent methods.