Mercurial > hg > CbC > old > device
changeset 718:d12029c499df
mc-code-spu no compile error
author | kono |
---|---|
date | Tue, 20 Nov 2007 17:51:50 +0900 |
parents | c1542a2482b1 |
children | 4c5ac4025fbd |
files | mc-code-spu.c mc-codegen.c mc-codegen.h |
diffstat | 3 files changed, 278 insertions(+), 794 deletions(-) [+] |
line wrap: on
line diff
--- a/mc-code-spu.c Sat Nov 17 02:36:57 2007 +0900 +++ b/mc-code-spu.c Tue Nov 20 17:51:50 2007 +0900 @@ -89,10 +89,10 @@ -static void dconst(int l,int h,double value); -static void code_assign_input_double_long(int e1,int e2) ; -static void code_assign_input_double_reg(int e1,int e2) ; -static void code_assign_input_float_int(int e1,int e2) ; + + + + #endif static void use_input_reg(int reg,int mode); static void ascii(char *s); @@ -164,24 +164,10 @@ #define REGISTER_OPERAND 3 //this is first register for input #define REGISTER_OPERAND_1 4 #define RET_FREGISTER FREG_OFFSET -#define FREGISTER_OPERAND (FREG_OFFSET) -#define FREGISTER_OPERAND_1 (FREG_OFFSET+1) - -#define RET_LREGISTER 3 -#define LREGISTER_OPERAND 3 -#define LREGISTER_OPERAND_1 4 - -#define RET_DREGISTER RET_LREGISTER -#define DREGISTER_OPERAND LREGISTER_OPERAND -#define DREGISTER_OPERAND_1 LREGISTER_OPERAND_1 -#define DREGISTER_OPERAND_L LREGISTER_OPERAND_L static int *regs = spu_regs; #define CREG_REGISTER REGISTER_OPERAND -#define FREG_FREGISTER FREGISTER_OPERAND -#define LREG_LREGISTER LREGISTER_OPERAND -#define DREG_DREGISTER LREG_LREGISTER #define CMP_C1T (-1) @@ -232,6 +218,21 @@ #endif +#define is_int_reg(reg) (1) +#define is_float_reg(reg) (1) +#define is_longlong_reg(reg) (1) + +#define use_int(reg) if (reg==USE_CREG) reg=use_int0() +#define use_float(d,reg) if (reg==USE_CREG) reg=use_int0() +#define use_longlong(reg) if (reg==USE_CREG) reg=use_int0() + +static int +use_int0() { + if (!creg) creg = get_register(); + return creg; +} + +static void set_ireg(int reg,int mode); #if LONGLONG_CODE @@ -240,7 +241,7 @@ #endif static void code_save_input_registers(int dots); -static void set_creg(int,int); + static int max_func_args; static int my_func_args; @@ -417,10 +418,7 @@ } else code_add(creg,CODE_LVAR(l),REG_fp); } else if (l<0) { /* local variable */ -// printf("\tsfi\t%s, fp, %d\n",register_name(creg), FUNC_LVAR(l)); trn = register_name(tmp = get_register()); - //disp = search_const(LVAR,glist2(lvar_offset_label,FUNC_LVAR(l)),&label); - //printf("\tlqdhoge\t%s, %d($sp)\n",trn,(disp*4)); printf("\tlqd\t%s, 64($sp)\n",trn); printf("\ta\t%s, $sp, %s\n",register_name(creg),trn); } else if (l>=ARG_LVAR_OFFSET) { /* caller's arguments */ @@ -446,11 +444,12 @@ size_of_int = SIZE_OF_INT; size_of_pointer = SIZE_OF_INT; - size_of_vector = SIZE_OF_VECTOR + size_of_vector = SIZE_OF_VECTOR; size_of_short = SIZE_OF_SHORT; size_of_float = SIZE_OF_FLOAT; size_of_double = SIZE_OF_DOUBLE; size_of_longlong = SIZE_OF_LONGLONG; + size_of_vector = SIZE_OF_VECTOR; endian = ENDIAN; struct_align = size_of_int; init_src = init_src0; @@ -461,6 +460,8 @@ emit_reinit() { /* called for each file */ + + // SPU では ptr cache は使わない方が良い? init_ptr_cache(); output_mode = -1; } @@ -473,8 +474,6 @@ void code_gexpr(int e){ - if (is_int_reg(creg) && creg!=ireg) error(-1); -// register_usage("code_gexpr"); } @@ -773,21 +772,8 @@ free_all_register(void) { int i; -// printf("## free_all register\n"); -#if LONGLONG_CODE||FLOAT_CODE - for(i=0;i<REAL_MAX_REGISTER;i++) { - regs[i+LREG_OFFSET]=0; - } - lreg = 0; - // set_lreg(LREG_LREGISTER,0); -#endif for(i=0;i<MAX_REGISTER;i++) { regs[i]=0; } -#if FLOAT_CODE - for(i=0;i<MAX_REGISTER;i++) { regs[i+FREG_OFFSET]=0; } - freg = get_dregister(1); - set_freg(FREG_FREGISTER,0); -#endif - ireg = creg = get_register(); + creg = get_register(); set_ireg(CREG_REGISTER,0); return; } @@ -798,46 +784,20 @@ { switch(car(s)) { case REGISTER: - switch(car(t)) { - case FREGISTER: break; - case REGISTER: - return cadr(s)==cadr(t); - break; - case LREGISTER: case DREGISTER: - if(cadr(s)==(cadr(t))) return 1; - if(cadr(s)==(cadr(t))) return 1; - break; - } - break; case FREGISTER: - switch(car(t)) { - case REGISTER: case LREGISTER: case DREGISTER: break; - case FREGISTER: - return cadr(s)==cadr(t); - break; - } - break; case DREGISTER: case LREGISTER: switch(car(t)) { - case FREGISTER: break; - case REGISTER: - if(cadr(t)==(cadr(s))) return 1; - if(cadr(t)==(cadr(s))) return 1; - break; - case LREGISTER: case DREGISTER: - if((cadr(t))==(cadr(s))) return 1; - if((cadr(t))==(cadr(s))) return 1; - if((cadr(t))==(cadr(s))) return 1; - if((cadr(t))==(cadr(s))) return 1; - break; - } - break; - } + case REGISTER: + case FREGISTER: + case DREGISTER: + case LREGISTER: + return cadr(s)==cadr(t); + } + } return 0; } - void register_usage(char *s) { @@ -847,10 +807,6 @@ #define USAGE_MAX 4 if (!lsrc) return; printf("## %d: %s:",lineno,s); - if (ireg) printf(" creg=%s",register_name(ireg)); - if (freg) printf(" freg=%s",register_name(freg)); - if (lreg) printf(" lreg=%s,%s",lregister_name_high(lreg), - lregister_name_low(lreg)); #if 1 for(j=0,i=1;i<MAX_REGISTER;i++) if (regs[i]) j++; if (j>USAGE_MAX) { @@ -867,36 +823,6 @@ printf(",%d",reg_stack[i-1]); } } - for(j=0,i=0;i<MAX_REGISTER;i++) if (regs[i+FREG_OFFSET]) j++; - if (j>USAGE_MAX) { - printf("\n# freg:"); - for(i=0;i<MAX_REGISTER;i++) { printf("%d",regs[i+FREG_OFFSET]); } - } - if (reg_sp>0) { - printf(" fstack "); - for(i=reg_sp;i>0;i--) { - if(reg_stack[i-1]>=0) { - printf(" %s",register_name(reg_stack[i-1])); - } else - printf(",%d",reg_stack[i-1]); - } - } - - for(j=0,i=0;i<REAL_MAX_REGISTER;i++) if (regs[i+LREG_OFFSET]) j++; - if (j>USAGE_MAX) { - printf("\n# lreg:"); - for(i=0;i<REAL_MAX_REGISTER;i++) { printf("%d",regs[i+LREG_OFFSET]); } - } - if (reg_sp>0) { - printf(" lstack "); - for(i=reg_sp;i>0;i--) { - if(reg_stack[i-1]>=0) { - printf(" %s",lregister_name_high(reg_stack[i-1])); - printf(",%s",lregister_name_low(reg_stack[i-1])); - } else - printf(",%d",reg_stack[i-1]); - } - } #endif printf("\n"); } @@ -909,14 +835,6 @@ error(-1); free_register(reg_stack[--reg_sp]); } - while(reg_sp > 0) { - error(-1); - free_register(reg_stack[--reg_sp]); - } - while(reg_sp > 0) { - error(-1); - free_register(reg_stack[--reg_sp]); - } use_int0(); text_mode(2); gexpr_code_init(); @@ -981,7 +899,7 @@ new_reg = get_register(); /* 絶対にとれる */ if (new_reg==creg) error(-1); /* who freed creg? */ reg_stack[reg_sp++] = creg; /* push するかわりにレジスタを使う */ - ireg = creg = new_reg; + creg = new_reg; if (!regs[creg]) regs[creg]=USING_REG; return old; } @@ -1146,9 +1064,7 @@ extern void code_ptr_cache_def(int r, NMTBL *nptr) { - //int label,disp; char *rrn = register_name(r); - //disp = search_const(GVAR,(int)nptr,&label); printf("\tlqd\t%s, %d($sp)\n",rrn,(nptr->sc)*16); } @@ -1251,30 +1167,7 @@ sign = make_const(c,&p1,&p2,&p3,mode); return (c==0||(p1&&!p2&&!p3))?sign:0; } -/* - -static void -code_const0(int e2,int reg,char *opt) -{ - char *crn,*add,*mov; - int s,p1,p2,p3; - //int label,disp; - int disp; - - use_int(reg); - crn = register_name(reg); - if ((s=make_const(e2,&p1,&p2,&p3,CONST))) { - add = s>0?"a":"sf"; - mov = s>0?"il":"ori"; - printf("\t%s\t%s, %s, %d\n",mov,crn,crn,p1); - if (p2) printf("\t%s\t%s, %s, %d\n",add,crn,crn,p2); - if (p3) printf("\t%s\t%s, %s, %d\n",add,crn,crn,p3); - } else { - //disp = search_const(CONST,e2,&label); - printf("\tlqd\t%s, %d($sp)\n",crn,(disp*4)); - } -} -*/ + extern void code_const(int e2,int reg) { char *crn; @@ -1327,8 +1220,6 @@ int dreg; int s,p1,p2,p3,h; char *add; - //int label,disp; - int disp; if (offset==0) { if(r!=reg) printf("\tori\t%s, %s, 0\n",crn,rrn); @@ -1355,12 +1246,8 @@ } printf("\t%s\t%s, %s, %s\n", add, crn, rrn ,rn2); - //if (p2) printf("\t%s\t%s, %s, %s\n",add,crn,rrn,rrn+1); - //if (p3) printf("\t%s\t%s, %s, %d\n",add,crn,crn,p3); } else { - //disp = search_const(CONST,offset,&label); drn = register_name(dreg = get_register()); - // printf("\tlqd\t%s, %d($sp)\n",drn,(disp*4)); printf("\ta\t%s, %s, %s\n",crn,drn,rrn); free_register(dreg); } @@ -1510,9 +1397,7 @@ void code_label_value(int label,int reg) { - //int lb,disp; use_int(reg); - //disp = search_const(LABEL,label,&lb); printf("\tila\t%s,.LC%d\n",register_name(reg),label); return; } @@ -1520,7 +1405,6 @@ void code_neg(int creg) { use_int(creg); - //printf("\trsb\t%s, %s, #0\n", register_name(creg), register_name(creg)); printf("\tsfi\t%s, %s, 0\n", register_name(creg), register_name(creg)); } @@ -1537,10 +1421,7 @@ code_lnot(int creg) { use_int(creg); - //printf("\tcmp\t%s, #0\n", register_name(creg)); - printf("\tceqbi\t%s,%s,0\n",register_name(creg),register_name(creg)); - //printf("\tmovnehoge\t%s, #0\n", register_name(creg)); - //printf("\tmoveq\t%s, #1\n", register_name(creg)); + printf("\tceqbi\t%s,%s,0\n",register_name(creg),register_name(creg)); } void @@ -1594,10 +1475,9 @@ } else { xrn = register_name(reg); } -//_1: ldrb r4, [r0], #1 @ zero_extendqisi2 *buffer++ code_ld(cload(sz,sign),reg,0,xreg,cext_at(sz,sign)); code_add(nreg,dir,reg); - code_ldf(cstore(sz),nrn,0,xreg,sz==SIZE_OF_SHORT?" @ movhi":""); + code_ldf(cstore(sz),nrn,0,xreg,""); free_register(nreg); } @@ -1605,13 +1485,10 @@ void code_return(int creg) { - //int label,disp; char *crn; use_int(creg); crn = register_name(creg); - //disp = search_const(LABEL,retcont,&label); - // printf("\tlqd\t%s, %d($sp)\n",crn,(disp*4)); } void @@ -1619,15 +1496,11 @@ /* save frame pointer */ if (is_code(fnptr)) { use_int(creg); - //printf("\tmov\t%s, fp\n",register_name(creg)); printf("\tori\t%s, fp, 0\n",register_name(creg)); } else { //int disp,label; - int disp; char *trn = register_name(REG_ip); use_int(creg); - //disp = search_const(LVAR,glist2(lvar_offset_label,FUNC_LVAR(0)),&label); - // printf("\tlqa\t%s, %d\n",trn,disp); printf("\ta\t%s, $sp, %s\n",register_name(creg),trn); } } @@ -1736,7 +1609,6 @@ ascii(s); text_mode(2); - //disp = search_const(LABEL,lb,&label); printf("\tila\t%s, .LC%d\n",crn,lb); set_attr(n,LABEL,lb); } @@ -1812,7 +1684,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; ireg=to; + free_register(creg); creg=to; } } // free_register(dreg); @@ -1833,7 +1705,6 @@ } crn = register_name(creg); on_register = 0; - // arg_reg = 1-CALLER_ARG(arg_disp-ARG_LVAR_OFFSET)/SIZE_OF_INT; arg_reg = (arg_disp-ARG_LVAR_OFFSET)/SIZE_OF_INT + 1; while (length>0 && arg_disp>=ARG_LVAR_OFFSET && @@ -1889,105 +1760,27 @@ static void set_ireg(int reg,int mode) { - if (!is_int_reg(reg)) error(-1); if (reg!=creg) { clear_ptr_cache_reg(reg); - if (ireg && reg!=ireg ) { - free_register(ireg); + if (creg && reg!=creg ) { if (mode) { - printf("\tori\t%s, %s, 0\n",register_name(reg),register_name(ireg)); + printf("\tori\t%s, %s, 0\n", + register_name(reg),register_name(creg)); } } free_register(creg); - if (creg==lreg) lreg=0; - regs[reg]=USING_REG; - } - creg = ireg = reg; -} - -static void -set_freg(int reg,int mode) -{ - if (!is_float_reg(reg)) error(-1); - if (reg!=creg) { - if (freg && reg!=freg) { - free_register(freg); - if (mode) { - printf("\t%s\t%s, %s\n", - "mvfs", - register_name(reg),register_name(freg)); - } - } - // if (creg!=ireg) free_register(creg); regs[reg]=USING_REG; } - creg = freg = reg; -} - -#if LONGLONG_CODE||FLOAT_CODE -static void -set_lreg0(int reg,int mode) -{ - if (reg!=creg) { - if (lreg && reg!=lreg) { - if (mode) { - lmove(reg,lreg); - } - free_register(lreg); - } - if (creg!=lreg) { - free_register(creg); - if (creg==ireg) ireg = 0; - } - regs[reg]=USING_REG; - clear_ptr_cache_reg(reg); - regs[reg]=USING_REG; - clear_ptr_cache_reg(reg); - regs[reg]=USING_REG; - } - creg = lreg = reg; -} -#endif - -#if LONGLONG_CODE -static void -set_lreg(int reg,int mode) -{ - if (!is_longlong_reg(reg)) error(-1); - set_lreg0(reg,mode); -} -#endif - -#if FLOAT_CODE -static void -set_dreg(int reg,int mode) -{ - return set_ireg(reg,mode); -} - - - -#endif + creg = reg; +} void use_reg(int arg) { -// printf("## use reg %d\n",arg); if (arg<0||arg> REGS_MAX) error(-1); clear_ptr_cache_reg(arg); regs[arg]=USING_REG; - if (is_longlong_reg(arg)) { - clear_ptr_cache_reg(arg); - regs[arg]=USING_REG; - clear_ptr_cache_reg(arg); - regs[arg]=USING_REG; - } else if (is_double_reg(arg)) { - clear_ptr_cache_reg(arg); - regs[arg]=USING_REG; - clear_ptr_cache_reg(arg); - regs[arg]=USING_REG; - } } void @@ -2074,143 +1867,12 @@ static void use_input_reg(int reg,int mode) { - if (is_int_reg(reg)) { - if (ireg&® == ireg) { - if (creg==ireg) creg = 0; - ireg = 0; - } - if (lreg) { - if (lreg==reg) { - regs[lreg]=0; - if (lreg>reg&& - (regs[lreg]==USING_REG|| - regs[lreg]==USING_DREG)) - { - free_register(lreg); - } - if (creg==lreg) creg = ireg; - free_register(lreg); - lreg = 0; - } else if (lreg==reg) { - regs[lreg]=0; - if (lreg>reg && ( - (regs[lreg]==USING_REG) || - (regs[lreg]==USING_DREG) )) - { - free_register(lreg); - } - if (creg==lreg) creg = ireg; - free_register(lreg); - lreg = 0; - } - } - } else if (is_longlong_reg(reg)) { - use_input_reg(reg,0); - use_input_reg(reg,0); - } else if (is_double_reg(reg)) { - use_input_reg(reg,0); - use_input_reg(reg,0); - } else if (is_float_reg(reg)) { - if (freg&® == freg) { - if (creg==freg) creg = ireg; - freg = 0; - } - } + if (creg&® == creg) { + creg = 0; + } if (mode) use_reg(reg); } -static void -code_assign_input_float_int(int e1,int e2) { -#if FLOAT_CODE - int r,tmp=-1; - float f; - char *frn; - // e1 = e2; - if (car(e1)!=REGISTER) { error(-1); return; } - frn = register_name(r=cadr(e1)); - switch(car(e2)) { - case FCONST: - f = dcadr(e2); - code_const(*((int*)&f),r); - break; - case FRGVAR: - code_rgvar(e2,r); - break; - case FRLVAR: - code_rlvar(cadr(e2),r); - break; - default: - g_expr(rvalue_t(e2,FLOAT)); - case FREGISTER: - tmp = new_lvar(SIZE_OF_INT); - code_dassign_lvar(tmp, (car(e2)==FREGISTER)?cadr(e2):freg,0); - code_rlvar(tmp,r); - if (tmp!=-1) free_lvar(tmp); - } -#endif -} - -static void -code_assign_input_double_long(int e1,int e2) { -#if FLOAT_CODE - int r,tmp=-1,reg=0; - double value; - // e1 = e2; - if (car(e1)!=LREGISTER) { error(-1); return; } - r=cadr(e1); - switch(car(e2)) { - case DCONST: - value = dcadr(e2); - dconst(r,r,value); - break; - case DRGVAR: - code_lrgvar(e2,r); - break; - case DRLVAR: - code_lrlvar(cadr(e2),r); - break; - default: - g_expr(rvalue_t(e2,DOUBLE)); - reg = freg; - case DREGISTER: - if (car(e2)==DREGISTER) reg = cadr(e2); - //printf("\tstqd\t%s, #sp, #-8]!\n",register_name(reg)); - //printf("\tstqd\t%s, #sp, #-8]!\n",register_name(reg)); - //printf("\tldmfd\tsp!, {%s, %s}\n",lregister_name_low(r),lregister_name_high(r)); - printf("\tstqd\t%s, -8($sp)\n",register_name(reg)); - printf("\tstqd\t%s, -8($sp)\n",register_name(reg)); - printf("\tlqx\t$sp,%s, %s\n",lregister_name_low(r),lregister_name_high(r)); - } - if (tmp!=-1) free_lvar(tmp); -#endif -} - -static void -code_assign_input_double_reg(int e1,int e2) { -#if FLOAT_CODE - int r,tmp=-1,reg=0; - double value; - if(car(e1)!=REGISTER) { error(-1); return;} - r = cadr(e1); - switch(car(e2)) { - case DCONST: - value = dcadr(e2); - dconst(r,r,value); - break; - case DRGVAR: - code_lrgvar(e2,r); - break; - case DRLVAR: - code_lrlvar(cadr(e2),r); - break; - default: - g_expr(rvalue_t(e2,DOUBLE)); - reg = freg; - } - if(tmp!=-1) free_lvar(tmp); -#endif -} - static int compute_complex_arg(int e3,int reg_arg_list,int arg) { int t=caddr(e3); @@ -2219,37 +1881,18 @@ if (car(arg)==REGISTER||car(arg)==DREGISTER|| car(arg)==FREGISTER||car(arg)==LREGISTER) use_input_reg(cadr(arg),1); - if (t==FLOAT&&car(arg)==REGISTER) - code_assign_input_float_int(arg, e4); - else if (t==DOUBLE&&car(arg)==LREGISTER) - code_assign_input_double_long(arg, e4); - else - g_expr_u(assign_expr0(arg,e4,t,t)); + g_expr_u(assign_expr0(arg,e4,t,t)); car(e3) = arg; return reg_arg_list; } static void increment_function_arg(int e3,int *pnargs,int *preg_arg,int *pfreg_arg) { - int nargs=0,reg_arg=0,freg_arg=0; - int t=caddr(e3); - if(scalar(t)) { - nargs ++ ; reg_arg++; freg_arg++; - } else if (t==LONGLONG||t==ULONGLONG||t==DOUBLE) { - nargs ++ ; reg_arg++; - nargs ++ ; reg_arg++; - } else if (t==FLOAT) { - reg_arg ++ ; freg_arg++; - nargs += size(t)/SIZE_OF_INT; - } else if (t>=0&&(car(t)==STRUCT||car(t)==UNION)) { - nargs += round4(size(t))/SIZE_OF_INT; - } else { - error(TYERR); - nargs ++ ; - } + int nargs=0,reg_arg=0; + + nargs ++ ; reg_arg++; *pnargs += nargs; *preg_arg += reg_arg; - *pfreg_arg += freg_arg; } #define AS_SAVE 1 @@ -2268,25 +1911,29 @@ } else if (t==LONGLONG||t==ULONGLONG) { if (mode==AS_SAVE) { return get_lregister_var(0); - } else if (reg_arg+1>=MAX_INPUT_REGISTER_VAR) { + } else if (reg_arg>=MAX_INPUT_REGISTER_VAR) { return list3n(LVAR,caller_arg_offset_v(nargs),0); } else return get_input_lregister_var(reg_arg,0,0); } else if (t==FLOAT) { if (mode==AS_SAVE) { return get_dregister_var(0,0); - } else if (freg_arg>=MAX_INPUT_DREGISTER_VAR) { + } else if (reg_arg>=MAX_INPUT_REGISTER_VAR) { return list3n(LVAR,caller_arg_offset_v(nargs),0); } else return get_input_dregister_var(freg_arg,0,0,0); } else if (t==DOUBLE) { if (mode==AS_SAVE) { return get_dregister_var(0,1); - } else if (reg_arg+1>=MAX_INPUT_DREGISTER_VAR) { + } else if (reg_arg>=MAX_INPUT_DREGISTER_VAR) { return list3n(LVAR,caller_arg_offset_v(nargs),0); } else return get_input_dregister_var(reg_arg,0,0,1); } else if (t>=0&&(car(t)==STRUCT||car(t)==UNION)) { + // 16byte もあるんだから、ほとんどの構造体は、レジスタに + // 乗ってしまうらしい。なので、レジスタに乗っている前提の + // コードを書いた方が良いらしい... + // でも、strop を書き直さないと出来ない if (mode==AS_SAVE) { return get_register_var(0); } else @@ -2389,8 +2036,6 @@ /* now all input register vars are free */ code_save_stacks(); - // set_lreg(LREG_LREGISTER,0); - set_freg(FREG_FREGISTER,0); set_ireg(CREG_REGISTER,0); // Struct arguments need emit_copy. it destructs 3 input registers. @@ -2470,8 +2115,8 @@ reg_arg_list = list2(arg,reg_arg_list); if (car(arg)==REGISTER) { use_input_reg(cadr(arg),1); - //code_assign_input_double_long(arg, e4); - code_assign_input_double_reg(arg, e4); + + } else { g_expr_u(assign_expr0(arg,e4,t,t)); } @@ -2479,7 +2124,7 @@ reg_arg_list = list2(arg,reg_arg_list); if (car(arg)==REGISTER) { use_input_reg(cadr(arg),1);/* protect from input register free */ - code_assign_input_float_int(arg, e4); + } else { g_expr_u(assign_expr0(arg,e4,t,t)); /* XXX */ } @@ -2496,23 +2141,10 @@ for(i=1;i<MAX_INPUT_REGISTER_VAR;i++) { free_register(i); } - if (ret_type==DOUBLE) { -#if FLOAT_CODE - set_dreg(RET_DREGISTER,0); - use_reg(RET_DREGISTER); -#endif - } else if (ret_type==FLOAT) { -#if FLOAT_CODE - set_freg(RET_FREGISTER,0); -#endif - } else if (ret_type==ULONGLONG||ret_type==LONGLONG) { -#if LONGLONG_CODE - set_lreg(RET_LREGISTER,0); - use_reg(RET_LREGISTER); -#endif - } else if (ret_type==VOID) { + if (ret_type!=VOID) { + set_ireg(RET_REGISTER,0); + use_reg(RET_REGISTER); } else { - set_ireg(RET_REGISTER,0); } return ret_type; } @@ -2547,13 +2179,8 @@ void code_fix_frame_pointer(int env) { char *trn; - //int disp,label; - //int label; - int disp; if (is_function(fnptr) && ! env) { trn = register_name(REG_ip); - //disp = search_const(LVAR,glist2(lvar_offset_label,FUNC_LVAR(0)),&label); - // printf("\tlqd\t%s, %d($sp)\n",trn,disp); printf("\ta\t$sp, $sp, %s\n",trn); } } @@ -2562,12 +2189,9 @@ code_unfix_frame_pointer() { char *trn; - //int disp,label; - int disp; + trn = register_name(REG_ip); - //disp = search_const(LVAR,glist2(lvar_offset_label,FUNC_LVAR(0)),&label); - // printf("\tlqd\t%s, %d($sp)\n",trn,disp); printf("\tsf\tfp, fp, %s\n",trn); } @@ -2624,44 +2248,28 @@ lload(int creg,int reg,int offset) { char *crn=register_name(creg); -#if ENDIAN_L==0 - if (creg!=reg) { - printf("\tlqd\t%s, %d(%s)\n",lregister_name_low(reg),offset,crn); - //printf("\tldr\t%s, [%s, #%d]\n",lregister_name_high(reg),crn,offset+SIZE_OF_INT); - } else { - printf("\tlqd\t%s, %d(%s)\n",lregister_name_high(reg),offset+SIZE_OF_INT,crn); - //printf("\tldr\t%s, [%s, #%d]\n",lregister_name_low(reg),crn,offset); - } -#else - if (creg!=reg) { - printf("\tlqd\t%s, %d(%s)\n",lregister_name_low(reg),offset+SIZE_OF_INT,crn); - //printf("\tldr\t%s, [%s, #%d]\n",lregister_name_high(reg),crn,offset); - } else { - printf("\tlqd\t%s, %d(%s)\n",lregister_name_high(reg),offset,crn); - //printf("\tldr\t%s, [%s, #%d]\n",lregister_name_low(reg),crn,offset+SIZE_OF_INT); - } -#endif + printf("\tlqd\t%s, %d(%s)\n",register_name(reg),offset,crn); } static void lmove(int to,int from) { - int l; - l = list3(to,0,from); - l = list3(to,l,from); - parallel_rassign(l); + printf("\tori\t%s, %s, 0\n", + register_name(to),register_name(from)); + + } static void set_operands(int r0,int r1,int r2,int r3) { - int l; - l = list3(DREGISTER_OPERAND_L,0,r0); - l = list3(DREGISTER_OPERAND_H,l,r1); - l = list3(DREGISTER_OPERAND_1_L,l,r2); - l = list3(DREGISTER_OPERAND_1_H,l,r3); - parallel_rassign(l); + + + + + + } @@ -2669,17 +2277,7 @@ lstore(int e2,int creg) { char *drn = register_name(e2); - char *crn_h; - char *crn_l; - crn_h = lregister_name_high(creg); - crn_l = lregister_name_low(creg); -#if ENDIAN_L==0 - printf("\tstqd\t%s, 0(%s)\n",crn_l,drn); - printf("\tstqd\t%s, %d(%s)\n",crn_h,SIZE_OF_INT,drn); -#else - printf("\tstqd\t%s, 0(%s)\n",crn_h,drn); - printf("\tstqd\t%s, %d(%s)\n",crn_l,SIZE_OF_INT,drn); -#endif + printf("\tstqd\t%s, 0(%s)\n",register_name(creg),drn); } int @@ -2699,11 +2297,7 @@ static char * cstore(int sz) { - switch(sz) { - case 1: return "stqd"; - case SIZE_OF_SHORT: return "stqd"; - default: return "stqd"; - } + return "stqd"; } void @@ -3054,7 +2648,7 @@ )) return 0; if (car(caddr(e1))==CONST && is_stage1_const(cadr(caddr(e1)),CMP)) { g_expr(cadr(e1)); - reg0 = ireg; + reg0 = creg; use_int(reg); pcond(op, cadr(caddr(e1)),reg0,reg,1,0,COND_VALUE_CONST); } else { @@ -3062,7 +2656,7 @@ emit_push(); g_expr(caddr(e1)); e2 = emit_pop(1); - reg0 = ireg; + reg0 = creg; use_int(reg); pcond(op, reg0,e2,reg,1,0,COND_VALUE); emit_pop_free(e2); @@ -3078,13 +2672,13 @@ if (car(caddr(e1))==CONST && is_stage1_const(cadr(caddr(e1)),CMP)) { g_expr(cadr(e1)); - pcond(op, cadr(caddr(e1)),ireg,0,cond,l1,COND_BRANCH_CONST); + pcond(op, cadr(caddr(e1)),creg,0,cond,l1,COND_BRANCH_CONST); } else { g_expr(cadr(e1)); emit_push(); g_expr(caddr(e1)); e2 = emit_pop(1); - pcond(op, ireg,e2,0,cond,l1,COND_BRANCH); + pcond(op, creg,e2,0,cond,l1,COND_BRANCH); emit_pop_free(e2); } return l1; @@ -3112,40 +2706,20 @@ { printf("## %s",s); } -/* -static int -code_register_save(int reg_save,int freg_save,int disp) -{ - int i; - printf("\tstmfd\tsp!, {"); - for (i=reg_var_num(0);i<reg_var_num(reg_save);i++) { - printf("%s, ",register_name(i)); - } - printf("fp, ip, lr, pc}\n"); - if (freg_save>0) { - printf("\tsfmfd\tf4, %d, [sp]!\n",freg_save); - } - return disp; -} -*/ static int code_register_restore(int reg_save,int freg_save,int disp) { int i; if (freg_save>0) { - i=reg_save*SIZE_OF_INT+ + i=reg_save*SIZE_OF_INT+ freg_save*SIZE_OF_DOUBLE + 20; - //printf("\tlfm\tf4, %d, [fp, #%d]\n",freg_save,-i); - printf("\tlqd\t$sp,%d($sp)\n",i); + printf("\tlqd\t$sp,%d($sp)\n",i); } - //printf("\tldmea\tfp, {"); for (i=reg_var_num(0);i<reg_var_num(reg_save);i++) { - //printf("%s, ",register_name(i)); - printf("\tlqd\t%s,-%d($sp)\n",register_name(i),-disp); + printf("\tlqd\t%s,-%d($sp)\n",register_name(i),-disp); disp -= SIZE_OF_FLOAT*4; } - //printf("fp, sp, pc}\n"); return disp; } @@ -3173,9 +2747,7 @@ void code_enter1(int args) { - // set_lreg(LREG_LREGISTER,0); set_ireg(CREG_REGISTER,0); - set_freg(FREG_FREGISTER,0); } void @@ -3215,9 +2787,7 @@ enter1() { text_mode(0); - // set_lreg(LREG_LREGISTER,0); set_ireg(CREG_REGISTER,0); - set_freg(FREG_FREGISTER,0); } void @@ -3249,13 +2819,13 @@ fwddef(retcont); if (cadr(fnptr->ty)==FLOAT) { #if FLOAT_CODE - creg = freg = cadr(get_input_dregister_var(0,0,1,0)); - set_freg(RET_FREGISTER,1); + creg = cadr(get_input_dregister_var(0,0,1,0)); + set_ireg(RET_REGISTER,1); #endif } else if (cadr(fnptr->ty)==DOUBLE) { #if FLOAT_CODE - creg = lreg = cadr(get_input_dregister_var(0,0,1,1)); - set_dreg(RET_DREGISTER,1); + creg = cadr(get_input_dregister_var(0,0,1,1)); + set_ireg(RET_REGISTER,1); #endif } else if (cadr(fnptr->ty)>0&&( car(cadr(fnptr->ty))==STRUCT || @@ -3266,7 +2836,7 @@ printf("\tlqd\t$1, %d($sp)\n",(my_func_args-1)*SIZE_OF_INT); emit_copy(6,3,sz,0,1,1); } else if (cadr(fnptr->ty)!=VOID) { - creg = ireg = cadr(get_input_register_var(0,0,1)); + creg = cadr(get_input_register_var(0,0,1)); if (creg!=RET_REGISTER) set_ireg(RET_REGISTER,1); } @@ -3284,9 +2854,8 @@ fwddef(entry_label); if (arg_on_register>0) printf("\tsfi\t$sp, $sp, %d\n",arg_on_register); - //code_register_save(max_reg_var,max_reg_var,0); - - //printf("\tsf\tfp, ip, #%d\n",4+arg_on_register); + // code_register_save(max_reg_var,max_reg_var,0); + code_add(REG_sp,disp-max_func_args*SIZE_OF_INT,REG_sp); gen_jmp(register_save_return_label); local_table(); @@ -3299,77 +2868,30 @@ int code_set_return_register(int mode) { - if (cadr(fnptr->ty)==FLOAT) { - set_freg(RET_FREGISTER,mode); - return ireg; - } else if (cadr(fnptr->ty)==DOUBLE) { -#if FLOAT_CODE - set_dreg(RET_DREGISTER,mode); - return ireg; -#endif - } else if (cadr(fnptr->ty)==LONGLONG||cadr(fnptr->ty)==ULONGLONG) { -#if LONGLONG_CODE - set_lreg(RET_LREGISTER,mode); - return ireg; -#endif - } else if (cadr(fnptr->ty)==VOID) { - return ireg; - } else { - set_ireg(RET_REGISTER,mode); - return ireg; - } + set_ireg(RET_REGISTER,mode); + return creg; } int code_get_fixed_creg(int reg,int type) { - switch(type) { -#if FLOAT_CODE - case DOUBLE: use_float(1,reg); break; - case FLOAT: use_float(0,reg); break; -#endif -#if LONGLONG_CODE - case LONGLONG: case ULONGLONG: use_longlong(reg); break; -#endif - default: - if (reg==USE_CREG) { - if (regs[CREG_REGISTER]==0||regs[CREG_REGISTER]==PTRC_REG) { - set_ireg(CREG_REGISTER,is_int_reg(creg)&®s[creg]==USING_REG); - return CREG_REGISTER; - } - } - use_int(reg); - break; + if (reg==USE_CREG) { + if (regs[CREG_REGISTER]==0||regs[CREG_REGISTER]==PTRC_REG) { + set_ireg(CREG_REGISTER,regs[creg]==USING_REG); + return CREG_REGISTER; + } } + use_int(reg); return reg; } void code_set_fixed_creg(int reg,int mode,int type) { - if (type==FLOAT) { -#if FLOAT_CODE - set_freg(reg,mode); -#endif - } else if (type==DOUBLE) { -#if FLOAT_CODE - set_dreg(reg,mode); -#endif - } else if (type==LONGLONG||type==ULONGLONG) { -#if LONGLONG_CODE - set_lreg(reg,mode); - // use_reg(reg); -#endif - } else { - set_ireg(reg,mode); - } + set_ireg(reg,mode); } void gen_gdecl(char *n, int gpc) { - /* - if (stmode!=STATIC) - printf(".globl %s\n",n); - */ } void @@ -3442,7 +2964,7 @@ cstring_mode(); } else data_mode(n->nm); - align(a); + code_align(a); if (n && n->sc!=STATIC) printf("\t.globl\t%s\n",n->nm); printf("%s:\n",n->nm); @@ -3473,7 +2995,7 @@ emit_int(int d) { data_mode(0); - align(0); + code_align(0); printf("\t.word %d\n",d); } @@ -3772,12 +3294,6 @@ return *j; } -static void -dconst(int l,int h,double value) -{ - code_dconst(code_d2(value),h,1); -} - void code_dconst(int e2,int freg,int d) @@ -3803,8 +3319,6 @@ #endif printf("\tlqd\t%s, .LC%d+%d($sp)\n",frn,label,disp); } else { - //disp = search_const(CONST,*((int*)&f),&label); - //printf("\tlqd\t%s, .LC%d+%d($sp)\n",frn,label,disp); } } @@ -3852,9 +3366,9 @@ int lreg; use_int(reg); lreg = get_dregister(1); - printf("\tflt%c\t%s, %s\n",dsuffix(d), + printf("\tflt\t%s, %s\n", register_name(lreg),register_name(reg)); - set_dreg(lreg,0); + set_ireg(lreg,0); return; } @@ -3870,7 +3384,7 @@ emit_dpush(1); code_dconst(dlist2(DCONST,2.147483648e9),USE_CREG,1); lrn = register_name(lreg = emit_dpop(d)); - frn = register_name(freg); + frn = register_name(creg); set_ireg(reg0=get_register(),0); crn = register_name(reg0); printf("\tcmfe\t%s, %s\n",lrn,frn); @@ -3893,7 +3407,7 @@ char *crn,*frn,*lrn; use_int(reg); crn = register_name(reg); - set_dreg(reg=get_dregister(1),0); + set_ireg(reg=get_dregister(1),0); frn = register_name(reg); printf("\tfltd\t%s, %s\n",frn,crn); printf("\tceqi\t%s, %s, 0\n",crn,crn); @@ -3913,7 +3427,7 @@ void code_d2f(int reg) { char *frn; - frn = register_name(freg); + frn = register_name(creg); printf("\tmvfs\t%s,%s\n",frn,frn); return; } @@ -3921,7 +3435,7 @@ void code_f2d(int reg) { char *frn; - frn = register_name(freg); + frn = register_name(creg); printf("\tori\t%s, %s, 0\n",frn,frn); return; } @@ -4051,13 +3565,13 @@ xreg=emit_dpop(d); - crn=register_name(ireg); + crn=register_name(creg); use_float(d,reg); frn =register_name(reg); - code_ldf(fload(d),register_name(freg),0,ireg,""); + code_ldf(fload(d),register_name(creg),0,creg,""); dtosop(op,reg,xreg); - code_ldf(fstore(d),register_name(freg),0,ireg,""); + code_ldf(fstore(d),register_name(creg),0,creg,""); emit_dpop_free(xreg,d); } @@ -4074,7 +3588,7 @@ code_dload_1(int d) { int g = get_dregister(d); - printf("\tmvf%c\t%s,#1\n",dsuffix(d),register_name(g)); + printf("\tmvf\t%s,#1\n",register_name(g)); return g; } @@ -4092,28 +3606,28 @@ grn=register_name(g=code_dload_1(d)); if (reg==USE_CREG) { reg=get_dregister(d); if (!reg) error(-1); - if (d) set_dreg(reg,0); else set_freg(reg,0); + set_ireg(reg,0); } frn=register_name(reg); - printf("\t%s%c\t%s, %s, %s\n", - dir>0?"adf":"suf",dsuffix(d), + printf("\t%s\t%s, %s, %s\n", + dir>0?"adf":"suf", crn,crn,grn); if (use && reg!=cadr(e2)) { - printf("\tmvf%c\t%s, %s\n",dsuffix(d),frn,crn); + printf("\tmvf\t%s, %s\n",frn,crn); } } else { g_expr(e2); if (!is_int_reg(creg)) error(-1); - reg0 = ireg; + reg0 = creg; if (reg==USE_CREG) { reg=get_dregister(d); if (!reg) error(-1); - if (d) set_dreg(reg,0); else set_freg(reg,0); + set_ireg(reg,0); } grn = register_name(g = code_dload_1(d)); frn=register_name(reg); code_ldf(fload(d),frn,0,reg0,""); - printf("\t%s%c\t%s, %s, %s\n", - dir>0?"adf":"suf",dsuffix(d), + printf("\t%s\t%s, %s, %s\n", + dir>0?"adf":"suf", frn,frn,grn); code_ldf(fstore(d),frn,0,reg0,""); } @@ -4133,27 +3647,27 @@ grn=register_name(g=code_dload_1(d)); if (reg==USE_CREG) { reg=get_dregister(d); if (!reg) error(-1); - set_freg(reg,0); + set_ireg(reg,0); } frn=register_name(reg); if (use && reg!=cadr(e2)) { - printf("\tmvf%c\t%s, %s\n",dsuffix(d),frn,crn); + printf("\tmvf\t%s, %s\n",frn,crn); } - printf("\t%s%c\t%s,%s,%s\n",dir>0?"adf":"suf", - dsuffix(d),crn,crn,grn); + printf("\t%s\t%s,%s,%s\n",dir>0?"adf":"suf", + crn,crn,grn); } else { g_expr(e2); if (!is_int_reg(creg)) error(-1); - crn=register_name(reg0=ireg); + crn=register_name(reg0=creg); if (reg==USE_CREG) { reg=get_dregister(d); if (!reg) error(-1); - set_freg(reg,0); + set_ireg(reg,0); } frn=register_name(reg); grn = register_name(g = code_dload_1(d)); code_ldf(fload(d),frn,0,reg0,""); - printf("\t%s%c\t%s, %s, %s\n", - dir>0?"adf":"suf",dsuffix(d), + printf("\t%s\t%s, %s, %s\n", + dir>0?"adf":"suf", grn,frn,grn); code_ldf(fstore(d),grn,0,reg0,""); } @@ -4229,8 +3743,8 @@ if (!is_float_reg(creg)) error(-1); if (reg_sp>MAX_MAX) error(-1); new_reg = get_dregister(d); /* ?????????? */ - reg_stack[reg_sp++] = freg; /* push ???????????????? */ - creg = freg = new_reg; + reg_stack[reg_sp++] = creg; /* push ???????????????? */ + creg = new_reg; } #endif @@ -4255,8 +3769,8 @@ emit_lpush(); g_expr(e2); e3 = emit_lpop(); - if (!is_longlong_reg(creg)) error(-1); - reg = lreg; + + reg = creg; l2 = fwdlabel(); regh = reg; regl = reg; e3h = e3; e3l = e3; @@ -4288,10 +3802,10 @@ code_cmp_lregister(int reg,int label,int cond) { use_longlong(reg); - printf("\torc\t%s, %s, %s\n", - lregister_name_low(reg), - lregister_name_low(reg), - lregister_name_high(reg)); + + + + code_cmp_register((reg),label,cond); } @@ -4351,32 +3865,32 @@ int r; use_longlong(creg); r = get_ptr_cache(ncaddr(e2)); -#if ENDIAN_L==0 - code_ldf(cstore(0),lregister_name_low(creg),cadr(e2),r,""); - code_ldf(cstore(0),lregister_name_high(creg),cadr(e2)+SIZE_OF_INT,r,""); -#else - code_ldf(cstore(0),lregister_name_high(creg),cadr(e2),r,""); - code_ldf(cstore(0),lregister_name_low(creg),cadr(e2)+SIZE_OF_INT,r,""); -#endif + + code_ldf(cstore(0),register_name(creg),cadr(e2),r,""); + + + + + } void code_lassign_lvar(int e2,int creg) { - char *crn_h; - char *crn_l; + char *crn; + use_longlong(creg); - crn_h = lregister_name_high(creg); - crn_l = lregister_name_low(creg); + crn = register_name(creg); + lvar_intro(e2); -#if ENDIAN_L==0 - printf("\tstqd\t%s, ",crn_l);lvar(e2,""); - printf("\tstqd\t%s, ",crn_h);lvar(e2+SIZE_OF_INT,""); -#else - printf("\tstqd\t%s, ",crn_h);lvar(e2,""); - printf("\tstqd\t%s, ",crn_l);lvar(e2+SIZE_OF_INT,""); -#endif + + printf("\tstqd\t%s, ",crn);lvar(e2,""); + + + + + } void @@ -4403,39 +3917,39 @@ if (reg_sp>MAX_MAX) error(-1); new_reg = get_lregister(); /* ??????????(?) */ reg_stack[reg_sp++] = creg; /* push ???????????????? */ - lreg = creg = new_reg; + creg = new_reg; } void code_lrgvar(int e1,int creg) { int r; - char *crn_h; - char *crn_l; + char *crn; + use_longlong(creg); - crn_h = lregister_name_high(creg); - crn_l = lregister_name_low(creg); + crn = register_name(creg); + r = get_ptr_cache(ncaddr(e1)); -#if ENDIAN_L==0 - code_ldf("lqd",crn_l,cadr(e1),r,""); - //code_ldf("ldr",crn_h,cadr(e1)+SIZE_OF_INT,r,""); -#else - code_ldf("lqd",crn_h,cadr(e1),r,""); - //code_ldf("ldr",crn_l,cadr(e1)+SIZE_OF_INT,r,""); -#endif + + code_ldf("lqd",crn,cadr(e1),r,""); + + + + + } void code_lrlvar(int e1,int creg) { - char *crn_h; - char *crn_l; + char *crn; + use_longlong(creg); - crn_h = lregister_name_high(creg); - crn_l = lregister_name_low(creg); + crn = register_name(creg); + lvar_intro(e1); - printf("\tlqd\t%s, ",crn_l); lvar(e1,""); - printf("\tlqd\t%s, ",crn_h); lvar(e1+SIZE_OF_INT,""); + printf("\tlqd\t%s, ",crn); lvar(e1,""); + } #endif @@ -4468,11 +3982,11 @@ code_lneg(int creg) { - char *rh,*rl; + char *rh; use_longlong(creg); - rl=lregister_name_low(creg); - rh=lregister_name_high(creg); - printf("\trsbs\t%s, %s, #0\n",rl,rl); + rh=register_name(creg); + + printf("\trsc\t%s, %s, #0\n",rh,rh); } @@ -4483,18 +3997,17 @@ clear_ptr_cache(); set_operands((reg),(reg),(oreg),(oreg)); extern_conv(lib); - // set_lreg(RET_LREGISTER,0); -} - -#define check_lreg(reg) lmove(reg,RET_LREGISTER) +} + +#define check_lreg(reg) lmove(reg,RET_REGISTER) void ltosop(int op,int reg,int oreg) { int dx = -1; int ox = -1; - char *orn_h,*crn_h; - char *orn_l,*crn_l; + char *orn, *crn; + // reg = reg op oreg @@ -4526,33 +4039,33 @@ if(ox!=-1) free_register(ox); return; } - orn_h = lregister_name_high(oreg); - orn_l = lregister_name_low(oreg); - crn_h = lregister_name_high(reg); - crn_l = lregister_name_low(reg); + orn = register_name(oreg); + + crn = register_name(reg); + switch(op) { case LADD: - printf("\tadds\t%s, %s, %s\n",crn_l,crn_l,orn_l); - printf("\tadc\t%s, %s, %s\n",crn_h,crn_h,orn_h); + printf("\tadds\t%s, %s, %s\n",crn,crn,orn); + break; case LSUB: - printf("\tsubs\t%s, %s, %s\n",crn_l,crn_l,orn_l); - printf("\tsbc\t%s, %s, %s\n",crn_h,crn_h,orn_h); + printf("\tsubs\t%s, %s, %s\n",crn,crn,orn); + break; case LCMP: error(-1); break; case LBAND: - printf("\tand\t%s, %s, %s\n",crn_l,crn_l,orn_l); - printf("\tand\t%s, %s, %s\n",crn_h,crn_h,orn_h); + printf("\tand\t%s, %s, %s\n",crn,crn,orn); + break; case LEOR: - printf("\teor\t%s, %s, %s\n",crn_l,crn_l,orn_l); - printf("\teor\t%s, %s, %s\n",crn_h,crn_h,orn_h); + printf("\teor\t%s, %s, %s\n",crn,crn,orn); + break; case LBOR: - printf("\tor\t%s, %s, %s\n",crn_l,crn_l,orn_l); - printf("\tor\t%s, %s, %s\n",crn_h,crn_h,orn_h); + printf("\tor\t%s, %s, %s\n",crn,crn,orn); + break; case LMUL: case LUMUL: @@ -4611,16 +4124,16 @@ void loprtc(int op,int creg,int e) { - char *crn_h; - char *crn_l; + char *crn; + char *grn; int v=0; int vh=0; int greg,dx=-1; use_longlong(creg); - crn_h = lregister_name_high(creg); - crn_l = lregister_name_low(creg); + crn = register_name(creg); + if (car(e)==LCONST) { v = lcadr(e); vh = lcadr(e)>>32; } else if (car(e)==CONST) { @@ -4639,18 +4152,18 @@ code_const(0,(creg)); return; } else if (v>31) { - //printf("\tmov\t%s, %s, lsl #%d\n",crn_h,crn_l,v-32); + // 右シフト - printf("\troti\t%s,%s,%d\n",crn_h,crn_h,96-v); + printf("\troti\t%s,%s,%d\n",crn,crn,96-v); code_const(0,(creg)); return; } greg = get_register(); grn = register_name(greg); - printf("\tshli\t%s, %s, %d\n",crn_h,crn_h,v); - printf("\troti\t%s, %s, -%d\n",grn,crn_l,32-v); - printf("\torc\t%s, %s,%s\n",crn_h,crn_h,grn); - printf("\tshli\t%s, %s,%d\n",crn_l,crn_l,v); + printf("\tshli\t%s, %s, %d\n",crn,crn,v); + printf("\troti\t%s, %s, -%d\n",grn,crn,32-v); + printf("\torc\t%s, %s,%s\n",crn,crn,grn); + printf("\tshli\t%s, %s,%d\n",crn,crn,v); free_register(greg); return; case LDIV: @@ -4659,19 +4172,19 @@ if (v==0) return; if (v==32) { code_register((creg),(creg)); - printf("\tshli\t%s, %s, 31\n",crn_h,crn_l); + printf("\tshli\t%s, %s, 31\n",crn,crn); return; } else if (v>31) { - printf("\t\t%s, %s, asr #%d\n",crn_l,crn_h,v-32); - printf("\tshl\t%s, %s, 31\n",crn_h,crn_l); + printf("\t\t%s, %s, asr #%d\n",crn,crn,v-32); + printf("\tshl\t%s, %s, 31\n",crn,crn); return; } greg = get_register(); grn = register_name(greg); - printf("\troti \t%s, %s, %d\n",crn_l,crn_l,v); - printf("\troti\t%s, %s, %d\n",grn,crn_h,160-v); - printf("\tor\t%s, %s,%s\n",crn_l,crn_l,grn); - printf("\tshli\t%s, %s, %d\n",crn_h,crn_h,v); + printf("\troti \t%s, %s, %d\n",crn,crn,v); + printf("\troti\t%s, %s, %d\n",grn,crn,160-v); + printf("\tor\t%s, %s,%s\n",crn,crn,grn); + printf("\tshli\t%s, %s, %d\n",crn,crn,v); free_register(greg); return; case LUDIV: @@ -4683,37 +4196,37 @@ code_const(0,(creg)); return; } else if (v>31) { - printf("\tmov\t%s, %s, lsr #%d\n",crn_l,crn_h,v-32); + printf("\tmov\t%s, %s, lsr #%d\n",crn,crn,v-32); code_const(0,(creg)); return; } greg = get_register(); grn = register_name(greg); - printf("\troti\t%s, %s, %d\n",grn,crn_h,96-v); - printf("\troti\t%s, %s, %d\n",crn_l,crn_l,v); - printf("\tor\t%s, %s,%s\n",crn_l,grn,crn_l); - printf("\troti\t%s, %s, %d\n",crn_h,crn_h,v); + printf("\troti\t%s, %s, %d\n",grn,crn,96-v); + printf("\troti\t%s, %s, %d\n",crn,crn,v); + printf("\tor\t%s, %s,%s\n",crn,grn,crn); + printf("\troti\t%s, %s, %d\n",crn,crn,v); free_register(greg); return; case LADD: - printf("\tadds\t%s, %s, #%d\n",crn_l,crn_l,v); - printf("\tadc\t%s, %s, #%d\n",crn_h,crn_h,vh); + printf("\tadds\t%s, %s, #%d\n",crn,crn,v); + printf("\tadc\t%s, %s, #%d\n",crn,crn,vh); break; case LSUB: - printf("\tsubs\t%s, %s, #%d\n",crn_l,crn_l,v); - printf("\tsbc\t%s, %s, #%d\n",crn_h,crn_h,vh); + printf("\tsubs\t%s, %s, #%d\n",crn,crn,v); + printf("\tsbc\t%s, %s, #%d\n",crn,crn,vh); break; case LBAND: - printf("\tandi\t%s, %s, %d\n",crn_l,crn_l,v); - printf("\tandi\t%s, %s, %d\n",crn_h,crn_h,vh); + printf("\tandi\t%s, %s, %d\n",crn,crn,v); + printf("\tandi\t%s, %s, %d\n",crn,crn,vh); break; case LEOR: - printf("\teor\t%s, %s, #%d\n",crn_l,crn_l,v); - printf("\teor\t%s, %s, #%d\n",crn_h,crn_h,vh); + printf("\teor\t%s, %s, #%d\n",crn,crn,v); + printf("\teor\t%s, %s, #%d\n",crn,crn,vh); break; case LBOR: - printf("\tori\t%s, %s, %d\n",crn_l,crn_l,v); - printf("\tori\t%s, %s, %d\n",crn_h,crn_h,vh); + printf("\tori\t%s, %s, %d\n",crn,crn,v); + printf("\tori\t%s, %s, %d\n",crn,crn,vh); break; default: error(-1); @@ -4725,15 +4238,15 @@ void code_i2ll(int reg) { - char *crn,*crn_h,*crn_l; + char *crn; int reg0; - crn = register_name(reg0 = ireg); + crn = register_name(reg0 = creg); use_longlong(reg); - crn_h = lregister_name_high(lreg); - crn_l = lregister_name_low(lreg); - if (reg0!=(lreg)) - printf("\tori\t%s, %s, 0\n",crn_l,crn); - printf("\tshli\t%s, %s, 31\n",crn_h,crn_l); + + + if (reg0!=(creg)) + printf("\tori\t%s, %s, 0\n",crn,crn); + printf("\tshli\t%s, %s, 31\n",crn,crn); } void @@ -4745,15 +4258,15 @@ void code_u2ll(int reg) { - char *crn,*crn_h,*crn_l; + char *crn; int reg0; - crn = register_name(reg0 = ireg); + crn = register_name(reg0 = creg); use_longlong(reg); - crn_h = lregister_name_high(lreg); - crn_l = lregister_name_low(lreg); - if (reg0!=(lreg)) - printf("\tori\t%s, %s, 0\n",crn_l,crn); - printf("\tmov\t%s, #0\n",crn_h); + + + if (reg0!=(creg)) + printf("\tori\t%s, %s, 0\n",crn,crn); + printf("\tmov\t%s, #0\n",crn); } void @@ -4765,12 +4278,12 @@ void code_ll2i(int reg) { - char *crn_l; + char *crn; int reg0; - crn_l = lregister_name_low(reg0=lreg); + crn = register_name(reg0=creg); use_int(reg); - if (ireg!=(reg0)) { - printf("\tori\t%s, %s, 0\n",register_name(ireg),crn_l); + if (creg!=(reg0)) { + printf("\tori\t%s, %s, 0\n",register_name(creg),crn); } } @@ -4798,11 +4311,9 @@ code_d2ll(int reg) { // fixdfdi$stub - code_assign_input_double_long( - list2(LREGISTER,LREGISTER_OPERAND),list2(FREGISTER,freg)) ; extern_conv("__fixdfdi"); - set_lreg(RET_LREGISTER,0); - if (reg!=USE_CREG&®!=RET_LREGISTER) { + set_ireg(RET_REGISTER,0); + if (reg!=USE_CREG&®!=RET_REGISTER) { use_longlong(reg); } } @@ -4810,11 +4321,9 @@ void code_d2ull(int reg) { - code_assign_input_double_long( - list2(LREGISTER,LREGISTER_OPERAND),list2(FREGISTER,freg)) ; extern_conv("__fixunsdfdi"); - set_lreg(RET_LREGISTER,0); - if (reg!=USE_CREG&®!=RET_LREGISTER) { + set_ireg(RET_REGISTER,0); + if (reg!=USE_CREG&®!=RET_REGISTER) { use_longlong(reg); } } @@ -4822,10 +4331,9 @@ void code_f2ll(int reg) { - code_assign_input_float_int(list2(REGISTER,REGISTER_OPERAND),list2(FREGISTER,freg)); extern_conv("__fixsfdi"); - set_lreg(RET_LREGISTER,0); - if (reg!=USE_CREG&®!=RET_LREGISTER) { + set_ireg(RET_REGISTER,0); + if (reg!=USE_CREG&®!=RET_REGISTER) { use_longlong(reg); } } @@ -4833,10 +4341,9 @@ void code_f2ull(int reg) { - code_assign_input_float_int(list2(REGISTER,REGISTER_OPERAND),list2(FREGISTER,freg)); extern_conv("__fixunssfdi"); - set_lreg(RET_LREGISTER,0); - if (reg!=USE_CREG&®!=RET_LREGISTER) { + set_ireg(RET_REGISTER,0); + if (reg!=USE_CREG&®!=RET_REGISTER) { use_longlong(reg); } } @@ -4844,10 +4351,10 @@ void code_ll2d(int reg) { - set_lreg(LREGISTER_OPERAND,1); + set_ireg(REGISTER_OPERAND,1); extern_conv("__floatdidf"); - set_dreg(RET_DREGISTER,0); - if (reg!=USE_CREG&®!=RET_FREGISTER) + set_ireg(RET_REGISTER,0); + if (reg!=USE_CREG&®!=RET_REGISTER) use_float(1,reg); } @@ -4855,10 +4362,10 @@ void code_ll2f(int reg) { - set_lreg(LREGISTER_OPERAND,1); + set_ireg(REGISTER_OPERAND,1); extern_conv("__floatdisf"); - set_freg(RET_FREGISTER,0); - if (reg!=USE_CREG&®!=RET_FREGISTER) + set_ireg(RET_REGISTER,0); + if (reg!=USE_CREG&®!=RET_REGISTER) use_float(0,reg); } @@ -4881,15 +4388,11 @@ { // v should be 8bit const with 2's shift if (v>0) { - printf("\tadds\t%s, %s, #%d\n", - lregister_name_low(rreg),lregister_name_low(dreg), v); - printf("\tadc\t%s, %s, #0\n", - lregister_name_high(rreg),lregister_name_high(dreg)); + printf("\taddq\t%s, %s, #%d\n", + register_name(rreg),register_name(dreg), v); } else { - printf("\tsubs\t%s, %s, #%d\n", - lregister_name_low(rreg),lregister_name_low(dreg), -v); - printf("\tsbc\t%s, %s, #0\n", - lregister_name_high(rreg),lregister_name_high(dreg)); + printf("\tsubq\t%s, %s, #%d\n", + register_name(rreg),register_name(dreg), -v); } } @@ -4911,7 +4414,7 @@ emit_push(); if (reg==USE_CREG) { dreg=get_lregister(); if (!dreg) error(-1); - set_lreg(dreg,0); // free old lreg==creg + set_ireg(dreg,0); // free old lreg==creg } else { dreg = reg; } @@ -4940,7 +4443,7 @@ nreg=get_lregister(); if (!nreg) error(-1); if (reg==USE_CREG) { dreg=get_lregister(); if (!dreg) error(-1); - set_lreg(dreg,0); // free old lreg==creg + set_ireg(dreg,0); // free old lreg==creg } else { dreg = reg; } @@ -4961,10 +4464,10 @@ // (*creg) op = pop() xreg = emit_lpop(0); /* pop e3 value */ if (!is_int_reg(creg)) error(-1); - edx = ireg; + edx = creg; emit_push(); use_longlong(reg); - if ((lreg)==edx || (lreg)==edx) { + if ((creg)==edx) { edx0 = get_register(); if(!edx0) error(-1); printf("## lassop\n\tori\t%s, %s, 0\n",register_name(edx0), register_name(edx)); @@ -4980,7 +4483,7 @@ emit_pop_free(edx); if (edx0!=-1) free_register(edx0); - if (reg!=lreg) + if (reg!=creg) free_register(reg); } @@ -5002,31 +4505,11 @@ for(i=0;i<reg_sp;i++) { if ((reg=reg_stack[i])>=0) { code_assign_lvar( - (reg_stack[i]=new_lvar(SIZE_OF_INT)),reg,0); + (reg_stack[i]=new_lvar(SIZE_OF_VECTOR)),reg,0); reg_stack[i]= reg_stack[i]-REG_LVAR_OFFSET; free_register(reg); } } -#if FLOAT_CODE - for(i=0;i<reg_sp;i++) { - if ((reg=reg_stack[i])>=0) { - code_dassign_lvar( - (reg_stack[i]=new_lvar(SIZE_OF_DOUBLE)),reg,1); - reg_stack[i]= reg_stack[i]-REG_LVAR_OFFSET; - free_register(reg); - } - } -#endif -#if LONGLONG_CODE - for(i=0;i<reg_sp;i++) { - if ((reg=reg_stack[i])>=0) { - code_lassign_lvar( - (reg_stack[i]=new_lvar(SIZE_OF_LONGLONG)),reg); - reg_stack[i]= reg_stack[i]-REG_LVAR_OFFSET; - free_register(reg); - } - } -#endif } void @@ -5041,7 +4524,6 @@ code_closing() { global_table(); - /* printf("\t.ident \"Micro-C compiled\"\n"); */ } #if CASE_CODE @@ -5510,8 +4992,8 @@ code_register(adr,tmp2); adr = tmp2; lload(adr,lvalue,0); use_longlong(value); - crn = lregister_name_high(value); - lrn = lregister_name_high(lvalue); + crn = register_name(value); + lrn = register_name(lvalue); /* shift left */ if (bitpos) loprtc(LLSHIFT,value,list2(CONST,bitpos)); @@ -5521,8 +5003,8 @@ mask = make_mask(64-bitpos-bitsize,bitpos>=32?63-bitpos:31); make_mask_and_or(mask,tmp,trn,crn,lrn); } - crn = lregister_name_low(value); - lrn = lregister_name_low(lvalue); + crn = register_name(value); + lrn = register_name(lvalue); if (bitpos<32) { /* make and-mask lower */ mask = make_mask(bitpos+bitsize>=32?0:32-bitpos-bitsize,31-bitpos); @@ -5547,9 +5029,9 @@ if (i) oprtc(LSHIFT,(value),list2(CONST,i)); if (i<0||32<=i) error(-1); - crn = lregister_name_low(value); + crn = register_name(value); code_ld(cload(0,0),(value),0,adr,cext_at(0,0)); - lrn = lregister_name_high(value); + lrn = register_name(value); mask = make_mask(0,31-bitpos); make_mask_and_or(mask,tmp,trn,crn,lrn); printf("\t%s\t%s, 0(%s)\n",cstore(0),crn,register_name(adr)); @@ -5657,7 +5139,7 @@ use_int(adr); lvalue = get_lregister(); lload(adr,lvalue,0); - crn = lregister_name_high(lvalue); + crn = register_name(lvalue); /* shift left */ lc = lcadr(value); lc <<= bitpos; @@ -5666,7 +5148,7 @@ mask = make_mask(64-bitpos-bitsize,bitpos>=32?63-bitpos:31); make_mask_and_or_const(mask,crn,(int)(lc>>32)); } - crn = lregister_name_low(lvalue); + crn = register_name(lvalue); if (bitpos<32) { /* make and-mask lower */ mask = make_mask(bitpos+bitsize>=32?0:32-bitpos-bitsize,31-bitpos);