/* a register VM with specialized instructions for registers 0-5, with
   regs 0-2 in real registers, with direct-threaded dispatch */

typedef void (*inst_t)(void **ip, long *regbase, long r0, long r1, long r2);

/* General case: register specifiers as immediate operands; 
   does not work for registers 0-2 */
void add_general(void **ip, long *regbase, long r0, long r1, long r2)
{
  unsigned long rdest=((unsigned char *)(ip+1))[0];
  unsigned long rsrc1=((unsigned char *)(ip+1))[1];
  unsigned long rsrc2=((unsigned char *)(ip+1))[2];
  regbase[rdest] = regbase[rsrc1]+regbase[rsrc2];
  ip+=2;
  inst_t next = ip[0];
  next(ip, regbase, r0, r1, r2);
}

void add_r3_r4_r5(void **ip, long *regbase, long r0, long r1, long r2)
{
  regbase[3] = regbase[4] + regbase[5];
  ip+=1;
  inst_t next = ip[0];
  next(ip, regbase, r0, r1, r2);
}

void add_r0_r1_r2(void **ip, long *regbase, long r0, long r1, long r2)
{
  r0 = r1+r2;
  ip+=1;
  inst_t next = ip[0];
  next(ip, regbase, r0, r1, r2);
}


