Mercurial > hg > CbC > old > device
changeset 189:f53d70110377
immediate instructions.
author | kono |
---|---|
date | Mon, 01 Dec 2003 21:18:45 +0900 |
parents | 4303255fc3cf |
children | 1b1c58483e67 |
files | mc-code-ia32.c mc-code-mips.c mc-code-powerpc.c mc-code.h mc-codegen.c |
diffstat | 5 files changed, 129 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/mc-code-ia32.c Mon Dec 01 20:07:57 2003 +0900 +++ b/mc-code-ia32.c Mon Dec 01 21:18:45 2003 +0900 @@ -1254,6 +1254,54 @@ regv[creg]=1; } +int +code_const_op_p(int op,int v) +{ + if (DIV||UDIV||MOD||UMOD) return 0; + else return 1; +} + +void +oprtc(int op,int orn) +{ + char *crn = register_name(creg,0); + + switch(op) { + case LSHIFT: + case ULSHIFT: + printf("\tsall $%d,%s\n",orn,crn); + return; + case RSHIFT: + printf("\tsarl $%d,%s\n",orn,crn); + return; + case URSHIFT: + printf("\tshrl $%d,%s\n",orn,crn); + return; + case ADD: + printf("\taddl $%d,%s\n",orn,crn); + break; + case SUB: case CMP: + printf("\tsubl $%d,%s\n",orn,crn); + break; + case BAND: + printf("\tandl $%d,%s\n",orn,crn); + break; + case EOR: + printf("\txorl $%d,%s\n",orn,crn); + break; + case BOR: + printf("\torl $%d,%s\n",orn,crn); + break; + case MUL: + case UMUL: + printf("\t%s $%d,%s\n","imull",orn,crn); + break; + default: + error(-1); + } +} + + static int edx_stack=0; int
--- a/mc-code-mips.c Mon Dec 01 20:07:57 2003 +0900 +++ b/mc-code-mips.c Mon Dec 01 21:18:45 2003 +0900 @@ -1709,6 +1709,19 @@ printf("\t%s %s,%s,%s\n",op,crn,rrn,crn); } +int +code_const_op_p(int op,int v) +{ + if (op==BAND||op==DIV||op==UDIV||op==MOD||op==UMOD) return 0; + return 0; +} + +void +oprtc(int op,int v) +{ +} + + void ld_indexx(int byte, int n, int xreg,int sign) { @@ -2021,29 +2034,23 @@ } } +int +code_get_fixed_creg(int reg,int type) { + return creg; +} + void -code_set_fixed_creg(int mode,int type) { +code_set_fixed_creg(int reg,int mode,int type) { if (type==FLOAT) { - if (cond_freg== -1) { - cond_freg = get_dregister_var(0,0); - if(car(cond_freg)!=FREGISTER) error(-1); - } - set_freg(cadr(cond_freg),mode); + set_freg(reg,mode); } else if (type==DOUBLE) { - if (cond_dreg== -1) { - cond_dreg = get_dregister_var(0,1); - if(car(cond_dreg)!=DREGISTER) error(-1); - } - set_dreg(cadr(cond_dreg),mode); + set_dreg(reg,mode); } else { - if (cond_reg== -1) { - cond_reg = get_register_var(0); - if(car(cond_reg)!=REGISTER) error(-1); - } - set_creg(cadr(cond_reg),mode); + set_creg(reg,mode); } } + void gen_gdecl(char *n, int gpc) {
--- a/mc-code-powerpc.c Mon Dec 01 20:07:57 2003 +0900 +++ b/mc-code-powerpc.c Mon Dec 01 21:18:45 2003 +0900 @@ -1750,6 +1750,54 @@ regv[creg]=1; } +int +code_const_op_p(int op,int v) +{ + if (op==BAND||op==DIV||op==UDIV||op==MOD||op==UMOD) return 0; + return (-127<v&&v<128); +} + +void +oprtc(int op,int v) +{ + char *crn = register_name(creg); + + switch(op) { + case LSHIFT: + case ULSHIFT: + printf("\tslwi %s,%s,%d\n",crn,crn,v); + return; + case RSHIFT: + printf("\tsrawi %s,%s,%d\n",crn,crn,v); + return; + case URSHIFT: + printf("\tsrwi %s,%s,%d\n",crn,crn,v); + return; + case ADD: + printf("\taddi %s,%s,lo16(%d)\n",crn,crn,v); + break; + case SUB: + printf("\tsubi %s,%s,lo16(%d)\n",crn,crn,v); + break; + case CMP: + printf("\tcmpwi cr0,%s,lo16(%d)\n",crn,v); + break; + case EOR: + printf("\txori %s,%s,lo16(%d)\n",crn,crn,v); + break; + case BOR: + printf("\tori %s,%s,lo16(%d)\n",crn,crn,v); + break; + case MUL: + printf("\tmulli %s,%s,lo16(%d)\n",crn,crn,v); + break; + case UMUL: + printf("\tmulli %s,%s,lo16(%d)\n",crn,crn,v); + break; + default: + error(-1); + } +} void shift(char *op, int reg)
--- a/mc-code.h Mon Dec 01 20:07:57 2003 +0900 +++ b/mc-code.h Mon Dec 01 21:18:45 2003 +0900 @@ -95,6 +95,9 @@ extern void global_table(void); extern void code_label(int labelno); +extern int code_const_op_p(int op,int v); +extern void oprtc(int op,int v); + /* floating point part */
--- a/mc-codegen.c Mon Dec 01 20:07:57 2003 +0900 +++ b/mc-codegen.c Mon Dec 01 21:18:45 2003 +0900 @@ -941,15 +941,20 @@ void machinop(int e1) { - int e2,e3,op; + int e2,e3,op,v; e2 = cadr(e1); op = car(e1); e3 = caddr(e1); + if (car(e3)==CONST && code_const_op_p(op,v=cadr(e3))) { + g_expr(e2); + oprtc(op,v); + return; + } g_expr(e3); emit_push(); g_expr(e2); - tosop(car(e1),(e2=pop_register())); + tosop(op,(e2=pop_register())); emit_pop_free(e2); return; }