Mercurial > hg > CbC > old > device
changeset 584:ef6e0e05137f
ia32 reconfigure continue...
author | kono |
---|---|
date | Wed, 18 Jan 2006 02:16:53 +0900 |
parents | 421be86892b3 |
children | a5b902b20300 |
files | mc-code-ia32.c |
diffstat | 1 files changed, 36 insertions(+), 34 deletions(-) [+] |
line wrap: on
line diff
--- a/mc-code-ia32.c Tue Jan 17 23:38:57 2006 +0900 +++ b/mc-code-ia32.c Wed Jan 18 02:16:53 2006 +0900 @@ -339,9 +339,10 @@ char *move_op; code_clear_stack_reg(reg1); - move_op = regs[reg0]?"\txchg %s,%s\n":"\tmovl %s,%s\n"; + move_op = (regs[reg1]||regs[reg1])?"\txchg %s,%s\n":"\tmovl %s,%s\n"; if (move) { printf(move_op,reg_name[reg0],reg_name[reg1]); + if (!regs[reg1]) regs[reg1]=USING_REG; } return reg0; } @@ -378,16 +379,16 @@ if (reg!=creg) { // clear_ptr_cache_reg(reg); if (ireg && reg!=ireg ) { - free_register(ireg); + if (regs[ireg]!=REG_VAR) free_register(ireg); if (mode) { - printf("\tmovl %s,%s\n",reg_name[reg],reg_name[ireg]); + printf("\tmovl %s,%s\n",reg_name[ireg],reg_name[reg]); } } if (regs[creg]!=REG_VAR) free_register(creg); if (creg==lreg) lreg = 0; - regs[reg]=USING_REG; } creg = ireg = reg; + if (!regs[reg]) regs[reg]=USING_REG; } #define is_long_reg(reg) (reg==REG_LCREG||reg==REG_L) @@ -398,10 +399,10 @@ use_longlong0(int reg) { int i = creg; - if (ireg) { free_register(ireg); ireg=0; } + if (ireg) { if (regs[ireg]!=REG_VAR) free_register(ireg); ireg=0; } if (!lreg||!regs[lreg]) { code_save_stacks(); - lreg = REG_LCREG; + lreg = (reg==USE_CREG)?REG_LCREG:reg; i = lreg; } if (!regs[i]) regs[i]=USING_REG; @@ -782,7 +783,7 @@ void emit_pop_free(int xreg) { - if (xreg>=0 && xreg!=creg) { + if (xreg>=0 && xreg!=creg && regs[xreg]!=REG_VAR) { free_register(xreg); } } @@ -1265,7 +1266,6 @@ printf("\tpushl %%ecx\n"); printf("\tpushl %s\n",register_name(from,0)); printf("\tpushl %s\n",register_name(to,0)); - printf("\tpopl %%ecx\n"); printf("\tpopl %%edi\n"); printf("\tpopl %%esi\n"); if (length<0) { @@ -1299,7 +1299,7 @@ /* this code is necessary for the value of assignment or function call */ /* otherwise we don't need this */ if(creg!=to) { - free_register(creg); creg=to; + if (regs[creg]!=REG_VAR) free_register(creg); creg=to; } } } @@ -1569,12 +1569,10 @@ } void -code_register_assop(int e2,int reg0,int op,int byte) { - int reg; - int xreg = creg; - creg = reg = e2; - tosop(op,reg,xreg); - set_ireg(xreg,0); +code_register_assop(int e2,int reg, int op,int byte) { + // reg <= reg(e2) op=reg + use_int(reg); + tosop(op,e2,reg); } void @@ -1585,9 +1583,9 @@ use_int(creg); xreg = emit_pop(0); /* pop e3 value */ emit_push(); - emit_pop_free(xreg); ld_indexx(byte,0,creg,ireg,sign); tosop(op,ireg,xreg); + emit_pop_free(xreg); if (byte) { use_data_reg(ireg,1); } @@ -1621,7 +1619,7 @@ char *orn,*crn; // creg = creg op oreg - use_int(creg); + use_int(reg); if(oreg==-1) { error(-1); @@ -1648,7 +1646,7 @@ } // regs[oreg]=1; orn = register_name(oreg,0); - crn = register_name(creg,0); + crn = register_name(reg,0); switch(op) { case ADD: printf("\taddl %s,%s\n",orn,crn); @@ -1671,8 +1669,8 @@ break; case DIV: case UDIV: - use_register(creg,REG_EAX,1); - if (oreg==REG_EAX) oreg=creg; + use_register(reg,REG_EAX,1); + if (oreg==REG_EAX) oreg=reg; else if (oreg==REG_EDX) { use_register(oreg,REG_ECX,1); oreg = REG_ECX; @@ -1683,11 +1681,12 @@ else printf("\txor %%edx,%%edx\n\tdivl %s\n",orn); set_ireg(REG_EAX,0); + set_ireg(reg,1); break; case MOD: case UMOD: - use_register(creg,REG_EAX,1); - if (oreg==REG_EAX) oreg=creg; + use_register(reg,REG_EAX,1); + if (oreg==REG_EAX) oreg=reg; else if (oreg==REG_EDX) { use_register(oreg,REG_ECX,1); oreg = REG_ECX; @@ -1698,6 +1697,7 @@ else printf("\txor %%edx,%%edx\n\tdivl %s\n",orn); set_ireg(REG_EDX,0); + set_ireg(reg,1); break; } if(ox) free_register(ox); @@ -1778,15 +1778,14 @@ void -shift(char *op, int reg,int creg) +shift(char *op, int oreg,int reg) { - use_int(creg); - if (reg>=0) { - use_register(reg,REG_ECX,1); - } else { - printf("\tpopl %%ecx\n"); - } - printf("\t%s %%cl,%s\n",op,register_name(creg,0)); + int dreg; + use_register(oreg,REG_ECX,1); + dreg = (reg==REG_ECX)?oreg:reg; + printf("\t%s %%cl,%s\n",op,register_name(dreg,0)); + set_ireg(dreg,0); + set_ireg(reg,1); } void @@ -2705,7 +2704,7 @@ code_assign_lvar( (reg_stack[i]=new_lvar(SIZE_OF_INT)),reg,0); reg_stack[i]= reg_stack[i]-REG_LVAR_OFFSET; - free_register(reg); + if (regs[reg]!=REG_VAR) free_register(reg); } } } @@ -2721,7 +2720,7 @@ code_assign_lvar( (reg_stack[i]=new_lvar(SIZE_OF_INT)),reg,0); reg_stack[i]= reg_stack[i]-REG_LVAR_OFFSET; - free_register(reg); + if (regs[reg]!=REG_VAR) free_register(reg); } } } @@ -3524,9 +3523,12 @@ void code_free_asm_operand(int repl) { + int reg; for(;repl;repl=cadr(repl)) { - if (car(car(repl))==REGISTER) - free_register(cadr(car(repl))); + if (car(car(repl))==REGISTER) { + reg = cadr(car(repl)); + if (regs[reg]!=REG_VAR) free_register(reg); + } } }