Mercurial > hg > CbC > old > device
diff mc-code-i64.c @ 931:2ed46e515c55
linux 64 ptr cache
author | kono |
---|---|
date | Sun, 13 Apr 2014 17:46:30 +0900 |
parents | 96c53f76b360 |
children | da35b4de1f9f |
line wrap: on
line diff
--- a/mc-code-i64.c Sun Apr 13 17:20:35 2014 +0900 +++ b/mc-code-i64.c Sun Apr 13 17:46:30 2014 +0900 @@ -531,11 +531,7 @@ #define __SIZEOF_LONG_LONG__ 8\n\ #define __LDBL_DIG__ 18\n\ #define __GNUC_GNU_INLINE__ 1\n\ -<<<<<<< local #define __extension__\n\ -======= -#define __extension__ \n\ ->>>>>>> other " #endif // extension is certainly wrong @@ -1120,9 +1116,7 @@ ireg = 0; } i = reg==USING_REG?creg:reg; -#ifdef __APPLE__ if (regs[i]==PTRC_REG) clear_ptr_cache_reg(i); -#endif if (!i||!ireg||!is_data_reg(i)) { if (!ireg) { ireg = get_data_register(); @@ -1166,10 +1160,8 @@ { if (!is_int_reg(reg)) error(-1); if (reg!=creg) { -#ifdef __APPLE__ if (regs[reg]==PTRC_REG) clear_ptr_cache_reg(reg); -#endif if (ireg && reg!=ireg ) { clear_ptr_cache_reg(ireg); if (regs[ireg]!=REG_VAR) free_register(ireg); @@ -1238,9 +1230,7 @@ { /* called for each file */ output_mode = -1; -#ifdef __APPLE__ init_ptr_cache(); -#endif } @@ -1286,7 +1276,6 @@ return i; /* その場所を表す番号を返す */ } } -#ifdef __APPLE__ /* PTR_CACHE をつぶす */ if ((i=last_ptr_cache())) { clear_ptr_cache_reg(i); @@ -1294,7 +1283,6 @@ regs_line[i]=glineno; return i; /* その場所を表す番号を返す */ } -#endif /* search register stack */ for(i=0;i<reg_sp;i++) { if ((reg=reg_stack[i])>=0) { @@ -1320,7 +1308,6 @@ return i; /* その場所を表す番号を返す */ } } -#ifdef __APPLE__ /* PTR_CACHE をつぶす */ while ((i=last_ptr_cache())) { clear_ptr_cache_reg(i); @@ -1330,7 +1317,6 @@ return i; /* その場所を表す番号を返す */ } } -#endif /* search register stack */ for(i=0;i<reg_sp;i++) { if (is_data_reg(i) && (reg=reg_stack[i])>=0) { @@ -1354,26 +1340,23 @@ extern void use_ptr_cache(int r) { -#ifdef __APPLE__ regs[r]=PTRC_REG; -#else - error(-1); -#endif } extern void code_ptr_cache_def(int r,NMTBL *nptr) { + char *rrn = register_name(r,0); #ifdef __APPLE__ - char *rrn = register_name(r,0); if (nptr->sc==STATIC && !(is_code(nptr)||is_function(nptr))) { printf("\tleaq _%s(%%rip),%s\n",nptr->nm, rrn); } else { printf("\tmovq _%s@GOTPCREL(%%rip),%s\n", nptr->nm, rrn); } + printf("\tleaq _%s,%s\n",nptr->nm, rrn); #else - error(-1); + printf("\tleaq %s,%s\n",nptr->nm, rrn); #endif } @@ -1690,10 +1673,6 @@ func_reg_arg_size = MAX_INPUT_REGISTER_VAR*SIZE_OF_LONGLONG + MAX_INPUT_DREGISTER_VAR*SIZE_OF_DOUBLE; -#ifndef __APPLE__ - // printf(".set %s%d, %d\n",lpfx, arg_offset_label, - // arg_offset_v+ arg_offset); -#endif } code_save_input_registers(dots, func_reg_arg_size ); arg_offset_v = func_reg_arg_size; @@ -1806,10 +1785,7 @@ void code_label(int labelno) { -#ifdef __APPLE__ clear_ptr_cache(); -#endif - // printf("\t.align 4\n"); printf("_%d:\n",labelno); } @@ -1822,6 +1798,7 @@ printf("\tleaq _%s+%d(%%rip),%s\n", nptr->nm,cadr(e1),register_name(creg,0)); return; } +#endif int r = get_ptr_cache(nptr); if (cadr(e1)) { printf("\tleaq %d(%s),%s\n", cadr(e1),register_name(r,0), @@ -1829,14 +1806,6 @@ } else { printf("\tmovq %s,%s\n", register_name(r,0), register_name(creg,0)); } -#else - if (cadr(e1)) { - printf("\tmovq $%s+%d,%s\n",nptr->nm,cadr(e1), - register_name(creg,0)); - } else { - printf("\tmovq $%s,%s\n",nptr->nm,register_name(creg,0)); - } -#endif } @@ -1847,12 +1816,13 @@ code_crgvar(e1,creg,0,SIZE_OF_INT); return; } +#ifdef __APPLE__ NMTBL *nptr = ncaddr(e1); -#ifdef __APPLE__ if (nptr->sc==STATIC && !(is_code(nptr)||is_function(nptr))) { printf("\tmovl _%s+%d(%%rip),%s\n", nptr->nm,cadr(e1),register_name(creg,SIZE_OF_INT)); return; } +#endif int r = get_ptr_cache(ncaddr(e1)); if (cadr(e1)) { printf("\tmovl %d(%s),%s\n", cadr(e1),register_name(r,0), @@ -1860,14 +1830,6 @@ } else { printf("\tmovl (%s),%s\n", register_name(r,0), register_name(creg,SIZE_OF_INT)); } -#else - if (cadr(e1)) { - printf("\tmovl %s+%d,%s\n",nptr->nm,cadr(e1), - register_name(creg,SIZE_OF_INT)); - } else - printf("\tmovl %s,%s\n",nptr->nm,register_name(creg,SIZE_OF_INT)); -#endif - } static char * @@ -1891,6 +1853,7 @@ printf("\t%s _%s+%d(%%rip),%s\n", cload(sign,sz),nptr->nm,cadr(e1),register_name(creg,regu(sign,sz,0))); return; } +#endif int r = get_ptr_cache(ncaddr(e1)); if (cadr(e1)) { printf("\t%s %d(%s),%s\n", cload(sign,sz),cadr(e1),register_name(r,0), @@ -1899,15 +1862,6 @@ printf("\t%s (%s),%s\n", cload(sign,sz), register_name(r,0), register_name(creg,regu(sign,sz,0))); } -#else - if (cadr(e1)) { - printf("\t%s %s+%d,%s\n",cload(sign,sz), - nptr->nm,cadr(e1),register_name(creg,regu(sign,sz,0))); - } else - printf("\t%s %s,%s\n",cload(sign,sz), - nptr->nm,register_name(creg,regu(sign,sz,0))); -#endif - } @@ -1983,11 +1937,9 @@ register_name(creg,0)); return; } +#endif int r = get_ptr_cache(n); printf("\tmovq %s,%s\n", register_name(r,0), register_name(creg,0)); -#else - printf("\tmovq $%s,%s\n",n->nm,register_name(creg,0)); -#endif } void @@ -2156,7 +2108,6 @@ void code_cmp_crgvar(int e1,int reg,int sz,int label,int cond) { use_int(reg); -#ifdef __APPLE__ int r = get_ptr_cache(ncaddr(e1)); if (cadr(e1)) { if (sz==1) @@ -2169,19 +2120,6 @@ else if (sz==SIZE_OF_SHORT) printf("\tcmpw $0,(%s)\n",register_name(r,0)); } -#else - if (cadr(e1)) { - if (sz==1) - printf("\tcmpb $0,%s+%d\n",(ncaddr(e1))->nm,cadr(e1)); - else if (sz==SIZE_OF_SHORT) - printf("\tcmpw $0,%s+%d\n",(ncaddr(e1))->nm,cadr(e1)); - } else { - if (sz==1) - printf("\tcmpb $0,%s\n",(ncaddr(e1))->nm); - else if (sz==SIZE_OF_SHORT) - printf("\tcmpw $0,%s\n",(ncaddr(e1))->nm); - } -#endif jcond(label,cond); } @@ -2201,18 +2139,11 @@ void code_cmp_rgvar(int e1,int reg,int label,int cond) { use_int(reg); -#ifdef __APPLE__ int r = get_ptr_cache(ncaddr(e1)); if (cadr(e1)) printf("\tcmpl $0,%d(%s)\n",cadr(e1),register_name(r,0)); else printf("\tcmpl $0,(%s)\n",register_name(r,0)); -#else - if (cadr(e1)) - printf("\tcmpl $0,%s+%d\n",(ncaddr(e1))->nm,cadr(e1)); - else - printf("\tcmpl $0,%s\n",(ncaddr(e1))->nm); -#endif jcond(label,cond); } @@ -2917,7 +2848,6 @@ code_assign_gvar(int e2,int creg,int byte) { if (byte && byte <SIZE_OF_INT) { use_data_reg(creg,1); } else { use_int(creg); } -#ifdef __APPLE__ int r = get_ptr_cache(ncaddr(e2)); if (cadr(e2)) printf("\t%s %s,%d(%s)\n",move(byte),register_name(creg,byte), @@ -2925,12 +2855,6 @@ else printf("\t%s %s,(%s)\n",move(byte),register_name(creg,byte), register_name(r,0)); -#else - if (cadr(e2)) - printf("\t%s %s,%s+%d\n",move(byte),register_name(creg,byte),(ncaddr(e2))->nm,cadr(e2)); - else - printf("\t%s %s,%s\n",move(byte),register_name(creg,byte),(ncaddr(e2))->nm); -#endif } void @@ -3063,10 +2987,8 @@ case UDIV: case MOD: case UMOD: -#ifdef __APPLE__ if (regs[REG_EDX]==PTRC_REG) clear_ptr_cache_reg(REG_EDX); -#endif use_register(reg,REG_EAX,1); if (oreg==REG_EAX) oreg=reg; if (oreg==REG_EDX) { @@ -4303,18 +4225,11 @@ void code_drgvar(int e2,int d,int freg) { use_float(d,freg); -#ifdef __APPLE__ int r = get_ptr_cache(ncaddr(e2)); if (cadr(e2)) printf("\t%s %d(%s),%s\n",fload(d),cadr(e2),register_name(r,0),fregister_name(freg)); else printf("\t%s (%s),%s\n",fload(d),register_name(r,0),fregister_name(freg)); -#else - if (cadr(e2)) - printf("\t%s %s+%d,%s\n",fload(d),(ncaddr(e2))->nm,cadr(e2),fregister_name(freg)); - else - printf("\t%s %s,%s\n",fload(d),(ncaddr(e2))->nm,fregister_name(freg)); -#endif } @@ -4330,18 +4245,11 @@ use_float(d,reg); char *f = fregister_name(reg); int t = get_dregister(d); -#ifdef __APPLE__ int r = get_ptr_cache(ncaddr(e2)); if (cadr(e2)) printf("\tmovs%s %d(%s),%s\n",db,cadr(e2),register_name(r,0),f); else printf("\tmovs%s (%s),%s\n",db,register_name(r,0),f); -#else - if (cadr(e2)) - printf("\tmovs%s %s+%d,%s\n",db,(ncaddr(e2))->nm,cadr(e2),f); - else - printf("\tmovs%s %s,%s\n",db,(ncaddr(e2))->nm,f); -#endif printf("\txorp%s %s,%s\n",db,f,fregister_name(t)); printf("\tucomis%s %s,%s\n",db,f,fregister_name(t)); free_register(t); @@ -4455,13 +4363,9 @@ one = &float_one_f; } char *grn=fregister_name(g); -#ifdef __APPLE__ int r = get_ptr_cache(one); char *drn=register_name(r,0); printf("\tmovs%s 0(%s),%s\n",d?"d":"s",drn,grn); -#else - printf("\tmovs%s %s,%s\n",d?"d":"s",one->nm,grn); -#endif return g; } @@ -4639,10 +4543,8 @@ code_cmp_dregister(int e2,int d,int label,int cond) { use_float(d,e2); -#ifdef __APPLE__ if (regs[REG_EAX]==PTRC_REG) clear_ptr_cache_reg(REG_EAX); -#endif int tmp = get_dregister(d); char *n = fregister_name(tmp); char *c = fregister_name(creg); @@ -4765,18 +4667,11 @@ void code_cmp_lrgvar(int e1,int e2,int label,int cond) { use_longlong(e2); -#ifdef __APPLE__ int r = get_ptr_cache(ncaddr(e1)); if (cadr(e1)) printf("\tcmpq $0,%d(%s)\n",cadr(e1),register_name(r,0)); else printf("\tcmpq $0,(%s)\n",register_name(r,0)); -#else - if (cadr(e1)) - printf("\tcmpq $0,%s+%d\n",(ncaddr(e1))->nm,cadr(e1)); - else - printf("\tcmpq $0,%s\n",(ncaddr(e1))->nm); -#endif jcond(label,cond); } @@ -5086,20 +4981,14 @@ printf("\tja\t_%d\n",dlabel); // this assumes 32bit offset, but it may too small if (delta==1) { -#ifdef __APPLE__ printf("\tleaq\t_%d(%%rip),%%rbx\n",l); printf("\tmovslq\t(%%rbx,%s,4),%s\n",crn,crn); printf("\taddq\t%%rbx,%s\n",crn); printf("\tjmp\t*%s\n",crn); -#else - printf("\tjmp\t*_%d(,%s,8)\n",l,crn); -#endif return; } -#ifdef __APPLE__ if (regs[REG_EAX]==PTRC_REG) clear_ptr_cache_reg(REG_EAX); -#endif use_register(creg,REG_EAX,1); crn = "%rax"; @@ -5108,41 +4997,29 @@ printf("\tmovl\t$1,%%edx\n"); printf("\tandl\t%%eax,%%edx\n"); printf("\tjne\t_%d\n",dlabel); -#ifdef __APPLE__ printf("\tleaq\t_%d(%%rip),%%rbx\n",l); printf("\tmovslq\t(%%rbx,%s,2),%s\n",crn,crn); printf("\taddq\t%%rbx,%s\n",crn); printf("\tjmp\t*%s\n",crn); -#else - printf("\tjmp\t*_%d(,%%eax,4)\n",l); -#endif break; case 4: printf("\tmovl\t$3,%%edx\n"); printf("\tandl\t%%eax,%%edx\n"); printf("\tjne\t_%d\n",dlabel); -#ifdef __APPLE__ printf("\tleaq\t_%d(%%rip),%%rbx\n",l); printf("\tmovslq\t(%%rbx,%s),%s\n",crn,crn); printf("\taddq\t%%rbx,%s\n",crn); printf("\tjmp\t*%s\n",crn); -#else - printf("\tjmp\t*_%d(,%%eax,2)\n",l); -#endif break; default: printf("\tmovl $%d,%%ecx\n",delta); printf("\txor %%edx,%%edx\n\tdivl %%ecx\n"); printf("\tandl\t%%edx,%%edx\n"); printf("\tjne\t_%d\n",dlabel); -#ifdef __APPLE__ printf("\tleaq\t_%d(%%rip),%%rbx\n",l); printf("\tmovslq\t(%%rbx,%s,4),%s\n",crn,crn); printf("\taddq\t%%rbx,%s\n",crn); printf("\tjmp\t*%s\n",crn); -#else - printf("\tjmp\t*_%d(,%%rax,8)\n",l); -#endif break; } @@ -5152,22 +5029,14 @@ code_table_open(int l) { output_mode=DATA_EMIT_MODE; -#ifdef __APPLE__ printf(" \t.align 2\n"); -#else - printf(" \t.section\t.rodata\n\t.align 4\n"); -#endif fwddef(l); } void code_table_value(int label,int table_top) { -#ifdef __APPLE__ printf("\t.long _%d-_%d\n",label,table_top); -#else - printf("\t.quad _%d\n",label); -#endif } void