- emit_jns(0);
- add_stub(CC_STUB,jaddr,out,0,i,start+i*4+8,NOTTAKEN,0);
- }
- }
- }
-}
-
-static void pagespan_assemble(int i, const struct regstat *i_regs)
-{
- int s1l=get_reg(i_regs->regmap,dops[i].rs1);
- int s2l=get_reg(i_regs->regmap,dops[i].rs2);
- void *taken = NULL;
- void *nottaken = NULL;
- int unconditional=0;
- if(dops[i].rs1==0)
- {
- s1l=s2l;
- s2l=-1;
- }
- else if(dops[i].rs2==0)
- {
- s2l=-1;
- }
- int hr=0;
- int addr=-1,alt=-1,ntaddr=-1;
- if(i_regs->regmap[HOST_BTREG]<0) {addr=HOST_BTREG;}
- else {
- while(hr<HOST_REGS)
- {
- if(hr!=EXCLUDE_REG && hr!=HOST_CCREG &&
- i_regs->regmap[hr]!=dops[i].rs1 &&
- i_regs->regmap[hr]!=dops[i].rs2 )
- {
- addr=hr++;break;
- }
- hr++;
- }
- }
- while(hr<HOST_REGS)
- {
- if(hr!=EXCLUDE_REG && hr!=HOST_CCREG && hr!=HOST_BTREG &&
- i_regs->regmap[hr]!=dops[i].rs1 &&
- i_regs->regmap[hr]!=dops[i].rs2 )
- {
- alt=hr++;break;
- }
- hr++;
- }
- if((dops[i].opcode&0x2E)==6) // BLEZ/BGTZ needs another register
- {
- while(hr<HOST_REGS)
- {
- if(hr!=EXCLUDE_REG && hr!=HOST_CCREG && hr!=HOST_BTREG &&
- i_regs->regmap[hr]!=dops[i].rs1 &&
- i_regs->regmap[hr]!=dops[i].rs2 )
- {
- ntaddr=hr;break;
- }
- hr++;
- }
- }
- assert(hr<HOST_REGS);
- if((dops[i].opcode&0x2e)==4||dops[i].opcode==0x11) { // BEQ/BNE/BEQL/BNEL/BC1
- load_reg(regs[i].regmap_entry,regs[i].regmap,CCREG);
- }
- emit_addimm(HOST_CCREG, ccadj[i] + CLOCK_ADJUST(2), HOST_CCREG);
- if(dops[i].opcode==2) // J
- {
- unconditional=1;
- }
- if(dops[i].opcode==3) // JAL
- {
- // TODO: mini_ht
- int rt=get_reg(i_regs->regmap,31);
- emit_movimm(start+i*4+8,rt);
- unconditional=1;
- }
- if(dops[i].opcode==0&&(dops[i].opcode2&0x3E)==8) // JR/JALR
- {
- emit_mov(s1l,addr);
- if(dops[i].opcode2==9) // JALR
- {
- int rt=get_reg(i_regs->regmap,dops[i].rt1);
- emit_movimm(start+i*4+8,rt);
- }
- }
- if((dops[i].opcode&0x3f)==4) // BEQ
- {
- if(dops[i].rs1==dops[i].rs2)
- {
- unconditional=1;
- }
- else
- #ifdef HAVE_CMOV_IMM
- if(1) {
- if(s2l>=0) emit_cmp(s1l,s2l);
- else emit_test(s1l,s1l);
- emit_cmov2imm_e_ne_compact(ba[i],start+i*4+8,addr);
- }
- else
- #endif
- {
- assert(s1l>=0);
- emit_mov2imm_compact(ba[i],addr,start+i*4+8,alt);
- if(s2l>=0) emit_cmp(s1l,s2l);
- else emit_test(s1l,s1l);
- emit_cmovne_reg(alt,addr);
- }
- }
- if((dops[i].opcode&0x3f)==5) // BNE
- {
- #ifdef HAVE_CMOV_IMM
- if(s2l>=0) emit_cmp(s1l,s2l);
- else emit_test(s1l,s1l);
- emit_cmov2imm_e_ne_compact(start+i*4+8,ba[i],addr);
- #else
- assert(s1l>=0);
- emit_mov2imm_compact(start+i*4+8,addr,ba[i],alt);
- if(s2l>=0) emit_cmp(s1l,s2l);
- else emit_test(s1l,s1l);
- emit_cmovne_reg(alt,addr);
- #endif
- }
- if((dops[i].opcode&0x3f)==0x14) // BEQL
- {
- if(s2l>=0) emit_cmp(s1l,s2l);
- else emit_test(s1l,s1l);
- if(nottaken) set_jump_target(nottaken, out);
- nottaken=out;
- emit_jne(0);
- }
- if((dops[i].opcode&0x3f)==0x15) // BNEL
- {
- if(s2l>=0) emit_cmp(s1l,s2l);
- else emit_test(s1l,s1l);
- nottaken=out;
- emit_jeq(0);
- if(taken) set_jump_target(taken, out);
- }
- if((dops[i].opcode&0x3f)==6) // BLEZ
- {
- emit_mov2imm_compact(ba[i],alt,start+i*4+8,addr);
- emit_cmpimm(s1l,1);
- emit_cmovl_reg(alt,addr);
- }
- if((dops[i].opcode&0x3f)==7) // BGTZ
- {
- emit_mov2imm_compact(ba[i],addr,start+i*4+8,ntaddr);
- emit_cmpimm(s1l,1);
- emit_cmovl_reg(ntaddr,addr);
- }
- if((dops[i].opcode&0x3f)==0x16) // BLEZL
- {
- assert((dops[i].opcode&0x3f)!=0x16);
- }
- if((dops[i].opcode&0x3f)==0x17) // BGTZL
- {
- assert((dops[i].opcode&0x3f)!=0x17);
- }
- assert(dops[i].opcode!=1); // BLTZ/BGEZ
-
- //FIXME: Check CSREG
- if(dops[i].opcode==0x11 && dops[i].opcode2==0x08 ) {
- if((source[i]&0x30000)==0) // BC1F
- {
- emit_mov2imm_compact(ba[i],addr,start+i*4+8,alt);
- emit_testimm(s1l,0x800000);
- emit_cmovne_reg(alt,addr);
- }
- if((source[i]&0x30000)==0x10000) // BC1T
- {
- emit_mov2imm_compact(ba[i],alt,start+i*4+8,addr);
- emit_testimm(s1l,0x800000);
- emit_cmovne_reg(alt,addr);
- }
- if((source[i]&0x30000)==0x20000) // BC1FL
- {
- emit_testimm(s1l,0x800000);
- nottaken=out;
- emit_jne(0);
- }
- if((source[i]&0x30000)==0x30000) // BC1TL
- {
- emit_testimm(s1l,0x800000);
- nottaken=out;
- emit_jeq(0);