Mercurial > hg > CbC > old > device
changeset 662:c9df4e08da9b
*** empty log message ***
author | kono |
---|---|
date | Thu, 22 Feb 2007 15:05:42 +0900 |
parents | f566ac85f2e0 |
children | 92a401bef729 |
files | Makefile mc-code-powerpc.c mc-code-spu.c |
diffstat | 3 files changed, 536 insertions(+), 204 deletions(-) [+] |
line wrap: on
line diff
--- a/Makefile Wed Feb 21 20:11:23 2007 +0900 +++ b/Makefile Thu Feb 22 15:05:42 2007 +0900 @@ -25,7 +25,7 @@ # TARGET=test/simp -all: mc-include.c mc +all: mc-include.c mc mc-spu allall: mc-include.c mc mc-ia32 mc-powerpc mc-mips mc-arm @@ -55,6 +55,9 @@ mc-arm : mc-code-arm.o $(COMPLIB) $(CONVERTER) $(CC) $(LDFLAGS) -g mc-code-arm.o $(COMPLIB) $(CONVERTER) -o $@ +mc-spu : mc-code-spu.o $(COMPLIB) $(CONVERTER) + $(CC) $(LDFLAGS) -g mc-code-spu.o $(COMPLIB) $(CONVERTER) -o $@ + conv/conv.h: conv_func.tbl tools/conv_func.pl perl tools/conv_func.pl conv/convdef.h: conv_func.tbl tools/conv_func.pl @@ -317,4 +320,4 @@ mc-code-mips.o: /usr/include/stdio.h /usr/include/_types.h mc-code-mips.o: /usr/include/sys/_types.h /usr/include/sys/cdefs.h mc-code-mips.o: /usr/include/machine/_types.h /usr/include/ppc/_types.h mc.h -mc-code-mips.o: mc-parse.h mc-code.h mc-codegen.h +mc-code-mips.o: mc-parse.h mc-code.h mc-codegen.h mc-include.c
--- a/mc-code-powerpc.c Wed Feb 21 20:11:23 2007 +0900 +++ b/mc-code-powerpc.c Thu Feb 22 15:05:42 2007 +0900 @@ -31,6 +31,8 @@ #include "mc-include.c" + + static char *init_src0 = "\ #define __ppc__ 1\n\ @@ -62,6 +64,13 @@ static int push_struct(int e4,int t,int arg); static void ascii(char *s); +#ifdef __APPLE__ +static char lpfx[] = "L_"; +static char npfx[] = "_"; +#else +static char lpfx[] = ".LC"; +static char npfx[] = ""; +#endif int eval_order = NORMAL; @@ -354,12 +363,12 @@ round16(-disp+max_func_args*SIZE_OF_INT+func_disp_offset); int r1_offsetv = round16(lvar_offsetv-reg_save+16); - printf(".set L_%d,%d\n",lvar_offset_label,r1_offsetv-lvar_offsetv); + printf(".set %s%d,%d\n",lpfx,lvar_offset_label,r1_offsetv-lvar_offsetv); if (r1_offsetv-lvar_offsetv > 65000) error(-1); // too large function arguments? - printf(".set L_%d,%d\n",r1_offset_label,r1_offsetv); + printf(".set %s%d,%d\n",lpfx,r1_offset_label,r1_offsetv); if (max_func_arg_label) { - printf(".set L_%d,%d\n",max_func_arg_label, + printf(".set %s%d,%d\n",lpfx,max_func_arg_label, round16(max_func_args*SIZE_OF_INT)+24); max_func_arg_label = 0; } @@ -404,7 +413,7 @@ } else if (l>=ARG_LVAR_OFFSET) { /* caller's arguments */ printf("lo16(%d)(r1)\n",CALLER_ARG(l-ARG_LVAR_OFFSET)); } else { /* callee's arguments */ - printf("lo16(%d+L_%d)(r30)\n",CALLEE_ARG(l),lvar_offset_label); + printf("lo16(%d+%s%d)(r30)\n",CALLEE_ARG(l),lpfx,lvar_offset_label); } } else { rn = register_name(large_offset_reg); @@ -418,7 +427,7 @@ } else if (l>=ARG_LVAR_OFFSET) { /* caller's arguments */ printf("lo16(%d)(%s)\n",CALLER_ARG(l-ARG_LVAR_OFFSET),rn); } else { /* callee's arguments */ - printf("lo16(%d+L_%d)(%s)\n",CALLEE_ARG(l),lvar_offset_label,rn); + printf("lo16(%d+%s%d)(%s)\n",CALLEE_ARG(l),lpfx,lvar_offset_label,rn); } free_register(large_offset_reg); } @@ -464,8 +473,8 @@ } else { /* callee's arguments */ if (LARGE_OFFSET(CALLEE_ARG(l))) { rn=register_name(large_offset_reg=get_register()); - printf("\taddis %s,r30,ha16(%d+L_%d)\n", - rn,CALLEE_ARG(l),lvar_offset_label); + printf("\taddis %s,r30,ha16(%d+%s%d)\n", + rn,CALLEE_ARG(l),lpfx,lvar_offset_label); } } } @@ -487,7 +496,7 @@ } else if (l>=ARG_LVAR_OFFSET) { /* caller's arguments */ printf("%d@l(1)\n",CALLER_ARG(l-ARG_LVAR_OFFSET)); } else { /* callee's arguments */ - printf("%d+L_%d@l(30)\n",CALLEE_ARG(l),lvar_offset_label); + printf("%d+%s%d@l(30)\n",CALLEE_ARG(l),lpfx,lvar_offset_label); } } else { rn = register_name(large_offset_reg); @@ -501,7 +510,7 @@ } else if (l>=ARG_LVAR_OFFSET) { /* caller's arguments */ printf("%d@l(%s)\n",CALLER_ARG(l-ARG_LVAR_OFFSET),rn); } else { /* callee's arguments */ - printf("%d+L_%d@l(%s)\n",CALLEE_ARG(l),lvar_offset_label,rn); + printf("%d+%s%d@l(%s)\n",CALLEE_ARG(l),lpfx,lvar_offset_label,rn); } free_register(large_offset_reg); } @@ -547,8 +556,8 @@ } else { /* callee's arguments */ if (LARGE_OFFSET(CALLEE_ARG(l))) { rn=register_name(large_offset_reg=get_register()); - printf("\tla %s,30,%d+L_%d@ha\n", - rn,CALLEE_ARG(l),lvar_offset_label); + printf("\tla %s,30,%d+%s%d@ha\n", + rn,CALLEE_ARG(l),lpfx,lvar_offset_label); } } } @@ -1292,11 +1301,7 @@ code_label(int labelno) { clear_ptr_cache(); -#ifdef __APPLE__ - printf("L_%d:\n",labelno); -#else - printf(".LC%d:\n",labelno); -#endif + printf("%s%d:\n",lpfx,labelno); } static void @@ -1445,7 +1450,7 @@ char *crn; use_int(reg); crn = register_name(reg); -#ifdef __APPLE___ +#ifdef __APPLE__ printf("\taddis %s,r31,ha16(L_%d-L_%d)\n",crn,label,code_base); printf("\tla %s,lo16(L_%d-L_%d)(%s)\n",crn,label,code_base,crn); #else @@ -1571,7 +1576,7 @@ void code_return(int creg) { - char *crn; + use_int(creg); code_label_value(retcont,creg); } @@ -1653,17 +1658,22 @@ // cmpflag = (cmpflag+1)%8; } +#ifdef __APPLE__ +static +char *crname_[] = { "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7" }; +#else +static +char *crname_[] = { "0", "1", "2", "3", "4", "5", "6", "7" }; +#endif +#define crname(d) (crname_[d]) + void code_cmp_crgvar(int e1,int reg,int sz,int label,int cond) { use_int(reg); code_ld(cload(sz),reg,cadr(e1),get_ptr_cache((NMTBL*)caddr(e1))); cext(0,sz,reg); inc_cmpflag(); -#ifdef __APPLE__ - printf("\tcmpwi cr%d,%s,0\n",cmpflag,register_name(reg)); -#else - printf("\tcmpwi %d,%s,0\n",cmpflag,register_name(reg)); -#endif + printf("\tcmpwi %s,%s,0\n",crname(cmpflag),register_name(reg)); jcond(label,cond); } @@ -1705,11 +1715,7 @@ code_cmp_register(int e2,int label,int cond) { use_int(e2); inc_cmpflag(); -#ifdef __APPLE__ - printf("\tcmpwi cr%d,%s,0\n",cmpflag,register_name(e2)); -#else - printf("\tcmpwi %d,%s,0\n",cmpflag,register_name(e2)); -#endif + printf("\tcmpwi %s,%s,0\n",crname(cmpflag),register_name(e2)); jcond(label,cond); } @@ -2519,12 +2525,12 @@ if (LARGE_OFFSET(offset)) { printf("\taddis %s,%s,ha16(%d)\n",crn,crn,offset); } - printf("\t%s %s,lo16(%d)(%s)\n",cload(sz),rrn,offset,crn); + printf("\t%s %s,lo16(%d)(%s)\n",op,crn,offset,rrn); #else if (LARGE_OFFSET(offset)) { printf("\taddis %s,%s,%d@ha\n",crn,crn,offset); } - printf("\t%s %s,%d@l(%s)\n",cload(sz),rrn,offset,crn); + printf("\t%s %s,%d@l(%s)\n",op,crn,offset,rrn); #endif } @@ -2736,11 +2742,11 @@ break; case CMP: inc_cmpflag(); - printf("\tcmpw cr%d,%s,%s\n",cmpflag,crn,orn); + printf("\tcmpw %s,%s,%s\n",crname(cmpflag),crn,orn); break; case UCMP: inc_cmpflag(); - printf("\tcmplw cr%d,%s,%s\n",cmpflag,crn,orn); + printf("\tcmplw %s,%s,%s\n",crname(cmpflag),crn,orn); break; case BAND: printf("\tand %s,%s,%s\n",crn,crn,orn); @@ -2835,17 +2841,17 @@ case CMP: inc_cmpflag(); #ifdef __APPLE__ - printf("\tcmpwi cr%d,%s,lo16(%d)\n",cmpflag,crn,v); + printf("\tcmpwi %s,%s,lo16(%d)\n",crname(cmpflag),crn,v); #else - printf("\tcmpwi %d,%s,%d@l\n",cmpflag,crn,v); + printf("\tcmpwi %s,%s,%d@l\n",crname(cmpflag),crn,v); #endif break; case UCMP: inc_cmpflag(); #ifdef __APPLE__ - printf("\tcmplwi cr%d,%s,lo16(%d)\n",cmpflag,crn,v); + printf("\tcmplwi %s,%s,lo16(%d)\n",crname(cmpflag),crn,v); #else - printf("\tcmplwi %d,%s,%d@l\n",cmpflag,crn,v); + printf("\tcmplwi %s,%s,%d@l\n",crname(cmpflag),crn,v); #endif break; case EOR: @@ -2912,22 +2918,14 @@ /* used in dosiwtch() */ inc_cmpflag(); if (-32767<e&&e<32767) { -#ifdef __APPLE__ - printf("\tcmpwi cr%d,%s,%d\n",cmpflag,register_name(csreg),e); -#else - printf("\tcmpwi %d,%s,%d\n",cmpflag,register_name(csreg),e); -#endif + printf("\tcmpwi %s,%s,%d\n",crname(cmpflag),register_name(csreg),e); jcond(label,cond); } else { regsv = regs[csreg]; regs[csreg]=USING_REG; reg = get_register(); regs[csreg]= regsv; code_const(e,reg); -#ifdef __APPLE__ - printf("\tcmpw cr%d,%s,%s\n",cmpflag,register_name(csreg),register_name(reg)); -#else - printf("\tcmpw %d,%s,%s\n",cmpflag,register_name(csreg),register_name(reg)); -#endif + printf("\tcmpw %s,%s,%s\n",crname(cmpflag),register_name(csreg),register_name(reg)); jcond(label,cond); free_register(reg); } @@ -3006,7 +3004,7 @@ default: error(-1); } g_expr(list3((t==INT?CMP:UCMP),cadr(e1),caddr(e1))); - printf("\tb%s cr%d,L_%d\n",s,cmpflag,l1); + printf("\tb%s %s,%s%d\n",s,crname(cmpflag),lpfx,l1); return l1; } @@ -3014,28 +3012,16 @@ jcond(int l, char cond) { if (cond==LT) { -#ifdef __APPLE__ - printf("\tb%s cr%d,L_%d\n",code_ge(0),cmpflag,l); -#else - printf("\tb%s %d,L_%d\n",code_ge(0),cmpflag,l); -#endif + printf("\tb%s %s,%s%d\n",code_ge(0),crname(cmpflag),lpfx,l); } else if (cond==1||cond==0) { -#ifdef __APPLE__ - printf("\tb%s cr%d,L_%d\n",cond?"ne":"eq",cmpflag,l); -#else - printf("\tb%s %d,.LC%d\n",cond?"ne":"eq",cmpflag,l); -#endif + printf("\tb%s %s,%s%d\n",cond?"ne":"eq",crname(cmpflag),lpfx,l); } else error(-1); } void jmp(int l) { -#ifdef __APPLE__ - printf("\tb\tL_%d\n",l); -#else - printf("\tb\t.LC%d\n",l); -#endif + printf("\tb\t%s%d\n",lpfx,l); } extern void @@ -3134,11 +3120,11 @@ else printf("\t.align 2\n"); if (stmode!=STATIC) - printf(".globl _%s\n",name); + printf(".globl %s%s\n",npfx,name); /* printf("\t.type\t%s,@function\n",name); */ - printf("_%s:\n",name); + printf("%s%s:\n",npfx,name); code_setup=fwdlabel(); printf("\tmflr r0\n"); printf("\tbl L_%d\n",code_setup); @@ -3163,7 +3149,7 @@ else printf("\t.align 2\n"); if (stmode!=STATIC) - printf(".globl _%s\n",name); + printf(".globl %s%s\n",npfx,name); /* printf("\t.type\t%s,@function\n",name); */ @@ -3178,9 +3164,9 @@ printf("\tstwu r1,lo16(-L_%d)(r1)\n",r1_offset_label); // printf("\tmr r30,r1\n"); #else - printf("\taddi 30,1,-L_%d@l\n",lvar_offset_label); - printf("\tlis 31,-L_%d@ha\n",r1_offset_label); - printf("\taddi 31,31,-L_%d@l\n",r1_offset_label); + printf("\taddi 30,1,-%s%d@l\n",lpfx,lvar_offset_label); + printf("\tlis 31,-%s%d@ha\n",lpfx,r1_offset_label); + printf("\taddi 31,31,-%s%d@l\n",lpfx,r1_offset_label); printf("\tstwux 1,1,31\n"); #endif printf("\tmflr 31\n"); @@ -3245,60 +3231,86 @@ #endif fwddef(retcont); if (cadr(fnptr->ty)==FLOAT||cadr(fnptr->ty)==DOUBLE) { - printf("\tfmr f1,f31\n"); + printf("\tfmr %s,%s\n",fregister_name(1),fregister_name(31)); } else if (cadr(fnptr->ty)>0&&( car(cadr(fnptr->ty))==STRUCT || car(cadr(fnptr->ty))==UNION)) { - // test routine? sz = size(cadr(fnptr->ty)); +#ifdef __APPLE__ printf("\tli r7,%d\n",sz); printf("\tsubl r6,r7,r30\n"); printf("\tlwz r3,lo16(%d)(r30)\n",(my_func_args-1)*SIZE_OF_INT); emit_copy(6,3,sz,0,1,1); +#else + printf("\tli 7,%d\n",sz); + printf("\tsubl 6,7,30\n"); + printf("\tlwz 3,%d@l(30)\n",(my_func_args-1)*SIZE_OF_INT); + emit_copy(6,3,sz,0,1,1); +#endif } else if (cadr(fnptr->ty)!=VOID) { - printf("\tmr r3,r29\n"); + printf("\tmr %s,%s\n",register_name(3),register_name(29)); } #if R1SAVE - // printf("\tb L_%d\n",retcont1); jmp(retcont1); #else -// printf("\tla r1,lo16(%d)(r30)\n", -// -reg_save+my_func_args*SIZE_OF_INT); #endif } fwddef(retlabel); #if R1SAVE - printf("\tlwz r1,0(r1)\n"); + printf("\tlwz %s,0(%s)\n",register_name(1),register_name(1)); if (retcont) { fwddef(retcont1); } #else +#ifdef __APPLE__ printf("\taddi r1,r30,lo16(L_%d)\n",lvar_offset_label); +#else + printf("\taddi 1,30,.LC%d@l\n",lvar_offset_label); +#endif #endif if (max_freg_var>=0) { - printf("\tlmw r%d,%d(r1)\n", - REG_VAR_BASE-max_reg_var,reg_save); + printf("\tlmw r%d,%d(%s)\n", + REG_VAR_BASE-max_reg_var,reg_save,register_name(1)); freg_save = 72-(REAL_MAX_FREGISTER-(FREG_VAR_BASE-max_freg_var))*4; +#ifdef __APPLE__ printf("\tb restFP+%d ; restore f%d-f31\n", freg_save, FREG_VAR_BASE-max_freg_var); +#else + printf("\tb restFP+%d ; restore f%d-f31\n", + freg_save, + FREG_VAR_BASE-max_freg_var); +#endif } else { +#ifdef __APPLE__ printf("\tlwz r0,8(r1)\n"); printf("\tmtlr r0\n"); printf("\tlmw r%d,%d(r1)\n", REG_VAR_BASE-max_reg_var,reg_save); +#else + printf("\tlwz %s,8(1)\n",register_name(0)); + printf("\tmtlr %s\n",register_name(0)); + printf("\tlmw %d,%d(1)\n", + REG_VAR_BASE-max_reg_var,reg_save); +#endif code_ret(); } disp &= -SIZE_OF_INT; fwddef(code_setup); - printf("\tstmw r%d,%d(r1)\n", - REG_VAR_BASE-max_reg_var,reg_save); - printf("\tstw r0,8(r1)\n"); + printf("\tstmw %s,%d(%s)\n", + register_name(REG_VAR_BASE-max_reg_var),reg_save,register_name(1)); + printf("\tstw %s,8(%s)\n",register_name(0),register_name(1)); if (max_freg_var>=0) +#ifdef __APPLE printf("\tb saveFP+%d ; save f%d-f31\n", freg_save, FREG_VAR_BASE-max_freg_var); +#else + printf("\tb saveFP+%d ; save f%d-f31\n", + freg_save, + FREG_VAR_BASE-max_freg_var); +#endif else { printf("\tblr\n"); } @@ -3352,7 +3364,11 @@ ascii(char *s) { cstring_mode(); +#ifdef __APPLE__ printf("\t.ascii \""); +#else + printf("\t.string \""); +#endif while(*s) { if (*s=='\n') printf("%cn",92); @@ -3375,7 +3391,7 @@ lb=fwdlabel(); cstring_mode(); - printf("L_%d:\n",lb); + printf("%s%d:\n",lpfx,lb); return lb; } @@ -3419,8 +3435,8 @@ } else data_mode(n->nm); if (n && n->sc!=STATIC) - printf("\t.globl\t_%s\n",n->nm); - printf("_%s:\n",n->nm); + printf("\t.globl\t%s%s\n",npfx,n->nm); + printf("%s%s:\n",npfx,n->nm); } extern void @@ -3494,16 +3510,16 @@ { data_mode(0); if (offset) - printf("\t.long _%s+%d\n",s,offset); + printf("\t.long %s%s+%d\n",npfx,s,offset); else - printf("\t.long _%s\n",s); + printf("\t.long %s%s\n",npfx,s); } extern void emit_label(int labelno) { data_mode(0); - printf("\t.long L_%d\n",labelno); + printf("\t.long %s%d\n",lpfx,labelno); } extern void @@ -3513,15 +3529,23 @@ int lb; #endif if (mode==GDECL) { +#ifdef DOT_SIZE +#ifdef __APPLE__ data_mode(0); -#ifdef DOT_SIZE + lb=fwdlabel(); + printf("%s%d:\n",lpfx,lb); + printf("\t.size\t%s,%s%d-%%ss\n",n->nm,lb,lpfx,npfx,n->nm); +#else + data_mode(0); lb=fwdlabel(); - printf("L_%d:\n",lb); - printf("\t.size\t%s,L_%d-%s\n",n->nm,lb,n->nm); + printf(".LC%d:\n",lb); + printf("\t.size\t%s,%s%d-%s%s\n",n->nm,lb,lpfx,npfx,n->nm); +#endif #endif } } +#ifdef __APPLE__ void global_table(void) { @@ -3535,7 +3559,7 @@ data_mode(0); init=1; } - printf(".comm _%s,%d\n",n->nm,size(n->ty)); + printf(".comm %s%s,%d\n",npfx,n->nm,size(n->ty)); } else if ((n->sc==STATIC) && n->dsp != -1) { /* n->dsp = -1 means initialized global */ if (is_code(n)||is_function(n)) continue; @@ -3543,7 +3567,7 @@ data_mode(0); init=1; } - printf(".lcomm _%s,%d\n",n->nm,size(n->ty)); + printf(".lcomm %s%s,%d\n",npfx,n->nm,size(n->ty)); } } for(n = global_list;n!=&null_nptr;n = n->next) { @@ -3604,7 +3628,57 @@ } } } - +#else + +static void +comm(NMTBL *n) +{ + int align = 1; + switch(n->ty) { + case DOUBLE: + case LONGLONG: + case ULONGLONG: + align = 8; break; + case INT: + case UNSIGNED: + case FLOAT: + align = 4; break; + case SHORT: + case USHORT: + align = 2; break; + } + printf("\t.comm %s,%d,%d\n",n->nm,size(n->ty),align); +} + +void +global_table(void) +{ + NMTBL *n; + int init; + init=0; + for(n=global_list;n;n=n->next) { + if ((n->sc == GVAR) && n->dsp != -1) { + /* n->dsp = -1 means initialized global */ + if (init==0) { + data_mode(0); + init=1; + } + comm(n); + } else if ((n->sc==STATIC) && n->dsp != -1) { + /* n->dsp = -1 means initialized global */ + if (is_code(n)||is_function(n)) continue; + if (init==0) { + data_mode(0); + init=1; + } + // printf(".local %s\n",n->nm); + comm(n); + } + } +} +#endif + +#ifdef __APPLE__ void local_table(void) { @@ -3624,12 +3698,36 @@ } } } +#else +void +local_table(void) +{ + NMTBL *n; + int init; + init=0; + /* static local variables */ + for(n = local_static_list;n!=&null_nptr;n = n->next) { + if (n->sc == STATIC) { + if (init==0) { + data_mode(0); + init=1; + } + if (n->dsp != -1) /* initialized static */ + printf(".lcomm %s,%d\n",n->nm,size(n->ty)); + } + } +} +#endif void cstring_mode(int align) { if (output_mode!=RODATA_EMIT_MODE) { +#ifdef __APPLE__ printf(".cstring\n\t.align 2\n"); +#else + printf("\t.section\t.rodata\n\t.align 2\n"); +#endif output_mode = RODATA_EMIT_MODE; } } @@ -3701,7 +3799,7 @@ { char *frn,*rrn,*grn; int greg,r; - grn = register_name(greg = get_dregister(d)); + grn = fregister_name(greg = get_dregister(d)); use_float(d,e2); frn = register_name(e2); float_zero_lib_used=1; @@ -3709,7 +3807,7 @@ rrn = register_name(r); printf("\tlfs %s,0(%s)\n",grn,rrn); inc_cmpflag(); - printf("\tfcmpu cr%d,%s,%s\n",cmpflag,grn,frn); + printf("\tfcmpu %s,%s,%s\n",crname(cmpflag),grn,frn); free_register(greg); jcond(label,cond); return; @@ -3824,7 +3922,7 @@ } else { text_mode(0); } - code_label_value(lb,rrn); + code_label_value(lb,r); if (d) { printf("\tlfd %s,0(%s)\n",frn,rrn); } else { @@ -3882,7 +3980,7 @@ } else { text_mode(0); } - code_label_value(lb,rrn); + code_label_value(lb,r); if (d) { printf("\tlfd %s,0(%s)\n",frn,rrn); } else { @@ -3934,7 +4032,53 @@ printf("\tlwz %s,",crn); lvar(e2+SIZE_OF_DOUBLE-SIZE_OF_INT); } +#ifndef __APPLE__ +static int saveFP_used=0; +static char *saveFP_lib[] = { +"saveFP: stfd 14,-144(1)", +" stfd 15,-136(1)", +" stfd 16,-128(1)", +" stfd 17,-120(1)", +" stfd 18,-112(1)", +" stfd 19,-104(1)", +" stfd 20,-96(1)", +" stfd 21,-88(1)", +" stfd 22,-80(1)", +" stfd 23,-72(1)", +" stfd 24,-64(1)", +" stfd 25,-56(1)", +" stfd 26,-48(1)", +" stfd 27,-40(1)", +" stfd 28,-32(1)", +" stfd 29,-24(1)", +" stfd 30,-16(1)", +" stfd 31,-8(1)", +" stw 0,8(1)", +" blr", +"restFP: lfd 14,-144(1)", +" lfd 15,-136(1)", +" lfd 16,-128(1)", +" lfd 17,-120(1)", +" lfd 18,-112(1)", +" lfd 19,-104(1)", +" lfd 20,-96(1)", +" lfd 21,-88(1)", +" lfd 22,-80(1)", +" lfd 23,-72(1)", +" lfd 24,-64(1)", +" lfd 25,-56(1)", +" lfd 26,-48(1)", +" lfd 27,-40(1)", +" lfd 28,-32(1)", +" lfd 29,-24(1)", +" lwz 0,8(1)", +" lfd 30,-16(1)", +" mtlr 0", +}; +#endif + static int i2d_lib_used=0; +#ifdef __APPLE__ static char *i2d_lib[] = { ".data", /* ".literal8", */ @@ -3961,6 +4105,34 @@ " blr", 0 }; +#else +static char *i2d_lib[] = { +".data", +/* ".literal8", */ +" .align 3", +"i2dLC0:", +" .long 1127219200", +" .long -2147483648", +".text", +" .align 2", +"i2d_:", +" mflr 0", +" bcl 20,31,__i2dL1$pb", +"i2dL1$pb:", +" mflr 10", +" mtlr 0", +" xoris 3,3,0x8000", +" stw 3,-28(1)", +" lis 0,0x4330", +" stw 0,-32(1)", +" lfd 0,-32(1)", +" addis 9,10,i2dLC0-i2dL1$pb@ha", +" lfd 1,i2dLC0-i2dL1$pb@l(9)", +" fsub 1,0,1", +" blr", +0 +}; +#endif void code_i2d() @@ -3974,6 +4146,7 @@ } static int d2u_lib_used=0; +#ifdef __APPLE__ static char *d2u_lib[] = { /* ".literal8", */ " .align 3", @@ -4008,6 +4181,42 @@ " blr", 0 }; +#else +static char *d2u_lib[] = { +/* ".literal8", */ +" .align 3", +"__d2uLC0:", +" .long 1105199104", +" .long 0", +".text", +" .align 2", +"d2u_:", +" mflr r0", +" bcl 20,31,__d2uL1$pb", +"__d2uL1$pb:", +" mflr r10", +" mtlr r0", +" addis r9,r10,ha16(__d2uLC0-__d2uL1$pb)", +" lfd f0,lo16(__d2uLC0-__d2uL1$pb)(r9)", +" fcmpu cr0,f1,f0", +" cror 2,1,2", +" beq- cr0,__d2uL2", +" fctiwz f0,f1", +" stfd f0,-32(r1)", +" lwz r3,-28(r1)", +" blr", +"__d2uL2:", +" addis r9,r10,ha16(__d2uLC0-__d2uL1$pb)", +" lfd f0,lo16(__d2uLC0-__d2uL1$pb)(r9)", +" fsub f0,f1,f0", +" fctiwz f0,f0", +" stfd f0,-24(r1)", +" lwz r3,-20(r1)", +" xoris r3,r3,0x8000", +" blr", +0 +}; +#endif void code_d2u() @@ -4021,6 +4230,7 @@ } static int u2d_lib_used=0; +#ifdef __APPLE__ static char *u2d_lib[] = { ".data", /* ".literal8", */ @@ -4046,6 +4256,33 @@ " blr", 0 }; +#else +static char *u2d_lib[] = { +".data", +/* ".literal8", */ +" .align 3", +"__u2dLC1:", +" .long 1127219200", +" .long 0", +".text", +" .align 2", +"u2d_:", +" mflr r0", +" bcl 20,31,__u2dL2$pb", +"__u2dL2$pb:", +" mflr r10", +" mtlr r0", +" stw r3,-28(r1)", +" lis r0,0x4330", +" stw r0,-32(r1)", +" lfd f0,-32(r1)", +" addis r9,r10,ha16(__u2dLC1-__u2dL2$pb)", +" lfd f1,lo16(__u2dLC1-__u2dL2$pb)(r9)", +" fsub f1,f0,f1", +" blr", +0 +}; +#endif void code_u2d() @@ -4101,7 +4338,7 @@ code_ldf(fload(1),grn,cadr(e2), get_ptr_cache((NMTBL*)caddr(e2))); inc_cmpflag(); - printf("\tfcmpu cr%d,%s,%s\n",cmpflag,frn,grn); + printf("\tfcmpu %s,%s,%s\n",crname(cmpflag),frn,grn); free_register(g); jcond(label,cond); } @@ -4119,7 +4356,7 @@ lvar_intro(e2); printf("\t%s %s,",fload(1),grn); lvar(e2); inc_cmpflag(); - printf("\tfcmpu cr%d,%s,%s\n",cmpflag,frn,grn); + printf("\tfcmpu %s,%s,%s\n",crname(cmpflag),frn,grn); free_register(g); jcond(label,cond); } @@ -4155,13 +4392,13 @@ case FCMP: case DCMP: inc_cmpflag(); - printf("\tfcmpu cr%d,%s,%s\n",cmpflag,frn,grn); + printf("\tfcmpu %s,%s,%s\n",crname(cmpflag),frn,grn); if (ox!=-1) free_register(ox); return; case FCMPGE: case DCMPGE: inc_cmpflag(); - printf("\tfcmpu cr%d,%s,%s\n",cmpflag,frn,grn); + printf("\tfcmpu %s,%s,%s\n",crname(cmpflag),frn,grn); if (ox!=-1) free_register(ox); return; default: @@ -4333,16 +4570,16 @@ g_expr(list3(DCMP, e1,e2)); switch(op) { case DOP+GT: case FOP+GT: - printf("\tbgt\tcr%d,L_%d\n",cmpflag,l1); + printf("\tbgt\t%s,%s%d\n",crname(cmpflag),lpfx,l1); break; case DOP+GE: case FOP+GE: - printf("\tbge\tcr%d,L_%d\n",cmpflag,l1); + printf("\tbge\t%s,%s%d\n",crname(cmpflag),lpfx,l1); break; case DOP+EQ: case FOP+EQ: - printf("\tbeq\tcr%d,L_%d\n",cmpflag,l1); + printf("\tbeq\t%s,%s%d\n",crname(cmpflag),lpfx,l1); break; case DOP+NEQ: case FOP+NEQ: - printf("\tbne\tcr%d,L_%d\n",cmpflag,l1); + printf("\tbne\t%s,%s%d\n",crname(cmpflag),lpfx,l1); break; } return l1; @@ -4407,7 +4644,7 @@ static void pcond(char *s,int cmpflag,int l1) { - printf("\tb%s cr%d,L_%d\n",s,cmpflag,l1); + printf("\tb%s %s,%s%d\n",s,crname(cmpflag),lpfx,l1); } static int @@ -4531,7 +4768,7 @@ lregister_name_low(reg), lregister_name_high(reg)); inc_cmpflag(); - printf("\tcmpwi cr%d,%s,0\n",cmpflag,lregister_name_low(reg)); + printf("\tcmpwi %s,%s,0\n",crname(cmpflag),lregister_name_low(reg)); jcond(label,cond); } @@ -4709,6 +4946,35 @@ static int lsrd_lib_used=0; static char *lsrd_lib[] = { +#ifdef __APPLE__ +".text", +" .align 2", +"lsrd__:", +" mr. r5,r5", +" beqlr", +" subfic r2,r5,32", +" stw r3,-32(r1)", +" stw r4,-28(r1)", +" cmpwi cr7,r2,0", +" bgt+ cr7,L__lsrd1", +" neg r0,r2", +" lwz r2,-32(r1)", +" li r9,0", +" srw r2,r2,r0", +" stw r9,-48(r1)", +" b L__lsrd2", +"L__lsrd1: lwz r0,-32(r1)", +" slw r9,r0,r2", +" lwz r2,-28(r1)", +" srw r0,r0,r5", +" srw r2,r2,r5", +" stw r0,-48(r1)", +" or r2,r2,r9", +"L__lsrd2: stw r2,-44(r1)", +" lwz r3,-48(r1)", +" lwz r4,-44(r1)", +" blr", +#else ".text", " .align 2", "lsrd__:", @@ -4736,11 +5002,41 @@ " lwz r3,-48(r1)", " lwz r4,-44(r1)", " blr", +#endif 0 }; static int asld_lib_used=0; static char *asld_lib[] = { +#ifdef __APPLE__ +".text", +" .align 2", +"asld__:", +" mr. r5,r5", +" beqlr", +" subfic r2,r5,32", +" stw r3,-32(r1)", +" stw r4,-28(r1)", +" cmpwi cr7,r2,0", +" bgt+ cr7,L__asld1", +" neg r0,r2", +" lwz r2,-28(r1)", +" li r9,0", +" slw r2,r2,r0", +" stw r9,-44(r1)", +" b L__asld2", +"L__asld1: lwz r0,-28(r1)", +" srw r9,r0,r2", +" lwz r2,-32(r1)", +" slw r0,r0,r5", +" slw r2,r2,r5", +" stw r0,-44(r1)", +" or r2,r2,r9", +"L__asld2: stw r2,-48(r1)", +" lwz r3,-48(r1)", +" lwz r4,-44(r1)", +" blr", +#else ".text", " .align 2", "asld__:", @@ -4768,11 +5064,13 @@ " lwz r3,-48(r1)", " lwz r4,-44(r1)", " blr", +#endif 0 }; static int asrd_lib_used=0; static char *asrd_lib[] = { +#ifdef __APPLE__ ".text", " .align 2", "asrd__:", @@ -4799,16 +5097,50 @@ " lwz r3,-48(r1)", " lwz r4,-44(r1)", " blr", +#else +".text", +" .align 2", +"asrd__:", +" mr. r5,r5", +" beqlr", +" subfic r2,r5,32", +" stw r3,-32(r1)", +" stw r4,-28(r1)", +" cmpwi cr7,r2,0", +" bgt+ cr7,L__asrd1", +" lwz r0,-32(r1)", +" neg r2,r2", +" sraw r2,r0,r2", +" srawi r0,r0,31", +" b L__asrd2", +"L__asrd1: lwz r0,-32(r1)", +" slw r9,r0,r2", +" lwz r2,-28(r1)", +" sraw r0,r0,r5", +" srw r2,r2,r5", +" or r2,r2,r9", +"L__asrd2: stw r0,-48(r1)", +" stw r2,-44(r1)", +" lwz r3,-48(r1)", +" lwz r4,-44(r1)", +" blr", +#endif 0 }; +#endif + static void extern_conv(char *conv) { code_save_stacks(); clear_ptr_cache(); extern_define(conv,0,FUNCTION,1); +#ifdef __APPLE__ printf("\tbl L_%s$stub\n",conv); +#else + printf("\tbl %s\n",conv); +#endif } #if FLOAT_CODE @@ -4849,7 +5181,9 @@ set_lreg_operand(reg,1); set_lreg(RET_LREGISTER,0); if (regv_l(oreg)!=5) { - printf("\tmr r5,%s\n", lregister_name_low(oreg)); + printf("\tmr %s,%s\n", + register_name(5), + lregister_name_low(oreg)); } printf("\tbl asld__\n"); } @@ -4863,7 +5197,9 @@ set_lreg_operand(reg,1); set_lreg(RET_LREGISTER,0); if (regv_l(oreg)!=5) { - printf("\tmr r5,%s\n", lregister_name_low(oreg)); + printf("\tmr %s,%s\n", + register_name(5), + lregister_name_low(oreg)); } printf("\tbl asrd__\n"); } @@ -4877,7 +5213,9 @@ set_lreg_operand(reg,1); set_lreg(RET_LREGISTER,0); if (regv_l(oreg)!=5) { - printf("\tmr r5,%s\n", lregister_name_low(oreg)); + printf("\tmr %s,%s\n", + register_name(5), + lregister_name_low(oreg)); } printf("\tbl lsrd__\n"); } @@ -4890,7 +5228,11 @@ set_lreg_operand(reg,1); set_lreg(RET_LREGISTER,0); set_lreg_operand1(oreg,1); +#ifdef __APPLE__ extern_conv("__divdi3"); +#else + extern_conv("_divdi3"); +#endif } static void @@ -4901,7 +5243,11 @@ set_lreg_operand(reg,1); set_lreg(RET_LREGISTER,0); set_lreg_operand1(oreg,1); +#ifdef __APPLE__ extern_conv("__udivdi3"); +#else + extern_conv("_udivdi3"); +#endif } static void @@ -4912,7 +5258,11 @@ set_lreg_operand(reg,1); set_lreg(RET_LREGISTER,0); set_lreg_operand1(oreg,1); +#ifdef __APPLE__ extern_conv("__moddi3"); +#else + extern_conv("_moddi3"); +#endif } static void @@ -4923,7 +5273,11 @@ set_lreg(RET_LREGISTER,0); set_lreg_operand(reg,1); set_lreg_operand1(oreg,1); +#ifdef __APPLE__ extern_conv("__umoddi3"); +#else + extern_conv("_umoddi3"); +#endif } #define check_lreg(reg) if (reg!=lreg) { lmove(reg,lreg); /* reg<=lreg */ } @@ -5169,7 +5523,11 @@ printf("\taddze %s,%s\n",crn_h,crn_h); break; case LBOR: +#ifdef __APPLE__ printf("\tori %s,%s,lo16(%d)\n",crn_l,crn_l,v); +#else + printf("\tori %s,%s,%d@l\n",crn_l,crn_l,v); +#endif break; default: error(-1); @@ -5340,7 +5698,6 @@ code_ll2f(creg); } -#endif static void ladd(int creg,int reg,int dir) // creg=reg+dir @@ -5523,6 +5880,9 @@ #endif #endif #endif +#ifndef __APPLE__ + if (saveFP_used) emit_lib(saveFP_lib); +#endif global_table(); /* printf("\t.ident \"Micro-C compiled\"\n"); */ } @@ -5553,23 +5913,31 @@ } else { printf("\taddi\t%s,%s,lo16(%d)\n",trn,crn,-min); } - printf("\tcmplwi cr%d,%s,%d\n",cmpflag,trn,max-min); - printf("\tbgt-\tcr%d,L_%d\n",cmpflag,dlabel); + printf("\tcmplwi %s,%s,%d\n",crname(cmpflag),trn,max-min); + printf("\tbgt-\t%s,%s%d\n",crname(cmpflag),lpfx,dlabel); inc_cmpflag(); switch(delta) { case 1: printf("\tslwi %s,%s,2\n",trn,trn); break; case 2: printf("\tli %s,1\n",srn); printf("\tand %s,%s,%s\n",srn,srn,trn); - printf("\tcmplwi cr%d,%s,0\n",cmpflag,srn); - printf("\tbne\tcr%d,L_%d\n",cmpflag,dlabel); + printf("\tcmplwi %s,%s,0\n",crname(cmpflag),srn); +#ifdef __APPLE__ + printf("\tbne\t%s,L_%d\n",crname(cmpflag),dlabel); +#else + printf("\tbne\t%s,.L%d\n",crname(cmpflag),dlabel); +#endif printf("\tslwi %s,%s,1\n",trn,trn); break; case 4: printf("\tli %s,3\n",srn); printf("\tand %s,%s,%s\n",srn,srn,trn); - printf("\tcmplwi cr%d,%s,0\n",cmpflag,srn); - printf("\tbne\tcr%d,L_%d\n",cmpflag,dlabel); + printf("\tcmplwi %s,%s,0\n",crname(cmpflag),srn); +#ifdef __APPLE__ + printf("\tbne\t%s,L_%d\n",crname(cmpflag),dlabel); +#else + printf("\tbne\t%s,.L%d\n",crname(cmpflag),dlabel); +#endif break; default: urn = register_name(u=get_register()); @@ -5577,10 +5945,15 @@ printf("\tdivwu %s,%s,%s\n",urn,trn,srn); printf("\tmullw %s,%s,%s\n",srn,urn,srn); printf("\tsubf %s,%s,%s\n",srn,trn,srn); - printf("\tcmplwi cr%d,%s,0\n",cmpflag,srn); - printf("\tbne\tcr%d,L_%d\n",cmpflag,dlabel); + printf("\tcmplwi %s,%s,0\n",crname(cmpflag),srn); +#ifdef __APPLE__ + printf("\tbne\t%s,L_%d\n",crname(cmpflag),dlabel); +#else + printf("\tbne\t%s,.L%d\n",crname(cmpflag),dlabel); +#endif printf("\tslwi %s,%s,2\n",trn,urn); } +#ifdef __APPLE__ printf("\taddis %s,r31,ha16(L_%d-L_%d)\n", srn,l,code_base); printf("\tla %s,lo16(L_%d-L_%d)(%s)\n", @@ -5590,6 +5963,17 @@ printf("\tadd r0,r0,%s\n",srn); printf("\tmtctr r0\n"); printf("\tbctr\n"); +#else + printf("\taddis %s,31,L_%d@h\n", + srn,l); + printf("\tla %s,L_%d@l(%s)\n", + srn,l,srn); + printf("\tadd %s,%s,%s\n",trn,srn,trn); + printf("\tlwz 0,0(%s)\n",trn); + printf("\tadd 0,0,%s\n",srn); + printf("\tmtctr 0\n"); + printf("\tbctr\n"); +#endif free_register(s); free_register(t); @@ -5606,7 +5990,7 @@ void code_table_value(int label,int table_top) { - printf("\t.long L_%d-L_%d\n",label,table_top); + printf("\t.long %s%d-%s%d\n",lpfx,label,lpfx,table_top); } void @@ -5632,7 +6016,7 @@ } else if (car(rstr)==FNAME) { printf("%s",(char*)cadr(rstr)); } else if (car(rstr)==STRING) { - printf("L_%d",cadr(rstr)); + printf("%s",(char*)cadr(rstr)); } else { error(-1); } @@ -5884,8 +6268,13 @@ } else { // use_int(adr); use_int(reg); +#ifdef __APPLE__ printf("\t%s %s,lo16(%d)(%s)\n",cload(size), register_name(reg),0,register_name(adr)); +#else + printf("\t%s %s,%d@l(%s)\n",cload(size), + register_name(reg),0,register_name(adr)); +#endif cext(sign,size,reg); /* shift left */ if ((i=bitpos+(32-bitsz))) @@ -5959,8 +6348,13 @@ // use_int(adr); use_int(value); lvalue = get_register(); +#ifdef __APPLE__ printf("\t%s %s,lo16(%d)(%s)\n",cload(size), register_name(lvalue),0,register_name(adr)); +#else + printf("\t%s %s,%d@l(%s)\n",cload(size), + register_name(lvalue),0,register_name(adr)); +#endif cext(sign,size,lvalue); crn = register_name(value); lrn = register_name(lvalue); @@ -5997,7 +6391,11 @@ if (c!=0) { /* do disjunction */ if (!((mask&c)&0xffff0000)) { +#ifdef __APPLE__ printf("\tori %s,%s,lo16(%d)\n",crn,crn,c); +#else + printf("\tori %s,%s,%d@l\n",crn,crn,c); +#endif } else { trn = register_name(tmp=get_register()); code_const(c,tmp); @@ -6050,8 +6448,13 @@ } else { use_int(adr); lvalue = get_register(); +#ifdef __APPLE__ printf("\t%s %s,lo16(%d)(%s)\n",cload(size), register_name(lvalue),0,register_name(adr)); +#else + printf("\t%s %s,%d@l(%s)\n",cload(size), + register_name(lvalue),0,register_name(adr)); +#endif cext(sign,size,lvalue); crn = register_name(lvalue); /* shift left */
--- a/mc-code-spu.c Wed Feb 21 20:11:23 2007 +0900 +++ b/mc-code-spu.c Thu Feb 22 15:05:42 2007 +0900 @@ -85,10 +85,10 @@ #if FLOAT_CODE static int code_d1(double d); static int code_d2(double d); -static void code_float_lib(char *opc,int oreg,int in_reg,int e1); -static void code_float_lib_c(char *lib,int from,int to,double value); -static void code_double_lib(char *lib,int to,int reg,int oreg); -static void code_double_lib_c(char *lib,int from,int to,double value); + + + + 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_float_int(int e1,int e2) ; @@ -1065,6 +1065,7 @@ return list3(FREGISTER,j,(int)n); } } + return list3(LVAR,new_lvar(SIZE_OF_INT),0); } int @@ -1951,7 +1952,7 @@ free_register(freg); if (mode) { printf("\t%s\t%s, %s\n", - "mvfs" + "mvfs", register_name(reg),register_name(freg)); } } @@ -2002,21 +2003,6 @@ return set_ireg(reg,mode); } -static void -set_lreg_operand(int reg,int mode) -{ - // save_stack,clear_ptr_cache is assumed - if (!is_longlong_reg(reg)) { error(-1); return; } - if (mode) { - lmove(LREGISTER_OPERAND,reg); - } -} - -static void -set_dreg_operand(int reg,int mode) -{ - set_lreg_operand(reg,mode); -} #endif @@ -3791,18 +3777,12 @@ #endif } -static void -fconst(int reg,double value) -{ - float f = value; - code_const(*((int*)&f),reg); -} void code_dconst(int e2,int freg,int d) { double value = dcadr(e2); - float f = value; + char *frn; int label,disp; @@ -3908,7 +3888,7 @@ void code_u2d0(int reg,int d) { - int tmp,freg1; + int freg1; char *crn,*frn,*lrn; use_int(reg); crn = register_name(reg); @@ -4019,60 +3999,6 @@ code_cmp_dregister(reg,d,label,cond); } -static void -code_double_lib(char *lib,int to,int reg,int oreg) -{ - code_save_stacks(); - clear_ptr_cache(); - set_operands(reg,reg,oreg,oreg); - extern_conv(lib); - set_dreg(RET_DREGISTER,0); - if (to!=RET_DREGISTER) { - lmove(to,RET_DREGISTER); - } -} - -static void -code_double_lib_c(char *lib,int from,int to,double value) -{ - code_save_stacks(); - clear_ptr_cache(); - set_dreg_operand(from,1); - dconst(DREGISTER_OPERAND_1_L,DREGISTER_OPERAND_1_H,value); - extern_conv(lib); - set_dreg(RET_DREGISTER,0); - if (to!=RET_DREGISTER) { - lmove(to,RET_DREGISTER); - } -} - -static void -code_float_lib(char *lib,int to,int reg,int oreg) -{ - code_save_stacks(); - clear_ptr_cache(); - if (reg!=FREGISTER_OPERAND) code_dregister(FREGISTER_OPERAND,reg,0); - if (to!=FREGISTER_OPERAND_1) code_dregister(FREGISTER_OPERAND_1,to,0); - extern_conv(lib); - set_freg(RET_FREGISTER,0); - if (to!=RET_FREGISTER) { - code_dregister(to,RET_FREGISTER,0); - } -} - -static void -code_float_lib_c(char *lib,int from,int to,double value) -{ - code_save_stacks(); - clear_ptr_cache(); - set_dreg_operand(from,1); - fconst(FREGISTER_OPERAND_1,value); - extern_conv(lib); - set_freg(RET_FREGISTER,0); - if (to!=RET_FREGISTER) { - code_dregister(to,RET_FREGISTER,0); - } -} void