Mercurial > hg > CbC > old > device
changeset 263:c922bade771d
MIPS go on...
author | kono |
---|---|
date | Sun, 16 May 2004 20:11:48 +0900 |
parents | df917628e532 |
children | 7de200d88747 |
files | Changes mc-code-ia32.c mc-code-mips.c mc-code-powerpc.c mc-code.h |
diffstat | 5 files changed, 153 insertions(+), 91 deletions(-) [+] |
line wrap: on
line diff
--- a/Changes Sat May 15 23:09:36 2004 +0900 +++ b/Changes Sun May 16 20:11:48 2004 +0900 @@ -4235,3 +4235,67 @@ 使うしかないらしい。 add.s の浮動小数点レジスタが印字されないけど。 + +Sun May 16 13:58:42 JST 2004 + +問題はレジスタのsaveだね。使ったレジスタはコード生成の後で +しかわからないので。後方にjmp すればいいんだけど。どんな +風に? + + subu $sp,$sp,$L_r1_offset + .cprestroe + sw $fp,$L_r1_offset-16($sp) + sw $31,$L_r1_offset-160($sp) + addu $fp,$sp,$L_r1_offset + jal $L_save-$L_save_label*4 + addu $fp,$fp,$L_fregister_save + jal $L_fsave-$L_fsave_label*4 + move $fp,$sp + + ... + sw $17,-12($fp) + sw $16,-8($fp) +$L_save: + j $31 +... + s.s $f22,-16($fp) + s.s $f21,-12($fp) + s.s $f20,-8($fp) +$L_fsave: + j $31 + +みたいな感じにする? すると、必ず$31はsaveすることになるけど。 +noreorder しないとだめかも。 + +この方がコンパクトだけど、 + subu $sp,$sp,$L_r1_offset + .cprestroe + sw $fp,$_Lr1_offset-16($sp) + sw $31,$_Lr1_offset-160($sp) + j $L_save +$L_fsave_0: + move $fp,$sp + + ... +$L_save: + ... + sw $17,-12($sp) + sw $16,-8($sp) + s.s $f22,-16($sp) + s.s $f21,-12($sp) + s.s $f20,-8($sp) + j $L_save_0 + +の方がいいかな。save する必要がなければ、 + j $L_save +$L_save_0: + move $fp,$sp + +$L_save = $L_fsave_0 + +とできるし。 + +両方作って、時間計る? + +まぁ、前者の方が凝っているし、命令数的にも変わらないから、 +space factor 的に前者の方が速いんじゃないか?
--- a/mc-code-ia32.c Sat May 15 23:09:36 2004 +0900 +++ b/mc-code-ia32.c Sun May 16 20:11:48 2004 +0900 @@ -99,6 +99,7 @@ static int code_disp_label; static int func_disp_label; + static int lvar(int l) { @@ -170,6 +171,7 @@ static void shift(char *op, int reg,int creg); static void ld_indexx(int byte, int n, int xreg,int reg,int sign); static void data_mode(char *name); +static void text_mode(); static int edx_setup(int rreg); static void edx_cleanup(); static void local_table(void);
--- a/mc-code-mips.c Sat May 15 23:09:36 2004 +0900 +++ b/mc-code-mips.c Sun May 16 20:11:48 2004 +0900 @@ -16,6 +16,7 @@ #define RODATA_EMIT_MODE 2 static void data_mode(char *name); +static void text_mode(int alignment); static void init_ptr_cache(); static void ld_indexx(int byte, int n, int xreg,int reg,int sign); static void local_table(void); @@ -27,9 +28,16 @@ static int output_mode = TEXT_EMIT_MODE; static int data_alignment = 0; -// static int code_disp_label; -// static int disp_label; -int code_top_label; +static FILE *asi; + +static int cprestore_label; +static int fmask_label; +static int fmask_offset_label; +static int mask_label; +static int mask_offset_label; +static int register_save_return_label; +static int register_save_label; + static int r1_offset_label; static int lvar_offset_label; @@ -866,7 +874,7 @@ free_register(lreg_stack[--lreg_sp]); } use_int0(); - text_mode(); + text_mode(2); gexpr_code_init(); register_usage("gexpr_init"); } @@ -880,7 +888,7 @@ max_reg_var=0; max_freg_var=0; reg_sp = 0; freg_sp = 0; - text_mode(); + text_mode(3); } #define reg_var_num(i) (REG_VAR_BASE-i) @@ -1369,7 +1377,7 @@ if (output_mode==TEXT_EMIT_MODE) { printf(".text\n"); } else { - text_mode(); + text_mode(2); } printf("\tla %s,$L_%d\n",crn,lb); } @@ -2427,14 +2435,13 @@ { static int count=0; /* this is called once per file */ -#if 0 char *p=cheapp; char *s,*t; -#endif + printf("\t.file %d \"%s\"\n",count++,filename); printf(".abicalls\n"); printf(".text\n"); -#if 0 + if (asi) { fclose(asi); asi = 0; @@ -2453,7 +2460,6 @@ asi = fopen(p,"w"); printf(".include \"%s\"\n",p); if (!asi) error(-1); -#endif } void @@ -2537,6 +2543,12 @@ disp += SIZE_OF_INT; } } + for(i=0;i<32;i++) { + if (freg_var_num(0)>i&&i>freg_var_num(max_reg_var)) { + printf("\ts.s %s,%d($sp)\n",register_name(i),disp); + disp += SIZE_OF_FLOAT; + } + } return disp; } @@ -2550,6 +2562,12 @@ disp += SIZE_OF_INT; } } + for(i=0;i<32;i++) { + if (freg_var_num(0)>i&&i>freg_var_num(max_reg_var)) { + printf("\tl.s %s,%d($sp)\n",register_name(i),disp); + disp += SIZE_OF_FLOAT; + } + } return disp; } @@ -2581,37 +2599,11 @@ return mask; } -static int -code_fregister_save(reg_save,freg_save,disp) -{ - int i; - for(i=0;i<32;i++) { - if (freg_var_num(0)>i&&i>freg_var_num(max_reg_var)) { - printf("\tsw %s,%d($sp)\n",register_name(i),disp); - disp += SIZE_OF_FLOAT; - } - } - return disp; -} - -static int -code_fregister_restore(reg_save,freg_save,disp) -{ - int i; - for(i=0;i<32;i++) { - if (freg_var_num(0)>i&&i>freg_var_num(max_reg_var)) { - printf("\tsw %s,%d($sp)\n",register_name(i),disp); - disp += SIZE_OF_FLOAT; - } - } - return disp; -} - void code_enter(char *name) { if (output_mode!=TEXT_EMIT_MODE) - text_mode(); + text_mode(3); else printf("\t.align 3\n"); if (stmode!=STATIC) @@ -2619,9 +2611,18 @@ #ifdef DOT_SIZE printf("\t.type\t%s,@function\n",name); #endif - code_top_label = backdef(); - r1_offset_label = fwdlabel(); - lvar_offset_label = 0; + + printf("%s:\n",name); + printf("\t.frame $fp,%d,$31\n",0); + printf("\t.mask 0x%x,%d\n",code_mask(),0); + printf("\t.fmask 0x%x,%d\n",code_fmask(),0); + + printf("\t.set noreorder\n"); + printf("\t.cpload $25\n"); + printf("\t.set reorder\n"); + printf("\tsubu $sp,$sp,$L_%d\n", r1_offset_label = fwdlabel()); + printf("\t.cprestore %d\n",max_func_args); + lvar_offset_label = fwdlabel(); max_func_args = 0; } @@ -2644,20 +2645,6 @@ printf(".set L_%d,%d\n",r1_offset_label,r1_offsetv); - printf("\t.align 2\n"); - printf("%s:\n",name); - printf("\t.frame $fp,%d,$31\n",0); - printf("\t.mask 0x%x,%d\n",code_mask(),0); - printf("\t.fmask 0x%x,%d\n",code_fmask(),0); - - printf("\t.set noreorder\n"); - printf("\t.cpload $25\n"); - printf("\t.set reorder\n"); - printf("\tsubu $sp,$sp,$L_%d\n",-r1_offsetv); - printf("\t.cprestore %d\n",max_func_args); - printf("\tj $L_%d\n",code_top_label); - - local_table(); printf("\t.end %s\n",name); // free_all_register(); @@ -2667,21 +2654,35 @@ enter(char *name) { if (output_mode!=TEXT_EMIT_MODE) - text_mode(); + text_mode(3); else - printf("\t.align 2\n"); - code_top_label = backdef(); + printf("\t.align 3\n"); - r1_offset_label = fwdlabel(); + max_func_args = 0; + lvar_offset_label = fwdlabel(); - max_func_args = 0; + printf(".ent %s\n",name); + printf("%s:\n",name); + printf("\t.frame $fp,$L_%d,$31\t",r1_offset_label); + printf("\t.mask 0x%x,%d\n",mask_label=fwdlabel(), + mask_offset_label=fwdlabel()); + printf("\t.fmask 0x%x,%d\n",fmask_label=fwdlabel(), + fmask_offset_label=fwdlabel()); + printf("\t.set noreorder\n"); + printf("\t.cpload $25\n"); + printf("\t.set reorder\n"); + printf("\tsubu $sp,$sp,$L_%d\n",r1_offset_label=fwdlabel()); + printf("\t.cprestore $L_%d\n",cprestore_label=fwdlabel()); + printf("\tj $L_%d\n",register_save_label=fwdlabel()); + register_save_return_label = backdef(); + printf("\tmove $fp,$sp\n"); } void enter1() { - text_mode(); + text_mode(0); // set_lreg(LREG_LREGISTER,0); set_ireg(CREG_REGISTER,0); set_freg(FREG_FREGISTER,0); @@ -2704,7 +2705,8 @@ if (control) { code_set_return_register(1); - } + } else + text_mode(2); if (retcont) { /* return from CbC segement */ if (control) jmp(retlabel); @@ -2734,35 +2736,24 @@ if (retcont) { fwddef(retcont1); } -#if 0 - fprintf(asi,"$L_%d=%d\n",r1_offset_label,0); - fprintf(asi,"$L_%d=%d\n",lvar_offset_label,0); - fprintf(asi,"$L_%d=0x%x\n",mask_label,code_mask_label()); - fprintf(asi,"$L_%d=%d\n",mask1_label,0); - fprintf(asi,"$L_%d=0x%x\n",fmask_label ,code_fmask_label()); - fprintf(asi,"$L_%d=%d\n",fmask1_label,0); - fprintf(asi,"$L_%d=%d\n",cprestore_label ,max_func_args); -#endif + disp &= -SIZE_OF_INT; r1_offsetv = round16(-disp) + max_reg_var*SIZE_OF_INT+max_freg_var*SIZE_OF_FLOAT+ round16(max_func_args); - printf(".set L_%d,%d\n",r1_offset_label,r1_offsetv); - printf(".set L_%d,%d\n",lvar_offset_label,lvar_offsetv); + fprintf(asi,"$L_%d=%d\n",r1_offset_label,r1_offsetv); + fprintf(asi,"$L_%d=%d\n",lvar_offset_label,lvar_offsetv); printf("\tmove $sp,$fp\n"); - code_fregister_restore(code_register_restore(disp)); + if (max_reg_var+max_freg_var) + code_register_restore(disp); printf("\tlw $31,%d($sp)\n",-disp); printf("\tlw $fp,%d($sp)\n",-disp-4); printf("\taddu $sp,$sp,%d\n",r1_offsetv); printf("\tj $31\n"); - printf("\t.align 2\n"); - printf(".ent %s\n",name); - printf("%s:\n",name); - printf("\t.frame $fp,%d,$31\t",r1_offsetv); printf("# vars= %d, regs= %d/%d, args= %d, extra= %d\n", round16(-disp), max_reg_var+2, @@ -2770,16 +2761,20 @@ round16(max_func_args), 0 ); - printf("\t.mask 0x%x,%d\n",code_mask(),code_mask_offset()); - printf("\t.fmask 0x%x,%d\n",code_fmask(),code_fmask_offset()); - - printf("\t.set noreorder\n"); - printf("\t.cpload $25\n"); - printf("\t.set reorder\n"); - printf("\tsubu $sp,$sp,%d\n",r1_offsetv); - printf("\t.cprestore %d\n",round16(max_func_args)); - code_fregister_save(code_register_save(disp)); - printf("\tj $L_%d\n",code_top_label); + fprintf(asi,"$L_%d=0x%x\n",mask_label,code_mask()); + fprintf(asi,"$L_%d=%d\n",mask_offset_label,code_mask_offset()); + fprintf(asi,"$L_%d=0x%x\n",fmask_label,code_fmask()); + fprintf(asi,"$L_%d=%d\n",fmask_offset_label,code_fmask_offset()); + fprintf(asi,"$L_%d=%d\n",cprestore_label ,round16(max_func_args)); + + if (max_reg_var+max_freg_var==0) { + fprintf(asi,"$L_%d=$L_%d\n", + register_save_label,register_save_return_label); + } else { + code_label(register_save_return_label); + code_register_save(disp); + jmp(register_save_return_label); + } local_table(); printf("\t.end %s\n",name); @@ -2976,11 +2971,11 @@ } void -text_mode(void) +text_mode(int align) { if (output_mode!=TEXT_EMIT_MODE) { printf(".text\n"); - printf("\t.align 2\n"); + if (align) printf("\t.align %d\n",align); output_mode = TEXT_EMIT_MODE; } } @@ -3420,7 +3415,7 @@ int cmp=0; d=(op<FOP); - use_float(reg,d); + use_float(d,reg); switch(op) { case FADD: opn="add.s"; break; case DADD: opc="dpadd"; break; @@ -4779,6 +4774,7 @@ { global_table(); /* printf("\t.ident \"Micro-C compiled\"\n"); */ + fclose(asi); asi=0; } /* end */
--- a/mc-code-powerpc.c Sat May 15 23:09:36 2004 +0900 +++ b/mc-code-powerpc.c Sun May 16 20:11:48 2004 +0900 @@ -16,6 +16,7 @@ #define RODATA_EMIT_MODE 2 static void data_mode(char *name); +static void text_mode(); static void init_ptr_cache(); static void ld_indexx(int byte, int n, int xreg,int reg,int sign); static void local_table(void);
--- a/mc-code.h Sat May 15 23:09:36 2004 +0900 +++ b/mc-code.h Sun May 16 20:11:48 2004 +0900 @@ -104,7 +104,6 @@ extern int code_get_fixed_creg(int reg,int type); extern void code_set_fixed_creg(int reg,int mode,int type); extern void code_set_return_register(int mode); -extern void text_mode(void); extern void global_table(void); extern void code_label(int labelno);