Oh, I think I saw something like that going on in the sneq source, but I couldn't completely make out what he was doing. That's a neat idea, I'll give it a shot.
The 1:20 ratio is only that way 'cause there isn't any profiling going on. For the moment, all 65c816 registers are statically mapped to the s-registers, and the translation includes encoded MIPS instructions to calculate the m and x flags, with appropriate branches to perform the necessary masking. Not to mention the fact that, with these statically mapped registers, I'm not taking any steps to avoid the clutter caused by the accumulator-based architecture.
So, for example, here's my current emit_lda function (which will need some fixing to take into consideration proper memory mapping):
Code:
void emit_lda( unsigned int **location, ADDRESS_MODE am ) {
/**
* --$t3 = effective address--
* --$t0 = *(effective address)--
* 0 andi $t1, S, MFLAG
* 4 bne $t1, $zero, 16
* 8 add A, $zero, $t0
* 12 j 24
* 16 andi A, A, 0xFF00
* 20 or A, A, $t0
* 24 nop
**/
emit_load_op( memPtr, location, T3, am );
emit_deref_mflag( location, T0, T3 );
unsigned int initLoc = (unsigned int)*location;
AND_I( location, T1, S, MFLAG );
BNE( location, T1, ZERO, 2 );
ADD( location, A, ZERO, T0 );
J( location, initLoc + 24 );
AND_I( location, A, A, 0xFF00 );
OR( location, A, A, T0 );
NOP( location );
}
The instruction macros look something like:
#define ADD_I( location, rt, rs, immediate ) \
**location = ITYPE( ADD_I_OP, rs, rt, immediate ); \
++(*location);
Once this all works, even if it's super slow, the emit functions are going to see a pretty big overhaul so I can work them into some kind of profiling scheme for on-the-fly instruction reordering, dynamic register allocation and general basic block optimizations. Until then, things will look a little messy.
And sure, I'll shoot you an IM when I get the chance. Right now it looks like you're idle, though. D;