What's new

what are the most used opcodes on r4300i by n64 games?

cufunha

New member
Hello everybody, Im new here and Im doing a new n64 emulator that runs fully on interpreter mode (I know it's slow). Im planning to emulate every little thing on n64, including a fully tottally emulated main processor (r4300i); when doing that funtion that calls the opcodes I'm planning to use a huge switch instead of a function pointer table beacuse I read it can get faster under some circunstances... these circunstances are basically, use very little code on the case labels and arrange the cases in probability order...
Thus, i need to know what are the most used opcodes, or what are the probability of each opcode to appear... is there any kind of disassembler that says the number of times each opcode appeared on the rom? if not, is there any good disassembler open source that I can easily modify the code to do that?

thankx for the help.
 

zenogais

New member
The only way a switch would be equal speed of an array of function pointers is if you're using an optimizing compiler, or your compiler optimizes switches to jump tables. If not then you are sadly mistaken and will have a very ugly and slow emulator.
 

WildNinji

New member
cufunha said:
Hello everybody, Im new here and Im doing a new n64 emulator that runs fully on interpreter mode (I know it's slow).
:luck:

cufunha said:
Im planning to emulate every little thing on n64, including a fully tottally emulated main processor (r4300i);
I think that emulating 100% of the CPU is just the starting point and is not so difficut to achieve. The hard part is getting the RCP emulation right: it is under documented and slow to emulate.

cufunha said:
when doing that funtion that calls the opcodes I'm planning to use a huge switch instead of a function pointer table beacuse I read it can get faster under some circunstances... these circunstances are basically, use very little code on the case labels and arrange the cases in probability order...
On modern processors the speedup is negligible, and on architectures like P4 (with a long branch-prediction-miss recovery time) this trick will make your routine 200% slower (4 time slower).

cufunha said:
Thus, i need to know what are the most used opcodes, or what are the probability of each opcode to appear...
You can extract this information by yourself
Code:
int opcodeUsed[OPCODE_NUM] = { 0...OPCODE_NUM = 0};

void executeOpcode(u32 instruction) {
    opcode = extractOp(instruction);
    opcodeUsed[opcode]++;
    (*opcodeTable[opcode])(instruction);
}

/* after some time you have a pretty reliable table of occurrences
    in opcodeUsed[] */
BTW I think the most used instruction are LW, SW, LUI, ORI, ADD(U), JR, BEQ SLL (NOP).

cufunha said:
is there any kind of disassembler that says the number of times each opcode appeared on the rom? if not, is there any good disassembler open source that I can easily modify the code to do that?
Cold code will tell you nothing. If you have a SW instruction inside a loop, the disassembler will tell you that the code execute a SW instr, insteat it is executed one million time or never (is the jump taken many times? is the jump ever taken?).
 
OP
C

cufunha

New member
thankx for the post... you're really right. I saw on an official amd optimizing guide that switches on athlon xp are faster sometimes than funtion tables, if they are rightly organized.
 

Top